tjf 15 цаг өмнө
parent
commit
0df110a560

+ 3 - 6
ruoyi-admin/src/main/resources/application-prod.yml

@@ -9,7 +9,7 @@ ruoyi:
     # 实例演示开关
     demoEnabled: false
     # 文件路径 示例( Windows配置D:/ruoyi/uploadPath,Linux配置 /home/ruoyi/uploadPath)
-    profile: /home/ruoyi/uploadPath/deviceManage
+    profile: /home/boman/uploadPath/deviceManage
     # 获取ip地址开关
     addressEnabled: false
     # 验证码类型 math 数组计算 char 字符验证
@@ -39,7 +39,7 @@ spring:
         # 端口,默认为6379
         port: 6379
         # 数据库索引
-        database: 6
+        database: 1
         # 密码
         password: D3fQYAsw
         # 连接超时时间
@@ -63,7 +63,7 @@ spring:
             master:
                 url: jdbc:mysql://127.0.0.1:3306/device_manage?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&nullCatalogMeansCurrent=true
                 username: root
-                password: zhaoshang@2018
+                password: 1q2w!Q@W
             # 从库数据源
             slave:
                 # 从数据源开关/默认关闭
@@ -114,6 +114,3 @@ spring:
                 wall:
                     config:
                         multi-statement-allow: true
-
-
-#极光推送

+ 6 - 3
ruoyi-admin/src/main/resources/application.yml

@@ -77,12 +77,15 @@ xss:
 # MQTT配置
 mqtt:
 #  server-uri: tcp://13.229.167.76:1883
-  server-uri: tcp://60.171.161.56:20009
+#  server-uri: tcp://60.171.161.56:20009
+  server-uri: tcp://127.0.0.1:1883
 #  server-uri: tcp://192.168.101.147:1883
 #  server-uri: tcp://127.0.0.1:1883
-  client-id: JavaClientBoman
+  client-id: JavaClientBoMan
   username: admin
-  password: 9o0p(O)P
+  password: 1qaz!QAZ
+#  username:
+#  password:
   default-topic: toServer_leaveStat,toServer_playStat
   default-qos: 1
   timeout: 30

+ 66 - 58
ruoyi-system/src/main/java/com/ruoyi/manage/service/impl/WarnManageServiceImpl.java

@@ -11,6 +11,7 @@ import com.ruoyi.manage.domain.WarnManage;
 import com.ruoyi.manage.mapper.EquipmentManageMapper;
 import com.ruoyi.manage.mapper.WarnManageMapper;
 import com.ruoyi.manage.service.IWarnManageService;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -27,6 +28,7 @@ import static com.ruoyi.common.constant.Constants.*;
  * @author boman
  * @date 2025-06-19
  */
