diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/common/enumeration/ProjectProcessStageEnum.java b/pmapi/src/main/java/com/ningdatech/pmapi/common/enumeration/ProjectProcessStageEnum.java index bcc0cce..5b8986b 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/common/enumeration/ProjectProcessStageEnum.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/common/enumeration/ProjectProcessStageEnum.java @@ -18,7 +18,9 @@ public enum ProjectProcessStageEnum { PROJECT_PREQUALIFICATION_APPROVAL_PROCESS(2,"项目预审审批流程"), DEPARTMENT_JOINT_APPROVAL_PROCESS(3,"部门联合审批流程"), CONSTRUCTION_PROJECT_APPROVAL_PROCESS(4,"建设方案审批流程"), - ACCEPTANCE_DECLARATION_APPROVAL_PROCESS(5,"验收申报审批流程"); + ACCEPTANCE_DECLARATION_APPROVAL_PROCESS(5,"验收申报审批流程"), + APPLY_DELAY(6,"申请延期审批流程"), + APPLY_BORROW(7,"申请借阅审批流程"); private Integer code; private String desc; diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/projectdeclared/controller/DelayedApplyController.java b/pmapi/src/main/java/com/ningdatech/pmapi/projectdeclared/controller/DelayedApplyController.java index d36a1d4..8649ea2 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/projectdeclared/controller/DelayedApplyController.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/projectdeclared/controller/DelayedApplyController.java @@ -45,6 +45,8 @@ public class DelayedApplyController { @ApiOperation(value = "延期申报", notes = "延期申报") @PostMapping("/apply") public String delayedApply(@Validated @RequestBody DelayedApplyDTO dto) { - return delayedApplyManage.delayedApply(dto); + String instanceId = delayedApplyManage.startDelayedApplyProcess(dto); + return "启动流程实例 【" + instanceId + "】 成功"; + //return delayedApplyManage.delayedApply(dto); } } diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/projectdeclared/manage/DelayedApplyManage.java b/pmapi/src/main/java/com/ningdatech/pmapi/projectdeclared/manage/DelayedApplyManage.java index 61bb7c7..8fa4c62 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/projectdeclared/manage/DelayedApplyManage.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/projectdeclared/manage/DelayedApplyManage.java @@ -2,7 +2,10 @@ package com.ningdatech.pmapi.projectdeclared.manage; import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.date.DatePattern; import com.alibaba.excel.EasyExcel; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.TypeReference; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; @@ -12,33 +15,53 @@ import com.ningdatech.basic.model.PageVo; import com.ningdatech.basic.util.CollUtils; import com.ningdatech.basic.util.NdDateUtils; import com.ningdatech.pmapi.common.constant.BizConst; +import com.ningdatech.pmapi.common.enumeration.ProjectProcessStageEnum; import com.ningdatech.pmapi.common.helper.UserInfoHelper; import com.ningdatech.pmapi.common.statemachine.util.StateMachineUtils; import com.ningdatech.pmapi.common.util.ExcelDownUtil; import com.ningdatech.pmapi.common.util.ExcelExportStyle; import com.ningdatech.pmapi.projectdeclared.model.dto.DeclaredProjectExportDTO; import com.ningdatech.pmapi.projectdeclared.model.dto.DelayedApplyDTO; +import com.ningdatech.pmapi.projectdeclared.model.dto.ProjectConditionDTO; import com.ningdatech.pmapi.projectdeclared.model.entity.Contract; import com.ningdatech.pmapi.projectdeclared.model.entity.PaymentPlan; import com.ningdatech.pmapi.projectdeclared.model.entity.Purchase; +import com.ningdatech.pmapi.projectlib.enumeration.InstTypeEnum; import com.ningdatech.pmapi.projectlib.enumeration.ProjectStatusEnum; import com.ningdatech.pmapi.projectlib.enumeration.ProjectTypeEnum; import com.ningdatech.pmapi.projectlib.helper.ProjectHelper; +import com.ningdatech.pmapi.projectlib.manage.ProjectLibManage; +import com.ningdatech.pmapi.projectlib.model.dto.ProjectDTO; import com.ningdatech.pmapi.projectlib.model.entity.Project; +import com.ningdatech.pmapi.projectlib.model.entity.ProjectInst; import com.ningdatech.pmapi.projectlib.model.req.ProjectListReq; import com.ningdatech.pmapi.projectlib.model.vo.ProjectLibListItemVO; +import com.ningdatech.pmapi.projectlib.service.IProjectInstService; import com.ningdatech.pmapi.projectlib.service.IProjectService; +import com.ningdatech.pmapi.staging.enums.MsgTypeEnum; +import com.ningdatech.pmapi.sys.manage.NoticeManage; +import com.ningdatech.pmapi.todocenter.constant.WorkNoticeContant; import com.ningdatech.pmapi.user.security.auth.model.UserFullInfoDTO; import com.ningdatech.pmapi.user.util.LoginUserUtil; +import com.wflow.bean.entity.WflowModels; +import com.wflow.exception.BusinessException; +import com.wflow.workflow.bean.dto.OrgInfoDTO; +import com.wflow.workflow.bean.vo.ProcessStartParamsVo; +import com.wflow.workflow.service.ProcessInstanceService; +import com.wflow.workflow.service.ProcessModelService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Component; +import org.springframework.transaction.annotation.Transactional; + import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.time.LocalDateTime; +import java.util.Collections; import java.util.List; +import java.util.Map; import java.util.Objects; import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Collectors; @@ -58,6 +81,12 @@ public class DelayedApplyManage { private final UserInfoHelper userInfoHelper; private final StateMachineUtils stateMachineUtils; + private final ProcessModelService processModelService; + private final DefaultDeclaredProjectManage defaultDeclaredProjectManage; + private final ProcessInstanceService processInstanceService; + private final ProjectLibManage projectLibManage; + private final NoticeManage noticeManage; + private final IProjectInstService projectInstService; /** * 延期的-项目列表 @@ -178,4 +207,62 @@ public class DelayedApplyManage { return "申请发起成功"; } + + /** + * 开启延期申请审批流程 + * @param dto + * @return + */ + @Transactional(rollbackFor = Exception.class) + public String startDelayedApplyProcess(DelayedApplyDTO dto) { + UserFullInfoDTO user = userInfoHelper.getUserFullInfo(LoginUserUtil.getUserId()); + String employeeCode = user.getEmployeeCode(); + VUtils.isTrue(StringUtils.isBlank(employeeCode)).throwMessage("获取登录用户 员工号 失败!"); + + Long projectId = dto.getProjectId(); + Project project = projectService.getNewProject(projectId); + VUtils.isTrue(Objects.isNull(project)).throwMessage("提交失败 此项目不存在!"); + + //首先要判断 项目当前状态 是不是 以终验 + VUtils.isTrue(!ProjectStatusEnum.TO_BE_FINALLY_INSPECTED.getCode().equals(project.getStatus()) || + !ProjectStatusEnum.PROJECT_APPROVED.getCode().equals(project.getStage())) + .throwMessage("提交失败 该项目不是 已立项|待终验"); + + VUtils.isTrue(Objects.isNull(project.getPlanAcceptanceTime()) + || project.getPlanAcceptanceTime().compareTo(LocalDateTime.now()) <= 0) + .throwMessage("当前项目还未过期验收"); + + String regionCode = user.getRegionCode(); + + WflowModels model = processModelService.getOne(Wrappers.lambdaQuery(WflowModels.class) + .eq(WflowModels::getRegionCode, regionCode) + .eq(WflowModels::getProcessType, ProjectProcessStageEnum.APPLY_DELAY.getCode()) + .last(BizConst.LIMIT_1)); + + if (Objects.isNull(model)) { + log.error("此 【{}】区域找不到延期申请流程配置", regionCode); + throw new BusinessException(String.format("此 【%s】区域找不到延期申请流程配置", regionCode)); + } + + ProcessStartParamsVo params = new ProcessStartParamsVo(); + params.setUser(defaultDeclaredProjectManage.buildUser(employeeCode)); + params.setProcessUsers(Collections.emptyMap()); + //放入条件判断的项目字段 + //把条件值给放入工作流 + defaultDeclaredProjectManage.buildCondition(params, project); + // 获取发起单位、发起单位主管单位、发起单位上级条线主管单位信息 + Map orgModelMap = defaultDeclaredProjectManage.buildOrgModelMap(employeeCode, project); + String instanceId = processInstanceService.newStartProcess(model.getProcessDefId(), model.getFormId(), params, orgModelMap); + log.info("终验方案项目申报成功 【{}】", instanceId); + + // 保存项目相关 + projectLibManage.saveProjectByApplyDelay(dto, project, instanceId); + + + //发送给第一个审批人消息 + noticeManage.sendFirtUser(project,model.getFormName(),instanceId, + WorkNoticeContant.PASS_MSG_TEMPLATE, MsgTypeEnum.PROJECT_REVIEW); + + return instanceId; + } } diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/projectlib/enumeration/InstTypeEnum.java b/pmapi/src/main/java/com/ningdatech/pmapi/projectlib/enumeration/InstTypeEnum.java index 2fdc39a..78b7f82 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/projectlib/enumeration/InstTypeEnum.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/projectlib/enumeration/InstTypeEnum.java @@ -24,7 +24,11 @@ public enum InstTypeEnum { PRELIMINARY_PREVIEW(2, "项目预审审批流程"), DEPT_UNITED_REVIEW(3,"部门联合审批流程"), CONSTRUCTION_PLAN_REVIEW(4,"建设方案审批流程"), - PROJECT_FINAL_INSPECTION(5,"验收申报审批流程"); + PROJECT_FINAL_INSPECTION(5,"验收申报审批流程"), + + APPLY_DELAY(6,"申请延期审批流程"), + + APPLY_BORROW(7,"申请借阅审批流程"); private Integer code; private String desc; diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/projectlib/manage/ProjectLibManage.java b/pmapi/src/main/java/com/ningdatech/pmapi/projectlib/manage/ProjectLibManage.java index 615dbf8..8f39f65 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/projectlib/manage/ProjectLibManage.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/projectlib/manage/ProjectLibManage.java @@ -3,6 +3,7 @@ package com.ningdatech.pmapi.projectlib.manage; import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.copier.CopyOptions; import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.date.DatePattern; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; @@ -10,6 +11,7 @@ import com.google.common.collect.Lists; import com.ningdatech.basic.function.VUtils; import com.ningdatech.basic.model.PageVo; import com.ningdatech.basic.util.CollUtils; +import com.ningdatech.basic.util.NdDateUtils; import com.ningdatech.file.entity.File; import com.ningdatech.file.service.FileService; import com.ningdatech.pmapi.common.constant.CommonConst; @@ -24,7 +26,9 @@ import com.ningdatech.pmapi.common.util.BizUtils; import com.ningdatech.pmapi.common.util.ExcelDownUtil; import com.ningdatech.pmapi.datascope.model.DataScopeDTO; import com.ningdatech.pmapi.datascope.utils.DataScopeUtil; +import com.ningdatech.pmapi.projectdeclared.model.dto.DelayedApplyDTO; import com.ningdatech.pmapi.projectdeclared.utils.GenerateProjectCodeUtil; +import com.ningdatech.pmapi.projectlib.enumeration.InstTypeEnum; import com.ningdatech.pmapi.projectlib.enumeration.ProjectStatusEnum; import com.ningdatech.pmapi.projectlib.handle.ProcessExecuteChainHandle; import com.ningdatech.pmapi.projectlib.helper.ProjectHelper; @@ -611,4 +615,29 @@ public class ProjectLibManage { } return user; } + + public void saveProjectByApplyDelay(DelayedApplyDTO dto, Project project, String instanceId) { + // 获取项目的立项批复时间和建设周期 + LocalDateTime approvalDate = project.getApprovalDate(); + String buildCycle = project.getBuildCycle(); + // 重新计算建设周期、验收时间 + String constructCycle = buildCycle + dto.getDelayedMonth(); + project.setBuildCycle(constructCycle); + Long delayedMonth = Long.valueOf(dto.getDelayedMonth()); + String acceptTime = NdDateUtils.format(approvalDate.plusMonths(delayedMonth), DatePattern.NORM_DATETIME_MINUTE_PATTERN); + project.setBuildCycle(acceptTime); + project.setInstCode(instanceId); + project.setApplyDelayFile(dto.getSupportingMaterials()); + project.setApplyDelayReason(dto.getDelayedReason()); + projectService.updateById(project); + + //保存项目和实例的关系 + ProjectInst projectInst = new ProjectInst(); + projectInst.setProjectId(project.getId()); + projectInst.setInstCode(instanceId); + projectInst.setInstType(InstTypeEnum.APPLY_DELAY.getCode()); + projectInst.setCreatOn(LocalDateTime.now()); + projectInst.setUpdateOn(LocalDateTime.now()); + projectInstService.save(projectInst); + } } diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/projectlib/model/entity/Project.java b/pmapi/src/main/java/com/ningdatech/pmapi/projectlib/model/entity/Project.java index 0d7bff5..596003e 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/projectlib/model/entity/Project.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/projectlib/model/entity/Project.java @@ -351,4 +351,10 @@ public class Project implements Serializable { @ApiModelProperty("计划验收时间") private LocalDateTime planAcceptanceTime; + + @ApiModelProperty("申请延期佐证材料") + private String applyDelayFile; + + @ApiModelProperty("申请延期理由") + private String applyDelayReason; } diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/scheduler/contants/TaskContant.java b/pmapi/src/main/java/com/ningdatech/pmapi/scheduler/contants/TaskContant.java index e303c10..6847ef7 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/scheduler/contants/TaskContant.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/scheduler/contants/TaskContant.java @@ -22,10 +22,19 @@ public interface TaskContant { public static final String[] DEFAULT_PROCESS_LIST = {"单位内部审批流程","项目预审审批流程","部门联合审批流程","建设方案审批流程","验收申报审批流程"}; - public static final Integer[] DEFAULT_PROCESS_TYPE_LIST = {ProjectProcessStageEnum.ORG_INTERNAL_APPROVAL_PROCESS.getCode(), + public static final Integer[] DEFAULT_PROCESS_TYPE_LIST = { + ProjectProcessStageEnum.ORG_INTERNAL_APPROVAL_PROCESS.getCode(), ProjectProcessStageEnum.PROJECT_PREQUALIFICATION_APPROVAL_PROCESS.getCode(), ProjectProcessStageEnum.DEPARTMENT_JOINT_APPROVAL_PROCESS.getCode(), ProjectProcessStageEnum.CONSTRUCTION_PROJECT_APPROVAL_PROCESS.getCode(), - ProjectProcessStageEnum.ACCEPTANCE_DECLARATION_APPROVAL_PROCESS.getCode()}; + ProjectProcessStageEnum.ACCEPTANCE_DECLARATION_APPROVAL_PROCESS.getCode(), + ProjectProcessStageEnum.APPLY_DELAY.getCode(), + ProjectProcessStageEnum.APPLY_BORROW.getCode() + }; + + public static final Integer[] APPLY_PROCESS_TYPE_LIST = { + ProjectProcessStageEnum.APPLY_DELAY.getCode(), + ProjectProcessStageEnum.APPLY_BORROW.getCode() + }; } } diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/scheduler/task/InitProcessTask.java b/pmapi/src/main/java/com/ningdatech/pmapi/scheduler/task/InitProcessTask.java index 51fe9fd..e4538df 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/scheduler/task/InitProcessTask.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/scheduler/task/InitProcessTask.java @@ -52,9 +52,9 @@ public class InitProcessTask { @Value("${hostname}") private String HOST_NAME; - @Scheduled(cron = "0 14 16 07 3 ?") + @Scheduled(cron = "0 40 17 12 6 ?") public void doTask() throws UnknownHostException { - if (HOST_NAME.equals(InetAddress.getLocalHost().getHostName())) { + //if (HOST_NAME.equals(InetAddress.getLocalHost().getHostName())) { log.info("=========== 初始化丽水二期 系统表单和流程配置 ======== 任务开始"); StopWatch stopWatch = new StopWatch(); stopWatch.start(); @@ -70,14 +70,14 @@ public class InitProcessTask { for(RegionDTO region : regions){ log.info("当前初始化的是 【{}】 表单信息",region.getRegionName()); - WflowForms existsForm = formsService.getOne(Wrappers.lambdaQuery(WflowForms.class) - .eq(WflowForms::getRegionCode, region.getRegionCode()) - .last("limit 1")); - if(Objects.nonNull(existsForm)){ - log.info("当前区域 【{}】 已经有表单数据 不需要初始化",region.getRegionName()); - formsMap.put(existsForm.getRegionCode(),existsForm); - continue; - } + //WflowForms existsForm = formsService.getOne(Wrappers.lambdaQuery(WflowForms.class) + // .eq(WflowForms::getRegionCode, region.getRegionCode()) + // .last("limit 1")); + //if(Objects.nonNull(existsForm)){ + // log.info("当前区域 【{}】 已经有表单数据 不需要初始化",region.getRegionName()); + // formsMap.put(existsForm.getRegionCode(),existsForm); + // continue; + //} WflowForms wflowForms = new WflowForms(); wflowForms.setFormId("fm" + IdUtil.objectId()); @@ -98,11 +98,11 @@ public class InitProcessTask { for(RegionDTO region : regions){ log.info("当前初始化的是 【{}】 流程配置",region.getRegionName()); - if(processModelService.count(Wrappers.lambdaQuery(WflowModels.class) - .eq(WflowModels::getRegionCode,region.getRegionCode())) > 0){ - log.info("当前区域 【{}】 已经有流程数据 不需要初始化",region.getRegionName()); - continue; - } + //if(processModelService.count(Wrappers.lambdaQuery(WflowModels.class) + // .eq(WflowModels::getRegionCode,region.getRegionCode())) > 0){ + // log.info("当前区域 【{}】 已经有流程数据 不需要初始化",region.getRegionName()); + // continue; + //} // WflowForms form = formsMap.get(region.getRegionCode()); // if(Objects.isNull(form)){ @@ -110,7 +110,9 @@ public class InitProcessTask { // continue; // } - Integer[] processTypeList = TaskContant.Wflow.DEFAULT_PROCESS_TYPE_LIST; + //Integer[] processTypeList = TaskContant.Wflow.DEFAULT_PROCESS_TYPE_LIST; + + Integer[] processTypeList = TaskContant.Wflow.APPLY_PROCESS_TYPE_LIST; for(Integer processType : processTypeList){ String formName = ProjectProcessStageEnum.getDesc(processType); WflowModelHistorysInsertDto models = new WflowModelHistorysInsertDto(); @@ -143,6 +145,6 @@ public class InitProcessTask { stopWatch.stop(); log.info("=========== 初始化丽水二期 系统表单和流程配置 ======== 任务结束 {}s",stopWatch.getTotalTimeSeconds()); - } + //} } }