15928045575 2 anni fa
parent
commit
2760e3eaa4

+ 10 - 0
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/controller/DeviceController.java

@@ -5,7 +5,9 @@ import com.sckw.core.annotation.Log;
 import com.sckw.core.web.response.HttpResult;
 import com.sckw.slope.detection.model.dto.LocationDTO;
 import com.sckw.slope.detection.model.param.DeviceAdd;
+import com.sckw.slope.detection.model.param.DeviceReferenceAdd;
 import com.sckw.slope.detection.model.param.DeviceQuery;
+import com.sckw.slope.detection.model.vo.DeviceReferenceVo;
 import com.sckw.slope.detection.service.DeviceService;
 import jakarta.servlet.http.HttpServletRequest;
 import jakarta.validation.Valid;
@@ -100,5 +102,13 @@ public class DeviceController {
         return deviceService.update(deviceAdd, request);
     }
 
+    @Log(description = "设置基准值")
+    //@RepeatSubmit(interval = 3000, message = "两次请求间隔未超过3秒")
+    @RequestMapping(name = "设置基准值", value = "/referenceEdit", method = RequestMethod.POST)
+    public HttpResult referenceEdit(@Valid @RequestBody DeviceReferenceAdd deviceReference, HttpServletRequest request) {
+        log.info("设置基准值 referenceEdit param:{}", JSONObject.toJSONString(deviceReference));
+        return deviceService.referenceEdit(deviceReference, request);
+    }
+
 
 }

+ 6 - 0
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/model/dos/mysql/KwsDeviceReference.java

