BPM 模型重构 6:增加任务分配规则的列表 API 接口

pull/2/head
YunaiV 2022-01-12 21:16:57 +08:00
parent 95ce628cce
commit 4e7f5489a5
24 changed files with 381 additions and 143 deletions

View File

@ -0,0 +1,4 @@
### 请求 /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}}

View File

@ -0,0 +1,36 @@
package cn.iocoder.yudao.adminserver.modules.bpm.controller.definition;
import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.adminserver.modules.bpm.controller.definition.vo.rule.BpmTaskAssignRuleRespVO;
import cn.iocoder.yudao.adminserver.modules.bpm.service.definition.BpmTaskAssignRuleService;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import io.swagger.annotations.Api;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.Collections;
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")
public CommonResult<List<BpmTaskAssignRuleRespVO>> getTaskAssignRuleList(
@RequestParam(value = "modelId", required = false) String modelId,
@RequestParam(value = "processDefinitionId", required = false) String processDefinitionId) {
return success(taskAssignRuleService.getTaskAssignRules(modelId, processDefinitionId));
}
}

View File

@ -0,0 +1,14 @@
package cn.iocoder.yudao.adminserver.modules.bpm.controller.definition.vo.rule;
import lombok.Data;
import java.util.Set;
@Data
public class BpmTaskAssignRuleBaseVO {
private Integer type;
private Set<Long> options;
}

View File

@ -0,0 +1,11 @@
package cn.iocoder.yudao.adminserver.modules.bpm.controller.definition.vo.rule;
import java.util.Set;
public class BpmTaskAssignRuleCreateReqVO extends BpmTaskAssignRuleBaseVO {
private String modelId;
private String taskDefinitionKey;
}

View File

@ -0,0 +1,17 @@
package cn.iocoder.yudao.adminserver.modules.bpm.controller.definition.vo.rule;
import lombok.Data;
@Data
public class BpmTaskAssignRuleRespVO extends BpmTaskAssignRuleBaseVO {
private Long id;
private String modelId;
private String processDefinitionId;
private String taskDefinitionKey;
private String taskDefinitionName;
}

View File

@ -0,0 +1,9 @@
package cn.iocoder.yudao.adminserver.modules.bpm.controller.definition.vo.rule;
import java.util.Set;
public class BpmTaskAssignRuleUpdateReqVO extends BpmTaskAssignRuleBaseVO {
private Long id;
}

View File

