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