Merge remote-tracking branch 'origin/main'

# Conflicts:
#	hbt-safety-supervision/hbt-safety-supervision-biz/src/main/java/com/hbt/safety/supervision/service/impl/HiddenDangerServiceImpl.java
main
fengxiaoyu 2023-02-20 18:31:26 +08:00
commit 4ac9c74480
14 changed files with 218 additions and 80 deletions

View File

@ -86,4 +86,13 @@ public class HazardousOperationController extends BaseController {
public String hazardousOperationManagement() { public String hazardousOperationManagement() {
return hazardousOperationService.hazardousOperationManagement(); return hazardousOperationService.hazardousOperationManagement();
} }
/**
* /
*/
@GetMapping(value = "/hazardousOperationVariationTendency")
public String hazardousOperationVariationTendency() {
return hazardousOperationService.hazardousOperationVariationTendency();
}
} }

View File

@ -97,6 +97,7 @@ public class RiskController extends BaseController
/** /**
* *
*
*/ */
@GetMapping("/weeklyQuantityStatistics") @GetMapping("/weeklyQuantityStatistics")
public String weeklyQuantityStatistics() { public String weeklyQuantityStatistics() {

View File

@ -1,5 +1,6 @@
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 com.hbt.safety.supervision.pojo.HazardousOperation; import com.hbt.safety.supervision.pojo.HazardousOperation;
@ -71,4 +72,12 @@ public interface HazardousOperationMapper
* @return * @return
*/ */
List<HazardousOperation> hazardousOperationManagement(); List<HazardousOperation> hazardousOperationManagement();
/**
* /
*
* @param yearAgo
* @return
*/
List<Date> hazardousOperationVariationTendency(Date yearAgo);
} }

View File

@ -1,5 +1,6 @@
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 com.hbt.safety.supervision.pojo.HiddenDanger; import com.hbt.safety.supervision.pojo.HiddenDanger;
@ -68,8 +69,8 @@ public interface HiddenDangerMapper
/** /**
* *
* *
* @param year * @param yearAgo
* @return * @return
*/ */
List<Integer> selectHiddenDangerSubmitDats(int year); List<Date> selectHiddenDangerSubmitDats(Date yearAgo);
} }

View File

@ -81,9 +81,9 @@ public interface RiskMapper
/** /**
* *
* *
* @param year * @param yearAgo
* @return * @return
*/ */
List<Integer> selectRiskSubmitDats(int year); List<Date> selectRiskSubmitDats(Date yearAgo);
} }

View File

@ -0,0 +1,14 @@
package com.hbt.safety.supervision.pojo.vo;
import lombok.Data;
/**
*
*/
@Data
public class WeekDateVo {
private int week; // 周数
private int count; // 数量
}

View File

@ -60,7 +60,20 @@ public interface IHazardousOperationService
*/ */
int deleteHazardousOperationById(int id); int deleteHazardousOperationById(int id);
/**
*
*
* @return
*/
String hazardousOperationStatistics(); String hazardousOperationStatistics();
/**
*
*/
String hazardousOperationManagement(); String hazardousOperationManagement();
/**
* /
*/
String hazardousOperationVariationTendency();
} }

View File

@ -6,11 +6,16 @@ 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.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 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
* *
@ -149,6 +154,9 @@ public class HazardousOperationServiceImpl implements IHazardousOperationService
return JSONObject.toJSONString(map); return JSONObject.toJSONString(map);
} }
/**
*
*/
@Override @Override
public String hazardousOperationManagement() { public String hazardousOperationManagement() {
// 获取当前时间 // 获取当前时间
@ -180,4 +188,41 @@ public class HazardousOperationServiceImpl implements IHazardousOperationService
map.put("historyHazardousOperation", historyHazardousOperation); map.put("historyHazardousOperation", historyHazardousOperation);
return JSONObject.toJSONString(map); return JSONObject.toJSONString(map);
} }
/**
* /
*
*/
@Override
public String hazardousOperationVariationTendency() {
// 获取当前时间往前推一年的时间
Date yearAgo = YearWeeksUtil.getyearAgoDate();
// 获取当前时间及往前推一年的危险作业开始结束时间
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();
List<WeekDateVo> weekDates = new ArrayList<>();
// 筛选数据
for (int i = 1; i <= weeks; i++) {
WeekDateVo weekDateVo = new WeekDateVo();
int finalI = i;
// 筛选 当前作业结束时间大于等于当前周的作业,即为进行中、待开始的作业
int count = (int) operationWeekList.stream().filter(s -> finalI <= s).count();
weekDateVo.setWeek(i);
weekDateVo.setCount(count);
weekDates.add(weekDateVo);
}
// 处理数据
return JSONObject.toJSONString(weekDates);
}
} }

