|
@@ -11,6 +11,7 @@ import com.ruoyi.manage.domain.WarnManage;
|
|
import com.ruoyi.manage.mapper.EquipmentManageMapper;
|
|
import com.ruoyi.manage.mapper.EquipmentManageMapper;
|
|
import com.ruoyi.manage.mapper.WarnManageMapper;
|
|
import com.ruoyi.manage.mapper.WarnManageMapper;
|
|
import com.ruoyi.manage.service.IWarnManageService;
|
|
import com.ruoyi.manage.service.IWarnManageService;
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
@@ -27,6 +28,7 @@ import static com.ruoyi.common.constant.Constants.*;
|
|
* @author boman
|
|
* @author boman
|
|
* @date 2025-06-19
|
|
* @date 2025-06-19
|
|
*/
|
|
*/
|
|
|
|
+@Slf4j
|
|
@Service
|
|
@Service
|
|
public class WarnManageServiceImpl implements IWarnManageService {
|
|
public class WarnManageServiceImpl implements IWarnManageService {
|
|
@Autowired
|
|
@Autowired
|
|
@@ -124,9 +126,9 @@ public class WarnManageServiceImpl implements IWarnManageService {
|
|
int warnMonthLastLeave = 0;
|
|
int warnMonthLastLeave = 0;
|
|
int warnMonthLastPlay = 0;
|
|
int warnMonthLastPlay = 0;
|
|
//本月部门数据
|
|
//本月部门数据
|
|
- List<Map<String, String>> deptNameMapList = new ArrayList<>();
|
|
|
|
|
|
+ List<Map<String, Object>> deptNameMapList = new ArrayList<>();
|
|
//上月部门数据
|
|
//上月部门数据
|
|
- List<Map<String, String>> deptNameLastMapList = new ArrayList<>();
|
|
|
|
|
|
+ List<Map<String, Object>> deptNameLastMapList = new ArrayList<>();
|
|
//计算告警数据
|
|
//计算告警数据
|
|
if (warnManages != null && !warnManages.isEmpty()) {
|
|
if (warnManages != null && !warnManages.isEmpty()) {
|
|
warnMonthAll = warnManages.size();
|
|
warnMonthAll = warnManages.size();
|
|
@@ -134,27 +136,30 @@ public class WarnManageServiceImpl implements IWarnManageService {
|
|
if (!collect.isEmpty()) {
|
|
if (!collect.isEmpty()) {
|
|
//离岗
|
|
//离岗
|
|
if (collect.get(ZERO) != null && !collect.get(ZERO).isEmpty()) {
|
|
if (collect.get(ZERO) != null && !collect.get(ZERO).isEmpty()) {
|
|
- warnMonthLastLeave = collect.get(ZERO).size();
|
|
|
|
|
|
+ warnMonthLeave = collect.get(ZERO).size();
|
|
}
|
|
}
|
|
//玩手机
|
|
//玩手机
|
|
if (collect.get(ONE) != null && !collect.get(ONE).isEmpty()) {
|
|
if (collect.get(ONE) != null && !collect.get(ONE).isEmpty()) {
|
|
- warnMonthLastPlay = collect.get(ONE).size();
|
|
|
|
|
|
+ warnMonthPlay = collect.get(ONE).size();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
//插入当月部门数据
|
|
//插入当月部门数据
|
|
- Map<String, List<WarnManage>> deptNameCollect = warnManages.stream().filter( e ->StringUtils.isNotEmpty(e.getDeptName())).collect(Collectors.groupingBy(WarnManage::getDeptName));
|
|
|
|
- List<Map<String, String>> finalDeptNameMapList = new ArrayList<>();
|
|
|
|
- deptNameCollect.forEach((deptName, v) -> {
|
|
|
|
- Map<String, String> deptMap = new HashMap<>(9);
|
|
|
|
- deptMap.put("deptName", deptName);
|
|
|
|
|
|
+ Map<Long, List<WarnManage>> deptNameCollect = warnManages.stream().filter( e ->e.getDeptId() != null).collect(Collectors.groupingBy(WarnManage::getDeptId));
|
|
|
|
+ List<Map<String, Object>> finalDeptNameMapList = new ArrayList<>();
|
|
|
|
+ deptNameCollect.forEach((deptId, v) -> {
|
|
|
|
+ Map<String, Object> deptMap = new HashMap<>(3);
|
|
|
|
+ deptMap.put("deptName", v.get(0).getDeptName());
|
|
deptMap.put("warnNum", String.valueOf(v.size()));
|
|
deptMap.put("warnNum", String.valueOf(v.size()));
|
|
|
|
+ deptMap.put("deptId", deptId);
|
|
finalDeptNameMapList.add(deptMap);
|
|
finalDeptNameMapList.add(deptMap);
|
|
});
|
|
});
|
|
deptNameMapList = finalDeptNameMapList;
|
|
deptNameMapList = finalDeptNameMapList;
|
|
}
|
|
}
|
|
|
|
+
|
|
//上月告警数据
|
|
//上月告警数据
|
|
Map<String, Object> warnLastMonth = redisCache.getCacheMap(WARN_LAST_MONTH + DateUtils.getMonth());
|
|
Map<String, Object> warnLastMonth = redisCache.getCacheMap(WARN_LAST_MONTH + DateUtils.getMonth());
|
|
if (warnLastMonth.isEmpty()) {
|
|
if (warnLastMonth.isEmpty()) {
|
|
|
|
+ Map<String, Object> lastMap = new HashMap<>();
|
|
//从数据库查询
|
|
//从数据库查询
|
|
warnManage.setWarnTime(DateUtils.getLastMonth());
|
|
warnManage.setWarnTime(DateUtils.getLastMonth());
|
|
List<WarnManage> warnManagesLast = warnManageMapper.selectWarnManageDeptListByTime(warnManage);
|
|
List<WarnManage> warnManagesLast = warnManageMapper.selectWarnManageDeptListByTime(warnManage);
|
|
@@ -164,30 +169,29 @@ public class WarnManageServiceImpl implements IWarnManageService {
|
|
if (!collect.isEmpty()) {
|
|
if (!collect.isEmpty()) {
|
|
//离岗
|
|
//离岗
|
|
if (collect.get(ZERO) != null && !collect.get(ZERO).isEmpty()) {
|
|
if (collect.get(ZERO) != null && !collect.get(ZERO).isEmpty()) {
|
|
- warnMonthLeave = collect.get(ZERO).size();
|
|
|
|
|
|
+ warnMonthLastLeave = collect.get(ZERO).size();
|
|
}
|
|
}
|
|
//玩手机
|
|
//玩手机
|
|
if (collect.get(ONE) != null && !collect.get(ONE).isEmpty()) {
|
|
if (collect.get(ONE) != null && !collect.get(ONE).isEmpty()) {
|
|
warnMonthLastPlay = collect.get(ONE).size();
|
|
warnMonthLastPlay = collect.get(ONE).size();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ //插入上月部门数据
|
|
|
|
+ Map<Long, List<WarnManage>> deptNameCollect = warnManagesLast.stream().filter( e ->e.getDeptId() != null).collect(Collectors.groupingBy(WarnManage::getDeptId));
|
|
|
|
+ List<Map<String, Object>> finalDeptNameLastMapList = new ArrayList<>();
|
|
|
|
+ deptNameCollect.forEach((deptId, v) -> {
|
|
|
|
+ Map<String, Object> deptMap = new HashMap<>(3);
|
|
|
|
+ deptMap.put("deptName", v.get(0).getDeptName());
|
|
|
|
+ deptMap.put("warnNum", String.valueOf(v.size()));
|
|
|
|
+ deptMap.put("deptId", deptId);
|
|
|
|
+ finalDeptNameLastMapList.add(deptMap);
|
|
|
|
+ });
|
|
|
|
+ deptNameLastMapList = finalDeptNameLastMapList;
|
|
}
|
|
}
|
|
- Map<String, Object> lastMap = new HashMap<>();
|
|
|
|
|
|
+ lastMap.put("deptNameCollect", deptNameLastMapList);
|
|
lastMap.put("warnMonthLastAll", warnMonthLastAll);
|
|
lastMap.put("warnMonthLastAll", warnMonthLastAll);
|
|
lastMap.put("warnMonthLastLeave", warnMonthLastLeave);
|
|
lastMap.put("warnMonthLastLeave", warnMonthLastLeave);
|
|
lastMap.put("warnMonthLastPlay", warnMonthLastPlay);
|
|
lastMap.put("warnMonthLastPlay", warnMonthLastPlay);
|
|
-
|
|
|
|
- //插入上月部门数据
|
|
|
|
- Map<String, List<WarnManage>> deptNameCollect = warnManages.stream().collect(Collectors.groupingBy(WarnManage::getDeptName));
|
|
|
|
- List<Map<String, String>> finalDeptNameLastMapList = new ArrayList<>();
|
|
|
|
- deptNameCollect.forEach((deptName, v) -> {
|
|
|
|
- Map<String, String> deptMap = new HashMap<>(9);
|
|
|
|
- deptMap.put("deptName", deptName);
|
|
|
|
- deptMap.put("warnNum", String.valueOf(v.size()));
|
|
|
|
- finalDeptNameLastMapList.add(deptMap);
|
|
|
|
- });
|
|
|
|
- lastMap.put("deptNameCollect", finalDeptNameLastMapList);
|
|
|
|
- deptNameLastMapList = finalDeptNameLastMapList;
|
|
|
|
redisCache.setCacheMap(WARN_LAST_MONTH + DateUtils.getMonth(), lastMap);
|
|
redisCache.setCacheMap(WARN_LAST_MONTH + DateUtils.getMonth(), lastMap);
|
|
} else {
|
|
} else {
|
|
warnMonthLastAll = Integer.parseInt(warnLastMonth.get("warnMonthLastAll").toString());
|
|
warnMonthLastAll = Integer.parseInt(warnLastMonth.get("warnMonthLastAll").toString());
|
|
@@ -198,16 +202,16 @@ public class WarnManageServiceImpl implements IWarnManageService {
|
|
|
|
|
|
//进行本月部门数据和上月部门数据对比,已本月部门数据为主
|
|
//进行本月部门数据和上月部门数据对比,已本月部门数据为主
|
|
if (!deptNameMapList.isEmpty()) {
|
|
if (!deptNameMapList.isEmpty()) {
|
|
- List<Map<String, String>> finalDeptNameMapList = deptNameLastMapList;
|
|
|
|
|
|
+ List<Map<String, Object>> finalDeptNameMapList = deptNameLastMapList;
|
|
deptNameMapList.forEach(deptNameMap -> {
|
|
deptNameMapList.forEach(deptNameMap -> {
|
|
- String deptName = deptNameMap.get("deptName");
|
|
|
|
- String warnNum = deptNameMap.get("warnNum");
|
|
|
|
|
|
+ String deptId = deptNameMap.get("deptId").toString();
|
|
|
|
+ String warnNum = deptNameMap.get("warnNum").toString();
|
|
String warnNumLast = "0";
|
|
String warnNumLast = "0";
|
|
if (!finalDeptNameMapList.isEmpty()) {
|
|
if (!finalDeptNameMapList.isEmpty()) {
|
|
- for (Map<String, String> lastMonthDeptMap : finalDeptNameMapList) {
|
|
|
|
- String deptNameLast = lastMonthDeptMap.get(deptName);
|
|
|
|
- if (StringUtils.isNotEmpty(deptNameLast)) {
|
|
|
|
- warnNumLast = lastMonthDeptMap.get("warnNum");
|
|
|
|
|
|
+ for (Map<String, Object> lastMonthDeptMap : finalDeptNameMapList) {
|
|
|
|
+ String deptIdLast = lastMonthDeptMap.get(deptId).toString();
|
|
|
|
+ if (StringUtils.isNotEmpty(deptIdLast)) {
|
|
|
|
+ warnNumLast = lastMonthDeptMap.get("warnNum").toString();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -313,7 +317,7 @@ public class WarnManageServiceImpl implements IWarnManageService {
|
|
return AjaxResult.success(map);
|
|
return AjaxResult.success(map);
|
|
}
|
|
}
|
|
|
|
|
|
- public static List<Map<String, String>> convertObjectToList(Object obj) {
|
|
|
|
|
|
+ public static List<Map<String, Object>> convertObjectToList(Object obj) {
|
|
// 1. 检查是否为 List 类型
|
|
// 1. 检查是否为 List 类型
|
|
if (!(obj instanceof List<?>)) {
|
|
if (!(obj instanceof List<?>)) {
|
|
throw new IllegalArgumentException("Object is not a List");
|
|
throw new IllegalArgumentException("Object is not a List");
|
|
@@ -339,7 +343,7 @@ public class WarnManageServiceImpl implements IWarnManageService {
|
|
}
|
|
}
|
|
|
|
|
|
// 4. 安全强制转换(已验证类型)
|
|
// 4. 安全强制转换(已验证类型)
|
|
- return (List<Map<String, String>>) obj;
|
|
|
|
|
|
+ return (List<Map<String, Object>>) obj;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -380,31 +384,35 @@ public class WarnManageServiceImpl implements IWarnManageService {
|
|
* @param message
|
|
* @param message
|
|
*/
|
|
*/
|
|
public void addWarnManage(MqttMessage message, String algorithmType) {
|
|
public void addWarnManage(MqttMessage message, String algorithmType) {
|
|
- String payload = message.getPayload();
|
|
|
|
- JSONObject jsonObject = JSONObject.parseObject(payload);
|
|
|
|
- String equipmentIp = jsonObject.getString("equipmentIp");
|
|
|
|
- EquipmentManage equipmentManage = new EquipmentManage();
|
|
|
|
- equipmentManage.setEquipmentIp(equipmentIp);
|
|
|
|
- EquipmentManage equipmentManageOld = equipmentManageMapper.selectEquipmentManageByEquipmentIp(equipmentManage);
|
|
|
|
- Long channelId = jsonObject.getLong("channelId");
|
|
|
|
- String parameterSet = jsonObject.getString("parameterSet");
|
|
|
|
- String algorithmResult = jsonObject.getString("algorithmResult");
|
|
|
|
- String photoUrl = jsonObject.getString("photoUrl");
|
|
|
|
- String videoUrl = jsonObject.getString("videoUrl");
|
|
|
|
- String rangName = jsonObject.getString("name");
|
|
|
|
- WarnManage warnManage = new WarnManage();
|
|
|
|
- warnManage.setEquipmentIp(equipmentIp);
|
|
|
|
- warnManage.setEquipmentName(equipmentManageOld.getEquipmentName());
|
|
|
|
- warnManage.setEquipmentId(equipmentManageOld.getEquipmentId());
|
|
|
|
- warnManage.setChannelId(channelId);
|
|
|
|
- warnManage.setParameterSet(parameterSet);
|
|
|
|
- warnManage.setAlgorithmType(algorithmType);
|
|
|
|
- warnManage.setReportStatus(algorithmResult);
|
|
|
|
- warnManage.setVideoAddress(videoUrl);
|
|
|
|
- warnManage.setWarnImage(photoUrl);
|
|
|
|
- warnManage.setCreateTime(DateUtils.getNowDate());
|
|
|
|
- warnManage.setWarnTime(DateUtils.getNowDate());
|
|
|
|
- warnManage.setRangName(rangName);
|
|
|
|
- warnManageMapper.insertWarnManage(warnManage);
|
|
|
|
|
|
+ try {
|
|
|
|
+ String payload = message.getPayload();
|
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(payload);
|
|
|
|
+ String equipmentIp = jsonObject.getString("equipmentIp");
|
|
|
|
+ EquipmentManage equipmentManage = new EquipmentManage();
|
|
|
|
+ equipmentManage.setEquipmentIp(equipmentIp);
|
|
|
|
+ EquipmentManage equipmentManageOld = equipmentManageMapper.selectEquipmentManageByEquipmentIp(equipmentManage);
|
|
|
|
+ Long channelId = jsonObject.getLong("channelId");
|
|
|
|
+ String parameterSet = jsonObject.getString("parameterSet");
|
|
|
|
+ String algorithmResult = jsonObject.getString("algorithmResult");
|
|
|
|
+ String photoUrl = jsonObject.getString("photoUrl");
|
|
|
|
+ String videoUrl = jsonObject.getString("videoUrl");
|
|
|
|
+ String rangName = jsonObject.getString("name");
|
|
|
|
+ WarnManage warnManage = new WarnManage();
|
|
|
|
+ warnManage.setEquipmentIp(equipmentIp);
|
|
|
|
+ warnManage.setEquipmentName(equipmentManageOld.getEquipmentName());
|
|
|
|
+ warnManage.setEquipmentId(equipmentManageOld.getEquipmentId());
|
|
|
|
+ warnManage.setChannelId(channelId);
|
|
|
|
+ warnManage.setParameterSet(parameterSet);
|
|
|
|
+ warnManage.setAlgorithmType(algorithmType);
|
|
|
|
+ warnManage.setReportStatus(algorithmResult);
|
|
|
|
+ warnManage.setVideoAddress(videoUrl);
|
|
|
|
+ warnManage.setWarnImage(photoUrl);
|
|
|
|
+ warnManage.setCreateTime(DateUtils.getNowDate());
|
|
|
|
+ warnManage.setWarnTime(DateUtils.getNowDate());
|
|
|
|
+ warnManage.setRangName(rangName);
|
|
|
|
+ warnManageMapper.insertWarnManage(warnManage);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ log.info("新增告警信息异常:{}", e.getMessage());
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|