+@Slf4j
 @Service
 public class WarnManageServiceImpl implements IWarnManageService {
     @Autowired
@@ -124,9 +126,9 @@ public class WarnManageServiceImpl implements IWarnManageService {
         int warnMonthLastLeave = 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()) {
             warnMonthAll = warnManages.size();
@@ -134,27 +136,30 @@ public class WarnManageServiceImpl implements IWarnManageService {
             if (!collect.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()) {
-                    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("deptId", deptId);
                 finalDeptNameMapList.add(deptMap);
             });
             deptNameMapList = finalDeptNameMapList;
         }
+
         //上月告警数据
         Map<String, Object> warnLastMonth = redisCache.getCacheMap(WARN_LAST_MONTH + DateUtils.getMonth());
         if (warnLastMonth.isEmpty()) {
+            Map<String, Object> lastMap = new HashMap<>();
             //从数据库查询
             warnManage.setWarnTime(DateUtils.getLastMonth());
             List<WarnManage> warnManagesLast = warnManageMapper.selectWarnManageDeptListByTime(warnManage);
@@ -164,30 +169,29 @@ public class WarnManageServiceImpl implements IWarnManageService {
                 if (!collect.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()) {
                         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("warnMonthLastLeave", warnMonthLastLeave);
             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);
         } else {
             warnMonthLastAll = Integer.parseInt(warnLastMonth.get("warnMonthLastAll").toString());
@@ -198,16 +202,16 @@ public class WarnManageServiceImpl implements IWarnManageService {
 
         //进行本月部门数据和上月部门数据对比,已本月部门数据为主
         if (!deptNameMapList.isEmpty()) {
-            List<Map<String, String>> finalDeptNameMapList = deptNameLastMapList;
+            List<Map<String, Object>> finalDeptNameMapList = deptNameLastMapList;
             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";
                 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);
     }
 
-    public static List<Map<String, String>> convertObjectToList(Object obj) {
+    public static List<Map<String, Object>> convertObjectToList(Object obj) {
         // 1. 检查是否为 List 类型
         if (!(obj instanceof List<?>)) {
             throw new IllegalArgumentException("Object is not a List");
@@ -339,7 +343,7 @@ public class WarnManageServiceImpl implements IWarnManageService {
         }
 
         // 4. 安全强制转换(已验证类型)
-        return (List<Map<String, String>>) obj;
+        return (List<Map<String, Object>>) obj;
     }
 
 
@@ -380,31 +384,35 @@ public class WarnManageServiceImpl implements IWarnManageService {
      * @param message
      */
     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());
+        }
     }
 }

+ 21 - 15
ruoyi-system/src/main/resources/mapper/manage/WarnManageMapper.xml

@@ -52,23 +52,29 @@
     </sql>
 
     <select id="selectWarnManageList" parameterType="WarnManage" resultMap="WarnManageResult">
-        <include refid="selectWarnManageVo"/>
+        select w.warn_id, w.equipment_ip, w.equipment_name, w.channel_id, w.channel_num, w.algorithm_type,
+        w.parameter_set, w.video_address, w.warn_image, w.report_status, w.warn_time,w.rang_name, w.del_flag, w.create_time,
+        e.dept_name,e.dept_id
+        from warn_manage w left join equipment_manage e on e.equipment_id = w.equipment_id
         <where>
-            del_flag = '0'
-            <if test="equipmentIp != null  and equipmentIp != ''">and equipment_ip = #{equipmentIp}</if>
-            <if test="equipmentName != null  and equipmentName != ''">and equipment_name like concat('%',
+            w.del_flag = '0'
+            <if test="equipmentIp != null  and equipmentIp != ''">and w.equipment_ip = #{equipmentIp}</if>
+            <if test="equipmentName != null  and equipmentName != ''">and w.equipment_name like concat('%',
                 #{equipmentName}, '%')
             </if>
-            <if test="channelId != null ">and channel_id = #{channelId}</if>
-            <if test="channelNum != null  and channelNum != ''">and channel_num = #{channelNum}</if>
-            <if test="algorithmType != null  and algorithmType != ''">and algorithm_type = #{algorithmType}</if>
-            <if test="parameterSet != null  and parameterSet != ''">and parameter_set = #{parameterSet}</if>
-            <if test="videoAddress != null  and videoAddress != ''">and video_address = #{videoAddress}</if>
-            <if test="warnImage != null  and warnImage != ''">and warn_image = #{warnImage}</if>
-            <if test="reportStatus != null  and reportStatus != ''">and report_status = #{reportStatus}</if>
-            <if test="warnTime != null ">and date_format(warn_time,'%Y%m%d') =date_format(#{warnTime},'%Y%m%d')</if>
+            <if test="channelId != null ">and w.channel_id = #{channelId}</if>
+            <if test="channelNum != null  and channelNum != ''">and w.channel_num = #{channelNum}</if>
+            <if test="algorithmType != null  and algorithmType != ''">and w.algorithm_type = #{algorithmType}</if>
+            <if test="parameterSet != null  and parameterSet != ''">and w.parameter_set = #{parameterSet}</if>
+            <if test="videoAddress != null  and videoAddress != ''">and w.video_address = #{videoAddress}</if>
+            <if test="warnImage != null  and warnImage != ''">and w.warn_image = #{warnImage}</if>
+            <if test="reportStatus != null  and reportStatus != ''">and w.report_status = #{reportStatus}</if>
+            <if test="rangName != null  and rangName != ''">and w.rang_name like concat('%',#{rangName}, '%') </if>
+            <if test="deptId != null  ">and e.dept_id = #{deptId}</if>
+            <if test="warnTime != null ">and date_format(w.warn_time,'%Y%m%d') =date_format(#{warnTime},'%Y%m%d')</if>
+            <if test="params.month != null ">and date_format(w.warn_time,'%Y%m') =date_format(#{warnTime},'%Y%m')</if>
             <if test="params.year != null and params.year != ''"><!-- 年份检索 -->
-                AND date_format(warn_time,'%Y') = #{params.year}
+                AND date_format(w.warn_time,'%Y') = #{params.year}
             </if>
         </where>
     </select>
@@ -106,10 +112,10 @@
             <if test="rangName != null">rang_name,</if>
             <if test="delFlag != null">del_flag,</if>
             <if test="createBy != null">create_by,</if>
-            <if test="createTime != null">create_time,</if>
             <if test="updateBy != null">update_by,</if>
             <if test="updateTime != null">update_time,</if>
             <if test="remark != null">remark,</if>
+            create_time
         </trim>
         <trim prefix="values (" suffix=")" suffixOverrides=",">
             <if test="equipmentId != null and equipmentId != ''">#{equipmentId},</if>
@@ -126,10 +132,10 @@
             <if test="rangName != null">#{rangName},</if>
             <if test="delFlag != null">#{delFlag},</if>
             <if test="createBy != null">#{createBy},</if>
-            <if test="createTime != null">#{createTime},</if>
             <if test="updateBy != null">#{updateBy},</if>
             <if test="updateTime != null">#{updateTime},</if>
             <if test="remark != null">#{remark},</if>
+            sysdate()
         </trim>
     </insert>