diff --git a/pqs-bpm/bpm-api/pom.xml b/pqs-bpm/bpm-api/pom.xml index 25dbb81b4..d21ee4c76 100644 --- a/pqs-bpm/bpm-api/pom.xml +++ b/pqs-bpm/bpm-api/pom.xml @@ -16,7 +16,6 @@ 8 8 UTF-8 - 6.8.0 1.5.5.Final 2.2.11 @@ -39,17 +38,7 @@ ${project.version} - - - org.flowable - flowable-spring-boot-starter-process - ${flowable.version} - - - org.flowable - flowable-spring-boot-starter-actuator - ${flowable.version} - + org.mapstruct diff --git a/pqs-bpm/bpm-api/src/main/java/com/njcn/bpm/api/BpmProcessFeignClient.java b/pqs-bpm/bpm-api/src/main/java/com/njcn/bpm/api/BpmProcessFeignClient.java new file mode 100644 index 000000000..8304d2e40 --- /dev/null +++ b/pqs-bpm/bpm-api/src/main/java/com/njcn/bpm/api/BpmProcessFeignClient.java @@ -0,0 +1,30 @@ +package com.njcn.bpm.api; + +import com.njcn.bpm.api.fallback.BpmProcessFeignClientFallbackFactory; +import com.njcn.bpm.pojo.dto.BpmProcessInstanceCreateReqDTO; +import com.njcn.common.pojo.constant.ServerInfo; +import com.njcn.common.pojo.response.HttpResult; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestParam; + + +/** + * 流程实例 Api 接口 + * + * @author 芋道源码 + */ +@FeignClient(value = ServerInfo.SUPERVISION,path = "/process",fallbackFactory = BpmProcessFeignClientFallbackFactory.class) +public interface BpmProcessFeignClient { + + /** + * + * @param userId 用户编号 + * @param reqDTO 创建信息 + * @return 实例的编号 + */ + @PostMapping("/createProcessInstance") + HttpResult createProcessInstance(@RequestParam("userId") String userId, @RequestBody BpmProcessInstanceCreateReqDTO reqDTO); + +} diff --git a/pqs-bpm/bpm-api/src/main/java/com/njcn/bpm/api/fallback/BpmProcessFeignClientFallbackFactory.java b/pqs-bpm/bpm-api/src/main/java/com/njcn/bpm/api/fallback/BpmProcessFeignClientFallbackFactory.java new file mode 100644 index 000000000..d5234899f --- /dev/null +++ b/pqs-bpm/bpm-api/src/main/java/com/njcn/bpm/api/fallback/BpmProcessFeignClientFallbackFactory.java @@ -0,0 +1,39 @@ +package com.njcn.bpm.api.fallback; + +import com.njcn.bpm.api.BpmProcessFeignClient; +import com.njcn.bpm.pojo.dto.BpmProcessInstanceCreateReqDTO; +import com.njcn.bpm.utils.BpmEnumUtil; +import com.njcn.common.pojo.enums.response.CommonResponseEnum; +import com.njcn.common.pojo.exception.BusinessException; +import com.njcn.common.pojo.response.HttpResult; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; +import feign.hystrix.FallbackFactory; + +/** + * @author denghuajun + * @version 1.0.0 + * @date 2022/3/16 + */ +@Slf4j +@Component +public class BpmProcessFeignClientFallbackFactory implements FallbackFactory { + @Override + public BpmProcessFeignClient create(Throwable throwable) { + //判断抛出异常是否为解码器抛出的业务异常 + Enum exceptionEnum = CommonResponseEnum.SERVICE_FALLBACK; + if (throwable.getCause() instanceof BusinessException) { + BusinessException businessException = (BusinessException) throwable.getCause(); + exceptionEnum = BpmEnumUtil.getExceptionEnum(businessException.getResult()); + } + Enum finalExceptionEnum = exceptionEnum; + return new BpmProcessFeignClient() { + @Override + public HttpResult createProcessInstance(String userId, BpmProcessInstanceCreateReqDTO reqDTO) { + log.error("{}异常,降级处理,异常为:{}", "创建流程实例", throwable.toString()); + throw new BusinessException(finalExceptionEnum); + } + + }; + } +} diff --git a/pqs-bpm/bpm-api/src/main/java/com/njcn/bpm/enums/BpmProcessInstanceStatusEnum.java b/pqs-bpm/bpm-api/src/main/java/com/njcn/bpm/enums/BpmProcessInstanceStatusEnum.java new file mode 100644 index 000000000..7df2dd49b --- /dev/null +++ b/pqs-bpm/bpm-api/src/main/java/com/njcn/bpm/enums/BpmProcessInstanceStatusEnum.java @@ -0,0 +1,38 @@ +package com.njcn.bpm.enums; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +import java.util.Arrays; + +/** + * 流程实例 ProcessInstance 的状态 + * + * @author 芋道源码 + */ +@Getter +@AllArgsConstructor +public enum BpmProcessInstanceStatusEnum implements IntArrayValuable { + + RUNNING(1, "审批中"), + APPROVE(2, "审批通过"), + REJECT(3, "审批不通过"), + CANCEL(4, "已取消"); + + public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(BpmProcessInstanceStatusEnum::getStatus).toArray(); + + /** + * 状态 + */ + private final Integer status; + /** + * 描述 + */ + private final String desc; + + @Override + public int[] array() { + return new int[0]; + } + +} diff --git a/pqs-bpm/bpm-api/src/main/java/com/njcn/bpm/enums/BpmResponseEnum.java b/pqs-bpm/bpm-api/src/main/java/com/njcn/bpm/enums/BpmResponseEnum.java index 3c77a433b..73b287423 100644 --- a/pqs-bpm/bpm-api/src/main/java/com/njcn/bpm/enums/BpmResponseEnum.java +++ b/pqs-bpm/bpm-api/src/main/java/com/njcn/bpm/enums/BpmResponseEnum.java @@ -25,6 +25,10 @@ public enum BpmResponseEnum { PROCESS_DEFINITION_NOT_EXISTS("A00568","流程定义不存在"), + + + PROCESS_DEFINITION_IS_SUSPENDED("A00568", "流程定义处于挂起状态"), + FORM_NOT_EXISTS("A00568","动态表单不存在"), MODEL_DEPLOY_FAIL_FORM_NOT_CONFIG("A00568","部署流程失败,原因:流程表单未配置,请点击【修改流程】按钮进行配置"), diff --git a/pqs-bpm/bpm-api/src/main/java/com/njcn/bpm/pojo/dto/BpmProcessInstanceCreateReqDTO.java b/pqs-bpm/bpm-api/src/main/java/com/njcn/bpm/pojo/dto/BpmProcessInstanceCreateReqDTO.java new file mode 100644 index 000000000..2342f1670 --- /dev/null +++ b/pqs-bpm/bpm-api/src/main/java/com/njcn/bpm/pojo/dto/BpmProcessInstanceCreateReqDTO.java @@ -0,0 +1,44 @@ +package com.njcn.bpm.pojo.dto; + +import lombok.Builder; +import lombok.Data; + +import javax.validation.constraints.NotEmpty; +import java.util.List; +import java.util.Map; + +/** + * 流程实例的创建 Request DTO + */ +@Data +public class BpmProcessInstanceCreateReqDTO { + + /** + * 流程定义的标识 + */ + @NotEmpty(message = "流程定义的标识不能为空") + private String processDefinitionKey; + + /** + * 变量实例(动态表单) + */ + private Map variables; + + /** + * 业务的唯一标识 + * + * 例如说,请假申请的编号。通过它,可以查询到对应的实例 + */ + @NotEmpty(message = "业务的唯一标识") + private String businessKey; + + /** + * 发起人自选审批人 Map + * + * key:taskKey 任务编码 + * value:审批人的数组 + * 例如:{ taskKey1 :[1, 2] },则表示 taskKey1 这个任务,提前设定了,由 userId 为 1,2 的用户进行审批 + */ + private Map> startUserSelectAssignees; + +} diff --git a/pqs-bpm/bpm-api/src/main/java/com/njcn/bpm/pojo/param/BpmModelParam.java b/pqs-bpm/bpm-api/src/main/java/com/njcn/bpm/pojo/param/BpmModelParam.java index fbed09f9a..5ba5ea04d 100644 --- a/pqs-bpm/bpm-api/src/main/java/com/njcn/bpm/pojo/param/BpmModelParam.java +++ b/pqs-bpm/bpm-api/src/main/java/com/njcn/bpm/pojo/param/BpmModelParam.java @@ -44,9 +44,10 @@ public class BpmModelParam implements Serializable { private Integer formType = 10; - + @ApiModelProperty("表单提交路由") private String formCustomCreatePath; + @ApiModelProperty("表单查看路由") private String formCustomViewPath; /** diff --git a/pqs-bpm/bpm-api/src/main/java/com/njcn/bpm/utils/ProcessEnumUtil.java b/pqs-bpm/bpm-api/src/main/java/com/njcn/bpm/utils/BpmEnumUtil.java similarity index 98% rename from pqs-bpm/bpm-api/src/main/java/com/njcn/bpm/utils/ProcessEnumUtil.java rename to pqs-bpm/bpm-api/src/main/java/com/njcn/bpm/utils/BpmEnumUtil.java index cd95b3334..1ee2da6f0 100644 --- a/pqs-bpm/bpm-api/src/main/java/com/njcn/bpm/utils/ProcessEnumUtil.java +++ b/pqs-bpm/bpm-api/src/main/java/com/njcn/bpm/utils/BpmEnumUtil.java @@ -15,7 +15,7 @@ import java.util.Objects; * @version 1.0.0 * @date 2021年12月20日 10:03 */ -public class ProcessEnumUtil { +public class BpmEnumUtil { /** * 获取HarmonicResponseEnum实例 diff --git a/pqs-bpm/bpm-boot/pom.xml b/pqs-bpm/bpm-boot/pom.xml index cb0c773f4..71258ea2f 100644 --- a/pqs-bpm/bpm-boot/pom.xml +++ b/pqs-bpm/bpm-boot/pom.xml @@ -15,6 +15,7 @@ 8 8 UTF-8 + 6.8.0 @@ -37,6 +38,18 @@ ${project.version} + + + org.flowable + flowable-spring-boot-starter-process + ${flowable.version} + + + org.flowable + flowable-spring-boot-starter-actuator + ${flowable.version} + + diff --git a/pqs-bpm/bpm-api/src/main/java/com/njcn/bpm/enums/BpmConstants.java b/pqs-bpm/bpm-boot/src/main/java/com/njcn/bpm/constant/BpmConstants.java similarity index 97% rename from pqs-bpm/bpm-api/src/main/java/com/njcn/bpm/enums/BpmConstants.java rename to pqs-bpm/bpm-boot/src/main/java/com/njcn/bpm/constant/BpmConstants.java index d420f102d..3cf107b9c 100644 --- a/pqs-bpm/bpm-api/src/main/java/com/njcn/bpm/enums/BpmConstants.java +++ b/pqs-bpm/bpm-boot/src/main/java/com/njcn/bpm/constant/BpmConstants.java @@ -1,4 +1,4 @@ -package com.njcn.bpm.enums; +package com.njcn.bpm.constant; import org.flowable.engine.runtime.ProcessInstance; diff --git a/pqs-bpm/bpm-boot/src/main/java/com/njcn/bpm/controller/BpmProcessDefinitionController.java b/pqs-bpm/bpm-boot/src/main/java/com/njcn/bpm/controller/BpmProcessDefinitionController.java index 33d47f025..992d04125 100644 --- a/pqs-bpm/bpm-boot/src/main/java/com/njcn/bpm/controller/BpmProcessDefinitionController.java +++ b/pqs-bpm/bpm-boot/src/main/java/com/njcn/bpm/controller/BpmProcessDefinitionController.java @@ -2,6 +2,7 @@ package com.njcn.bpm.controller; import cn.hutool.core.collection.CollUtil; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.njcn.bpm.pojo.dto.BpmProcessInstanceCreateReqDTO; import com.njcn.bpm.pojo.param.BpmProcessDefinitionInfoParam; import com.njcn.bpm.pojo.po.BpmCategory; import com.njcn.bpm.pojo.po.BpmForm; @@ -10,9 +11,11 @@ import com.njcn.bpm.pojo.vo.BpmProcessDefinitionInfoVO; import com.njcn.bpm.service.IBpmCategoryService; import com.njcn.bpm.service.IBpmFormService; import com.njcn.bpm.service.IBpmProcessDefinitionService; +import com.njcn.bpm.service.task.IBpmProcessInstanceService; import com.njcn.bpm.strategy.BpmTaskCandidateStartUserSelectStrategy; import com.njcn.bpm.utils.BpmProcessDefinitionConvert; import com.njcn.common.pojo.annotation.OperateInfo; +import com.njcn.common.pojo.constant.OperateType; import com.njcn.common.pojo.enums.common.LogEnum; import com.njcn.common.pojo.enums.response.CommonResponseEnum; import com.njcn.common.pojo.response.HttpResult; @@ -54,6 +57,8 @@ public class BpmProcessDefinitionController extends BaseController { private final IBpmCategoryService categoryService; + private final IBpmProcessInstanceService processInstanceService; + @OperateInfo(info = LogEnum.BUSINESS_COMMON) @PostMapping("/page") @ApiOperation("获得流程定义分页") @@ -120,4 +125,13 @@ public class BpmProcessDefinitionController extends BaseController { processDefinition, null, null, null, null, bpmnModel, userTaskList), methodDescribe); } + + @OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.ADD) + @ApiOperation("创建流程实例") + @PostMapping("/createProcessInstance") + HttpResult createProcessInstance(@RequestParam("userId") String userId, @RequestBody BpmProcessInstanceCreateReqDTO reqDTO){ + String methodDescribe = getMethodDescribe("createProcessInstance"); + String instanceId = processInstanceService.createProcessInstance(userId, reqDTO); + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, instanceId, methodDescribe); + } } diff --git a/pqs-bpm/bpm-boot/src/main/java/com/njcn/bpm/service/IBpmCategoryService.java b/pqs-bpm/bpm-boot/src/main/java/com/njcn/bpm/service/IBpmCategoryService.java index 4c5712331..206cc6a99 100644 --- a/pqs-bpm/bpm-boot/src/main/java/com/njcn/bpm/service/IBpmCategoryService.java +++ b/pqs-bpm/bpm-boot/src/main/java/com/njcn/bpm/service/IBpmCategoryService.java @@ -50,11 +50,11 @@ public interface IBpmCategoryService extends IService { /** * 获得流程分类 Map,基于指定编码 * - * @param codes 编号数组 + * @param ids 编号数组 * @return 流程分类 Map */ - default Map getCategoryMap(Collection codes) { - return convertMap(getCategoryListByCode(codes), BpmCategory::getCode); + default Map getCategoryMap(Collection ids) { + return convertMap(getCategoryListById(ids), BpmCategory::getId); } /** @@ -62,7 +62,7 @@ public interface IBpmCategoryService extends IService { * * @return 流程分类列表 */ - List getCategoryListByCode(Collection codes); + List getCategoryListById(Collection codes); diff --git a/pqs-bpm/bpm-boot/src/main/java/com/njcn/bpm/service/impl/BpmCategoryServiceImpl.java b/pqs-bpm/bpm-boot/src/main/java/com/njcn/bpm/service/impl/BpmCategoryServiceImpl.java index 1153c2ab9..99938cfd1 100644 --- a/pqs-bpm/bpm-boot/src/main/java/com/njcn/bpm/service/impl/BpmCategoryServiceImpl.java +++ b/pqs-bpm/bpm-boot/src/main/java/com/njcn/bpm/service/impl/BpmCategoryServiceImpl.java @@ -83,12 +83,12 @@ public class BpmCategoryServiceImpl extends ServiceImpl getCategoryListByCode(Collection codes) { - if (CollUtil.isEmpty(codes)) { + public List getCategoryListById(Collection ids) { + if (CollUtil.isEmpty(ids)) { return Collections.emptyList(); } LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>(); - lambdaQueryWrapper.in(BpmCategory::getCode,codes); + lambdaQueryWrapper.in(BpmCategory::getId,ids); return this.baseMapper.selectList(lambdaQueryWrapper); } diff --git a/pqs-bpm/bpm-boot/src/main/java/com/njcn/bpm/service/task/IBpmProcessInstanceService.java b/pqs-bpm/bpm-boot/src/main/java/com/njcn/bpm/service/task/IBpmProcessInstanceService.java index 20fbcdf5a..e79f95e46 100644 --- a/pqs-bpm/bpm-boot/src/main/java/com/njcn/bpm/service/task/IBpmProcessInstanceService.java +++ b/pqs-bpm/bpm-boot/src/main/java/com/njcn/bpm/service/task/IBpmProcessInstanceService.java @@ -1,5 +1,6 @@ package com.njcn.bpm.service.task; +import com.njcn.bpm.pojo.dto.BpmProcessInstanceCreateReqDTO; import org.flowable.engine.delegate.event.FlowableCancelledEvent; import org.flowable.engine.history.HistoricProcessInstance; import org.flowable.engine.runtime.ProcessInstance; @@ -26,6 +27,18 @@ public interface IBpmProcessInstanceService { * @return 流程实例 */ ProcessInstance getProcessInstance(String id); + + + /** + * 创建流程实例(提供给内部) + * + * @param userId 用户编号 + * @param createReqDTO 创建信息 + * @return 实例的编号 + */ + String createProcessInstance(String userId, BpmProcessInstanceCreateReqDTO createReqDTO); + + // // /** // * 获得流程实例列表 @@ -89,14 +102,7 @@ public interface IBpmProcessInstanceService { // */ // String createProcessInstance(Long userId, @Valid BpmProcessInstanceCreateReqVO createReqVO); // -// /** -// * 创建流程实例(提供给内部) -// * -// * @param userId 用户编号 -// * @param createReqDTO 创建信息 -// * @return 实例的编号 -// */ -// String createProcessInstance(Long userId, @Valid BpmProcessInstanceCreateReqDTO createReqDTO); + // // /** // * 发起人取消流程实例 diff --git a/pqs-bpm/bpm-boot/src/main/java/com/njcn/bpm/service/task/impl/BpmProcessInstanceServiceImpl.java b/pqs-bpm/bpm-boot/src/main/java/com/njcn/bpm/service/task/impl/BpmProcessInstanceServiceImpl.java index 9083efe05..372437b07 100644 --- a/pqs-bpm/bpm-boot/src/main/java/com/njcn/bpm/service/task/impl/BpmProcessInstanceServiceImpl.java +++ b/pqs-bpm/bpm-boot/src/main/java/com/njcn/bpm/service/task/impl/BpmProcessInstanceServiceImpl.java @@ -1,22 +1,27 @@ package com.njcn.bpm.service.task.impl; import cn.hutool.core.collection.CollUtil; -import cn.hutool.core.util.ArrayUtil; -import cn.hutool.core.util.StrUtil; +import com.njcn.bpm.constant.BpmConstants; +import com.njcn.bpm.enums.BpmProcessInstanceStatusEnum; +import com.njcn.bpm.enums.BpmResponseEnum; +import com.njcn.bpm.pojo.dto.BpmProcessInstanceCreateReqDTO; +import com.njcn.bpm.service.IBpmProcessDefinitionService; import com.njcn.bpm.service.task.IBpmProcessInstanceService; +import com.njcn.bpm.strategy.BpmTaskCandidateStartUserSelectStrategy; +import com.njcn.bpm.utils.CollectionUtils; +import com.njcn.common.pojo.exception.BusinessException; +import com.njcn.user.api.UserFeignClient; +import com.njcn.user.pojo.po.User; import lombok.extern.slf4j.Slf4j; import org.flowable.bpmn.model.BpmnModel; import org.flowable.bpmn.model.UserTask; import org.flowable.engine.HistoryService; import org.flowable.engine.RuntimeService; -import org.flowable.engine.delegate.event.FlowableCancelledEvent; -import org.flowable.engine.history.HistoricProcessInstance; -import org.flowable.engine.history.HistoricProcessInstanceQuery; import org.flowable.engine.repository.ProcessDefinition; import org.flowable.engine.runtime.ProcessInstance; import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; +import com.njcn.bpm.utils.FlowableUtils; import javax.annotation.Resource; import javax.validation.Valid; @@ -25,13 +30,13 @@ import java.util.*; /** * 流程实例 Service 实现类 - * + *

* ProcessDefinition & ProcessInstance & Execution & Task 的关系: - * 1. - * + * 1. + *

* HistoricProcessInstance & ProcessInstance 的关系: - * 1. - * + * 1. + *

* 简单来说,前者 = 历史 + 运行中的流程实例,后者仅是运行中的流程实例 * * @author 芋道源码 @@ -43,16 +48,18 @@ public class BpmProcessInstanceServiceImpl implements IBpmProcessInstanceService @Resource private RuntimeService runtimeService; + @Resource private HistoryService historyService; -// @Resource -// private BpmProcessDefinitionService processDefinitionService; + @Resource + private IBpmProcessDefinitionService processDefinitionService; + // @Resource // private BpmMessageService messageService; // -// @Resource -// private AdminUserApi adminUserApi; + @Resource + private UserFeignClient userFeignClient; // // @Resource // private BpmProcessInstanceEventPublisher processInstanceEventPublisher; @@ -64,6 +71,8 @@ public class BpmProcessInstanceServiceImpl implements IBpmProcessInstanceService .processInstanceId(id) .singleResult(); } + + // // @Override // public List getProcessInstances(Set ids) { @@ -128,70 +137,72 @@ public class BpmProcessInstanceServiceImpl implements IBpmProcessInstanceService // return createProcessInstance0(userId, definition, createReqVO.getVariables(), null, // createReqVO.getStartUserSelectAssignees()); // } -// -// @Override -// public String createProcessInstance(Long userId, @Valid BpmProcessInstanceCreateReqDTO createReqDTO) { -// // 获得流程定义 -// ProcessDefinition definition = processDefinitionService.getActiveProcessDefinition(createReqDTO.getProcessDefinitionKey()); -// // 发起流程 -// return createProcessInstance0(userId, definition, createReqDTO.getVariables(), createReqDTO.getBusinessKey(), -// createReqDTO.getStartUserSelectAssignees()); -// } -// -// private String createProcessInstance0(Long userId, ProcessDefinition definition, -// Map variables, String businessKey, -// Map> startUserSelectAssignees) { -// // 1.1 校验流程定义 -// if (definition == null) { -// throw exception(PROCESS_DEFINITION_NOT_EXISTS); -// } -// if (definition.isSuspended()) { -// throw exception(PROCESS_DEFINITION_IS_SUSPENDED); -// } -// // 1.2 校验发起人自选审批人 -// validateStartUserSelectAssignees(definition, startUserSelectAssignees); -// -// // 2. 创建流程实例 -// if (variables == null) { -// variables = new HashMap<>(); -// } -// FlowableUtils.filterProcessInstanceFormVariable(variables); // 过滤一下,避免 ProcessInstance 系统级的变量被占用 -// variables.put(BpmConstants.PROCESS_INSTANCE_VARIABLE_STATUS, // 流程实例状态:审批中 -// BpmProcessInstanceStatusEnum.RUNNING.getStatus()); -// if (CollUtil.isNotEmpty(startUserSelectAssignees)) { -// variables.put(BpmConstants.PROCESS_INSTANCE_VARIABLE_START_USER_SELECT_ASSIGNEES, startUserSelectAssignees); -// } -// ProcessInstance instance = runtimeService.createProcessInstanceBuilder() -// .processDefinitionId(definition.getId()) -// .businessKey(businessKey) -// .name(definition.getName().trim()) -// .variables(variables) -// .start(); -// return instance.getId(); -// } -// -// private void validateStartUserSelectAssignees(ProcessDefinition definition, Map> startUserSelectAssignees) { -// // 1. 获得发起人自选审批人的 UserTask 列表 -// BpmnModel bpmnModel = processDefinitionService.getProcessDefinitionBpmnModel(definition.getId()); -// List userTaskList = BpmTaskCandidateStartUserSelectStrategy.getStartUserSelectUserTaskList(bpmnModel); -// if (CollUtil.isEmpty(userTaskList)) { -// return; -// } -// -// // 2. 校验发起人自选审批人的 UserTask 是否都配置了 -// userTaskList.forEach(userTask -> { -// List assignees = startUserSelectAssignees != null ? startUserSelectAssignees.get(userTask.getId()) : null; -// if (CollUtil.isEmpty(assignees)) { -// throw exception(PROCESS_INSTANCE_START_USER_SELECT_ASSIGNEES_NOT_CONFIG, userTask.getName()); -// } -// Map userMap = adminUserApi.getUserMap(assignees); -// assignees.forEach(assignee -> { -// if (userMap.get(assignee) == null) { -// throw exception(PROCESS_INSTANCE_START_USER_SELECT_ASSIGNEES_NOT_EXISTS, userTask.getName(), assignee); -// } -// }); -// }); -// } + + @Override + public String createProcessInstance(String userId, @Valid BpmProcessInstanceCreateReqDTO createReqDTO) { + // 获得流程定义 + ProcessDefinition definition = processDefinitionService.getActiveProcessDefinition(createReqDTO.getProcessDefinitionKey()); + // 发起流程 + return createProcessInstance(userId, definition, createReqDTO.getVariables(), createReqDTO.getBusinessKey(), + createReqDTO.getStartUserSelectAssignees()); + } + + private String createProcessInstance(String userId, ProcessDefinition definition, + Map variables, String businessKey, + Map> startUserSelectAssignees) { + // 1.1 校验流程定义 + if (definition == null) { + throw new BusinessException(BpmResponseEnum.PROCESS_DEFINITION_NOT_EXISTS); + } + if (definition.isSuspended()) { + throw new BusinessException(BpmResponseEnum.PROCESS_DEFINITION_IS_SUSPENDED); + } + + // 1.2 校验发起人自选审批人 + validateStartUserSelectAssignees(definition, startUserSelectAssignees); + + // 2. 创建流程实例 + if (variables == null) { + variables = new HashMap<>(); + } + FlowableUtils.filterProcessInstanceFormVariable(variables); // 过滤一下,避免 ProcessInstance 系统级的变量被占用 + variables.put(BpmConstants.PROCESS_INSTANCE_VARIABLE_STATUS, // 流程实例状态:审批中 + BpmProcessInstanceStatusEnum.RUNNING.getStatus()); + if (CollUtil.isNotEmpty(startUserSelectAssignees)) { + variables.put(BpmConstants.PROCESS_INSTANCE_VARIABLE_START_USER_SELECT_ASSIGNEES, startUserSelectAssignees); + } + ProcessInstance instance = runtimeService.createProcessInstanceBuilder() + .processDefinitionId(definition.getId()) + .businessKey(businessKey) + .name(definition.getName().trim()) + .variables(variables) + .start(); + return instance.getId(); + } + + private void validateStartUserSelectAssignees(ProcessDefinition definition, Map> startUserSelectAssignees) { + // 1. 获得发起人自选审批人的 UserTask 列表 + BpmnModel bpmnModel = processDefinitionService.getProcessDefinitionBpmnModel(definition.getId()); + List userTaskList = BpmTaskCandidateStartUserSelectStrategy.getStartUserSelectUserTaskList(bpmnModel); + if (CollUtil.isEmpty(userTaskList)) { + return; + } + + // 2. 校验发起人自选审批人的 UserTask 是否都配置了 + userTaskList.forEach(userTask -> { + List assignees = startUserSelectAssignees != null ? startUserSelectAssignees.get(userTask.getId()) : null; + if (CollUtil.isEmpty(assignees)) { + throw new BusinessException("审批任务(" + userTask.getName() + ")的审批人未配置"); + } + List userList = userFeignClient.getUserByIdList(assignees).getData(); + Map userMap = CollectionUtils.convertMap(userList, User::getId); + assignees.forEach(assignee -> { + if (userMap.get(assignee) == null) { + throw new BusinessException("审批任务(" + userTask.getName() + ")的审批人(" + assignee + ")不存在"); + } + }); + }); + } // // @Override // public void cancelProcessInstanceByStartUser(Long userId, @Valid BpmProcessInstanceCancelReqVO cancelReqVO) { diff --git a/pqs-bpm/bpm-boot/src/main/java/com/njcn/bpm/utils/FlowableUtils.java b/pqs-bpm/bpm-boot/src/main/java/com/njcn/bpm/utils/FlowableUtils.java index 3a4215234..1ed66e20e 100644 --- a/pqs-bpm/bpm-boot/src/main/java/com/njcn/bpm/utils/FlowableUtils.java +++ b/pqs-bpm/bpm-boot/src/main/java/com/njcn/bpm/utils/FlowableUtils.java @@ -1,6 +1,6 @@ package com.njcn.bpm.utils; -import com.njcn.bpm.enums.BpmConstants; +import com.njcn.bpm.constant.BpmConstants; import org.flowable.common.engine.api.delegate.Expression; import org.flowable.common.engine.api.variable.VariableContainer; import org.flowable.common.engine.impl.el.ExpressionManager; diff --git a/pqs-common/common-core/src/main/java/com/njcn/common/pojo/constant/ServerInfo.java b/pqs-common/common-core/src/main/java/com/njcn/common/pojo/constant/ServerInfo.java index 4cceecaad..762204568 100644 --- a/pqs-common/common-core/src/main/java/com/njcn/common/pojo/constant/ServerInfo.java +++ b/pqs-common/common-core/src/main/java/com/njcn/common/pojo/constant/ServerInfo.java @@ -15,6 +15,7 @@ public interface ServerInfo { String COMMON = "pqs-common"; String DEVICE = "device-boot"; String EVENT = "event-boot"; + String SUPERVISION = "supervision-boot"; String HARMONIC = "harmonic-boot"; String REPORT = "report-boot"; String SYSTEM = "system-boot"; diff --git a/pqs-supervision/supervision-api/src/main/java/com/njcn/supervision/enums/FlowStatusEnum.java b/pqs-supervision/supervision-api/src/main/java/com/njcn/supervision/enums/FlowStatusEnum.java new file mode 100644 index 000000000..97f18f55f --- /dev/null +++ b/pqs-supervision/supervision-api/src/main/java/com/njcn/supervision/enums/FlowStatusEnum.java @@ -0,0 +1,46 @@ +package com.njcn.supervision.enums; + +import lombok.Getter; + +import java.util.Objects; + +/** + * 流程审批状态 + */ +@Getter +public enum FlowStatusEnum { + + AUDIT(1, "审批中"), + APPROVE(2, "审批通过"), + OPPOSE(3, "审批不通过"), + CANCEL(4, "已取消"); + + private final Integer code; + + private final String name; + + FlowStatusEnum(Integer code, String name) { + this.code = code; + this.name = name; + } + + + public static String getNameByCode(Integer code) { + for (FlowStatusEnum userNatureEnum : FlowStatusEnum.values()) { + if (Objects.equals(userNatureEnum.code, code)) { + return userNatureEnum.name; + } + } + return ""; + } + + + public static Integer getCodeByName(String name) { + for (FlowStatusEnum userNatureEnum : FlowStatusEnum.values()) { + if (userNatureEnum.name.equalsIgnoreCase(name)) { + return userNatureEnum.code; + } + } + return 0; + } +} diff --git a/pqs-supervision/supervision-api/src/main/java/com/njcn/supervision/enums/SupervisionUserStatusEnum.java b/pqs-supervision/supervision-api/src/main/java/com/njcn/supervision/enums/SupervisionUserStatusEnum.java new file mode 100644 index 000000000..3edb3abc9 --- /dev/null +++ b/pqs-supervision/supervision-api/src/main/java/com/njcn/supervision/enums/SupervisionUserStatusEnum.java @@ -0,0 +1,28 @@ +package com.njcn.supervision.enums; + +import lombok.Getter; + +/** + * 技术监督用户状态枚举 + */ +@Getter +public enum SupervisionUserStatusEnum { + + /** + * 技术监督用户状态:可研/建设/运行/退运 + */ + RESEARCH(0, "可研"), + BUILD(1, "建设"), + PRODUCT(2, "运行"), + QUIT(3, "退运"); + + private final int code; + + private final String message; + + SupervisionUserStatusEnum(int code, String message) { + this.code=code; + this.message=message; + } + +} diff --git a/pqs-supervision/supervision-api/src/main/java/com/njcn/supervision/enums/UserNatureEnum.java b/pqs-supervision/supervision-api/src/main/java/com/njcn/supervision/enums/UserNatureEnum.java new file mode 100644 index 000000000..4267434ff --- /dev/null +++ b/pqs-supervision/supervision-api/src/main/java/com/njcn/supervision/enums/UserNatureEnum.java @@ -0,0 +1,49 @@ +package com.njcn.supervision.enums; + +import lombok.Getter; + +import java.util.Objects; + +/** + * 用户性质枚举 + */ +@Getter +public enum UserNatureEnum { + + BUILD_POWER_GRID(0, "新建电网工程"), + EXTEND_POWER_GRID(1, "扩建电网工程"), + BUILD_NON_LINEAR_LOAD(2, "新建非线性负荷用户"), + EXTEND_NON_LINEAR_LOAD(3, "扩建非线性负荷用户"), + BUILD_NEW_ENERGY_POWER_STATION(4, "新建新能源发电站"), + EXTEND_NEW_ENERGY_POWER_STATION(5, "扩建新能源发电站"), + SENSITIVE_USER(6, "敏感及重要用户"); + + private final Integer code; + + private final String name; + + UserNatureEnum(Integer code, String name) { + this.code = code; + this.name = name; + } + + + public static String getNameByCode(Integer code) { + for (UserNatureEnum userNatureEnum : UserNatureEnum.values()) { + if (Objects.equals(userNatureEnum.code, code)) { + return userNatureEnum.name; + } + } + return ""; + } + + + public static Integer getCodeByName(String name) { + for (UserNatureEnum userNatureEnum : UserNatureEnum.values()) { + if (userNatureEnum.name.equalsIgnoreCase(name)) { + return userNatureEnum.code; + } + } + return 0; + } +} diff --git a/pqs-supervision/supervision-api/src/main/java/com/njcn/supervision/pojo/param/user/UserReportParam.java b/pqs-supervision/supervision-api/src/main/java/com/njcn/supervision/pojo/param/user/UserReportParam.java index 1f94bd9ba..208ff2743 100644 --- a/pqs-supervision/supervision-api/src/main/java/com/njcn/supervision/pojo/param/user/UserReportParam.java +++ b/pqs-supervision/supervision-api/src/main/java/com/njcn/supervision/pojo/param/user/UserReportParam.java @@ -7,12 +7,15 @@ import com.njcn.supervision.pojo.po.user.UserReportSensitivePO; import com.njcn.supervision.pojo.po.user.UserReportSubstationPO; import com.njcn.web.pojo.param.BaseParam; import io.swagger.annotations.ApiModelProperty; +import io.swagger.v3.oas.annotations.media.Schema; import lombok.AllArgsConstructor; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; import java.time.LocalDate; +import java.util.List; +import java.util.Map; /** * @@ -58,7 +61,7 @@ public class UserReportParam extends BaseEntity { * 用户性质 */ @ApiModelProperty(value = "用户性质") - private String userType; + private Integer userType; /** * 所属地市 @@ -76,7 +79,7 @@ public class UserReportParam extends BaseEntity { * 用户状态 */ @ApiModelProperty(value = "用户状态") - private String userStatus; + private Integer userStatus; /** * 变电站 @@ -108,6 +111,9 @@ public class UserReportParam extends BaseEntity { @ApiModelProperty(value = "预测评估结论") private String evaluationConclusion; + @ApiModelProperty("发起人自选审批人 Map") + private Map> startUserSelectAssignees; + private UserReportProjectPO userReportProjectPO; @@ -117,7 +123,9 @@ public class UserReportParam extends BaseEntity { @Data + @EqualsAndHashCode(callSuper = true) public static class UserReportUpdate extends UserReportParam { + @ApiModelProperty("id") private String Id; diff --git a/pqs-supervision/supervision-api/src/main/java/com/njcn/supervision/pojo/po/user/UserReportPO.java b/pqs-supervision/supervision-api/src/main/java/com/njcn/supervision/pojo/po/user/UserReportPO.java index 318b4864d..b87db3eb0 100644 --- a/pqs-supervision/supervision-api/src/main/java/com/njcn/supervision/pojo/po/user/UserReportPO.java +++ b/pqs-supervision/supervision-api/src/main/java/com/njcn/supervision/pojo/po/user/UserReportPO.java @@ -58,7 +58,7 @@ public class UserReportPO extends BaseEntity { * 用户性质 */ @TableField(value = "user_type") - private String userType; + private Integer userType; /** * 所属地市 @@ -76,7 +76,7 @@ public class UserReportPO extends BaseEntity { * 用户状态 */ @TableField(value = "user_status") - private String userStatus; + private Integer userStatus; /** * 变电站 diff --git a/pqs-supervision/supervision-api/src/main/java/com/njcn/supervision/pojo/vo/user/UserReportVO.java b/pqs-supervision/supervision-api/src/main/java/com/njcn/supervision/pojo/vo/user/UserReportVO.java index e7179db43..8b4f75449 100644 --- a/pqs-supervision/supervision-api/src/main/java/com/njcn/supervision/pojo/vo/user/UserReportVO.java +++ b/pqs-supervision/supervision-api/src/main/java/com/njcn/supervision/pojo/vo/user/UserReportVO.java @@ -51,7 +51,7 @@ public class UserReportVO { * 用户性质 */ @ApiModelProperty(value = "用户性质") - private String userType; + private Integer userType; /** * 所属地市 @@ -69,7 +69,7 @@ public class UserReportVO { * 用户状态 */ @ApiModelProperty(value = "用户状态") - private String userStatus; + private Integer userStatus; /** * 变电站 diff --git a/pqs-supervision/supervision-boot/pom.xml b/pqs-supervision/supervision-boot/pom.xml index 93aef070c..153369092 100644 --- a/pqs-supervision/supervision-boot/pom.xml +++ b/pqs-supervision/supervision-boot/pom.xml @@ -24,6 +24,12 @@ ${project.version} + + com.njcn + bpm-api + ${project.version} + + com.njcn common-web diff --git a/pqs-supervision/supervision-boot/src/main/java/com/njcn/supervision/controller/user/UserReportManageController.java b/pqs-supervision/supervision-boot/src/main/java/com/njcn/supervision/controller/user/UserReportManageController.java index 6d895a490..6637508d8 100644 --- a/pqs-supervision/supervision-boot/src/main/java/com/njcn/supervision/controller/user/UserReportManageController.java +++ b/pqs-supervision/supervision-boot/src/main/java/com/njcn/supervision/controller/user/UserReportManageController.java @@ -37,18 +37,14 @@ public class UserReportManageController extends BaseController { private final UserReportPOService userReportPOService; - - - @OperateInfo(info = LogEnum.BUSINESS_COMMON,operateType= OperateType.ADD) - @PostMapping("/addUserReport") + @PostMapping("/add") @ApiOperation("新增干扰源用户(未建档干扰源用户管理)") @ApiImplicitParam(name = "userReportParam", value = "实体参数", required = true) - public HttpResult addUserReport(@RequestBody @Validated UserReportParam userReportParam){ + public HttpResult addUserReport(@RequestBody @Validated UserReportParam userReportParam){ String methodDescribe = getMethodDescribe("addUserReport"); - boolean res = userReportPOService.addUserReport(userReportParam); - - return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, res, methodDescribe); + String userReportId = userReportPOService.addUserReport(userReportParam); + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, userReportId, methodDescribe); } diff --git a/pqs-supervision/supervision-boot/src/main/java/com/njcn/supervision/mapper/user/mapping/UserReportPOMapper.xml b/pqs-supervision/supervision-boot/src/main/java/com/njcn/supervision/mapper/user/mapping/UserReportPOMapper.xml index 4967c0ede..da869bd81 100644 --- a/pqs-supervision/supervision-boot/src/main/java/com/njcn/supervision/mapper/user/mapping/UserReportPOMapper.xml +++ b/pqs-supervision/supervision-boot/src/main/java/com/njcn/supervision/mapper/user/mapping/UserReportPOMapper.xml @@ -1,7 +1,7 @@ - + diff --git a/pqs-supervision/supervision-boot/src/main/java/com/njcn/supervision/mapper/user/mapping/UserReportProjectPOMapper.xml b/pqs-supervision/supervision-boot/src/main/java/com/njcn/supervision/mapper/user/mapping/UserReportProjectPOMapper.xml index cc91f096a..925117cd4 100644 --- a/pqs-supervision/supervision-boot/src/main/java/com/njcn/supervision/mapper/user/mapping/UserReportProjectPOMapper.xml +++ b/pqs-supervision/supervision-boot/src/main/java/com/njcn/supervision/mapper/user/mapping/UserReportProjectPOMapper.xml @@ -1,7 +1,7 @@ - + diff --git a/pqs-supervision/supervision-boot/src/main/java/com/njcn/supervision/mapper/user/mapping/UserReportSensitivePOMapper.xml b/pqs-supervision/supervision-boot/src/main/java/com/njcn/supervision/mapper/user/mapping/UserReportSensitivePOMapper.xml index 6594e0586..00fcbde2c 100644 --- a/pqs-supervision/supervision-boot/src/main/java/com/njcn/supervision/mapper/user/mapping/UserReportSensitivePOMapper.xml +++ b/pqs-supervision/supervision-boot/src/main/java/com/njcn/supervision/mapper/user/mapping/UserReportSensitivePOMapper.xml @@ -1,7 +1,7 @@ - + diff --git a/pqs-supervision/supervision-boot/src/main/java/com/njcn/supervision/mapper/user/mapping/UserReportSubstationPOMapper.xml b/pqs-supervision/supervision-boot/src/main/java/com/njcn/supervision/mapper/user/mapping/UserReportSubstationPOMapper.xml index a9ca8a154..16e633fc4 100644 --- a/pqs-supervision/supervision-boot/src/main/java/com/njcn/supervision/mapper/user/mapping/UserReportSubstationPOMapper.xml +++ b/pqs-supervision/supervision-boot/src/main/java/com/njcn/supervision/mapper/user/mapping/UserReportSubstationPOMapper.xml @@ -1,7 +1,7 @@ - + diff --git a/pqs-supervision/supervision-boot/src/main/java/com/njcn/supervision/service/user/UserReportPOService.java b/pqs-supervision/supervision-boot/src/main/java/com/njcn/supervision/service/user/UserReportPOService.java index 1a4f4f089..621723cab 100644 --- a/pqs-supervision/supervision-boot/src/main/java/com/njcn/supervision/service/user/UserReportPOService.java +++ b/pqs-supervision/supervision-boot/src/main/java/com/njcn/supervision/service/user/UserReportPOService.java @@ -18,7 +18,7 @@ import java.util.List; public interface UserReportPOService extends IService { - boolean addUserReport(UserReportParam userReportParam); + String addUserReport(UserReportParam userReportParam); boolean auditUserReport(UserReportParam.UserReportUpdate userReportUpdate); diff --git a/pqs-supervision/supervision-boot/src/main/java/com/njcn/supervision/service/user/impl/UserReportPOServiceImpl.java b/pqs-supervision/supervision-boot/src/main/java/com/njcn/supervision/service/user/impl/UserReportPOServiceImpl.java index 3af265eec..d89094b7d 100644 --- a/pqs-supervision/supervision-boot/src/main/java/com/njcn/supervision/service/user/impl/UserReportPOServiceImpl.java +++ b/pqs-supervision/supervision-boot/src/main/java/com/njcn/supervision/service/user/impl/UserReportPOServiceImpl.java @@ -2,10 +2,16 @@ package com.njcn.supervision.service.user.impl; import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.util.StrUtil; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.njcn.bpm.api.BpmProcessFeignClient; +import com.njcn.bpm.pojo.dto.BpmProcessInstanceCreateReqDTO; import com.njcn.common.pojo.enums.common.DataStateEnum; +import com.njcn.common.pojo.exception.BusinessException; +import com.njcn.supervision.enums.FlowStatusEnum; +import com.njcn.supervision.enums.UserNatureEnum; import com.njcn.supervision.mapper.user.UserReportPOMapper; import com.njcn.supervision.pojo.param.user.UserReportParam; import com.njcn.supervision.pojo.po.user.UserReportPO; @@ -24,14 +30,12 @@ import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanWrapper; import org.springframework.beans.BeanWrapperImpl; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; -import java.util.HashSet; -import java.util.List; -import java.util.Objects; -import java.util.Set; +import java.util.*; +import java.util.stream.Collectors; /** - * * Description: * Date: 2024/4/25 10:07【需求编号】 * @@ -42,59 +46,91 @@ import java.util.Set; @RequiredArgsConstructor public class UserReportPOServiceImpl extends ServiceImpl implements UserReportPOService { + /** + * 用户信息建档对应的流程定义 KEY + */ + public static final String PROCESS_KEY = "build_user_info"; + private final UserReportProjectPOService userReportProjectPOService; private final UserReportSubstationPOService userReportSubstationPOService; private final UserReportSensitivePOService userReportSensitivePOService; + private final BpmProcessFeignClient bpmProcessFeignClient; + @Override - public boolean addUserReport(UserReportParam userReportParam) { + @Transactional(rollbackFor = Exception.class) + public String addUserReport(UserReportParam userReportParam) { + //判断工程名称是否有重复的 + checkProjectName(userReportParam, false); UserReportPO userReportPO = new UserReportPO(); - BeanUtils.copyProperties(userReportParam,userReportPO); - userReportPO.setState(1); - boolean save = this.save(userReportPO); - String id = userReportPO.getId(); - if(Objects.equals(userReportPO.getUserType(),"1")|| - Objects.equals(userReportPO.getUserType(),"2")){ + BeanUtils.copyProperties(userReportParam, userReportPO); + userReportPO.setState(DataStateEnum.ENABLE.getCode()); + this.save(userReportPO); + if ( + CollectionUtil.newArrayList( + UserNatureEnum.BUILD_POWER_GRID.getCode(), + UserNatureEnum.EXTEND_POWER_GRID.getCode() + ).contains(userReportPO.getUserType())) { + //电网工程类用户额外数据 UserReportProjectPO userReportProjectPO = userReportParam.getUserReportProjectPO(); - userReportProjectPO.setId(id); - userReportProjectPO.setState(1); + userReportProjectPO.setId(userReportPO.getId()); + userReportProjectPO.setState(DataStateEnum.ENABLE.getCode()); userReportProjectPOService.saveOrUpdate(userReportProjectPO); - }else if(Objects.equals(userReportPO.getUserType(),"3")|| - Objects.equals(userReportPO.getUserType(),"4")){ + } else if ( + CollectionUtil.newArrayList( + UserNatureEnum.BUILD_NON_LINEAR_LOAD.getCode(), + UserNatureEnum.EXTEND_NON_LINEAR_LOAD.getCode(), + UserNatureEnum.BUILD_NEW_ENERGY_POWER_STATION.getCode(), + UserNatureEnum.EXTEND_NEW_ENERGY_POWER_STATION.getCode() + ).contains(userReportPO.getUserType())) { + //非线性负荷用户 & 新能源发电站用户 UserReportSubstationPO userReportSubstationPO = userReportParam.getUserReportSubstationPO(); - userReportSubstationPO.setId(id); - userReportSubstationPO.setState(1); + userReportSubstationPO.setId(userReportPO.getId()); + userReportSubstationPO.setState(DataStateEnum.ENABLE.getCode()); userReportSubstationPOService.saveOrUpdate(userReportSubstationPO); - }else if(Objects.equals(userReportPO.getUserType(),"5")){ + } else if (UserNatureEnum.SENSITIVE_USER.getCode().equals(userReportPO.getUserType())) { + // 敏感及重要用户 UserReportSensitivePO userReportSensitivePO = userReportParam.getUserReportSensitivePO(); - userReportSensitivePO.setId(id); - userReportSensitivePO.setState(1); + userReportSensitivePO.setId(userReportPO.getId()); + userReportSensitivePO.setState(DataStateEnum.ENABLE.getCode()); userReportSensitivePOService.saveOrUpdate(userReportSensitivePO); } + // 发起 BPM 流程 + Map processInstanceVariables = new HashMap<>(); + BpmProcessInstanceCreateReqDTO bpmProcessInstanceCreateReqDTO = new BpmProcessInstanceCreateReqDTO(); + bpmProcessInstanceCreateReqDTO.setProcessDefinitionKey(PROCESS_KEY); + bpmProcessInstanceCreateReqDTO.setBusinessKey(userReportPO.getId()); + bpmProcessInstanceCreateReqDTO.setStartUserSelectAssignees(userReportParam.getStartUserSelectAssignees()); + bpmProcessInstanceCreateReqDTO.setVariables(processInstanceVariables); + String processInstanceId = bpmProcessFeignClient.createProcessInstance(userReportPO.getCreateBy(),bpmProcessInstanceCreateReqDTO).getData(); + // 将工作流的编号,更新到流程单中 + userReportPO.setProcessInstanceId(processInstanceId); + this.baseMapper.updateById(userReportPO); - return save; + return userReportPO.getId(); } + @Override public boolean auditUserReport(UserReportParam.UserReportUpdate userReportUpdate) { String id = userReportUpdate.getId(); UserReportPO byId = this.getById(id); - BeanUtils.copyProperties(userReportUpdate,byId); + BeanUtils.copyProperties(userReportUpdate, byId); this.updateById(byId); - if(Objects.equals(userReportUpdate.getUserType(),"1")|| - Objects.equals(userReportUpdate.getUserType(),"2")){ + if (Objects.equals(userReportUpdate.getUserType(), "1") || + Objects.equals(userReportUpdate.getUserType(), "2")) { UserReportProjectPO userReportProjectPO = userReportProjectPOService.getById(id); - BeanUtils.copyProperties(userReportUpdate.getUserReportProjectPO(),userReportProjectPO,getNullPropertyNames(userReportUpdate.getUserReportProjectPO())); + BeanUtils.copyProperties(userReportUpdate.getUserReportProjectPO(), userReportProjectPO, getNullPropertyNames(userReportUpdate.getUserReportProjectPO())); userReportProjectPOService.updateById(userReportProjectPO); - }else if(Objects.equals(userReportUpdate.getUserType(),"3")|| - Objects.equals(userReportUpdate.getUserType(),"4")){ - UserReportSubstationPO userReportSubstationPO = userReportSubstationPOService.getById(id); - BeanUtils.copyProperties(userReportUpdate.getUserReportSubstationPO(),userReportSubstationPO,getNullPropertyNames(userReportUpdate.getUserReportSubstationPO())); + } else if (Objects.equals(userReportUpdate.getUserType(), "3") || + Objects.equals(userReportUpdate.getUserType(), "4")) { + UserReportSubstationPO userReportSubstationPO = userReportSubstationPOService.getById(id); + BeanUtils.copyProperties(userReportUpdate.getUserReportSubstationPO(), userReportSubstationPO, getNullPropertyNames(userReportUpdate.getUserReportSubstationPO())); userReportSubstationPOService.updateById(userReportSubstationPO); - }else if(Objects.equals(userReportUpdate.getUserType(),"5")){ - UserReportSensitivePO userReportSensitivePO = userReportSensitivePOService.getById(id); - BeanUtils.copyProperties(userReportUpdate.getUserReportSensitivePO(),userReportSensitivePO,getNullPropertyNames(userReportUpdate.getUserReportSensitivePO())); + } else if (Objects.equals(userReportUpdate.getUserType(), "5")) { + UserReportSensitivePO userReportSensitivePO = userReportSensitivePOService.getById(id); + BeanUtils.copyProperties(userReportUpdate.getUserReportSensitivePO(), userReportSensitivePO, getNullPropertyNames(userReportUpdate.getUserReportSensitivePO())); userReportSensitivePOService.updateById(userReportSensitivePO); } @@ -111,10 +147,10 @@ public class UserReportPOServiceImpl extends ServiceImpl userReportVOQueryWrapper = new QueryWrapper<>(); userReportVOQueryWrapper.in("supervision_user_report.create_by", CollectionUtil.newArrayList(userIndex)) .eq("supervision_user_report.state", DataStateEnum.ENABLE.getCode()); - if(Objects.nonNull(userReportQueryParam)){ - if(StrUtil.isNotBlank(userReportQueryParam.getCity())){ + if (Objects.nonNull(userReportQueryParam)) { + if (StrUtil.isNotBlank(userReportQueryParam.getCity())) { //查询所有区域下的数据 - userReportVOQueryWrapper.in("supervision_user_report.city",userReportQueryParam.getCity()); + userReportVOQueryWrapper.in("supervision_user_report.city", userReportQueryParam.getCity()); } } userReportVOQueryWrapper.orderByDesc("supervision_user_report.create_time"); @@ -123,10 +159,10 @@ public class UserReportPOServiceImpl extends ServiceImpl ids) { - this.lambdaUpdate().set(UserReportPO::getState,0).in(UserReportPO::getId,ids).update(); - userReportProjectPOService.lambdaUpdate().set(UserReportProjectPO::getState,0).in(UserReportProjectPO::getId,ids).update(); - userReportSubstationPOService.lambdaUpdate().set(UserReportSubstationPO::getState,0).in(UserReportSubstationPO::getId,ids).update(); - userReportSensitivePOService.lambdaUpdate().set(UserReportSensitivePO::getState,0).in(UserReportSensitivePO::getId,ids).update(); + this.lambdaUpdate().set(UserReportPO::getState, 0).in(UserReportPO::getId, ids).update(); + userReportProjectPOService.lambdaUpdate().set(UserReportProjectPO::getState, 0).in(UserReportProjectPO::getId, ids).update(); + userReportSubstationPOService.lambdaUpdate().set(UserReportSubstationPO::getState, 0).in(UserReportSubstationPO::getId, ids).update(); + userReportSensitivePOService.lambdaUpdate().set(UserReportSensitivePO::getState, 0).in(UserReportSensitivePO::getId, ids).update(); return true; } @@ -134,23 +170,55 @@ public class UserReportPOServiceImpl extends ServiceImpl emptyNames = new HashSet ( ); + Set emptyNames = new HashSet<>(); for (java.beans.PropertyDescriptor pd : pds) { - Object srcValue = src.getPropertyValue (pd.getName ( )); - if (srcValue == null){ - emptyNames.add (pd.getName ( )); + Object srcValue = src.getPropertyValue(pd.getName()); + if (srcValue == null) { + emptyNames.add(pd.getName()); } } - String[] result = new String[emptyNames.size ( )]; - return emptyNames.toArray (result); + String[] result = new String[emptyNames.size()]; + return emptyNames.toArray(result); } + /** + * 判断工程名称是否重复,如果重复则提示用户XXX已经创建该工程 + * + * @param userReportParam 用户申请数据 + * @param isExcludeSelf 是否排除自己,一般新增不排除,更新时需要排除自己 + */ + private void checkProjectName(UserReportParam userReportParam, boolean isExcludeSelf) { + LambdaQueryWrapper userReportPOLambdaQueryWrapper = new LambdaQueryWrapper<>(); + userReportPOLambdaQueryWrapper + .eq(UserReportPO::getProjectName, userReportParam.getProjectName()) + .eq(UserReportPO::getState, DataStateEnum.ENABLE.getCode()); + //更新的时候,需排除当前记录 + if (isExcludeSelf) { + if (userReportParam instanceof UserReportParam.UserReportUpdate) { + userReportPOLambdaQueryWrapper.ne(UserReportPO::getId, ((UserReportParam.UserReportUpdate) userReportParam).getId()); + } + } + List userReportPOList = this.baseMapper.selectList(userReportPOLambdaQueryWrapper); + if (CollectionUtil.isNotEmpty(userReportPOList)) { + //过滤已取消的申请 + userReportPOList = userReportPOList.stream() + .filter(userReportPO -> !userReportPO.getStatus().equals(FlowStatusEnum.CANCEL.getCode())) + .collect(Collectors.toList()); + //如果还存在,则说明有人申请过了 + if (CollectionUtil.isNotEmpty(userReportPOList)) { + throw new BusinessException(userReportParam.getProjectName().concat(",该工程已被").concat(userReportPOList.get(0).getReporter()).concat("申请")); + } + } + } + + }