提交 | 用户 | 时间
|
a6de49
|
1 |
package com.iailab.module.data.channel.modbus.service.impl; |
H |
2 |
|
|
3 |
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
4 |
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
c7f709
|
5 |
import com.iailab.framework.common.pojo.PageResult; |
a6de49
|
6 |
import com.iailab.framework.common.util.object.ConvertUtils; |
H |
7 |
import com.iailab.module.data.channel.modbus.dao.ChannelModBusTagDao; |
c7f709
|
8 |
import com.iailab.module.data.channel.modbus.dto.ChannelModbusTagDTO; |
a6de49
|
9 |
import com.iailab.module.data.channel.modbus.entity.ChannelModBusTagEntity; |
H |
10 |
import com.iailab.module.data.channel.modbus.service.ChannelModbusTagService; |
c7f709
|
11 |
import com.iailab.module.data.channel.modbus.vo.ModBusTagPageReqVO; |
a6de49
|
12 |
import lombok.extern.slf4j.Slf4j; |
H |
13 |
import org.springframework.beans.factory.annotation.Value; |
|
14 |
import org.springframework.stereotype.Service; |
|
15 |
|
|
16 |
import javax.annotation.Resource; |
c7f709
|
17 |
import java.util.Date; |
a6de49
|
18 |
import java.util.List; |
H |
19 |
|
|
20 |
/** |
c7f709
|
21 |
* @author lirm |
a6de49
|
22 |
* @Description |
c7f709
|
23 |
* @createTime 2024年08月27日 |
a6de49
|
24 |
*/ |
H |
25 |
@Slf4j |
|
26 |
@Service |
|
27 |
public class ChannelModbusTagServiceImpl extends ServiceImpl<ChannelModBusTagDao, ChannelModBusTagEntity> implements ChannelModbusTagService { |
|
28 |
@Resource |
|
29 |
private ChannelModBusTagDao channelModBusTagDao; |
|
30 |
|
|
31 |
@Value("${iems.upload-dir}") |
|
32 |
private String uploadDir; |
|
33 |
|
|
34 |
@Override |
c7f709
|
35 |
public PageResult<ChannelModBusTagEntity> queryPage(ModBusTagPageReqVO reqVO) { |
L |
36 |
return channelModBusTagDao.selectPage(reqVO); |
a6de49
|
37 |
} |
H |
38 |
|
|
39 |
@Override |
|
40 |
public ChannelModBusTagEntity info(String id) { |
|
41 |
return channelModBusTagDao.selectById(id); |
|
42 |
} |
|
43 |
|
|
44 |
@Override |
|
45 |
public void add(ChannelModBusTagEntity channelModBusTagEntity) { |
|
46 |
channelModBusTagDao.insert(channelModBusTagEntity); |
|
47 |
} |
|
48 |
|
|
49 |
@Override |
|
50 |
public void update(ChannelModBusTagEntity channelModBusTagEntity) { |
|
51 |
channelModBusTagDao.updateById(channelModBusTagEntity); |
|
52 |
} |
|
53 |
|
|
54 |
@Override |
|
55 |
public void delete(String id) { |
|
56 |
channelModBusTagDao.deleteById(id); |
|
57 |
} |
|
58 |
|
|
59 |
@Override |
|
60 |
public List<ChannelModBusTagEntity> getByDevice(String device) { |
|
61 |
QueryWrapper<ChannelModBusTagEntity> queryWrapper = new QueryWrapper<>(); |
|
62 |
queryWrapper.eq("device", device); |
|
63 |
queryWrapper.orderByDesc("create_time"); |
|
64 |
return channelModBusTagDao.selectList(queryWrapper); |
|
65 |
} |
|
66 |
|
|
67 |
@Override |
|
68 |
public List<ChannelModbusTagDTO> selectAll() { |
|
69 |
List<ChannelModBusTagEntity> entityList = baseMapper.selectList( |
|
70 |
null |
|
71 |
); |
|
72 |
return ConvertUtils.sourceToTarget(entityList, ChannelModbusTagDTO.class); |
|
73 |
} |
|
74 |
|
|
75 |
@Override |
|
76 |
public List<ChannelModBusTagEntity> listByIds(List<String> ids) { |
|
77 |
return baseMapper.selectList(new QueryWrapper<ChannelModBusTagEntity>().in("id", ids)); |
|
78 |
} |
|
79 |
|
|
80 |
@Override |
|
81 |
public void deleteByDeviceName(String name) { |
|
82 |
baseMapper.delete(new QueryWrapper<ChannelModBusTagEntity>().eq("device", name)); |
|
83 |
} |
|
84 |
|
|
85 |
// /** |
|
86 |
// * 导入Tag |
|
87 |
// * |
|
88 |
// * @param device |
|
89 |
// * @param file |
|
90 |
// * @throws Exception |
|
91 |
// */ |
|
92 |
// @Override |
|
93 |
// @Transactional(rollbackFor = Exception.class) |
|
94 |
// public void importTag(String device, MultipartFile file) throws Exception { |
|
95 |
// try { |
|
96 |
// String suffix = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".")); |
|
97 |
// String fileName = UUID.randomUUID().toString() + suffix; |
|
98 |
// String path = uploadDir + fileName; |
|
99 |
// file.transferTo(new File(path)); |
|
100 |
// |
|
101 |
// XSSFWorkbook hssfWorkbook = new XSSFWorkbook(new FileInputStream(path)); |
|
102 |
// XSSFSheet sheet = hssfWorkbook.getSheetAt(0); |
|
103 |
// int lastRowNum = sheet.getLastRowNum(); |
|
104 |
// log.info("最后一行:" + lastRowNum); |
|
105 |
// int lastCellNum = 6; |
|
106 |
// List<ChannelModBusTagEntity> dangerList = new ArrayList<>(); |
|
107 |
// for (int i = 1; i <= lastRowNum; i++) { |
|
108 |
// XSSFRow row = sheet.getRow(i); |
|
109 |
// for (int j = row.getFirstCellNum(); j < lastCellNum; j++) { |
|
110 |
// row.getCell(j).setCellType(CellType.STRING); |
|
111 |
// } |
|
112 |
// ChannelModBusTagEntity tagEntity = new ChannelModBusTagEntity(); |
|
113 |
// tagEntity.setId(UUID.randomUUID().toString()); |
|
114 |
// tagEntity.setTagName(row.getCell(1).getStringCellValue()); |
|
115 |
// tagEntity.setDataType(row.getCell(2).getStringCellValue()); |
|
116 |
// tagEntity.setEnabled(true); |
|
117 |
// tagEntity.setFormat(""); |
|
118 |
// tagEntity.setDevice(device); |
|
119 |
// tagEntity.setSamplingRate(0); |
|
120 |
// row.getCell(4).setCellType(CellType.STRING); |
|
121 |
// System.out.println(row.getCell(3).getStringCellValue()); |
|
122 |
// if(row.getCell(3).getStringCellValue().equals("1")){ |
|
123 |
// tagEntity.setAddress(String.format("1%04d",Integer.parseInt(row.getCell(4).getStringCellValue()))); |
|
124 |
// }else if(row.getCell(3).getStringCellValue().equals("3")){ |
|
125 |
// tagEntity.setAddress(String.format("4%04d",Integer.parseInt(row.getCell(4).getStringCellValue()))); |
|
126 |
// } |
|
127 |
// tagEntity.setTagDesc(row.getCell(5).getStringCellValue()); |
|
128 |
// dangerList.add(tagEntity); |
|
129 |
// } |
|
130 |
// if (CollectionUtils.isEmpty(dangerList)) { |
|
131 |
// return; |
|
132 |
// } |
|
133 |
// //getBaseMapper().insertList(dangerList); |
|
134 |
// dangerList.forEach(item -> { |
|
135 |
// try { |
|
136 |
// getBaseMapper().insert(item); |
|
137 |
// } catch (Exception ex) { |
|
138 |
// log.warn("插入异常:" + item.getTagName()); |
|
139 |
// } |
|
140 |
// }); |
|
141 |
// } catch (Exception ex) { |
|
142 |
// ex.printStackTrace(); |
|
143 |
// log.warn("导入失败!"); |
|
144 |
// throw ex; |
|
145 |
// } |
|
146 |
// } |
|
147 |
|
|
148 |
} |