From ff763ecc9e3aa99de5e583e2f930a446b47f9514 Mon Sep 17 00:00:00 2001
From: houzhongjian <houzhongyi@126.com>
Date: 星期五, 08 十一月 2024 11:13:42 +0800
Subject: [PATCH] 提交海康摄像头SDK

---
 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/service/impl/DaPointServiceImpl.java |  102 +++++++++++++++++++++++++++++++-------------------
 1 files changed, 63 insertions(+), 39 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 a2b1ce0..a761e3b 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,22 +1,18 @@
 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.channel.common.service.ChannelSourceService;
 import com.iailab.module.data.common.enums.CommonConstant;
 import com.iailab.module.data.common.enums.IsEnableEnum;
-import com.iailab.module.data.point.common.IncreaseCodeEnum;
+import com.iailab.module.data.common.enums.IncreaseCodeEnum;
 import com.iailab.module.data.point.common.PointTypeEnum;
 import com.iailab.module.data.point.dao.DaPointDao;
 import com.iailab.module.data.point.dto.DaMeasurePointDTO;
@@ -31,14 +27,11 @@
 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.*;
@@ -65,6 +58,9 @@
 
     @Resource
     private ConfigApi configApi;
+
+    @Resource
+    private ChannelSourceService channelSourceService;
 
     @Override
     public PageResult<DaPointDTO> queryPage(DaPointPageReqVO reqVO) {
@@ -129,18 +125,24 @@
     public void add(DaPointDTO dataPoint) {
         DaPointEntity daPointEntity = ConvertUtils.sourceToTarget(dataPoint, DaPointEntity.class);
         daPointEntity.setId(UUID.randomUUID().toString());
-        if (PointTypeEnum.MEASURE_POINT.getName().equals(dataPoint.getPointType())) {
-            DaMeasurePointDTO measurePoint = new DaMeasurePointDTO();
-            measurePoint.setSourceType(dataPoint.getSourceOption().get(0));
-            measurePoint.setSourceId(dataPoint.getSourceOption().get(1));
-            measurePoint.setTagNo(dataPoint.getSourceOption().get(2));
-            daMeasurePointService.add(measurePoint, daPointEntity.getId());
-            daPointEntity.setPointNo(daSequenceNumService.getAndIncreaseByCode(IncreaseCodeEnum.POINT_M.name()));
-        } else if (PointTypeEnum.CALCULATE_POINT.getName().equals(dataPoint.getPointType())) {
-            daMathPointService.add(dataPoint.getMathPoint(), daPointEntity.getId());
-            daPointEntity.setPointNo(daSequenceNumService.getAndIncreaseByCode(IncreaseCodeEnum.POINT_C.name()));
-        } else if (PointTypeEnum.CONSTANT.getName().equals(dataPoint.getPointType())) {
-            daPointEntity.setPointNo(daSequenceNumService.getAndIncreaseByCode(IncreaseCodeEnum.POINT_F.name()));
+        switch (PointTypeEnum.getEumByCode(dataPoint.getPointType())) {
+            case MEASURE_POINT:
+                DaMeasurePointDTO measurePoint = new DaMeasurePointDTO();
+                measurePoint.setSourceType(dataPoint.getSourceOption().get(0));
+                measurePoint.setSourceId(dataPoint.getSourceOption().get(1));
+                measurePoint.setTagNo(dataPoint.getSourceOption().get(2));
+                daMeasurePointService.add(measurePoint, daPointEntity.getId());
+                daPointEntity.setPointNo(daSequenceNumService.getAndIncreaseByCode(IncreaseCodeEnum.POINT_M.name()));
+                break;
+            case CALCULATE_POINT:
+                daMathPointService.add(dataPoint.getMathPoint(), daPointEntity.getId());
+                daPointEntity.setPointNo(daSequenceNumService.getAndIncreaseByCode(IncreaseCodeEnum.POINT_C.name()));
+                break;
+            case CONSTANT:
+                daPointEntity.setPointNo(daSequenceNumService.getAndIncreaseByCode(IncreaseCodeEnum.POINT_F.name()));
+                break;
+            default:
+                break;
         }
         daPointEntity.setIsEnable(CommonConstant.IS_ENABLE);
         daPointEntity.setCreateTime(new Date());
@@ -153,14 +155,19 @@
         DaPointEntity daPointEntity = ConvertUtils.sourceToTarget(dataPoint, DaPointEntity.class);
         daPointEntity.setUpdateTime(new Date());
         daPointDao.updateById(daPointEntity);
-        if (PointTypeEnum.MEASURE_POINT.getName().equals(dataPoint.getPointType())) {
-            DaMeasurePointDTO measurePoint = dataPoint.getMeasurePoint();
-            measurePoint.setSourceType(dataPoint.getSourceOption().get(0));
-            measurePoint.setSourceId(dataPoint.getSourceOption().get(1));
-            measurePoint.setTagNo(dataPoint.getSourceOption().get(2));
-            daMeasurePointService.update(measurePoint);
-        } else if (PointTypeEnum.CALCULATE_POINT.getName().equals(dataPoint.getPointType())) {
-            daMathPointService.update(dataPoint.getMathPoint());
+        switch (PointTypeEnum.getEumByCode(dataPoint.getPointType())) {
+            case MEASURE_POINT:
+                DaMeasurePointDTO measurePoint = dataPoint.getMeasurePoint();
+                measurePoint.setSourceType(dataPoint.getSourceOption().get(0));
+                measurePoint.setSourceId(dataPoint.getSourceOption().get(1));
+                measurePoint.setTagNo(dataPoint.getSourceOption().get(2));
+                daMeasurePointService.update(measurePoint);
+                break;
+            case CALCULATE_POINT:
+                daMathPointService.update(dataPoint.getMathPoint());
+                break;
+            default:
+                break;
         }
     }
 
@@ -298,7 +305,8 @@
         if (CollUtil.isEmpty(importPoints)) {
             throw exception(POINT_IMPORT_LIST_IS_EMPTY);
         }
-        
+
+        Map<String, Map<String, String>> sourcesIdMap = channelSourceService.getSourcesId();
         // 2. 遍历,逐个创建 or 更新
         PointImportRespVO respVO = PointImportRespVO.builder().createPointnames(new ArrayList<>())
                 .updatePointnames(new ArrayList<>()).failurePointnames(new LinkedHashMap<>()).build();
@@ -307,20 +315,33 @@
             // 判断如果不存在,再进行插入
             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());
+                switch (PointTypeEnum.getEumByCode(daPointEntity.getPointType())) {
+                    case MEASURE_POINT:
+                        DaMeasurePointDTO measurePoint = new DaMeasurePointDTO();
+                        measurePoint.setSourceType(importPoint.getSourceType());
+                        measurePoint.setSourceId(sourcesIdMap.get(importPoint.getSourceType()).get(importPoint.getSourceName()));
+                        measurePoint.setTagNo(importPoint.getTagNo());
+                        measurePoint.setValueType(importPoint.getValueType());
+                        measurePoint.setDimension(importPoint.getDimension());
+                        daMeasurePointService.add(measurePoint, daPointEntity.getId());
+                        daPointEntity.setPointNo(daSequenceNumService.getAndIncreaseByCode(IncreaseCodeEnum.POINT_M.name()));
+                        break;
+                    case CALCULATE_POINT:
+                        daMathPointService.add(importPoint.getExpression(), daPointEntity.getId());
+                        daPointEntity.setPointNo(daSequenceNumService.getAndIncreaseByCode(IncreaseCodeEnum.POINT_C.name()));
+                        break;
+                    case CONSTANT:
+                        daPointEntity.setPointNo(daSequenceNumService.getAndIncreaseByCode(IncreaseCodeEnum.POINT_F.name()));
+                        break;
+                    default:
+                        break;
+                }
 
-                daMeasurePointService.add(measurePoint, daPointEntity.getId());
                 daPointDao.insert(daPointEntity);
-
                 respVO.getCreatePointnames().add(importPoint.getPointName());
                 return;
             }
@@ -336,9 +357,12 @@
             baseMapper.updateById(updatePoint);
             DaMeasurePointEntity measurePoint = new DaMeasurePointEntity();
             measurePoint.setSourceType(importPoint.getSourceType());
-            measurePoint.setSourceId(importPoint.getSourceId());
+            measurePoint.setSourceId(sourcesIdMap.get(importPoint.getSourceType()).get(importPoint.getSourceName()));
             measurePoint.setTagNo(importPoint.getTagNo());
             daMeasurePointService.update(measurePoint, new QueryWrapper<DaMeasurePointEntity>().eq("point_id",updatePoint.getId()));
+
+
+
             respVO.getUpdatePointnames().add(importPoint.getPointName());
         });
         return respVO;

--
Gitblit v1.9.3