@ -23,9 +23,9 @@ import java.util.Map;
* @author yunlong.li
*/
@Mapper
public interface BpmDefinitionConvert {
public interface BpmProcessDefinitionConvert {
BpmDefinitionConvert INSTANCE = Mappers.getMapper(BpmDefinitionConvert.class);
BpmProcessDefinitionConvert INSTANCE = Mappers.getMapper(BpmProcessDefinitionConvert.class);
default List<BpmProcessDefinitionPageItemRespVO> convertList(List<ProcessDefinition> list, Map<String, Deployment> deploymentMap,
Map<String, BpmProcessDefinitionExtDO> processDefinitionDOMap, Map<Long, BpmFormDO> formMap) {

View File

@ -0,0 +1,36 @@
package cn.iocoder.yudao.adminserver.modules.bpm.convert.definition;
import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.adminserver.modules.bpm.controller.definition.vo.rule.BpmTaskAssignRuleRespVO;
import cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.definition.BpmTaskAssignRuleDO;
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
import org.activiti.bpmn.model.UserTask;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
@Mapper
public interface BpmTaskAssignRuleConvert {
BpmTaskAssignRuleConvert INSTANCE = Mappers.getMapper(BpmTaskAssignRuleConvert.class);
default List<BpmTaskAssignRuleRespVO> convertList(List<UserTask> tasks, List<BpmTaskAssignRuleDO> rules) {
Map<String, BpmTaskAssignRuleDO> ruleMap = CollectionUtils.convertMap(rules, BpmTaskAssignRuleDO::getTaskDefinitionKey);
// 以 UserTask 为主维度,原因是:流程图编辑后,一些规则实际就没用了。
return CollectionUtils.convertList(tasks, task -> {
BpmTaskAssignRuleRespVO respVO = convert(ruleMap.get(task.getId()));
if (respVO == null) {
respVO = new BpmTaskAssignRuleRespVO();
respVO.setTaskDefinitionKey(task.getId());
}
respVO.setTaskDefinitionName(task.getName());
return respVO;
});
}
BpmTaskAssignRuleRespVO convert(BpmTaskAssignRuleDO bean);
}

View File

@ -1,23 +1,21 @@
package cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.definition;
import cn.iocoder.yudao.adminserver.modules.bpm.enums.definition.BpmTaskRuleScriptEnum;
import cn.iocoder.yudao.adminserver.modules.bpm.enums.definition.BpmTaskRuleTypeEnum;
import cn.iocoder.yudao.adminserver.modules.bpm.enums.definition.BpmTaskAssignRuleTypeEnum;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
import cn.iocoder.yudao.framework.mybatis.core.type.JsonLongSetTypeHandler;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
import lombok.*;
import org.activiti.engine.repository.Model;
import org.activiti.engine.repository.ProcessDefinition;
import org.activiti.engine.task.Task;
import java.util.List;
import java.util.Set;
/**
* Bpm
* Bpm
* BPMN UserTask assigneecandidateUsers 使
*
* 1. {@link #processDefinitionId} {@link #PROCESS_DEFINITION_ID_NULL}
@ -25,19 +23,19 @@ import java.util.Set;
*
* @author
*/
@TableName(value = "bpm_task_rule", autoResultMap = true)
@TableName(value = "bpm_task_assign_rule", autoResultMap = true)
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class BpmTaskRuleDO extends BaseDO {
public class BpmTaskAssignRuleDO extends BaseDO {
/**
* {@link #processDefinitionId}
*/
private static final String PROCESS_DEFINITION_ID_NULL = "";
public static final String PROCESS_DEFINITION_ID_NULL = "";
/**
*
@ -67,7 +65,7 @@ public class BpmTaskRuleDO extends BaseDO {
/**
*
*
* {@link BpmTaskRuleTypeEnum}
* {@link BpmTaskAssignRuleTypeEnum}
*/
@TableField("`type`")
private Integer type;
@ -75,12 +73,12 @@ public class BpmTaskRuleDO extends BaseDO {
*
* type
*
* 1. {@link BpmTaskRuleTypeEnum#ROLE}
* 2. {@link BpmTaskRuleTypeEnum#DEPT}
* 3. {@link BpmTaskRuleTypeEnum#DEPT_LEADER}
* 4. {@link BpmTaskRuleTypeEnum#USER}
* 5. {@link BpmTaskRuleTypeEnum#USER_GROUP}
* 6. {@link BpmTaskRuleTypeEnum#SCRIPT} {@link BpmTaskRuleScriptEnum#getId()}
* 1. {@link BpmTaskAssignRuleTypeEnum#ROLE}
* 2. {@link BpmTaskAssignRuleTypeEnum#DEPT}
* 3. {@link BpmTaskAssignRuleTypeEnum#DEPT_LEADER}
* 4. {@link BpmTaskAssignRuleTypeEnum#USER}
* 5. {@link BpmTaskAssignRuleTypeEnum#USER_GROUP}
* 6. {@link BpmTaskAssignRuleTypeEnum#SCRIPT} {@link BpmTaskRuleScriptEnum#getId()}
*/
@TableField(typeHandler = JsonLongSetTypeHandler.class)
private Set<Long> options;

View File

@ -0,0 +1,5 @@
package cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.definition;
// TODO 芋艿:先埋个坑。任务消息的配置规则。说白了,就是不同的
public class BpmTaskMessageRuleDO {
}

View File

@ -0,0 +1,27 @@
package cn.iocoder.yudao.adminserver.modules.bpm.dal.mysql.definition;
import cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.definition.BpmTaskAssignRuleDO;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.lang.Nullable;
import java.util.List;
@Mapper
public interface BpmTaskAssignRuleMapper extends BaseMapperX<BpmTaskAssignRuleDO> {
default List<BpmTaskAssignRuleDO> selectListByProcessDefinitionId(String processDefinitionId,
@Nullable String taskDefinitionKey) {
return selectList(new QueryWrapperX<BpmTaskAssignRuleDO>()
.eq("process_definition_id", processDefinitionId)
.eqIfPresent("task_definition_key", taskDefinitionKey));
}
default List<BpmTaskAssignRuleDO> selectListByModelId(String modelId) {
return selectList(new QueryWrapperX<BpmTaskAssignRuleDO>()
.eq("model_id", modelId)
.eq("process_definition_id", BpmTaskAssignRuleDO.PROCESS_DEFINITION_ID_NULL));
}
}

View File

@ -1,21 +0,0 @@
package cn.iocoder.yudao.adminserver.modules.bpm.dal.mysql.definition;
import cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.definition.BpmTaskRuleDO;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.lang.Nullable;
import java.util.List;
@Mapper
public interface BpmTaskRuleMapper extends BaseMapperX<BpmTaskRuleDO> {
default List<BpmTaskRuleDO> selectListByProcessDefinitionId(String processDefinitionId,
@Nullable String taskDefinitionKey) {
return selectList(new QueryWrapperX<BpmTaskRuleDO>()
.eq("process_definition_id", processDefinitionId)
.eqIfPresent("task_definition_key", taskDefinitionKey));
}
}

View File

@ -4,13 +4,13 @@ import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* BPM
* BPM
*
* @author
*/
@Getter
@AllArgsConstructor
public enum BpmTaskRuleTypeEnum {
public enum BpmTaskAssignRuleTypeEnum {
ROLE(10, "指定角色"),

View File

@ -2,7 +2,7 @@ package cn.iocoder.yudao.adminserver.modules.bpm.framework.activiti.config;
import cn.iocoder.yudao.adminserver.modules.bpm.framework.activiti.core.behavior.BpmActivityBehaviorFactory;
import cn.iocoder.yudao.adminserver.modules.bpm.framework.activiti.core.listener.BpmTackActivitiEventListener;
import cn.iocoder.yudao.adminserver.modules.bpm.service.definition.BpmTaskRuleService;
import cn.iocoder.yudao.adminserver.modules.bpm.service.definition.BpmTaskAssignRuleService;
import org.activiti.spring.boot.ProcessEngineConfigurationConfigurer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@ -45,7 +45,7 @@ public class BpmActivitiConfiguration {
}
@Bean
public BpmActivityBehaviorFactory bpmActivityBehaviorFactory(BpmTaskRuleService taskRuleService) {
public BpmActivityBehaviorFactory bpmActivityBehaviorFactory(BpmTaskAssignRuleService taskRuleService) {
BpmActivityBehaviorFactory bpmActivityBehaviorFactory = new BpmActivityBehaviorFactory();
bpmActivityBehaviorFactory.setBpmTaskRuleService(taskRuleService);
return bpmActivityBehaviorFactory;

View File

@ -1,7 +1,6 @@
package cn.iocoder.yudao.adminserver.modules.bpm.framework.activiti.core.behavior;
import cn.iocoder.yudao.adminserver.modules.bpm.framework.activiti.core.behavior.BpmUserTaskActivitiBehavior;
import cn.iocoder.yudao.adminserver.modules.bpm.service.definition.BpmTaskRuleService;
import cn.iocoder.yudao.adminserver.modules.bpm.service.definition.BpmTaskAssignRuleService;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.Setter;
@ -22,7 +21,7 @@ import org.activiti.engine.impl.bpmn.parser.factory.DefaultActivityBehaviorFacto
public class BpmActivityBehaviorFactory extends DefaultActivityBehaviorFactory {
@Setter
private BpmTaskRuleService bpmTaskRuleService;
private BpmTaskAssignRuleService bpmTaskRuleService;
@Override
public UserTaskActivityBehavior createUserTaskActivityBehavior(UserTask userTask) {

View File

@ -3,11 +3,10 @@ package cn.iocoder.yudao.adminserver.modules.bpm.framework.activiti.core.behavio
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.definition.BpmTaskRuleDO;
import cn.iocoder.yudao.adminserver.modules.bpm.enums.definition.BpmTaskRuleTypeEnum;
import cn.iocoder.yudao.adminserver.modules.bpm.service.definition.BpmTaskRuleService;
import cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.definition.BpmTaskAssignRuleDO;
import cn.iocoder.yudao.adminserver.modules.bpm.enums.definition.BpmTaskAssignRuleTypeEnum;
import cn.iocoder.yudao.adminserver.modules.bpm.service.definition.BpmTaskAssignRuleService;
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
import cn.iocoder.yudao.framework.common.util.collection.SetUtils;
import lombok.Setter;
import org.activiti.bpmn.model.UserTask;
import org.activiti.engine.ActivitiException;
@ -29,7 +28,7 @@ import java.util.Set;
public class BpmUserTaskActivitiBehavior extends UserTaskActivityBehavior {
@Setter
private BpmTaskRuleService bpmTaskRuleService;
private BpmTaskAssignRuleService bpmTaskRuleService;
public BpmUserTaskActivitiBehavior(UserTask userTask) {
super(userTask);
@ -40,7 +39,7 @@ public class BpmUserTaskActivitiBehavior extends UserTaskActivityBehavior {
String assignee, String owner, List<String> candidateUsers, List<String> candidateGroups,
TaskEntity task, ExpressionManager expressionManager, DelegateExecution execution) {
// 获得任务的规则
BpmTaskRuleDO rule = getTaskRule(task);
BpmTaskAssignRuleDO rule = getTaskRule(task);
// 获得任务的候选用户们
Set<Long> candidateUserIds = calculateTaskCandidateUsers(task, rule);
// 设置负责人
@ -53,8 +52,8 @@ public class BpmUserTaskActivitiBehavior extends UserTaskActivityBehavior {
}
}
private BpmTaskRuleDO getTaskRule(TaskEntity task) {
List<BpmTaskRuleDO> taskRules = bpmTaskRuleService.getTaskRulesByProcessDefinitionId(task.getProcessDefinitionId(),
private BpmTaskAssignRuleDO getTaskRule(TaskEntity task) {
List<BpmTaskAssignRuleDO> taskRules = bpmTaskRuleService.getTaskAssignRulesByProcessDefinitionId(task.getProcessDefinitionId(),
task.getTaskDefinitionKey());
if (CollUtil.isEmpty(taskRules)) {
throw new ActivitiException(StrUtil.format("流程任务({}/{}/{}) 找不到符合的任务规则",
@ -73,17 +72,17 @@ public class BpmUserTaskActivitiBehavior extends UserTaskActivityBehavior {
return CollUtil.get(candidateUserIds, index);
}
private Set<Long> calculateTaskCandidateUsers(TaskEntity task, BpmTaskRuleDO rule) {
private Set<Long> calculateTaskCandidateUsers(TaskEntity task, BpmTaskAssignRuleDO rule) {
Set<Long> assigneeUserIds = null;
if (Objects.equals(BpmTaskRuleTypeEnum.ROLE.getType(), rule.getType())) {
if (Objects.equals(BpmTaskAssignRuleTypeEnum.ROLE.getType(), rule.getType())) {
assigneeUserIds = calculateTaskCandidateUsersByRole(task, rule);
} else if (Objects.equals(BpmTaskRuleTypeEnum.DEPT.getType(), rule.getType())) {
} else if (Objects.equals(BpmTaskAssignRuleTypeEnum.DEPT.getType(), rule.getType())) {
assigneeUserIds = calculateTaskCandidateUsersByDept(task, rule);
} else if (Objects.equals(BpmTaskRuleTypeEnum.DEPT_LEADER.getType(), rule.getType())) {
} else if (Objects.equals(BpmTaskAssignRuleTypeEnum.DEPT_LEADER.getType(), rule.getType())) {
assigneeUserIds = calculateTaskCandidateUsersByDept(task, rule);
} else if (Objects.equals(BpmTaskRuleTypeEnum.USER.getType(), rule.getType())) {
} else if (Objects.equals(BpmTaskAssignRuleTypeEnum.USER.getType(), rule.getType())) {
assigneeUserIds = calculateTaskCandidateUsersByUser(task, rule);
} else if (Objects.equals(BpmTaskRuleTypeEnum.USER_GROUP.getType(), rule.getType())) {
} else if (Objects.equals(BpmTaskAssignRuleTypeEnum.USER_GROUP.getType(), rule.getType())) {
assigneeUserIds = calculateTaskCandidateUsersByUser(task, rule);
}
@ -96,28 +95,28 @@ public class BpmUserTaskActivitiBehavior extends UserTaskActivityBehavior {
return assigneeUserIds;
}
private Set<Long> calculateTaskCandidateUsersByRole(TaskEntity task, BpmTaskRuleDO rule) {
private Set<Long> calculateTaskCandidateUsersByRole(TaskEntity task, BpmTaskAssignRuleDO rule) {
throw new UnsupportedOperationException("暂不支持该任务规则");
}
private Set<Long> calculateTaskCandidateUsersByDept(TaskEntity task, BpmTaskRuleDO rule) {
private Set<Long> calculateTaskCandidateUsersByDept(TaskEntity task, BpmTaskAssignRuleDO rule) {
throw new UnsupportedOperationException("暂不支持该任务规则");
}
private Set<Long> calculateTaskCandidateUsersByDeptLeader(TaskEntity task, BpmTaskRuleDO rule) {
private Set<Long> calculateTaskCandidateUsersByDeptLeader(TaskEntity task, BpmTaskAssignRuleDO rule) {
throw new UnsupportedOperationException("暂不支持该任务规则");
}
private Set<Long> calculateTaskCandidateUsersByUser(TaskEntity task, BpmTaskRuleDO rule) {
private Set<Long> calculateTaskCandidateUsersByUser(TaskEntity task, BpmTaskAssignRuleDO rule) {
return rule.getOptions();
}
private Set<Long> calculateTaskCandidateUsersByUserGroup(TaskEntity task, BpmTaskRuleDO rule) {
private Set<Long> calculateTaskCandidateUsersByUserGroup(TaskEntity task, BpmTaskAssignRuleDO rule) {
throw new UnsupportedOperationException("暂不支持该任务规则");
}
private Set<Long> calculateTaskCandidateUsersByScript(TaskEntity task, BpmTaskRuleDO rule) {
private Set<Long> calculateTaskCandidateUsersByScript(TaskEntity task, BpmTaskAssignRuleDO rule) {
throw new UnsupportedOperationException("暂不支持该任务规则");
}

View File

@ -2,6 +2,7 @@ package cn.iocoder.yudao.adminserver.modules.bpm.service.definition;
import cn.iocoder.yudao.adminserver.modules.bpm.controller.definition.vo.model.*;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import org.activiti.bpmn.model.BpmnModel;
import javax.validation.Valid;
@ -66,4 +67,12 @@ public interface BpmModelService {
*/
void updateModelState(String id, Integer state);
/**
* BPMN Model
*
* @param id
* @return BPMN Model
*/
BpmnModel getBpmnModel(String id);
}

View File

@ -0,0 +1,47 @@
package cn.iocoder.yudao.adminserver.modules.bpm.service.definition;
import cn.iocoder.yudao.adminserver.modules.bpm.controller.definition.vo.rule.BpmTaskAssignRuleRespVO;
import cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.definition.BpmTaskAssignRuleDO;
import org.springframework.lang.Nullable;
import java.util.List;
/**
* BPM Service
*
* @author
*/
public interface BpmTaskAssignRuleService {
/**
*
*
* @param processDefinitionId
* @param taskDefinitionKey Key
* @return
*/
List<BpmTaskAssignRuleDO> getTaskAssignRulesByProcessDefinitionId(String processDefinitionId,
@Nullable String taskDefinitionKey);
/**
*
*
* @param modelId
* @return
*/
List<BpmTaskAssignRuleDO> getTaskAssignRulesByModelId(String modelId);
/**
*
*
* @param processDefinitionId
* @param processDefinitionId
* @return
*/
List<BpmTaskAssignRuleRespVO> getTaskAssignRules(String modelId, String processDefinitionId);
// TODO 芋艿:创建任务规则
// TODO 芋艿:复制任务规则
}

View File

@ -1,36 +0,0 @@
package cn.iocoder.yudao.adminserver.modules.bpm.service.definition;
import cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.definition.BpmTaskRuleDO;
import org.springframework.lang.Nullable;
import java.util.List;
/**
* BPM Service
*
* @author
*/
public interface BpmTaskRuleService {
/**
*
*
* @param processDefinitionId
* @param taskDefinitionKey Key
* @return
*/
List<BpmTaskRuleDO> getTaskRulesByProcessDefinitionId(String processDefinitionId,
@Nullable String taskDefinitionKey);
/**
*
*
* @param modelId
* @return
*/
List<BpmTaskRuleDO> getTaskRulesByModelId(Long modelId);
// TODO 芋艿:创建任务规则
// TODO 芋艿:复制任务规则
}

View File

@ -1,5 +1,6 @@
package cn.iocoder.yudao.adminserver.modules.bpm.service.definition.impl;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.adminserver.modules.bpm.controller.definition.vo.model.*;
import cn.iocoder.yudao.adminserver.modules.bpm.convert.definition.BpmModelConvert;
@ -9,6 +10,7 @@ import cn.iocoder.yudao.adminserver.modules.bpm.service.definition.dto.BpmDefini
import cn.iocoder.yudao.adminserver.modules.bpm.service.definition.BpmFormService;
import cn.iocoder.yudao.adminserver.modules.bpm.service.definition.BpmModelService;
import cn.iocoder.yudao.adminserver.modules.bpm.service.definition.dto.BpmModelMetaInfoRespDTO;
import cn.iocoder.yudao.framework.activiti.core.util.ActivitiUtils;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
@ -210,6 +212,15 @@ public class BpmModelServiceImpl implements BpmModelService {
bpmProcessDefinitionService.updateProcessDefinitionState(definition.getId(), state);
}
@Override
public BpmnModel getBpmnModel(String id) {
byte[] bpmnBytes = repositoryService.getModelEditorSource(id);
if (ArrayUtil.isEmpty(bpmnBytes)) {
return null;
}
return ActivitiUtils.buildBpmnModel(bpmnBytes);
}
private Model getModelByKey(String key) {
return repositoryService.createModelQuery().modelKey(key).singleResult();
}

View File

@ -6,7 +6,7 @@ import cn.iocoder.yudao.adminserver.modules.bpm.controller.definition.vo.process
import cn.iocoder.yudao.adminserver.modules.bpm.controller.definition.vo.process.BpmProcessDefinitionPageItemRespVO;
import cn.iocoder.yudao.adminserver.modules.bpm.controller.definition.vo.process.BpmProcessDefinitionPageReqVO;
import cn.iocoder.yudao.adminserver.modules.bpm.controller.definition.vo.process.BpmProcessDefinitionRespVO;
import cn.iocoder.yudao.adminserver.modules.bpm.convert.definition.BpmDefinitionConvert;
import cn.iocoder.yudao.adminserver.modules.bpm.convert.definition.BpmProcessDefinitionConvert;
import cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.definition.BpmProcessDefinitionExtDO;
import cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.definition.BpmFormDO;
import cn.iocoder.yudao.adminserver.modules.bpm.dal.mysql.definition.BpmProcessDefinitionExtMapper;
@ -90,7 +90,7 @@ public class BpmProcessDefinitionServiceImpl implements BpmProcessDefinitionServ
// 拼接结果
long definitionCount = definitionQuery.count();
return new PageResult<>(BpmDefinitionConvert.INSTANCE.convertList(processDefinitions, deploymentMap,
return new PageResult<>(BpmProcessDefinitionConvert.INSTANCE.convertList(processDefinitions, deploymentMap,
processDefinitionDOMap, formMap), definitionCount);
}
@ -112,7 +112,7 @@ public class BpmProcessDefinitionServiceImpl implements BpmProcessDefinitionServ
Map<String, BpmProcessDefinitionExtDO> processDefinitionDOMap = CollectionUtils.convertMap(processDefinitionDOs,
BpmProcessDefinitionExtDO::getProcessDefinitionId);
// 执行查询,并返回
return BpmDefinitionConvert.INSTANCE.convertList3(processDefinitions, processDefinitionDOMap);
return BpmProcessDefinitionConvert.INSTANCE.convertList3(processDefinitions, processDefinitionDOMap);
}
@Override
@ -196,7 +196,7 @@ public class BpmProcessDefinitionServiceImpl implements BpmProcessDefinitionServ
}
// 插入拓展表
BpmProcessDefinitionExtDO definitionDO = BpmDefinitionConvert.INSTANCE.convert2(createReqDTO)
BpmProcessDefinitionExtDO definitionDO = BpmProcessDefinitionConvert.INSTANCE.convert2(createReqDTO)
.setProcessDefinitionId(definition.getId());
processDefinitionMapper.insert(definitionDO);
return definition.getId();

View File

@ -0,0 +1,79 @@
package cn.iocoder.yudao.adminserver.modules.bpm.service.definition.impl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.adminserver.modules.bpm.controller.definition.vo.rule.BpmTaskAssignRuleRespVO;
import cn.iocoder.yudao.adminserver.modules.bpm.convert.definition.BpmTaskAssignRuleConvert;
import cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.definition.BpmTaskAssignRuleDO;
import cn.iocoder.yudao.adminserver.modules.bpm.dal.mysql.definition.BpmTaskAssignRuleMapper;
import cn.iocoder.yudao.adminserver.modules.bpm.service.definition.BpmModelService;
import cn.iocoder.yudao.adminserver.modules.bpm.service.definition.BpmProcessDefinitionService;
import cn.iocoder.yudao.adminserver.modules.bpm.service.definition.BpmTaskAssignRuleService;
import cn.iocoder.yudao.framework.activiti.core.util.ActivitiUtils;
import lombok.extern.slf4j.Slf4j;
import org.activiti.bpmn.model.BpmnModel;
import org.activiti.bpmn.model.UserTask;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;
/**
* BPM Service
*/
@Service
@Validated
@Slf4j
public class BpmTaskAssignRuleServiceImpl implements BpmTaskAssignRuleService {
@Resource
private BpmTaskAssignRuleMapper taskRuleMapper;
@Resource
@Lazy // 解决循环依赖
private BpmModelService modelService;
@Resource
@Lazy // 解决循环依赖
private BpmProcessDefinitionService processDefinitionService;
@Override
public List<BpmTaskAssignRuleDO> getTaskAssignRulesByProcessDefinitionId(String processDefinitionId,
String taskDefinitionKey) {
return taskRuleMapper.selectListByProcessDefinitionId(processDefinitionId, taskDefinitionKey);
}
@Override
public List<BpmTaskAssignRuleDO> getTaskAssignRulesByModelId(String modelId) {
return taskRuleMapper.selectListByModelId(modelId);
}
@Override
public List<BpmTaskAssignRuleRespVO> getTaskAssignRules(String modelId, String processDefinitionId) {
// 获得规则
List<BpmTaskAssignRuleDO> rules = Collections.emptyList();
BpmnModel model = null;
if (StrUtil.isNotEmpty(modelId)) {
rules = getTaskAssignRulesByModelId(modelId);
model = modelService.getBpmnModel(modelId);
} else if (StrUtil.isNotEmpty(processDefinitionId)) {
rules = getTaskAssignRulesByProcessDefinitionId(processDefinitionId, null);
model = processDefinitionService.getBpmnModel(processDefinitionId);
}
if (CollUtil.isEmpty(rules) || model == null) {
return Collections.emptyList();
}
// 获得用户任务,只有用户任务才可以设置分配规则
List<UserTask> userTasks = ActivitiUtils.getBpmnModelElements(model, UserTask.class);
if (CollUtil.isEmpty(userTasks)) {
return Collections.emptyList();
}
// 转换数据
return BpmTaskAssignRuleConvert.INSTANCE.convertList(userTasks, rules);
}
}

View File

@ -1,35 +0,0 @@
package cn.iocoder.yudao.adminserver.modules.bpm.service.definition.impl;
import cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.definition.BpmTaskRuleDO;
import cn.iocoder.yudao.adminserver.modules.bpm.dal.mysql.definition.BpmTaskRuleMapper;
import cn.iocoder.yudao.adminserver.modules.bpm.service.definition.BpmTaskRuleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
import java.util.List;
/**
* BPM Service
*/
@Service
@Validated
@Slf4j
public class BpmTaskRuleServiceImpl implements BpmTaskRuleService {
@Resource
private BpmTaskRuleMapper taskRuleMapper;
@Override
public List<BpmTaskRuleDO> getTaskRulesByProcessDefinitionId(String processDefinitionId,
String taskDefinitionKey) {
return taskRuleMapper.selectListByProcessDefinitionId(processDefinitionId, taskDefinitionKey);
}
@Override
public List<BpmTaskRuleDO> getTaskRulesByModelId(Long modelId) {
return null;
}
}

View File

@ -4,11 +4,15 @@ import cn.hutool.core.util.ReflectUtil;
import com.alibaba.ttl.TransmittableThreadLocal;
import org.activiti.bpmn.converter.BpmnXMLConverter;
import org.activiti.bpmn.model.BpmnModel;
import org.activiti.engine.history.HistoricProcessInstance;
import org.activiti.bpmn.model.FlowElement;
import org.activiti.bpmn.model.Process;
import org.activiti.engine.impl.identity.Authentication;
import org.activiti.engine.impl.persistence.entity.HistoricProcessInstanceEntityImpl;
import org.activiti.engine.impl.persistence.entity.HistoricScopeInstanceEntityImpl;
import org.activiti.engine.impl.util.io.StringStreamSource;
import org.activiti.engine.impl.util.io.BytesStreamSource;
import javax.xml.bind.Element;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;
/**
* Activiti
@ -42,4 +46,29 @@ public class ActivitiUtils {
// ========== BPMN XML 相关 ==========
/**
* BPMN Model
*
* @param bpmnBytes BPMN XML
* @return BPMN Model
*/
public static BpmnModel buildBpmnModel(byte[] bpmnBytes) {
// 转换成 BpmnModel 对象
BpmnXMLConverter converter = new BpmnXMLConverter();
return converter.convertToBpmnModel(new BytesStreamSource(bpmnBytes), true, true);
}
public static <T extends FlowElement> List<T> getBpmnModelElements(BpmnModel model, Class<T> clazz) {
List<T> result = new ArrayList<>();
model.getProcesses().forEach(process -> {
process.getFlowElements().forEach(flowElement -> {
if (flowElement.getClass().isAssignableFrom(clazz)) {
result.add((T) flowElement);
}
});
});
return result;
}
}