From ee9f604388a3e77d3f4654e326f3976552e7f532 Mon Sep 17 00:00:00 2001
From: Jay <csj123456>
Date: 星期一, 25 十一月 2024 13:40:07 +0800
Subject: [PATCH] 测点启用和禁用

---
 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/kio/service/impl/ChannelKioTagServiceImpl.java |  128 ++++++++++++++++++++++++------------------
 1 files changed, 72 insertions(+), 56 deletions(-)

diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/kio/service/impl/ChannelKioTagServiceImpl.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/kio/service/impl/ChannelKioTagServiceImpl.java
index 1ded093..bb8034b 100644
--- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/kio/service/impl/ChannelKioTagServiceImpl.java
+++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/kio/service/impl/ChannelKioTagServiceImpl.java
@@ -1,106 +1,122 @@
 package com.iailab.module.data.channel.kio.service.impl;
 
+import cn.hutool.core.collection.CollUtil;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.baomidou.mybatisplus.core.metadata.IPage;
-import com.iailab.framework.common.constant.Constant;
-import com.iailab.framework.common.page.PageData;
-import com.iailab.framework.common.service.impl.BaseServiceImpl;
+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.kio.dao.ChannelKioTagDao;
-import com.iailab.module.data.channel.kio.dto.ChannelKioTagDTO;
 import com.iailab.module.data.channel.kio.entity.ChannelKioTagEntity;
 import com.iailab.module.data.channel.kio.service.ChannelKioTagService;
+import com.iailab.module.data.channel.kio.vo.KioTagPageReqVO;
+import com.iailab.module.data.channel.tag.vo.TagImportExcelVO;
+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.commons.lang3.StringUtils;
-import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
-import java.util.Arrays;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
+
+import static com.iailab.framework.common.exception.util.ServiceExceptionUtil.exception;
+import static com.iailab.module.data.enums.ErrorCodeConstants.*;
 
 /**
- * @author PanZhibao
+ * @author lirm
  * @Description
- * @createTime 2024年06月05日
+ * @createTime 2024年08月26日
  */
 @Slf4j
 @Service
