| | |
| | | package com.iailab.module.data.channel.opcda.service.impl; |
| | | |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import com.baomidou.dynamic.datasource.annotation.DSTransactional; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.iailab.framework.common.pojo.PageResult; |
| | | import com.iailab.framework.common.util.object.BeanUtils; |
| | | import com.iailab.framework.common.util.object.ConvertUtils; |
| | | import com.iailab.module.data.channel.opcda.dao.ChannelOPCDATagDao; |
| | | import com.iailab.module.data.channel.opcda.dto.ChannelOPCDATagDTO; |
| | | import com.iailab.module.data.channel.opcda.entity.ChannelOPCDATagEntity; |
| | | import com.iailab.module.data.channel.opcda.service.ChannelOPCDATagService; |
| | | import com.iailab.module.data.channel.opcda.vo.OpcDaTagImportExcelVO; |
| | | import com.iailab.module.data.channel.opcda.vo.OpcDaTagPageReqVO; |
| | | import com.iailab.module.data.channel.tag.vo.TagImportRespVO; |
| | | import com.iailab.module.data.common.enums.CommonConstant; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.poi.ss.usermodel.CellType; |
| | | import org.apache.poi.xssf.usermodel.XSSFRow; |
| | |
| | | import org.apache.poi.xssf.usermodel.XSSFWorkbook; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.io.File; |
| | | import java.io.FileInputStream; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.UUID; |
| | | import java.util.*; |
| | | |
| | | import static com.iailab.framework.common.exception.util.ServiceExceptionUtil.exception; |
| | | import static com.iailab.module.data.enums.ErrorCodeConstants.*; |
| | | |
| | | /** |
| | | * @author lirm |
| | |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @DSTransactional(rollbackFor = Exception.class) |
| | | public void importTag(String serverId, MultipartFile file) throws Exception { |
| | | try { |
| | | String suffix = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".")); |
| | |
| | | tagEntity.setTagName(row.getCell(1).getStringCellValue()); |
| | | tagEntity.setDataType(row.getCell(2).getStringCellValue()); |
| | | tagEntity.setItemId(row.getCell(3).getStringCellValue()); |
| | | tagEntity.setEnabled(true); |
| | | tagEntity.setEnabled(CommonConstant.IS_ENABLE); |
| | | tagEntity.setServerId(serverId); |
| | | dangerList.add(tagEntity); |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public TagImportRespVO importOpcDaTagList(List<OpcDaTagImportExcelVO> importTags, boolean isUpdateSupport, String serverId) { |
| | | // 1.1 参数校验 |
| | | if (CollUtil.isEmpty(importTags)) { |
| | | throw exception(TAG_IMPORT_LIST_IS_EMPTY); |
| | | } |
| | | // 2. 遍历,逐个创建 or 更新 |
| | | TagImportRespVO respVO = TagImportRespVO.builder().createTagNames(new ArrayList<>()) |
| | | .updateTagNames(new ArrayList<>()).failureTagNames(new LinkedHashMap<>()).build(); |
| | | importTags.forEach(importTag -> { |
| | | // 判断如果不存在,再进行插入 |
| | | ChannelOPCDATagEntity existTag = channelOPCDATagDao.selectOne(new QueryWrapper<ChannelOPCDATagEntity>() |
| | | .eq("server_id", serverId) |
| | | .eq("tag_name",importTag.getTagName())); |
| | | if (existTag == null) { |
| | | ChannelOPCDATagEntity channelOPCDATagEntity = ConvertUtils.sourceToTarget(importTag, ChannelOPCDATagEntity.class); |
| | | channelOPCDATagEntity.setId(UUID.randomUUID().toString()); |
| | | channelOPCDATagEntity.setEnabled(CommonConstant.IS_ENABLE); |
| | | channelOPCDATagEntity.setServerId(serverId); |
| | | channelOPCDATagEntity.setCreateTime(new Date()); |
| | | channelOPCDATagDao.insert(channelOPCDATagEntity); |
| | | |
| | | respVO.getCreateTagNames().add(channelOPCDATagEntity.getTagName()); |
| | | return; |
| | | } |
| | | |
| | | // 如果存在,判断是否允许更新 |
| | | if (!isUpdateSupport) { |
| | | respVO.getFailureTagNames().put(importTag.getTagName(), TAG_EXISTS.getMsg()); |
| | | return; |
| | | } |
| | | |
| | | ChannelOPCDATagEntity updateTag = BeanUtils.toBean(importTag, ChannelOPCDATagEntity.class); |
| | | updateTag.setId(existTag.getId()); |
| | | baseMapper.updateById(updateTag); |
| | | respVO.getUpdateTagNames().add(importTag.getTagName()); |
| | | }); |
| | | return respVO; |
| | | } |
| | | |
| | | } |