diff --git a/sql/ruoyi-vue-pro.sql b/sql/ruoyi-vue-pro.sql index 1eb8ad09f..90cfbec7d 100644 --- a/sql/ruoyi-vue-pro.sql +++ b/sql/ruoyi-vue-pro.sql @@ -2391,4 +2391,18 @@ INSERT INTO `tool_test_demo` VALUES (106, '老五1', 0, 1, 1, '牛逼哈2', '', INSERT INTO `tool_test_demo` VALUES (107, '哈哈哈哈', 1, 0, 1, 'biubiubui', '', '2021-02-06 14:00:54', '', '2021-02-06 14:00:54', b'0'); COMMIT; +CREATE TABLE `bpm_process_definition` ( + `id` bigint NOT NULL AUTO_INCREMENT COMMENT '编号', + `process_definition_id` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '流程定义的编号', + `description` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '描述', + `form_id` bigint DEFAULT NULL COMMENT '表单编号', + `creator` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT '' COMMENT '创建者', + `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `updater` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT '' COMMENT '更新者', + `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', + `deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除', + PRIMARY KEY (`id`) USING BTREE +) ENGINE=InnoDB AUTO_INCREMENT=13 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='Bpm 流程定义的拓展表\n'; + SET FOREIGN_KEY_CHECKS = 1; + diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/model/BpmModelController.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/model/BpmModelController.java index 5a2d4e17e..3b4f177e9 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/model/BpmModelController.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/model/BpmModelController.java @@ -25,10 +25,10 @@ public class BpmModelController { // TODO @芋艿:权限 - @GetMapping ("/page") + @GetMapping("/page") @ApiOperation(value = "获得模型分页") public CommonResult> getModelPage(ModelPageReqVO pageVO) { - return success(bpmModelService.getModelPage(pageVO)); + return success(bpmModelService.getModelPage(pageVO)); } @GetMapping("/get") @@ -43,7 +43,7 @@ public class BpmModelController { @PostMapping("/create") @ApiOperation(value = "新建模型") public CommonResult createModel(@RequestBody BpmModelCreateReqVO createRetVO) { - return success(bpmModelService.createModel(createRetVO)); + return success(bpmModelService.createModel(createRetVO)); } @PutMapping("/update") @@ -56,15 +56,17 @@ public class BpmModelController { @DeleteMapping("/delete") @ApiOperation("删除模型") @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = String.class) - public CommonResult deleteModel(@RequestParam("id") String id) { + public CommonResult deleteModel(@RequestParam("id") String id) { bpmModelService.deleteModel(id); return success(true); } @PostMapping("/deploy") @ApiOperation(value = "部署模型") - public CommonResult deploy(@RequestParam String modelId) { - return bpmModelService.deploy(modelId); + @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = String.class) + public CommonResult deployModel(@RequestParam("id") String id) { + bpmModelService.deployModel(id); + return success(true); } } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/model/vo/BpmModelBaseVO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/model/vo/BpmModelBaseVO.java index 9ab133b43..b3f78c4da 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/model/vo/BpmModelBaseVO.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/model/vo/BpmModelBaseVO.java @@ -4,7 +4,6 @@ import io.swagger.annotations.ApiModelProperty; import lombok.Data; import javax.validation.constraints.NotEmpty; -import javax.validation.constraints.NotNull; /** * 流程模型 Base VO,提供给添加、修改、详细的子 VO 使用 @@ -22,7 +21,6 @@ public class BpmModelBaseVO { private String name; @ApiModelProperty(value = "流程描述", example = "我是描述") - @NotEmpty(message = "流程描述不能为空") private String description; @ApiModelProperty(value = "流程分类", notes = "参见 bpm_model_category 数据字典", example = "1") @@ -30,7 +28,6 @@ public class BpmModelBaseVO { private String category; @ApiModelProperty(value = "表单编号", example = "1024") - @NotNull(message = "表单编号不能为空") private Long formId; } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/workflow/TaskController.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/workflow/TaskController.java index 2492bccf6..32260bd56 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/workflow/TaskController.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/workflow/TaskController.java @@ -1,7 +1,7 @@ package cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow; import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.*; -import cn.iocoder.yudao.adminserver.modules.bpm.service.workflow.BpmTaskService; +import cn.iocoder.yudao.adminserver.modules.bpm.service.task.BpmTaskService; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.servlet.ServletUtils; diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/convert/model/ModelConvert.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/convert/model/ModelConvert.java index 22dc62873..6495f8019 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/convert/model/ModelConvert.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/convert/model/ModelConvert.java @@ -5,6 +5,7 @@ import cn.iocoder.yudao.adminserver.modules.bpm.controller.model.vo.BpmModelPage import cn.iocoder.yudao.adminserver.modules.bpm.controller.model.vo.BpmModelRespVO; import cn.iocoder.yudao.adminserver.modules.bpm.controller.model.vo.BpmModelUpdateReqVO; import cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.form.BpmFormDO; +import cn.iocoder.yudao.adminserver.modules.bpm.service.definition.dto.BpmDefinitionCreateReqDTO; import cn.iocoder.yudao.adminserver.modules.bpm.service.model.dto.BpmModelMetaInfoRespDTO; import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.framework.common.util.json.JsonUtils; @@ -58,6 +59,19 @@ public interface ModelConvert { BpmModelRespVO convert(Model model); + default BpmDefinitionCreateReqDTO convert2(Model model) { + BpmDefinitionCreateReqDTO createReqDTO = new BpmDefinitionCreateReqDTO(); + createReqDTO.setName(model.getName()); + createReqDTO.setKey(model.getKey()); + createReqDTO.setCategory(model.getCategory()); + BpmModelMetaInfoRespDTO metaInfo = JsonUtils.parseObject(model.getMetaInfo(), BpmModelMetaInfoRespDTO.class); + if (metaInfo != null) { + createReqDTO.setDescription(metaInfo.getDescription()); + createReqDTO.setFormId(metaInfo.getFormId()); + } + return createReqDTO; + } + default void copy(Model model, BpmModelCreateReqVO bean) { model.setName(bean.getName()); model.setKey(bean.getKey()); diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/convert/workflow/ProcessDefinitionConvert.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/convert/workflow/BpmDefinitionConvert.java similarity index 50% rename from yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/convert/workflow/ProcessDefinitionConvert.java rename to yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/convert/workflow/BpmDefinitionConvert.java index e2a48c693..c3d22ad0b 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/convert/workflow/ProcessDefinitionConvert.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/convert/workflow/BpmDefinitionConvert.java @@ -1,17 +1,24 @@ package cn.iocoder.yudao.adminserver.modules.bpm.convert.workflow; import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.processdefinition.ProcessDefinitionRespVO; +import cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.definition.BpmProcessDefinitionDO; +import cn.iocoder.yudao.adminserver.modules.bpm.service.definition.dto.BpmDefinitionCreateReqDTO; import org.activiti.engine.repository.ProcessDefinition; import org.mapstruct.Mapper; import org.mapstruct.factory.Mappers; /** + * Bpm 流程定义的 Convert + * * @author yunlong.li */ @Mapper -public interface ProcessDefinitionConvert { - ProcessDefinitionConvert INSTANCE = Mappers.getMapper(ProcessDefinitionConvert.class); +public interface BpmDefinitionConvert { + + BpmDefinitionConvert INSTANCE = Mappers.getMapper(BpmDefinitionConvert.class); ProcessDefinitionRespVO convert(ProcessDefinition processDefinition); + BpmProcessDefinitionDO convert(BpmDefinitionCreateReqDTO bean); + } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/dataobject/definition/BpmProcessDefinitionDO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/dataobject/definition/BpmProcessDefinitionDO.java new file mode 100644 index 000000000..fda5c4b1a --- /dev/null +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/dataobject/definition/BpmProcessDefinitionDO.java @@ -0,0 +1,47 @@ +package cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.definition; + +import cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.form.BpmFormDO; +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.*; +import org.activiti.engine.repository.ProcessDefinition; + +/** + * Bpm 流程定义的拓展表 + * 主要解决 主要进行 Activiti {@link ProcessDefinition} 不支持拓展字段,所以新建拓展表 + * + * @author 芋道源码 + */ +@TableName(value = "bpm_process_definition", autoResultMap = true) +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class BpmProcessDefinitionDO extends BaseDO { + + /** + * 编号 + */ + @TableId + private Long id; + /** + * 流程定义的编号 + * + * 关联 {@link ProcessDefinition#getId()} + */ + private String processDefinitionId; + /** + * 描述 + */ + private String description; + /** + * 表单编号 + * + * 关联 {@link BpmFormDO#getId()} + */ + private Long formId; + +} diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/dataobject/process/ProcessDefinitionDO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/dataobject/process/ProcessDefinitionDO.java deleted file mode 100644 index d023c91f4..000000000 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/dataobject/process/ProcessDefinitionDO.java +++ /dev/null @@ -1,29 +0,0 @@ -package cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.process; - -/** - * 流程模型实体类 映射 activiti ProcessDefinition接口 - * - * @author ZJQ - * @date 2021/9/7 23:23 - */ -public class ProcessDefinitionDO { - - private String id; - - private String category; - - private String key; - - private String name; - - private String version; - - private String resourceName; - - private String deploymentId; - - private String diagramResourceName; - - private boolean suspended; - -} diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/dataobject/process/package-info.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/dataobject/process/package-info.java deleted file mode 100644 index 0410bc3ca..000000000 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/dataobject/process/package-info.java +++ /dev/null @@ -1,4 +0,0 @@ -/** - * TODO 芋艿:工作流的定义 - */ -package cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.process; diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/mysql/definition/BpmProcessDefinitionMapper.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/mysql/definition/BpmProcessDefinitionMapper.java new file mode 100644 index 000000000..d3f517c17 --- /dev/null +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/mysql/definition/BpmProcessDefinitionMapper.java @@ -0,0 +1,9 @@ +package cn.iocoder.yudao.adminserver.modules.bpm.dal.mysql.definition; + +import cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.definition.BpmProcessDefinitionDO; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface BpmProcessDefinitionMapper extends BaseMapper { +} diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/BpmDefinitionService.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/BpmDefinitionService.java index 3d3417056..4d902a586 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/BpmDefinitionService.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/BpmDefinitionService.java @@ -3,9 +3,11 @@ package cn.iocoder.yudao.adminserver.modules.bpm.service.definition; import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.FileResp; import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.processdefinition.ProcessDefinitionPageReqVo; import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.processdefinition.ProcessDefinitionRespVO; +import cn.iocoder.yudao.adminserver.modules.bpm.service.definition.dto.BpmDefinitionCreateReqDTO; import cn.iocoder.yudao.framework.common.pojo.PageResult; import org.activiti.engine.repository.ProcessDefinition; +import javax.validation.Valid; import java.util.List; import java.util.Set; @@ -30,12 +32,28 @@ public interface BpmDefinitionService { */ FileResp export(String processDefinitionId); + /** + * 获得编号对应的 ProcessDefinition + * + * @param id 编号 + * @return 流程定义 + */ + ProcessDefinition getDefinition(String id); + /** * 获得 deploymentId 对应的 ProcessDefinition 数组 * * @param deploymentId 部署编号 * @return 流程定义的数组 */ - List getProcessDefinitionListByDeploymentIds(Set deploymentId); + List getDefinitionListByDeploymentIds(Set deploymentId); + + /** + * 创建流程定义 + * + * @param createReqDTO 创建信息 + * @return 流程编号 + */ + String createDefinition(@Valid BpmDefinitionCreateReqDTO createReqDTO); } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/process/ProcessService.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/ProcessService.java similarity index 87% rename from yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/process/ProcessService.java rename to yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/ProcessService.java index 6a0d636cf..7e8cb6831 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/process/ProcessService.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/ProcessService.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.adminserver.modules.bpm.service.process; +package cn.iocoder.yudao.adminserver.modules.bpm.service.definition; import org.springframework.web.multipart.MultipartFile; @@ -8,6 +8,7 @@ import org.springframework.web.multipart.MultipartFile; * @author ZJQ * @date 2021/9/5 21:00 */ +@Deprecated public interface ProcessService { /** diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/process/impl/ProcessServiceImpl.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/ProcessServiceImpl.java similarity index 96% rename from yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/process/impl/ProcessServiceImpl.java rename to yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/ProcessServiceImpl.java index a084cbe25..60e8dbebb 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/process/impl/ProcessServiceImpl.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/ProcessServiceImpl.java @@ -1,6 +1,6 @@ -package cn.iocoder.yudao.adminserver.modules.bpm.service.process.impl; +package cn.iocoder.yudao.adminserver.modules.bpm.service.definition; -import cn.iocoder.yudao.adminserver.modules.bpm.service.process.ProcessService; +import cn.iocoder.yudao.adminserver.modules.bpm.service.definition.ProcessService; import lombok.extern.slf4j.Slf4j; import org.activiti.engine.RepositoryService; import org.activiti.engine.repository.Deployment; @@ -25,6 +25,7 @@ import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionU */ @Service @Slf4j +@Deprecated public class ProcessServiceImpl implements ProcessService { private static final String BPMN20_XML = "bpmn20.xml"; diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/dto/BpmDefinitionCreateReqDTO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/dto/BpmDefinitionCreateReqDTO.java new file mode 100644 index 000000000..69948366f --- /dev/null +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/dto/BpmDefinitionCreateReqDTO.java @@ -0,0 +1,43 @@ +package cn.iocoder.yudao.adminserver.modules.bpm.service.definition.dto; + +import lombok.Data; + +import javax.validation.constraints.NotEmpty; + +/** + * 流程定义创建 Request DTO + */ +@Data +public class BpmDefinitionCreateReqDTO { + + /** + * 流程标识 + */ + @NotEmpty(message = "流程标识不能为空") + private String key; + /** + * 流程名称 + */ + @NotEmpty(message = "流程名称不能为空") + private String name; + /** + * 流程描述 + */ + private String description; + /** + * 流程分类 + * 参见 bpm_model_category 数据字典 + */ + @NotEmpty(message = "流程分类不能为空") + private String category; + /** + * BPMN XML + */ + @NotEmpty(message = "BPMN XML 不能为空") + private String bpmnXml; + /** + * 动态表单编号,允许空 + */ + private Long formId; + +} diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/workflow/impl/BpmProcessDefinitionServiceImpl.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/impl/BpmDefinitionServiceImpl.java similarity index 52% rename from yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/workflow/impl/BpmProcessDefinitionServiceImpl.java rename to yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/impl/BpmDefinitionServiceImpl.java index 6f835a765..5d00473fc 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/workflow/impl/BpmProcessDefinitionServiceImpl.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/impl/BpmDefinitionServiceImpl.java @@ -1,23 +1,28 @@ -package cn.iocoder.yudao.adminserver.modules.bpm.service.workflow.impl; +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.workflow.vo.FileResp; import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.processdefinition.ProcessDefinitionPageReqVo; import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.processdefinition.ProcessDefinitionRespVO; -import cn.iocoder.yudao.adminserver.modules.bpm.convert.workflow.ProcessDefinitionConvert; +import cn.iocoder.yudao.adminserver.modules.bpm.convert.workflow.BpmDefinitionConvert; +import cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.definition.BpmProcessDefinitionDO; +import cn.iocoder.yudao.adminserver.modules.bpm.dal.mysql.definition.BpmProcessDefinitionMapper; import cn.iocoder.yudao.adminserver.modules.bpm.service.definition.BpmDefinitionService; +import cn.iocoder.yudao.adminserver.modules.bpm.service.definition.dto.BpmDefinitionCreateReqDTO; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.activiti.api.process.runtime.ProcessRuntime; import org.activiti.bpmn.converter.BpmnXMLConverter; import org.activiti.bpmn.model.BpmnModel; import org.activiti.engine.RepositoryService; +import org.activiti.engine.repository.Deployment; import org.activiti.engine.repository.ProcessDefinition; import org.activiti.engine.repository.ProcessDefinitionQuery; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.validation.annotation.Validated; +import javax.annotation.Resource; import java.util.Collections; import java.util.List; import java.util.Set; @@ -25,16 +30,22 @@ import java.util.stream.Collectors; /** * 流程定义实现 + * 主要进行 Activiti {@link ProcessDefinition} 和 {@link Deployment} 的维护 + * * @author yunlongn */ -@Slf4j @Service -@RequiredArgsConstructor -public class BpmProcessDefinitionServiceImpl implements BpmDefinitionService { +@Validated +@Slf4j +public class BpmDefinitionServiceImpl implements BpmDefinitionService { - private final RepositoryService repositoryService; + private static final String BPMN_FILE_SUFFIX = ".bpmn"; - private final ProcessRuntime processRuntime; + @Resource + private RepositoryService repositoryService; + + @Resource + private BpmProcessDefinitionMapper processDefinitionMapper; @Override public PageResult pageList(ProcessDefinitionPageReqVo processDefinitionPageReqVo) { @@ -47,7 +58,7 @@ public class BpmProcessDefinitionServiceImpl implements BpmDefinitionService { .listPage((processDefinitionPageReqVo.getPageNo() - 1) * processDefinitionPageReqVo.getPageSize(), processDefinitionPageReqVo.getPageSize()); final List respVOList = processDefinitions.stream() - .map(ProcessDefinitionConvert.INSTANCE::convert).collect(Collectors.toList()); + .map(BpmDefinitionConvert.INSTANCE::convert).collect(Collectors.toList()); return new PageResult<>(respVOList, processDefinitionQuery.count()); } @@ -62,11 +73,36 @@ public class BpmProcessDefinitionServiceImpl implements BpmDefinitionService { } @Override - public List getProcessDefinitionListByDeploymentIds(Set deploymentIds) { + public ProcessDefinition getDefinition(String id) { + return repositoryService.getProcessDefinition(id); + } + + @Override + public List getDefinitionListByDeploymentIds(Set deploymentIds) { if (CollUtil.isEmpty(deploymentIds)) { return Collections.emptyList(); } return repositoryService.createProcessDefinitionQuery().deploymentIds(deploymentIds).list(); } + @Override + @Transactional(rollbackFor = Exception.class) // 因为进行多个 activiti 操作,所以开启事务 + public String createDefinition(BpmDefinitionCreateReqDTO createReqDTO) { + // 创建 Deployment 部署 + Deployment deploy = repositoryService.createDeployment() + .key(createReqDTO.getKey()).name(createReqDTO.getName()).category(createReqDTO.getCategory()) + .addString(createReqDTO.getName() + BPMN_FILE_SUFFIX, createReqDTO.getBpmnXml()) + .deploy(); + + // 设置 ProcessDefinition 的 category 分类 + ProcessDefinition definition = repositoryService.createProcessDefinitionQuery().deploymentId(deploy.getId()).singleResult(); + repositoryService.setProcessDefinitionCategory(definition.getId(), createReqDTO.getCategory()); + + // 插入拓展表 + BpmProcessDefinitionDO definitionDO = BpmDefinitionConvert.INSTANCE.convert(createReqDTO) + .setProcessDefinitionId(definition.getId()); + processDefinitionMapper.insert(definitionDO); + return definition.getId(); + } + } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/model/BpmModelService.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/model/BpmModelService.java index 62b8ef1a5..83d68e5a8 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/model/BpmModelService.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/model/BpmModelService.java @@ -1,7 +1,6 @@ package cn.iocoder.yudao.adminserver.modules.bpm.service.model; import cn.iocoder.yudao.adminserver.modules.bpm.controller.model.vo.*; -import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; import javax.validation.Valid; @@ -45,11 +44,11 @@ public interface BpmModelService { void updateModel(@Valid BpmModelUpdateReqVO updateReqVO); /** - * 部署模型 使模型成为一个 process - * @param modelId 模型Id - * @return 返回成功 + * 将流程模型,部署成一个流程定义 + * + * @param id 编号 */ - CommonResult deploy(String modelId); + void deployModel(String id); /** * 删除模型 diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/model/impl/BpmModelServiceImpl.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/model/impl/BpmModelServiceImpl.java index 3f23befce..fbfb35779 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/model/impl/BpmModelServiceImpl.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/model/impl/BpmModelServiceImpl.java @@ -1,45 +1,35 @@ package cn.iocoder.yudao.adminserver.modules.bpm.service.model.impl; -import cn.hutool.core.util.ArrayUtil; import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.adminserver.modules.bpm.controller.model.vo.*; import cn.iocoder.yudao.adminserver.modules.bpm.convert.model.ModelConvert; import cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.form.BpmFormDO; -import cn.iocoder.yudao.adminserver.modules.bpm.enums.BpmErrorCodeConstants; import cn.iocoder.yudao.adminserver.modules.bpm.service.definition.BpmDefinitionService; +import cn.iocoder.yudao.adminserver.modules.bpm.service.definition.dto.BpmDefinitionCreateReqDTO; import cn.iocoder.yudao.adminserver.modules.bpm.service.form.BpmFormService; import cn.iocoder.yudao.adminserver.modules.bpm.service.model.BpmModelService; import cn.iocoder.yudao.adminserver.modules.bpm.service.model.dto.BpmModelMetaInfoRespDTO; -import cn.iocoder.yudao.framework.common.pojo.CommonResult; 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; import cn.iocoder.yudao.framework.common.util.object.PageUtils; import lombok.extern.slf4j.Slf4j; -import org.activiti.bpmn.converter.BpmnXMLConverter; -import org.activiti.bpmn.model.BpmnModel; import org.activiti.engine.RepositoryService; -import org.activiti.engine.repository.Deployment; import org.activiti.engine.repository.Model; import org.activiti.engine.repository.ModelQuery; import org.activiti.engine.repository.ProcessDefinition; -import org.apache.commons.lang3.exception.ExceptionUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.ObjectUtils; import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; -import javax.xml.stream.XMLInputFactory; -import javax.xml.stream.XMLStreamReader; -import java.io.ByteArrayInputStream; -import java.io.InputStreamReader; -import java.nio.charset.StandardCharsets; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; +import static cn.iocoder.yudao.adminserver.modules.bpm.enums.BpmErrorCodeConstants.BPMN_MODEL_NOT_EXISTS; import static cn.iocoder.yudao.adminserver.modules.bpm.enums.BpmErrorCodeConstants.BPM_MODEL_KEY_EXISTS; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap; @@ -55,8 +45,6 @@ import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils. @Slf4j public class BpmModelServiceImpl implements BpmModelService { - private static final String BPMN_FILE_SUFFIX = ".bpmn"; - @Resource private RepositoryService repositoryService; @Resource @@ -83,8 +71,8 @@ public class BpmModelServiceImpl implements BpmModelService { // 获得 ProcessDefinition Map Set deploymentIds = new HashSet<>(); - models.forEach(model -> CollectionUtils.addIfNotNull(deploymentIds, model.getId())); - List processDefinitions = bpmDefinitionService.getProcessDefinitionListByDeploymentIds(deploymentIds); + models.forEach(model -> CollectionUtils.addIfNotNull(deploymentIds, model.getDeploymentId())); + List processDefinitions = bpmDefinitionService.getDefinitionListByDeploymentIds(deploymentIds); Map processDefinitionMap = convertMap(processDefinitions, ProcessDefinition::getDeploymentId); // 拼接结果 @@ -98,9 +86,7 @@ public class BpmModelServiceImpl implements BpmModelService { BpmModelRespVO modelRespVO = ModelConvert.INSTANCE.convert(model); // 拼接 bpmn XML byte[] bpmnBytes = repositoryService.getModelEditorSource(id); - if (ArrayUtil.isNotEmpty(bpmnBytes)) { - modelRespVO.setBpmnXml(StrUtil.utf8Str(bpmnBytes)); - } + modelRespVO.setBpmnXml(StrUtil.utf8Str(bpmnBytes)); return modelRespVO; } @@ -124,26 +110,13 @@ public class BpmModelServiceImpl implements BpmModelService { return model.getId(); } -// @Override -// @Transactional(rollbackFor = Exception.class) // 因为进行多个 activiti 操作,所以开启事务 -// public String createModel(BpmModelCreateReqVO createReqVO) { -// Deployment deploy = repositoryService.createDeployment() -// .key(createReqVO.getKey()).name(createReqVO.getName()).category(createReqVO.getCategory()) -// .addString(createReqVO.getName() + BPMN_FILE_SUFFIX, createReqVO.getBpmnXml()) -// .deploy(); -// // 设置 ProcessDefinition 的 category 分类 -// ProcessDefinition definition = repositoryService.createProcessDefinitionQuery().deploymentId(deploy.getId()).singleResult(); -// repositoryService.setProcessDefinitionCategory(definition.getId(), createReqVO.getCategory()); -// return definition.getId(); -// } - @Override @Transactional(rollbackFor = Exception.class) // 因为进行多个 activiti 操作,所以开启事务 public void updateModel(BpmModelUpdateReqVO updateReqVO) { // 校验流程模型存在 Model model = repositoryService.getModel(updateReqVO.getId()); if (model == null) { - throw exception(BpmErrorCodeConstants.BPMN_MODEL_NOT_EXISTS); + throw exception(BPMN_MODEL_NOT_EXISTS); } // TODO @芋艿:需要校验下 key 的格式 @@ -156,40 +129,27 @@ public class BpmModelServiceImpl implements BpmModelService { } @Override - public CommonResult deploy(String modelId) { - try { - Model modelData = repositoryService.getModel(modelId); - if (ObjectUtils.isEmpty(modelData)) { - throw exception(BpmErrorCodeConstants.BPMN_MODEL_NOT_EXISTS); - } - byte[] bytes = repositoryService.getModelEditorSource(modelData.getId()); - if (bytes == null) { - throw exception(BpmErrorCodeConstants.BPMN_MODEL_NOT_EXISTS); - } - // 将xml转换为流 - // TODO @Li:这里是标准逻辑,看看 hutool 有没工具类提供。如果没有,咱自己封装一个 - ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes); - XMLInputFactory xif = XMLInputFactory.newInstance(); - InputStreamReader in = new InputStreamReader(inputStream, StandardCharsets.UTF_8); - XMLStreamReader xtr = xif.createXMLStreamReader(in); - // 流数据转化为 model - BpmnModel model = new BpmnXMLConverter().convertToBpmnModel(xtr); - if(ObjectUtils.isEmpty(model.getProcesses())){ - throw exception(BpmErrorCodeConstants.BPMN_MODEL_PROCESS_NOT_EXISTS); - } - byte[] bpmnBytes = new BpmnXMLConverter().convertToXML(model); - // 部署发布模型流程 - String processName = modelData.getName() + ".bpmn20.xml"; - Deployment deployment = repositoryService.createDeployment() - .name(modelData.getName()) - .addString(processName, new String(bpmnBytes, StandardCharsets.UTF_8)) - .deploy(); - // 部署成功 - return CommonResult.success(deployment.getId()); - } catch (Exception e) { - log.info("模型部署失败!modelId = {} e = {} ", modelId, ExceptionUtils.getStackTrace(e)); - throw exception(BpmErrorCodeConstants.BPMN_MODEL_ERROR); + @Transactional(rollbackFor = Exception.class) // 因为进行多个 activiti 操作,所以开启事务 + public void deployModel(String id) { + // 校验流程模型存在 + Model model = repositoryService.getModel(id); + if (ObjectUtils.isEmpty(model)) { + throw exception(BPMN_MODEL_NOT_EXISTS); } + byte[] bpmnBytes = repositoryService.getModelEditorSource(model.getId()); + if (bpmnBytes == null) { + throw exception(BPMN_MODEL_NOT_EXISTS); + } + + // 创建流程定义 + BpmDefinitionCreateReqDTO definitionCreateReqDTO = ModelConvert.INSTANCE.convert2(model) + .setBpmnXml(StrUtil.utf8Str(bpmnBytes)); + String definitionId = bpmDefinitionService.createDefinition(definitionCreateReqDTO); + + // 更新 model 的 deploymentId,进行关联 + ProcessDefinition definition = bpmDefinitionService.getDefinition(definitionId); + model.setDeploymentId(definition.getDeploymentId()); + repositoryService.saveModel(model); } @Override @@ -197,7 +157,7 @@ public class BpmModelServiceImpl implements BpmModelService { // 校验流程模型存在 Model model = repositoryService.getModel(id); if (model == null) { - throw exception(BpmErrorCodeConstants.BPMN_MODEL_NOT_EXISTS); + throw exception(BPMN_MODEL_NOT_EXISTS); } // 执行删除 repositoryService.deleteModel(id); diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/workflow/BpmTaskService.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/task/BpmTaskService.java similarity index 96% rename from yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/workflow/BpmTaskService.java rename to yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/task/BpmTaskService.java index 37d14d81f..dceba6ff6 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/workflow/BpmTaskService.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/task/BpmTaskService.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.adminserver.modules.bpm.service.workflow; +package cn.iocoder.yudao.adminserver.modules.bpm.service.task; import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.*; import cn.iocoder.yudao.framework.common.pojo.PageResult; diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/workflow/impl/BpmTaskServiceImpl.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/task/impl/BpmTaskServiceImpl.java similarity index 98% rename from yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/workflow/impl/BpmTaskServiceImpl.java rename to yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/task/impl/BpmTaskServiceImpl.java index 8ca9bbb1c..381c4ab35 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/workflow/impl/BpmTaskServiceImpl.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/task/impl/BpmTaskServiceImpl.java @@ -1,10 +1,10 @@ -package cn.iocoder.yudao.adminserver.modules.bpm.service.workflow.impl; +package cn.iocoder.yudao.adminserver.modules.bpm.service.task.impl; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.io.IoUtil; import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.*; import cn.iocoder.yudao.adminserver.modules.bpm.convert.workflow.TaskConvert; -import cn.iocoder.yudao.adminserver.modules.bpm.service.workflow.BpmTaskService; +import cn.iocoder.yudao.adminserver.modules.bpm.service.task.BpmTaskService; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils; @@ -28,7 +28,6 @@ import org.activiti.engine.repository.ProcessDefinition; import org.activiti.engine.runtime.ProcessInstance; import org.activiti.engine.task.Comment; import org.activiti.image.ProcessDiagramGenerator; -import org.apache.commons.lang3.exception.ExceptionUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.ObjectUtils; diff --git a/yudao-admin-ui/src/api/bpm/model.js b/yudao-admin-ui/src/api/bpm/model.js index 7c5d0dba6..8cb7e314b 100644 --- a/yudao-admin-ui/src/api/bpm/model.js +++ b/yudao-admin-ui/src/api/bpm/model.js @@ -38,10 +38,9 @@ export function deleteModel(id) { }) } -export function deployModel(data) { +export function deployModel(id) { return request({ - url: '/bpm/model/deploy?modelId='+ data.modelId, - method: 'POST', - data: data + url: '/bpm/model/deploy?id=' + id, + method: 'POST' }) } diff --git a/yudao-admin-ui/src/views/bpm/model/index.vue b/yudao-admin-ui/src/views/bpm/model/index.vue index 264efefa3..f2cba25cd 100644 --- a/yudao-admin-ui/src/views/bpm/model/index.vue +++ b/yudao-admin-ui/src/views/bpm/model/index.vue @@ -27,10 +27,9 @@ - - - - + + +