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

+ 2 - 0
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/dao/tdengine/SlopeDataMapper.java

@@ -28,6 +28,8 @@ public interface SlopeDataMapper extends BaseMapper<SlopeData> {
 
     SlopeData selectListByLine(@Param("snCode") String snCode,@Param("item") String item);
 
+    List<SlopeData> selectListByTwoLine(@Param("snCode") String snCode,@Param("item") String item);
+
     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);

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

@@ -95,5 +95,15 @@ public class DeviceIntegrationVo implements Serializable {
      */
     private String currentData;
 
+    /**
+     *当前测量值
+     */
+    private String partNames;
+
+    /**
+     *公式字典值
+     */
+    private String formula;
+
     private static final long serialVersionUID = 1L;
 }

+ 41 - 5
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/service/CommonService.java

@@ -11,13 +11,16 @@ import com.sckw.core.model.enums.MessageLogEnum;
 import com.sckw.core.model.page.PageRes;
 import com.sckw.core.utils.IdWorker;
 import com.sckw.core.web.response.PhpResult;
+
 import com.sckw.slope.detection.dao.mysql.KwsDeviceReferenceMapper;
 import com.sckw.slope.detection.dao.mysql.KwsDictMapper;
 import com.sckw.slope.detection.dao.mysql.KwsLogMapper;
 import com.sckw.slope.detection.model.dos.mysql.KwsDeviceReference;
 import com.sckw.slope.detection.model.dos.mysql.KwsLog;
+import com.sckw.slope.detection.model.dos.tdengine.SlopeData;
 import com.sckw.slope.detection.model.dto.HeaderData;
 import com.sckw.slope.detection.model.dto.SystemDict;
+import com.sckw.slope.detection.model.vo.DeviceIntegrationVo;
 import com.sckw.slope.detection.model.vo.QueryDictTypePageReqVo;
 import com.sckw.slope.detection.service.api.DetectionApiService;
 import jakarta.servlet.http.HttpServletRequest;
@@ -26,13 +29,10 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.cloud.context.config.annotation.RefreshScope;
 import org.springframework.stereotype.Service;
-
+import com.sckw.slope.detection.dao.tdengine.SlopeDataMapper;
 import java.math.BigDecimal;
 import java.time.LocalDateTime;
-import java.util.Base64;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 
 /**
  * @author lfdc
@@ -59,6 +59,9 @@ public class CommonService {
     @Autowired
     KwsLogMapper logMapper;
 
+    @Autowired
+    SlopeDataMapper slopeDataMapper;
+
     public HeaderData getHeaderData(HttpServletRequest request) {
         /**
          * {"companyId":"198","companyName":"四川金顶集团","createBy":"2","createName":"600678","updateBy":"2","updateName":"600678","mountainId":"198"}
@@ -248,4 +251,37 @@ public class CommonService {
         log.setCreateTime(LocalDateTime.now());
         return logMapper.insert(log);
     }
+
+    //集成要数判断
+    public double returnIntegrationData(String snCode, List<SlopeData> data, DeviceIntegrationVo inter){
+
+        BigDecimal offsetValue = new BigDecimal("0.00");
+        BigDecimal subtract = new BigDecimal(data.get(0).getVal()).subtract(new BigDecimal(data.get(1).getVal()));
+        Date newD = data.get(0).getTs();
+        Date oldD = data.get(1).getTs();
+        double diff = (newD.getTime()-oldD.getTime())/(1000*60*60.0);
+        //判断集成要素
+        if(DictItemEnum.LONGITUDE_X.getValue().equals(inter.getPartNames())){
+            List<SlopeData> y = slopeDataMapper.selectListByTwoLine(snCode, DictItemEnum.LATITUDE_Y.getValue());
+            double angleInRadians = Double.parseDouble(y.get(1).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(inter.getPartNames())) {
+            offsetValue = new BigDecimal(LATITUDE_REFERENCE).multiply(subtract);
+        }
+        if (DictItemEnum.ALTITUDE_Z.getValue().equals(inter.getPartNames())) {
+            offsetValue = subtract.divide(new BigDecimal(1000), 9, BigDecimal.ROUND_HALF_UP);
+        }
+        if(inter.getFormula().equals(String.valueOf(NumberConstant.ONE))){//加速度(a-a’)/t²   formula=1
+            BigDecimal t = new BigDecimal(diff).multiply(new BigDecimal(diff));
+            return offsetValue.divide(t,9, BigDecimal.ROUND_HALF_UP).doubleValue();
+
+        }else if(inter.getFormula().equals(String.valueOf(NumberConstant.TWO))){//速度(a-a’)/t    formula=2
+            return offsetValue.divide(new BigDecimal(diff),9, BigDecimal.ROUND_HALF_UP).doubleValue();
+        }
+        return 0;
+    }
 }

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

@@ -324,7 +324,10 @@ public class DeviceService {
                         .eq(KwsProject::getId, projectDevice.getProjectId().toString())
                         .eq(KwsProject::getDelFlag, NumberConstant.ZERO)
                 );
-                vo.setProjectName(project.getName().toString());
+                if(Objects.nonNull(project)){
+                    vo.setProjectName(project.getName().toString());
+                }
+
             }
             vo.setPart(partData);
         }
@@ -334,13 +337,16 @@ public class DeviceService {
         intergData = deviceIntegrationMapper.selectListByParmsAndInterName(vo);
         if (!Objects.isNull(intergData)) {
             for (DeviceIntegrationVo inter : intergData) {
+                List<SlopeData> slopeData = slopeDataMapper.selectListByTwoLine(snCode, inter.getPartNames());//获取到当前测量值--现在只有单一值
+                if (!Objects.isNull(slopeData)) {
+                    double data = commonService.returnIntegrationData(snCode,slopeData,inter);
+                    inter.setCurrentData(String.valueOf(data));
+                }
                 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());
-                        }
+
                         inter.setIntegrationCurrentBaseData(re.getCurrentValue().toString());
                         inter.setOffset(re.getOffset().toString());
                     }

+ 1 - 1
slope-modules/slope-detection/src/main/resources/mapper/mysql/KwsDeviceIntegrationMapper.xml

@@ -203,7 +203,7 @@
     <select id="selectListByParmsAndInterName" resultType="com.sckw.slope.detection.model.vo.DeviceIntegrationVo">
         <!--@mbg.generated-->
         select
-        d.id,d.integration_id,integration_name,part_names,i.unit
+        d.id,d.integration_id,integration_name,part_names,i.unit,formula
         from kws_device_integration as d
         inner join kws_integration as i on d.integration_id=i.id
         where d.del_flag = 0 and i.del_flag = 0

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

@@ -47,6 +47,15 @@
         order by ts desc limit 1
     </select>
 
+    <select id="selectListByTwoLine" 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 2
+    </select>
+
     <select id="selectListByLineOrderByCreateTime" resultType="com.sckw.slope.detection.model.dos.tdengine.SlopeData">
         SELECT
         <include refid="Base_List">