View File

@ -142,10 +142,13 @@ public class HiddenDangerServiceImpl implements IHiddenDangerService
* @return * @return
*/ */
public String hiddenDangerWeeklyStatistics() { public String hiddenDangerWeeklyStatistics() {
// 获取当前年份
int year = YearWeeksUtil.getCurrentYear(); // 获取当前时间往前推一年的时间
List<Integer> list = hiddenDangerMapper.selectHiddenDangerSubmitDats(year); Date yearAgo = YearWeeksUtil.getyearAgoDate();
// 处理数据
return YearWeeksUtil.dealWeekDate(list, year); // 获取当前时间及往前推一年的风险时间
List<Date> list = hiddenDangerMapper.selectHiddenDangerSubmitDats(yearAgo);
return YearWeeksUtil.dealWeekDate(list);
} }
} }

View File

@ -1,11 +1,7 @@
package com.hbt.safety.supervision.service.impl; package com.hbt.safety.supervision.service.impl;
import java.util.Date; import java.util.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
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.mapper.RiskMapper; import com.hbt.safety.supervision.mapper.RiskMapper;
import com.hbt.safety.supervision.pojo.Risk; import com.hbt.safety.supervision.pojo.Risk;
@ -119,10 +115,12 @@ public class RiskServiceImpl implements IRiskService
* *
*/ */
public String weeklyQuantityStatistics() { public String weeklyQuantityStatistics() {
// 获取当前年份 // 获取当前时间往前推一年的时间
int year = YearWeeksUtil.getCurrentYear(); Date yearAgo = YearWeeksUtil.getyearAgoDate();
List<Integer> list = riskMapper.selectRiskSubmitDats(year);
// 处理数据 // 获取当前时间及往前推一年的风险时间
return YearWeeksUtil.dealWeekDate(list, year); List<Date> list = riskMapper.selectRiskSubmitDats(yearAgo);
return YearWeeksUtil.dealWeekDate(list);
} }
} }

View File

