15928045575 2 سال پیش
والد
کامیت
d09ae2d3b9

+ 6 - 0
slope-common/slope-common-core/src/main/java/com/sckw/core/model/enums/MessageLogEnum.java

@@ -171,6 +171,12 @@ public enum MessageLogEnum {
     REPORT_BATCH_DELETE("slope_manage", "PROJECT_LOG", "报表批量删除", "27",
             "共有${count}条边坡报表被批量删除,请确认", "报表批量删除"),
 
+    REFERENCE_EDIT("slope_manage", "PROJECT_LOG", "调整基准", "29",
+            "设备【${name}】已调整了监测基准值,所属边坡【${projectName}】,【${desc}】", "调整基准"),
+
+    REFERENCE_ADD("slope_manage", "PROJECT_LOG", "设置基准", "30",
+            "设备【${name}】已设置了监测基准值,所属边坡【${projectName}】,【${desc}】", "设置基准"),
+
     ;
 
 

+ 2 - 0
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/dao/mysql/KwsDeviceMapper.java

@@ -40,6 +40,8 @@ public interface KwsDeviceMapper extends BaseMapper<KwsDevice> {
 
     List<DeviceVo> selectByDeviceParam(@Param("deviceQuery") DeviceQuery deviceQuery);
 
+    List<DeviceVo> selectProjectByDeviceId(@Param("deviceId") String deviceId);
+
     /**
      * 查询项目绑定的设备
      *

+ 5 - 1
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/service/BackTrackService.java

@@ -36,6 +36,7 @@ import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.CollectionUtils;
 
 import java.math.BigDecimal;
+import java.text.DecimalFormat;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.*;
@@ -251,9 +252,12 @@ public class BackTrackService {
                     } else {//如果是其他
                         offsetValue = subtract;
                     }
+                    double number = offsetValue.doubleValue();
+                    DecimalFormat decimalFormat = new DecimalFormat("#.00");
+                    String result = decimalFormat.format(number);
                     Map<String, Object> temp = new HashMap<>();
                     temp.put("time", key);
-                    temp.put("offset", offsetValue);
+                    temp.put("offset", result);
                     datemap.add(temp);
                 }
                 Collections.reverse(datemap);

+ 24 - 10
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/service/CommonService.java

@@ -37,6 +37,7 @@ import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
 
 import java.math.BigDecimal;
+import java.text.DecimalFormat;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.time.LocalDateTime;
@@ -181,10 +182,13 @@ public class CommonService {
                 angleInRadians = deviceReference.getCurrentValue().doubleValue();
             }
             double cosValue = Math.cos(Math.toRadians(angleInRadians));;
-            double doubleValue = subtract.divide(new BigDecimal("360"), 11, BigDecimal.ROUND_HALF_UP).doubleValue();
+            double doubleValue = subtract.divide(new BigDecimal("360"), 18, BigDecimal.ROUND_HALF_UP).doubleValue();
             offsetValue = new BigDecimal(equatorial_circumference).multiply(new BigDecimal(cosValue)).multiply(new BigDecimal(doubleValue));
         }
-        return offsetValue;
+        double number = offsetValue.doubleValue();
+        DecimalFormat decimalFormat = new DecimalFormat("#.00");
+        String result = decimalFormat.format(number);
+        return new BigDecimal(result);
     }
 
     /**
@@ -198,7 +202,7 @@ public class CommonService {
     public BigDecimal computeOriginalOffset(String value, String itemName, KwsDeviceReference deviceRelation) {
         BigDecimal offsetValue = new BigDecimal("0.00");
         if (DictItemEnum.ALTITUDE_Z.getValue().equals(itemName)) {
-            offsetValue = new BigDecimal(value).divide(new BigDecimal(1000), 9, BigDecimal.ROUND_HALF_UP);
+            offsetValue = new BigDecimal(value).divide(new BigDecimal(1000), 18, BigDecimal.ROUND_HALF_UP);
         }
         BigDecimal subtract = new BigDecimal(value).subtract((deviceRelation == null ? new BigDecimal("0.00") : deviceRelation.getOriginalValue()));
         if (DictItemEnum.LATITUDE_Y.getValue().equals(itemName)) {
@@ -216,7 +220,7 @@ public class CommonService {
                 angleInRadians = deviceReference.getOriginalValue().doubleValue();
             }
             double cosValue = Math.cos(Math.toRadians(angleInRadians));
-            double doubleValue = subtract.divide(new BigDecimal("360"), 9, BigDecimal.ROUND_HALF_UP).doubleValue();
+            double doubleValue = subtract.divide(new BigDecimal("360"), 18, BigDecimal.ROUND_HALF_UP).doubleValue();
             offsetValue = new BigDecimal(equatorial_circumference).multiply(new BigDecimal(cosValue)).multiply(new BigDecimal(doubleValue));
         }
         return offsetValue;
@@ -231,14 +235,19 @@ public class CommonService {
      * @param deviceRelation
      * @return
      */
-    public BigDecimal getValueByOffset(String value, String itemName, KwsDeviceReference deviceRelation) {
+    public BigDecimal getValueByOffset(String value, String itemName, KwsDeviceReference deviceRelation,String snCode) {
         BigDecimal offsetValue = new BigDecimal("0.00");
         if (DictItemEnum.ALTITUDE_Z.getValue().equals(itemName)) {
             offsetValue = new BigDecimal(value).multiply(new BigDecimal(1000));
         }
         //BigDecimal subtract = new BigDecimal(value).subtract((deviceRelation == null ? new BigDecimal("0.00") : deviceRelation.getCurrentValue()));
         if (DictItemEnum.LATITUDE_Y.getValue().equals(itemName)) {
-            offsetValue = new BigDecimal(value).divide(new BigDecimal(equatorial_circumference)).add(new BigDecimal(deviceRelation.getCurrentValue().toString()));
+            SlopeData slopeData = slopeDataMapper.selectListByLine(snCode, DictItemEnum.LATITUDE_Y.getValue());
+            String currentY = "0";
+            if (!Objects.isNull(slopeData)) {
+                currentY = slopeData.getVal();
+            }
+            offsetValue = new BigDecimal(currentY).subtract(new BigDecimal(value).divide(new BigDecimal(LATITUDE_REFERENCE), 18, BigDecimal.ROUND_HALF_UP));
         }
         double angleInRadians = 0;
         if (DictItemEnum.LONGITUDE_X.getValue().equals(itemName)) {
@@ -254,8 +263,13 @@ public class CommonService {
             double cosValue = Math.cos(Math.toRadians(angleInRadians));
             BigDecimal doubleValue = new BigDecimal(value).multiply(new BigDecimal(360));//offset*360
             BigDecimal offsetValue1 = new BigDecimal(equatorial_circumference).multiply(new BigDecimal(cosValue));// L*cos(A)
-            BigDecimal xTmp = doubleValue.divide(offsetValue1, 9, BigDecimal.ROUND_HALF_UP);//除法
-            offsetValue = xTmp.add(new BigDecimal(deviceRelation.getCurrentValue().toString()));//加
+            BigDecimal xTmp = doubleValue.divide(offsetValue1, 18, BigDecimal.ROUND_HALF_UP);
+            SlopeData slopeData = slopeDataMapper.selectListByLine(snCode, DictItemEnum.LONGITUDE_X.getValue());
+            String currentX = "0";
+            if (!Objects.isNull(slopeData)) {
+                currentX = slopeData.getVal();
+            }
+            offsetValue = new BigDecimal(currentX).subtract(xTmp);//
         }
         return offsetValue;
     }
@@ -287,7 +301,7 @@ public class CommonService {
             double angleInRadians = Double.parseDouble(y.get(1).getVal());
             double cosValue =Math.cos(Math.toRadians(angleInRadians));
 
-            double doubleValue = subtract.divide(new BigDecimal("360"), 9, BigDecimal.ROUND_HALF_UP).doubleValue();
+            double doubleValue = subtract.divide(new BigDecimal("360"), 18, BigDecimal.ROUND_HALF_UP).doubleValue();
             offsetValue = new BigDecimal(equatorial_circumference).multiply(new BigDecimal(cosValue)).multiply(new BigDecimal(doubleValue));
         }
         if (DictItemEnum.LATITUDE_Y.getValue().equals(inter.getPartNames())) {
@@ -353,7 +367,7 @@ public class CommonService {
                 if (y.size() > 0) {
                     double angleInRadians = Double.parseDouble(y.get(0).getVal());
                     double cosValue = Math.cos(Math.toRadians(angleInRadians));
-                    double doubleValue = subtract.divide(new BigDecimal("360"), 9, BigDecimal.ROUND_HALF_UP).doubleValue();
+                    double doubleValue = subtract.divide(new BigDecimal("360"), 18, BigDecimal.ROUND_HALF_UP).doubleValue();
                     offsetValue = new BigDecimal(equatorial_circumference).multiply(new BigDecimal(cosValue)).multiply(new BigDecimal(doubleValue));
                 }
             }

+ 47 - 2
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/service/DeviceService.java

@@ -3,6 +3,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.dynamic.datasource.annotation.DSTransactional;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.github.pagehelper.PageHelper;
@@ -735,7 +736,7 @@ public class DeviceService {
         return HttpResult.ok(mapList);
     }
 
-    @Transactional
+    @DSTransactional
     public HttpResult referenceEdit(DeviceReferenceAdd deviceReference, HttpServletRequest response) {
 
         HeaderData headerData = commonService.getHeaderData(response);
@@ -745,8 +746,24 @@ public class DeviceService {
         JSONArray array = JSON.parseArray(listData);
         LocalDateTime now = LocalDateTime.now();
         BigDecimal zero = new BigDecimal("0");
+        KwsDevice deviceHas = deviceMapper.selectOne(new LambdaQueryWrapper<KwsDevice>()
+                .eq(KwsDevice::getId, deviceId));
+        String logDesc = "";
+        Integer isHas = 0;
+        Map<String, SystemDict> modelPart = commonService.getDictList(null, new HashMap<>() {{
+            put("code", DictEnum.MODEL_PART.getCodeType());
+            put("type", "1");
+        }});
+
         for (Object object : array) {
             JSONObject obj = (JSONObject) object;
+            if(modelPart.containsKey(obj.get("item"))){
+                logDesc += modelPart.get(obj.get("item")).getLabel()+ ":" +obj.get("value")+",";
+            }else{
+                logDesc += obj.get("item")+ ":" +obj.get("value")+",";
+            }
+
+
             KwsDeviceReference reference = deviceReferenceMapper.selectOne(new LambdaQueryWrapper<KwsDeviceReference>()
                     .eq(KwsDeviceReference::getMountainId, headerData.getMountainId())
                     .eq(KwsDeviceReference::getDeviceId, deviceId)
@@ -763,6 +780,7 @@ public class DeviceService {
                 kwsDeviceReference.setCurrentValue(value);
                 kwsDeviceReference.setValue(value);
             } else {
+                isHas = 1;
                 //如果有数据,则先删除原有数据。
                 deviceReferenceMapper.update(null, new LambdaUpdateWrapper<KwsDeviceReference>()
                         .eq(KwsDeviceReference::getMountainId, headerData.getMountainId())
@@ -781,7 +799,8 @@ public class DeviceService {
                     kwsDeviceReference.setValue(reference.getCurrentValue());
 
                 } else {
-                    BigDecimal currentValue = commonService.getValueByOffset(value.toString(), obj.get("item").toString(), reference);
+
+                    BigDecimal currentValue = commonService.getValueByOffset(value.toString(), obj.get("item").toString(), reference,deviceHas.getSnCode());
                     kwsDeviceReference.setValue(reference.getCurrentValue());
                     kwsDeviceReference.setOffset(value);
                     kwsDeviceReference.setCurrentValue(currentValue);//原始位置+偏移的坐标
@@ -807,6 +826,32 @@ public class DeviceService {
                 .eq(KwsDevice::getId, deviceId)
                 .set(KwsDevice::getStatus, NumberConstant.FOUR)
         );
+        //获取新增设备的型号
+        Map<String, Object> logMap = new HashMap<>(NumberConstant.SIXTEEN);
+        logMap.put("name", deviceHas.getName());
+        logMap.put("desc", logDesc);
+        logMap.put("projectName", "");
+        //List<DeviceVo> list = deviceMapper.selectProjectByDeviceId(String.valueOf(deviceId));
+        KwsProjectDevice device = projectDeviceMapper.selectOne(new LambdaQueryWrapper<KwsProjectDevice>()
+                .eq(KwsProjectDevice::getDeviceId, deviceId)
+                .eq(KwsProjectDevice::getDelFlag,NumberConstant.ZERO)
+                .last("LIMIT 1")
+                .orderByDesc(KwsProjectDevice::getCreateTime));
+
+        if(Objects.nonNull(device)){
+            KwsProject project = projectMapper.selectOne(new LambdaQueryWrapper<KwsProject>()
+                    .eq(KwsProject::getId, device.getProjectId())
+                    .eq(KwsProject::getDelFlag,NumberConstant.ZERO));
+
+            logMap.put("projectName", project.getName());
+        }
+
+        if(isHas == 1){
+            commonService.insertLog(MessageLogEnum.REFERENCE_EDIT, headerData, logMap, Long.parseLong(headerData.getUpdateBy()));
+        }else{
+            commonService.insertLog(MessageLogEnum.REFERENCE_ADD, headerData, logMap, Long.parseLong(headerData.getUpdateBy()));
+        }
+
 
         return HttpResult.ok();
     }

+ 59 - 10
slope-modules/slope-detection/src/main/resources/bootstrap-sky.yml

@@ -1,13 +1,27 @@
 spring:
-  application:
-    name: slope-detection
+  datasource:
+    dynamic:
+      primary: master #设置默认的数据源或者数据源组,默认值即为master
+      strict: false #严格匹配数据源,默认false. true未匹配到指定数据源时抛异常,false使用默认数据源
+      datasource:
+        master:
+          url: jdbc:mysql://10.10.10.230:3306/sckw_slope?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=GMT%2B8
+          username: sckw_dev
+          password: Yy123...
+          driver-class-name: com.mysql.jdbc.Driver # 3.2.0开始支持SPI可省略此配置
+        td:
+          url: jdbc:TAOS-RS://10.10.10.221:6041/devicesV2?charset=UTF-8&locale=en_US.UTF-8&timezone=UTC-8
+          username: root
+          password: taosdata
+          driver-class-name: com.taosdata.jdbc.rs.RestfulDriver
+          pool-name: Data_trans_HikariCP
   cloud:
     nacos:
       discovery:
         # 服务注册地址
         server-addr: 10.10.10.230:8848
         # 命名空间
-        namespace: slope-manage-service-sky
+        namespace: slope-manage-service-lfdc
         # 共享配置
         group: slope-manage-service
       config:
@@ -16,7 +30,7 @@ spring:
         # 配置文件格式
         file-extension: yaml
         # 命名空间
-        namespace: slope-manage-service-sky
+        namespace: slope-manage-service-lfdc
         # 共享配置
         group: slope-manage-service
         #可以读多个配置文件  需要在同一个命名空间下面可以是不同的组
@@ -30,15 +44,16 @@ mqtt:
     #完成超时时间
     completionTimeout: 3000
     #通过mqtt发送消息验证所需用户名
-    username: test
+    username: admin
+    port: 1883
     #通过mqtt发送消息验证所需密码
-    password: test
+    password: public..
     #连接的mqtt地址
-    url: tcp://10.10.10.225:1883
+    url: tcp://10.10.10.108
     #客户端id
-    clientId: mqttx_12411c5cec
+    clientId: mqttx_111222333
     #推送主题  后面跟着#是监控下面所有的话题
-    topic: slope
+    topic: system/iot/device_data_slope/#
     #topic: my-test
     # 会话心跳时间
     keepAliveInterval: 20
@@ -48,4 +63,38 @@ mqtt:
     keepalive: 20
   # 要消费的topic配置
   receive:
-    topic: slopePush/slopePull/test/out,test,slope,sharjeck/ai/test/out
+    topic: slopePush/slopePull/test/out,test,slope,sharjeck/ai/test/out,system/iot/original_data_slope,system/iot/device_data_slope,system/iot/deviceDataSlopeDemo
+  isConsume: false
+OkHttpClit:
+  url: http://10.10.10.185:9501
+## 订阅发布使用
+##ENMQX_HOST=10.10.10.108
+#ENMQX_PORT=1883
+#ENMQX_USERNAME=admin
+#ENMQX_PASSWORD=public..
+#
+##http:发布与订阅/api/v5/publish
+#ENMQX_API_HOST=http://10.10.10.108:18083
+#ENMQX_API_USERNAME=7dd9f635e3eddfca
+#ENMQX_API_PASSWORD=Z9A7kzHsICN5QRG9B8NTodceliwgh9AD9Bg6v4l9CXF1wL1B
+
+
+#oss上传
+aliyun:
+  oss:
+    endpoint: oss-cn-chengdu.aliyuncs.com
+    accessKeyId: LTAI5tPEbubCGq5Rdwygbz4Q
+    secret: 7mQLWMaBJeZPRV1SRGogctYGXwppjQ
+    bucket: kaiwu-saas
+scheduled:
+  template:
+    enable: false
+  device:
+    enable: false
+
+mybatis-plus:
+  #  mapper-locations: classpath*:/mapper/*/*.xml    #扫描xml文件
+  #  #实体扫描,多个package用逗号或者分号分隔
+  #  typeAliasesPackage: com.sckw.*.model.dos.mysql,com.sckw.*.model.dos.tdengine
+  configuration:
+    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl

+ 1 - 1
slope-modules/slope-detection/src/main/resources/bootstrap.yml

@@ -6,7 +6,7 @@ spring:
     name: slope-detection
 #    name: slope-detection
   profiles:
-    active: lfdc
+    active: sky
     #active: ${DEPLOY_MODE:dev}
   main:
     allow-bean-definition-overriding: true

+ 7 - 0
slope-modules/slope-detection/src/main/resources/mapper/mysql/KwsDeviceMapper.xml

@@ -39,6 +39,13 @@
       where del_flag = 0
         and id = #{id,jdbcType=BIGINT}
   </select>
+
+    <select id="selectProjectByDeviceId" parameterType="java.lang.Long" resultMap="BaseResultMap">
+        <!--@mbg.generated-->
+        select * from kws_project as p inner join kws_project_device as d on p.id=d.project_id WHERE
+        p.del_flag=0 and d.del_flag=0 and d.device_id=#{deviceId,jdbcType=BIGINT} order by d.create_time desc limit 1
+    </select>
+
   <select id="selectByDeviceParam" resultType="com.sckw.slope.detection.model.vo.DeviceVo">
       select DISTINCT d.id,
              d.name,

+ 4 - 4
slope-modules/slope-detection/src/main/resources/mapper/tdengine/SlopeDataMapper.xml

@@ -38,13 +38,13 @@
         line,
         val
     </sql>
+
     <select id="selectListByLine" resultType="com.sckw.slope.detection.model.dos.tdengine.SlopeData">
         SELECT
         <include refid="Base_List">
         </include>
-        FROM devicesv2.device_#{snCode}
-        where line = #{item}
-        order by ts desc limit 1
+        FROM devicesv2.device_${snCode}
+        where line = #{item} order by ts desc limit 1
     </select>
 
     <select id="selectListByTwoLine" resultType="com.sckw.slope.detection.model.dos.tdengine.SlopeData">
@@ -97,7 +97,7 @@
         SELECT
         <include refid="Base_List">
         </include>
-        FROM devicesv2.device_#{snCode}
+        FROM devicesv2.device_${snCode}
         where  raw_ts &gt;= #{dateStart} and raw_ts &lt;= #{dateEnd}
 
         <if test="parts != null">