From ce7e00e3e4a64581c016605c69aacdfab1b7ac10 Mon Sep 17 00:00:00 2001 From: PoffyZhang <99775271@qq.com> Date: Sun, 12 Feb 2023 11:04:49 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A2=84=E5=AE=A1=E9=A1=B9=E7=9B=AE=20?= =?UTF-8?q?=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PrequalificationDeclaredController.java | 19 ++-- .../entity/dto/PreDeclaredProjectDto.java | 43 ++++++++ .../manage/DeclaredProjectManage.java | 3 +- .../PrequalificationDeclaredProjectManage.java | 118 +++++++++++++++++++++ 4 files changed, 175 insertions(+), 8 deletions(-) create mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/projectdeclared/entity/dto/PreDeclaredProjectDto.java create mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/projectdeclared/manage/PrequalificationDeclaredProjectManage.java diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/projectdeclared/controller/PrequalificationDeclaredController.java b/pmapi/src/main/java/com/ningdatech/pmapi/projectdeclared/controller/PrequalificationDeclaredController.java index d47b415..8d6d249 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/projectdeclared/controller/PrequalificationDeclaredController.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/projectdeclared/controller/PrequalificationDeclaredController.java @@ -1,9 +1,8 @@ package com.ningdatech.pmapi.projectdeclared.controller; import com.ningdatech.basic.model.PageVo; -import com.ningdatech.pmapi.projectdeclared.entity.dto.DeclaredProjectListParamDto; -import com.ningdatech.pmapi.projectdeclared.entity.vo.ProjectDeclaredListItemVO; -import com.ningdatech.pmapi.projectdeclared.manage.DeclaredProjectManage; +import com.ningdatech.pmapi.projectdeclared.entity.dto.PreDeclaredProjectDto; +import com.ningdatech.pmapi.projectdeclared.manage.PrequalificationDeclaredProjectManage; import com.ningdatech.pmapi.projectlib.enumeration.ProjectStatusEnum; import com.ningdatech.pmapi.projectlib.manage.ProjectLibManage; import com.ningdatech.pmapi.projectlib.model.req.ProjectListReq; @@ -13,10 +12,7 @@ import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.ModelAttribute; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; /** * @Classname PrequalificationDeclaredController @@ -34,6 +30,8 @@ public class PrequalificationDeclaredController { private final ProjectLibManage projectLibManage; + private final PrequalificationDeclaredProjectManage prequalificationDeclaredProjectManage; + @ApiOperation(value = "可预审申报项目列表", notes = "可预审申报项目列表") @GetMapping("/list") public PageVo list(@Validated @ModelAttribute ProjectListReq req) { @@ -42,4 +40,11 @@ public class PrequalificationDeclaredController { req.setStatus(ProjectStatusEnum.PENDING_PREQUALIFICATION.getCode()); return projectLibManage.projectLibList(req); } + + @ApiOperation(value = "申报预审", notes = "申报预审") + @PostMapping("/start") + public String startTheProcess(@Validated @RequestBody PreDeclaredProjectDto dto) { + String instanceId = prequalificationDeclaredProjectManage.startTheProcess(dto); + return "提交预审 " + instanceId + " 成功"; + } } diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/projectdeclared/entity/dto/PreDeclaredProjectDto.java b/pmapi/src/main/java/com/ningdatech/pmapi/projectdeclared/entity/dto/PreDeclaredProjectDto.java new file mode 100644 index 0000000..fae8f58 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/projectdeclared/entity/dto/PreDeclaredProjectDto.java @@ -0,0 +1,43 @@ +package com.ningdatech.pmapi.projectdeclared.entity.dto; + +import cn.hutool.core.collection.CollUtil; +import com.google.common.collect.Maps; +import com.ningdatech.pmapi.projectlib.model.dto.ProjectDto; +import com.wflow.workflow.bean.dto.ProcessInstanceUserDto; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import javax.validation.constraints.NotNull; +import java.io.Serializable; +import java.util.Map; + +/** + * @Classname DeclaredProjectDto + * @Description 申报项目 + * @Date 2023/2/1 14:52 + * @Author PoffyZhang + */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class PreDeclaredProjectDto implements Serializable { + + @NotNull + private Long projectId; + + private Map formData; + + @NotNull + private ProcessInstanceUserDto user; + + public Map getFormData(){ + if(CollUtil.isEmpty(this.formData)){ + this.formData = Maps.newHashMap(); + return this.formData; + } + return this.formData; + } +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/projectdeclared/manage/DeclaredProjectManage.java b/pmapi/src/main/java/com/ningdatech/pmapi/projectdeclared/manage/DeclaredProjectManage.java index 7c87cbe..810e69d 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/projectdeclared/manage/DeclaredProjectManage.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/projectdeclared/manage/DeclaredProjectManage.java @@ -142,7 +142,8 @@ public class DeclaredProjectManage { .last("limit 1")); if (Objects.isNull(model)) { - throw new BusinessException(String.format("此 【%s】区域找不到流程配置", regionCode)); + log.error("此 【{}】区域找不到单位流程配置", regionCode); + throw new BusinessException(String.format("此 【%s】区域找不到单位流程配置", regionCode)); } ProcessStartParamsVo params = new ProcessStartParamsVo(); diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/projectdeclared/manage/PrequalificationDeclaredProjectManage.java b/pmapi/src/main/java/com/ningdatech/pmapi/projectdeclared/manage/PrequalificationDeclaredProjectManage.java new file mode 100644 index 0000000..1e04fba --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/projectdeclared/manage/PrequalificationDeclaredProjectManage.java @@ -0,0 +1,118 @@ +package com.ningdatech.pmapi.projectdeclared.manage; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.TypeReference; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.ningdatech.basic.function.VUtils; +import com.ningdatech.pmapi.common.enums.ProjectProessStageEnum; +import com.ningdatech.pmapi.common.statemachine.util.StateMachineUtils; +import com.ningdatech.pmapi.projectdeclared.entity.dto.PreDeclaredProjectDto; +import com.ningdatech.pmapi.projectdeclared.entity.dto.ProjectConditionDto; +import com.ningdatech.pmapi.projectlib.enumeration.ProjectStatusEnum; +import com.ningdatech.pmapi.projectlib.model.entity.Project; +import com.ningdatech.pmapi.projectlib.service.IProjectService; +import com.wflow.bean.entity.WflowModels; +import com.wflow.exception.BusinessException; +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.springframework.beans.BeanUtils; +import org.springframework.stereotype.Component; + +import java.time.LocalDateTime; +import java.util.Collections; +import java.util.Map; +import java.util.Objects; + +/** + * @Classname ProqualificationDeclaredProjectManage + * @Description + * @Date 2023/2/13 14:48 + * @Author PoffyZhang + */ +@Component +@Slf4j +@RequiredArgsConstructor +public class PrequalificationDeclaredProjectManage { + + private final IProjectService projectService; + + private final StateMachineUtils stateMachineUtils; + + private final ProcessInstanceService processService; + + private final ProcessModelService processModelService; + + /** + * 提交预审 + * + * @param dto + * @return + */ + public String startTheProcess(PreDeclaredProjectDto dto) { + Project projectInfo = projectService.getById(dto.getProjectId()); + + VUtils.isTrue(Objects.isNull(projectInfo)).throwMessage("提交失败 此项目不存在!"); + + String regionCode = projectInfo.getAreaCode(); + + WflowModels model = processModelService.getOne(Wrappers.lambdaQuery(WflowModels.class) + .eq(WflowModels::getRegionCode, regionCode) + .eq(WflowModels::getFormName, ProjectProessStageEnum.PROJECT_PREQUALIFICATION_APPROVAL_PROCESS.getDesc()) + .last("limit 1")); + + if (Objects.isNull(model)) { + log.error("此 【{}】区域找不到 预审流程配置", regionCode); + throw new BusinessException(String.format("此 【%s】区域找不到 预审流程配置", regionCode)); + } + + //首先要判断 项目当前状态 是不是 待预审 + VUtils.isTrue(!ProjectStatusEnum.PENDING_PREQUALIFICATION.getCode().equals(projectInfo.getStatus()) || + !ProjectStatusEnum.NOT_APPROVED.getCode().equals(projectInfo.getStage())) + .throwMessage("提交失败 该项目不是 待预审状态或者未立项阶段"); + //TODO 再判断 该项目是否 真实走完 单位内部审批 + + ProcessStartParamsVo params = new ProcessStartParamsVo(); + params.setUser(dto.getUser()); + params.setProcessUsers(Collections.emptyMap()); + //放入条件判断的项目字段 + ProjectConditionDto conditionDto = new ProjectConditionDto(); + BeanUtils.copyProperties(projectInfo, conditionDto); + if (Objects.nonNull(conditionDto)) { + dto.getFormData().putAll( + JSON.parseObject(JSON.toJSONString(conditionDto), new TypeReference>() { + }) + ); + } + params.setFormData(dto.getFormData()); + String instanceId = processService.startProcess(model.getProcessDefId(), params); + log.info("提交预审项目成功 【{}】", instanceId); + + //保存预审项目 + modifyProject(projectInfo, instanceId); + + return instanceId; + } + + /** + * 提交预审项目 时 更新信息 + * + * @param project + * @param instanceId + */ + private void modifyProject(Project project, String instanceId) { + //流程启动之后 入库项目 重要业务信息 用于列表查询 展示 + try { + project.setUpdateOn(LocalDateTime.now()); + project.setInstCode(instanceId); + //调用状态机 进入下一个通过状态 + stateMachineUtils.execute(project,stateMachineUtils.getProjectStatusPassEvent(project.getStatus())); + projectService.updateById(project); + } catch (Exception e) { + log.error("提交预审 项目信息修改 错误 ", e); + throw new BusinessException("提交预审 项目信息修改 错误 :" + e.getMessage()); + } + } +}