15928045575 2 лет назад
Родитель
Сommit
d224263a12

+ 2 - 2
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/controller/backTrackController.java

@@ -53,9 +53,9 @@ public class backTrackController {
     @Log(description = "返回设备折线图")
     //@RepeatSubmit(interval = 3000, message = "两次请求间隔未超过3秒")
     @RequestMapping(name = "返回设备折线图", value = "/getDeviceChart", method = RequestMethod.GET)
-    public HttpResult getDeviceChart(@RequestParam("deviceId") String deviceId,@RequestParam("snCode") String snCode, @RequestParam("part") String part, @RequestParam("dateStart") String dateStart, @RequestParam("dateEnd") String dateEnd, @RequestParam("original") Integer original) throws ParseException {
+    public HttpResult getDeviceChart(@RequestParam("deviceId") String deviceId,@RequestParam("snCode") String snCode, @RequestParam("part") String part, @RequestParam("dateStart") String dateStart, @RequestParam("dateEnd") String dateEnd, @RequestParam("original") Integer original, HttpServletRequest request) throws ParseException {
         log.info("返回设备折线图 getDeviceChart param :{},part:{}",deviceId,part);
-        return backTrackService.getDeviceChart(deviceId,snCode,part,dateStart,dateEnd,original);
+        return backTrackService.getDeviceChart(deviceId,snCode,part,dateStart,dateEnd,original,request);
     }
 
 

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

@@ -30,4 +30,6 @@ public interface KwsIntegrationMapper extends BaseMapper<KwsIntegration> {
     List<IntegrationItemVO> getDataByFindInSet(String partNames);
 
     List<IntegrationVo> getDataByName(@Param("integrationQuery") IntegrationQuery integrationQuery);
+
+    List<IntegrationVo> getDataByInNames(@Param("mountainId") String  mountainId,@Param("integrationName") String[]  integrationName);
 }

+ 3 - 1
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/dao/tdengine/SlopeDataMapper.java

@@ -30,9 +30,11 @@ public interface SlopeDataMapper extends BaseMapper<SlopeData> {
 
     List<SlopeData> selectListByTwoLine(@Param("snCode") String snCode,@Param("item") String item);
 
+    List<SlopeData> selectListLineByMsgId(@Param("snCode") String snCode,@Param("item") String item,@Param("msgId") String msgId);
+
     List<SlopeData> selectLineList(@Param("snCode") String snCode, @Param("item") String item, @Param("dateStart") String dateStart, @Param("dateEnd") String dateEnd);
 
-    List<SlopeData> selectLineListByArray(@Param("snCode") String snCode, @Param("parts") String[] parts, @Param("dateStart") String dateStart, @Param("dateEnd") String dateEnd);
+    List<SlopeData> selectLineListByArray(@Param("snCode") String snCode, @Param("parts") Object parts, @Param("dateStart") String dateStart, @Param("dateEnd") String dateEnd);
 
     List<SlopeData> selectLineListByList(@Param("snCode") String snCode, @Param("parts") List<String> parts, @Param("dateStart") String dateStart, @Param("dateEnd") String dateEnd);
 

+ 27 - 2
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/service/BackTrackService.java

@@ -23,6 +23,7 @@ import com.sckw.slope.detection.model.dto.DeviceDataDTO;
 import com.sckw.slope.detection.model.dto.HeaderData;
 import com.sckw.slope.detection.model.dto.SystemDict;
 import com.sckw.slope.detection.model.param.IntegrationQuery;
+import com.sckw.slope.detection.model.vo.DeviceIntegrationVo;
 import com.sckw.slope.detection.model.vo.IntegrationVo;
 import jakarta.servlet.http.HttpServletRequest;
 import lombok.extern.slf4j.Slf4j;
@@ -63,6 +64,9 @@ public class BackTrackService {
     @Autowired
     KwsDeviceReferenceMapper deviceReferenceMapper;
 
+    @Autowired
+    KwsDeviceIntegrationMapper deviceIntegrationMapper;
+
     @Autowired
     KwsThresholdMapper thresholdMapper;
 
@@ -107,7 +111,7 @@ public class BackTrackService {
         String[] arr = parts.split(",");
         List<String> list = Arrays.asList(arr);
         List<KwsDeviceReference> references = deviceReferenceMapper.selectList(new LambdaQueryWrapper<KwsDeviceReference>()
-                .in(KwsDeviceReference::getId, list)
+                .in(KwsDeviceReference::getItem, list)
                 .in(KwsDeviceReference::getDeviceId, devicesId)
                 .eq(KwsDeviceReference::getDelFlag, NumberConstant.ZERO)
         );
@@ -123,11 +127,14 @@ public class BackTrackService {
         return HttpResult.ok(devices);
     }
 
-    public HttpResult getDeviceChart(String devicesId, String snCode, String parts, String dateStart, String dateEnd, Integer original) throws ParseException {
+    public HttpResult getDeviceChart(String devicesId, String snCode, String parts, String dateStart, String dateEnd, Integer original, HttpServletRequest response) throws ParseException {
         //先查询设备
         KwsDevice deviceHas = deviceMapper.selectOne(new LambdaQueryWrapper<KwsDevice>()
                 .eq(KwsDevice::getSnCode, snCode));
         String[] arr = parts.split(",");
+
+
+
         if (!DeviceEnum.ALREADY_REFERRED_TO.getStatus().equals(deviceHas.getStatus().toString())) {//未基准
             try {
                 InsTables insTables = insTablesMapper.selectTableIsExit("device_" + snCode);
@@ -158,6 +165,15 @@ public class BackTrackService {
 
                 }
             }
+            List<Object> listm =  new ArrayList<>();
+            //首先获取集成要数的数据
+            List<DeviceIntegrationVo> intergData = deviceIntegrationMapper.selectListParamsAndInterNameByDeviceId(Long.parseLong(devicesId));
+            if(Objects.nonNull(intergData)){
+                for (DeviceIntegrationVo listvo : intergData){
+                    listm = commonService.returnIntegrationDataArray(snCode,dateStart,dateEnd,listvo,"rawId","val");
+                    map.put(listvo.getIntegrationName(),listm);
+                }
+            }
             return HttpResult.ok(map);
         }
 
@@ -233,6 +249,15 @@ public class BackTrackService {
             }
             mapList.put(element.getItem(), datemap);
         }
+        List<Object> listm =  new ArrayList<>();
+        //首先获取集成要数的数据
+        List<DeviceIntegrationVo> intergData = deviceIntegrationMapper.selectListParamsAndInterNameByDeviceId(Long.parseLong(devicesId));
+        if(Objects.nonNull(intergData)){
+            for (DeviceIntegrationVo listvo : intergData){
+                listm = commonService.returnIntegrationDataArray(snCode,dateStart,dateEnd,listvo,"time","offset");
+                mapList.put(listvo.getIntegrationName(),listm);
+            }
+        }
         returnData.put("references", references);
         returnData.put("threshold", kwsThresholds);
         returnData.put("chart", mapList);

+ 51 - 0
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/service/CommonService.java

@@ -313,4 +313,55 @@ public class CommonService {
         }
         return map;
     }
+
+    public List<Object> returnIntegrationDataArray(String snCode, String dateStart, String dateEnd,DeviceIntegrationVo listvo,String key1,String key2){
+        //首先获取全部数据
+        String[] partName  = {listvo.getPartNames()};
+        List<SlopeData> selectedData = slopeDataMapper.selectLineListByArray(snCode, partName, dateStart, dateEnd);
+        Map<String, List<Object>> mapList = new HashMap<>();
+        List<Object> listTmp = new ArrayList<>();
+        for(int i=0;i<selectedData.size();i++) {
+            if(i+1>=selectedData.size()){
+                continue;
+            }
+            BigDecimal offsetValue = new BigDecimal("0.00");
+            double offsetRetrun = 0;
+            BigDecimal subtract = new BigDecimal(selectedData.get(i + 1).getVal()).subtract(new BigDecimal(selectedData.get(i).getVal()));
+            Date newD = selectedData.get(i + 1).getTs();
+            Date oldD = selectedData.get(i).getTs();
+            double diff = (newD.getTime() - oldD.getTime()) / (1000 * 60 * 60.0);
+            //判断集成要素
+            if (DictItemEnum.LONGITUDE_X.getValue().equals(listvo.getPartNames())) {
+                //依次获取当前推送的Y轴数据
+                List<SlopeData> y = slopeDataMapper.selectListLineByMsgId(snCode, DictItemEnum.LATITUDE_Y.getValue(),selectedData.get(i).getMsgId());
+                if(y.size()>0){
+                    double angleInRadians = Double.parseDouble(y.get(0).getVal());
+                    double cosValue = Math.cos(angleInRadians);
+                    double doubleValue = subtract.divide(new BigDecimal("360"), 9, BigDecimal.ROUND_HALF_UP).doubleValue();
+                    offsetValue = new BigDecimal(equatorial_circumference).multiply(new BigDecimal(cosValue)).multiply(new BigDecimal(doubleValue));
+                }
+            }
+            if (DictItemEnum.LATITUDE_Y.getValue().equals(listvo.getPartNames())) {
+                offsetValue = new BigDecimal(LATITUDE_REFERENCE).multiply(subtract);
+            }
+            if (DictItemEnum.ALTITUDE_Z.getValue().equals(listvo.getPartNames())) {
+                offsetValue = subtract.divide(new BigDecimal(1000), 9, BigDecimal.ROUND_HALF_UP);
+            }
+            if (listvo.getFormula().equals(String.valueOf(NumberConstant.ONE))) {//加速度(a-a’)/t²   formula=1
+                BigDecimal t = new BigDecimal(diff).multiply(new BigDecimal(diff));
+                offsetRetrun = offsetValue.divide(t, 9, BigDecimal.ROUND_HALF_UP).doubleValue();
+
+            } else if (listvo.getFormula().equals(String.valueOf(NumberConstant.TWO))) {//速度(a-a’)/t    formula=2
+                offsetRetrun = offsetValue.divide(new BigDecimal(diff), 9, BigDecimal.ROUND_HALF_UP).doubleValue();
+            }
+            Map<String ,Object> map = new HashMap();
+            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+            String time = sdf.format(selectedData.get(i + 1).getRawId());
+            map.put(key1,time);
+            map.put(key2,offsetRetrun);
+            listTmp.add(map);
+        }
+        //mapList.put(listvo.getIntegrationName(),listTmp);
+        return listTmp;
+    }
 }

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

@@ -342,7 +342,7 @@ public class DeviceService {
         if (!Objects.isNull(intergData)) {
             for (DeviceIntegrationVo inter : intergData) {
                 List<SlopeData> slopeData = slopeDataMapper.selectListByTwoLine(snCode, inter.getPartNames());//获取到当前测量值--现在只有单一值
-                if (!Objects.isNull(slopeData)) {
+                if (!Objects.isNull(slopeData) && slopeData.size()>0) {
                     double data = commonService.returnIntegrationData(snCode,slopeData,inter);
                     inter.setCurrentData(String.valueOf(data));
                 }

+ 17 - 0
slope-modules/slope-detection/src/main/resources/mapper/mysql/KwsIntegrationMapper.xml

@@ -49,6 +49,23 @@
       </if>
       order by create_time desc
     </select>
+
+  <select id="getDataByInNames" resultType="com.sckw.slope.detection.model.vo.IntegrationVo">
+    <!--@mbg.generated-->
+    select
+    <include refid="Base_Column_List" />
+    from kws_integration
+    where del_flag=0
+    and mountain_id = #{mountainId}
+    <if test="integrationName != null and integrationName != ''">
+      and integration_name in
+      <foreach collection="integrationName" separator="," open="(" close=")" item="Name">
+        #{Name}
+      </foreach>
+    </if>
+    order by create_time desc
+  </select>
+
     <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
     <!--@mbg.generated-->
     delete from kws_integration

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

@@ -56,6 +56,16 @@
         order by ts desc limit 2
     </select>
 
+    <select id="selectListLineByMsgId" resultType="com.sckw.slope.detection.model.dos.tdengine.SlopeData">
+        SELECT
+        <include refid="Base_List">
+        </include>
+        FROM devicesv2.device_#{snCode}
+        where line = #{item}
+        and msg_id = #{msgId}
+        order by ts desc limit 1
+    </select>
+
     <select id="selectListByLineOrderByCreateTime" resultType="com.sckw.slope.detection.model.dos.tdengine.SlopeData">
         SELECT
         <include refid="Base_List">