fix: 修改风险趋势图和隐患趋势图统计

修改风险趋势图和隐患趋势图统计
main
zhangyu 2023-03-03 11:52:01 +08:00
parent f0d66f8110
commit 7c74ad3d93
10 changed files with 117 additions and 112 deletions

View File

@ -4,6 +4,7 @@ import java.util.Date;
import java.util.List; import java.util.List;
import com.hbt.safety.supervision.pojo.HiddenDanger; import com.hbt.safety.supervision.pojo.HiddenDanger;
import com.hbt.safety.supervision.pojo.vo.TrendVo;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
/** /**
@ -82,5 +83,5 @@ public interface HiddenDangerMapper
* @param endTime * @param endTime
* @return * @return
*/ */
List<String> selectHiddenDangerSubmitDat(@Param("startTime") String startTime, @Param("endTime") String endTime); List<TrendVo> selectHiddenDangerSubmitDat(@Param("startTime") String startTime, @Param("endTime") String endTime);
} }

View File

@ -5,6 +5,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import com.hbt.safety.supervision.pojo.Risk; import com.hbt.safety.supervision.pojo.Risk;
import com.hbt.safety.supervision.pojo.vo.TrendVo;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
@ -93,5 +94,5 @@ public interface RiskMapper
* @param endTime * @param endTime
* @return * @return
*/ */
List<String> selectRiskSubmitDat(@Param("startTime") String startTime, @Param("endTime") String endTime); List<TrendVo> selectRiskSubmitDat(@Param("startTime") String startTime, @Param("endTime") String endTime);
} }

View File

@ -0,0 +1,14 @@
package com.hbt.safety.supervision.pojo.vo;
import lombok.Data;
/**
* vo
*/
@Data
public class TrendVo {
private String date;
private int type;
}

View File

@ -2,6 +2,8 @@ package com.hbt.safety.supervision.pojo.vo;
import lombok.Data; import lombok.Data;
import java.util.List;
/** /**
* *
* *
@ -14,5 +16,5 @@ public class WeekDateVo {
private String date; private String date;
/** 数量 */ /** 数量 */
private int count; private List<StatisticsVo> list;
} }

View File

@ -10,6 +10,7 @@ import com.github.pagehelper.PageInfo;
import com.hbt.safety.supervision.mapper.HiddenDangerMapper; import com.hbt.safety.supervision.mapper.HiddenDangerMapper;
import com.hbt.safety.supervision.pojo.HiddenDanger; import com.hbt.safety.supervision.pojo.HiddenDanger;
import com.hbt.safety.supervision.pojo.vo.DateVo; import com.hbt.safety.supervision.pojo.vo.DateVo;
import com.hbt.safety.supervision.pojo.vo.TrendVo;
import com.hbt.safety.supervision.service.IHiddenDangerService; import com.hbt.safety.supervision.service.IHiddenDangerService;
import com.hbt.safety.supervision.util.StatisticsResultUtil; import com.hbt.safety.supervision.util.StatisticsResultUtil;
import com.hbt.safety.supervision.util.YearWeeksUtil; import com.hbt.safety.supervision.util.YearWeeksUtil;
@ -169,7 +170,7 @@ public class HiddenDangerServiceImpl implements IHiddenDangerService
String endTime = statisticsList.get(statisticsList.size()-1).get("endTime"); String endTime = statisticsList.get(statisticsList.size()-1).get("endTime");
// 查询时间范围内隐患数据 // 查询时间范围内隐患数据
List<String> list = hiddenDangerMapper.selectHiddenDangerSubmitDat(startTime, endTime); List<TrendVo> list = hiddenDangerMapper.selectHiddenDangerSubmitDat(startTime, endTime);
return YearWeeksUtil.getResultData(statisticsList, list, date); return YearWeeksUtil.getResultData(statisticsList, list, date, HIDDENDANGER_STATUS);
} }
} }

View File

