From a9b8f1075a8200acb1d6b35b1b88041a60bedabd Mon Sep 17 00:00:00 2001
From: liriming <1343021927@qq.com>
Date: 星期二, 29 十月 2024 09:13:52 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'

---
 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/service/impl/DaPointServiceImpl.java |   82 ++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 80 insertions(+), 2 deletions(-)

diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/service/impl/DaPointServiceImpl.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/service/impl/DaPointServiceImpl.java
index 4f28365..fee2663 100644
--- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/service/impl/DaPointServiceImpl.java
+++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/service/impl/DaPointServiceImpl.java
@@ -1,12 +1,19 @@
 package com.iailab.module.data.point.service.impl;
 
+import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.util.StrUtil;
 import com.alibaba.fastjson.JSONArray;
 import com.baomidou.dynamic.datasource.annotation.DSTransactional;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.google.common.annotations.VisibleForTesting;
+import com.iailab.framework.common.exception.ServiceException;
 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.framework.datapermission.core.util.DataPermissionUtils;
+import com.iailab.framework.mybatis.core.query.LambdaQueryWrapperX;
 import com.iailab.module.data.common.enums.CommonConstant;
 import com.iailab.module.data.common.enums.IsEnableEnum;
 import com.iailab.module.data.point.common.IncreaseCodeEnum;
@@ -14,18 +21,27 @@
 import com.iailab.module.data.point.dao.DaPointDao;
 import com.iailab.module.data.point.dto.DaMeasurePointDTO;
 import com.iailab.module.data.point.dto.DaPointDTO;
+import com.iailab.module.data.point.entity.DaMeasurePointEntity;
 import com.iailab.module.data.point.entity.DaPointEntity;
 import com.iailab.module.data.point.service.DaMathPointService;
 import com.iailab.module.data.point.service.DaMeasurePointService;
 import com.iailab.module.data.point.service.DaPointService;
 import com.iailab.module.data.point.service.DaSequenceNumService;
-import com.iailab.module.data.point.vo.DaPointPageReqVO;
+import com.iailab.module.data.point.vo.*;
+import com.iailab.module.infra.api.config.ConfigApi;
 import org.apache.commons.lang3.ObjectUtils;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.CollectionUtils;
+
 
 import javax.annotation.Resource;
 import java.util.*;
+
+import com.iailab.module.data.enums.ErrorCodeConstants;
+
+import static com.iailab.framework.common.exception.util.ServiceExceptionUtil.exception;
+import static com.iailab.module.data.enums.ErrorCodeConstants.*;
 
 /**
  * @author lirm
@@ -47,10 +63,12 @@
     @Resource
     private DaPointDao daPointDao;
 
+    @Resource
+    private ConfigApi configApi;
 
     @Override
     public PageResult<DaPointDTO> queryPage(DaPointPageReqVO reqVO) {
-        IPage<DaPointDTO> page = daPointDao.selectPage(reqVO);
+        IPage<DaPointDTO> page = daPointDao.selectPageList(reqVO);
         return new PageResult<DaPointDTO>(page.getRecords(), page.getTotal());
     }
 
@@ -240,6 +258,66 @@
     }
 
     @Override
+    @DSTransactional(rollbackFor = Exception.class) // 添加事务,异常则回滚所有导入
+    public PointImportRespVO importPointList(List<PointImportExcelVO> importPoints, boolean isUpdateSupport) {
+        // 1.1 参数校验
+        if (CollUtil.isEmpty(importPoints)) {
+            throw exception(POINT_IMPORT_LIST_IS_EMPTY);
+        }
+        
+        // 2. 遍历,逐个创建 or 更新
+        PointImportRespVO respVO = PointImportRespVO.builder().createPointnames(new ArrayList<>())
+                .updatePointnames(new ArrayList<>()).failurePointnames(new LinkedHashMap<>()).build();
+        importPoints.forEach(importPoint -> {
+
+            // 判断如果不存在,再进行插入
+            DaPointEntity existPoint = baseMapper.selectByPointName(importPoint.getPointName());
+            if (existPoint == null) {
+
+                DaPointEntity daPointEntity = ConvertUtils.sourceToTarget(importPoint, DaPointEntity.class);
+                daPointEntity.setId(UUID.randomUUID().toString());
+                DaMeasurePointDTO measurePoint = new DaMeasurePointDTO();
+                measurePoint.setSourceType(importPoint.getSourceType());
+                measurePoint.setSourceId(importPoint.getSourceId());
+                measurePoint.setTagNo(importPoint.getTagNo());
+                daPointEntity.setPointNo(daSequenceNumService.getAndIncreaseByCode(IncreaseCodeEnum.POINT_M.name()));
+                daPointEntity.setIsEnable(CommonConstant.IS_ENABLE);
+                daPointEntity.setCreateTime(new Date());
+
+                daMeasurePointService.add(measurePoint, daPointEntity.getId());
+                daPointDao.insert(daPointEntity);
+
+                respVO.getCreatePointnames().add(importPoint.getPointName());
+                return;
+            }
+
+            // 如果存在,判断是否允许更新
+            if (!isUpdateSupport) {
+                respVO.getFailurePointnames().put(importPoint.getPointName(), POINT_EXISTS.getMsg());
+                return;
+            }
+
+            DaPointEntity updatePoint = BeanUtils.toBean(importPoint, DaPointEntity.class);
+            updatePoint.setId(existPoint.getId());
+            baseMapper.updateById(updatePoint);
+            DaMeasurePointEntity measurePoint = new DaMeasurePointEntity();
+            measurePoint.setSourceType(importPoint.getSourceType());
+            measurePoint.setSourceId(importPoint.getSourceId());
+            measurePoint.setTagNo(importPoint.getTagNo());
+            daMeasurePointService.update(measurePoint, new QueryWrapper<DaMeasurePointEntity>().eq("point_id",updatePoint.getId()));
+            respVO.getUpdatePointnames().add(importPoint.getPointName());
+        });
+        return respVO;
+    }
+
+    @Override
+    public PageResult<DaPointEntity> queryExcelList(DaPointPageReqVO exportReqVO) {
+
+        return daPointDao.selectExcelList(exportReqVO);
+
+    }
+
+    @Override
     public void enableByIds(String[] ids) {
         if (CollectionUtils.isEmpty(Arrays.asList(ids))) {
             return;

--
Gitblit v1.9.3