Jelajahi Sumber

时间项目统计增加筛选

lengfaqiang 2 tahun lalu
induk
melakukan
34333061dd

+ 14 - 8
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/consumer/MqttCallbackHandler.java

@@ -7,6 +7,7 @@ import com.sckw.core.model.constant.Global;
 import com.sckw.core.model.constant.NumberConstant;
 import com.sckw.core.model.enums.AlarmTitleEnum;
 import com.sckw.core.model.enums.AlarmTypeEnum;
+import com.sckw.core.model.enums.DictEnum;
 import com.sckw.core.model.enums.DictItemEnum;
 import com.sckw.core.utils.CollectionUtils;
 import com.sckw.core.utils.DateUtils;
@@ -22,6 +23,7 @@ import com.sckw.slope.detection.model.dos.tdengine.SlopeData;
 import com.sckw.slope.detection.model.dto.AlarmList;
 import com.sckw.slope.detection.model.dto.DevicesAlarm;
 import com.sckw.slope.detection.model.dto.DevicesItem;
+import com.sckw.slope.detection.model.dto.SystemDict;
 import com.sckw.slope.detection.model.param.SmsMessageParam;
 import com.sckw.slope.detection.model.vo.DeviceIntegrationVo;
 import com.sckw.slope.detection.service.CommonService;
@@ -85,7 +87,7 @@ public class MqttCallbackHandler extends AbstractHandler {
         log.info("MqttDeviceCallbackHandler:" + topic + "|" + payload);
 
         DevicesAlarm devicesAlarm = JSONObject.parseObject(payload, DevicesAlarm.class);
-//        Map<String, SystemDict> dictByDictCode = commonService.getDictByDictCode(DictEnum.MODEL_PART);
+        Map<String, SystemDict> dictByDictCode = commonService.getDictByDictCode(DictEnum.MODEL_PART);
 //        JSONObject objects = JSONObject.parseObject(payload);
 //        String deviceTs = objects.getString("ts");
 //        String deviceGuid = objects.getString("guid");
@@ -146,7 +148,9 @@ public class MqttCallbackHandler extends AbstractHandler {
                         Long level = Long.valueOf(map.get("level"));
                         Long thresholdId = Long.valueOf(map.get("thresholdId"));
                         //阈值表以及明细表存储
-                        long id = insertAlarmAndDetail(level, device, thresholdId, itemValue, ts, AlarmTitleEnum.ALARM_TITLE_TWO.getStatus(), AlarmTypeEnum.ALARM_ONE.getCode());
+                        String url = dictByDictCode.get(itemName) == null ? null : dictByDictCode.get(itemName).getUrl();
+                        String itemValueAndUnit = StringUtils.isBlank(url) ? itemValue : (itemValue + url);
+                        long id = insertAlarmAndDetail(level, device, thresholdId, itemValueAndUnit, ts, AlarmTitleEnum.ALARM_TITLE_TWO.getStatus(), AlarmTypeEnum.ALARM_ONE.getCode());
                         //todo 不适用redis存统计  使用新字段处理
                         /**阈值次数存redis*/
 //                        redisPutAlarmCount(id);
@@ -190,11 +194,11 @@ public class MqttCallbackHandler extends AbstractHandler {
         if (!org.springframework.util.CollectionUtils.isEmpty(deviceIntegrations)) {
             integrationIds = deviceIntegrations.stream().map(KwsDeviceIntegration::getIntegrationId).collect(Collectors.toList());
         }
-        List<KwsIntegration> integrations = integrationMapper.selectList(
-                new LambdaQueryWrapper<KwsIntegration>()
-                        .in(KwsIntegration::getId, integrationIds)
-                        .eq(KwsIntegration::getDelFlag, NumberConstant.ZERO)
-        );
+//        List<KwsIntegration> integrations = integrationMapper.selectList(
+//                new LambdaQueryWrapper<KwsIntegration>()
+//                        .in(KwsIntegration::getId, integrationIds)
+//                        .eq(KwsIntegration::getDelFlag, NumberConstant.ZERO)
+//        );
 //        Map<String, Long> integrationMap = new HashMap<>(NumberConstant.SIXTEEN);
 //        if (!org.springframework.util.CollectionUtils.isEmpty(integrations)) {
 //            integrationMap = integrations.stream().collect(Collectors.toMap(KwsIntegration::getPartNames, KwsIntegration::getId));
@@ -218,7 +222,9 @@ public class MqttCallbackHandler extends AbstractHandler {
                         Long level = Long.valueOf(map.get("level"));
                         Long thresholdId = Long.valueOf(map.get("thresholdId"));
                         //阈值表以及明细表存储
-                        long id = insertAlarmAndDetail(level, device, thresholdId, deviceIntegration.getPartNames(), ts, AlarmTitleEnum.ALARM_TITLE_TWO.getStatus(), AlarmTypeEnum.ALARM_ONE.getCode());
+                        String url = deviceIntegration.getUnit() == null ? null : deviceIntegration.getUnit();
+                        String itemValueAndUnit = StringUtils.isBlank(url) ? String.valueOf(offset) : (offset + deviceIntegration.getUnit());
+                        long id = insertAlarmAndDetail(level, device, thresholdId, itemValueAndUnit, ts, AlarmTitleEnum.ALARM_TITLE_TWO.getStatus(), AlarmTypeEnum.ALARM_ONE.getCode());
                         Map<String, Object> messageMap = new HashMap<>();
                         pushSmsMessage(messageUrl, device, level, thresholdId, messageMap);
                     }

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

@@ -329,6 +329,15 @@
             <if test="type != null and type != ''">
                 and a.type = #{type}
             </if>
+            <if test="startTime != null and startTime != ''">
+                and b.create_time &gt; #{startTime}
+            </if>
+            <if test="endTime != null and endTime != ''">
+                and b.create_time &lt; #{endTime}
+            </if>
+            <if test="level != null and level != ''">
+                and a.level = #{level}
+            </if>
         </where>
         GROUP BY a.project_id
     </select>