From dc9ddaeba9dc92eaf11f142866a5d0d84ff485ff Mon Sep 17 00:00:00 2001 From: hewenqiang <1527468660@qq.com> Date: Thu, 20 Jan 2022 12:03:06 +0800 Subject: [PATCH] =?UTF-8?q?fix=20--=20=E4=BF=AE=E6=94=B9=E6=B5=81=E7=A8=8B?= =?UTF-8?q?=E5=AE=9A=E4=B9=89=E6=A8=A1=E5=9D=97=EF=BC=8C=E4=B8=BB=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=E6=98=BE=E7=A4=BA=E6=9C=80=E6=96=B0=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E7=9A=84=E6=B5=81=E7=A8=8B=E9=83=A8=E7=BD=B2=EF=BC=8C=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E2=80=9C=E7=89=88=E6=9C=AC=E7=AE=A1=E7=90=86=E2=80=9D?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E3=80=82=E4=BC=98=E5=8C=96=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../workflow/FlowDefinitionController.java | 88 ++++--- .../workflow/domain/dto/FlowProcDefDto.java | 56 ---- .../workflow/domain/vo/FlowDefinitionVo.java | 91 +++++++ .../service/IFlowDefinitionService.java | 34 ++- .../impl/FlowDefinitionServiceImpl.java | 186 ++++++++------ ruoyi-ui/src/api/workflow/definition.js | 32 +-- .../views/workflow/definition/designer.vue | 22 +- .../src/views/workflow/definition/index.vue | 242 ++++++++++-------- 8 files changed, 444 insertions(+), 307 deletions(-) delete mode 100644 ruoyi-system/src/main/java/com/ruoyi/workflow/domain/dto/FlowProcDefDto.java create mode 100644 ruoyi-system/src/main/java/com/ruoyi/workflow/domain/vo/FlowDefinitionVo.java diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/workflow/FlowDefinitionController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/workflow/FlowDefinitionController.java index 3eb96486..cb16266a 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/workflow/FlowDefinitionController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/workflow/FlowDefinitionController.java @@ -1,13 +1,16 @@ package com.ruoyi.web.controller.workflow; +import com.ruoyi.common.core.controller.BaseController; +import com.ruoyi.common.core.domain.PageQuery; import com.ruoyi.common.core.domain.R; import com.ruoyi.common.core.domain.entity.SysRole; import com.ruoyi.common.core.domain.entity.SysUser; -import com.ruoyi.workflow.domain.dto.FlowProcDefDto; -import com.ruoyi.workflow.domain.dto.FlowSaveXmlVo; -import com.ruoyi.workflow.service.IFlowDefinitionService; +import com.ruoyi.common.core.page.TableDataInfo; import com.ruoyi.system.service.ISysRoleService; import com.ruoyi.system.service.ISysUserService; +import com.ruoyi.workflow.domain.dto.FlowSaveXmlVo; +import com.ruoyi.workflow.domain.vo.FlowDefinitionVo; +import com.ruoyi.workflow.service.IFlowDefinitionService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; @@ -32,14 +35,14 @@ import java.util.Map; * 工作流程定义 *