@ -1,11 +1,10 @@
package com.hbt.safety.supervision.util; package com.hbt.safety.supervision.util;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import org.springframework.util.CollectionUtils; import com.hbt.safety.supervision.pojo.vo.WeekDateVo;
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;
/** /**
* *
@ -19,73 +18,115 @@ public class YearWeeksUtil {
*/ */
public static int getCurrentYear() { public static int getCurrentYear() {
Calendar calendar = Calendar.getInstance(); Calendar calendar = Calendar.getInstance();
int weekYear = calendar.get(Calendar.YEAR);//获得当前的年 return calendar.get(Calendar.YEAR);
return weekYear;
}
/**
*
* @param year
* @param week
* @return
*/
public static Map<String, String> getWeekRangeMap(int year, int week) {
Map<String, String> timeMap = new HashMap<>();
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, 2);//获得指定年的第几周的开始日期
Date time=calendar.getTime();
String startTime = new SimpleDateFormat("yyyy-MM-dd").format(time)+" 00:00:00";
timeMap.put("startTime",startTime);
calendar.setWeekDate(weekYear, week, 1);//获得指定年的第几周的结束日期
time=calendar.getTime();
String endTime = new SimpleDateFormat("yyyy-MM-dd").format(time)+" 23:59:59";
timeMap.put("endTime",endTime);
return timeMap;
} }
/** /**
* *
* *
* @param year * @return
* @return
* @throws ParseException
*/ */
public static int getYearWeekConut(int year){ public static int getYearWeekConut() {
int week = 52; // 获取当前时间
Date nowDate = getNowDate();
// 获取当前时间 往前推一年的时间
Date yearAgo = getyearAgoDate();
// 计算两个时间之间的天数
return weekBetween(yearAgo, nowDate);
}
/**
*
*
* @param date
* @return
*/
public static int weekBetweenYearAgoDate(Date date) {
// 获取一年前的时间
Date yearAgo = getyearAgoDate();
// 获取周数
return weekBetween(yearAgo, date);
}
/**
*
*
* @return
*/
private static Date getNowDate () {
Calendar calendar = Calendar.getInstance();
calendar.setTime(new Date());
return calendar.getTime();
}
/**
*
*
* @return
*/
public static Date getyearAgoDate () {
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.YEAR, -1);
return calendar.getTime();
}
/**
*
*
* @param start
* @param end
* @return
*/
private static int weekBetween(Date start, Date end) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
try { try {
Map<String, String> timeMap = getWeekRangeMap(year,53); start = sdf.parse(sdf.format(start));
if(!CollectionUtils.isEmpty(timeMap)){ end = sdf.parse(sdf.format(end));
String startTime = timeMap.get("startTime"); } catch (ParseException e) {
if(startTime.substring(0, 4).equals(year+"")){ //判断年度是否相符如果相符说明有53个周。
week = 53;
}
}
} catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
long startTime = start.getTime();
long endTime = end.getTime();
long betweenDays = (endTime - startTime) / (1000 * 3600 * 24);
int days = Integer.parseInt(String.valueOf(betweenDays));
int week;
if (days % 7 == 0) {
week = days / 7;
} else {
week = (days / 7) + 1;
}
return week; return week;
} }
public static String dealWeekDate(List<Integer> list, int year) { /**
Map<Object, List<Integer>> weekList = new HashMap<>(); *
if (list != null) { *
weekList = list.stream().collect(Collectors.groupingBy(s -> s)); * @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);
} }
Map<Integer, Integer> weekStatistics = new HashMap<>();
// 获取当前年份周数 // 获取当前时间和往前推一年间的周数
int week = YearWeeksUtil.getYearWeekConut(year); int weeks = getYearWeekConut();
for (int i = 1; i <= week; i++) {
if (weekList.containsKey(i)) { List<WeekDateVo> weekDates = new ArrayList<>();
weekStatistics.put(i, weekList.get(i).size()); // 筛选数据
} else { for (int i = 1; i <= weeks; i++) {
weekStatistics.put(i, 0); WeekDateVo weekDateVo = new WeekDateVo();
} int finalI = i;
int count = (int) weekList.stream().filter(s -> s == finalI).count();
weekDateVo.setWeek(i);
weekDateVo.setCount(count);
weekDates.add(weekDateVo);
} }
return JSONObject.toJSONString(weekStatistics); // 处理数据
return JSONObject.toJSONString(weekDates);
} }
} }

View File

@ -103,4 +103,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="hazardousOperationManagement" resultType="HazardousOperation"> <select id="hazardousOperationManagement" resultType="HazardousOperation">
select name,operation_start operationStart ,operation_end operationEnd from hazardous_operation select name,operation_start operationStart ,operation_end operationEnd from hazardous_operation
</select> </select>
<select id="hazardousOperationVariationTendency" resultType="java.util.Date">
select operation_end from hazardous_operation where DATE_FORMAT(operation_start,'%Y-%m-%d') >= DATE_FORMAT(#{yearAgo},'%Y-%m-%d')
</select>
</mapper> </mapper>

View File

@ -118,7 +118,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
select name, reform_status reformStatus from hidden_danger where exceed_time_limit_status = 0 select name, reform_status reformStatus from hidden_danger where exceed_time_limit_status = 0
</select> </select>
<select id="selectHiddenDangerSubmitDats" resultType="Integer"> <select id="selectHiddenDangerSubmitDats" resultType="java.util.Date">
select WEEK(submit_date, 1) + 1 from hidden_danger where YEAR(submit_date) = #{year} select submit_date from hidden_danger where DATE_FORMAT(submit_date,'%Y-%m-%d') >= DATE_FORMAT(#{yearAgo},'%Y-%m-%d')
</select> </select>
</mapper> </mapper>

View File

@ -108,7 +108,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
select name, level from risk select name, level from risk
</select> </select>
<select id="selectRiskSubmitDats" resultType="Integer"> <select id="selectRiskSubmitDats" resultType="java.util.Date">
select WEEK(submit_date, 1) + 1 from risk where YEAR(submit_date) = #{year} select submit_date from risk where DATE_FORMAT(submit_date,'%Y-%m-%d') >= DATE_FORMAT(#{yearAgo},'%Y-%m-%d')
</select> </select>
</mapper> </mapper>