-public class ChannelKioTagServiceImpl extends BaseServiceImpl<ChannelKioTagDao, ChannelKioTagEntity> implements ChannelKioTagService {
+public class ChannelKioTagServiceImpl extends ServiceImpl<ChannelKioTagDao, ChannelKioTagEntity> implements ChannelKioTagService {
     @Resource
     private ChannelKioTagDao channelKioTagDao;
 
-    @Value("${iems.upload-dir}")
-    private String uploadDir;
-
     @Override
-    public PageData<ChannelKioTagDTO> page(Map<String, Object> params) {
-        IPage<ChannelKioTagEntity> page = baseDao.selectPage(
-                getPage(params, Constant.CREATE_TIME, false),
-                getWrapper(params)
-        );
-        return getPageData(page, ChannelKioTagDTO.class);
+    public PageResult<ChannelKioTagEntity> queryPage(KioTagPageReqVO reqVO) {
+        return channelKioTagDao.selectPage(reqVO);
     }
 
     @Override
-    public ChannelKioTagDTO get(String id) {
-        ChannelKioTagEntity entity = baseDao.selectById(id);
-        return ConvertUtils.sourceToTarget(entity, ChannelKioTagDTO.class);
+    public ChannelKioTagEntity info(String id) {
+        return channelKioTagDao.selectById(id);
     }
 
     @Override
-    public void save(ChannelKioTagDTO dto) {
-        ChannelKioTagEntity entity = ConvertUtils.sourceToTarget(dto, ChannelKioTagEntity.class);
-        entity.setCreateTime(new Date());
-        entity.setUpdateTime(new Date());
-        insert(entity);
+    public void add(ChannelKioTagEntity channelKioTagEntity) {
+        channelKioTagDao.insert(channelKioTagEntity);
     }
 
     @Override
-    public void update(ChannelKioTagDTO dto) {
-        ChannelKioTagEntity entity = ConvertUtils.sourceToTarget(dto, ChannelKioTagEntity.class);
-        entity.setUpdateTime(new Date());
-        updateById(entity);
+    public void update(ChannelKioTagEntity channelKioTagEntity) {
+        channelKioTagDao.updateById(channelKioTagEntity);
     }
 
     @Override
-    public void delete(String[] ids) {
-        baseDao.deleteBatchIds(Arrays.asList(ids));
+    public void delete(String id) {
+        channelKioTagDao.deleteById(id);
     }
 
     @Override
-    public List<ChannelKioTagDTO> getByDevice(String device) {
+    public List<ChannelKioTagEntity> getByDevice(String device) {
         QueryWrapper<ChannelKioTagEntity> wrapper = new QueryWrapper<>();
-        wrapper.like(StringUtils.isNotBlank(device), "device", device)
-        .orderByAsc("tag_id");
-        List<ChannelKioTagEntity> list = baseDao.selectList(wrapper);
-        return ConvertUtils.sourceToTarget(list, ChannelKioTagDTO.class);
+        wrapper.like("device", device);
+        wrapper.orderByAsc("tag_id");
+        List<ChannelKioTagEntity> list = channelKioTagDao.selectList(wrapper);
+        return list;
     }
 
     @Override
-    public ChannelKioTagDTO getByTagName(String tagName) {
+    public ChannelKioTagEntity getByTagName(String tagName) {
         QueryWrapper<ChannelKioTagEntity> wrapper = new QueryWrapper<>();
         wrapper.eq("tag_name", tagName);
-        ChannelKioTagEntity entity = baseDao.selectOne(wrapper);
-        return ConvertUtils.sourceToTarget(entity, ChannelKioTagDTO.class);
+        ChannelKioTagEntity entity = channelKioTagDao.selectOne(wrapper);
+        return entity;
     }
 
     @Override
     public void deleteByDeviceName(String name) {
-        baseDao.delete(new QueryWrapper<ChannelKioTagEntity>().eq("device",name));
+        channelKioTagDao.delete(new QueryWrapper<ChannelKioTagEntity>().eq("device",name));
     }
 
-    private QueryWrapper<ChannelKioTagEntity> getWrapper(Map<String, Object> params){
-        String tagName = (String) params.get("tagName");
-        String device = (String) params.get("device");
-        QueryWrapper<ChannelKioTagEntity> wrapper = new QueryWrapper<>();
-        wrapper.eq(StringUtils.isNotBlank(device), "device", device);
-        wrapper.like(StringUtils.isNotBlank(tagName), "tag_name", tagName);
-        wrapper.orderByDesc("create_time");
-        return wrapper;
+    @Override
+    public TagImportRespVO importKioTagList(List<TagImportExcelVO> importTags, boolean isUpdateSupport, String device) {
+        // 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 -> {
+            // 判断如果不存在,再进行插入
+            ChannelKioTagEntity existTag = channelKioTagDao.selectOne(new QueryWrapper<ChannelKioTagEntity>()
+                    .eq("device", device)
+                    .eq("tag_name",importTag.getTagName()));
+            if (existTag == null) {
+                ChannelKioTagEntity channelKioTagEntity = ConvertUtils.sourceToTarget(importTag, ChannelKioTagEntity.class);
+                channelKioTagEntity.setId(UUID.randomUUID().toString());
+                channelKioTagEntity.setEnabled(CommonConstant.IS_ENABLE);
+                channelKioTagEntity.setDevice(device);
+                channelKioTagEntity.setCreateTime(new Date());
+                channelKioTagDao.insert(channelKioTagEntity);
+
+                respVO.getCreateTagNames().add(channelKioTagEntity.getTagName());
+                return;
+            }
+
+            // 如果存在,判断是否允许更新
+            if (!isUpdateSupport) {
+                respVO.getFailureTagNames().put(importTag.getTagName(), TAG_EXISTS.getMsg());
+                return;
+            }
+
+            ChannelKioTagEntity updateTag = BeanUtils.toBean(importTag, ChannelKioTagEntity.class);
+            updateTag.setId(existTag.getId());
+            baseMapper.updateById(updateTag);
+            respVO.getUpdateTagNames().add(importTag.getTagName());
+        });
+        return respVO;
     }
-
-
 }
\ No newline at end of file

--
Gitblit v1.9.3