* - * @author XuanXuan - * @date 2021-04-03 + * @author KonBAI + * @date 2022-01-17 */ @Slf4j @Api(tags = "流程定义") @RestController @RequestMapping("/workflow/definition") -public class FlowDefinitionController { +public class FlowDefinitionController extends BaseController { @Autowired private IFlowDefinitionService flowDefinitionService; @@ -52,45 +55,57 @@ public class FlowDefinitionController { @GetMapping(value = "/list") - @ApiOperation(value = "流程定义列表", response = FlowProcDefDto.class) - public R list(@ApiParam(value = "当前页码", required = true) @RequestParam Integer pageNum, - @ApiParam(value = "每页条数", required = true) @RequestParam Integer pageSize) { - return R.success(flowDefinitionService.list(pageNum, pageSize)); + @ApiOperation(value = "流程定义列表", response = FlowDefinitionVo.class) + public TableDataInfo list(PageQuery pageQuery) { + return flowDefinitionService.list(pageQuery); + } + + /** + * 列出指定流程的发布版本列表 + * @param processKey 流程定义Key + * @return + */ + @GetMapping(value = "/publishList") + @ApiOperation(value = "流程定义列表", response = FlowDefinitionVo.class) + public TableDataInfo publishList(@ApiParam(value = "流程定义Key", required = true) @RequestParam String processKey, + PageQuery pageQuery) { + return flowDefinitionService.publishList(processKey, pageQuery); } @ApiOperation(value = "导入流程文件", notes = "上传bpmn20的xml文件") @PostMapping("/import") - public R importFile(@RequestParam(required = false) String name, - @RequestParam(required = false) String category, - MultipartFile file) { + public R importFile(@RequestParam(required = false) String name, + @RequestParam(required = false) String category, + MultipartFile file) { try (InputStream in = file.getInputStream()) { flowDefinitionService.importFile(name, category, in); } catch (Exception e) { log.error("导入失败:", e); - return R.success(e.getMessage()); + return error(e.getMessage()); } - return R.success("导入成功"); + return success("导入成功"); } @ApiOperation(value = "读取xml文件") - @GetMapping("/readXml/{deployId}") - public R readXml(@ApiParam(value = "流程定义id") @PathVariable(value = "deployId") String deployId) { + @GetMapping("/readXml/{definitionId}") + public R readXml(@ApiParam(value = "流程定义ID") @PathVariable(value = "definitionId") String definitionId) { try { - return flowDefinitionService.readXml(deployId); + return R.success(null, flowDefinitionService.readXml(definitionId)); } catch (Exception e) { - return R.error("加载xml文件异常"); + return R.error("加载xml文件异常", null); } } @ApiOperation(value = "读取图片文件") - @GetMapping("/readImage/{deployId}") - public void readImage(@ApiParam(value = "流程定义id") @PathVariable(value = "deployId") String deployId, HttpServletResponse response) { + @GetMapping("/readImage/{definitionId}") + public void readImage(@ApiParam(value = "流程定义id") @PathVariable(value = "definitionId") String definitionId, + HttpServletResponse response) { try (OutputStream os = response.getOutputStream()) { - BufferedImage image = ImageIO.read(flowDefinitionService.readImage(deployId)); + BufferedImage image = ImageIO.read(flowDefinitionService.readImage(definitionId)); response.setContentType("image/png"); if (image != null) { ImageIO.write(image, "png", os); @@ -103,51 +118,52 @@ public class FlowDefinitionController { @ApiOperation(value = "保存流程设计器内的xml文件") @PostMapping("/save") - public R save(@RequestBody FlowSaveXmlVo vo) { + public R save(@RequestBody FlowSaveXmlVo vo) { try (InputStream in = new ByteArrayInputStream(vo.getXml().getBytes(StandardCharsets.UTF_8))) { flowDefinitionService.importFile(vo.getName(), vo.getCategory(), in); } catch (Exception e) { log.error("导入失败:", e); - return R.success(e.getMessage()); + return success(e.getMessage()); } - return R.success("导入成功"); + return success("导入成功"); } @ApiOperation(value = "根据流程定义id启动流程实例") @PostMapping("/start/{procDefId}") - public R start(@ApiParam(value = "流程定义id") @PathVariable(value = "procDefId") String procDefId, - @ApiParam(value = "变量集合,json对象") @RequestBody Map variables) { - return flowDefinitionService.startProcessInstanceById(procDefId, variables); + public R start(@ApiParam(value = "流程定义id") @PathVariable(value = "procDefId") String procDefId, + @ApiParam(value = "变量集合,json对象") @RequestBody Map variables) { + flowDefinitionService.startProcessInstanceById(procDefId, variables); + return success("流程启动成功"); } @ApiOperation(value = "激活或挂起流程定义") @PutMapping(value = "/updateState") - public R updateState(@ApiParam(value = "1:激活,2:挂起", required = true) @RequestParam Integer state, - @ApiParam(value = "流程部署ID", required = true) @RequestParam String deployId) { - flowDefinitionService.updateState(state, deployId); - return R.success(); + public R updateState(@ApiParam(value = "ture:挂起,false:激活", required = true) @RequestParam Boolean suspended, + @ApiParam(value = "流程定义ID", required = true) @RequestParam String definitionId) { + flowDefinitionService.updateState(suspended, definitionId); + return success(); } @ApiOperation(value = "删除流程") @DeleteMapping(value = "/delete") - public R delete(@ApiParam(value = "流程部署ID", required = true) @RequestParam String deployId) { + public R delete(@ApiParam(value = "流程部署ID", required = true) @RequestParam String deployId) { flowDefinitionService.delete(deployId); - return R.success(); + return success(); } @ApiOperation(value = "指定流程办理人员列表") @GetMapping("/userList") - public R userList(SysUser user) { + public R> userList(SysUser user) { List list = userService.selectUserList(user); return R.success(list); } @ApiOperation(value = "指定流程办理组列表") @GetMapping("/roleList") - public R roleList(SysRole role) { + public R> roleList(SysRole role) { List list = sysRoleService.selectRoleList(role); return R.success(list); } diff --git a/ruoyi-system/src/main/java/com/ruoyi/workflow/domain/dto/FlowProcDefDto.java b/ruoyi-system/src/main/java/com/ruoyi/workflow/domain/dto/FlowProcDefDto.java deleted file mode 100644 index 1a1187d4..00000000 --- a/ruoyi-system/src/main/java/com/ruoyi/workflow/domain/dto/FlowProcDefDto.java +++ /dev/null @@ -1,56 +0,0 @@ -package com.ruoyi.workflow.domain.dto; -import com.fasterxml.jackson.annotation.JsonFormat; -import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiModelProperty; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -import java.io.Serializable; -import java.util.Date; - -/** - *

流程定义

- * - * @author XuanXuan - * @date 2021-04-03 - */ -@Data -@AllArgsConstructor -@NoArgsConstructor -@ApiModel("流程定义") -public class FlowProcDefDto implements Serializable { - - @ApiModelProperty("流程id") - private String id; - - @ApiModelProperty("流程名称") - private String name; - - @ApiModelProperty("流程key") - private String key; - - @ApiModelProperty("流程分类") - private String category; - - @ApiModelProperty("配置表单名称") - private String formName; - - @ApiModelProperty("配置表单id") - private Long formId; - - @ApiModelProperty("版本") - private int version; - - @ApiModelProperty("部署ID") - private String deploymentId; - - @ApiModelProperty("流程定义状态: 1:激活 , 2:中止") - private int suspensionState; - - @ApiModelProperty("部署时间") - @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") - private Date deploymentTime; - - -} diff --git a/ruoyi-system/src/main/java/com/ruoyi/workflow/domain/vo/FlowDefinitionVo.java b/ruoyi-system/src/main/java/com/ruoyi/workflow/domain/vo/FlowDefinitionVo.java new file mode 100644 index 00000000..b4503355 --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/workflow/domain/vo/FlowDefinitionVo.java @@ -0,0 +1,91 @@ +package com.ruoyi.workflow.domain.vo; + +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; +import com.alibaba.excel.annotation.ExcelProperty; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.util.Date; + + + +/** + * 流程定义视图对象 workflow_definition + * + * @author KonBAI + * @date 2022-01-17 + */ +@Data +@ApiModel("流程定义视图对象") +@ExcelIgnoreUnannotated +public class FlowDefinitionVo { + + private static final long serialVersionUID = 1L; + + /** + * 流程定义ID + */ + @ExcelProperty(value = "流程定义ID") + @ApiModelProperty("流程定义ID") + private String definitionId; + + /** + * 流程名称 + */ + @ExcelProperty(value = "流程名称") + @ApiModelProperty("流程名称") + private String processName; + + /** + * 流程Key + */ + @ExcelProperty(value = "流程Key") + @ApiModelProperty("流程Key") + private String processKey; + + /** + * 分类编码 + */ + @ExcelProperty(value = "分类编码") + @ApiModelProperty("分类编码") + private String categoryCode; + + @ApiModelProperty("版本") + private Integer version; + + /** + * 表单ID + */ + @ExcelProperty(value = "表单ID") + @ApiModelProperty("表单ID") + private Long formId; + + /** + * 表单名称 + */ + @ExcelProperty(value = "表单名称") + @ApiModelProperty("表单名称") + private String formName; + + /** + * 部署ID + */ + @ExcelProperty(value = "部署ID") + @ApiModelProperty("部署ID") + private String deploymentId; + + /** + * 流程定义状态: 1:激活 , 2:中止 + */ + @ExcelProperty(value = "流程定义状态: 1:激活 , 2:中止") + @ApiModelProperty("流程定义状态: 1:激活 , 2:中止") + private Boolean suspended; + + /** + * 部署时间 + */ + @ExcelProperty(value = "部署时间") + @ApiModelProperty("部署时间") + private Date deploymentTime; +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/workflow/service/IFlowDefinitionService.java b/ruoyi-system/src/main/java/com/ruoyi/workflow/service/IFlowDefinitionService.java index 6d43950f..0d6fd64f 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/workflow/service/IFlowDefinitionService.java +++ b/ruoyi-system/src/main/java/com/ruoyi/workflow/service/IFlowDefinitionService.java @@ -1,8 +1,8 @@ package com.ruoyi.workflow.service; -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import com.ruoyi.common.core.domain.R; -import com.ruoyi.workflow.domain.dto.FlowProcDefDto; +import com.ruoyi.common.core.domain.PageQuery; +import com.ruoyi.common.core.page.TableDataInfo; +import com.ruoyi.workflow.domain.vo.FlowDefinitionVo; import java.io.IOException; import java.io.InputStream; @@ -20,11 +20,17 @@ public interface IFlowDefinitionService { /** * 流程定义列表 * - * @param pageNum 当前页码 - * @param pageSize 每页条数 + * @param pageQuery 分页参数 * @return 流程定义分页列表数据 */ - Page list(Integer pageNum, Integer pageSize); + TableDataInfo list(PageQuery pageQuery); + + /** + * + * @param processKey + * @return + */ + TableDataInfo publishList(String processKey, PageQuery pageQuery); /** * 导入流程文件 @@ -37,10 +43,10 @@ public interface IFlowDefinitionService { /** * 读取xml - * @param deployId + * @param definitionId 流程定义ID * @return */ - R readXml(String deployId) throws IOException; + String readXml(String definitionId) throws IOException; /** * 根据流程定义ID启动流程实例 @@ -50,16 +56,16 @@ public interface IFlowDefinitionService { * @return */ - R startProcessInstanceById(String procDefId, Map variables); + void startProcessInstanceById(String procDefId, Map variables); /** * 激活或挂起流程定义 * - * @param state 状态 - * @param deployId 流程部署ID + * @param suspended 状态 + * @param definitionId 流程定义ID */ - void updateState(Integer state, String deployId); + void updateState(Boolean suspended, String definitionId); /** @@ -72,8 +78,8 @@ public interface IFlowDefinitionService { /** * 读取图片文件 - * @param deployId + * @param definitionId 流程定义ID * @return */ - InputStream readImage(String deployId); + InputStream readImage(String definitionId); } diff --git a/ruoyi-system/src/main/java/com/ruoyi/workflow/service/impl/FlowDefinitionServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/workflow/service/impl/FlowDefinitionServiceImpl.java index 7eaf2ec8..7a9e2cff 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/workflow/service/impl/FlowDefinitionServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/workflow/service/impl/FlowDefinitionServiceImpl.java @@ -2,54 +2,56 @@ package com.ruoyi.workflow.service.impl; import cn.hutool.core.util.StrUtil; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import com.ruoyi.common.core.domain.R; +import com.ruoyi.common.core.domain.PageQuery; +import com.ruoyi.common.core.page.TableDataInfo; +import com.ruoyi.common.exception.ServiceException; import com.ruoyi.common.utils.LoginUtils; import com.ruoyi.flowable.common.constant.ProcessConstants; import com.ruoyi.flowable.common.enums.FlowComment; -import com.ruoyi.workflow.domain.dto.FlowProcDefDto; import com.ruoyi.flowable.factory.FlowServiceFactory; +import com.ruoyi.system.domain.SysForm; +import com.ruoyi.workflow.domain.vo.FlowDefinitionVo; import com.ruoyi.workflow.service.IFlowDefinitionService; import com.ruoyi.workflow.service.ISysDeployFormService; -import com.ruoyi.system.domain.SysForm; +import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.commons.io.IOUtils; import org.flowable.bpmn.model.BpmnModel; import org.flowable.engine.repository.Deployment; +import org.flowable.engine.repository.DeploymentBuilder; import org.flowable.engine.repository.ProcessDefinition; import org.flowable.engine.repository.ProcessDefinitionQuery; import org.flowable.engine.runtime.ProcessInstance; import org.flowable.image.impl.DefaultProcessDiagramGenerator; import org.flowable.task.api.Task; -import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import org.springframework.transaction.interceptor.TransactionAspectSupport; -import javax.annotation.Resource; import java.io.IOException; import java.io.InputStream; import java.nio.charset.StandardCharsets; import java.util.*; +import java.util.stream.Collectors; /** * 流程定义 * - * @author XuanXuan - * @date 2021-04-03 + * @author KonBAI + * @date 2022-01-17 */ +@RequiredArgsConstructor @Service @Slf4j public class FlowDefinitionServiceImpl extends FlowServiceFactory implements IFlowDefinitionService { - @Resource - private ISysDeployFormService sysDeployFormService; + private final ISysDeployFormService sysDeployFormService; private static final String BPMN_FILE_SUFFIX = ".bpmn"; @Override public boolean exist(String processDefinitionKey) { - ProcessDefinitionQuery processDefinitionQuery - = repositoryService.createProcessDefinitionQuery().processDefinitionKey(processDefinitionKey); + ProcessDefinitionQuery processDefinitionQuery = repositoryService.createProcessDefinitionQuery() + .processDefinitionKey(processDefinitionKey); long count = processDefinitionQuery.count(); return count > 0; } @@ -58,37 +60,78 @@ public class FlowDefinitionServiceImpl extends FlowServiceFactory implements IFl /** * 流程定义列表 * - * @param pageNum 当前页码 - * @param pageSize 每页条数 + * @param pageQuery 分页参数 * @return 流程定义分页列表数据 */ @Override - public Page list(Integer pageNum, Integer pageSize) { - Page page = new Page<>(); + public TableDataInfo list(PageQuery pageQuery) { + Page page = new Page<>(); // 流程定义列表数据查询 ProcessDefinitionQuery processDefinitionQuery = repositoryService.createProcessDefinitionQuery() -// .latestVersion() - .orderByProcessDefinitionKey().asc(); - page.setTotal(processDefinitionQuery.count()); - List processDefinitionList = processDefinitionQuery.listPage(pageNum - 1, pageSize); + .latestVersion() + .orderByProcessDefinitionKey().asc(); + long pageTotal = processDefinitionQuery.count(); + if (pageTotal <= 0) { + return TableDataInfo.build(); + } + List definitionList = processDefinitionQuery.listPage(pageQuery.getPageNum() - 1, pageQuery.getPageSize()); - List dataList = new ArrayList<>(); - for (ProcessDefinition processDefinition : processDefinitionList) { + List definitionVoList = new ArrayList<>(); + for (ProcessDefinition processDefinition : definitionList) { String deploymentId = processDefinition.getDeploymentId(); Deployment deployment = repositoryService.createDeploymentQuery().deploymentId(deploymentId).singleResult(); - FlowProcDefDto reProcDef = new FlowProcDefDto(); - BeanUtils.copyProperties(processDefinition, reProcDef); + FlowDefinitionVo vo = new FlowDefinitionVo(); + vo.setDefinitionId(processDefinition.getId()); + vo.setProcessKey(processDefinition.getKey()); + vo.setProcessName(processDefinition.getName()); + vo.setVersion(processDefinition.getVersion()); + vo.setCategoryCode(processDefinition.getCategory()); + vo.setDeploymentId(processDefinition.getDeploymentId()); + vo.setSuspended(processDefinition.isSuspended()); SysForm sysForm = sysDeployFormService.selectSysDeployFormByDeployId(deploymentId); if (Objects.nonNull(sysForm)) { - reProcDef.setFormName(sysForm.getFormName()); - reProcDef.setFormId(sysForm.getFormId()); + vo.setFormId(sysForm.getFormId()); + vo.setFormName(sysForm.getFormName()); } // 流程定义时间 - reProcDef.setDeploymentTime(deployment.getDeploymentTime()); - dataList.add(reProcDef); + vo.setCategoryCode(deployment.getCategory()); + vo.setDeploymentTime(deployment.getDeploymentTime()); + definitionVoList.add(vo); } - page.setRecords(dataList); - return page; + page.setRecords(definitionVoList); + page.setTotal(pageTotal); + return TableDataInfo.build(page); + } + + @Override + public TableDataInfo publishList(String processKey, PageQuery pageQuery) { + Page page = new Page<>(); + // 创建查询条件 + ProcessDefinitionQuery processDefinitionQuery = repositoryService.createProcessDefinitionQuery() + .processDefinitionKey(processKey) + .orderByProcessDefinitionVersion().asc(); + long pageTotal = processDefinitionQuery.count(); + if (pageTotal <= 0) { + return TableDataInfo.build(); + } + // 根据查询条件,查询所有版本 + List processDefinitionList = processDefinitionQuery + .listPage(pageQuery.getPageNum() - 1, pageQuery.getPageSize()); + List flowDefinitionVoList = processDefinitionList.stream().map(item -> { + FlowDefinitionVo vo = new FlowDefinitionVo(); + vo.setDefinitionId(item.getId()); + vo.setProcessKey(item.getKey()); + vo.setProcessName(item.getName()); + vo.setVersion(item.getVersion()); + vo.setCategoryCode(item.getCategory()); + vo.setDeploymentId(item.getDeploymentId()); + vo.setSuspended(item.isSuspended()); + // BeanUtil.copyProperties(item, vo); + return vo; + }).collect(Collectors.toList()); + page.setRecords(flowDefinitionVoList); + page.setTotal(pageTotal); + return TableDataInfo.build(page); } @@ -100,51 +143,54 @@ public class FlowDefinitionServiceImpl extends FlowServiceFactory implements IFl * @param in */ @Override + @Transactional(rollbackFor = Exception.class) public void importFile(String name, String category, InputStream in) { - Deployment deploy = repositoryService.createDeployment().addInputStream(name + BPMN_FILE_SUFFIX, in).name(name).category(category).deploy(); - ProcessDefinition definition = repositoryService.createProcessDefinitionQuery().deploymentId(deploy.getId()).singleResult(); - repositoryService.setProcessDefinitionCategory(definition.getId(), category); - + String processName = name + BPMN_FILE_SUFFIX; + // 创建流程部署 + DeploymentBuilder deploymentBuilder = repositoryService.createDeployment() + .name(processName) + .key(name) + .category(category) + .addInputStream(processName, in); + // 部署 + deploymentBuilder.deploy(); } /** * 读取xml * - * @param deployId + * @param definitionId 流程定义ID * @return */ @Override - public R readXml(String deployId) throws IOException { - ProcessDefinition definition = repositoryService.createProcessDefinitionQuery().deploymentId(deployId).singleResult(); - InputStream inputStream = repositoryService.getResourceAsStream(definition.getDeploymentId(), definition.getResourceName()); - String result = IOUtils.toString(inputStream, StandardCharsets.UTF_8.name()); - return R.success("", result); + public String readXml(String definitionId) throws IOException { + InputStream inputStream = repositoryService.getProcessModel(definitionId); + return IOUtils.toString(inputStream, StandardCharsets.UTF_8.name()); } /** * 读取xml * - * @param deployId + * @param definitionId 流程定义ID * @return */ @Override - public InputStream readImage(String deployId) { - ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().deploymentId(deployId).singleResult(); + public InputStream readImage(String definitionId) { //获得图片流 DefaultProcessDiagramGenerator diagramGenerator = new DefaultProcessDiagramGenerator(); - BpmnModel bpmnModel = repositoryService.getBpmnModel(processDefinition.getId()); + BpmnModel bpmnModel = repositoryService.getBpmnModel(definitionId); //输出为图片 return diagramGenerator.generateDiagram( - bpmnModel, - "png", - Collections.emptyList(), - Collections.emptyList(), - "宋体", - "宋体", - "宋体", - null, - 1.0, - false); + bpmnModel, + "png", + Collections.emptyList(), + Collections.emptyList(), + "宋体", + "宋体", + "宋体", + null, + 1.0, + false); } @@ -157,12 +203,12 @@ public class FlowDefinitionServiceImpl extends FlowServiceFactory implements IFl */ @Override @Transactional(rollbackFor = Exception.class) - public R startProcessInstanceById(String procDefId, Map variables) { + public void startProcessInstanceById(String procDefId, Map variables) { try { ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionId(procDefId) - .latestVersion().singleResult(); + .latestVersion().singleResult(); if (Objects.nonNull(processDefinition) && processDefinition.isSuspended()) { - return R.error("流程已被挂起,请先激活流程"); + throw new ServiceException("流程已被挂起,请先激活流程"); } // variables.put("skip", true); // variables.put(ProcessConstants.FLOWABLE_SKIP_EXPRESSION_ENABLED, true); @@ -175,17 +221,15 @@ public class FlowDefinitionServiceImpl extends FlowServiceFactory implements IFl Task task = taskService.createTaskQuery().processInstanceId(processInstance.getProcessInstanceId()).singleResult(); if (Objects.nonNull(task)) { if (!StrUtil.equalsAny(task.getAssignee(), UserIdStr)) { - TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); - return R.error("数据验证失败,该工作流第一个用户任务的指派人并非当前用户,不能执行该操作!"); + throw new ServiceException("数据验证失败,该工作流第一个用户任务的指派人并非当前用户,不能执行该操作!"); } taskService.addComment(task.getId(), processInstance.getProcessInstanceId(), FlowComment.NORMAL.getType(), LoginUtils.getNickName() + "发起流程申请"); // taskService.setAssignee(task.getId(), UserIdStr); taskService.complete(task.getId(), variables); } - return R.success("流程启动成功"); } catch (Exception e) { e.printStackTrace(); - return R.error("流程启动错误"); + throw new ServiceException("流程启动错误"); } } @@ -193,19 +237,17 @@ public class FlowDefinitionServiceImpl extends FlowServiceFactory implements IFl /** * 激活或挂起流程定义 * - * @param state 状态 - * @param deployId 流程部署ID + * @param suspended 是否暂停状态 + * @param definitionId 流程定义ID */ @Override - public void updateState(Integer state, String deployId) { - ProcessDefinition procDef = repositoryService.createProcessDefinitionQuery().deploymentId(deployId).singleResult(); - // 激活 - if (state == 1) { - repositoryService.activateProcessDefinitionById(procDef.getId(), true, null); - } - // 挂起 - if (state == 2) { - repositoryService.suspendProcessDefinitionById(procDef.getId(), true, null); + public void updateState(Boolean suspended, String definitionId) { + if (!suspended) { + // 激活 + repositoryService.activateProcessDefinitionById(definitionId, true, null); + } else { + // 挂起 + repositoryService.suspendProcessDefinitionById(definitionId, true, null); } } diff --git a/ruoyi-ui/src/api/workflow/definition.js b/ruoyi-ui/src/api/workflow/definition.js index 45286e1d..98737c27 100644 --- a/ruoyi-ui/src/api/workflow/definition.js +++ b/ruoyi-ui/src/api/workflow/definition.js @@ -9,6 +9,16 @@ export function listDefinition(query) { }) } +// 查询指定流程发布的版本列表 +export function publishList(query) { + return request({ + url: '/workflow/definition/publishList', + method: 'get', + params: query + }) +} + + // 部署流程实例 export function definitionStart(procDefId,data) { return request({ @@ -54,9 +64,9 @@ export function roleList(query) { } // 读取xml文件 -export function readXml(deployId) { +export function readXml(definitionId) { return request({ - url: '/workflow/definition/readXml/' + deployId, + url: '/workflow/definition/readXml/' + definitionId, method: 'get' }) } @@ -85,24 +95,6 @@ export function saveXml(data) { }) } -// 新增流程定义 -export function addDeployment(data) { - return request({ - url: '/system/deployment', - method: 'post', - data: data - }) -} - -// 修改流程定义 -export function updateDeployment(data) { - return request({ - url: '/system/deployment', - method: 'put', - data: data - }) -} - // 删除流程定义 export function delDeployment(query) { return request({ diff --git a/ruoyi-ui/src/views/workflow/definition/designer.vue b/ruoyi-ui/src/views/workflow/definition/designer.vue index cb19faa3..cd1208ab 100644 --- a/ruoyi-ui/src/views/workflow/definition/designer.vue +++ b/ruoyi-ui/src/views/workflow/definition/designer.vue @@ -1,6 +1,11 @@ @@ -14,6 +19,7 @@ export default { data () { return { loadIndex: 0, + loading: false, formFlowEntryData: { entryId: undefined, processDefinitionName: undefined, @@ -39,10 +45,10 @@ export default { } }, created() { - const deployId = this.$route.query && this.$route.query.deployId; + const definitionId = this.$route.query && this.$route.query.definitionId; // 查询流程xml - if (deployId) { - this.getModelDetail(deployId); + if (definitionId) { + this.getModelDetail(definitionId); } this.getDicts("sys_process_category").then(res => { this.categorys = res.data; @@ -50,11 +56,13 @@ export default { }, methods: { /** xml 文件 */ - getModelDetail(deployId) { + getModelDetail(definitionId) { + this.loading = true; // 发送请求,获取xml - readXml(deployId).then(res =>{ + readXml(definitionId).then(res =>{ this.formFlowEntryData.bpmnXml = res.data; - this.loadIndex = deployId; + this.loadIndex = definitionId; + this.loading = false; }) }, onSaveFlowEntry ({ saveData, modeler }) { diff --git a/ruoyi-ui/src/views/workflow/definition/index.vue b/ruoyi-ui/src/views/workflow/definition/index.vue index b568e86c..6a0174b1 100644 --- a/ruoyi-ui/src/views/workflow/definition/index.vue +++ b/ruoyi-ui/src/views/workflow/definition/index.vue @@ -67,18 +67,17 @@ - + - - - + +