|
@@ -13,10 +13,8 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.text.DecimalFormat;
|
|
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 java.util.stream.Collectors;
|
|
|
|
|
|
import static com.ruoyi.common.constant.Constants.*;
|
|
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));
|
|
Map<String, List<WarnManage>> collect = warnManages.stream().collect(Collectors.groupingBy(WarnManage::getAlgorithmType));
|
|
if (!collect.isEmpty()) {
|
|
if (!collect.isEmpty()) {
|
|
//离岗
|
|
//离岗
|
|
- if (!collect.get(ZERO).isEmpty()) {
|
|
|
|
|
|
+ if (collect.get(ZERO) != null && !collect.get(ZERO).isEmpty()) {
|
|
warnMonthLastLeave = collect.get(ZERO).size();
|
|
warnMonthLastLeave = collect.get(ZERO).size();
|
|
}
|
|
}
|
|
//玩手机
|
|
//玩手机
|
|
- if (!collect.get(ONE).isEmpty()) {
|
|
|
|
|
|
+ if (collect.get(ONE) != null && !collect.get(ONE).isEmpty()) {
|
|
warnMonthLastPlay = collect.get(ONE).size();
|
|
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));
|
|
Map<String, List<WarnManage>> collect = warnManagesLast.stream().collect(Collectors.groupingBy(WarnManage::getAlgorithmType));
|
|
if (!collect.isEmpty()) {
|
|
if (!collect.isEmpty()) {
|
|
//离岗
|
|
//离岗
|
|
- if (!collect.get(ZERO).isEmpty()) {
|
|
|
|
|
|
+ if (collect.get(ZERO) != null && !collect.get(ZERO).isEmpty()) {
|
|
warnMonthLeave = collect.get(ZERO).size();
|
|
warnMonthLeave = collect.get(ZERO).size();
|
|
}
|
|
}
|
|
//玩手机
|
|
//玩手机
|
|
- if (!collect.get(ONE).isEmpty()) {
|
|
|
|
|
|
+ if (collect.get(ONE) != null && !collect.get(ONE).isEmpty()) {
|
|
warnMonthLastPlay = collect.get(ONE).size();
|
|
warnMonthLastPlay = collect.get(ONE).size();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -205,7 +203,7 @@ public class WarnManageServiceImpl implements IWarnManageService {
|
|
for (Map<String, String> lastMonthDeptMap : finalDeptNameMapList) {
|
|
for (Map<String, String> lastMonthDeptMap : finalDeptNameMapList) {
|
|
String deptNameLast = lastMonthDeptMap.get(deptName);
|
|
String deptNameLast = lastMonthDeptMap.get(deptName);
|
|
if (StringUtils.isNotEmpty(deptNameLast)) {
|
|
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);
|
|
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) {
|
|
public static List<Map<String, String>> convertObjectToList(Object obj) {
|
|
// 1. 检查是否为 List 类型
|
|
// 1. 检查是否为 List 类型
|
|
if (!(obj instanceof List<?>)) {
|
|
if (!(obj instanceof List<?>)) {
|