From 5f9bf98779e2c3e69324d75849efdda00868da4f Mon Sep 17 00:00:00 2001
From: doum <doum>
Date: 星期五, 29 五月 2026 15:45:47 +0800
Subject: [PATCH] 新增智能电表、空调管理
---
server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/YwElectricalWarningServiceImpl.java | 73 ++++++++++++++++++++++++++++++++++++
1 files changed, 72 insertions(+), 1 deletions(-)
diff --git a/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/YwElectricalWarningServiceImpl.java b/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/YwElectricalWarningServiceImpl.java
index d499d3b..1f12943 100644
--- a/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/YwElectricalWarningServiceImpl.java
+++ b/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/YwElectricalWarningServiceImpl.java
@@ -22,6 +22,7 @@
import com.doumee.dao.business.model.YwElectricalRoom;
import com.doumee.dao.business.model.YwElectricalWarning;
import com.doumee.dao.business.model.YwRoom;
+import com.doumee.dao.business.vo.WarningTypeStatVO;
import com.doumee.service.business.YwElectricalWarningService;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import org.apache.commons.lang3.StringUtils;
@@ -35,9 +36,11 @@
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
+import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
+import java.util.Set;
import java.util.stream.Collectors;
/**
@@ -98,6 +101,7 @@
}
Map<String, YwElectrical> addressMap = buildElectricalAddressMap();
Map<String, YwElectrical> didMap = buildElectricalDidMap();
+ Set<Integer> affectedElectricalIds = new LinkedHashSet<>();
Date now = new Date();
int addCount = 0;
int updateCount = 0;
@@ -129,6 +133,9 @@
entity.setMsg(item.getMsg());
entity.setEditDate(now);
resolveElectricalId(entity, addressMap, didMap);
+ if (entity.getElectricalId() != null) {
+ affectedElectricalIds.add(entity.getElectricalId());
+ }
if (isNew) {
ywElectricalWarningMapper.insert(entity);
addCount++;
@@ -137,7 +144,8 @@
updateCount++;
}
}
- return "鍚屾瀹屾垚锛氭柊澧炪��" + addCount + "銆戞潯锛屾洿鏂般��" + updateCount + "銆戞潯";
+ int electricalUpdateCount = updateElectricalWarnTypes(affectedElectricalIds, now);
+ return "鍚屾瀹屾垚锛氭柊澧炪��" + addCount + "銆戞潯锛屾洿鏂般��" + updateCount + "銆戞潯锛屽洖鍐欑數琛ㄩ璀︺��" + electricalUpdateCount + "銆戝彴";
} finally {
Constants.DEALING_ELECTRICAL_WARNING_SYNC = false;
}
@@ -148,6 +156,38 @@
List<WarningDefOptionDTO> list = new ArrayList<>();
for (ElectronicConstant.warningDefId item : ElectronicConstant.warningDefId.listByDeviceType(ELECTRICAL_DEVICE_TYPE)) {
list.add(new WarningDefOptionDTO(item.getKey(), item.getName()));
+ }
+ return list;
+ }
+
+ @Override
+ public List<WarningTypeStatVO> warningTypeStats() {
+ QueryWrapper<YwElectricalWarning> wrapper = new QueryWrapper<>();
+ wrapper.select("warning_def_id", "count(1) as cnt")
+ .eq("isdeleted", Constants.ZERO)
+ .eq("device_type", ELECTRICAL_DEVICE_TYPE)
+ .isNotNull("warning_def_id")
+ .groupBy("warning_def_id")
+ .orderByDesc("cnt");
+ List<Map<String, Object>> rows = ywElectricalWarningMapper.selectMaps(wrapper);
+ List<WarningTypeStatVO> list = new ArrayList<>();
+ if (CollectionUtils.isEmpty(rows)) {
+ return list;
+ }
+ for (Map<String, Object> row : rows) {
+ Object defIdObj = row.get("warning_def_id");
+ if (defIdObj == null) {
+ continue;
+ }
+ Integer warningDefId = Integer.parseInt(String.valueOf(defIdObj));
+ Object cntObj = row.get("cnt");
+ long count = cntObj == null ? 0L : Long.parseLong(String.valueOf(cntObj));
+ WarningTypeStatVO stat = new WarningTypeStatVO();
+ stat.setWarningDefId(warningDefId);
+ stat.setCount(count);
+ ElectronicConstant.warningDefId def = ElectronicConstant.warningDefId.getByKey(warningDefId);
+ stat.setWarningName(def != null ? def.getName() : "鏈煡鎶ヨ");
+ list.add(stat);
}
return list;
}
@@ -285,6 +325,37 @@
}
}
+ /** 鎸夌數琛ㄦ眹鎬诲叏閮ㄦ姤璀︾被鍨嬶紝閫楀彿鍒嗛殧鍥炲啓 warn_type */
+ private int updateElectricalWarnTypes(Set<Integer> affectedElectricalIds, Date editDate) {
+ if (CollectionUtils.isEmpty(affectedElectricalIds)) {
+ return 0;
+ }
+ for (Integer electricalId : affectedElectricalIds) {
+ refreshElectricalWarnType(electricalId, editDate);
+ }
+ return affectedElectricalIds.size();
+ }
+
+ private void refreshElectricalWarnType(Integer electricalId, Date editDate) {
+ List<YwElectricalWarning> warnings = ywElectricalWarningMapper.selectList(new QueryWrapper<YwElectricalWarning>().lambda()
+ .eq(YwElectricalWarning::getElectricalId, electricalId)
+ .eq(YwElectricalWarning::getIsdeleted, Constants.ZERO));
+ LinkedHashSet<Integer> defIds = new LinkedHashSet<>();
+ if (!CollectionUtils.isEmpty(warnings)) {
+ for (YwElectricalWarning warning : warnings) {
+ if (warning.getWarningDefId() != null) {
+ defIds.add(warning.getWarningDefId());
+ }
+ }
+ }
+ String warnType = defIds.stream().map(String::valueOf).collect(Collectors.joining(","));
+ YwElectrical upd = new YwElectrical();
+ upd.setId(electricalId);
+ upd.setWarnType(StringUtils.isBlank(warnType) ? null : warnType);
+ upd.setEditDate(editDate);
+ ywElectricalMapper.updateById(upd);
+ }
+
private YwElectricalWarning findExisting(String deviceAddress, Integer warningDefId, Date startTime) {
return ywElectricalWarningMapper.selectOne(new QueryWrapper<YwElectricalWarning>().lambda()
.eq(YwElectricalWarning::getDeviceAddress, deviceAddress)
--
Gitblit v1.9.3