@@ -30,6 +30,12 @@ public class KwsDeviceReference implements Serializable {
 
     private String mountainId;
 
+    /**
+     * 基准值
+     */
+    private BigDecimal value;
+
+
     /**
     * 原始基准值
     */

+ 36 - 0
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/model/param/DeviceReferenceAdd.java

@@ -0,0 +1,36 @@
+package com.sckw.slope.detection.model.param;
+
+import lombok.Data;
+
+import java.util.List;
+
+
+/**
+ * @author sky
+ * @description 新增
+ * @date 2023-10-31 15:10:14
+ */
+@Data
+public class DeviceReferenceAdd {
+
+    private Long id;
+
+    /**
+     * 设备id
+     */
+    private Long deviceId;
+
+
+    /**
+     * 状态
+     */
+    private int status;
+
+
+
+    /**
+     * 新增时的数据
+     */
+    private String referceData;
+
+}

+ 5 - 0
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/model/vo/DeviceIntegrationVo.java

@@ -75,5 +75,10 @@ public class DeviceIntegrationVo implements Serializable {
      */
     private String integrationBaseData;
 
+    /**
+     *当前测量值
+     */
+    private String currentData;
+
     private static final long serialVersionUID = 1L;
 }

+ 4 - 0
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/model/vo/DevicePartModelVo.java

@@ -38,6 +38,10 @@ public class DevicePartModelVo implements Serializable {
      * 要素基准
      */
     private String partBaseData;
+    /**
+     * 当前测量值
+     */
+    private String currentData;
 
     /**
      * 状态

+ 6 - 0
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/model/vo/DeviceReferenceVo.java

@@ -10,6 +10,7 @@ import java.math.BigDecimal;
 import java.time.LocalDateTime;
 import java.util.Date;
 import java.util.List;
+import java.util.Map;
 
 /**
  * @author sky
@@ -83,6 +84,11 @@ public class DeviceReferenceVo implements Serializable {
     @TableLogic(value = "0")
     private int delFlag;
 
+    /**
+     * 新增时的数据
+     */
+    private String referceData;
+
 
 
     private static final long serialVersionUID = 1L;

+ 73 - 1
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/service/DeviceService.java

@@ -1,5 +1,7 @@
 package com.sckw.slope.detection.service;
-
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.github.pagehelper.PageHelper;
@@ -27,6 +29,7 @@ import com.sckw.slope.detection.model.dos.tdengine.SlopeData;
 import com.sckw.slope.detection.model.dto.*;
 import com.sckw.slope.detection.model.param.DeviceAdd;
 import com.sckw.slope.detection.model.param.DeviceQuery;
+import com.sckw.slope.detection.model.param.DeviceReferenceAdd;
 import com.sckw.slope.detection.model.vo.*;
 import jakarta.servlet.http.HttpServletRequest;
 import lombok.extern.slf4j.Slf4j;
@@ -217,6 +220,7 @@ public class DeviceService {
                 .eq(KwsDeviceReference::getMountainId, headerData.getMountainId())
                 .eq(KwsDeviceReference::getDelFlag, NumberConstant.ZERO)
         );
+        String snCode = device.getSnCode();
         //获取基础要数
         List<DevicePartModelVo> partData = new ArrayList<>();
         partData = deviceModelPartMapper.selectByModelId(deviceModel.getId());
@@ -229,7 +233,12 @@ public class DeviceService {
                 }
                 references.forEach(re -> {
                         if (part.getPartName().equals(re.getItem())) {
+                            SlopeData slopeData = slopeDataMapper.selectListByLine(snCode, re.getItem());//获取到当前测量值
                             part.setPartBaseData(re.getOriginalValue().toString());
+                            if(!Objects.isNull(slopeData)){
+                                part.setCurrentData(slopeData.getVal());
+                            }
+
                         }
                 });
             }
@@ -243,7 +252,12 @@ public class DeviceService {
             for (DeviceIntegrationVo inter : intergData) {
                 references.forEach(re -> {
                     if (inter.getIntegrationName().equals(re.getItem())) {
+                        SlopeData slopeData = slopeDataMapper.selectListByLine(snCode, re.getItem());//获取到当前测量值
                         inter.setIntegrationBaseData(re.getOriginalValue().toString());
+                        if(!Objects.isNull(slopeData)){
+                            inter.setCurrentData(slopeData.getVal());
+                        }
+
                     }
                 });
             }
@@ -580,5 +594,63 @@ public class DeviceService {
         return HttpResult.ok(mapList);
     }
 
+    @Transactional
+    public HttpResult referenceEdit(DeviceReferenceAdd deviceReference, HttpServletRequest response) {
+
+        HeaderData headerData = commonService.getHeaderData(response);
+        String listData = deviceReference.getReferceData();
+        Long deviceId = deviceReference.getDeviceId();
+        JSONArray array = JSON.parseArray(listData);
+        LocalDateTime now = LocalDateTime.now();
+        BigDecimal zero = new BigDecimal("0");
+        for(Object object : array){
+            JSONObject obj = (JSONObject)object;
+            KwsDeviceReference reference = deviceReferenceMapper.selectOne(new LambdaQueryWrapper<KwsDeviceReference>()
+                    .eq(KwsDeviceReference::getMountainId, headerData.getMountainId())
+                    .eq(KwsDeviceReference::getDeviceId, deviceId)
+                    .eq(KwsDeviceReference::getDelFlag, 0)
+                    .eq(KwsDeviceReference::getItem, obj.get("item"))
+            );
+            long interId = new IdWorker(NumberConstant.ONE).nextId();
+            KwsDeviceReference kwsDeviceReference = new KwsDeviceReference();
+            BigDecimal value  = new BigDecimal(obj.get("value").toString());
+
+            if(Objects.isNull(reference)){
+                kwsDeviceReference.setOffset(zero);
+                kwsDeviceReference.setOriginalValue(zero);
+                kwsDeviceReference.setCurrentValue(value);
+            }else{
+                //如果有数据,则先删除原有数据。
+                deviceReferenceMapper.update(null, new LambdaUpdateWrapper<KwsDeviceReference>()
+                        .eq(KwsDeviceReference::getMountainId, headerData.getMountainId())
+                        .eq(KwsDeviceReference::getDeviceId, deviceId)
+                        .eq(KwsDeviceReference::getDelFlag, 0)
+                        .eq(KwsDeviceReference::getItem, obj.get("item"))
+                        .set(KwsDeviceReference::getDelFlag, NumberConstant.ONE)
+                );
+                BigDecimal offset = value.subtract(reference.getValue());
+                kwsDeviceReference.setOffset(offset);
+                kwsDeviceReference.setCurrentValue(reference.getValue());
+                kwsDeviceReference.setOriginalValue(value);
+            }
+            kwsDeviceReference.setId(interId);
+            kwsDeviceReference.setDeviceId(deviceId);
+            kwsDeviceReference.setMountainId(headerData.getCompanyId());
+            kwsDeviceReference.setType(Integer.parseInt(obj.get("type").toString()));
+            kwsDeviceReference.setItem(obj.get("item").toString());
+            kwsDeviceReference.setValue(value);
+
+
+            kwsDeviceReference.setCreateBy(Long.parseLong(headerData.getCreateBy()));
+            kwsDeviceReference.setCreateTime(now);
+            kwsDeviceReference.setStatus(NumberConstant.ONE);
+            kwsDeviceReference.setUpdateBy(Long.parseLong(headerData.getUpdateBy()));
+            kwsDeviceReference.setUpdateTime(now);
+            deviceReferenceMapper.insert(kwsDeviceReference);
+        }
+
+        return HttpResult.ok();
+    }
+
 
 }