tjf 2 days ago
parent
commit
a8f9bed33b

+ 10 - 0
ruoyi-admin/src/main/java/com/ruoyi/web/controller/manage/IndexController.java

@@ -5,6 +5,7 @@ import com.ruoyi.common.core.domain.AjaxResult;
 import com.ruoyi.manage.service.IWarnManageService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
@@ -27,4 +28,13 @@ public class IndexController extends BaseController {
         return  warnManageService.getWarnManageIndex();
     }
 
+
+    /**
+     * 年度告警统计
+     */
+    @GetMapping("/warnManageIndexYear/{year}")
+    public AjaxResult warnManageIndexYear(@PathVariable String year) {
+        return  warnManageService.warnManageIndexYear(year);
+    }
+
 }

+ 2 - 0
ruoyi-common/src/main/java/com/ruoyi/common/constant/Constants.java

@@ -190,4 +190,6 @@ public class Constants {
     public static final String DETECTION_PLAYRATE = "detection/playrate";
     //rtsp地址
     public static final String DETECTION_RTSP = "detection/rtsp";
+    //首页统计折线图往期年份数据
+    public static final String WARN_MANAGE_LAST_YEAR = "warn_manage_last_year:";
 }

+ 16 - 0
ruoyi-common/src/main/java/com/ruoyi/common/utils/DateUtils.java

@@ -57,6 +57,15 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils {
         return dateTimeNow(YYYY_MM);
     }
 
+    /**
+     * 获取当前日期, 默认格式为yyyy-MM-dd
+     *
+     * @return String
+     */
+    public static String getYear() {
+        return dateTimeNow(YYYY);
+    }
+
     /**
      * 获取上月日期
      *
@@ -182,4 +191,11 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils {
         ZonedDateTime zdt = localDateTime.atZone(ZoneId.systemDefault());
         return Date.from(zdt.toInstant());
     }
+
+    public static int getMonth(Date date) {
+        Calendar cal = Calendar.getInstance();
+        cal.setTime(date);
+        return cal.get(Calendar.MONTH) + 1;
+    }
+
 }

+ 5 - 0
ruoyi-system/src/main/java/com/ruoyi/manage/service/IWarnManageService.java

@@ -67,4 +67,9 @@ public interface IWarnManageService
      * @return
      */
    AjaxResult getWarnManageIndex();
+
+    /**
+     * 年度告警统计
+     */
+   AjaxResult warnManageIndexYear(String year);
 }

+ 12 - 1
ruoyi-system/src/main/java/com/ruoyi/manage/service/impl/ChannelNumberServiceImpl.java

