forked from xxhjsb/wit-park-backend
接口变更
parent
41212ab886
commit
60c758f8c6
|
@ -103,7 +103,12 @@ public class HazardousOperationController extends BaseController {
|
||||||
return hazardousOperationService.hazardousOperationVariationTendency();
|
return hazardousOperationService.hazardousOperationVariationTendency();
|
||||||
}
|
}
|
||||||
|
|
||||||
// todo 按危险作业等级统计
|
/**
|
||||||
|
* 按危险作业等级统计
|
||||||
|
*/
|
||||||
|
@ApiOperation("危险作业页-按危险作业等级统计")
|
||||||
|
@GetMapping(value = "/hazardousOperationLevelStatistics")
|
||||||
|
public String hazardousOperationLevelStatistics() {
|
||||||
|
return hazardousOperationService.hazardousOperationLevelStatistics();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -108,6 +108,4 @@ public class RiskController extends BaseController
|
||||||
public String weeklyQuantityStatistics() {
|
public String weeklyQuantityStatistics() {
|
||||||
return riskService.weeklyQuantityStatistics();
|
return riskService.weeklyQuantityStatistics();
|
||||||
}
|
}
|
||||||
|
|
||||||
// todo 风险项类型及数量统计
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package com.hbt.safety.supervision.mapper;
|
package com.hbt.safety.supervision.mapper;
|
||||||
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import com.hbt.safety.supervision.pojo.HazardousOperation;
|
import com.hbt.safety.supervision.pojo.HazardousOperation;
|
||||||
|
|
||||||
|
@ -62,7 +62,7 @@ public interface HazardousOperationMapper
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询统计所需数据
|
* 查询统计所需数据
|
||||||
* @return
|
* @return 统计数据
|
||||||
*/
|
*/
|
||||||
List<HazardousOperation> selectHazardousOperations();
|
List<HazardousOperation> selectHazardousOperations();
|
||||||
|
|
||||||
|
@ -76,8 +76,13 @@ public interface HazardousOperationMapper
|
||||||
/**
|
/**
|
||||||
* 进行中/已备案作业数量变化趋势图
|
* 进行中/已备案作业数量变化趋势图
|
||||||
*
|
*
|
||||||
* @param yearAgo 当前时间往前推一年的时间
|
* @param startTime 当前时间往前推一年的时间
|
||||||
* @return 返回值
|
* @return 返回值
|
||||||
*/
|
*/
|
||||||
List<Date> hazardousOperationVariationTendency(Date yearAgo);
|
List<HazardousOperation> hazardousOperationVariationTendency(String startTime);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 按危险作业等级统计
|
||||||
|
*/
|
||||||
|
List<Map<Object, Object>> hazardousOperationLevelStatistics();
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 隐患Mapper接口
|
* 隐患Mapper接口
|
||||||
|
@ -72,4 +73,6 @@ public interface HiddenDangerMapper
|
||||||
* @return 返回值
|
* @return 返回值
|
||||||
*/
|
*/
|
||||||
List<Date> selectHiddenDangerSubmitDats(Date yearAgo);
|
List<Date> selectHiddenDangerSubmitDats(Date yearAgo);
|
||||||
|
|
||||||
|
List<Date> selectHiddenDangerSubmitDat(@Param("startTime") String startTime, @Param("endTime") String endTime);
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ import java.util.Map;
|
||||||
|
|
||||||
import com.hbt.safety.supervision.pojo.Risk;
|
import com.hbt.safety.supervision.pojo.Risk;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 风险Mapper接口
|
* 风险Mapper接口
|
||||||
|
@ -85,4 +86,13 @@ public interface RiskMapper
|
||||||
*/
|
*/
|
||||||
List<Date> selectRiskSubmitDats(Date yearAgo);
|
List<Date> selectRiskSubmitDats(Date yearAgo);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 风险项每周数量统计
|
||||||
|
*
|
||||||
|
* @param startTime 开始时间
|
||||||
|
* @param endTime 结束时间
|
||||||
|
* @return 返回值
|
||||||
|
*/
|
||||||
|
List<Date> selectRiskSubmitDat(@Param("startTime") String startTime, @Param("endTime") String endTime);
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,7 @@ public class HazardousOperation extends BaseEntity
|
||||||
|
|
||||||
/** 危险作业等级 */
|
/** 危险作业等级 */
|
||||||
@ApiModelProperty(value = "危险作业等级")
|
@ApiModelProperty(value = "危险作业等级")
|
||||||
private String operationLevel;
|
private int operationLevel;
|
||||||
|
|
||||||
/** 责任企业id */
|
/** 责任企业id */
|
||||||
@ApiModelProperty(value = "责任企业id")
|
@ApiModelProperty(value = "责任企业id")
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
package com.hbt.safety.supervision.pojo.vo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class DateVo {
|
||||||
|
|
||||||
|
/** 日期和周集合 */
|
||||||
|
private List<String> date;
|
||||||
|
|
||||||
|
/** 周的跨度 */
|
||||||
|
private List<Map<String, String>> statisticsList;
|
||||||
|
}
|
|
@ -0,0 +1,19 @@
|
||||||
|
package com.hbt.safety.supervision.pojo.vo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 危险操作折线图统计
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class HazardousOperationWeekDateVo {
|
||||||
|
|
||||||
|
/** 时间 */
|
||||||
|
private String date;
|
||||||
|
|
||||||
|
/** 进行中的数量 */
|
||||||
|
private int onGoingCount;
|
||||||
|
|
||||||
|
/** 待开始的数量 */
|
||||||
|
private int toBeStartedCount;
|
||||||
|
}
|
|
@ -8,7 +8,7 @@ import lombok.Data;
|
||||||
@Data
|
@Data
|
||||||
public class WeekDateVo {
|
public class WeekDateVo {
|
||||||
|
|
||||||
private int week; // 周数
|
private String date; // 周数
|
||||||
|
|
||||||
private int count; // 数量
|
private int count; // 数量
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,4 +75,9 @@ public interface IHazardousOperationService
|
||||||
* 进行中/已备案作业数量变化趋势图
|
* 进行中/已备案作业数量变化趋势图
|
||||||
*/
|
*/
|
||||||
String hazardousOperationVariationTendency();
|
String hazardousOperationVariationTendency();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 按危险作业等级统计
|
||||||
|
*/
|
||||||
|
String hazardousOperationLevelStatistics();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,21 +1,20 @@
|
||||||
package com.hbt.safety.supervision.service.impl;
|
package com.hbt.safety.supervision.service.impl;
|
||||||
|
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.hbt.safety.supervision.pojo.HazardousOperation;
|
import com.hbt.safety.supervision.pojo.HazardousOperation;
|
||||||
|
import com.hbt.safety.supervision.pojo.vo.DateVo;
|
||||||
|
import com.hbt.safety.supervision.pojo.vo.HazardousOperationWeekDateVo;
|
||||||
import com.hbt.safety.supervision.pojo.vo.StatisticsVo;
|
import com.hbt.safety.supervision.pojo.vo.StatisticsVo;
|
||||||
import com.hbt.safety.supervision.pojo.vo.WeekDateVo;
|
|
||||||
import com.hbt.safety.supervision.util.YearWeeksUtil;
|
import com.hbt.safety.supervision.util.YearWeeksUtil;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import com.hbt.safety.supervision.mapper.HazardousOperationMapper;
|
import com.hbt.safety.supervision.mapper.HazardousOperationMapper;
|
||||||
import com.hbt.safety.supervision.service.IHazardousOperationService;
|
import com.hbt.safety.supervision.service.IHazardousOperationService;
|
||||||
|
|
||||||
import static com.hbt.safety.supervision.util.YearWeeksUtil.getYearWeekConut;
|
|
||||||
import static com.hbt.safety.supervision.util.YearWeeksUtil.weekBetweenYearAgoDate;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 危险作业Service业务层处理
|
* 危险作业Service业务层处理
|
||||||
*
|
*
|
||||||
|
@ -194,37 +193,50 @@ public class HazardousOperationServiceImpl implements IHazardousOperationService
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String hazardousOperationVariationTendency() {
|
public String hazardousOperationVariationTendency() {
|
||||||
|
DateVo dateVo = YearWeeksUtil.getYeardate();
|
||||||
// 获取当前时间往前推一年的时间
|
List<Map<String, String>> statisticsList = dateVo.getStatisticsList();
|
||||||
Date yearAgo = YearWeeksUtil.getyearAgoDate();
|
List<String> date = dateVo.getDate();
|
||||||
|
if (statisticsList == null || date == null || statisticsList.size() == 0
|
||||||
|
|| date.size() == 0 || statisticsList.size() != date.size()) {
|
||||||
// 获取当前时间及往前推一年的危险作业开始结束时间
|
return null;
|
||||||
List<Date> list = hazardousOperationMapper.hazardousOperationVariationTendency(yearAgo);
|
|
||||||
|
|
||||||
List<Integer> operationWeekList = new ArrayList<>();
|
|
||||||
// 遍历危险作业,计算每个时间的周数
|
|
||||||
for (Date date : list) {;
|
|
||||||
// 计算上报风险危险作业结束时间,与一年前时间间的周数
|
|
||||||
int endWeek = weekBetweenYearAgoDate(date);
|
|
||||||
operationWeekList.add(endWeek);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取当前时间和往前推一年间的周数
|
// 查询时间范围内的隐患信息
|
||||||
int weeks = getYearWeekConut();
|
String startTime = statisticsList.get(0).get("startTime");
|
||||||
|
|
||||||
List<WeekDateVo> weekDates = new ArrayList<>();
|
List<HazardousOperation> hazardousOperations = hazardousOperationMapper.hazardousOperationVariationTendency(startTime);
|
||||||
// 筛选数据
|
|
||||||
for (int i = 1; i <= weeks; i++) {
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
||||||
WeekDateVo weekDateVo = new WeekDateVo();
|
List<HazardousOperationWeekDateVo> hazardousOperationWeekDateVos = new ArrayList<>();
|
||||||
|
// 组装数据
|
||||||
|
for (int i = 0; i < statisticsList.size(); i++) {
|
||||||
int finalI = i;
|
int finalI = i;
|
||||||
// 筛选 当前作业结束时间大于等于当前周的作业,即为进行中、待开始的作业
|
// 筛选进行中的数量 进行中:作业开始时间大于等于周开始的时间,小于等于周结束的时间 或者作业结束时间大于等周开始时间小于等于周结束时间
|
||||||
int count = (int) operationWeekList.stream().filter(s -> finalI <= s).count();
|
int onGoingCount = (int) hazardousOperations.stream()
|
||||||
weekDateVo.setDate(i+"");
|
.filter(s -> (sdf.format(s.getOperationStart()).compareTo(statisticsList.get(finalI).get("startTime")) >=0
|
||||||
weekDateVo.setCount(count);
|
&& sdf.format(s.getOperationStart()).compareTo(statisticsList.get(finalI).get("endTime")) <= 0)
|
||||||
weekDates.add(weekDateVo);
|
|| (sdf.format(s.getOperationEnd()).compareTo(statisticsList.get(finalI).get("startTime")) >= 0
|
||||||
|
&& sdf.format(s.getOperationEnd()).compareTo(statisticsList.get(finalI).get("endTime")) <= 0)).count();
|
||||||
|
|
||||||
|
// 筛选待开始的数量 待开始:周结束时间小于 作业开始时间
|
||||||
|
int toBeStartedCount = (int) hazardousOperations.stream()
|
||||||
|
.filter(s -> sdf.format(s.getOperationStart()).compareTo(statisticsList.get(finalI).get("endTime")) > 0).count();
|
||||||
|
HazardousOperationWeekDateVo hazardousOperationWeekDateVo = new HazardousOperationWeekDateVo();
|
||||||
|
hazardousOperationWeekDateVo.setDate(date.get(i));
|
||||||
|
hazardousOperationWeekDateVo.setOnGoingCount(onGoingCount);
|
||||||
|
hazardousOperationWeekDateVo.setToBeStartedCount(toBeStartedCount);
|
||||||
|
hazardousOperationWeekDateVos.add(hazardousOperationWeekDateVo);
|
||||||
|
|
||||||
}
|
}
|
||||||
// 处理数据
|
return JSONObject.toJSONString(hazardousOperationWeekDateVos);
|
||||||
return JSONObject.toJSONString(weekDates);
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 按危险作业等级统计
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String hazardousOperationLevelStatistics() {
|
||||||
|
List<Map<Object, Object>> map = hazardousOperationMapper.hazardousOperationLevelStatistics();
|
||||||
|
return JSONObject.toJSONString(map);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ import java.util.stream.Collectors;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
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.StatisticsVo;
|
import com.hbt.safety.supervision.pojo.vo.StatisticsVo;
|
||||||
import com.hbt.safety.supervision.service.IHiddenDangerService;
|
import com.hbt.safety.supervision.service.IHiddenDangerService;
|
||||||
import com.hbt.safety.supervision.util.YearWeeksUtil;
|
import com.hbt.safety.supervision.util.YearWeeksUtil;
|
||||||
|
@ -139,12 +140,19 @@ public class HiddenDangerServiceImpl implements IHiddenDangerService
|
||||||
*/
|
*/
|
||||||
public String hiddenDangerWeeklyStatistics() {
|
public String hiddenDangerWeeklyStatistics() {
|
||||||
|
|
||||||
// 获取当前时间往前推一年的时间
|
DateVo dateVo = YearWeeksUtil.getYeardate();
|
||||||
Date yearAgo = YearWeeksUtil.getyearAgoDate();
|
List<Map<String, String>> statisticsList = dateVo.getStatisticsList();
|
||||||
|
List<String> date = dateVo.getDate();
|
||||||
|
if (statisticsList == null || date == null || statisticsList.size() == 0
|
||||||
|
|| date.size() == 0 || statisticsList.size() != date.size()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
// 查询时间范围内的隐患信息
|
||||||
|
String startTime = statisticsList.get(0).get("startTime");
|
||||||
|
String endTime = statisticsList.get(statisticsList.size()-1).get("endTime");
|
||||||
|
|
||||||
// 获取当前时间及往前推一年的风险时间
|
// 查询时间范围内隐患数据
|
||||||
List<Date> list = hiddenDangerMapper.selectHiddenDangerSubmitDats(yearAgo);
|
List<Date> list = hiddenDangerMapper.selectHiddenDangerSubmitDat(startTime, endTime);
|
||||||
|
return YearWeeksUtil.getResultData(statisticsList, list, date);
|
||||||
return YearWeeksUtil.dealWeekDate(list);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ import java.util.stream.Collectors;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
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.service.IRiskService;
|
import com.hbt.safety.supervision.service.IRiskService;
|
||||||
import com.hbt.safety.supervision.util.YearWeeksUtil;
|
import com.hbt.safety.supervision.util.YearWeeksUtil;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
@ -106,7 +107,7 @@ public class RiskServiceImpl implements IRiskService
|
||||||
if (list == null) {
|
if (list == null) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
Map<Object, List<Risk>> map = list.stream().collect(Collectors.groupingBy(s -> s.getLevel()));
|
Map<Object, List<Risk>> map = list.stream().collect(Collectors.groupingBy(Risk::getLevel));
|
||||||
return JSONObject.toJSONString(map);
|
return JSONObject.toJSONString(map);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,12 +115,23 @@ public class RiskServiceImpl implements IRiskService
|
||||||
* 风险项每周数量统计
|
* 风险项每周数量统计
|
||||||
*/
|
*/
|
||||||
public String weeklyQuantityStatistics() {
|
public String weeklyQuantityStatistics() {
|
||||||
// 获取当前时间往前推一年的时间
|
|
||||||
Date yearAgo = YearWeeksUtil.getyearAgoDate();
|
|
||||||
|
|
||||||
// 获取当前时间及往前推一年的风险时间
|
|
||||||
List<Date> list = riskMapper.selectRiskSubmitDats(yearAgo);
|
|
||||||
|
|
||||||
return YearWeeksUtil.dealWeekDate(list);
|
DateVo dateVo = YearWeeksUtil.getYeardate();
|
||||||
|
List<Map<String, String>> statisticsList = dateVo.getStatisticsList();
|
||||||
|
List<String> date = dateVo.getDate();
|
||||||
|
if (statisticsList == null || date == null || statisticsList.size() == 0
|
||||||
|
|| date.size() == 0 || statisticsList.size() != date.size()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 查询时间范围内的隐患信息
|
||||||
|
String startTime = statisticsList.get(0).get("startTime");
|
||||||
|
String endTime = statisticsList.get(statisticsList.size()-1).get("endTime");
|
||||||
|
|
||||||
|
// 查询时间范围内隐患数据
|
||||||
|
List<Date> list = riskMapper.selectRiskSubmitDat(startTime, endTime);
|
||||||
|
|
||||||
|
return YearWeeksUtil.getResultData(statisticsList, list, date);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,15 @@
|
||||||
package com.hbt.safety.supervision.util;
|
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.safety.supervision.pojo.vo.DateVo;
|
||||||
import com.hbt.safety.supervision.pojo.vo.WeekDateVo;
|
import com.hbt.safety.supervision.pojo.vo.WeekDateVo;
|
||||||
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 时间工具类
|
* 时间工具类
|
||||||
|
@ -15,6 +20,9 @@ public class YearWeeksUtil {
|
||||||
* 定义12个月常量*/
|
* 定义12个月常量*/
|
||||||
public static final int MONTH = 12;
|
public static final int MONTH = 12;
|
||||||
|
|
||||||
|
public static final String START_TIME = "startTime";
|
||||||
|
public static final String END_TIME = "endTime";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取当前年
|
* 获取当前年
|
||||||
*
|
*
|
||||||
|
@ -74,6 +82,17 @@ public class YearWeeksUtil {
|
||||||
return calendar.getTime();
|
return calendar.getTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前时间 数据今年第几周
|
||||||
|
*
|
||||||
|
* @return 时间
|
||||||
|
*/
|
||||||
|
public static int getNowWeek () {
|
||||||
|
Calendar calendar = Calendar.getInstance();
|
||||||
|
calendar.setTime(new Date());
|
||||||
|
return calendar.get(Calendar.WEEK_OF_YEAR);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取当前时间 往前推一年的月份
|
* 获取当前时间 往前推一年的月份
|
||||||
*
|
*
|
||||||
|
@ -137,11 +156,203 @@ public class YearWeeksUtil {
|
||||||
WeekDateVo weekDateVo = new WeekDateVo();
|
WeekDateVo weekDateVo = new WeekDateVo();
|
||||||
int finalI = i;
|
int finalI = i;
|
||||||
int count = (int) weekList.stream().filter(s -> s == finalI).count();
|
int count = (int) weekList.stream().filter(s -> s == finalI).count();
|
||||||
weekDateVo.setWeek(i);
|
weekDateVo.setDate(i+"");
|
||||||
weekDateVo.setCount(count);
|
weekDateVo.setCount(count);
|
||||||
weekDates.add(weekDateVo);
|
weekDates.add(weekDateVo);
|
||||||
}
|
}
|
||||||
// 处理数据
|
// 处理数据
|
||||||
return JSONObject.toJSONString(weekDates);
|
return JSONObject.toJSONString(weekDates);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取某年某周的时间跨度
|
||||||
|
*
|
||||||
|
* @param year 年份
|
||||||
|
* @param week 周数
|
||||||
|
* @return k-v
|
||||||
|
*/
|
||||||
|
public static Map<String, String> getWeekRangeMap(int year, int week) {
|
||||||
|
Map<String, String> dateMap = new HashMap<>(8);
|
||||||
|
Calendar calendar = Calendar.getInstance();
|
||||||
|
calendar.set(Calendar.YEAR, year);
|
||||||
|
// 设置星期一为一周开始的第一天
|
||||||
|
calendar.setFirstDayOfWeek(Calendar.MONDAY);
|
||||||
|
// 可以不用设置
|
||||||
|
calendar.setMinimalDaysInFirstWeek(4);
|
||||||
|
// 获得当前的年
|
||||||
|
int weekYear = calendar.get(Calendar.YEAR);
|
||||||
|
// 获得指定年的第几周的开始日期(星期几)
|
||||||
|
calendar.setWeekDate(weekYear, week, Calendar.MONDAY);
|
||||||
|
Date time = calendar.getTime();
|
||||||
|
String startTime = new SimpleDateFormat(DateUtils.YYYY_MM_DD).format(time);
|
||||||
|
dateMap.put(START_TIME, startTime);
|
||||||
|
// 获得指定年的第几周的结束日期(星期几)
|
||||||
|
calendar.setWeekDate(weekYear, week, Calendar.SUNDAY);
|
||||||
|
time = calendar.getTime();
|
||||||
|
String endTime = new SimpleDateFormat(DateUtils.YYYY_MM_DD).format(time);
|
||||||
|
dateMap.put(END_TIME, endTime);
|
||||||
|
return dateMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取某年有多少周
|
||||||
|
*
|
||||||
|
* @param year 年份
|
||||||
|
* @return 当前年份的总周数
|
||||||
|
*/
|
||||||
|
public static int getYearWeekCount(int year) {
|
||||||
|
int week = 52;
|
||||||
|
try {
|
||||||
|
Map<String, String> timeMap = getWeekRangeMap(year, 53);
|
||||||
|
if (!CollectionUtils.isEmpty(timeMap)) {
|
||||||
|
String startTime = timeMap.get(START_TIME);
|
||||||
|
if (startTime.substring(0, 4).equals(year + "")) {
|
||||||
|
// 判断年度是否相符,如果相符说明有53个周。
|
||||||
|
week = 53;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return week;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取某年所有周的日期跨度
|
||||||
|
*
|
||||||
|
* @param year 年份
|
||||||
|
* @return list 当前年份所有周的日期范围
|
||||||
|
*/
|
||||||
|
public static List<Map<String, String>> getYearWeekMap(int year) {
|
||||||
|
int weeks = getYearWeekCount(year);
|
||||||
|
List<Map<String, String>> yearWeekMap = new ArrayList<>();
|
||||||
|
for (int i = 1; i <= weeks; i++) {
|
||||||
|
Map<String, String> dateMap = getWeekRangeMap(year, i);
|
||||||
|
yearWeekMap.add(dateMap);
|
||||||
|
}
|
||||||
|
return yearWeekMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Description: 判断一个时间是否在一个时间段内 </br>
|
||||||
|
*
|
||||||
|
* @param nowTime 当前时间 </br>
|
||||||
|
* @param beginTime 开始时间 </br>
|
||||||
|
* @param endTime 结束时间 </br>
|
||||||
|
*/
|
||||||
|
public static boolean belongCalendar(String nowTime, String beginTime, String endTime) {
|
||||||
|
Calendar date = Calendar.getInstance();
|
||||||
|
date.setTime(java.sql.Date.valueOf(nowTime));
|
||||||
|
Calendar begin = Calendar.getInstance();
|
||||||
|
begin.setTime(java.sql.Date.valueOf(beginTime));
|
||||||
|
Calendar end = Calendar.getInstance();
|
||||||
|
end.setTime(java.sql.Date.valueOf(endTime));
|
||||||
|
return (date.after(begin) && date.before(end)) || nowTime.equals(beginTime) || nowTime.equals(endTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取往前推一年的所有周和 范围数据
|
||||||
|
* W
|
||||||
|
*/
|
||||||
|
public static DateVo getYeardate() {
|
||||||
|
int year = getCurrentYear();
|
||||||
|
int lastYear = year - 1;
|
||||||
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
||||||
|
String dateNowStr = sdf.format(new Date());
|
||||||
|
List<Map<String, String>> thisYearList = getYearWeekMap(year);
|
||||||
|
List<Map<String, String>> lastYearList = getYearWeekMap(year - 1);
|
||||||
|
List<Map<String, String>> statisticsList = new ArrayList<>();
|
||||||
|
List<String> date = new ArrayList<>();
|
||||||
|
|
||||||
|
// 查看当前时间属于今年的周还是去年。如2023-01-01 属于去年最后一个周
|
||||||
|
int count = (int) thisYearList.stream()
|
||||||
|
.filter(s -> belongCalendar(dateNowStr, s.get("startTime"),s.get("endTime"))).count();
|
||||||
|
if (count == 0) {
|
||||||
|
// 当前时间不属于今年的周
|
||||||
|
count = (int) lastYearList.stream()
|
||||||
|
.filter(s -> belongCalendar(dateNowStr, s.get("startTime"),s.get("endTime"))).count();
|
||||||
|
if (count == 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
int lastYearCount = lastYearList.size();
|
||||||
|
lastYearList = lastYearList.stream()
|
||||||
|
.filter(s -> s.get("endTime").compareTo(dateNowStr) < 0)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
if (lastYearList.size() < 52) {
|
||||||
|
// 前年数据统计
|
||||||
|
List<Map<String, String>> beforeLastYearList = getYearWeekMap(year - 1);
|
||||||
|
|
||||||
|
int beforeYearCount = beforeLastYearList.size();
|
||||||
|
// 前年年年份需统计周数
|
||||||
|
int beforeLastYearWeek = 52 - lastYearList.size();
|
||||||
|
// 获取前年需统计数据
|
||||||
|
beforeLastYearList = beforeLastYearList.subList(beforeLastYearList.size() - beforeLastYearWeek, beforeLastYearList.size());
|
||||||
|
statisticsList.addAll(beforeLastYearList);
|
||||||
|
// 判断前年从第几周开始算起
|
||||||
|
int beforeYearStartWeek = beforeYearCount - beforeLastYearList.size() + 1;
|
||||||
|
int beforYear = year - 2;
|
||||||
|
for (int i = 0; i < beforeLastYearList.size() ;i ++) {
|
||||||
|
int week = beforeYearStartWeek + i;
|
||||||
|
date.add(beforYear + "-" + week);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
statisticsList.addAll(lastYearList);
|
||||||
|
// 判断去年从第几周开始算起
|
||||||
|
int lastYearStartWeek = lastYearCount - lastYearList.size() + 1;
|
||||||
|
for (int i = 0; i < lastYearList.size() ;i ++) {
|
||||||
|
int week = lastYearStartWeek + i;
|
||||||
|
date.add(lastYear + "-" + week);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 获取今年所需统计的周
|
||||||
|
thisYearList = thisYearList.stream()
|
||||||
|
.filter(s -> s.get("endTime").compareTo(dateNowStr) < 0)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
if (thisYearList.size() < 52) {
|
||||||
|
// 去年年份需统计周数
|
||||||
|
int lastYearWeek = 52 - thisYearList.size();
|
||||||
|
int lastYearCount = lastYearList.size();
|
||||||
|
// 获取去年需统计数据
|
||||||
|
lastYearList = lastYearList.subList(lastYearList.size() - lastYearWeek, lastYearList.size());
|
||||||
|
statisticsList.addAll(lastYearList);
|
||||||
|
|
||||||
|
// 判断去年从第几周开始算起
|
||||||
|
int lastYearStartWeek = lastYearCount - lastYearList.size() + 1;
|
||||||
|
for (int i = 0; i < lastYearList.size() ;i ++) {
|
||||||
|
int week = lastYearStartWeek + i;
|
||||||
|
date.add(lastYear + "-" + week);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
statisticsList.addAll(thisYearList);
|
||||||
|
|
||||||
|
// 判断今年从第几周开始算起
|
||||||
|
for (int i = 0; i < thisYearList.size() ;i ++) {
|
||||||
|
int week = i + 1;
|
||||||
|
date.add(year + "-" + week);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
DateVo dateVo = new DateVo();
|
||||||
|
dateVo.setDate(date);
|
||||||
|
dateVo.setStatisticsList(statisticsList);
|
||||||
|
return dateVo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getResultData(List<Map<String, String>> statisticsList, List<Date> list, List<String> date) {
|
||||||
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
||||||
|
List<WeekDateVo> weekDateVos = new ArrayList<>();
|
||||||
|
// 组装数据
|
||||||
|
for (int i = 0; i < statisticsList.size(); i++) {
|
||||||
|
int finalI = i;
|
||||||
|
int hiddenDangerCount = (int) list.stream()
|
||||||
|
.filter(s -> YearWeeksUtil.belongCalendar(sdf.format(s), statisticsList.get(finalI).get("startTime"),
|
||||||
|
statisticsList.get(finalI).get("endTime"))).count();
|
||||||
|
WeekDateVo weekDateVo = new WeekDateVo();
|
||||||
|
weekDateVo.setDate(date.get(i));
|
||||||
|
weekDateVo.setCount(hiddenDangerCount);
|
||||||
|
weekDateVos.add(weekDateVo);
|
||||||
|
}
|
||||||
|
return JSONObject.toJSONString(weekDateVos);
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -107,7 +107,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
left join enterprise_information as e on a.enterprise_id = e.id
|
left join enterprise_information as e on a.enterprise_id = e.id
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="hazardousOperationVariationTendency" resultType="java.util.Date">
|
<select id="hazardousOperationVariationTendency" resultType="HazardousOperation">
|
||||||
select operation_end from hazardous_operation where DATE_FORMAT(operation_start,'%Y-%m-%d') >= DATE_FORMAT(#{yearAgo},'%Y-%m-%d')
|
select operation_start operationStart, operation_end operationEnd from hazardous_operation where DATE_FORMAT(operation_start,'%Y-%m-%d') >= #{startTime}
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select id="hazardousOperationLevelStatistics" resultType="java.util.Map">
|
||||||
|
select operation_level as level, count(id) as count from hazardous_operation group by operation_level
|
||||||
</select>
|
</select>
|
||||||
</mapper>
|
</mapper>
|
|
@ -121,4 +121,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
<select id="selectHiddenDangerSubmitDats" resultType="java.util.Date">
|
<select id="selectHiddenDangerSubmitDats" resultType="java.util.Date">
|
||||||
select submit_date from hidden_danger where DATE_FORMAT(submit_date,'%Y-%m-%d') >= DATE_FORMAT(#{yearAgo},'%Y-%m-%d')
|
select submit_date from hidden_danger where DATE_FORMAT(submit_date,'%Y-%m-%d') >= DATE_FORMAT(#{yearAgo},'%Y-%m-%d')
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<select id="selectHiddenDangerSubmitDat" resultType="java.util.Date">
|
||||||
|
select submit_date from hidden_danger where DATE_FORMAT(submit_date,'%Y-%m-%d') >= #{startTime} and DATE_FORMAT(submit_date,'%Y-%m-%d') <= #{endTime}
|
||||||
|
</select>
|
||||||
</mapper>
|
</mapper>
|
|
@ -111,4 +111,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
<select id="selectRiskSubmitDats" resultType="java.util.Date">
|
<select id="selectRiskSubmitDats" resultType="java.util.Date">
|
||||||
select submit_date from risk where DATE_FORMAT(submit_date,'%Y-%m-%d') >= DATE_FORMAT(#{yearAgo},'%Y-%m-%d')
|
select submit_date from risk where DATE_FORMAT(submit_date,'%Y-%m-%d') >= DATE_FORMAT(#{yearAgo},'%Y-%m-%d')
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<select id="selectRiskSubmitDat" resultType="java.util.Date">
|
||||||
|
select submit_date from risk where DATE_FORMAT(submit_date,'%Y-%m-%d') >= #{startTime} and DATE_FORMAT(submit_date,'%Y-%m-%d') <= #{endTime}
|
||||||
|
</select>
|
||||||
</mapper>
|
</mapper>
|
Loading…
Reference in New Issue