@ -3,11 +3,10 @@ package com.hbt.safety.supervision.service.impl;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSON;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hbt.safety.supervision.mapper.RiskMapper; import com.hbt.safety.supervision.mapper.RiskMapper;
import com.hbt.safety.supervision.pojo.Risk; import com.hbt.safety.supervision.pojo.Risk;
import com.hbt.safety.supervision.pojo.vo.DateVo; import com.hbt.safety.supervision.pojo.vo.DateVo;
import com.hbt.safety.supervision.pojo.vo.TrendVo;
import com.hbt.safety.supervision.service.IRiskService; import com.hbt.safety.supervision.service.IRiskService;
import com.hbt.safety.supervision.util.StatisticsResultUtil; import com.hbt.safety.supervision.util.StatisticsResultUtil;
import com.hbt.safety.supervision.util.YearWeeksUtil; import com.hbt.safety.supervision.util.YearWeeksUtil;
@ -140,8 +139,8 @@ public class RiskServiceImpl implements IRiskService
String endTime = statisticsList.get(statisticsList.size()-1).get("endTime"); String endTime = statisticsList.get(statisticsList.size()-1).get("endTime");
// 查询时间范围内隐患数据 // 查询时间范围内隐患数据
List<String> list = riskMapper.selectRiskSubmitDat(startTime, endTime); List<TrendVo> list = riskMapper.selectRiskSubmitDat(startTime, endTime);
return YearWeeksUtil.getResultData(statisticsList, list, date); return YearWeeksUtil.getResultData(statisticsList, list, date, RISK_LEVEL);
} }
} }

View File

