lengfaqiang 2 лет назад
Родитель
Сommit
069b4a988f

+ 4 - 12
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/dao/tdengine/OriginalMapper.java

@@ -1,8 +1,10 @@
 package com.sckw.slope.detection.dao.tdengine;
 
 import com.baomidou.dynamic.datasource.annotation.DS;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.sckw.slope.detection.model.dos.tdengine.Original;
 import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
 import org.springframework.stereotype.Repository;
 
 import java.util.Date;
@@ -10,16 +12,6 @@ import java.util.Date;
 @DS("td")
 @Mapper
 @Repository
-public interface OriginalMapper {
-    int deleteByPrimaryKey(Date ts);
-
-    int insert(Original record);
-
-    int insertSelective(Original record);
-
-    Original selectByPrimaryKey(Date ts);
-
-    int updateByPrimaryKeySelective(Original record);
-
-    int updateByPrimaryKey(Original record);
+public interface OriginalMapper extends BaseMapper<Original> {
+    Original selectByData(@Param("rawTs") Date rawTs);
 }

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

@@ -147,6 +147,42 @@ public class CommonService {
         return offsetValue;
     }
 
+    /**
+     * 计算xyz值的偏移量  当前只用于计算偏移数据的offset
+     *
+     * @param value
+     * @param itemName
+     * @param deviceRelation
+     * @return
+     */
+    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);
+        }
+        BigDecimal subtract = new BigDecimal(value).subtract((deviceRelation == null ? new BigDecimal("0.00") : deviceRelation.getOriginalValue()));
+        if (DictItemEnum.LATITUDE_Y.getValue().equals(itemName)) {
+            offsetValue = new BigDecimal(equatorial_circumference).multiply(subtract);
+        }
+        double angleInRadians = 0;
+        if (DictItemEnum.LONGITUDE_X.getValue().equals(itemName)) {
+            KwsDeviceReference deviceReference = deviceReferenceMapper.selectOne(new LambdaQueryWrapper<KwsDeviceReference>()
+                    .eq(KwsDeviceReference::getDeviceId, deviceRelation.getDeviceId())
+                    .eq(KwsDeviceReference::getType, NumberConstant.ONE)
+                    .eq(KwsDeviceReference::getDelFlag, NumberConstant.ZERO)
+                    .eq(KwsDeviceReference::getItem, DictItemEnum.LATITUDE_Y.getValue())
+            );
+            if (deviceReference != null) {
+                angleInRadians = deviceReference.getOriginalValue().doubleValue();
+            }
+            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));
+        }
+        return offsetValue;
+    }
+
+
     /**
      *  根据偏移量,返回测量值
      *

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

@@ -506,7 +506,12 @@ public class DeviceService {
                 if (insTables == null) {
                     insTablesMapper.createTable("devicesv2" + snCode);
                 }
-                SlopeData slopeData = slopeDataMapper.selectListByLine(snCode, item);
+                SlopeData slopeData = null;
+                try {
+                    slopeData = slopeDataMapper.selectListByLine(snCode, item);
+                } catch (Exception e) {
+                    log.error("select tdengine devices error :{}",e.getMessage(),e);
+                }
                 String val = slopeData == null ? null : slopeData.getVal();
                 //存在经度纬度海拔等要素 要进行公式计算
                 /**
@@ -521,7 +526,12 @@ public class DeviceService {
                 if (itemList.contains(re.getItem())) {
                     BigDecimal offsetValue = new BigDecimal("0.00");
                     if (Objects.nonNull(currentValue)) {
-                        SlopeData selected = slopeDataMapper.selectListByLine(kwsDevice.getSnCode(), "2");
+                        SlopeData selected = null;
+                        try {
+                            selected = slopeDataMapper.selectListByLine(kwsDevice.getSnCode(), DictItemEnum.LATITUDE_Y.getValue());
+                        } catch (Exception e) {
+                            log.error("select tdengine devices error :{}",e.getMessage(),e);
+                        }
                         double angleInRadians = Math.toRadians(selected == null ? 0L : Double.parseDouble(selected.getVal()));
                         double cosValue = Math.cos(angleInRadians);
                         if (org.apache.commons.lang3.StringUtils.isNotBlank(val)) {

+ 42 - 17
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/service/KwsAlarmService.java

@@ -7,12 +7,15 @@ import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageInfo;
 import com.sckw.core.exception.BusinessException;
 import com.sckw.core.model.enums.DictEnum;
+import com.sckw.core.model.enums.DictItemEnum;
 import com.sckw.core.model.page.PageRes;
 import com.sckw.core.model.vo.BaseList;
 import com.sckw.core.model.vo.PublicBaseList;
 import com.sckw.core.web.response.HttpResult;
 import com.sckw.slope.detection.dao.mysql.*;
+import com.sckw.slope.detection.dao.tdengine.DevicesMapper;
 import com.sckw.slope.detection.model.dos.mysql.*;
+import com.sckw.slope.detection.model.dos.tdengine.Devices;
 import com.sckw.slope.detection.model.dto.HeaderData;
 import com.sckw.slope.detection.model.dto.SystemDict;
 import com.sckw.slope.detection.model.param.AlarmLogThresholdQuery;
@@ -65,6 +68,9 @@ public class KwsAlarmService {
     @Autowired
     KwsAlarmMapper alarmMapper;
 
+    @Autowired
+    DevicesMapper devicesMapper;
+
     public PageRes logSelectAll(AlarmLogThresholdQuery query) {
         PageHelper.startPage(query.getPage(), query.getPageSize());
 //        List<KwsAlarm> kwsAlarms = alarmMapper.selectList(new LambdaQueryWrapper<KwsAlarm>()
@@ -270,23 +276,42 @@ public class KwsAlarmService {
                     .eq(KwsDeviceReference::getDeviceId, deviceId)
                     .eq(KwsDeviceReference::getItem, itemName)
             );
-            if (deviceReference != null) {
-                vo.setAlarmId(kwsAlarm.getId().toString());
-                vo.setAlarmDetailId(id);
-                vo.setDeviceId(deviceId.toString());
-                vo.setItemName(itemName);
-                vo.setCurrentValue(deviceReference.getCurrentValue());
-                vo.setCurrentOffset(deviceReference.getOffset());
-                vo.setOriginalValue(deviceReference.getOriginalValue());
-                vo.setOriginalOffset(new BigDecimal("0.00"));
-                KwsDeviceReference lastDeviceReference = deviceReferenceMapper.selectOne(new LambdaQueryWrapper<KwsDeviceReference>()
-                        .eq(KwsDeviceReference::getDelFlag, 1)
-                        .eq(KwsDeviceReference::getDeviceId, deviceId)
-                        .eq(KwsDeviceReference::getItem, itemName)
-                        .orderByDesc(KwsDeviceReference::getUpdateTime)
-                        .last("limit 1")
-                );
-                vo.setLastReferenceValue(lastDeviceReference == null ? null : lastDeviceReference.getCurrentValue());
+            KwsDevice device = deviceMapper.selectById(deviceId);
+            if (device == null) {
+                return HttpResult.ok(vo);
+            }
+            List<String> list = new ArrayList<>();
+            list.add(DictItemEnum.LONGITUDE_X.getValue());
+            list.add(DictItemEnum.LATITUDE_Y.getValue());
+            list.add(DictItemEnum.ALTITUDE_Z.getValue());
+            Devices devices = null;
+            try {
+                devices = devicesMapper.selectLastDataByCodeAndItemName(device.getSnCode(),kwsThreshold.getItemName());
+            } catch (Exception e) {
+                log.error("select tdengine device error :{}", e.getMessage(), e);
+//                throw new RuntimeException(e);
+            }
+            vo.setAlarmId(kwsAlarm.getId().toString());
+            vo.setAlarmDetailId(id);
+            vo.setDeviceId(deviceId.toString());
+            vo.setItemName(itemName);
+            vo.setLastReferenceValue(deviceReference == null ? null : deviceReference.getCurrentValue());
+            if (devices != null) {
+                String val = devices.getVal();
+                if (list.contains(itemName)){
+                    if (deviceReference != null) {
+                        BigDecimal computeOffset = commonService.computeOffset(val, kwsThreshold.getItemName(), deviceReference);
+                        BigDecimal computeOriginalOffset = commonService.computeOriginalOffset(val, kwsThreshold.getItemName(), deviceReference);
+                        vo.setCurrentValue(deviceReference.getCurrentValue());
+                        vo.setCurrentOffset(computeOffset);
+                        vo.setOriginalValue(deviceReference.getOriginalValue());
+                        vo.setOriginalOffset(computeOriginalOffset);
+                    }
+                }else {
+                    vo.setCurrentValue(deviceReference.getCurrentValue());
+                    vo.setOriginalValue(deviceReference.getOriginalValue());
+                }
+
             }
         }
         Map<String, SystemDict> levelDict = commonService.getDictByDictCode(DictEnum.THRESHOLD_LEVEL);

+ 19 - 5
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/service/LogService.java

@@ -8,8 +8,11 @@ import com.sckw.core.model.page.PageRes;
 import com.sckw.core.model.page.PageResult;
 import com.sckw.core.web.response.HttpResult;
 import com.sckw.slope.detection.dao.mysql.KwsLogMapper;
+import com.sckw.slope.detection.dao.tdengine.DevicesMapper;
+import com.sckw.slope.detection.dao.tdengine.OriginalMapper;
 import com.sckw.slope.detection.dao.tdengine.SlopeDataMapper;
 import com.sckw.slope.detection.model.dos.mysql.KwsLog;
+import com.sckw.slope.detection.model.dos.tdengine.Original;
 import com.sckw.slope.detection.model.param.ProjectLogQuery;
 import com.sckw.slope.detection.model.vo.LogSelectVO;
 import com.sckw.slope.detection.model.vo.SlopeDataVo;
@@ -21,10 +24,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.util.CollectionUtils;
 
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 import java.util.stream.Collectors;
 
 /**
@@ -46,7 +46,9 @@ public class LogService {
         PageHelper.startPage(query.getPage(), query.getPageSize());
         List<KwsLog> kwsLogs = logMapper.selectList(new LambdaQueryWrapper<KwsLog>()
                 .eq(StringUtils.isNotBlank(query.getType()), KwsLog::getType, query.getType())
-                .like(StringUtils.isNotBlank(query.getContent()), KwsLog::getContent, query.getContent()));
+                .like(StringUtils.isNotBlank(query.getContent()), KwsLog::getContent, query.getContent())
+                .orderByDesc(KwsLog::getCreateTime)
+        );
         PageInfo<KwsLog> info = new PageInfo<>(kwsLogs);
         if (CollectionUtils.isEmpty(kwsLogs)) {
             return PageRes.build(info, kwsLogs);
@@ -78,6 +80,12 @@ public class LogService {
         return HttpResult.ok(returnList);
     }
 
+    @Autowired
+    DevicesMapper devicesMapper;
+
+    @Autowired
+    OriginalMapper originalMapper;
+
     public PageResult selectMetadata(Integer page, Integer pageSize, HttpServletRequest request) {
         Integer newPage = (page - 1) * pageSize;
         List<SlopeDataVo> list = slopeDataMapper.selectListByMaster(newPage, pageSize);
@@ -86,6 +94,12 @@ public class LogService {
         if (!CollectionUtils.isEmpty(listByMasterCount)) {
             count = listByMasterCount.stream().count();
         }
+        if (!CollectionUtils.isEmpty(list)) {
+            for (SlopeDataVo slopeDataVo : listByMasterCount) {
+                Date rawId = slopeDataVo.getRawId();
+                Original original = originalMapper.selectByData(rawId);
+            }
+        }
         PageResult build = PageResult.build(page, pageSize, count, list);
         return build;
     }

+ 33 - 4
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/service/ProjectService.java

@@ -239,10 +239,19 @@ public class ProjectService {
 
     public HttpResult monitorItem(String id, HttpServletRequest request) {
         String companyId = commonService.getHeaderData(request).getCompanyId();
+        Map<String, SystemDict> modelTypeDict = commonService.getDictByDictCode(DictEnum.MODEL_PART);
         //查询基本要素
         List<BaseItemDTO> baseItem = projectDeviceMapper.selectDataByProjectId(Long.parseLong(id));
         List<IntegrationItemVO> integrationItem = projectDeviceMapper.selectIntegrationItemByProjectId(Long.parseLong(id));
         JSONObject jsonObject = new JSONObject();
+        if (!CollectionUtils.isEmpty(baseItem)) {
+            for (BaseItemDTO baseItemDTO : baseItem) {
+                baseItemDTO.setPartName(baseItemDTO.getPartName() == null ? null :
+                        (modelTypeDict == null ? baseItemDTO.getPartName() :
+                                (modelTypeDict.get(baseItemDTO.getPartName()) == null ? baseItemDTO.getPartName() :
+                                        (modelTypeDict.get(baseItemDTO.getPartName()).getLabel()))));
+            }
+        }
         jsonObject.put("baseItem", baseItem);
         jsonObject.put("integrationItem", integrationItem);
         return HttpResult.ok(jsonObject);
@@ -589,7 +598,12 @@ public class ProjectService {
                             Date date = new Date();
                             String dateStart = DateUtil.getDateTimeToHour(date, 24);
                             String dateEnd = DateUtil.localDateTimeFormat(LocalDateTime.now());
-                            List<SlopeData> selected = slopeDataMapper.selectLineList(kwsDevice.getSnCode(), item, dateStart, dateEnd);
+                            List<SlopeData> selected = null;
+                            try {
+                                selected = slopeDataMapper.selectLineList(kwsDevice.getSnCode(), item, dateStart, dateEnd);
+                            } catch (Exception e) {
+                                log.error("select tdengine devices error :{}", e.getMessage(), e);
+                            }
                             List<Map<String, Object>> mapList = new ArrayList<>();
                             if (!CollectionUtils.isEmpty(selected)) {
                                 for (int i = 0; i < selected.size(); i++) {
@@ -711,7 +725,12 @@ public class ProjectService {
                     for (int i = 0; i < dateList.size(); i++) {
                         String dateStart = DateUtil.getDateTimeToHour(dateList.get(i), 24);
                         String dateEnd = DateUtil.localDateTimeFormat(LocalDateTime.now());
-                        List<SlopeData> selected = slopeDataMapper.selectLineList(kwsDevice.getSnCode(), partName, dateStart, dateEnd);
+                        List<SlopeData> selected = null;
+                        try {
+                            selected = slopeDataMapper.selectLineList(kwsDevice.getSnCode(), partName, dateStart, dateEnd);
+                        } catch (Exception e) {
+                            log.error("select tdengine devices error :{}", e.getMessage(), e);
+                        }
                         if (!CollectionUtils.isEmpty(selected)) {
                             for (SlopeData message : selected) {
                                 BigDecimal offsetValue = new BigDecimal("0.00");
@@ -867,7 +886,12 @@ public class ProjectService {
                             } catch (Exception e) {
                                 continue;
                             }
-                            List<SlopeData> selected = slopeDataMapper.selectLineList(kwsDevice.getSnCode(), item, dateStart, dateEnd);
+                            List<SlopeData> selected = null;
+                            try {
+                                selected = slopeDataMapper.selectLineList(kwsDevice.getSnCode(), item, dateStart, dateEnd);
+                            } catch (Exception e) {
+                                log.error("select tdengine devices error :{}", e.getMessage(), e);
+                            }
                             List<Map<String, Object>> mapList = new ArrayList<>();
                             if (!CollectionUtils.isEmpty(selected)) {
                                 for (int i = 0; i < selected.size(); i++) {
@@ -1008,7 +1032,12 @@ public class ProjectService {
                     Date date = new Date();
                     String dateStart = DateUtil.getDateTimeToHour(date, 24);
                     String dateEnd = DateUtil.localDateTimeFormat(LocalDateTime.now());
-                    List<SlopeData> selected = slopeDataMapper.selectLineList(kwsDevice.getSnCode(), partName, dateStart, dateEnd);
+                    List<SlopeData> selected = null;
+                    try {
+                        selected = slopeDataMapper.selectLineList(kwsDevice.getSnCode(), partName, dateStart, dateEnd);
+                    } catch (Exception e) {
+                        log.error("select tdengine devices error :{}", e.getMessage(), e);
+                    }
                     if (!CollectionUtils.isEmpty(selected)) {
                         for (SlopeData message : selected) {
                             BigDecimal offsetValue = new BigDecimal("0.00");

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

@@ -231,7 +231,7 @@
                 and b.mountain_id = #{mountainId}
             </if>
             <if test="level != null and level != ''">
-                and a.level = #{level}
+                and b.level = #{level}
             </if>
         </where>
         ) t

+ 8 - 0
slope-modules/slope-detection/src/main/resources/mapper/tdengine/OriginalMapper.xml

@@ -77,4 +77,12 @@
       guid = #{guid,jdbcType=VARCHAR}
     where ts = #{ts,jdbcType=TIMESTAMP}
   </update>
+
+  <select id="selectByData" resultMap="BaseResultMap">
+      SELECT
+      <include refid="Base_Column_List">
+      </include>
+      FROM devicesv2.original_${deviceCode}
+      order by ts desc limit 1
+    </select>
 </mapper>

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

@@ -70,7 +70,7 @@
         SELECT
         <include refid="Base_List">
         </include>
-        FROM devicesv2.device_#{snCode}
+        FROM devicesv2.device_${snCode}
         where line = #{item} and ts &gt;= #{dateStart} and ts &lt;= #{dateEnd} order by ts desc
     </select>