From 62507dfea545ed7de7295a079fa107b071c73507 Mon Sep 17 00:00:00 2001 From: PoffyZhang <99775271@qq.com> Date: Thu, 7 Dec 2023 15:23:06 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=97=E8=A1=A8=20=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E9=97=AE=E9=A2=98=20debug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../manage/EarlyWarningStatisticsManage.java | 150 +++++++++++++++++++++ .../model/vo/EarlyWarningStatisticsVO.java | 31 +++-- .../pmapi/projectlib/mapper/ProjectMapper.xml | 15 +++ .../pmapi/sys/utils/EarlyWarningUtil.java | 64 +++++++++ .../pmapi/workbench/manage/WorkbenchManage.java | 35 ++--- 5 files changed, 264 insertions(+), 31 deletions(-) create mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/sys/utils/EarlyWarningUtil.java diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/dashboard/manage/EarlyWarningStatisticsManage.java b/pmapi/src/main/java/com/ningdatech/pmapi/dashboard/manage/EarlyWarningStatisticsManage.java index 084d8b3..76272dc 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/dashboard/manage/EarlyWarningStatisticsManage.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/dashboard/manage/EarlyWarningStatisticsManage.java @@ -1,10 +1,36 @@ package com.ningdatech.pmapi.dashboard.manage; +import cn.hutool.core.collection.CollUtil; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.google.common.collect.Lists; +import com.ningdatech.pmapi.common.enumeration.ProjectProcessStageEnum; +import com.ningdatech.pmapi.common.model.entity.DataDTO; import com.ningdatech.pmapi.dashboard.model.vo.EarlyWarningStatisticsVO; +import com.ningdatech.pmapi.projectlib.enumeration.WarningFlowTypeEnum; +import com.ningdatech.pmapi.projectlib.model.entity.ProjectInst; +import com.ningdatech.pmapi.projectlib.service.IProjectInstService; +import com.ningdatech.pmapi.sys.model.entity.WflowEarlyWarningRecords; +import com.ningdatech.pmapi.sys.service.IEarlyWarningRecordsService; +import com.ningdatech.pmapi.sys.utils.EarlyWarningUtil; +import com.ningdatech.pmapi.user.security.auth.model.UserInfoDetails; +import com.ningdatech.pmapi.user.util.LoginUserUtil; +import com.wflow.enums.WarningRuleTypeEnum; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.flowable.engine.HistoryService; +import org.flowable.engine.TaskService; +import org.flowable.engine.history.HistoricProcessInstance; +import org.flowable.task.api.Task; import org.springframework.stereotype.Component; +import java.time.LocalDateTime; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Set; +import java.util.stream.Collectors; + /** * @Classname EarlyWarningStatisticsManage * @Description @@ -16,13 +42,137 @@ import org.springframework.stereotype.Component; @Slf4j public class EarlyWarningStatisticsManage { + private final IEarlyWarningRecordsService earlyWarningRecordsService; + + private final HistoryService historyService; + + private final IProjectInstService projectInstService; + + private final TaskService taskService; + private static final List threeYears = Lists.newArrayList(LocalDateTime.now().getYear() - 2, + LocalDateTime.now().getYear() - 1,LocalDateTime.now().getYear()); public EarlyWarningStatisticsVO statistics(Integer year) { + UserInfoDetails user = LoginUserUtil.loginUserDetail(); EarlyWarningStatisticsVO res = new EarlyWarningStatisticsVO(); + LambdaQueryWrapper wrapper = Wrappers.lambdaQuery(WflowEarlyWarningRecords.class); + EarlyWarningUtil.buildPermissonWrapper(wrapper,user); + List records = earlyWarningRecordsService.list(wrapper); + //累积总告警数 + res.setAccumulatedAlarmsTotal(records.size()); + res.setAccumulatedAlarmsFlow(records.stream().filter(a -> { + if (Objects.nonNull(a.getRuleType()) && + a.getRuleType().equals(WarningRuleTypeEnum.PROCESS_WARNING.getCode())) { + return Boolean.TRUE; + } + return Boolean.FALSE; + }).collect(Collectors.toList()).size()); + res.setAccumulatedAlarmsFilling(records.stream().filter(a -> { + if (Objects.nonNull(a.getRuleType()) && + a.getRuleType().equals(WarningRuleTypeEnum.DECLARED_WARNING.getCode())) { + return Boolean.TRUE; + } + return Boolean.FALSE; + }).collect(Collectors.toList()).size()); + //近三年 + List threeYearsAlarms = Lists.newArrayList(); + for(Integer thisYear : threeYears){ + DataDTO yearData = new DataDTO(); + yearData.setName(thisYear.toString()); + yearData.setNum(records.stream().filter(r -> { + if(Objects.nonNull(r.getWarningTime()) && + thisYear.equals(r.getWarningTime().getYear())){ + return Boolean.TRUE; + } + return Boolean.FALSE; + }).collect(Collectors.toList()).size()); + threeYearsAlarms.add(yearData); + } + res.setThreeYearsAlarms(threeYearsAlarms); + //当前各流程报警数 + List alarmsFlowsNow = Lists.newArrayList(); + for(ProjectProcessStageEnum stageEnum : ProjectProcessStageEnum.values()){ + DataDTO flowData = new DataDTO(); + String processName = stageEnum.getDesc(); + Integer processType = stageEnum.getCode(); + flowData.setName(processName); + flowData.setCode(processType.toString()); + flowData.setNum(computeFlowWarningNow(processType,records)); + alarmsFlowsNow.add(flowData); + } + res.setAlarmsFlowsNow(alarmsFlowsNow); + + //当前各填报报警数 + List alarmsFillingNow = Lists.newArrayList(); + for(WarningFlowTypeEnum fillingEnum : WarningFlowTypeEnum.values()){ + DataDTO fillingData = new DataDTO(); + String processName = fillingEnum.getDesc(); + Integer processType = fillingEnum.getCode(); + fillingData.setName(processName); + fillingData.setCode(processType.toString()); + fillingData.setNum(computeFlowWarningNow(processType,records)); + alarmsFillingNow.add(fillingData); + } + res.setAlarmsFillingNow(alarmsFillingNow); return res; } + + //计算某个流程当前正在告警的数量 + private Integer computeFlowWarningNow(Integer processType,List records) { + List processRecords = records.stream().filter(r -> { + if (Objects.nonNull(r.getRuleType()) && + WarningRuleTypeEnum.PROCESS_WARNING.getCode().equals(r.getRuleType())) { + return Boolean.TRUE; + } + return Boolean.FALSE; + }).filter(r -> Objects.nonNull(r.getNodeId())).collect(Collectors.toList()); + if(CollUtil.isEmpty(processRecords)){ + return 0; + } + Map> warningMap = processRecords.stream() + .collect(Collectors.groupingBy(WflowEarlyWarningRecords::getNodeId)); + + //1.先查出 所育 这个类型的 流程 + List proInsts = projectInstService.list(Wrappers.lambdaQuery(ProjectInst.class) + .eq(ProjectInst::getInstType, processType)); + if(CollUtil.isEmpty(proInsts)){ + return 0; + } + //2.再筛选一下 选出 正在审核 未完成的 + Set instCodes = proInsts.stream().map(ProjectInst::getInstCode) + .collect(Collectors.toSet()); + List processes = historyService.createHistoricProcessInstanceQuery() + .processInstanceIds(instCodes) + .unfinished() + .orderByProcessInstanceStartTime() + .asc() + .list(); + if(CollUtil.isEmpty(processes)){ + return 0; + } + //查出所有正在执行的工作流任务 + List tasks = taskService.createTaskQuery() + .list(); + if(CollUtil.isEmpty(tasks)){ + return 0; + } + Map> taskMap = tasks.stream() + .collect(Collectors.groupingBy(Task::getProcessInstanceId)); + return processes.stream().filter(p -> { + if(taskMap.containsKey(p.getId())){ + List tasksThis = taskMap.get(p.getId()); + for(Task taskThis : tasksThis){ + //说明 当前有告警 + if(warningMap.containsKey(taskThis.getTaskDefinitionKey())){ + return Boolean.TRUE; + } + } + } + return Boolean.FALSE; + }).collect(Collectors.toList()).size(); + } } diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/dashboard/model/vo/EarlyWarningStatisticsVO.java b/pmapi/src/main/java/com/ningdatech/pmapi/dashboard/model/vo/EarlyWarningStatisticsVO.java index b29b309..91b4de8 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/dashboard/model/vo/EarlyWarningStatisticsVO.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/dashboard/model/vo/EarlyWarningStatisticsVO.java @@ -14,24 +14,27 @@ import java.util.List; public class EarlyWarningStatisticsVO implements Serializable { private static final long serialVersionUID = 1L; - @ApiModelProperty("评审召开总数") - private Integer meetingTotal = 0; + @ApiModelProperty("累积报警数") + private Integer accumulatedAlarmsTotal = 0; - @ApiModelProperty("评审通过数") - private Integer passReview = 0; + @ApiModelProperty("流程累积报警数") + private Integer accumulatedAlarmsFlow = 0; - @ApiModelProperty("评审不通过率") - private BigDecimal notPassRate = BigDecimal.ZERO; + @ApiModelProperty("填报累积报警数") + private Integer accumulatedAlarmsFilling = 0; - @ApiModelProperty("各区县召开总数") - private List regionMeetings; + @ApiModelProperty("近三年累积报警数") + private List threeYearsAlarms; - @ApiModelProperty("预审/验收 会议情况") - private List meetingTypes; + @ApiModelProperty("当前各流程报警情况") + private List alarmsFlowsNow; - @ApiModelProperty("各区县不通过率") - private List notPassRegionMeetings; + @ApiModelProperty("当前各填报报警情况") + private List alarmsFillingNow; - @ApiModelProperty("各部门不通过top10") - private List notPassTop10; + @ApiModelProperty("建设周期预警监测") + private List constructionAlarms; + + @ApiModelProperty("安全监测") + private List safetyMonitoring; } \ No newline at end of file diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/projectlib/mapper/ProjectMapper.xml b/pmapi/src/main/java/com/ningdatech/pmapi/projectlib/mapper/ProjectMapper.xml index 2a7601a..d7dd17c 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/projectlib/mapper/ProjectMapper.xml +++ b/pmapi/src/main/java/com/ningdatech/pmapi/projectlib/mapper/ProjectMapper.xml @@ -68,6 +68,9 @@ and p.build_org_name like concat('%',#{req.buildOrgName},'%') + + and p.build_org_name like concat('%',#{req.buildOrg},'%') + and p.status = #{req.status} @@ -156,6 +159,9 @@ and b.base_build_deprt like concat('%',#{req.buildOrgName},'%') + + and b.base_build_deprt like concat('%',#{req.buildOrg},'%') + and b.base_proj_set_prog = #{req.status} @@ -244,6 +250,9 @@ and b.base_build_deprt like concat('%',#{req.buildOrgName},'%') + + and b.base_build_deprt like concat('%',#{req.buildOrg},'%') + and b.base_proj_set_prog = #{req.status} @@ -356,6 +365,9 @@ and p.build_org_name like concat('%',#{req.buildOrgName},'%') + + and p.build_org_name like concat('%',#{req.buildOrg},'%') + and p.status = #{req.status} @@ -444,6 +456,9 @@ and b.base_build_deprt like concat('%',#{req.buildOrgName},'%') + + and b.base_build_deprt like concat('%',#{req.buildOrg},'%') + and b.base_proj_set_prog = #{req.status} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sys/utils/EarlyWarningUtil.java b/pmapi/src/main/java/com/ningdatech/pmapi/sys/utils/EarlyWarningUtil.java new file mode 100644 index 0000000..3e22e94 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sys/utils/EarlyWarningUtil.java @@ -0,0 +1,64 @@ +package com.ningdatech.pmapi.sys.utils; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.ningdatech.pmapi.projectlib.model.entity.Project; +import com.ningdatech.pmapi.sys.model.entity.WflowEarlyWarningRecords; +import com.ningdatech.pmapi.user.security.auth.model.UserFullInfoDTO; +import com.ningdatech.pmapi.user.security.auth.model.UserInfoDetails; + +/** + * @Classname EarlyWarningUtil + * @Description + * @Date 2023/12/7 14:14 + * @Author PoffyZhang + */ +public class EarlyWarningUtil { + + public static void buildPermissonWrapper(LambdaQueryWrapper wrapper, + UserInfoDetails user) { + //如果是超管的话 + if(user.getSuperAdmin()){ + //可以看所有 + //如果是区管 + }else if(user.getRegionAdmin()){ + wrapper.eq(WflowEarlyWarningRecords::getAreaCode,user.getRegionCode()); + }else if(user.getIsOrgAdmin()){ + wrapper.eq(WflowEarlyWarningRecords::getBuildOrgCode,user.getEmpPosUnitCode()); + }else{ + //否则都只能看自己单位的 + wrapper.eq(WflowEarlyWarningRecords::getBuildOrgCode,user.getEmpPosUnitCode()); + } + } + + public static void buildPermissonFullWrapper(LambdaQueryWrapper wrapper, + UserFullInfoDTO user) { + //如果是超管的话 + if(user.getSuperAdmin()){ + //可以看所有 + //如果是区管 + }else if(user.getRegionAdmin()){ + wrapper.eq(WflowEarlyWarningRecords::getAreaCode,user.getRegionCode()); + }else if(user.getIsOrgAdmin()){ + wrapper.eq(WflowEarlyWarningRecords::getBuildOrgCode,user.getEmpPosUnitCode()); + }else{ + //否则都只能看自己单位的 + wrapper.eq(WflowEarlyWarningRecords::getBuildOrgCode,user.getEmpPosUnitCode()); + } + } + + public static void buildPermissonProjectWrapper(LambdaQueryWrapper wrapper, + UserFullInfoDTO user) { + //如果是超管的话 + if(user.getSuperAdmin()){ + //可以看所有 + //如果是区管 + }else if(user.getRegionAdmin()){ + wrapper.eq(Project::getAreaCode,user.getRegionCode()); + }else if(user.getIsOrgAdmin()){ + wrapper.eq(Project::getBuildOrgCode,user.getEmpPosUnitCode()); + }else{ + //否则都只能看自己单位的 + wrapper.eq(Project::getBuildOrgCode,user.getEmpPosUnitCode()); + } + } +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/workbench/manage/WorkbenchManage.java b/pmapi/src/main/java/com/ningdatech/pmapi/workbench/manage/WorkbenchManage.java index de2232c..4b5c792 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/workbench/manage/WorkbenchManage.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/workbench/manage/WorkbenchManage.java @@ -26,6 +26,7 @@ import com.ningdatech.pmapi.sys.model.req.NoticeListReq; import com.ningdatech.pmapi.sys.model.vo.ProjectEarlyWarningVO; import com.ningdatech.pmapi.sys.service.IEarlyWarningRecordsService; import com.ningdatech.pmapi.sys.service.IProjectEarlyWarningService; +import com.ningdatech.pmapi.sys.utils.EarlyWarningUtil; import com.ningdatech.pmapi.todocenter.manage.TodoCenterManage; import com.ningdatech.pmapi.todocenter.model.req.ToBeProcessedReq; import com.ningdatech.pmapi.todocenter.model.vo.TodoCenterStatisticsVO; @@ -40,6 +41,7 @@ import com.wflow.service.IEarlyWarningService; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; +import org.apache.poi.hssf.record.DVALRecord; import org.springframework.stereotype.Component; import java.time.LocalDateTime; @@ -157,11 +159,10 @@ public class WorkbenchManage { private WorkbenchVO.ProjectEarlyWarning getProjectEarlyWarning(UserFullInfoDTO user) { WorkbenchVO.ProjectEarlyWarning projectEarlyWarning = new WorkbenchVO.ProjectEarlyWarning(); - - List projects = projectService.list(Wrappers.lambdaQuery(Project.class) - .eq(Project::getNewest, Boolean.TRUE) - .eq(user.getRegionAdmin()&&!user.getSuperAdmin(),Project::getAreaCode,user.getRegionCode()) - .eq((user.getIsOrgAdmin()&&!user.getSuperAdmin()) || user.notAdmin(),Project::getBuildOrgCode,user.getEmpPosUnitCode())); + LambdaQueryWrapper projectWrapper = Wrappers.lambdaQuery(Project.class) + .eq(Project::getNewest, Boolean.TRUE); + EarlyWarningUtil.buildPermissonProjectWrapper(projectWrapper,user); + List projects = projectService.list(projectWrapper); Set projectCodeS = Sets.newHashSet(); Map projectNameMap = projects.stream() .filter(p -> projectCodeS.add(p.getProjectCode())) @@ -170,16 +171,16 @@ public class WorkbenchManage { //4.1 //累积预警统计 WorkbenchVO.WarningStatistics accumulate = new WorkbenchVO.WarningStatistics(); - Long overCount = earlyWarningRecordsService.count(Wrappers.lambdaQuery(WflowEarlyWarningRecords.class) + LambdaQueryWrapper overWrapper = Wrappers.lambdaQuery(WflowEarlyWarningRecords.class) .eq(WflowEarlyWarningRecords::getNoticeType, WarningNoticeTypeEnum.OVER.getCode()) - .or(q2 -> q2.isNull(WflowEarlyWarningRecords::getNoticeType)) - .eq(user.getRegionAdmin()&&!user.getSuperAdmin(),WflowEarlyWarningRecords::getAreaCode,user.getRegionCode()) - .eq((user.getIsOrgAdmin()&&!user.getSuperAdmin()) || user.notAdmin(),WflowEarlyWarningRecords::getBuildOrgCode,user.getEmpPosUnitCode())); + .or(q2 -> q2.isNull(WflowEarlyWarningRecords::getNoticeType)); + EarlyWarningUtil.buildPermissonFullWrapper(overWrapper,user); + Long overCount = earlyWarningRecordsService.count(overWrapper); accumulate.setOver(overCount.intValue()); - Long adventCount = earlyWarningRecordsService.count(Wrappers.lambdaQuery(WflowEarlyWarningRecords.class) - .eq(WflowEarlyWarningRecords::getNoticeType, WarningNoticeTypeEnum.ADVENT.getCode()) - .eq(user.getRegionAdmin(),WflowEarlyWarningRecords::getAreaCode,user.getRegionCode()) - .eq((user.getIsOrgAdmin()&&!user.getSuperAdmin()) || user.notAdmin(),WflowEarlyWarningRecords::getBuildOrgCode,user.getEmpPosUnitCode())); + LambdaQueryWrapper adventWrapper = Wrappers.lambdaQuery(WflowEarlyWarningRecords.class) + .eq(WflowEarlyWarningRecords::getNoticeType, WarningNoticeTypeEnum.ADVENT.getCode()); + EarlyWarningUtil.buildPermissonFullWrapper(adventWrapper,user); + Long adventCount = earlyWarningRecordsService.count(adventWrapper); accumulate.setAdvent(adventCount.intValue()); projectEarlyWarning.setAccumulate(accumulate); @@ -189,16 +190,16 @@ public class WorkbenchManage { Page overPage = Page.of(1,1000); Page adventPage = Page.of(1,1000); Page normalPage = Page.of(1,1000); - LambdaQueryWrapper overWrapper = Wrappers.lambdaQuery(ProjectEarlyWarning.class) + LambdaQueryWrapper overPWrapper = Wrappers.lambdaQuery(ProjectEarlyWarning.class) .eq(ProjectEarlyWarning::getStatus, ProjectEarlyWarningStatusEnum.OVER_TIME.name()) .eq(user.getRegionAdmin()&&!user.getSuperAdmin(),ProjectEarlyWarning::getAreaCode,user.getRegionCode()) .eq((user.getIsOrgAdmin()&&!user.getSuperAdmin()) || user.notAdmin(),ProjectEarlyWarning::getBuildOrgCode,user.getEmpPosUnitCode()); - projectEarlyWarningService.page(overPage,overWrapper); - LambdaQueryWrapper adventWrapper = Wrappers.lambdaQuery(ProjectEarlyWarning.class) + projectEarlyWarningService.page(overPage,overPWrapper); + LambdaQueryWrapper adventPWrapper = Wrappers.lambdaQuery(ProjectEarlyWarning.class) .eq(ProjectEarlyWarning::getStatus, ProjectEarlyWarningStatusEnum.ADVENT_TIME.name()) .eq(user.getRegionAdmin()&&!user.getSuperAdmin(),ProjectEarlyWarning::getAreaCode,user.getRegionCode()) .eq((user.getIsOrgAdmin()&&!user.getSuperAdmin()) || user.notAdmin(),ProjectEarlyWarning::getBuildOrgCode,user.getEmpPosUnitCode()); - projectEarlyWarningService.page(adventPage,adventWrapper); + projectEarlyWarningService.page(adventPage,adventPWrapper); LambdaQueryWrapper normalWrapper = Wrappers.lambdaQuery(ProjectEarlyWarning.class) .eq(ProjectEarlyWarning::getStatus, ProjectEarlyWarningStatusEnum.NORMAL.name()) .eq(user.getRegionAdmin()&&!user.getSuperAdmin(),ProjectEarlyWarning::getAreaCode,user.getRegionCode())