@ -10,15 +10,26 @@ import java.util.Map;
public class StatisticsResultUtil { public class StatisticsResultUtil {
public static String defaultResultStatistics(int count) { public static String defaultResultStatistics(int count) {
List<StatisticsVo> list = defaultResultStatisticsList(count);
return JSONObject.toJSONString(list);
}
public static String resultStatistics(int count, Map<Integer, Long> map) {
List<StatisticsVo> list = resultStatisticsList(count, map);
return JSONObject.toJSONString(list);
}
public static List<StatisticsVo> defaultResultStatisticsList(int count) {
List<StatisticsVo> list = new ArrayList<>(); List<StatisticsVo> list = new ArrayList<>();
for (int i = 1; i <= count; i++) { for (int i = 1; i <= count; i++) {
StatisticsVo statisticsVo = new StatisticsVo(i, 0); StatisticsVo statisticsVo = new StatisticsVo(i, 0);
list.add(statisticsVo); list.add(statisticsVo);
} }
return JSONObject.toJSONString(list); return list;
} }
public static String resultStatistics(int count, Map<Integer, Long> map) { public static List<StatisticsVo> resultStatisticsList(int count, Map<Integer, Long> map) {
List<StatisticsVo> list = new ArrayList<>(); List<StatisticsVo> list = new ArrayList<>();
// 组装数据数据 // 组装数据数据
for (int i =1; i <= count; i ++) { for (int i =1; i <= count; i ++) {
@ -27,6 +38,6 @@ public class StatisticsResultUtil {
statisticsVo.setCount(map.getOrDefault(i, 0L).intValue()); statisticsVo.setCount(map.getOrDefault(i, 0L).intValue());
list.add(statisticsVo); list.add(statisticsVo);
} }
return JSONObject.toJSONString(list); return list;
} }
} }

View File

@ -3,6 +3,7 @@ package com.hbt.safety.supervision.util;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.hbt.common.core.utils.DateUtils; import com.hbt.common.core.utils.DateUtils;
import com.hbt.safety.supervision.pojo.vo.DateVo; import com.hbt.safety.supervision.pojo.vo.DateVo;
import com.hbt.safety.supervision.pojo.vo.TrendVo;
import com.hbt.safety.supervision.pojo.vo.WeekDateVo; import com.hbt.safety.supervision.pojo.vo.WeekDateVo;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
@ -132,39 +133,6 @@ public class YearWeeksUtil {
return week; return week;
} }
/**
*
*
* @param list
* @return
*/
public static String dealWeekDate(List<Date> list) {
List<Integer> weekList = new ArrayList<>();
// 遍历风险时间,计算每个时间的周数
for (Date date : list) {
// 计算上报风险时间,与一年前时间间的周数
int week = weekBetweenYearAgoDate(date);
weekList.add(week);
}
// 获取当前时间和往前推一年间的周数
int weeks = getYearWeekConut();
List<WeekDateVo> weekDates = new ArrayList<>();
// 筛选数据
for (int i = 1; i <= weeks; i++) {
WeekDateVo weekDateVo = new WeekDateVo();
int finalI = i;
int count = (int) weekList.stream().filter(s -> s == finalI).count();
weekDateVo.setDate(i+"");
weekDateVo.setCount(count);
weekDates.add(weekDateVo);
}
// 处理数据
return JSONObject.toJSONString(weekDates);
}
/** /**
* *
* *
@ -339,17 +307,25 @@ public class YearWeeksUtil {
return dateVo; return dateVo;
} }
public static String getResultData(List<Map<String, String>> statisticsList, List<String> list, List<String> date) { public static String getResultData(List<Map<String, String>> statisticsList, List<TrendVo> list, List<String> date, int count) {
List<WeekDateVo> weekDateVos = new ArrayList<>(); List<WeekDateVo> weekDateVos = new ArrayList<>();
// 组装数据 // 组装数据
for (int i = 0; i < statisticsList.size(); i++) { for (int i = 0; i < statisticsList.size(); i++) {
int finalI = i; int finalI = i;
int hiddenDangerCount = (int) list.stream()
.filter(s -> YearWeeksUtil.belongCalendar(s, statisticsList.get(finalI).get("startTime"), List<TrendVo> trendVos = list.stream()
statisticsList.get(finalI).get("endTime"))).count(); .filter(s -> YearWeeksUtil.belongCalendar(s.getDate(), statisticsList.get(finalI).get("startTime"),
statisticsList.get(finalI).get("endTime"))).collect(Collectors.toList());
WeekDateVo weekDateVo = new WeekDateVo(); WeekDateVo weekDateVo = new WeekDateVo();
weekDateVo.setDate(date.get(i)); weekDateVo.setDate(date.get(i));
weekDateVo.setCount(hiddenDangerCount);
if(CollectionUtils.isEmpty(list)) {
weekDateVo.setList(StatisticsResultUtil.defaultResultStatisticsList(count));
} else {
Map<Integer, Long> map = trendVos.stream()
.collect(Collectors.groupingBy(TrendVo::getType, Collectors.counting()));
weekDateVo.setList(StatisticsResultUtil.resultStatisticsList(count, map));
}
weekDateVos.add(weekDateVo); weekDateVos.add(weekDateVo);
} }
return JSONObject.toJSONString(weekDateVos); return JSONObject.toJSONString(weekDateVos);

View File

@ -121,7 +121,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
select id, name, reform_status reformStatus from hidden_danger where exceed_time_limit_status = 0 select id, name, reform_status reformStatus from hidden_danger where exceed_time_limit_status = 0
</select> </select>
<select id="selectHiddenDangerSubmitDat" resultType="String"> <select id="selectHiddenDangerSubmitDat" resultType="com.hbt.safety.supervision.pojo.vo.TrendVo">
select DATE_FORMAT(submit_date,'%Y-%m-%d') submit_date from hidden_danger where DATE_FORMAT(submit_date,'%Y-%m-%d') >= #{startTime} and DATE_FORMAT(submit_date,'%Y-%m-%d') &lt;= #{endTime} select DATE_FORMAT(submit_date,'%Y-%m-%d') date , reform_status type from hidden_danger where DATE_FORMAT(submit_date,'%Y-%m-%d') >= #{startTime} and DATE_FORMAT(submit_date,'%Y-%m-%d') &lt;= #{endTime}
</select> </select>
</mapper> </mapper>

View File

@ -115,7 +115,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
select DATE_FORMAT(submit_date,'%Y-%m-%d %H:%i:%S') as submit_date from risk where DATE_FORMAT(submit_date,'%Y-%m-%d') >= DATE_FORMAT(#{yearAgo},'%Y-%m-%d') select DATE_FORMAT(submit_date,'%Y-%m-%d %H:%i:%S') as submit_date from risk where DATE_FORMAT(submit_date,'%Y-%m-%d') >= DATE_FORMAT(#{yearAgo},'%Y-%m-%d')
</select> </select>
<select id="selectRiskSubmitDat" resultType="String"> <select id="selectRiskSubmitDat" resultType="TrendVo">
select DATE_FORMAT(submit_date,'%Y-%m-%d') as submit_date from risk where DATE_FORMAT(submit_date,'%Y-%m-%d') >= #{startTime} and DATE_FORMAT(submit_date,'%Y-%m-%d') &lt;= #{endTime} select DATE_FORMAT(submit_date,'%Y-%m-%d') as date , level as type from risk where DATE_FORMAT(submit_date,'%Y-%m-%d') >= #{startTime} and DATE_FORMAT(submit_date,'%Y-%m-%d') &lt;= #{endTime}
</select> </select>
</mapper> </mapper>