|
@@ -1,16 +1,21 @@
|
|
package cn.iocoder.yudao.module.bpm.service.definition;
|
|
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.ArrayUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
|
import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
|
|
import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
|
|
|
|
+import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
|
import cn.iocoder.yudao.framework.common.util.object.PageUtils;
|
|
import cn.iocoder.yudao.framework.common.util.object.PageUtils;
|
|
import cn.iocoder.yudao.framework.common.util.validation.ValidationUtils;
|
|
import cn.iocoder.yudao.framework.common.util.validation.ValidationUtils;
|
|
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.BpmModelCreateReqVO;
|
|
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.BpmModelCreateReqVO;
|
|
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.BpmModelPageReqVO;
|
|
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.BpmModelPageReqVO;
|
|
|
|
+import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.BpmModelRespVO;
|
|
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.BpmModelUpdateReqVO;
|
|
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.BpmModelUpdateReqVO;
|
|
|
|
+import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.rule.BpmTaskAssignRuleCreateReqVO;
|
|
import cn.iocoder.yudao.module.bpm.convert.definition.BpmModelConvert;
|
|
import cn.iocoder.yudao.module.bpm.convert.definition.BpmModelConvert;
|
|
import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmFormDO;
|
|
import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmFormDO;
|
|
|
|
+import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmTaskAssignRuleDO;
|
|
import cn.iocoder.yudao.module.bpm.enums.definition.BpmModelFormTypeEnum;
|
|
import cn.iocoder.yudao.module.bpm.enums.definition.BpmModelFormTypeEnum;
|
|
import cn.iocoder.yudao.module.bpm.framework.flowable.core.candidate.BpmTaskCandidateInvoker;
|
|
import cn.iocoder.yudao.module.bpm.framework.flowable.core.candidate.BpmTaskCandidateInvoker;
|
|
import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.BpmnModelUtils;
|
|
import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.BpmnModelUtils;
|
|
@@ -36,7 +41,10 @@ import org.springframework.validation.annotation.Validated;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
import javax.validation.Valid;
|
|
import javax.validation.Valid;
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.LinkedHashMap;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
+import java.util.Map;
|
|
import java.util.Objects;
|
|
import java.util.Objects;
|
|
|
|
|
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
|
@@ -80,6 +88,7 @@ public class BpmModelServiceImpl implements BpmModelService {
|
|
if (StrUtil.isNotBlank(pageVO.getCategory())) {
|
|
if (StrUtil.isNotBlank(pageVO.getCategory())) {
|
|
modelQuery.modelCategory(pageVO.getCategory());
|
|
modelQuery.modelCategory(pageVO.getCategory());
|
|
}
|
|
}
|
|
|
|
+ modelQuery.modelTenantId(FlowableUtils.getTenantId());
|
|
// 执行查询
|
|
// 执行查询
|
|
long count = modelQuery.count();
|
|
long count = modelQuery.count();
|
|
if (count == 0) {
|
|
if (count == 0) {
|
|
@@ -92,6 +101,155 @@ public class BpmModelServiceImpl implements BpmModelService {
|
|
return new PageResult<>(models, count);
|
|
return new PageResult<>(models, count);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
+ public Map<String, String> copyAndDeploy(String modelKey, String modelTenantId) {
|
|
|
|
+
|
|
|
|
+ Map<String, String> resultMap = new LinkedHashMap<>();
|
|
|
|
+ // 复制部署模型结果说明
|
|
|
|
+ // StringBuilder resultBuilder = new StringBuilder();
|
|
|
|
+
|
|
|
|
+ // 模型key列表:共12个
|
|
|
|
+ List<String> modelKeyList = new ArrayList<>();
|
|
|
|
+ modelKeyList.add("oa_universal");
|
|
|
|
+ modelKeyList.add("oa_entry");
|
|
|
|
+ modelKeyList.add("oa_conversion");
|
|
|
|
+ modelKeyList.add("oa_renew");
|
|
|
|
+ modelKeyList.add("oa_turnover");
|
|
|
|
+ modelKeyList.add("oa_leave");
|
|
|
|
+ modelKeyList.add("oa_business");
|
|
|
|
+ modelKeyList.add("oa_out");
|
|
|
|
+ modelKeyList.add("oa_receive");
|
|
|
|
+ modelKeyList.add("oa_purchase");
|
|
|
|
+ modelKeyList.add("oa_expense");
|
|
|
|
+ modelKeyList.add("oa_stamp");
|
|
|
|
+
|
|
|
|
+ // 默认租户:1
|
|
|
|
+ if (StrUtil.isBlank(modelTenantId)) {
|
|
|
|
+ modelTenantId = "1";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 指定了模型key,只部署指定的模型,否则部署定义好的所有模型
|
|
|
|
+ if (StrUtil.isNotBlank(modelKey)) {
|
|
|
|
+ if (modelKeyList.contains(modelKey)) {
|
|
|
|
+ List<Model> nowList = repositoryService.createModelQuery()
|
|
|
|
+ .modelKey(modelKey)
|
|
|
|
+ .modelTenantId(FlowableUtils.getTenantId())
|
|
|
|
+ .list();
|
|
|
|
+ if (CollUtil.isNotEmpty(nowList)) {
|
|
|
|
+ resultMap.put(modelKey + ":" + FlowableUtils.getTenantId(), "模型已存在");
|
|
|
|
+ // resultBuilder.append(modelKey).append(":").append(FlowableUtils.getTenantId()).append("的模型已存在");
|
|
|
|
+ return resultMap;
|
|
|
|
+ }
|
|
|
|
+ List<Model> list = repositoryService.createModelQuery()
|
|
|
|
+ .modelKey(modelKey)
|
|
|
|
+ .modelTenantId(modelTenantId)
|
|
|
|
+ .list();
|
|
|
|
+ // 同一个租户,同一个key,应该只有一条模型记录
|
|
|
|
+ if (CollUtil.isNotEmpty(list) && list.size() == 1) {
|
|
|
|
+ // 模型源
|
|
|
|
+ Model model = list.get(0);
|
|
|
|
+
|
|
|
|
+ // 新模型
|
|
|
|
+ Model newModel = repositoryService.newModel();
|
|
|
|
+ newModel.setName(model.getName());
|
|
|
|
+ newModel.setKey(model.getKey());
|
|
|
|
+ newModel.setVersion(1);
|
|
|
|
+ newModel.setMetaInfo(model.getMetaInfo());
|
|
|
|
+ newModel.setTenantId(FlowableUtils.getTenantId());
|
|
|
|
+
|
|
|
|
+ byte[] bpmnBytes = this.getModelBpmnXML(model.getId());
|
|
|
|
+ BpmModelRespVO bpmModelRespVO = BpmModelConvert.INSTANCE.buildModel(model, bpmnBytes);
|
|
|
|
+ BpmModelUpdateReqVO updateReqVO = BeanUtils.toBean(bpmModelRespVO, BpmModelUpdateReqVO.class);
|
|
|
|
+ // 修改流程定义
|
|
|
|
+ BpmModelConvert.INSTANCE.copyToUpdateModel(newModel, updateReqVO);
|
|
|
|
+ // 添加模型
|
|
|
|
+ repositoryService.saveModel(newModel);
|
|
|
|
+ // 添加 BPMN XML
|
|
|
|
+ repositoryService.addModelEditorSource(newModel.getId(), StrUtil.utf8Bytes(updateReqVO.getBpmnXml()));
|
|
|
|
+
|
|
|
|
+ // 添加分配规则
|
|
|
|
+ List<BpmTaskAssignRuleDO> taskAssignRuleListByModelId = taskAssignRuleService.getTaskAssignRuleListByModelId2(model.getId());
|
|
|
|
+ for (BpmTaskAssignRuleDO bpmTaskAssignRuleDO : taskAssignRuleListByModelId) {
|
|
|
|
+ bpmTaskAssignRuleDO.setModelId(newModel.getId());
|
|
|
|
+ BpmTaskAssignRuleCreateReqVO bpmTaskAssignRuleCreateReqVO = BeanUtils.toBean(bpmTaskAssignRuleDO, BpmTaskAssignRuleCreateReqVO.class);
|
|
|
|
+ taskAssignRuleService.createTaskAssignRule(bpmTaskAssignRuleCreateReqVO);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 部署流程
|
|
|
|
+ this.deployModel(newModel.getId());
|
|
|
|
+
|
|
|
|
+ resultMap.put(modelKey + ":" + FlowableUtils.getTenantId(), "模型复制部署成功");
|
|
|
|
+ // resultBuilder.append(modelKey).append(":").append(FlowableUtils.getTenantId()).append(" 模型复制部署成功;").append(System.lineSeparator());
|
|
|
|
+ } else {
|
|
|
|
+ resultMap.put(modelKey + ":" + FlowableUtils.getTenantId(), "源模型不存在或数量大于1个,请查看原因");
|
|
|
|
+ // resultBuilder.append(modelKey).append(":").append(FlowableUtils.getTenantId()).append(" 源模型数量大于1个,请查看原因").append(System.lineSeparator());
|
|
|
|
+ return resultMap;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ for (int i = 0; i < modelKeyList.size(); i++) {
|
|
|
|
+ modelKey = modelKeyList.get(i);
|
|
|
|
+
|
|
|
|
+ List<Model> nowList = repositoryService.createModelQuery()
|
|
|
|
+ .modelKey(modelKey)
|
|
|
|
+ .modelTenantId(FlowableUtils.getTenantId())
|
|
|
|
+ .list();
|
|
|
|
+ if (CollUtil.isNotEmpty(nowList)) {
|
|
|
|
+ resultMap.put(modelKey + ":" + FlowableUtils.getTenantId(), "模型已存在");
|
|
|
|
+ // resultBuilder.append(modelKey).append(":").append(FlowableUtils.getTenantId()).append("的模型已存在").append(System.lineSeparator());
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ List<Model> list = repositoryService.createModelQuery()
|
|
|
|
+ .modelKey(modelKey)
|
|
|
|
+ .modelTenantId(modelTenantId)
|
|
|
|
+ .list();
|
|
|
|
+ // 同一个租户,同一个key,应该只有一条模型记录
|
|
|
|
+ if (CollUtil.isNotEmpty(list) && list.size() == 1) {
|
|
|
|
+ // 模型源
|
|
|
|
+ Model model = list.get(0);
|
|
|
|
+
|
|
|
|
+ // 新模型
|
|
|
|
+ Model newModel = repositoryService.newModel();
|
|
|
|
+ newModel.setName(model.getName());
|
|
|
|
+ newModel.setKey(model.getKey());
|
|
|
|
+ newModel.setVersion(1);
|
|
|
|
+ newModel.setMetaInfo(model.getMetaInfo());
|
|
|
|
+ newModel.setTenantId(FlowableUtils.getTenantId());
|
|
|
|
+
|
|
|
|
+ byte[] bpmnBytes = this.getModelBpmnXML(model.getId());
|
|
|
|
+ BpmModelRespVO bpmModelRespVO = BpmModelConvert.INSTANCE.buildModel(model, bpmnBytes);
|
|
|
|
+ BpmModelUpdateReqVO updateReqVO = BeanUtils.toBean(bpmModelRespVO, BpmModelUpdateReqVO.class);
|
|
|
|
+ // 修改流程定义
|
|
|
|
+ BpmModelConvert.INSTANCE.copyToUpdateModel(newModel, updateReqVO);
|
|
|
|
+ // 添加模型
|
|
|
|
+ repositoryService.saveModel(newModel);
|
|
|
|
+ // 添加 BPMN XML
|
|
|
|
+ repositoryService.addModelEditorSource(newModel.getId(), StrUtil.utf8Bytes(updateReqVO.getBpmnXml()));
|
|
|
|
+
|
|
|
|
+ // 添加分配规则
|
|
|
|
+ List<BpmTaskAssignRuleDO> taskAssignRuleListByModelId = taskAssignRuleService.getTaskAssignRuleListByModelId2(model.getId());
|
|
|
|
+ for (BpmTaskAssignRuleDO bpmTaskAssignRuleDO : taskAssignRuleListByModelId) {
|
|
|
|
+ bpmTaskAssignRuleDO.setModelId(newModel.getId());
|
|
|
|
+ BpmTaskAssignRuleCreateReqVO bpmTaskAssignRuleCreateReqVO = BeanUtils.toBean(bpmTaskAssignRuleDO, BpmTaskAssignRuleCreateReqVO.class);
|
|
|
|
+ taskAssignRuleService.createTaskAssignRule(bpmTaskAssignRuleCreateReqVO);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 部署流程
|
|
|
|
+ this.deployModel(newModel.getId());
|
|
|
|
+
|
|
|
|
+ resultMap.put(modelKey + ":" + FlowableUtils.getTenantId(), "模型复制部署成功");
|
|
|
|
+ // resultBuilder.append(modelKey).append(":").append(FlowableUtils.getTenantId()).append(" 模型复制部署成功;").append(System.lineSeparator());
|
|
|
|
+ } else {
|
|
|
|
+ resultMap.put(modelKey + ":" + FlowableUtils.getTenantId(), "源模型不存在或数量大于1个,请查看原因");
|
|
|
|
+ // resultBuilder.append(modelKey).append(":").append(FlowableUtils.getTenantId()).append(" 源模型数量大于1个,请查看原因;").append(System.lineSeparator());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return resultMap;
|
|
|
|
+ }
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Transactional(rollbackFor = Exception.class)
|
|
public String createModel(@Valid BpmModelCreateReqVO createReqVO, String bpmnXml) {
|
|
public String createModel(@Valid BpmModelCreateReqVO createReqVO, String bpmnXml) {
|