9bccf323 sonin

巡检分析 任务指标 详情

1 个父辈 99fae81f
......@@ -158,19 +158,19 @@ public class InspectionAnalysisController {
@GetMapping("/getInspectionTaskIndicators")
public Result<InspectionTaskIndicatorsVO> getInspectionTaskIndicators(String startDate,String endDate){
Result<InspectionTaskIndicatorsVO> result = new Result<>();
InspectionTaskIndicatorsVO inspectionTaskIndicatorsVO = inspectionAnalysisService.getInspectionTaskIndicatorsNew(startDate,endDate);
InspectionTaskIndicatorsVO inspectionTaskIndicatorsVO = inspectionAnalysisService.getInspectionTaskIndicators(startDate,endDate);
result.setSuccess(true);
result.setResult(inspectionTaskIndicatorsVO);
return result;
}
@ApiOperation(value = "巡检分析-巡检任务指标-详情", notes = "巡检分析-巡检任务指标-详情")
@GetMapping("/getInspectionTaskIndicatorsDetail")
public Result<List<InspectionEquipIndicatorsDetailVO>> getInspectionTaskIndicatorsDetail(String departId,String startDate,String endDate){
Result<List<InspectionEquipIndicatorsDetailVO>> result = new Result<>();
public Result<List<InspectionTaskIndicatorsVO>> getInspectionTaskIndicatorsDetail(String departId,String startDate,String endDate){
Result<List<InspectionTaskIndicatorsVO>> result = new Result<>();
if(StringUtils.isEmpty(departId)){
departId = BaseContextHandler.getDeparts();
}
List<InspectionEquipIndicatorsDetailVO> dataList = inspectionAnalysisService.getInspectionTaskIndicatorsDetail( JSUtils.quoteEach(departId,",") ,startDate,endDate);
List<InspectionTaskIndicatorsVO> dataList = inspectionAnalysisService.getInspectionTaskIndicatorsDetail( JSUtils.quoteEach(departId,",") ,startDate,endDate);
result.setSuccess(true);
result.setResult(dataList);
return result;
......
......@@ -28,7 +28,7 @@ public interface IInspectionAnalysisService {
* @param endDate
* @return
*/
List<InspectionEquipIndicatorsDetailVO> getInspectionTaskIndicatorsDetail(String departIds, String startDate, String endDate);
List<InspectionTaskIndicatorsVO> getInspectionTaskIndicatorsDetail(String departIds, String startDate, String endDate);
/***
* 巡检分析-巡检设备指标
* @param startDate
......
......@@ -29,6 +29,8 @@ import java.text.NumberFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;
import java.util.stream.Collectors;
/**
......@@ -381,18 +383,12 @@ public class InspectionAnalysisServiceImpl implements IInspectionAnalysisService
inspectionTaskIndicatorsVO.setAbnormalRate("0");
inspectionTaskIndicatorsVO.setProcessedAbnormalRate("0");
//查询时间内巡检任务信息
InspectionTaskVO inspectionTaskVO = new InspectionTaskVO();
QueryWrapper<InspectionTask> inspectionTaskQueryWrapper = new QueryWrapper();
if (StringUtils.isNotBlank(startDate) && StringUtils.isNotBlank(endDate)) {
inspectionTaskQueryWrapper.ge("inspection_cycle_start_date", startDate + " 00:00:00");
inspectionTaskQueryWrapper.le("inspection_cycle_start_date", endDate + " 23:59:59");
inspectionTaskVO.setStartTime(inspectionTaskVO.getStartTime() + " 00:00:00");
inspectionTaskVO.setEndTime(inspectionTaskVO.getEndTime() + " 23:59:59");
}
// List<InspectionTask> inspectionTaskList = inspectionTaskService.list(inspectionTaskQueryWrapper);
IPage<InspectionTask> pageList = inspectionTaskService.getPage(null, inspectionTaskVO);
List<InspectionTask> inspectionTaskList = pageList.getRecords();
List<InspectionTask> inspectionTaskList = inspectionTaskService.list(inspectionTaskQueryWrapper);
//各状态的数量
Map<String, List<InspectionTask>> taskStateMap = new HashMap<>();
List<InspectionTask> inspectionTasks;
......@@ -411,13 +407,13 @@ public class InspectionAnalysisServiceImpl implements IInspectionAnalysisService
//未检任务
List<InspectionTask> notCheckedInspectionTaskList = taskStateMap.get("3") == null ? new ArrayList<>() : taskStateMap.get("3");
//进行中任务
// List<InspectionTask> inProgressInspectionTaskList = taskStateMap.get("1") == null ? new ArrayList<>() : taskStateMap.get("1");
List<InspectionTask> inProgressInspectionTaskList = taskStateMap.get("1") == null ? new ArrayList<>() : taskStateMap.get("1");
//已检任务数
int checkedInspectionTaskCount = checkedInspectionTaskList.size();
//未检任务数
int notCheckedInspectionTaskCount = notCheckedInspectionTaskList.size();
//进行中任务数
// int inProgressInspectionTaskCount = inProgressInspectionTaskList.size();
int inProgressInspectionTaskCount = inProgressInspectionTaskList.size();
//已检任务ID集合
List<String> checkedInspectionTaskIdList = checkedInspectionTaskList.stream().map(InspectionTask::getId).collect(Collectors.toList());
if (checkedInspectionTaskIdList.size() > 0) {
......@@ -460,12 +456,12 @@ public class InspectionAnalysisServiceImpl implements IInspectionAnalysisService
processInstanceStateMap.put(state, tempProcessInstanceIdList);
}
//异常项数量(问题上报)
// Integer abnormalItemsCount = problemReportPlanList.size();
Integer abnormalItemsCount = problemReportPlanList.size();
//已处理异常项数量(问题上报)
// Integer processedAbnormalItemsCount = 0;
// if (processInstanceStateMap != null && processInstanceStateMap.get(FlowEngineConstant.STATUS_FINISHED) != null) {
// processedAbnormalItemsCount = processInstanceStateMap.get(FlowEngineConstant.STATUS_FINISHED).size();
// }
Integer processedAbnormalItemsCount = 0;
if (processInstanceStateMap != null && processInstanceStateMap.get(FlowEngineConstant.STATUS_FINISHED) != null) {
processedAbnormalItemsCount = processInstanceStateMap.get(FlowEngineConstant.STATUS_FINISHED).size();
}
//完成率
String completionRate = "0";
if (totalInspectionTaskCount != 0) {
......@@ -482,14 +478,14 @@ public class InspectionAnalysisServiceImpl implements IInspectionAnalysisService
abnormalRate = numberFormat.format(abnormalInspectionTaskCount / (double) checkedInspectionTaskCount * 100);
}
//异常项处理率
// String processedAbnormalRate = "0";
// if (abnormalItemsCount != 0) {
// processedAbnormalRate = numberFormat.format(processedAbnormalItemsCount / (double)abnormalItemsCount * 100);
// }
String processedAbnormalRate = "0";
if (abnormalItemsCount != 0) {
processedAbnormalRate = numberFormat.format(processedAbnormalItemsCount / (double)abnormalItemsCount * 100);
}
inspectionTaskIndicatorsVO.setCompletionRate(completionRate);
inspectionTaskIndicatorsVO.setUnCompletionRate(unCompletionRate);
inspectionTaskIndicatorsVO.setAbnormalRate(abnormalRate);
// inspectionTaskIndicatorsVO.setProcessedAbnormalRate(processedAbnormalRate);
inspectionTaskIndicatorsVO.setProcessedAbnormalRate(processedAbnormalRate);
}
return inspectionTaskIndicatorsVO;
}
......@@ -527,8 +523,150 @@ public class InspectionAnalysisServiceImpl implements IInspectionAnalysisService
* @param endDate
* @return
*/
public List<InspectionEquipIndicatorsDetailVO> getInspectionTaskIndicatorsDetail(String departIds, String startDate, String endDate){
return inspectionAnalysisMapper.getInspectionEquipIndicatorsDetail(departIds, startDate, endDate);
public List<InspectionTaskIndicatorsVO> getInspectionTaskIndicatorsDetail(String departIds, String startDate, String endDate){
List<InspectionTaskIndicatorsVO> voList = new ArrayList<>();
//查询时间内巡检任务信息
QueryWrapper<InspectionTask> inspectionTaskQueryWrapper = new QueryWrapper();
if (StringUtils.isNotBlank(startDate) && StringUtils.isNotBlank(endDate)) {
inspectionTaskQueryWrapper.ge("inspection_cycle_start_date", startDate + " 00:00:00");
inspectionTaskQueryWrapper.le("inspection_cycle_start_date", endDate + " 23:59:59");
}
List<InspectionTask> inspectionTaskList = inspectionTaskService.list(inspectionTaskQueryWrapper);
// 巡检任务按照departId分组
Map<String, List<String>> departId2inspectionTaskIdMap = new LinkedHashMap<>();
for (InspectionTask inspectionTask : inspectionTaskList) {
String departId = inspectionTask.getDepartId();
List<String> inspectionTaskIdList = departId2inspectionTaskIdMap.computeIfAbsent(departId, k -> new ArrayList<>());
inspectionTaskIdList.add(inspectionTask.getId());
}
List<CompletableFuture> completableFutureList = new ArrayList<>();
// 翻译
Map<String, String> sysDepartDictMap = businessService.dictMap("sys_depart", null);
// 遍历departId
for (Map.Entry<String, List<String>> entry0: departId2inspectionTaskIdMap.entrySet()) {
String departId = entry0.getKey();
List<String> tempInspectionTaskIdList = entry0.getValue();
completableFutureList.add(CompletableFuture.supplyAsync(() -> {
InspectionTaskIndicatorsVO vo = new InspectionTaskIndicatorsVO();
vo.setDepartName(StringUtils.isEmpty(departId) ? departId : sysDepartDictMap.get(departId));
//初始化数据
vo.setCompletionRate("0");
vo.setUnCompletionRate("0");
vo.setAbnormalRate("0");
vo.setProcessedAbnormalRate("0");
//各状态的数量
Map<String, List<InspectionTask>> taskStateMap = new HashMap<>();
List<InspectionTask> inspectionTasks;
List<InspectionTask> tmpInspectionTaskList = inspectionTaskList.stream().filter(item -> tempInspectionTaskIdList.contains(item.getId())).collect(Collectors.toList());
for (InspectionTask inspectionTask : tmpInspectionTaskList) {
inspectionTasks = new ArrayList<>();
if (taskStateMap.get(inspectionTask.getTaskState()) != null) {
inspectionTasks = taskStateMap.get(inspectionTask.getTaskState());
}
inspectionTasks.add(inspectionTask);
taskStateMap.put(inspectionTask.getTaskState(), inspectionTasks);
}
//应检任务数
int totalInspectionTaskCount = tmpInspectionTaskList.size();
//已检任务
List<InspectionTask> checkedInspectionTaskList = taskStateMap.get("2") == null ? new ArrayList<>() : taskStateMap.get("2");
//未检任务
List<InspectionTask> notCheckedInspectionTaskList = taskStateMap.get("3") == null ? new ArrayList<>() : taskStateMap.get("3");
//进行中任务
List<InspectionTask> inProgressInspectionTaskList = taskStateMap.get("1") == null ? new ArrayList<>() : taskStateMap.get("1");
//已检任务数
int checkedInspectionTaskCount = checkedInspectionTaskList.size();
//未检任务数
int notCheckedInspectionTaskCount = notCheckedInspectionTaskList.size();
//进行中任务数
int inProgressInspectionTaskCount = inProgressInspectionTaskList.size();
//已检任务ID集合
List<String> checkedInspectionTaskIdList = checkedInspectionTaskList.stream().map(InspectionTask::getId).collect(Collectors.toList());
if (checkedInspectionTaskIdList.size() > 0) {
//通过已检任务ID查询填报内容
QueryWrapper<InspectionTaskFillContent> inspectionTaskFillContentQueryWrapper = new QueryWrapper();
inspectionTaskFillContentQueryWrapper.select("inspection_task_id as inspectionTaskId");
inspectionTaskFillContentQueryWrapper.in("inspection_task_id", checkedInspectionTaskIdList);
inspectionTaskFillContentQueryWrapper.eq("choice_state", "0");
inspectionTaskFillContentQueryWrapper.groupBy("inspection_task_id");
List<Map<String, Object>> mapList = inspectionTaskFillContentService.listMaps(inspectionTaskFillContentQueryWrapper);
//异常任务数
int abnormalInspectionTaskCount = mapList.size();
//查询问题上报id集合
QueryWrapper<InspectionTaskProblemReport> inspectionTaskProblemReportQueryWrapper = new QueryWrapper<>();
inspectionTaskFillContentQueryWrapper.in("inspection_task_id", checkedInspectionTaskIdList);
List<InspectionTaskProblemReport> inspectionTaskProblemReportList = inspectionTaskProblemReportService.list(inspectionTaskProblemReportQueryWrapper);
List<String> problemReportIdList = inspectionTaskProblemReportList.stream().map(InspectionTaskProblemReport::getProblemReportPlanId).collect(Collectors.toList());
List<ProblemReportPlan> problemReportPlanList = new ArrayList<>();
if (problemReportIdList.size() > 0) {
QueryWrapper<ProblemReportPlan> problemReportPlanQueryWrapper = new QueryWrapper<>();
problemReportPlanQueryWrapper.in("id", problemReportIdList);
problemReportPlanList = problemReportPlanService.list(problemReportPlanQueryWrapper);
}
//存放问题上报的实例ID
Set<String> processInstanceIdList = problemReportPlanList.stream().map(ProblemReportPlan::getProcessInstanceId).collect(Collectors.toSet());
Map<String, Map<String, String>> processStateMap = new HashMap<>();
if (processInstanceIdList.size() > 0) {
processStateMap = flowBusinessService.getProcessState(processInstanceIdList);
}
Map<String, List<String>> processInstanceStateMap = new HashMap<>();
List<String> tempProcessInstanceIdList;
for (Map.Entry<String, Map<String, String>> entry : processStateMap.entrySet()) {
tempProcessInstanceIdList = new ArrayList<>();
String processInstanceId = entry.getKey();
String state = entry.getValue().get("state");
if (processInstanceStateMap.get(state) != null) {
tempProcessInstanceIdList = processInstanceStateMap.get(state);
}
tempProcessInstanceIdList.add(processInstanceId);
processInstanceStateMap.put(state, tempProcessInstanceIdList);
}
//异常项数量(问题上报)
Integer abnormalItemsCount = problemReportPlanList.size();
//已处理异常项数量(问题上报)
Integer processedAbnormalItemsCount = 0;
if (processInstanceStateMap != null && processInstanceStateMap.get(FlowEngineConstant.STATUS_FINISHED) != null) {
processedAbnormalItemsCount = processInstanceStateMap.get(FlowEngineConstant.STATUS_FINISHED).size();
}
//完成率
String completionRate = "0";
if (totalInspectionTaskCount != 0) {
completionRate = numberFormat.format(checkedInspectionTaskCount / (double) totalInspectionTaskCount * 100);
}
//未检率
String unCompletionRate = "0";
if (totalInspectionTaskCount != 0) {
unCompletionRate = numberFormat.format(notCheckedInspectionTaskCount / (double) totalInspectionTaskCount * 100);
}
//异常率
String abnormalRate = "0";
if (checkedInspectionTaskCount != 0) {
abnormalRate = numberFormat.format(abnormalInspectionTaskCount / (double) checkedInspectionTaskCount * 100);
}
//异常项处理率
String processedAbnormalRate = "0";
if (abnormalItemsCount != 0) {
processedAbnormalRate = numberFormat.format(processedAbnormalItemsCount / (double)abnormalItemsCount * 100);
}
vo.setCompletionRate(completionRate);
vo.setUnCompletionRate(unCompletionRate);
vo.setAbnormalRate(abnormalRate);
vo.setProcessedAbnormalRate(processedAbnormalRate);
}
return vo;
}, (Executor) SpringContextUtils.getBean("taskExecutor2")));
}
// 等待所有子线程处理完毕
CompletableFuture.allOf(completableFutureList.toArray(new CompletableFuture[0])).join();
for (CompletableFuture completableFuture : completableFutureList) {
try {
InspectionTaskIndicatorsVO vo = (InspectionTaskIndicatorsVO) completableFuture.get();
voList.add(vo);
} catch (Exception e) {
e.printStackTrace();
}
}
return voList;
}
/***
......
......@@ -26,4 +26,6 @@ public class InspectionTaskIndicatorsVO {
private String abnormalRate;
@ApiModelProperty(value = "异常项处理率")
private String processedAbnormalRate;
private String departName;
}
......
......@@ -45,4 +45,32 @@ public class TaskPoolConfig {
executor.initialize();
return executor;
}
@Bean(name="taskExecutor2")
public ThreadPoolTaskExecutor taskExecutor2() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
//配置核心线程数:就是线程池中的核心线程数量,这几个核心线程,只是在没有用的时候,也不会被回收
executor.setCorePoolSize(50);
//配置最大线程数:就是线程池中可以容纳的最大线程的数量
executor.setMaxPoolSize(200);
//配置队列大小
executor.setQueueCapacity(500);
//线程池维护线程所允许的空闲时间:就是线程池中除了核心线程之外的其他的最长可以保留的时间,因为在线程池中,除了核心线程即使在无任务的情况下也不能被清除,其余的都是有存活时间的,意思就是非核心线程可以保留的最长的空闲时间
executor.setKeepAliveSeconds(60);
//配置线程池中的线程的名称前缀
executor.setThreadNamePrefix("task-executor2-");
// handler,是一种拒绝策略,我们可以在任务满了之后,拒绝执行某些任务。
// rejection-policy:当pool已经达到max size的时候,如何处理新任务
// CALLER_RUNS:不在新线程中执行任务,而是有调用者所在的线程来执行
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
// AbortPolicy:用于被拒绝任务的处理程序,它将抛出RejectedExecutionException
// CallerRunsPolicy:用于被拒绝任务的处理程序,它直接在execute方法的调用线程中运行被拒绝的任务。
// DiscardOldestPolicy:用于被拒绝任务的处理程序,它放弃最旧的未处理请求,然后重试execute。
// DiscardPolicy:用于被拒绝任务的处理程序,默认情况下它将丢弃被拒绝的任务。
//执行初始化
executor.initialize();
return executor;
}
}
\ No newline at end of file
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!