@@ -74,7 +74,18 @@ public class ChannelNumberServiceImpl implements IChannelNumberService {
      */
     @Override
     public List<ChannelNumber> selectChannelNumberList(ChannelNumber channelNumber) {
-        return channelNumberMapper.selectChannelNumberList(channelNumber);
+        List<ChannelNumber> channelNumbers = channelNumberMapper.selectChannelNumberList(channelNumber);
+        if (channelNumbers != null && !channelNumbers.isEmpty()) {
+            Long channelId = channelNumbers.get(0).getChannelId();
+            //判断是否设置过参数
+            ParameterSet parameterSet = parameterSetMapper.selectParameterSetByChannelId(channelId);
+            if (parameterSet != null) {
+                channelNumber.setIsChannel(Y);
+                channelNumber.setParameterSet(parameterSet);
+            }
+        }
+        return channelNumbers;
+
     }
 
     /**

+ 85 - 9
ruoyi-system/src/main/java/com/ruoyi/manage/service/impl/WarnManageServiceImpl.java

@@ -13,10 +13,8 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import java.text.DecimalFormat;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.text.SimpleDateFormat;
+import java.util.*;
 import java.util.stream.Collectors;
 
 import static com.ruoyi.common.constant.Constants.*;
@@ -131,11 +129,11 @@ public class WarnManageServiceImpl implements IWarnManageService {
             Map<String, List<WarnManage>> collect = warnManages.stream().collect(Collectors.groupingBy(WarnManage::getAlgorithmType));
             if (!collect.isEmpty()) {
                 //离岗
-                if (!collect.get(ZERO).isEmpty()) {
+                if (collect.get(ZERO) != null && !collect.get(ZERO).isEmpty()) {
                     warnMonthLastLeave = collect.get(ZERO).size();
                 }
                 //玩手机
-                if (!collect.get(ONE).isEmpty()) {
+                if (collect.get(ONE) != null && !collect.get(ONE).isEmpty()) {
                     warnMonthLastPlay = collect.get(ONE).size();
                 }
             }
@@ -161,11 +159,11 @@ public class WarnManageServiceImpl implements IWarnManageService {
                 Map<String, List<WarnManage>> collect = warnManagesLast.stream().collect(Collectors.groupingBy(WarnManage::getAlgorithmType));
                 if (!collect.isEmpty()) {
                     //离岗
-                    if (!collect.get(ZERO).isEmpty()) {
+                    if (collect.get(ZERO) != null && !collect.get(ZERO).isEmpty()) {
                         warnMonthLeave = collect.get(ZERO).size();
                     }
                     //玩手机
-                    if (!collect.get(ONE).isEmpty()) {
+                    if (collect.get(ONE) != null && !collect.get(ONE).isEmpty()) {
                         warnMonthLastPlay = collect.get(ONE).size();
                     }
                 }
@@ -205,7 +203,7 @@ public class WarnManageServiceImpl implements IWarnManageService {
                     for (Map<String, String> lastMonthDeptMap : finalDeptNameMapList) {
                         String deptNameLast = lastMonthDeptMap.get(deptName);
                         if (StringUtils.isNotEmpty(deptNameLast)) {
-                             warnNumLast = lastMonthDeptMap.get("warnNum");
+                            warnNumLast = lastMonthDeptMap.get("warnNum");
                         }
                     }
                 }
@@ -233,6 +231,84 @@ public class WarnManageServiceImpl implements IWarnManageService {
         return AjaxResult.success(map);
     }
 
+    /**
+     * 年度告警统计
+     * 接收年份查询
+     */
+    @Override
+    public AjaxResult warnManageIndexYear(String year) {
+        Map<String, Object> map = new HashMap<>();
+        //当前年份数据从数据库查询
+        if (StringUtils.isNotEmpty(year) && DateUtils.getYear().equals(year)) {
+            return warnManageIndexYearData(year);
+        } else {
+            map = redisCache.getCacheMap(WARN_MANAGE_LAST_YEAR + year);
+            if (map == null) {
+                return warnManageIndexYearData(year);
+            }
+        }
+        return AjaxResult.success(map);
+
+    }
+
+
+    /**
+     * 从数据库查询
+     *
+     * @param year
+     * @return
+     */
+    public AjaxResult warnManageIndexYearData(String year) {
+        //定义返回值
+        Map<String, Object> map = new HashMap<>(3);
+        List<String> x = new ArrayList<>(Arrays.asList("01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"));
+        List<Integer> y1 = new ArrayList<>();
+        List<Integer> y2 = new ArrayList<>();
+        WarnManage warnManage = new WarnManage();
+        Map<String, Object> params = new HashMap<>();
+        params.put("year", year);
+        warnManage.setParams(params);
+        //按年份检索的数据
+        List<WarnManage> warnManages = warnManageMapper.selectWarnManageList(warnManage);
+        if (warnManages != null && !warnManages.isEmpty()) {
+            // 使用Collectors.groupingBy按月份分组
+            Map<String, List<WarnManage>> WarnManageCollectMonth = warnManages.stream().collect(Collectors.groupingBy(item ->
+                    new SimpleDateFormat("MM").format(item.getWarnTime())));
+            for (String month : x) {
+                List<WarnManage> warnManagesMonthList = WarnManageCollectMonth.get(month);
+                //如果当月没有告警
+                if (warnManagesMonthList != null && !warnManagesMonthList.isEmpty()) {
+                    Map<String, List<WarnManage>> algorithmTypeCollect = warnManagesMonthList.stream().collect(Collectors.groupingBy(WarnManage::getAlgorithmType));
+                    if (algorithmTypeCollect != null && !algorithmTypeCollect.isEmpty()) {
+                        //离岗
+                        if (algorithmTypeCollect.get(ZERO) != null && !algorithmTypeCollect.get(ZERO).isEmpty()) {
+                            y1.add(algorithmTypeCollect.get(ZERO).size());
+                        } else {
+                            y1.add(0);
+                        }
+                        //玩手机
+                        if (algorithmTypeCollect.get(ONE) != null && !algorithmTypeCollect.get(ONE).isEmpty()) {
+                            y2.add(algorithmTypeCollect.get(ONE).size());
+                        } else {
+                            y2.add(0);
+                        }
+                    }
+                } else {
+                    y1.add(0);
+                    y2.add(0);
+                }
+            }
+        }
+        map.put("x", x);
+        map.put("y1", y1);
+        map.put("y2", y2);
+        //把非当前年份的数据存储到redis
+        if (StringUtils.isNotEmpty(year) && !DateUtils.getYear().equals(year)) {
+            redisCache.setCacheMap(WARN_MANAGE_LAST_YEAR + year, map);
+        }
+        return AjaxResult.success(map);
+    }
+
     public static List<Map<String, String>> convertObjectToList(Object obj) {
         // 1. 检查是否为 List 类型
         if (!(obj instanceof List<?>)) {

+ 6 - 3
ruoyi-system/src/main/resources/mapper/manage/WarnManageMapper.xml

@@ -62,7 +62,10 @@
             <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="warnTime != null ">and date_format(warn_time,'%Y%m%d') =date_format(#{warnTime},'%Y%m%d')</if>
+            <if test="params.year != null and params.year != ''"><!-- 年份检索 -->
+                AND date_format(warn_time,'%Y') = #{params.year}
+            </if>
         </where>
     </select>
 
@@ -72,8 +75,8 @@
         e.dept_name,e.dept_id
         from warn_manage w left join equipment_manage e on e.equipment_ip = w.equipment_ip
         <where>
-            del_flag = '0'
-            <if test="warnTime != null ">and date_format(warn_time,'%Y%m') =date_format(#{warnTime},'%Y%m'</if>
+            w.del_flag = '0'
+            <if test="warnTime != null ">and date_format(warn_time,'%Y%m') =date_format(#{warnTime},'%Y%m')</if>
         </where>
     </select>