mirror of
				https://gitee.com/hhyykk/ipms-sjy.git
				synced 2025-10-31 10:18:42 +08:00 
			
		
		
		
	工作流 Flowable 流程模型, 流程定义 优化
This commit is contained in:
		| @@ -1,4 +0,0 @@ | ||||
| ### 请求 /bpm/task-assign-rule/list 接口 => 成功 | ||||
| GET {{baseUrl}}/bpm/task-assign-rule/list?processDefinitionId=leave:9:59689ba0-7284-11ec-965c-a2380e71991a | ||||
| tenant-id: 1 | ||||
| Authorization: Bearer {{token}} | ||||
| @@ -1,59 +0,0 @@ | ||||
| package cn.iocoder.yudao.module.bpm.controller.admin.definition; | ||||
|  | ||||
| import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.rule.BpmTaskAssignRuleCreateReqVO; | ||||
| import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.rule.BpmTaskAssignRuleRespVO; | ||||
| import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.rule.BpmTaskAssignRuleUpdateReqVO; | ||||
| import cn.iocoder.yudao.module.bpm.service.definition.BpmTaskAssignRuleService; | ||||
| import cn.iocoder.yudao.framework.common.pojo.CommonResult; | ||||
| import io.swagger.annotations.Api; | ||||
| import io.swagger.annotations.ApiImplicitParam; | ||||
| import io.swagger.annotations.ApiImplicitParams; | ||||
| import io.swagger.annotations.ApiOperation; | ||||
| import org.springframework.security.access.prepost.PreAuthorize; | ||||
| import org.springframework.validation.annotation.Validated; | ||||
| import org.springframework.web.bind.annotation.*; | ||||
|  | ||||
| import javax.annotation.Resource; | ||||
| import javax.validation.Valid; | ||||
| import java.util.List; | ||||
|  | ||||
| import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | ||||
|  | ||||
| @Api(tags = "管理后台 - 任务分配规则") | ||||
| @RestController | ||||
| @RequestMapping("/bpm/task-assign-rule") | ||||
| @Validated | ||||
| public class BpmTaskAssignRuleController { | ||||
|  | ||||
|     @Resource | ||||
|     private BpmTaskAssignRuleService taskAssignRuleService; | ||||
|  | ||||
|     @GetMapping("/list") | ||||
|     @ApiOperation(value = "获得任务分配规则列表") | ||||
|     @ApiImplicitParams({ | ||||
|             @ApiImplicitParam(name = "modelId", value = "模型编号", example = "1024", dataTypeClass = String.class), | ||||
|             @ApiImplicitParam(name = "processDefinitionId", value = "刘晨定义的编号", example = "2048", dataTypeClass = String.class) | ||||
|     }) | ||||
|     @PreAuthorize("@ss.hasPermission('bpm:task-assign-rule:query')") | ||||
|     public CommonResult<List<BpmTaskAssignRuleRespVO>> getTaskAssignRuleList( | ||||
|             @RequestParam(value = "modelId", required = false) String modelId, | ||||
|             @RequestParam(value = "processDefinitionId", required = false) String processDefinitionId) { | ||||
|         return success(taskAssignRuleService.getTaskAssignRuleList(modelId, processDefinitionId)); | ||||
|     } | ||||
|  | ||||
|     @PostMapping("/create") | ||||
|     @ApiOperation(value = "创建任务分配规则") | ||||
|     @PreAuthorize("@ss.hasPermission('bpm:task-assign-rule:create')") | ||||
|     public CommonResult<Long> createTaskAssignRule(@Valid @RequestBody BpmTaskAssignRuleCreateReqVO reqVO) { | ||||
|         return success(taskAssignRuleService.createTaskAssignRule(reqVO)); | ||||
|     } | ||||
|  | ||||
|     @PutMapping("/update") | ||||
|     @ApiOperation(value = "更新任务分配规则") | ||||
|     @PreAuthorize("@ss.hasPermission('bpm:task-assign-rule:update')") | ||||
|     public CommonResult<Boolean> updateTaskAssignRule(@Valid @RequestBody BpmTaskAssignRuleUpdateReqVO reqVO) { | ||||
|         taskAssignRuleService.updateTaskAssignRule(reqVO); | ||||
|         return success(true); | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -11,7 +11,60 @@ import javax.validation.Valid; | ||||
|  * | ||||
|  * @author yunlongn | ||||
|  */ | ||||
| public interface BpmModelService extends BpmModelCommonService { | ||||
| public interface BpmModelService { | ||||
|     /** | ||||
|      * 获得流程模型分页 | ||||
|      * | ||||
|      * @param pageVO 分页查询 | ||||
|      * @return 流程模型分页 | ||||
|      */ | ||||
|     PageResult<BpmModelPageItemRespVO> getModelPage(BpmModelPageReqVO pageVO); | ||||
|  | ||||
|     /** | ||||
|      * 创建流程模型 | ||||
|      * | ||||
|      * @param modelVO 创建信息 | ||||
|      * @param bpmnXml BPMN XML | ||||
|      * @return 创建的流程模型的编号 | ||||
|      */ | ||||
|     String createModel(@Valid BpmModelCreateReqVO modelVO, String bpmnXml); | ||||
|  | ||||
|     /** | ||||
|      * 获得流程模块 | ||||
|      * | ||||
|      * @param id 编号 | ||||
|      * @return 流程模型 | ||||
|      */ | ||||
|     BpmModelRespVO getModel(String id); | ||||
|  | ||||
|     /** | ||||
|      * 修改流程模型 | ||||
|      * | ||||
|      * @param updateReqVO 更新信息 | ||||
|      */ | ||||
|     void updateModel(@Valid BpmModelUpdateReqVO updateReqVO); | ||||
|  | ||||
|     /** | ||||
|      * 将流程模型,部署成一个流程定义 | ||||
|      * | ||||
|      * @param id 编号 | ||||
|      */ | ||||
|     void deployModel(String id); | ||||
|  | ||||
|     /** | ||||
|      * 删除模型 | ||||
|      * | ||||
|      * @param id 编号 | ||||
|      */ | ||||
|     void deleteModel(String id); | ||||
|  | ||||
|     /** | ||||
|      * 修改模型的状态,实际更新的部署的流程定义的状态 | ||||
|      * | ||||
|      * @param id 编号 | ||||
|      * @param state 状态 | ||||
|      */ | ||||
|     void updateModelState(String id, Integer state); | ||||
|  | ||||
|     /** | ||||
|      * 获得流程模型编号对应的 BPMN Model | ||||
|   | ||||
| @@ -3,8 +3,10 @@ package cn.iocoder.yudao.module.bpm.service.definition; | ||||
| import cn.hutool.core.collection.CollUtil; | ||||
| import cn.hutool.core.util.ArrayUtil; | ||||
| import cn.hutool.core.util.StrUtil; | ||||
| import cn.iocoder.yudao.framework.common.util.validation.ValidationUtils; | ||||
| import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.*; | ||||
| import cn.iocoder.yudao.module.bpm.convert.definition.BpmModelConvert; | ||||
| import cn.iocoder.yudao.module.bpm.enums.definition.BpmModelFormTypeEnum; | ||||
| import cn.iocoder.yudao.module.bpm.service.definition.dto.BpmModelMetaInfoRespDTO; | ||||
| import cn.iocoder.yudao.framework.activiti.core.util.ActivitiUtils; | ||||
| import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||||
| @@ -45,17 +47,16 @@ import static cn.iocoder.yudao.module.bpm.enums.ErrorCodeConstants.*; | ||||
| @Service | ||||
| @Validated | ||||
| @Slf4j | ||||
| public class BpmModelServiceImpl extends BpmAbstractModelService implements BpmModelService { | ||||
| public class BpmModelServiceImpl  implements BpmModelService { | ||||
|  | ||||
|     @Resource | ||||
|     private RepositoryService repositoryService; | ||||
|  | ||||
|     @Resource | ||||
|     private BpmProcessDefinitionService processDefinitionService; | ||||
|  | ||||
|     public BpmModelServiceImpl(BpmFormService bpmFormService,BpmTaskAssignRuleService taskAssignRuleService) { | ||||
|         super(bpmFormService, taskAssignRuleService); | ||||
|     } | ||||
|     @Resource | ||||
|     private BpmFormService bpmFormService; | ||||
|     @Resource | ||||
|     private BpmTaskAssignRuleService taskAssignRuleService; | ||||
|  | ||||
|     @Override | ||||
|     public PageResult<BpmModelPageItemRespVO> getModelPage(BpmModelPageReqVO pageVO) { | ||||
| @@ -167,7 +168,7 @@ public class BpmModelServiceImpl extends BpmAbstractModelService implements BpmM | ||||
|         // 校验表单已配 | ||||
|         BpmFormDO form = checkFormConfig(model.getMetaInfo()); | ||||
|         // 校验任务分配规则已配置 | ||||
|         checkTaskAssignRuleAllConfig(id); | ||||
|         taskAssignRuleService.checkTaskAssignRuleAllConfig(id); | ||||
|  | ||||
|         // 校验模型是否发生修改。如果未修改,则不允许创建 | ||||
|         BpmProcessDefinitionCreateReqDTO definitionCreateReqDTO = BpmModelConvert.INSTANCE.convert2(model, form).setBpmnBytes(bpmnBytes); | ||||
| @@ -247,4 +248,32 @@ public class BpmModelServiceImpl extends BpmAbstractModelService implements BpmM | ||||
|         return repositoryService.createModelQuery().modelKey(key).singleResult(); | ||||
|     } | ||||
|  | ||||
|     private void checkKeyNCName(String key) { | ||||
|         if (!ValidationUtils.isXmlNCName(key)) { | ||||
|             throw exception(MODEL_KEY_VALID); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 校验流程表单已配置 | ||||
|      * | ||||
|      * @param metaInfoStr 流程模型 metaInfo 字段 | ||||
|      * @return 流程表单 | ||||
|      */ | ||||
|     private BpmFormDO checkFormConfig(String  metaInfoStr) { | ||||
|         BpmModelMetaInfoRespDTO metaInfo = JsonUtils.parseObject(metaInfoStr, BpmModelMetaInfoRespDTO.class); | ||||
|         if (metaInfo == null || metaInfo.getFormType() == null) { | ||||
|             throw exception(MODEL_DEPLOY_FAIL_FORM_NOT_CONFIG); | ||||
|         } | ||||
|         // 校验表单存在 | ||||
|         if (Objects.equals(metaInfo.getFormType(), BpmModelFormTypeEnum.NORMAL.getType())) { | ||||
|             BpmFormDO form = bpmFormService.getForm(metaInfo.getFormId()); | ||||
|             if (form == null) { | ||||
|                 throw exception(FORM_NOT_EXISTS); | ||||
|             } | ||||
|             return form; | ||||
|         } | ||||
|         return null; | ||||
|     } | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -24,7 +24,55 @@ import java.util.Set; | ||||
|  * @author ZJQ | ||||
|  * @author 芋道源码 | ||||
|  */ | ||||
| public interface BpmProcessDefinitionService extends BpmProcessDefinitionCommonService { | ||||
| public interface BpmProcessDefinitionService { | ||||
|  | ||||
|     /** | ||||
|      * 获得流程定义分页 | ||||
|      * | ||||
|      * @param pageReqVO 分页入参 | ||||
|      * @return 流程定义 Page | ||||
|      */ | ||||
|     PageResult<BpmProcessDefinitionPageItemRespVO> getProcessDefinitionPage(BpmProcessDefinitionPageReqVO pageReqVO); | ||||
|  | ||||
|     /** | ||||
|      * 创建流程定义 | ||||
|      * | ||||
|      * @param createReqDTO 创建信息 | ||||
|      * @return 流程编号 | ||||
|      */ | ||||
|     String createProcessDefinition(@Valid BpmProcessDefinitionCreateReqDTO createReqDTO); | ||||
|  | ||||
|     /** | ||||
|      * 更新流程定义状态 | ||||
|      * | ||||
|      * @param id 流程定义的编号 | ||||
|      * @param state 状态 | ||||
|      */ | ||||
|     void updateProcessDefinitionState(String id, Integer state); | ||||
|  | ||||
|     /** | ||||
|      * 获得流程定义对应的 BPMN XML | ||||
|      * | ||||
|      * @param id 流程定义编号 | ||||
|      * @return BPMN XML | ||||
|      */ | ||||
|     String getProcessDefinitionBpmnXML(String id); | ||||
|  | ||||
|     /** | ||||
|      * 获得需要创建的流程定义,是否和当前激活的流程定义相等 | ||||
|      * | ||||
|      * @param createReqDTO 创建信息 | ||||
|      * @return 是否相等 | ||||
|      */ | ||||
|     boolean isProcessDefinitionEquals(@Valid BpmProcessDefinitionCreateReqDTO createReqDTO); | ||||
|  | ||||
|     /** | ||||
|      * 获得编号对应的 BpmProcessDefinitionExtDO | ||||
|      * | ||||
|      * @param id 编号 | ||||
|      * @return 流程定义拓展 | ||||
|      */ | ||||
|     BpmProcessDefinitionExtDO getProcessDefinitionExt(String id); | ||||
|  | ||||
|     /** | ||||
|      * 获得流程定义列表 | ||||
|   | ||||
| @@ -173,6 +173,21 @@ public class BpmTaskAssignRuleServiceImpl implements BpmTaskAssignRuleService { | ||||
|         taskRuleMapper.insertBatch(newRules); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void checkTaskAssignRuleAllConfig(String id) { | ||||
|         // 一个用户任务都没配置,所以无需配置规则 | ||||
|         List<BpmTaskAssignRuleRespVO> taskAssignRules = getTaskAssignRuleList(id, null); | ||||
|         if (CollUtil.isEmpty(taskAssignRules)) { | ||||
|             return; | ||||
|         } | ||||
|         // 校验未配置规则的任务 | ||||
|         taskAssignRules.forEach(rule -> { | ||||
|             if (CollUtil.isEmpty(rule.getOptions())) { | ||||
|                 throw exception(MODEL_DEPLOY_FAIL_TASK_ASSIGN_RULE_NOT_CONFIG, rule.getTaskDefinitionName()); | ||||
|             } | ||||
|         }); | ||||
|     } | ||||
|  | ||||
|     private void validTaskAssignRuleOptions(Integer type, Set<Long> options) { | ||||
|         if (Objects.equals(type, BpmTaskAssignRuleTypeEnum.ROLE.getType())) { | ||||
|             roleApi.validRoles(options); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 jason
					jason