diff --git a/hz-pm-api/src/main/java/com/hz/pm/api/projectlib/model/enumeration/WarningFlowTypeEnum.java b/hz-pm-api/src/main/java/com/hz/pm/api/projectlib/model/enumeration/WarningFlowTypeEnum.java index 808063e..98e6b25 100644 --- a/hz-pm-api/src/main/java/com/hz/pm/api/projectlib/model/enumeration/WarningFlowTypeEnum.java +++ b/hz-pm-api/src/main/java/com/hz/pm/api/projectlib/model/enumeration/WarningFlowTypeEnum.java @@ -23,15 +23,15 @@ public enum WarningFlowTypeEnum { */ UNIT_INNER_AUDIT(1, "预审申报", null, "declareManage/planDeclaration/preExaminationDeclare"), PRELIMINARY_PREVIEW(2, "建设方案申报", null, "declareManage/constructionPlanDeclare"), - DEPT_UNITED_REVIEW(3, "采购结果备案", ProjectStatus.TO_BE_PURCHASED.getCode(), "declareManage/procurementRecord/purchaseResults"), + WITHOUT_PURCHASE(3, "采购结果备案", ProjectStatus.TO_BE_PURCHASED, "declareManage/procurementRecord/purchaseResults"), CONSTRUCTION_PLAN_REVIEW(4, "初验备案", null, "declareManage/acceptanceApply/initialInspectionRecord"), - PROJECT_FINAL_INSPECTION(5, "验收申报", ProjectStatus.ON_PILOT_RUNNING.getCode(), "declareManage/acceptanceApply/finalInspectionDeclare"); + PROJECT_FINAL_INSPECTION(5, "验收申报", ProjectStatus.ON_PILOT_RUNNING, "declareManage/acceptanceApply/finalInspectionDeclare"); private Integer code; private String desc; //对应的 待提交时的项目状态 - private Integer projectStutas; + private ProjectStatus projectStatus; private String path; diff --git a/hz-pm-api/src/main/java/com/hz/pm/api/projectlib/service/IProjectStatusChangeService.java b/hz-pm-api/src/main/java/com/hz/pm/api/projectlib/service/IProjectStatusChangeService.java index a2b7dc2..8467ed9 100644 --- a/hz-pm-api/src/main/java/com/hz/pm/api/projectlib/service/IProjectStatusChangeService.java +++ b/hz-pm-api/src/main/java/com/hz/pm/api/projectlib/service/IProjectStatusChangeService.java @@ -78,4 +78,15 @@ public interface IProjectStatusChangeService extends IService listLastEventMap(Collection projectCodes, + ProjectStateChangeEvent event) { + Wrapper query = Wrappers.lambdaQuery(ProjectStatusChange.class) + .in(ProjectStatusChange::getProjectCode, projectCodes) + .eq(ProjectStatusChange::getEvent, event) + .orderByDesc(ProjectStatusChange::getCreateOn); + return BizUtils.groupFirstMap(list(query), + ProjectStatusChange::getProjectCode, + Comparator.comparing(ProjectStatusChange::getCreateOn).reversed()); + } + } diff --git a/hz-pm-api/src/main/java/com/hz/pm/api/scheduler/task/EarlyWarningProjectTask.java b/hz-pm-api/src/main/java/com/hz/pm/api/scheduler/task/EarlyWarningProjectTask.java index 935f29e..7128109 100644 --- a/hz-pm-api/src/main/java/com/hz/pm/api/scheduler/task/EarlyWarningProjectTask.java +++ b/hz-pm-api/src/main/java/com/hz/pm/api/scheduler/task/EarlyWarningProjectTask.java @@ -1,7 +1,6 @@ package com.hz.pm.api.scheduler.task; import cn.hutool.core.collection.CollUtil; -import cn.hutool.core.date.StopWatch; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.google.common.collect.Sets; import com.hz.pm.api.common.model.constant.BizConst; @@ -10,6 +9,7 @@ import com.hz.pm.api.projectlib.model.entity.ProjectRenewalFundDeclaration; import com.hz.pm.api.projectlib.model.enumeration.ProjectRenewalApprovalStatusEnum; import com.hz.pm.api.projectlib.model.enumeration.WarningFlowTypeEnum; import com.hz.pm.api.projectlib.model.enumeration.WarningOperationTypeEnum; +import com.hz.pm.api.projectlib.model.enumeration.status.ProjectStatus; import com.hz.pm.api.projectlib.service.IProjectRenewalFundDeclarationService; import com.hz.pm.api.projectlib.service.IProjectService; import com.hz.pm.api.sys.enumeration.ProjectEarlyWarningStatusEnum; @@ -23,12 +23,9 @@ import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.flowable.engine.TaskService; import org.flowable.task.api.Task; -import org.springframework.beans.factory.annotation.Value; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; -import java.net.InetAddress; -import java.net.UnknownHostException; import java.time.LocalDateTime; import java.util.List; import java.util.Map; @@ -52,26 +49,13 @@ public class EarlyWarningProjectTask { private final IEarlyWarningRecordsService earlyWarningRecordsService; private final IProjectRenewalFundDeclarationService renewalFundDeclarationService; private final TaskService taskService; - @Value("${hostname:}") - private String HOST_NAME; - - @Scheduled(fixedDelay = 12, initialDelay = 1, timeUnit = TimeUnit.MINUTES) - public void doEarlyWarningDeclared() throws UnknownHostException { - if (!HOST_NAME.equals(InetAddress.getLocalHost().getHostName())) { - return; - } - - log.info("=========== 预警项目维度任务开始 ========"); - StopWatch stopWatch = new StopWatch(); - stopWatch.start(); + @Scheduled(fixedDelay = 5, initialDelay = 5, timeUnit = TimeUnit.MINUTES) + public void doEarlyWarningDeclared() { List projects = projectService.list(Wrappers.lambdaQuery(Project.class) .eq(Project::getNewest, Boolean.TRUE)); if (CollUtil.isEmpty(projects)) { - log.info("系统没有项目 退出任务"); - stopWatch.stop(); - log.info("=========== 预警项目维度任务结束 耗时{}s", stopWatch.getTotalTimeSeconds()); return; } @@ -122,15 +106,9 @@ public class EarlyWarningProjectTask { //3.去查询 各个报警 是否已经正常 List trueWarnings = warnings.stream().filter(w -> Objects.nonNull(w.getNormal()) && !w.getNormal()).collect(Collectors.toList()); if (CollUtil.isEmpty(trueWarnings)) { - log.info("没有异常的项目 要去查询"); - stopWatch.stop(); - log.info("=========== 预警项目维度任务结束 耗时{}s", stopWatch.getTotalTimeSeconds()); return; } checkNormal(trueWarnings); - - stopWatch.stop(); - log.info("=========== 预警项目维度任务结束 耗时{}s", stopWatch.getTotalTimeSeconds()); } //3.去查询 各个报警 是否已经正常 @@ -272,9 +250,9 @@ public class EarlyWarningProjectTask { if (Objects.isNull(flowTypeEnum)) { continue; } - Integer projectStutas = flowTypeEnum.getProjectStutas(); + ProjectStatus projectStatus = flowTypeEnum.getProjectStatus(); //已经不是这个状态了 说明已经被提交了 - if (!projectStutas.equals(project.getStatus())) { + if (!projectStatus.eq(project.getStatus())) { declaredWarning.setDeclaredWarning(Boolean.FALSE); //其它三种 都没有 说明已经正常了 if (!declaredWarning.getProcessWarning() && diff --git a/hz-pm-api/src/main/java/com/hz/pm/api/scheduler/task/EarlyWarningInstanceNotStartTask.java b/hz-pm-api/src/main/java/com/hz/pm/api/scheduler/task/EarlyWarningWithoutSubmitTask.java similarity index 85% rename from hz-pm-api/src/main/java/com/hz/pm/api/scheduler/task/EarlyWarningInstanceNotStartTask.java rename to hz-pm-api/src/main/java/com/hz/pm/api/scheduler/task/EarlyWarningWithoutSubmitTask.java index 8fcb127..8cbc64e 100644 --- a/hz-pm-api/src/main/java/com/hz/pm/api/scheduler/task/EarlyWarningInstanceNotStartTask.java +++ b/hz-pm-api/src/main/java/com/hz/pm/api/scheduler/task/EarlyWarningWithoutSubmitTask.java @@ -2,6 +2,7 @@ package com.hz.pm.api.scheduler.task; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.date.StopWatch; +import cn.hutool.core.util.NumberUtil; import cn.hutool.core.util.StrUtil; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; @@ -11,23 +12,29 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.hz.pm.api.common.enumeration.CommonEnum; +import com.hz.pm.api.common.statemachine.event.ProjectStateChangeEvent; +import com.hz.pm.api.common.util.EnvironmentUtil; import com.hz.pm.api.common.util.StrUtils; import com.hz.pm.api.projectdeclared.model.entity.Operation; import com.hz.pm.api.projectdeclared.service.IOperationService; import com.hz.pm.api.projectlib.model.entity.Project; import com.hz.pm.api.projectlib.model.entity.ProjectRenewalFundDeclaration; +import com.hz.pm.api.projectlib.model.entity.ProjectStatusChange; import com.hz.pm.api.projectlib.model.enumeration.ProjectRenewalApprovalStatusEnum; import com.hz.pm.api.projectlib.model.enumeration.WarningFlowTypeEnum; import com.hz.pm.api.projectlib.model.enumeration.WarningNoticeTypeEnum; import com.hz.pm.api.projectlib.model.enumeration.WarningOperationTypeEnum; import com.hz.pm.api.projectlib.service.IProjectRenewalFundDeclarationService; import com.hz.pm.api.projectlib.service.IProjectService; +import com.hz.pm.api.projectlib.service.IProjectStatusChangeService; import com.hz.pm.api.sys.manage.EarlyWarningManage; import com.hz.pm.api.sys.manage.RoleManage; import com.hz.pm.api.sys.service.IProjectEarlyWarningService; +import com.hz.pm.api.user.helper.MhUnitCache; import com.hz.pm.api.user.model.entity.UserInfo; import com.hz.pm.api.user.model.enumeration.RoleEnum; import com.hz.pm.api.user.service.IUserInfoService; +import com.ningdatech.basic.util.CollUtils; import com.ningdatech.basic.util.StrPool; import com.wflow.bean.entity.WflowEarlyWarning; import com.wflow.enums.WarningRuleTypeEnum; @@ -42,6 +49,7 @@ import org.springframework.stereotype.Component; import java.net.UnknownHostException; import java.time.Duration; import java.time.LocalDateTime; +import java.time.temporal.ChronoUnit; import java.util.List; import java.util.Map; import java.util.Objects; @@ -55,8 +63,8 @@ import java.util.stream.Collectors; @Slf4j @Component @RequiredArgsConstructor -@ConditionalOnExpression("${early-warning-instance-task:false}") -public class EarlyWarningInstanceNotStartTask { +@ConditionalOnExpression("${early-warning-without-submit.open:false}") +public class EarlyWarningWithoutSubmitTask { private final IEarlyWarningService earlyWarningService; private final IProjectService projectService; @@ -66,11 +74,22 @@ public class EarlyWarningInstanceNotStartTask { private final IProjectRenewalFundDeclarationService renewalFundDeclarationService; private final RoleManage roleManage; private final IProjectEarlyWarningService projectEarlyWarningService; + private final MhUnitCache mhUnitCache; + private final IProjectStatusChangeService projectStatusChangeService; + private final EnvironmentUtil environmentUtil; + + private ChronoUnit getTimeUnit() { + if (environmentUtil.isDevEnv()) { + return ChronoUnit.MINUTES; + } else { + return ChronoUnit.DAYS; + } + } /** * 填报预警 */ - @Scheduled(cron = "${early-warning-instance-task.cron:0 0/5 * * * ?}") + @Scheduled(cron = "${early-warning-without-submit.cron:0 0/5 * * * ?}") public void doEarlyWarningDeclared() { StopWatch stopWatch = new StopWatch(); stopWatch.start(); @@ -80,14 +99,8 @@ public class EarlyWarningInstanceNotStartTask { .eq(WflowEarlyWarning::getIsOpen, true); List warnings = earlyWarningService.list(query); for (WflowEarlyWarning warning : warnings) { - String noticeMethod = warning.getNoticeMethod(); - if (StringUtils.isBlank(noticeMethod) || - (!noticeMethod.contains(String.valueOf(CommonEnum.ZWDD.getCode())) && - !noticeMethod.contains(String.valueOf(CommonEnum.MOBILE.getCode())))) { - log.info("通知方式为空或者错误!"); - return; - } - + long mhUnitId = NumberUtil.parseLong(warning.getAreaCode()); + List viewUnitIds = mhUnitCache.getViewChildIdsRecursion(mhUnitId); String noticeContent = warning.getNoticeContent(); String adventContent = warning.getAdventContent(); String rule = warning.getRule(); @@ -100,63 +113,59 @@ public class EarlyWarningInstanceNotStartTask { Integer biz = rJson.getInteger("biz"); String notice = rJson.getString("notice"); Integer adventTime = rJson.getInteger("adventTime"); - if ((Objects.isNull(time) && Objects.isNull(adventTime)) || Objects.isNull(biz)) { - log.info("规则数据 错误 :{}", rJson); + WarningFlowTypeEnum flowType = WarningFlowTypeEnum.getByCode(biz); + if (((Objects.isNull(time) && Objects.isNull(adventTime)) || Objects.isNull(biz)) + || StrUtil.isBlank(notice) + || flowType == null) { + log.warn("规则数据 错误 :{}", rJson); return; } - - if (StringUtils.isBlank(notice)) { - log.info("取不到提醒人配置 : " + rJson); - return; - } - - WarningFlowTypeEnum flowTypeEnum = WarningFlowTypeEnum.getByCode(biz); - if (Objects.isNull(flowTypeEnum)) { - log.info("匹配不到 业务类型"); - return; - } - String path = flowTypeEnum.getPath(); - - //得出 对应待提交的项目状态 - Integer projectStatus = flowTypeEnum.getProjectStutas(); - String areaCode = warning.getAreaCode(); - //测试先用分钟 + String path = flowType.getPath(); //查询 所有这个区域的项目 未提交的项目 - List needNextProjects = projectService.list(Wrappers.lambdaQuery(Project.class) - .eq(Project::getAreaCode, areaCode) + Wrapper projectQuery = Wrappers.lambdaQuery(Project.class) + .eq(Project::getBuildOrgCode, viewUnitIds) .eq(Project::getNewest, Boolean.TRUE) - .eq(Project::getStatus, projectStatus)); - + .eq(Project::getStatus, flowType.getProjectStatus().getCode()); + List needNextProjects = projectService.list(projectQuery); Map> noticeMap = Maps.newHashMap(); - //需要发通知的项目 + List projectCodes = CollUtils.fieldList(needNextProjects, Project::getProjectCode); + Map projectStatusChangeMap; + switch (flowType) { + case WITHOUT_PURCHASE: + projectStatusChangeMap = projectStatusChangeService.listLastEventMap(projectCodes, + ProjectStateChangeEvent.DECLARED_RECORD_PASS); + break; + default: + return; + } + // 需要发通知的项目 List needToWaringProjects = needNextProjects.stream() .filter(p -> { + ProjectStatusChange change = projectStatusChangeMap.get(p.getProjectCode()); List noticeTypes = Lists.newArrayList(); - if (Objects.nonNull(time) && Duration.between(p.getUpdateOn(), LocalDateTime.now()).toMinutes() >= time * 60 && //time * 60 - Duration.between(p.getUpdateOn(), LocalDateTime.now()).toMinutes() <= time * 60 + 1) { //time * 60 - noticeTypes.add(com.wflow.enums.WarningNoticeTypeEnum.OVER.getCode()); - } - if (Objects.nonNull(adventTime) && Duration.between(p.getUpdateOn(), LocalDateTime.now()).toMinutes() >= adventTime * 60 && //time * 60 - Duration.between(p.getUpdateOn(), LocalDateTime.now()).toMinutes() <= adventTime * 60 + 1) { - noticeTypes.add(com.wflow.enums.WarningNoticeTypeEnum.ADVENT.getCode()); - } - if (CollUtil.isNotEmpty(noticeTypes)) { - noticeMap.put(p.getProjectCode(), noticeTypes); - //项目 填报预警 - projectEarlyWarningService.earlyWarning(p, - WarningRuleTypeEnum.DECLARED_WARNING.getCode(), noticeTypes); - return Boolean.TRUE; + LocalDateTime touchTime = change == null ? null : change.getCreateOn(); + if (touchTime != null) { + if (Objects.nonNull(time)) { + long duration = Duration.between(touchTime, LocalDateTime.now()).get(getTimeUnit()); + if (duration >= time && duration < time + (environmentUtil.isDevEnv() ? 5 : 1)) { + noticeTypes.add(com.wflow.enums.WarningNoticeTypeEnum.OVER.getCode()); + } + } + if (Objects.nonNull(adventTime)) { + long duration = Duration.between(touchTime, LocalDateTime.now()).get(getTimeUnit()); + if (duration >= adventTime && duration < adventTime + (environmentUtil.isDevEnv() ? 5 : 1)) { + noticeTypes.add(com.wflow.enums.WarningNoticeTypeEnum.ADVENT.getCode()); + } + } + if (CollUtil.isNotEmpty(noticeTypes)) { + noticeMap.put(p.getProjectCode(), noticeTypes); + //项目 填报预警 + projectEarlyWarningService.earlyWarning(p, WarningRuleTypeEnum.DECLARED_WARNING.getCode(), noticeTypes); + return Boolean.TRUE; + } } return Boolean.FALSE; - }) - .collect(Collectors.toList()); - - if (StringUtils.isBlank(noticeMethod) || - (!noticeMethod.contains(String.valueOf(CommonEnum.ZWDD.getCode())) && - !noticeMethod.contains(String.valueOf(CommonEnum.MOBILE.getCode())))) { - log.info("通知方式为空或者错误!"); - return; - } + }).collect(Collectors.toList()); for (Project needToWaringProject : needToWaringProjects) { String username; @@ -197,7 +206,7 @@ public class EarlyWarningInstanceNotStartTask { List noticeTypes = noticeMap.get(needToWaringProject.getProjectCode()); for (Integer noticeType : noticeTypes) { for (String employeeCode : batchEmployees) { - earlyWarningManage.doEarlyWarning(noticeMethod, Objects.nonNull(noticeType) && noticeType.equals(1) ? noticeContent : adventContent, + earlyWarningManage.doEarlyWarning(warning.getNoticeMethod(), Objects.nonNull(noticeType) && noticeType.equals(1) ? noticeContent : adventContent, adventTime, time, biz, needToWaringProject.getUpdateOn(), Long.valueOf(employeeCode), needToWaringProject, WarningRuleTypeEnum.DECLARED_WARNING.getCode(), noticeType, path, batchEmployeesStr, @@ -216,7 +225,7 @@ public class EarlyWarningInstanceNotStartTask { log.info("=========== 预警填报超时任务结束 耗时{}s", stopWatch.getTotalTimeSeconds()); } - @Scheduled(cron = "10 0/2 * * * ?") + //@Scheduled(cron = "10 0/2 * * * ?") public void doEarlyWarningOperation() throws UnknownHostException { log.info("=========== 预警实施超时任务开始 ========"); StopWatch stopWatch = new StopWatch(); @@ -400,7 +409,7 @@ public class EarlyWarningInstanceNotStartTask { * * @throws UnknownHostException */ - @Scheduled(cron = "20 0/2 * * * ?") + //@Scheduled(cron = "20 0/2 * * * ?") public void doEarlyWarningRenewalFund() throws UnknownHostException { log.info("=========== 预警续建资金项目 超时任务开始 ========"); StopWatch stopWatch = new StopWatch(); diff --git a/hz-pm-api/src/main/java/com/hz/pm/api/sys/manage/EarlyWarningManage.java b/hz-pm-api/src/main/java/com/hz/pm/api/sys/manage/EarlyWarningManage.java index 074c5e1..af39f3e 100644 --- a/hz-pm-api/src/main/java/com/hz/pm/api/sys/manage/EarlyWarningManage.java +++ b/hz-pm-api/src/main/java/com/hz/pm/api/sys/manage/EarlyWarningManage.java @@ -108,7 +108,7 @@ public class EarlyWarningManage { records.setRuleType(WarningRuleTypeEnum.RENEWAL_FUND.getCode()); break; default: - log.info("匹配不到 规则类型"); + log.warn("匹配不到 规则类型"); return; } diff --git a/hz-pm-api/src/main/java/com/hz/pm/api/workbench/controller/WorkbenchController.java b/hz-pm-api/src/main/java/com/hz/pm/api/workbench/controller/WorkbenchController.java index 29cae02..8c2298a 100644 --- a/hz-pm-api/src/main/java/com/hz/pm/api/workbench/controller/WorkbenchController.java +++ b/hz-pm-api/src/main/java/com/hz/pm/api/workbench/controller/WorkbenchController.java @@ -7,6 +7,7 @@ import com.hz.pm.api.workbench.model.WorkbenchProjectLibReq; import com.hz.pm.api.workbench.model.WorkbenchReq; import com.hz.pm.api.workbench.model.vo.ProjectProcessStatVO; import com.hz.pm.api.workbench.model.vo.ProjectTotalViewVO; +import com.hz.pm.api.workbench.model.vo.WorkbenchProjectEarlyWarnVO; import com.hz.pm.api.workbench.model.vo.WorkbenchVO; import com.ningdatech.basic.model.PageVo; import com.ningdatech.log.annotation.WebLog; @@ -73,8 +74,14 @@ public class WorkbenchController { @GetMapping("/systemReplaceInfos") @ApiOperation("获取项目替代情况") - public SystemReplaceInfoVO systemReplaceInfos(WorkbenchProjectLibReq req ) { + public SystemReplaceInfoVO systemReplaceInfos(WorkbenchProjectLibReq req) { return workbenchManage.listSystemReplaceInfos(req); } + @GetMapping("/projectEarlyWarnings") + @ApiOperation("获取项目预警") + public WorkbenchProjectEarlyWarnVO projectEarlyWarnings(WorkbenchReq req) { + return workbenchManage.projectEarlyWarnings(req); + } + } diff --git a/hz-pm-api/src/main/java/com/hz/pm/api/workbench/manage/WorkbenchManage.java b/hz-pm-api/src/main/java/com/hz/pm/api/workbench/manage/WorkbenchManage.java index 2b5afb1..dab0f74 100644 --- a/hz-pm-api/src/main/java/com/hz/pm/api/workbench/manage/WorkbenchManage.java +++ b/hz-pm-api/src/main/java/com/hz/pm/api/workbench/manage/WorkbenchManage.java @@ -1,13 +1,17 @@ package com.hz.pm.api.workbench.manage; +import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.map.MapUtil; import cn.hutool.core.util.NumberUtil; import cn.hutool.core.util.StrUtil; import com.baomidou.mybatisplus.core.conditions.Wrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Assert; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.google.common.collect.Sets; import com.hz.pm.api.common.helper.UserInfoHelper; import com.hz.pm.api.common.model.constant.BizConst; import com.hz.pm.api.common.model.constant.ExistsSqlConst; @@ -36,9 +40,13 @@ import com.hz.pm.api.projectlib.service.IProjectGovSystemReplaceInfosService; import com.hz.pm.api.projectlib.service.IProjectService; import com.hz.pm.api.projectlib.service.IProjectStatusChangeService; import com.hz.pm.api.projectlib.service.IPurchaseStatusChangeService; +import com.hz.pm.api.sys.enumeration.ProjectEarlyWarningStatusEnum; import com.hz.pm.api.sys.manage.EarlyWarningManage; +import com.hz.pm.api.sys.model.entity.ProjectEarlyWarning; import com.hz.pm.api.sys.model.entity.WflowEarlyWarningRecords; +import com.hz.pm.api.sys.model.vo.ProjectEarlyWarningVO; import com.hz.pm.api.sys.service.IEarlyWarningRecordsService; +import com.hz.pm.api.sys.service.IProjectEarlyWarningService; import com.hz.pm.api.todocenter.manage.TodoCenterManage; import com.hz.pm.api.todocenter.model.req.ToBeProcessedReq; import com.hz.pm.api.todocenter.model.vo.ResToBeProcessedVO; @@ -51,10 +59,7 @@ import com.hz.pm.api.workbench.converter.WorkbenchConverter; import com.hz.pm.api.workbench.model.WorkbenchProcessNode; import com.hz.pm.api.workbench.model.WorkbenchProjectLibReq; import com.hz.pm.api.workbench.model.WorkbenchReq; -import com.hz.pm.api.workbench.model.vo.ProjectProcessStatVO; -import com.hz.pm.api.workbench.model.vo.ProjectTotalViewVO; -import com.hz.pm.api.workbench.model.vo.SystemReplaceStatVO; -import com.hz.pm.api.workbench.model.vo.WorkbenchVO; +import com.hz.pm.api.workbench.model.vo.*; import com.ningdatech.basic.model.PageVo; import com.ningdatech.basic.util.CollUtils; import com.ningdatech.basic.util.StrPool; @@ -105,6 +110,7 @@ public class WorkbenchManage { private final MhUnitCache mhUnitCache; private final IProjectGovSystemReplaceInfosService systemReplaceInfosService; private final IPurchaseStatusChangeService purchaseStatusChangeService; + private final IProjectEarlyWarningService projectEarlyWarningService; public WorkbenchVO getWorkbenchData(Integer year) { WorkbenchVO res = new WorkbenchVO(); @@ -697,4 +703,96 @@ public class WorkbenchManage { retDetail.setReplaceDetail(retList); return retDetail; } + + public WorkbenchProjectEarlyWarnVO projectEarlyWarnings(WorkbenchReq req) { + Long unitId = Optional.ofNullable(req.getUnitId()).orElseGet(LoginUserUtil::getMhUnitId); + List viewUnitIds = mhUnitCache.getViewChildIdsRecursion(unitId); + List viewUnitIdList = CollUtils.convert(viewUnitIds, String::valueOf); + WorkbenchProjectEarlyWarnVO earlyWarningStat = new WorkbenchProjectEarlyWarnVO(); + LambdaQueryWrapper pageQuery = Wrappers.lambdaQuery(ProjectEarlyWarning.class) + .in(ProjectEarlyWarning::getBuildOrgCode, viewUnitIdList); + QueryWrapper countQuery = new QueryWrapper<>(); + countQuery.select("count(1) \"total\", status \"status\""); + countQuery.in("build_org_code", viewUnitIdList); + if (req.getUnitStrip() != null) { + String unitStripSql = String.format("select 1 from nd_project np where " + + "np.project_code = nd_project_early_warning.project_code " + + " and np.newest = 1 and np.unit_strip = %d", req.getUnitStrip()); + countQuery.exists(unitStripSql); + pageQuery.exists(unitStripSql); + } + if (req.getProjectYear() != null) { + LocalDate startDate = LocalDate.of(req.getProjectYear(), 1, 1); + LocalDate endDate = LocalDate.now().plusDays(1); + pageQuery.between(ProjectEarlyWarning::getCreateOn, startDate, endDate); + countQuery.between("create_on", startDate, endDate); + } + countQuery.groupBy("status"); + List> counts = projectEarlyWarningService.listMaps(countQuery); + Map countMap = CollUtils.listToMap(counts, + w -> MapUtil.getStr(w, "status"), w -> MapUtil.getInt(w, "total")); + earlyWarningStat.setOvertime(countMap.getOrDefault(ProjectEarlyWarningStatusEnum.OVER_TIME.name(), 0)); + earlyWarningStat.setAdvent(countMap.getOrDefault(ProjectEarlyWarningStatusEnum.ADVENT_TIME.name(), 0)); + earlyWarningStat.setTotal(earlyWarningStat.getAdvent() + earlyWarningStat.getOvertime()); + if (counts.isEmpty()) { + return earlyWarningStat; + } + if (req.getProjectEarlyWarningStatus() == null) { + pageQuery.in(ProjectEarlyWarning::getStatus, ProjectEarlyWarningStatusEnum.OVER_TIME, + ProjectEarlyWarningStatusEnum.ADVENT_TIME); + } else { + pageQuery.eq(ProjectEarlyWarning::getStatus, req.getProjectEarlyWarningStatus()); + } + Page page = Page.of(1, 500); + if (req.getProjectEarlyWarningStatus() == null) { + pageQuery.in(ProjectEarlyWarning::getStatus, ProjectEarlyWarningStatusEnum.OVER_TIME, + ProjectEarlyWarningStatusEnum.ADVENT_TIME); + } else { + pageQuery.eq(ProjectEarlyWarning::getStatus, req.getProjectEarlyWarningStatus()); + } + projectEarlyWarningService.page(page, pageQuery); + if (CollUtil.isNotEmpty(page.getRecords())) { + List projectCodes = CollUtils.fieldList(page.getRecords(), ProjectEarlyWarning::getProjectCode); + + Wrapper wewQuery = Wrappers.lambdaQuery(WflowEarlyWarningRecords.class) + .in(WflowEarlyWarningRecords::getProjectCode, projectCodes) + .orderByDesc(WflowEarlyWarningRecords::getWarningTime); + List warningRecords = earlyWarningRecordsService.list(wewQuery); + Set projectCodeSet = Sets.newHashSet(); + Map warningMap = warningRecords.stream() + .filter(w -> projectCodeSet.add(w.getProjectCode())) + .collect(Collectors.toMap(WflowEarlyWarningRecords::getProjectCode, w -> w)); + + Wrapper projectQuery = Wrappers.lambdaQuery(Project.class) + .select(Project::getProjectCode, Project::getProjectName) + .in(Project::getProjectCode, projectCodes) + .eq(Project::getNewest, Boolean.TRUE); + List projects = projectService.list(projectQuery); + Map projectNameMap = projects.stream() + .collect(Collectors.toMap(Project::getProjectCode, Project::getProjectName)); + + List warnings = page.getRecords().stream().map(o -> { + ProjectEarlyWarningVO vo = BeanUtil.copyProperties(o, ProjectEarlyWarningVO.class); + //取最新一条预警信息 + if (warningMap.containsKey(vo.getProjectCode())) { + WflowEarlyWarningRecords wew = warningMap.get(vo.getProjectCode()); + vo.setWarningTime(wew.getWarningTime()); + vo.setInstStart(wew.getInstStart()); + vo.setWarningUserId(wew.getWarningUserId()); + vo.setNoticeMethod(wew.getNoticeMethod()); + vo.setNoticeContent(wew.getNoticeContent()); + vo.setPath(wew.getPath()); + vo.setBatchUserIds(wew.getBatchUserIds()); + vo.setRecordId(wew.getId()); + } + vo.setProjectName(projectNameMap.get(o.getProjectCode())); + return vo; + }).filter(w -> Objects.nonNull(w.getWarningTime())) + .sorted(Comparator.comparing(ProjectEarlyWarningVO::getWarningTime).reversed()) + .collect(Collectors.toList()); + earlyWarningStat.setProjectEarlyWarnings(warnings); + } + return earlyWarningStat; + } + } diff --git a/hz-pm-api/src/main/java/com/hz/pm/api/workbench/model/WorkbenchReq.java b/hz-pm-api/src/main/java/com/hz/pm/api/workbench/model/WorkbenchReq.java index 94bc2e2..db9ad0d 100644 --- a/hz-pm-api/src/main/java/com/hz/pm/api/workbench/model/WorkbenchReq.java +++ b/hz-pm-api/src/main/java/com/hz/pm/api/workbench/model/WorkbenchReq.java @@ -1,5 +1,6 @@ package com.hz.pm.api.workbench.model; +import com.hz.pm.api.sys.enumeration.ProjectEarlyWarningStatusEnum; import io.swagger.annotations.ApiModelProperty; import lombok.Data; @@ -21,4 +22,7 @@ public class WorkbenchReq { @ApiModelProperty("领域") private Integer unitStrip; + @ApiModelProperty("预警状态") + private ProjectEarlyWarningStatusEnum projectEarlyWarningStatus; + } diff --git a/hz-pm-api/src/main/java/com/hz/pm/api/workbench/model/vo/WorkbenchProjectEarlyWarnVO.java b/hz-pm-api/src/main/java/com/hz/pm/api/workbench/model/vo/WorkbenchProjectEarlyWarnVO.java new file mode 100644 index 0000000..1f2ce15 --- /dev/null +++ b/hz-pm-api/src/main/java/com/hz/pm/api/workbench/model/vo/WorkbenchProjectEarlyWarnVO.java @@ -0,0 +1,29 @@ +package com.hz.pm.api.workbench.model.vo; + +import com.hz.pm.api.sys.model.vo.ProjectEarlyWarningVO; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.util.List; + +/** + *

+ * ProjectEarlyWarning + *

+ * + * @author WendyYang + * @since 00:28 2024/8/28 + */ +@Data +public class WorkbenchProjectEarlyWarnVO { + + private Integer total; + + private Integer advent; + + private Integer overtime; + + @ApiModelProperty("超期项目预警") + private List projectEarlyWarnings; + +} \ No newline at end of file diff --git a/hz-pm-api/src/main/java/com/hz/pm/api/workbench/model/vo/WorkbenchVO.java b/hz-pm-api/src/main/java/com/hz/pm/api/workbench/model/vo/WorkbenchVO.java index 792ffa1..469097d 100644 --- a/hz-pm-api/src/main/java/com/hz/pm/api/workbench/model/vo/WorkbenchVO.java +++ b/hz-pm-api/src/main/java/com/hz/pm/api/workbench/model/vo/WorkbenchVO.java @@ -3,10 +3,8 @@ package com.hz.pm.api.workbench.model.vo; import cn.hutool.core.util.ObjectUtil; import com.hz.pm.api.projectlib.model.vo.ProjectLibListItemVO; import com.hz.pm.api.sys.model.vo.NoticeListItemVO; -import com.hz.pm.api.sys.model.vo.ProjectEarlyWarningVO; import com.hz.pm.api.sys.model.vo.WflowEarlyWarningRecordsVO; import com.hz.pm.api.todocenter.model.vo.TodoCenterStatisticsVO; -import com.ningdatech.basic.model.PageVo; import io.swagger.annotations.ApiModelProperty; import lombok.Data; @@ -25,14 +23,6 @@ import java.util.Objects; @Data public class WorkbenchVO { - @ApiModelProperty("待办中心统计数据 以及代办处理") - public TodoCenterStatisticsVO todoCerter; - - @ApiModelProperty("单位申报管理统计数据") - public DeclaredStatistics orgDeclared; - - @ApiModelProperty("区域申报管理统计数据 只有区域管理员才有数据") - public DeclaredStatistics regionDeclared; @ApiModelProperty("项目动态") public List projects; @@ -40,41 +30,11 @@ public class WorkbenchVO { @ApiModelProperty("公告列表") public Map> noticeList; - @ApiModelProperty("预警记录") - public List earlyWarning; + private TodoCenterStatisticsVO todoCerter; @ApiModelProperty("项目预警记录") - public ProjectEarlyWarning projectEarlyWarning; - - @Data - public static class ProjectEarlyWarning { - @ApiModelProperty("统计数据-累积") - private WarningStatistics accumulate; - - @ApiModelProperty("统计数据-当前") - private WarningStatistics current; - - @ApiModelProperty("超期项目预警") - private PageVo overs; - - @ApiModelProperty("临期项目预警") - private PageVo advents; + public WorkbenchProjectEarlyWarnVO workbenchProjectEarlyWarnVO; - @ApiModelProperty("正常项目") - private PageVo normals; - } - - @Data - public static class WarningStatistics { - @ApiModelProperty("正常") - private Integer normal = 0; - - @ApiModelProperty("临期") - private Integer advent = 0; - - @ApiModelProperty("超期") - private Integer over = 0; - } @Data public static class EarlyWarning {