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