yang_shj
2 years ago
41 changed files with 1239 additions and 60 deletions
@ -0,0 +1,13 @@ |
|||||||
|
package com.hnac.hzims.scheduled.mapper.inspect; |
||||||
|
|
||||||
|
import com.hnac.hzinfo.inspect.task.entity.TaskEntity; |
||||||
|
import org.apache.ibatis.annotations.Mapper; |
||||||
|
import org.springblade.core.datascope.mapper.UserDataScopeBaseMapper; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author ysj |
||||||
|
*/ |
||||||
|
@Mapper |
||||||
|
public interface TaskMapper extends UserDataScopeBaseMapper<TaskEntity> { |
||||||
|
|
||||||
|
} |
@ -0,0 +1,11 @@ |
|||||||
|
package com.hnac.hzims.scheduled.mapper.operation; |
||||||
|
|
||||||
|
import com.hnac.hzims.operational.defect.entity.OperPhenomenonEntity; |
||||||
|
import org.springblade.core.datascope.mapper.UserDataScopeBaseMapper; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author ysj |
||||||
|
*/ |
||||||
|
public interface PhenomenonMapper extends UserDataScopeBaseMapper<OperPhenomenonEntity> { |
||||||
|
|
||||||
|
} |
@ -0,0 +1,10 @@ |
|||||||
|
package com.hnac.hzims.scheduled.mapper.safeproduct; |
||||||
|
|
||||||
|
import com.hnac.hzims.safeproduct.entity.CheckCompanyEntity; |
||||||
|
import org.springblade.core.datascope.mapper.UserDataScopeBaseMapper; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author ysj |
||||||
|
*/ |
||||||
|
public interface CompanyMapper extends UserDataScopeBaseMapper<CheckCompanyEntity> { |
||||||
|
} |
@ -0,0 +1,11 @@ |
|||||||
|
package com.hnac.hzims.scheduled.mapper.safeproduct; |
||||||
|
|
||||||
|
import com.hnac.hzims.safeproduct.entity.CheckMonthEntity; |
||||||
|
import org.springblade.core.datascope.mapper.UserDataScopeBaseMapper; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author ysj |
||||||
|
*/ |
||||||
|
public interface MonthMapper extends UserDataScopeBaseMapper<CheckMonthEntity> { |
||||||
|
|
||||||
|
} |
@ -0,0 +1,11 @@ |
|||||||
|
package com.hnac.hzims.scheduled.mapper.safeproduct; |
||||||
|
|
||||||
|
import com.hnac.hzims.safeproduct.entity.SafeEquipmentTrialEntity; |
||||||
|
import org.springblade.core.datascope.mapper.UserDataScopeBaseMapper; |
||||||
|
|
||||||
|
/** |
||||||
|
* 设备试验mapper接口 |
||||||
|
*/ |
||||||
|
public interface TrialMapper extends UserDataScopeBaseMapper<SafeEquipmentTrialEntity> { |
||||||
|
|
||||||
|
} |
@ -0,0 +1,15 @@ |
|||||||
|
package com.hnac.hzims.scheduled.service.inspect; |
||||||
|
|
||||||
|
import com.hnac.hzinfo.inspect.task.entity.TaskEntity; |
||||||
|
import com.hnac.hzinfo.inspect.task.vo.DutyInspectTaskVO; |
||||||
|
import org.springblade.core.mp.base.BaseService; |
||||||
|
|
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author ysj |
||||||
|
*/ |
||||||
|
public interface TaskService extends BaseService<TaskEntity> { |
||||||
|
|
||||||
|
DutyInspectTaskVO task(String start, String end, List<Long> areas); |
||||||
|
} |
@ -0,0 +1,64 @@ |
|||||||
|
package com.hnac.hzims.scheduled.service.inspect.impl; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
||||||
|
import com.hnac.hzims.scheduled.mapper.inspect.TaskMapper; |
||||||
|
import com.hnac.hzims.scheduled.service.inspect.TaskService; |
||||||
|
import com.hnac.hzinfo.inspect.task.entity.TaskEntity; |
||||||
|
import com.hnac.hzinfo.inspect.task.vo.DutyInspectTaskVO; |
||||||
|
import lombok.AllArgsConstructor; |
||||||
|
import lombok.extern.slf4j.Slf4j; |
||||||
|
import org.springblade.core.mp.base.BaseServiceImpl; |
||||||
|
import org.springblade.core.tool.api.R; |
||||||
|
import org.springblade.core.tool.utils.CollectionUtil; |
||||||
|
import org.springframework.stereotype.Service; |
||||||
|
|
||||||
|
import java.util.List; |
||||||
|
import java.util.stream.Collectors; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author ysj |
||||||
|
*/ |
||||||
|
@Service |
||||||
|
@Slf4j |
||||||
|
@AllArgsConstructor |
||||||
|
public class TaskServiceImpl extends BaseServiceImpl<TaskMapper, TaskEntity> implements TaskService { |
||||||
|
|
||||||
|
/** |
||||||
|
* 时间区间机构的巡检任务数据查询 |
||||||
|
* @param start |
||||||
|
* @param end |
||||||
|
* @param areas |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
@Override |
||||||
|
public DutyInspectTaskVO task(String start, String end, List<Long> areas) { |
||||||
|
DutyInspectTaskVO task = new DutyInspectTaskVO(); |
||||||
|
task.setInspectTaskSum(0); |
||||||
|
task.setInspectTaskFinish(0); |
||||||
|
task.setNotExecuteTaskCount(0); |
||||||
|
// 查询所有巡检任务
|
||||||
|
List<TaskEntity> tasks = this.list(new LambdaQueryWrapper<TaskEntity>() {{ |
||||||
|
ge(TaskEntity::getPlanStartTime, start) |
||||||
|
.le(TaskEntity::getPlanStartTime, end) |
||||||
|
.in(TaskEntity::getCreateDept, areas); |
||||||
|
}}); |
||||||
|
if(CollectionUtil.isEmpty(tasks)){ |
||||||
|
return task; |
||||||
|
} |
||||||
|
task.setInspectTaskIds(tasks.stream().map(TaskEntity::getId).map(Object::toString).collect(Collectors.joining(","))); |
||||||
|
task.setInspectTaskSum(tasks.size()); |
||||||
|
// 所有处理完成巡检任务
|
||||||
|
List<TaskEntity> finshList = tasks.stream().filter(o-> null != o.getStatus() && o.getStatus().equals(3)).collect(Collectors.toList()); |
||||||
|
if(CollectionUtil.isEmpty(finshList)){ |
||||||
|
return task; |
||||||
|
} |
||||||
|
task.setInspectTaskFinish(finshList.size()); |
||||||
|
// 未执行任务数
|
||||||
|
List<TaskEntity> notExecuteList = tasks.stream().filter(o-> null != o.getStatus() && o.getStatus().equals(0)).collect(Collectors.toList()); |
||||||
|
if(CollectionUtil.isEmpty(notExecuteList)){ |
||||||
|
return task; |
||||||
|
} |
||||||
|
task.setNotExecuteTaskCount(notExecuteList.size()); |
||||||
|
return task; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,15 @@ |
|||||||
|
package com.hnac.hzims.scheduled.service.operation; |
||||||
|
|
||||||
|
import com.hnac.hzims.operational.defect.entity.OperPhenomenonEntity; |
||||||
|
import com.hnac.hzims.operational.report.vo.DutyDefectVO; |
||||||
|
import org.springblade.core.mp.base.BaseService; |
||||||
|
|
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author ysj |
||||||
|
*/ |
||||||
|
public interface PhenomenonService extends BaseService<OperPhenomenonEntity> { |
||||||
|
|
||||||
|
DutyDefectVO defect(String start, String end, List<Long> areas); |
||||||
|
} |
@ -0,0 +1,9 @@ |
|||||||
|
package com.hnac.hzims.scheduled.service.operation; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author ysj |
||||||
|
*/ |
||||||
|
public interface ReportService { |
||||||
|
|
||||||
|
void loadMonthReport(String param, int i); |
||||||
|
} |
@ -0,0 +1,60 @@ |
|||||||
|
package com.hnac.hzims.scheduled.service.operation.impl; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
||||||
|
import com.hnac.hzims.operational.defect.entity.OperPhenomenonEntity; |
||||||
|
import com.hnac.hzims.operational.report.vo.DutyDefectVO; |
||||||
|
import com.hnac.hzims.scheduled.mapper.operation.PhenomenonMapper; |
||||||
|
import com.hnac.hzims.scheduled.service.operation.PhenomenonService; |
||||||
|
import lombok.AllArgsConstructor; |
||||||
|
import lombok.extern.slf4j.Slf4j; |
||||||
|
import org.springblade.core.mp.base.BaseServiceImpl; |
||||||
|
import org.springblade.core.tool.utils.CollectionUtil; |
||||||
|
import org.springblade.core.tool.utils.Func; |
||||||
|
import org.springframework.stereotype.Service; |
||||||
|
|
||||||
|
import java.util.List; |
||||||
|
import java.util.stream.Collectors; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author ysj |
||||||
|
*/ |
||||||
|
@Service |
||||||
|
@Slf4j |
||||||
|
@AllArgsConstructor |
||||||
|
public class PhenomenonServiceImpl extends BaseServiceImpl<PhenomenonMapper, OperPhenomenonEntity> implements PhenomenonService { |
||||||
|
|
||||||
|
/** |
||||||
|
* 时间范围内机构缺陷数据查询 |
||||||
|
* @param start |
||||||
|
* @param end |
||||||
|
* @param areas |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
@Override |
||||||
|
public DutyDefectVO defect(String start, String end, List<Long> areas) { |
||||||
|
DutyDefectVO defectVO = new DutyDefectVO(); |
||||||
|
// 查询缺陷现象总数
|
||||||
|
List<OperPhenomenonEntity> operPhenomenonList = this.list(new LambdaQueryWrapper<OperPhenomenonEntity>(){{ |
||||||
|
ge(OperPhenomenonEntity::getCreateTime,start); |
||||||
|
le(OperPhenomenonEntity::getCreateTime,end); |
||||||
|
in(OperPhenomenonEntity::getCreateDept,areas); |
||||||
|
}}); |
||||||
|
if(CollectionUtil.isEmpty(operPhenomenonList)){ |
||||||
|
defectVO.setDefectSum(0); |
||||||
|
defectVO.setDefect(0); |
||||||
|
return defectVO; |
||||||
|
} |
||||||
|
defectVO.setTotalIds(operPhenomenonList.stream().map(o->String.valueOf(o.getId())).collect(Collectors.joining(","))); |
||||||
|
defectVO.setDefectSum(operPhenomenonList.size()); |
||||||
|
// 消缺数
|
||||||
|
List<Long> defectList = operPhenomenonList.stream().filter(o -> (Func.isNotEmpty(o.getIsDefect()) && o.getIsDefect() == 0) || "1".equals(o.getConclusionStatus())). |
||||||
|
map(OperPhenomenonEntity::getId).collect(Collectors.toList()); |
||||||
|
if(CollectionUtil.isEmpty(defectList)){ |
||||||
|
defectVO.setDefect(0); |
||||||
|
return defectVO; |
||||||
|
} |
||||||
|
// 缺陷总数
|
||||||
|
defectVO.setDefect(defectList.size()); |
||||||
|
return defectVO; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,527 @@ |
|||||||
|
package com.hnac.hzims.scheduled.service.operation.impl; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
||||||
|
import com.google.common.util.concurrent.ThreadFactoryBuilder; |
||||||
|
import com.hnac.hzims.equipment.entity.PlanGenerationEntity; |
||||||
|
import com.hnac.hzims.message.dto.MailPushDto; |
||||||
|
import com.hnac.hzims.message.fegin.IPushMsgClient; |
||||||
|
import com.hnac.hzims.operational.main.constant.HomePageConstant; |
||||||
|
import com.hnac.hzims.operational.main.vo.AreaMonthReportVo; |
||||||
|
import com.hnac.hzims.operational.main.vo.MaintainVo; |
||||||
|
import com.hnac.hzims.operational.main.vo.OverhaulVo; |
||||||
|
import com.hnac.hzims.operational.report.vo.DutyDefectVO; |
||||||
|
import com.hnac.hzims.operational.station.entity.StationEntity; |
||||||
|
import com.hnac.hzims.safeproduct.dto.SafeEquipmentTrialDTO; |
||||||
|
import com.hnac.hzims.scheduled.service.equipment.PlanService; |
||||||
|
import com.hnac.hzims.scheduled.service.inspect.TaskService; |
||||||
|
import com.hnac.hzims.scheduled.service.operation.*; |
||||||
|
import com.hnac.hzims.scheduled.service.safeproduct.MonthService; |
||||||
|
import com.hnac.hzims.scheduled.service.safeproduct.TrialService; |
||||||
|
import com.hnac.hzims.scheduled.service.ticket.TicketService; |
||||||
|
import com.hnac.hzims.ticket.workTicket.vo.TicketMonthVO; |
||||||
|
import com.hnac.hzinfo.inspect.task.vo.DutyInspectTaskVO; |
||||||
|
import lombok.RequiredArgsConstructor; |
||||||
|
import lombok.extern.slf4j.Slf4j; |
||||||
|
import org.apache.commons.collections4.MapUtils; |
||||||
|
import org.springblade.core.tool.api.R; |
||||||
|
import org.springblade.core.tool.utils.CollectionUtil; |
||||||
|
import org.springblade.core.tool.utils.DateUtil; |
||||||
|
import org.springblade.core.tool.utils.ObjectUtil; |
||||||
|
import org.springblade.core.tool.utils.StringUtil; |
||||||
|
import org.springblade.system.entity.Dept; |
||||||
|
import org.springblade.system.feign.ISysClient; |
||||||
|
import org.springblade.system.user.entity.User; |
||||||
|
import org.springblade.system.user.feign.IUserClient; |
||||||
|
import org.springframework.beans.factory.annotation.Value; |
||||||
|
import org.springframework.data.redis.core.RedisTemplate; |
||||||
|
import org.springframework.stereotype.Service; |
||||||
|
|
||||||
|
import java.math.BigDecimal; |
||||||
|
import java.text.SimpleDateFormat; |
||||||
|
import java.time.LocalDateTime; |
||||||
|
import java.time.ZoneId; |
||||||
|
import java.util.*; |
||||||
|
import java.util.concurrent.*; |
||||||
|
import java.util.stream.Collectors; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author ysj |
||||||
|
*/ |
||||||
|
@Service |
||||||
|
@RequiredArgsConstructor |
||||||
|
@Slf4j |
||||||
|
public class ReportServiceImpl implements ReportService { |
||||||
|
|
||||||
|
private final PlanService planService; |
||||||
|
private final TaskService taskService; |
||||||
|
private final TrialService trialService; |
||||||
|
private final AccessService accessService; |
||||||
|
private final TicketService ticketService; |
||||||
|
private final StationService stationService; |
||||||
|
private final MonthService monthService; |
||||||
|
private final PhenomenonService phenomenonService; |
||||||
|
private final MaintenanceService maintenanceService; |
||||||
|
private final RedisTemplate redisTemplate; |
||||||
|
private final ISysClient sysClient; |
||||||
|
private final IUserClient userClient; |
||||||
|
private final IPushMsgClient pushMsgClient; |
||||||
|
|
||||||
|
private final static String recent_year_cache_final = "hzims:operation:key:power:data"; |
||||||
|
|
||||||
|
@Value("${hzims.operation.area.report}") |
||||||
|
private String report_month_cache_final; |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* 区域-月报 |
||||||
|
* @param param |
||||||
|
* @param year |
||||||
|
*/ |
||||||
|
@Override |
||||||
|
public void loadMonthReport(String param, int year) { |
||||||
|
// 获取所有机构
|
||||||
|
R<List<Dept>> R = sysClient.getDeptList(); |
||||||
|
if (!R.isSuccess() || CollectionUtil.isEmpty(R.getData())) { |
||||||
|
return; |
||||||
|
} |
||||||
|
// 查询所有服务类型——"运维服务"、站点类型——"水电站"
|
||||||
|
List<StationEntity> stations = stationService.list(Wrappers.<StationEntity>lambdaQuery() |
||||||
|
.eq(StationEntity::getServeType,HomePageConstant.HYDROPOWER_SERVETYPE) |
||||||
|
.eq(StationEntity::getType,HomePageConstant.HYDROPOWER) |
||||||
|
); |
||||||
|
if (CollectionUtil.isEmpty(stations)) { |
||||||
|
return; |
||||||
|
} |
||||||
|
// 站点近年发电数据
|
||||||
|
Map<Long, Map<String, Float>> powerMap = (Map<Long, Map<String, Float>>) redisTemplate.opsForValue().get(recent_year_cache_final); |
||||||
|
// 存储数据节点 key - 月份 value - 区域数据集合
|
||||||
|
Map<String, List<AreaMonthReportVo>> map = new HashMap<>(); |
||||||
|
// 月份集合
|
||||||
|
List<String> monthList = getMonthList(year, Calendar.getInstance().get(Calendar.MONTH)); |
||||||
|
monthList.forEach(mon -> { |
||||||
|
List<AreaMonthReportVo> list = this.getAreaReportByMon(R.getData(), powerMap, stations, mon); |
||||||
|
if (CollectionUtil.isEmpty(list)) { |
||||||
|
return; |
||||||
|
} |
||||||
|
map.put(mon, list); |
||||||
|
}); |
||||||
|
// 推送当月报表邮件
|
||||||
|
this.sendMonthReport(map, R.getData()); |
||||||
|
redisTemplate.opsForValue().set(report_month_cache_final, map); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 获取近年月份集合 |
||||||
|
* |
||||||
|
* @param year |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public static List<String> getMonthList(int year, int endMoth) { |
||||||
|
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM"); |
||||||
|
// 开始日期
|
||||||
|
Calendar endCal = Calendar.getInstance(); |
||||||
|
endCal.setTime(new Date()); |
||||||
|
endCal.add(Calendar.MONTH, -endCal.get(Calendar.MONTH) + endMoth); |
||||||
|
endCal.add(Calendar.DATE, -endCal.get(Calendar.DATE) + 1); |
||||||
|
|
||||||
|
// 结束日期
|
||||||
|
Calendar startCal = Calendar.getInstance(); |
||||||
|
startCal.setTime(new Date()); |
||||||
|
startCal.set(Calendar.YEAR, startCal.get(Calendar.YEAR) - year); |
||||||
|
startCal.add(Calendar.MONTH, -startCal.get(Calendar.MONTH)); |
||||||
|
startCal.add(Calendar.DATE, -startCal.get(Calendar.DATE) + 1); |
||||||
|
// 获取日期之间的月份
|
||||||
|
List<String> list = new ArrayList<>(); |
||||||
|
while (endCal.after(startCal)) { |
||||||
|
list.add(format.format(startCal.getTime())); |
||||||
|
startCal.add(Calendar.MONTH, 1); |
||||||
|
} |
||||||
|
list.add(format.format(endCal.getTime())); |
||||||
|
return list; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 区域月报数据加载 |
||||||
|
* @param deptList |
||||||
|
* @param powerMap |
||||||
|
* @param stationList |
||||||
|
* @param mon |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
private List<AreaMonthReportVo> getAreaReportByMon(List<Dept> deptList, Map<Long, Map<String, Float>> powerMap, List<StationEntity> stationList, String mon) { |
||||||
|
LocalDateTime startTime = LocalDateTime.parse(mon + "-01 00:00:00", DateUtil.DATETIME_FORMATTER); |
||||||
|
LocalDateTime endTime = getEndTime(mon); |
||||||
|
// 查询所有站点的计划发电量
|
||||||
|
List<PlanGenerationEntity> planList = this.planPower(stationList, mon); |
||||||
|
// 站点实际发电量
|
||||||
|
Map<Long, Float> actualMap = this.actualPower(powerMap, stationList, mon + "-01"); |
||||||
|
// 站点去年发电量
|
||||||
|
Map<Long, Float> oldActualMap = this.actualPower(powerMap, stationList, lastyear(1,mon)); |
||||||
|
// 站点前发电量
|
||||||
|
Map<Long, Float> oldOldActualMap = this.actualPower(powerMap, stationList, lastyear(2,mon)); |
||||||
|
// 取机构中区域部分
|
||||||
|
List<Dept> areaList = deptList.stream().filter(o -> o.getDeptCategory().equals(3)).collect(Collectors.toList()); |
||||||
|
if (CollectionUtil.isEmpty(areaList)) { |
||||||
|
return null; |
||||||
|
} |
||||||
|
List<AreaMonthReportVo> areaMonthReportVoList = new ArrayList<>(); |
||||||
|
areaList.forEach(area -> { |
||||||
|
AreaMonthReportVo areaMonthReport = new AreaMonthReportVo(); |
||||||
|
areaMonthReport.setAreaId(area.getId()); |
||||||
|
areaMonthReport.setAreaName(area.getDeptName()); |
||||||
|
// 获取区域下的站点
|
||||||
|
List<Long> stationIdList = deptList.stream().filter(o -> o.getParentId().equals(area.getId()) && o.getDeptCategory().equals(4)).map(Dept::getId).collect(Collectors.toList()); |
||||||
|
List<StationEntity> areaStationList = stationList.stream().filter(o -> stationIdList.contains(o.getRefDept())).collect(Collectors.toList()); |
||||||
|
if (CollectionUtil.isEmpty(areaStationList)) { |
||||||
|
return; |
||||||
|
} |
||||||
|
// 计划发电量、实际发电量、发电完成率
|
||||||
|
this.powerMonth(planList, actualMap, oldActualMap, areaStationList, areaMonthReport); |
||||||
|
// 操作票、操作票合格率/ 工作票、工作票合格率
|
||||||
|
this.doubleMonth(area, areaMonthReport, mon + "-01 00:00:00", this.strEndTime(mon)); |
||||||
|
// 日常维护、巡检任务、缺陷数、消缺率、检修任务
|
||||||
|
this.taskMonth(Collections.singletonList(area.getId()), areaMonthReport, mon + "-01 00:00:00", strEndTime(mon)); |
||||||
|
// 预测
|
||||||
|
this.predictPlanPower(oldActualMap,oldOldActualMap,areaStationList,areaMonthReport); |
||||||
|
// 安全生产会议次数、月度检查报告、技能培训、安全大检查
|
||||||
|
this.securityCheck(Collections.singletonList(area.getId()),areaMonthReport,mon + "-01 00:00:00", strEndTime(mon)); |
||||||
|
// 设备试验
|
||||||
|
this.getDeviceTry(mon + "-01 00:00:00", strEndTime(mon), Collections.singletonList(area.getId()),areaMonthReport); |
||||||
|
areaMonthReportVoList.add(areaMonthReport); |
||||||
|
}); |
||||||
|
return areaMonthReportVoList; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 获取结束时间 |
||||||
|
*/ |
||||||
|
private LocalDateTime getEndTime(String mon) { |
||||||
|
Date date = DateUtil.parse(mon + "-01 00:00:00",DateUtil.DATETIME_FORMAT); |
||||||
|
Calendar calendar = Calendar.getInstance(); |
||||||
|
calendar.setTime(date); |
||||||
|
calendar.add(Calendar.MONTH, 1); |
||||||
|
return calendar.getTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 获取站点计划发电量 |
||||||
|
*/ |
||||||
|
private List<PlanGenerationEntity> planPower(List<StationEntity> stationList, String mon) { |
||||||
|
List<String> list = stationList.stream().map(StationEntity::getCode).collect(Collectors.toList()); |
||||||
|
return planService.planGeneration(list, null, mon); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 获取站点月份实际发电量 |
||||||
|
*/ |
||||||
|
private Map<Long, Float> actualPower(Map<Long, Map<String, Float>> powerMap, List<StationEntity> stationList, String month) { |
||||||
|
if (MapUtils.isEmpty(powerMap)) { |
||||||
|
return null; |
||||||
|
} |
||||||
|
// 站点Id集合
|
||||||
|
List<Long> stationIdList = stationList.stream().map(StationEntity::getId).collect(Collectors.toList()); |
||||||
|
// 存储站点实际发电量
|
||||||
|
Map<Long, Float> actualPowerMap = new HashMap<>(); |
||||||
|
stationIdList.forEach(key -> { |
||||||
|
Map<String, Float> monthMap = powerMap.get(key); |
||||||
|
if (MapUtils.isEmpty(monthMap)) { |
||||||
|
return; |
||||||
|
} |
||||||
|
float actualPower = 0f; |
||||||
|
if(ObjectUtil.isNotEmpty(monthMap.get(month))){ |
||||||
|
actualPower = monthMap.get(month); |
||||||
|
} |
||||||
|
actualPowerMap.put(key, actualPower); |
||||||
|
}); |
||||||
|
return actualPowerMap; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 获取去年时间 |
||||||
|
*/ |
||||||
|
private String lastyear(int year,String mon) { |
||||||
|
Date date = DateUtil.parse(mon + "-01 00:00:00",DateUtil.DATETIME_FORMAT); |
||||||
|
Calendar calendar = Calendar.getInstance(); |
||||||
|
calendar.setTime(date); |
||||||
|
calendar.set(Calendar.YEAR, calendar.get(Calendar.YEAR) - year); |
||||||
|
calendar.add(Calendar.DATE, -calendar.get(Calendar.DATE) + 1); |
||||||
|
return DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATE); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 获取结束时间 |
||||||
|
*/ |
||||||
|
private String strEndTime(String mon) { |
||||||
|
Date date = DateUtil.parse(mon + "-01 00:00:00",DateUtil.DATETIME_FORMAT); |
||||||
|
Calendar calendar = Calendar.getInstance(); |
||||||
|
calendar.setTime(date); |
||||||
|
calendar.add(Calendar.MONTH, 1); |
||||||
|
return DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATE); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 区域-月计划发电量、月实际发电量、月发电完成率、同比 |
||||||
|
* |
||||||
|
* @param planList |
||||||
|
* @param actualMap |
||||||
|
* @param oldActualMap |
||||||
|
* @param areaStationList |
||||||
|
* @param areaMonthReport |
||||||
|
*/ |
||||||
|
private void powerMonth(List<PlanGenerationEntity> planList, Map<Long, Float> actualMap, Map<Long, Float> oldActualMap, List<StationEntity> areaStationList, AreaMonthReportVo areaMonthReport) { |
||||||
|
// 计划发电量
|
||||||
|
List<String> codeList = areaStationList.stream().map(StationEntity::getCode).collect(Collectors.toList()); |
||||||
|
double planPower = planList.stream().filter(o -> codeList.contains(o.getStationId())).mapToDouble(PlanGenerationEntity::getPlanGeneration).sum(); |
||||||
|
areaMonthReport.setPlanPower(Float.parseFloat(String.valueOf(planPower))); |
||||||
|
if (MapUtils.isEmpty(actualMap)) { |
||||||
|
areaMonthReport.setActualPower(0f); |
||||||
|
areaMonthReport.setPowerFinishRate(0.0); |
||||||
|
return; |
||||||
|
} |
||||||
|
// 实际发电量
|
||||||
|
List<Long> ids = areaStationList.stream().map(StationEntity::getId).collect(Collectors.toList()); |
||||||
|
double actualPower = actualMap.entrySet().stream().filter(e -> ids.contains(e.getKey())).mapToDouble(Map.Entry::getValue).sum(); |
||||||
|
areaMonthReport.setActualPower(Float.parseFloat(String.valueOf(actualPower))); |
||||||
|
if (Math.abs(planPower) <= 0) { |
||||||
|
areaMonthReport.setPowerFinishRate(0.0); |
||||||
|
} else { |
||||||
|
// 发电完成率
|
||||||
|
double powerFinishRate = BigDecimal.valueOf(actualPower / planPower * 100).setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue(); |
||||||
|
areaMonthReport.setPowerFinishRate(powerFinishRate); |
||||||
|
} |
||||||
|
// 同比
|
||||||
|
double oldActualPower = oldActualMap.entrySet().stream().filter(e -> ids.contains(e.getKey())).mapToDouble(Map.Entry::getValue).sum(); |
||||||
|
if (Math.abs(actualPower) <= 0 || Math.abs(oldActualPower) <= 0) { |
||||||
|
areaMonthReport.setComparePowerRate(0.0); |
||||||
|
return; |
||||||
|
} |
||||||
|
double comparePowerRate = BigDecimal.valueOf(actualPower / oldActualPower).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); |
||||||
|
areaMonthReport.setComparePowerRate(comparePowerRate); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 区域-操作票、操作票合格率/ 工作票、工作票合格率 |
||||||
|
* |
||||||
|
* @param area |
||||||
|
* @param areaMonthReport |
||||||
|
*/ |
||||||
|
private void doubleMonth(Dept area, AreaMonthReportVo areaMonthReport, String startTime, String endTime) { |
||||||
|
// 站点归属机构集合
|
||||||
|
TicketMonthVO ticket = ticketService.operateWork(startTime,endTime,Collections.singletonList(area.getId())); |
||||||
|
if (ObjectUtil.isEmpty(ticket)) { |
||||||
|
areaMonthReport.setOperate(0); |
||||||
|
areaMonthReport.setOperaQualifyRate(0.0); |
||||||
|
areaMonthReport.setWork(0); |
||||||
|
areaMonthReport.setWorkQualifyRate(0.0); |
||||||
|
return; |
||||||
|
} |
||||||
|
// 操作票
|
||||||
|
int operate = ticket.getOperate(); |
||||||
|
int operateQualify = ticket.getOperateQualify(); |
||||||
|
areaMonthReport.setOperate(operate); |
||||||
|
if (operateQualify <= 0) { |
||||||
|
areaMonthReport.setOperaQualifyRate(0.0); |
||||||
|
} else { |
||||||
|
double operateQualifyRate = BigDecimal.valueOf(operateQualify / (double) operate * 100L).setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue(); |
||||||
|
areaMonthReport.setOperaQualifyRate(operateQualifyRate); |
||||||
|
} |
||||||
|
//工作票
|
||||||
|
int work = ticket.getWork(); |
||||||
|
int workQualify = ticket.getWorkQualify(); |
||||||
|
areaMonthReport.setWork(work); |
||||||
|
if (workQualify <= 0) { |
||||||
|
areaMonthReport.setWorkQualifyRate(0.0); |
||||||
|
} else { |
||||||
|
double workQualifyRate = BigDecimal.valueOf(workQualify / (double) work * 100L).setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue(); |
||||||
|
areaMonthReport.setWorkQualifyRate(workQualifyRate); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 任务月报-日常维护、巡检任务、缺陷数、消缺率、检修任务 |
||||||
|
* |
||||||
|
* @param areas |
||||||
|
* @param areaMonthReport |
||||||
|
*/ |
||||||
|
private void taskMonth(List<Long> areas, AreaMonthReportVo areaMonthReport, String startTime, String endTime) { |
||||||
|
//通过线程池异步获取月报各模块内容 主要分为五块内容
|
||||||
|
ThreadFactory namedThreadFactory = new ThreadFactoryBuilder().setNameFormat("area_month_report-pool-%d").build(); |
||||||
|
ExecutorService exe = new ThreadPoolExecutor(4, 4, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(1024), namedThreadFactory, new ThreadPoolExecutor.AbortPolicy()); |
||||||
|
//监控线程执行完后返回结果
|
||||||
|
CountDownLatch countDownLatch = new CountDownLatch(4); |
||||||
|
// 日常维护
|
||||||
|
exe.execute(() -> { |
||||||
|
MaintainVo maintainVo = maintenanceService.maintain(startTime, endTime, areas); |
||||||
|
int maintainSum = maintainVo.getMaintain(); |
||||||
|
areaMonthReport.setRoutineMaintenance(maintainSum); |
||||||
|
countDownLatch.countDown(); |
||||||
|
}); |
||||||
|
|
||||||
|
// 巡检任务
|
||||||
|
exe.execute(() -> { |
||||||
|
DutyInspectTaskVO task = taskService.task(startTime,endTime,areas); |
||||||
|
if (ObjectUtil.isEmpty(task)) { |
||||||
|
areaMonthReport.setInspect(0); |
||||||
|
} else { |
||||||
|
int inspect = task.getInspectTaskSum(); |
||||||
|
areaMonthReport.setInspect(inspect); |
||||||
|
} |
||||||
|
countDownLatch.countDown(); |
||||||
|
}); |
||||||
|
|
||||||
|
// 消缺
|
||||||
|
exe.execute(() -> { |
||||||
|
DutyDefectVO defectVO = phenomenonService.defect(startTime, endTime, areas); |
||||||
|
int defectSum = defectVO.getDefectSum(); |
||||||
|
int defect = defectVO.getDefect(); |
||||||
|
areaMonthReport.setDefect(defectSum); |
||||||
|
if (defectSum <= 0) { |
||||||
|
areaMonthReport.setDefectRate(0.0); |
||||||
|
} else { |
||||||
|
double deletionRate = BigDecimal.valueOf(defect / defectSum * 100L).setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue(); |
||||||
|
areaMonthReport.setDefectRate(deletionRate); |
||||||
|
} |
||||||
|
countDownLatch.countDown(); |
||||||
|
}); |
||||||
|
|
||||||
|
// 检修
|
||||||
|
exe.execute(() -> { |
||||||
|
OverhaulVo overhaulVo = accessService.overhaul(startTime, endTime, areas); |
||||||
|
int overhaul = overhaulVo.getOverhaul(); |
||||||
|
areaMonthReport.setMaintenanceTasks(overhaul); |
||||||
|
countDownLatch.countDown(); |
||||||
|
}); |
||||||
|
|
||||||
|
//所有模板数据获取完成后释放锁
|
||||||
|
try { |
||||||
|
countDownLatch.await(); |
||||||
|
} catch (InterruptedException e) { |
||||||
|
e.printStackTrace(); |
||||||
|
Thread.currentThread().interrupt(); |
||||||
|
} |
||||||
|
exe.shutdown(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 预测发电量 |
||||||
|
* @param oldActualMap |
||||||
|
* @param oldOldActualMap |
||||||
|
* @param areaStationList |
||||||
|
* @param areaMonthReport |
||||||
|
*/ |
||||||
|
private void predictPlanPower(Map<Long, Float> oldActualMap, Map<Long, Float> oldOldActualMap, List<StationEntity> areaStationList, AreaMonthReportVo areaMonthReport) { |
||||||
|
areaMonthReport.setPredictPlanPower(0.0); |
||||||
|
// 实际发电量
|
||||||
|
List<Long> ids = areaStationList.stream().map(StationEntity::getId).collect(Collectors.toList()); |
||||||
|
if(CollectionUtil.isEmpty(ids)){ |
||||||
|
return; |
||||||
|
} |
||||||
|
double oldActualPower = oldActualMap.entrySet().stream().filter(e -> ids.contains(e.getKey())).mapToDouble(Map.Entry::getValue).sum(); |
||||||
|
double oldOldActualPower = oldOldActualMap.entrySet().stream().filter(e -> ids.contains(e.getKey())).mapToDouble(Map.Entry::getValue).sum(); |
||||||
|
if(Math.abs(oldActualPower) <= 0 && Math.abs(oldOldActualPower) <= 0 ){ |
||||||
|
return; |
||||||
|
} |
||||||
|
double predictPlanPower = BigDecimal.valueOf((oldActualPower + oldOldActualPower) / 2).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); |
||||||
|
areaMonthReport.setPredictPlanPower(predictPlanPower); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 安全检查 |
||||||
|
* @param areas |
||||||
|
* @param areaMonthReport |
||||||
|
* @param startTime |
||||||
|
* @param endTime |
||||||
|
*/ |
||||||
|
private void securityCheck(List<Long> areas, AreaMonthReportVo areaMonthReport,String startTime,String endTime) { |
||||||
|
areaMonthReport.setSafetyMeeting(0); |
||||||
|
areaMonthReport.setSelfReport(0); |
||||||
|
areaMonthReport.setSkillTrainy(0); |
||||||
|
areaMonthReport.setSecurityCheck(0); |
||||||
|
// 站点归属机构集合
|
||||||
|
Map<String, Object> map = new HashMap<>(); |
||||||
|
map.put("startDate", startTime); |
||||||
|
map.put("endDate", endTime); |
||||||
|
map.put("deptList", areas); |
||||||
|
// 调用安全大检查fegin接口
|
||||||
|
Map<String, Object> count = monthService.check(map); |
||||||
|
if(MapUtils.isEmpty(count)){ |
||||||
|
return; |
||||||
|
} |
||||||
|
// 安全生产会议
|
||||||
|
areaMonthReport.setSafetyMeeting((Integer) count.get("safetyMeetingNum")); |
||||||
|
// 月度自查报告
|
||||||
|
areaMonthReport.setSelfReport((Integer) count.get("monthCheckNum")); |
||||||
|
// 技能培训
|
||||||
|
areaMonthReport.setSkillTrainy((Integer) count.get("skillsTrainingNum")); |
||||||
|
// 安全大检查
|
||||||
|
areaMonthReport.setSecurityCheck((Integer) count.get("bigCheckNum")); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 获取设备试验数据 |
||||||
|
* @param startTime |
||||||
|
* @param endTime |
||||||
|
* @param areas |
||||||
|
* @param areaMonthReport |
||||||
|
*/ |
||||||
|
private void getDeviceTry(String startTime,String endTime,List<Long> areas,AreaMonthReportVo areaMonthReport) { |
||||||
|
areaMonthReport.setDeviceTry(0); |
||||||
|
SafeEquipmentTrialDTO request = new SafeEquipmentTrialDTO(); |
||||||
|
request.setDeptList(areas); |
||||||
|
request.setStartTime(startTime); |
||||||
|
request.setEndTime(endTime); |
||||||
|
areaMonthReport.setDeviceTry(trialService.count(request)); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 推送当月月报 |
||||||
|
* |
||||||
|
* @param map |
||||||
|
* @param list |
||||||
|
*/ |
||||||
|
private void sendMonthReport(Map<String, List<AreaMonthReportVo>> map, List<Dept> list) { |
||||||
|
if (MapUtils.isEmpty(map) || CollectionUtil.isEmpty(list)) { |
||||||
|
return; |
||||||
|
} |
||||||
|
// 获取邮件接收人
|
||||||
|
Dept dept = list.stream().min(Comparator.comparing(Dept::getDeptCategory)).get(); |
||||||
|
if(ObjectUtil.isEmpty(dept)){ |
||||||
|
return; |
||||||
|
} |
||||||
|
R<List<User>> userR = userClient.userListByDeptId(dept.getId()); |
||||||
|
if(!userR.isSuccess() && CollectionUtil.isEmpty(userR.getData())){ |
||||||
|
return; |
||||||
|
} |
||||||
|
List<User> userList = userR.getData().stream().filter(o->dept.getId().equals(o.getCreateDept())).collect(Collectors.toList()); |
||||||
|
if(CollectionUtil.isEmpty(userList)){ |
||||||
|
return; |
||||||
|
} |
||||||
|
List<String> mailList = userList.stream().map(User::getEmail).filter(StringUtil::isNotBlank).collect(Collectors.toList()); |
||||||
|
if(CollectionUtil.isEmpty(mailList)){ |
||||||
|
return; |
||||||
|
} |
||||||
|
// 获取月报数据
|
||||||
|
List<AreaMonthReportVo> entityList = map.get(DateUtil.format(new Date(),"yyyy-MM")); |
||||||
|
if (CollectionUtil.isEmpty(entityList)) { |
||||||
|
return; |
||||||
|
} |
||||||
|
// 发送邮件
|
||||||
|
MailPushDto pushDto = new MailPushDto(); |
||||||
|
pushDto.setBusinessClassify("system"); |
||||||
|
pushDto.setBusinessKey("Month_Report"); |
||||||
|
pushDto.setSubject("水电站生产运行"); |
||||||
|
Map<String, Object> param = new HashMap<>(); |
||||||
|
param.put("templatePath", "/data/hzims/message/mail/template/stationRunMonthReport.html"); |
||||||
|
Map<String, Object> parameters = new HashMap<>(); |
||||||
|
parameters.put("data",entityList); |
||||||
|
param.put("parameters", parameters); |
||||||
|
pushDto.setExtras(param); |
||||||
|
pushDto.setText("水电站生产运行月报内容"); |
||||||
|
pushDto.setToAccount(mailList.toArray(new String[0])); |
||||||
|
pushDto.setHtml(true); |
||||||
|
pushDto.setCreateUser(userR.getData().get(0).getCreateUser()); |
||||||
|
pushDto.setTenantId(dept.getTenantId()); |
||||||
|
pushDto.setCreateDept(dept.getId()); |
||||||
|
pushMsgClient.sendMail(pushDto); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,11 @@ |
|||||||
|
package com.hnac.hzims.scheduled.service.safeproduct; |
||||||
|
|
||||||
|
import com.hnac.hzims.safeproduct.entity.CheckCompanyEntity; |
||||||
|
import org.springblade.core.mp.base.BaseService; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author ysj |
||||||
|
*/ |
||||||
|
public interface CompanyService extends BaseService<CheckCompanyEntity> { |
||||||
|
|
||||||
|
} |
@ -0,0 +1,12 @@ |
|||||||
|
package com.hnac.hzims.scheduled.service.safeproduct; |
||||||
|
|
||||||
|
import com.hnac.hzims.safeproduct.entity.CheckItemInstanceEntity; |
||||||
|
import org.springblade.core.mp.base.BaseService; |
||||||
|
|
||||||
|
/** |
||||||
|
* Created by Sam Huang 2022/5/6 8:28 |
||||||
|
*/ |
||||||
|
public interface InstanceService extends BaseService<CheckItemInstanceEntity> { |
||||||
|
|
||||||
|
|
||||||
|
} |
@ -0,0 +1,14 @@ |
|||||||
|
package com.hnac.hzims.scheduled.service.safeproduct; |
||||||
|
|
||||||
|
import com.hnac.hzims.safeproduct.entity.CheckMonthEntity; |
||||||
|
import org.springblade.core.mp.base.BaseService; |
||||||
|
|
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author ysj |
||||||
|
*/ |
||||||
|
public interface MonthService extends BaseService<CheckMonthEntity> { |
||||||
|
|
||||||
|
Map<String, Object> check(Map<String, Object> map); |
||||||
|
} |
@ -0,0 +1,13 @@ |
|||||||
|
package com.hnac.hzims.scheduled.service.safeproduct; |
||||||
|
|
||||||
|
import com.hnac.hzims.safeproduct.dto.SafeEquipmentTrialDTO; |
||||||
|
import com.hnac.hzims.safeproduct.entity.SafeEquipmentTrialEntity; |
||||||
|
import org.springblade.core.mp.base.BaseService; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author ysj |
||||||
|
*/ |
||||||
|
public interface TrialService extends BaseService<SafeEquipmentTrialEntity> { |
||||||
|
|
||||||
|
int count(SafeEquipmentTrialDTO trial); |
||||||
|
} |
@ -0,0 +1,19 @@ |
|||||||
|
package com.hnac.hzims.scheduled.service.safeproduct.impl; |
||||||
|
|
||||||
|
import com.hnac.hzims.safeproduct.entity.CheckCompanyEntity; |
||||||
|
import com.hnac.hzims.scheduled.mapper.safeproduct.CompanyMapper; |
||||||
|
import com.hnac.hzims.scheduled.service.safeproduct.CompanyService; |
||||||
|
import lombok.AllArgsConstructor; |
||||||
|
import lombok.extern.slf4j.Slf4j; |
||||||
|
import org.springblade.core.mp.base.BaseServiceImpl; |
||||||
|
import org.springframework.stereotype.Service; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author ysj |
||||||
|
*/ |
||||||
|
@Service |
||||||
|
@AllArgsConstructor |
||||||
|
@Slf4j |
||||||
|
public class CompanyServiceImpl extends BaseServiceImpl<CompanyMapper, CheckCompanyEntity> implements CompanyService { |
||||||
|
|
||||||
|
} |
@ -0,0 +1,19 @@ |
|||||||
|
package com.hnac.hzims.scheduled.service.safeproduct.impl; |
||||||
|
|
||||||
|
import com.hnac.hzims.safeproduct.entity.CheckItemInstanceEntity; |
||||||
|
import com.hnac.hzims.scheduled.mapper.safeproduct.InstanceMapper; |
||||||
|
import com.hnac.hzims.scheduled.service.safeproduct.InstanceService; |
||||||
|
import lombok.AllArgsConstructor; |
||||||
|
import lombok.extern.slf4j.Slf4j; |
||||||
|
import org.springblade.core.mp.base.BaseServiceImpl; |
||||||
|
import org.springframework.stereotype.Service; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author ysj |
||||||
|
*/ |
||||||
|
@Service |
||||||
|
@AllArgsConstructor |
||||||
|
@Slf4j |
||||||
|
public class InstanceServiceImpl extends BaseServiceImpl<InstanceMapper, CheckItemInstanceEntity> implements InstanceService { |
||||||
|
|
||||||
|
} |
@ -0,0 +1,96 @@ |
|||||||
|
package com.hnac.hzims.scheduled.service.safeproduct.impl; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.Wrapper; |
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
||||||
|
import com.hnac.hzims.safeproduct.entity.CheckCompanyEntity; |
||||||
|
import com.hnac.hzims.safeproduct.entity.CheckItemInstanceEntity; |
||||||
|
import com.hnac.hzims.safeproduct.entity.CheckMonthEntity; |
||||||
|
import com.hnac.hzims.scheduled.mapper.safeproduct.MonthMapper; |
||||||
|
import com.hnac.hzims.scheduled.service.safeproduct.CompanyService; |
||||||
|
import com.hnac.hzims.scheduled.service.safeproduct.InstanceService; |
||||||
|
import com.hnac.hzims.scheduled.service.safeproduct.MonthService; |
||||||
|
import lombok.AllArgsConstructor; |
||||||
|
import lombok.extern.slf4j.Slf4j; |
||||||
|
import org.apache.commons.lang3.StringUtils; |
||||||
|
import org.springblade.core.mp.base.BaseServiceImpl; |
||||||
|
import org.springblade.core.tool.api.R; |
||||||
|
import org.springblade.core.tool.utils.CollectionUtil; |
||||||
|
import org.springblade.core.tool.utils.ObjectUtil; |
||||||
|
import org.springframework.stereotype.Service; |
||||||
|
|
||||||
|
import java.util.HashMap; |
||||||
|
import java.util.List; |
||||||
|
import java.util.Map; |
||||||
|
import java.util.concurrent.atomic.AtomicInteger; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author ysj |
||||||
|
*/ |
||||||
|
@Service |
||||||
|
@AllArgsConstructor |
||||||
|
@Slf4j |
||||||
|
public class MonthServiceImpl extends BaseServiceImpl<MonthMapper, CheckMonthEntity> implements MonthService { |
||||||
|
|
||||||
|
private final CompanyService companyService; |
||||||
|
private final InstanceService instanceService; |
||||||
|
|
||||||
|
@Override |
||||||
|
public Map<String, Object> check(Map<String, Object> map) { |
||||||
|
if (ObjectUtil.isEmpty(map)) { |
||||||
|
return null; |
||||||
|
} |
||||||
|
Map<String, Object> result = new HashMap<>(); |
||||||
|
String startDate = (String) map.get("startDate"); |
||||||
|
String endDate = (String) map.get("endDate"); |
||||||
|
List<Long> deptList = (List<Long>) map.get("deptList"); |
||||||
|
String startMonth = startDate.substring(0, 7); |
||||||
|
String endMonth = endDate.substring(0, 7); |
||||||
|
//月度自查次数
|
||||||
|
Wrapper<CheckMonthEntity> wrapper = new LambdaQueryWrapper<CheckMonthEntity>() {{ |
||||||
|
in(CheckMonthEntity::getCreateDept, deptList); |
||||||
|
between(CheckMonthEntity::getMonth, startMonth, endMonth); |
||||||
|
}}; |
||||||
|
List<CheckMonthEntity> monthList = this.list(wrapper); |
||||||
|
result.put("monthCheckNum", monthList != null ? monthList.size() : 0); |
||||||
|
//公司大检查次数
|
||||||
|
Wrapper<CheckCompanyEntity> wrapper1 = new LambdaQueryWrapper<CheckCompanyEntity>() {{ |
||||||
|
in(CheckCompanyEntity::getCreateDept, deptList); |
||||||
|
ge(CheckCompanyEntity::getStartTime, startDate); |
||||||
|
le(CheckCompanyEntity::getEndTime, endDate); |
||||||
|
}}; |
||||||
|
List<CheckCompanyEntity> companyList = companyService.list(wrapper1); |
||||||
|
result.put("bigCheckNum", companyList != null ? companyList.size() : 0); |
||||||
|
|
||||||
|
AtomicInteger safetyMeetingNum = new AtomicInteger(0); |
||||||
|
AtomicInteger skillsTrainingNum = new AtomicInteger(0); |
||||||
|
|
||||||
|
if (CollectionUtil.isNotEmpty(monthList)) { |
||||||
|
monthList.forEach(checkMonthEntity -> { |
||||||
|
Long checkId = checkMonthEntity.getId(); |
||||||
|
Wrapper<CheckItemInstanceEntity> wrapper2 = new LambdaQueryWrapper<CheckItemInstanceEntity>() {{ |
||||||
|
eq(CheckItemInstanceEntity::getCheckId, checkId); |
||||||
|
}}; |
||||||
|
List<CheckItemInstanceEntity> list = instanceService.list(wrapper2); |
||||||
|
if (CollectionUtil.isNotEmpty(list)) { |
||||||
|
list.forEach(instanceEntity -> { |
||||||
|
//安全生产会议检查项,系统统计情况不为空纳入统计次数
|
||||||
|
if ("现场每月1次安全生产会议".equals(instanceEntity.getItem())) { |
||||||
|
if (StringUtils.isNotEmpty(instanceEntity.getSystemSituation())) { |
||||||
|
safetyMeetingNum.addAndGet(1); |
||||||
|
} |
||||||
|
} |
||||||
|
//技能培训检查项,系统统计情况不为空纳入统计次数
|
||||||
|
if ("每月开展1次技能培训".equals(instanceEntity.getItem())) { |
||||||
|
if (StringUtils.isNotEmpty(instanceEntity.getSystemSituation())) { |
||||||
|
skillsTrainingNum.addAndGet(1); |
||||||
|
} |
||||||
|
} |
||||||
|
}); |
||||||
|
} |
||||||
|
}); |
||||||
|
} |
||||||
|
result.put("safetyMeetingNum", safetyMeetingNum.get()); |
||||||
|
result.put("skillsTrainingNum", skillsTrainingNum.get()); |
||||||
|
return result; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,50 @@ |
|||||||
|
package com.hnac.hzims.scheduled.service.safeproduct.impl; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
||||||
|
import com.hnac.hzims.safeproduct.dto.SafeEquipmentTrialDTO; |
||||||
|
import com.hnac.hzims.safeproduct.entity.SafeEquipmentTrialEntity; |
||||||
|
import com.hnac.hzims.scheduled.mapper.safeproduct.TrialMapper; |
||||||
|
import com.hnac.hzims.scheduled.service.safeproduct.TrialService; |
||||||
|
import lombok.RequiredArgsConstructor; |
||||||
|
import org.springblade.core.mp.base.BaseServiceImpl; |
||||||
|
import org.springblade.core.tool.utils.CollectionUtil; |
||||||
|
import org.springblade.core.tool.utils.ObjectUtil; |
||||||
|
import org.springframework.stereotype.Service; |
||||||
|
|
||||||
|
import java.util.Optional; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author ysj |
||||||
|
*/ |
||||||
|
@Service |
||||||
|
@RequiredArgsConstructor |
||||||
|
public class TrialServiceImpl extends BaseServiceImpl<TrialMapper, SafeEquipmentTrialEntity> implements TrialService { |
||||||
|
|
||||||
|
/** |
||||||
|
* 时间区间机构的设备实验数据查询 |
||||||
|
* @param trial |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
@Override |
||||||
|
public int count(SafeEquipmentTrialDTO trial) { |
||||||
|
if (ObjectUtil.isEmpty(trial)) { |
||||||
|
return 0; |
||||||
|
} |
||||||
|
QueryWrapper<SafeEquipmentTrialEntity> queryWrapper = new QueryWrapper<SafeEquipmentTrialEntity>() {{ |
||||||
|
if (CollectionUtil.isEmpty(trial.getDeptList())) { |
||||||
|
if (Optional.ofNullable(trial.getCreateDept()).isPresent()) { |
||||||
|
eq("create_dept", trial.getCreateDept()); |
||||||
|
} |
||||||
|
} else { |
||||||
|
in("create_dept", trial.getDeptList()); |
||||||
|
} |
||||||
|
if (Optional.ofNullable(trial.getStartTime()).isPresent()) { |
||||||
|
gt("create_time", trial.getStartTime()); |
||||||
|
} |
||||||
|
if (Optional.ofNullable(trial.getEndTime()).isPresent()) { |
||||||
|
lt("create_time", trial.getEndTime()); |
||||||
|
} |
||||||
|
}}; |
||||||
|
return this.baseMapper.selectCount(queryWrapper); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,4 @@ |
|||||||
|
<?xml version="1.0" encoding="UTF-8" ?> |
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" > |
||||||
|
<mapper namespace="com.hnac.hzims.scheduled.mapper.inspect.TaskMapper"> |
||||||
|
</mapper> |
@ -0,0 +1,5 @@ |
|||||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
||||||
|
<mapper namespace="com.hnac.hzims.scheduled.mapper.operation.PhenomenonMapper"> |
||||||
|
|
||||||
|
</mapper> |
@ -0,0 +1,6 @@ |
|||||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
||||||
|
<mapper namespace="com.hnac.hzims.scheduled.mapper.safeproduct.CompanyMapper"> |
||||||
|
|
||||||
|
|
||||||
|
</mapper> |
@ -0,0 +1,5 @@ |
|||||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
||||||
|
<mapper namespace="com.hnac.hzims.scheduled.mapper.safeproduct.InstanceMapper"> |
||||||
|
|
||||||
|
</mapper> |
@ -0,0 +1,5 @@ |
|||||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
||||||
|
<mapper namespace="com.hnac.hzims.scheduled.mapper.safeproduct.MonthMapper"> |
||||||
|
|
||||||
|
</mapper> |
@ -0,0 +1,20 @@ |
|||||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
||||||
|
<mapper namespace="com.hnac.hzims.scheduled.mapper.safeproduct.TrialMapper"> |
||||||
|
|
||||||
|
<!-- 通用查询映射结果 --> |
||||||
|
<resultMap id="safeEquipmentTrialResultMap" type="com.hnac.hzims.safeproduct.entity.SafeEquipmentTrialEntity"> |
||||||
|
<result column="ID" property="id"/> |
||||||
|
<result column="FILE_PATH" property="filePath"/> |
||||||
|
<result column="FILE_NAME" property="fileName"/> |
||||||
|
<result column="TENANT_ID" property="tenantId"/> |
||||||
|
<result column="CREATE_DEPT" property="createDept"/> |
||||||
|
<result column="CREATE_TIME" property="createTime"/> |
||||||
|
<result column="CREATE_USER" property="createUser"/> |
||||||
|
<result column="UPDATE_USER" property="updateUser"/> |
||||||
|
<result column="UPDATE_TIME" property="updateTime"/> |
||||||
|
<result column="STATUS" property="status"/> |
||||||
|
<result column="IS_DELETED" property="isDeleted"/> |
||||||
|
</resultMap> |
||||||
|
|
||||||
|
</mapper> |
@ -1,20 +0,0 @@ |
|||||||
<?xml version="1.0" encoding="UTF-8"?> |
|
||||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
|
||||||
<mapper namespace="com.hnac.hzims.safeproduct.mapper.CheckItemInstanceMapper"> |
|
||||||
|
|
||||||
|
|
||||||
<select id="getCheckItemInstanceByMonth" resultType="com.hnac.hzims.safeproduct.entity.CheckItemInstanceEntity"> |
|
||||||
SELECT * |
|
||||||
FROM hzims_safe_check_item_instance t |
|
||||||
WHERE t.IS_DELETED = 0 |
|
||||||
AND t.CHECK_ID IN (SELECT id |
|
||||||
FROM hzims_safe_check_month |
|
||||||
WHERE IS_DELETED = 0 AND CREATE_DEPT = #{deptId} AND MONTH IN |
|
||||||
<foreach item="item" index="index" collection="months" open="(" separator="," close=" )"> |
|
||||||
#{item} |
|
||||||
</foreach> |
|
||||||
) |
|
||||||
</select> |
|
||||||
|
|
||||||
|
|
||||||
</mapper> |
|
Loading…
Reference in new issue