提交 | 用户 | 时间
|
a6de49
|
1 |
package com.iailab.module.data.channel.kio.service.impl; |
H |
2 |
|
03e8ac
|
3 |
import cn.hutool.core.collection.CollUtil; |
a6de49
|
4 |
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
aecc49
|
5 |
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
L |
6 |
import com.iailab.framework.common.pojo.PageResult; |
03e8ac
|
7 |
import com.iailab.framework.common.util.object.BeanUtils; |
J |
8 |
import com.iailab.framework.common.util.object.ConvertUtils; |
a6de49
|
9 |
import com.iailab.module.data.channel.kio.dao.ChannelKioTagDao; |
H |
10 |
import com.iailab.module.data.channel.kio.entity.ChannelKioTagEntity; |
|
11 |
import com.iailab.module.data.channel.kio.service.ChannelKioTagService; |
aecc49
|
12 |
import com.iailab.module.data.channel.kio.vo.KioTagPageReqVO; |
03e8ac
|
13 |
import com.iailab.module.data.channel.tag.vo.TagImportExcelVO; |
J |
14 |
import com.iailab.module.data.channel.tag.vo.TagImportRespVO; |
|
15 |
import com.iailab.module.data.common.enums.CommonConstant; |
a6de49
|
16 |
import lombok.extern.slf4j.Slf4j; |
H |
17 |
import org.springframework.stereotype.Service; |
|
18 |
|
|
19 |
import javax.annotation.Resource; |
03e8ac
|
20 |
import java.util.*; |
J |
21 |
|
|
22 |
import static com.iailab.framework.common.exception.util.ServiceExceptionUtil.exception; |
|
23 |
import static com.iailab.module.data.enums.ErrorCodeConstants.*; |
a6de49
|
24 |
|
H |
25 |
/** |
aecc49
|
26 |
* @author lirm |
a6de49
|
27 |
* @Description |
aecc49
|
28 |
* @createTime 2024年08月26日 |
a6de49
|
29 |
*/ |
H |
30 |
@Slf4j |
|
31 |
@Service |
aecc49
|
32 |
public class ChannelKioTagServiceImpl extends ServiceImpl<ChannelKioTagDao, ChannelKioTagEntity> implements ChannelKioTagService { |
a6de49
|
33 |
@Resource |
H |
34 |
private ChannelKioTagDao channelKioTagDao; |
|
35 |
|
|
36 |
@Override |
aecc49
|
37 |
public PageResult<ChannelKioTagEntity> queryPage(KioTagPageReqVO reqVO) { |
L |
38 |
return channelKioTagDao.selectPage(reqVO); |
a6de49
|
39 |
} |
H |
40 |
|
|
41 |
@Override |
aecc49
|
42 |
public ChannelKioTagEntity info(String id) { |
L |
43 |
return channelKioTagDao.selectById(id); |
a6de49
|
44 |
} |
H |
45 |
|
|
46 |
@Override |
aecc49
|
47 |
public void add(ChannelKioTagEntity channelKioTagEntity) { |
L |
48 |
channelKioTagDao.insert(channelKioTagEntity); |
a6de49
|
49 |
} |
H |
50 |
|
|
51 |
@Override |
aecc49
|
52 |
public void update(ChannelKioTagEntity channelKioTagEntity) { |
L |
53 |
channelKioTagDao.updateById(channelKioTagEntity); |
a6de49
|
54 |
} |
H |
55 |
|
|
56 |
@Override |
aecc49
|
57 |
public void delete(String id) { |
L |
58 |
channelKioTagDao.deleteById(id); |
a6de49
|
59 |
} |
H |
60 |
|
|
61 |
@Override |
aecc49
|
62 |
public List<ChannelKioTagEntity> getByDevice(String device) { |
a6de49
|
63 |
QueryWrapper<ChannelKioTagEntity> wrapper = new QueryWrapper<>(); |
aecc49
|
64 |
wrapper.like("device", device); |
L |
65 |
wrapper.orderByAsc("tag_id"); |
|
66 |
List<ChannelKioTagEntity> list = channelKioTagDao.selectList(wrapper); |
|
67 |
return list; |
a6de49
|
68 |
} |
H |
69 |
|
|
70 |
@Override |
aecc49
|
71 |
public ChannelKioTagEntity getByTagName(String tagName) { |
a6de49
|
72 |
QueryWrapper<ChannelKioTagEntity> wrapper = new QueryWrapper<>(); |
H |
73 |
wrapper.eq("tag_name", tagName); |
aecc49
|
74 |
ChannelKioTagEntity entity = channelKioTagDao.selectOne(wrapper); |
L |
75 |
return entity; |
a6de49
|
76 |
} |
H |
77 |
|
|
78 |
@Override |
|
79 |
public void deleteByDeviceName(String name) { |
aecc49
|
80 |
channelKioTagDao.delete(new QueryWrapper<ChannelKioTagEntity>().eq("device",name)); |
a6de49
|
81 |
} |
03e8ac
|
82 |
|
J |
83 |
@Override |
|
84 |
public TagImportRespVO importKioTagList(List<TagImportExcelVO> importTags, boolean isUpdateSupport, String device) { |
|
85 |
// 1.1 参数校验 |
|
86 |
if (CollUtil.isEmpty(importTags)) { |
|
87 |
throw exception(TAG_IMPORT_LIST_IS_EMPTY); |
|
88 |
} |
|
89 |
// 2. 遍历,逐个创建 or 更新 |
|
90 |
TagImportRespVO respVO = TagImportRespVO.builder().createTagNames(new ArrayList<>()) |
|
91 |
.updateTagNames(new ArrayList<>()).failureTagNames(new LinkedHashMap<>()).build(); |
|
92 |
importTags.forEach(importTag -> { |
|
93 |
// 判断如果不存在,再进行插入 |
|
94 |
ChannelKioTagEntity existTag = channelKioTagDao.selectOne(new QueryWrapper<ChannelKioTagEntity>() |
|
95 |
.eq("device", device) |
|
96 |
.eq("tag_name",importTag.getTagName())); |
|
97 |
if (existTag == null) { |
|
98 |
ChannelKioTagEntity channelKioTagEntity = ConvertUtils.sourceToTarget(importTag, ChannelKioTagEntity.class); |
|
99 |
channelKioTagEntity.setId(UUID.randomUUID().toString()); |
|
100 |
channelKioTagEntity.setEnabled(CommonConstant.IS_ENABLE); |
|
101 |
channelKioTagEntity.setDevice(device); |
|
102 |
channelKioTagEntity.setCreateTime(new Date()); |
|
103 |
channelKioTagDao.insert(channelKioTagEntity); |
|
104 |
|
|
105 |
respVO.getCreateTagNames().add(channelKioTagEntity.getTagName()); |
|
106 |
return; |
|
107 |
} |
|
108 |
|
|
109 |
// 如果存在,判断是否允许更新 |
|
110 |
if (!isUpdateSupport) { |
|
111 |
respVO.getFailureTagNames().put(importTag.getTagName(), TAG_EXISTS.getMsg()); |
|
112 |
return; |
|
113 |
} |
|
114 |
|
|
115 |
ChannelKioTagEntity updateTag = BeanUtils.toBean(importTag, ChannelKioTagEntity.class); |
|
116 |
updateTag.setId(existTag.getId()); |
|
117 |
baseMapper.updateById(updateTag); |
|
118 |
respVO.getUpdateTagNames().add(importTag.getTagName()); |
|
119 |
}); |
|
120 |
return respVO; |
|
121 |
} |
a6de49
|
122 |
} |