package com.gkhy.safePlatform.doublePrevention.service.impl;
|
|
import com.gkhy.safePlatform.account.rpc.apimodel.AccountDepartmentService;
|
import com.gkhy.safePlatform.account.rpc.apimodel.model.resp.DepInfoRPCRespDTO;
|
import com.gkhy.safePlatform.commons.enums.E;
|
import com.gkhy.safePlatform.commons.exception.AusinessException;
|
import com.gkhy.safePlatform.commons.vo.ResultVO;
|
import com.gkhy.safePlatform.doublePrevention.entity.dto.DataCountI1RespDO;
|
import com.gkhy.safePlatform.doublePrevention.entity.dto.DataCountI2RespDO;
|
import com.gkhy.safePlatform.doublePrevention.entity.dto.req.DataCountI1ReqDTO;
|
import com.gkhy.safePlatform.doublePrevention.entity.dto.req.DataCountI2ReqDTO;
|
import com.gkhy.safePlatform.doublePrevention.entity.dto.resp.DataCountI1RespDTO;
|
import com.gkhy.safePlatform.doublePrevention.entity.dto.resp.DataCountI2RespDTO;
|
import com.gkhy.safePlatform.doublePrevention.repository.param.DataCountIMonthParams;
|
import com.gkhy.safePlatform.doublePrevention.service.DataCountService;
|
import com.gkhy.safePlatform.doublePrevention.service.baseService.PreventDangerManageService;
|
import org.apache.commons.lang3.ObjectUtils;
|
import org.apache.dubbo.config.annotation.DubboReference;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
|
import java.text.ParseException;
|
import java.text.SimpleDateFormat;
|
import java.util.*;
|
|
@Service
|
public class DataCountServiceImpl implements DataCountService {
|
|
@DubboReference(check = false)
|
private AccountDepartmentService accountDepartmentService;
|
|
@Autowired
|
private PreventDangerManageService preventDangerManageService;
|
|
/**
|
* 数据统计-隐患数据统计-I1计算
|
*/
|
@Override
|
public DataCountI1RespDTO listMonthDataCountI1(DataCountI1ReqDTO dataCountI1ReqDTO){
|
|
|
//获取时间格式化工具
|
SimpleDateFormat monthFormat = new SimpleDateFormat("yyyy-MM-dd");
|
|
StringBuffer time = new StringBuffer();
|
String year = dataCountI1ReqDTO.getYear().toString();
|
String month;
|
if (dataCountI1ReqDTO.getMonth() < 10) {
|
month = "0" + dataCountI1ReqDTO.getMonth().toString();
|
}else {
|
month = dataCountI1ReqDTO.getMonth().toString();
|
}
|
time.append(year + "-" + month + "-" + "01");
|
//确定开始时间
|
Date startTime = null;
|
|
try {
|
startTime = monthFormat.parse(String.valueOf(time));
|
} catch (ParseException e) {
|
throw new RuntimeException(e);
|
}
|
|
//确定结束时间
|
Calendar calendar = Calendar.getInstance();
|
calendar.setTime(startTime);//设置起时间
|
calendar.add(Calendar.MONTH, +1);//增加1个月
|
Date endTime = calendar.getTime();
|
|
//封装查询参数
|
DataCountIMonthParams countParams = new DataCountIMonthParams();
|
countParams.setStartTime(startTime);
|
countParams.setEndTime(endTime);
|
DepInfoRPCRespDTO depInfo = new DepInfoRPCRespDTO();
|
//如果depId不为空
|
if (ObjectUtils.isNotEmpty(dataCountI1ReqDTO.getDepId())){
|
//获取部门信息
|
ResultVO<DepInfoRPCRespDTO> depInfoByDepId = accountDepartmentService.getDepInfoByDepId(dataCountI1ReqDTO.getDepId());
|
depInfo = (DepInfoRPCRespDTO) depInfoByDepId.getData();
|
if (ObjectUtils.isEmpty(depInfo)){
|
throw new AusinessException(E.DATA_DATABASE_NO_EXISTENT, "部门已经被删除");
|
}
|
//获取部门及所有子部门信息
|
ResultVO<List<Long>> listResultVO = accountDepartmentService.listDepAndSubDepIds(dataCountI1ReqDTO.getDepId());
|
if (ObjectUtils.isEmpty(listResultVO)){
|
throw new AusinessException(E.DATA_DATABASE_NO_EXISTENT, "部门不存在");
|
}
|
List<Long> ids = (List<Long>) listResultVO.getData();
|
countParams.setIds(ids);
|
}
|
|
DataCountI1RespDO dataCountI1RespDO = preventDangerManageService.listMonthDataCountI1(countParams);
|
|
DataCountI1RespDTO respDTO = new DataCountI1RespDTO();
|
//封装返回值
|
respDTO.setRiskCount(dataCountI1RespDO.getA());
|
respDTO.setDeathCount(dataCountI1RespDO.getA1());
|
respDTO.setHeavyInjureCount(dataCountI1RespDO.getA2());
|
respDTO.setLightInjureCount(dataCountI1RespDO.getA3());
|
respDTO.setYear(dataCountI1ReqDTO.getYear());
|
respDTO.setMonth(dataCountI1ReqDTO.getMonth());
|
respDTO.setDepId(dataCountI1ReqDTO.getDepId());
|
respDTO.setDep(depInfo.getDepName());
|
|
|
return respDTO;
|
}
|
/**
|
* 数据统计-隐患数据统计-I1计算 - 年
|
*/
|
@Override
|
public List<DataCountI1RespDTO> listYearDataCountI1(DataCountI1ReqDTO dataCountI1ReqDTO) {
|
|
//获取时间格式化工具
|
SimpleDateFormat monthFormat = new SimpleDateFormat("yyyy-MM-dd");
|
StringBuffer time = new StringBuffer();
|
String year = dataCountI1ReqDTO.getYear().toString();
|
Date date = new Date();
|
|
time.append(year + "-" + "01" + "-" + "01");
|
//确定开始时间
|
Date originTime = null;
|
try {
|
originTime = monthFormat.parse(String.valueOf(time));
|
} catch (ParseException e) {
|
throw new RuntimeException(e);
|
}
|
//获得本月第一天
|
Calendar calendar = new GregorianCalendar();
|
calendar.setTime(date);
|
calendar.add(Calendar.MONTH, 0);
|
calendar.set(Calendar.DAY_OF_MONTH, 1);
|
Date firstDay = calendar.getTime();
|
|
Date startTime = originTime;
|
Date endTime = null;
|
//获取list
|
List<DataCountI1RespDTO> list = new ArrayList<>();
|
List<Long> ids = new ArrayList<>();
|
DepInfoRPCRespDTO depInfo = new DepInfoRPCRespDTO();
|
|
//如果depId不为空
|
if (ObjectUtils.isNotEmpty(dataCountI1ReqDTO.getDepId())){
|
ResultVO<DepInfoRPCRespDTO> depInfoByDepId = accountDepartmentService.getDepInfoByDepId(dataCountI1ReqDTO.getDepId());
|
depInfo = (DepInfoRPCRespDTO) depInfoByDepId.getData();
|
if (ObjectUtils.isEmpty(depInfo)){
|
throw new AusinessException(E.DATA_DATABASE_NO_EXISTENT, "部门已经被删除");
|
}
|
ResultVO<List<Long>> listResultVO = accountDepartmentService.listDepAndSubDepIds(dataCountI1ReqDTO.getDepId());
|
if (ObjectUtils.isEmpty(listResultVO)){
|
throw new AusinessException(E.DATA_DATABASE_NO_EXISTENT, "部门不存在");
|
}
|
ids = (List<Long>) listResultVO.getData();
|
}
|
|
//循环统计本年度数据
|
int i = 1;
|
while (originTime.getTime() < firstDay.getTime()){
|
calendar.setTime(startTime);//设置起时间
|
calendar.add(Calendar.MONTH, +1);//增加1个月
|
endTime = calendar.getTime();
|
//封装查询参数
|
DataCountIMonthParams countParams = new DataCountIMonthParams();
|
countParams.setStartTime(startTime);
|
countParams.setEndTime(endTime);
|
countParams.setIds(ids);
|
//查询
|
DataCountI1RespDO dataCountI1RespDO = preventDangerManageService.listMonthDataCountI1(countParams);
|
DataCountI1RespDTO respDTO = new DataCountI1RespDTO();
|
//封装返回值
|
respDTO.setRiskCount(dataCountI1RespDO.getA());
|
respDTO.setDeathCount(dataCountI1RespDO.getA1());
|
respDTO.setHeavyInjureCount(dataCountI1RespDO.getA2());
|
respDTO.setLightInjureCount(dataCountI1RespDO.getA3());
|
respDTO.setYear(dataCountI1ReqDTO.getYear());
|
respDTO.setMonth(i);
|
//todo 部门相关信息
|
respDTO.setDepId(dataCountI1ReqDTO.getDepId());
|
respDTO.setDep(depInfo.getDepName());
|
|
list.add(respDTO);
|
originTime = endTime;
|
startTime = endTime;
|
i ++;
|
}
|
|
return list;
|
}
|
|
/**
|
* 数据统计-隐患等级-I2计算 - 月
|
*/
|
@Override
|
public DataCountI2RespDTO listMonthDataCountI2(DataCountI2ReqDTO dataCountI2ReqDTO){
|
|
//获取时间格式化工具
|
SimpleDateFormat monthFormat = new SimpleDateFormat("yyyy-MM-dd");
|
|
StringBuffer time = new StringBuffer();
|
String year = dataCountI2ReqDTO.getYear().toString();
|
String month;
|
if (dataCountI2ReqDTO.getMonth() < 10) {
|
month = "0" + dataCountI2ReqDTO.getMonth().toString();
|
}else {
|
month = dataCountI2ReqDTO.getMonth().toString();
|
}
|
time.append(year + "-" + month + "-" + "01");
|
//确定开始时间
|
Date startTime = null;
|
try {
|
startTime = monthFormat.parse(String.valueOf(time));
|
} catch (ParseException e) {
|
throw new RuntimeException(e);
|
}
|
//确定结束时间
|
Calendar calendar = Calendar.getInstance();
|
calendar.setTime(startTime);//设置起时间
|
calendar.add(Calendar.MONTH, +1);//增加1个月
|
Date endTime = calendar.getTime();
|
DepInfoRPCRespDTO depInfo = new DepInfoRPCRespDTO();
|
|
//封装查询参数
|
DataCountIMonthParams countParams = new DataCountIMonthParams();
|
countParams.setStartTime(startTime);
|
countParams.setEndTime(endTime);
|
//如果depId不为空
|
if (ObjectUtils.isNotEmpty(dataCountI2ReqDTO.getDepId())){
|
//todo 部门相关信息
|
ResultVO<DepInfoRPCRespDTO> depInfoByDepId = accountDepartmentService.getDepInfoByDepId(dataCountI2ReqDTO.getDepId());
|
depInfo = (DepInfoRPCRespDTO) depInfoByDepId.getData();
|
if (ObjectUtils.isEmpty(depInfo)){
|
throw new AusinessException(E.DATA_DATABASE_NO_EXISTENT, "部门已经被删除");
|
}
|
ResultVO<List<Long>> listResultVO = accountDepartmentService.listDepAndSubDepIds(dataCountI2ReqDTO.getDepId());
|
if (ObjectUtils.isEmpty(listResultVO)){
|
throw new AusinessException(E.DATA_DATABASE_NO_EXISTENT, "部门不存在");
|
}
|
List<Long> ids = (List<Long>) listResultVO.getData();
|
countParams.setIds(ids);
|
}
|
|
DataCountI2RespDO dataCountI2RespDO = preventDangerManageService.listMonthDataCountI2(countParams);
|
DataCountI2RespDTO respDTO = new DataCountI2RespDTO();
|
//封装返回值
|
respDTO.setHeavyRiskCount(dataCountI2RespDO.getB1());
|
respDTO.setHeavyRiskRectifyCount(dataCountI2RespDO.getB1Rectify());
|
respDTO.setLightRiskCount(dataCountI2RespDO.getB2());
|
respDTO.setLightRiskRectifyCount(dataCountI2RespDO.getB2Rectify());
|
respDTO.setMonth(dataCountI2ReqDTO.getYear());
|
respDTO.setMonth(dataCountI2ReqDTO.getMonth());
|
respDTO.setDepId(dataCountI2ReqDTO.getDepId());
|
respDTO.setDep(depInfo.getDepName());
|
|
return respDTO;
|
}
|
/**
|
* 数据统计-隐患数据统计-I2计算 - 年
|
*/
|
@Override
|
public List<DataCountI2RespDTO> listYearDataCountI2(DataCountI2ReqDTO dataCountI2ReqDTO){
|
|
//获取时间格式化工具
|
SimpleDateFormat monthFormat = new SimpleDateFormat("yyyy-MM-dd");
|
StringBuffer time = new StringBuffer();
|
String year = dataCountI2ReqDTO.getYear().toString();
|
Date date = new Date();
|
|
time.append(year + "-" + "01" + "-" + "01");
|
//确定开始时间
|
Date originTime = null;
|
try {
|
originTime = monthFormat.parse(String.valueOf(time));
|
} catch (ParseException e) {
|
throw new RuntimeException(e);
|
}
|
//获得本月第一天
|
Calendar calendar = new GregorianCalendar();
|
calendar.setTime(date);
|
calendar.add(Calendar.MONTH, 0);
|
calendar.set(Calendar.DAY_OF_MONTH, 1);
|
Date firstDay = calendar.getTime();
|
|
Date startTime = originTime;
|
Date endTime = null;
|
//获取list
|
List<DataCountI2RespDTO> list = new ArrayList<>();
|
List<Long> ids = new ArrayList<>();
|
DepInfoRPCRespDTO depInfo = new DepInfoRPCRespDTO();
|
|
//如果depId不为空
|
if (ObjectUtils.isNotEmpty(dataCountI2ReqDTO.getDepId())){
|
ResultVO<DepInfoRPCRespDTO> depInfoByDepId = accountDepartmentService.getDepInfoByDepId(dataCountI2ReqDTO.getDepId());
|
depInfo = (DepInfoRPCRespDTO) depInfoByDepId.getData();
|
if (ObjectUtils.isEmpty(depInfo)){
|
throw new AusinessException(E.DATA_DATABASE_NO_EXISTENT, "部门已经被删除");
|
}
|
ResultVO<List<Long>> listResultVO = accountDepartmentService.listDepAndSubDepIds(dataCountI2ReqDTO.getDepId());
|
if (ObjectUtils.isEmpty(listResultVO)){
|
throw new AusinessException(E.DATA_DATABASE_NO_EXISTENT, "部门不存在");
|
}
|
ids = (List<Long>) listResultVO.getData();
|
}
|
|
//循环统计年度数据
|
int i = 1;
|
while (originTime.getTime() < firstDay.getTime()){
|
calendar.setTime(startTime);//设置起时间
|
calendar.add(Calendar.MONTH, +1);//增加1个月
|
endTime = calendar.getTime();
|
//封装查询参数
|
DataCountIMonthParams countParams = new DataCountIMonthParams();
|
countParams.setStartTime(startTime);
|
countParams.setEndTime(endTime);
|
countParams.setIds(ids);
|
//查询
|
DataCountI2RespDO dataCountI2RespDO = preventDangerManageService.listMonthDataCountI2(countParams);
|
DataCountI2RespDTO respDTO = new DataCountI2RespDTO();
|
//封装返回值
|
respDTO.setHeavyRiskCount(dataCountI2RespDO.getB1());
|
respDTO.setHeavyRiskRectifyCount(dataCountI2RespDO.getB1Rectify());
|
respDTO.setLightRiskCount(dataCountI2RespDO.getB2());
|
respDTO.setLightRiskRectifyCount(dataCountI2RespDO.getB2Rectify());
|
respDTO.setMonth(dataCountI2ReqDTO.getMonth());
|
respDTO.setYear(dataCountI2ReqDTO.getYear());
|
respDTO.setMonth(i);
|
respDTO.setDepId(dataCountI2ReqDTO.getDepId());
|
respDTO.setDep(depInfo.getDepName());
|
|
list.add(respDTO);
|
originTime = endTime;
|
startTime = endTime;
|
i++;
|
}
|
|
return list;
|
}
|
}
|