Ver código fonte

数据查询delfag处理

lengfaqiang 2 anos atrás
pai
commit
3c4d44cd12

+ 5 - 0
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/model/dto/BaseItemDTO.java

@@ -21,4 +21,9 @@ public class BaseItemDTO implements Serializable {
      * 要素名
      */
     private String partName;
+
+    /**
+     * 要素名
+     */
+    private String partNameLabel;
 }

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

@@ -93,13 +93,11 @@ public class DeviceService {
     KwsDeviceReferenceMapper deviceReferenceMapper;
 
 
-
-
     @Transactional
     public HttpResult dels(String ids, HttpServletRequest response) {
         KwsDevice device = deviceMapper.selectOne(new LambdaQueryWrapper<KwsDevice>()
                 .eq(KwsDevice::getId, ids));
-        if(Objects.isNull(device)){
+        if (Objects.isNull(device)) {
             throw new SystemException(HttpStatus.QUERY_FAIL_CODE, HttpStatus.DEVICE_NOT_EXISTS);
         }
         //List<Long> list = StringUtils.splitStrToList(ids, Long.class);
@@ -247,7 +245,7 @@ public class DeviceService {
         //获取基础要数
         List<DevicePartModelVo> partData = new ArrayList<>();
         partData = deviceModelPartMapper.selectByModelId(deviceModel.getId());
-        if(!Objects.isNull(partData)){//首先在kws_device_model_part获取数据,然后到字典中查询
+        if (!Objects.isNull(partData)) {//首先在kws_device_model_part获取数据,然后到字典中查询
             for (DevicePartModelVo part : partData) {
                 for (SystemDict value : dictList.values()) {
                     if (part.getPartName().equals(value.getValue())) {
@@ -255,14 +253,14 @@ 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());
-                            }
-
+                    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());
                         }
+
+                    }
                 });
             }
             vo.setPart(partData);
@@ -271,13 +269,13 @@ public class DeviceService {
         //获取集成要素
         List<DeviceIntegrationVo> intergData = new ArrayList<>();
         intergData = deviceIntegrationMapper.selectListByParmsAndInterName(vo);
-        if(!Objects.isNull(intergData)){
+        if (!Objects.isNull(intergData)) {
             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)){
+                        if (!Objects.isNull(slopeData)) {
                             inter.setCurrentData(slopeData.getVal());
                         }
 
@@ -288,8 +286,6 @@ public class DeviceService {
         }
 
 
-
-
         return HttpResult.ok(vo);
     }
 
@@ -353,20 +349,20 @@ public class DeviceService {
         device.setUpdateBy(Long.parseLong(headerData.getUpdateBy()));
         device.setUpdateTime(now);
         Integer updateStatus = deviceMapper.updateById(device);
-        if(updateStatus == 1){
+        if (updateStatus == 1) {
             int update = deviceIntegrationMapper.update(null, new LambdaUpdateWrapper<KwsDeviceIntegration>()
                     .eq(KwsDeviceIntegration::getDeviceId, deviceAdd.getId())
                     .set(KwsDeviceIntegration::getDelFlag, NumberConstant.ONE)
-                    .set(KwsDeviceIntegration::getUpdateBy,Long.parseLong(headerData.getUpdateBy()) )
+                    .set(KwsDeviceIntegration::getUpdateBy, Long.parseLong(headerData.getUpdateBy()))
                     .set(KwsDeviceIntegration::getUpdateTime, now));
             //if (update < 1) {
-                //throw new BusinessException("删除设备集成要素异常");
+            //throw new BusinessException("删除设备集成要素异常");
             //}
 
             //新增到数据表kws_device_Integration
             KwsDeviceIntegration deIntergration = new KwsDeviceIntegration();
             String[] temp;//接收分割后的数组
-            if(!deviceAdd.getIntegrationId().isEmpty()){
+            if (!deviceAdd.getIntegrationId().isEmpty()) {
                 temp = deviceAdd.getIntegrationId().split(Global.COMMA);
 
                 for (int i = 0; i < temp.length; i++) {
@@ -419,7 +415,7 @@ public class DeviceService {
                 headerData.getMountainId(), status, Long.parseLong(deviceId));
 
 
-        List<ProjectDeviceVO> projectDeviceList = projectMapper.selectDeviceByProjectId(headerData.getMountainId(), Long.parseLong(projectId), Long.parseLong(deviceId),null);
+        List<ProjectDeviceVO> projectDeviceList = projectMapper.selectDeviceByProjectId(headerData.getMountainId(), Long.parseLong(projectId), Long.parseLong(deviceId), null);
         List<String> deviceIds = new ArrayList<>();
         if (!CollectionUtils.isEmpty(projectDeviceList)) {
             deviceIds = projectDeviceList.stream().map(ProjectDeviceVO::getId).distinct().collect(Collectors.toList());
@@ -499,7 +495,7 @@ public class DeviceService {
                 if (itemList.contains(re.getItem())) {
                     BigDecimal offsetValue = new BigDecimal("0.00");
                     if (org.apache.commons.lang3.StringUtils.isNotBlank(val)) {
-                        offsetValue = new BigDecimal(val).divide(new BigDecimal(1000),12,BigDecimal.ROUND_HALF_UP);
+                        offsetValue = new BigDecimal(val).divide(new BigDecimal(1000), 12, BigDecimal.ROUND_HALF_UP);
                     }
 //                    currentMeasurement.put(itemName, offsetValue);
                     vo.setCurrentMeasurementValue(offsetValue == null ? null : offsetValue.toString());
@@ -548,10 +544,13 @@ public class DeviceService {
                     if (!CollectionUtils.isEmpty(stringList)) {
                         for (int i = 0; i < stringList.size(); i++) {
                             String snCode = kwsDevice.getSnCode();
-                            InsTables insTables = insTablesMapper.selectTableIsExit("devicesv2" + snCode);
+                            InsTables insTables = insTablesMapper.selectTableIsExit("devices" + snCode);
                             if (insTables == null) {
-                                insTablesMapper.createTable("devicesv2" + snCode);
+                                continue;
                             }
+//                            if (insTables == null) {
+//                                insTablesMapper.createTable("devices_" + snCode);
+//                            }
                             List<SlopeData> selected = slopeDataMapper.selectListByLineOrderByCreateTime(snCode, stringList.get(i));
                             if (!CollectionUtils.isEmpty(selected)) {
                                 if (selected.size() == 2) {
@@ -569,7 +568,7 @@ public class DeviceService {
 //                                    long epochMilli1 = date1.toInstant(ZoneOffset.of("+8")).toEpochMilli();
                                     long t = (epochMilli - epochMilli1) / (60 * 60 * 1000);
                                     long val = Long.parseLong(currSlopeData.getVal()) - Long.parseLong(lastSlopeData.getVal());
-                                    decimal = BigDecimal.valueOf(val).divide((new BigDecimal(t).multiply(new BigDecimal(t))),12,BigDecimal.ROUND_HALF_UP);
+                                    decimal = BigDecimal.valueOf(val).divide((new BigDecimal(t).multiply(new BigDecimal(t))), 12, BigDecimal.ROUND_HALF_UP);
                                 }
                             }
                         }
@@ -595,8 +594,8 @@ public class DeviceService {
         JSONArray array = JSON.parseArray(listData);
         LocalDateTime now = LocalDateTime.now();
         BigDecimal zero = new BigDecimal("0");
-        for(Object object : array){
-            JSONObject obj = (JSONObject)object;
+        for (Object object : array) {
+            JSONObject obj = (JSONObject) object;
             KwsDeviceReference reference = deviceReferenceMapper.selectOne(new LambdaQueryWrapper<KwsDeviceReference>()
                     .eq(KwsDeviceReference::getMountainId, headerData.getMountainId())
                     .eq(KwsDeviceReference::getDeviceId, deviceId)
@@ -605,13 +604,13 @@ public class DeviceService {
             );
             long interId = new IdWorker(NumberConstant.ONE).nextId();
             KwsDeviceReference kwsDeviceReference = new KwsDeviceReference();
-            BigDecimal value  = new BigDecimal(obj.get("value").toString());
+            BigDecimal value = new BigDecimal(obj.get("value").toString());
 
-            if(Objects.isNull(reference)){
+            if (Objects.isNull(reference)) {
                 kwsDeviceReference.setOffset(zero);
                 kwsDeviceReference.setOriginalValue(zero);
                 kwsDeviceReference.setCurrentValue(value);
-            }else{
+            } else {
                 //如果有数据,则先删除原有数据。
                 deviceReferenceMapper.update(null, new LambdaUpdateWrapper<KwsDeviceReference>()
                         .eq(KwsDeviceReference::getMountainId, headerData.getMountainId())
@@ -623,13 +622,13 @@ public class DeviceService {
                 //BigDecimal offset = value.subtract(reference.getValue());
                 kwsDeviceReference.setOriginalValue(reference.getOriginalValue());//原始基准不变
                 //调整经纬度
-                if(type.equals(NumberConstant.ONE)){
+                if (type.equals(NumberConstant.ONE)) {
                     BigDecimal offset = commonService.computeOffset(value.toString(), obj.get("item").toString(), reference);
                     kwsDeviceReference.setOffset(offset);//当前位置-上一次的位置的距离的距离
                     kwsDeviceReference.setCurrentValue(value);
                     kwsDeviceReference.setValue(reference.getCurrentValue());
 
-                }else{
+                } else {
                     BigDecimal currentValue = commonService.computeOffset(value.toString(), obj.get("item").toString(), reference);
                     kwsDeviceReference.setValue(reference.getCurrentValue());
                     kwsDeviceReference.setOffset(value);
@@ -661,6 +660,15 @@ public class DeviceService {
         String companyId = commonService.getHeaderData(request).getCompanyId();
         //查询基本要素
         List<BaseItemDTO> baseItem = projectDeviceMapper.selectDataByDeviceId(Long.parseLong(id));
+        Map<String, SystemDict> dictByDictCode = commonService.getDictByDictCode(DictEnum.MODEL_PART);
+        if (!CollectionUtils.isEmpty(baseItem)) {
+            for (BaseItemDTO baseItemDTO : baseItem) {
+                baseItemDTO.setPartNameLabel(baseItemDTO.getPartName() == null ? null :
+                        (dictByDictCode == null ? baseItemDTO.getPartName() :
+                                (dictByDictCode.get(baseItemDTO.getPartName()) == null ?
+                                        (baseItemDTO.getPartName()) : dictByDictCode.get(baseItemDTO.getPartName()).getLabel())));
+            }
+        }
         List<IntegrationItemVO> integrationItem = projectDeviceMapper.selectIntegrationItemByDeviceId(Long.parseLong(id));
         com.alibaba.fastjson2.JSONObject jsonObject = new com.alibaba.fastjson2.JSONObject();
         jsonObject.put("baseItem", baseItem);

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

@@ -249,7 +249,7 @@ public class ThresholdService {
         }
         //页面阈值等级校验
         //当前使用阈值123级硬编码校验
-        checkThresholdLevel(configurationDTO, headerData);
+//        checkThresholdLevel(configurationDTO, headerData);
         //后期阈值等级扩容可调用此方法
         //checkLevelMax(threshold, configurationDTO, headerData);
         for (ThresholdBean thresholdBean : threshold) {

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

@@ -294,7 +294,11 @@
         FROM kws_device a
                  LEFT JOIN kws_project_device b ON a.id = b.device_id
                  LEFT JOIN kws_project c ON b.project_id = c.id
-        WHERE c.id = #{projectId}
+        WHERE
+         a.del_flag=0
+        and b.del_flag=0
+        and c.del_flag=0
+        and c.id = #{projectId}
     </select>
 
     <select id="selectDeviceAllByProjectAndMountainId" resultType="com.sckw.slope.detection.model.dto.ThresholdSelectDTO">

+ 6 - 6
slope-modules/slope-detection/src/main/resources/mapper/tdengine/InsTables.xml

@@ -33,7 +33,7 @@
         <include refid="Base_List">
         </include>
         from information_schema.ins_tables a
-        where a.db_name = 'devices'
+        where a.db_name = 'devicesv2'
           and a.table_name = #{tableName}
     </select>
 
@@ -41,12 +41,12 @@
         CREATE TABLE #{tableName}
         (
             ts          TIMESTAMP,
-            raw_id      TIMESTAMP,
-            tslver_id   INT ,
+            tslver_id   INT,
+            line        VARCHAR(64),
+            val         VARCHAR(64),
+            msg_id      VARCHAR(64),
             guid        VARCHAR(64),
-            line        VARCHAR(16),
-            val         VARCHAR(16),
-            create_time TIMESTAMP
+            raw_ts      TIMESTAMP
         )
     </insert>
 </mapper>