FlowDefinitionController.java 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. package com.ruoyi.flowable.controller;
  2. import com.ruoyi.common.core.controller.BaseController;
  3. import com.ruoyi.common.core.domain.AjaxResult;
  4. import com.ruoyi.common.core.domain.entity.SysRole;
  5. import com.ruoyi.common.core.domain.entity.SysUser;
  6. import com.ruoyi.flowable.domain.dto.FlowSaveXmlVo;
  7. import com.ruoyi.flowable.service.IFlowDefinitionService;
  8. import com.ruoyi.system.domain.FlowProcDefDto;
  9. import com.ruoyi.system.domain.SysExpression;
  10. import com.ruoyi.system.service.ISysExpressionService;
  11. import com.ruoyi.system.service.ISysRoleService;
  12. import com.ruoyi.system.service.ISysUserService;
  13. import io.swagger.annotations.Api;
  14. import io.swagger.annotations.ApiOperation;
  15. import io.swagger.annotations.ApiParam;
  16. import lombok.extern.slf4j.Slf4j;
  17. import org.springframework.beans.factory.annotation.Autowired;
  18. import org.springframework.web.bind.annotation.*;
  19. import org.springframework.web.multipart.MultipartFile;
  20. import javax.annotation.Resource;
  21. import javax.imageio.ImageIO;
  22. import javax.servlet.http.HttpServletResponse;
  23. import java.awt.image.BufferedImage;
  24. import java.io.ByteArrayInputStream;
  25. import java.io.IOException;
  26. import java.io.InputStream;
  27. import java.io.OutputStream;
  28. import java.nio.charset.StandardCharsets;
  29. import java.util.List;
  30. import java.util.Map;
  31. /**
  32. * <p>
  33. * 工作流程定义
  34. * </p>
  35. *
  36. * @author Tony
  37. * @date 2021-04-03
  38. */
  39. @Slf4j
  40. @Api(tags = "流程定义")
  41. @RestController
  42. @RequestMapping("/flowable/definition")
  43. public class FlowDefinitionController extends BaseController {
  44. @Autowired
  45. private IFlowDefinitionService flowDefinitionService;
  46. @Autowired
  47. private ISysUserService userService;
  48. @Resource
  49. private ISysRoleService sysRoleService;
  50. @Resource
  51. private ISysExpressionService sysExpressionService;
  52. @GetMapping(value = "/list")
  53. @ApiOperation(value = "流程定义列表", response = FlowProcDefDto.class)
  54. public AjaxResult list(@ApiParam(value = "当前页码", required = true) @RequestParam Integer pageNum,
  55. @ApiParam(value = "每页条数", required = true) @RequestParam Integer pageSize,
  56. @ApiParam(value = "流程名称", required = false) @RequestParam(required = false) String name) {
  57. return AjaxResult.success(flowDefinitionService.list(name, pageNum, pageSize));
  58. }
  59. @ApiOperation(value = "导入流程文件", notes = "上传bpmn20的xml文件")
  60. @PostMapping("/import")
  61. public AjaxResult importFile(@RequestParam(required = false) String name,
  62. @RequestParam(required = false) String category,
  63. MultipartFile file) {
  64. InputStream in = null;
  65. try {
  66. in = file.getInputStream();
  67. flowDefinitionService.importFile(name, category, in);
  68. } catch (Exception e) {
  69. log.error("导入失败:", e);
  70. return AjaxResult.success(e.getMessage());
  71. } finally {
  72. try {
  73. if (in != null) {
  74. in.close();
  75. }
  76. } catch (IOException e) {
  77. log.error("关闭输入流出错", e);
  78. }
  79. }
  80. return AjaxResult.success("导入成功");
  81. }
  82. @ApiOperation(value = "读取xml文件")
  83. @GetMapping("/readXml/{deployId}")
  84. public AjaxResult readXml(@ApiParam(value = "流程定义id") @PathVariable(value = "deployId") String deployId) {
  85. try {
  86. return flowDefinitionService.readXml(deployId);
  87. } catch (Exception e) {
  88. return AjaxResult.error("加载xml文件异常");
  89. }
  90. }
  91. @ApiOperation(value = "读取图片文件")
  92. @GetMapping("/readImage/{deployId}")
  93. public void readImage(@ApiParam(value = "流程定义id") @PathVariable(value = "deployId") String deployId, HttpServletResponse response) {
  94. OutputStream os = null;
  95. BufferedImage image = null;
  96. try {
  97. image = ImageIO.read(flowDefinitionService.readImage(deployId));
  98. response.setContentType("image/png");
  99. os = response.getOutputStream();
  100. if (image != null) {
  101. ImageIO.write(image, "png", os);
  102. }
  103. } catch (Exception e) {
  104. e.printStackTrace();
  105. } finally {
  106. try {
  107. if (os != null) {
  108. os.flush();
  109. os.close();
  110. }
  111. } catch (IOException e) {
  112. e.printStackTrace();
  113. }
  114. }
  115. }
  116. @ApiOperation(value = "保存流程设计器内的xml文件")
  117. @PostMapping("/save")
  118. public AjaxResult save(@RequestBody FlowSaveXmlVo vo) {
  119. InputStream in = null;
  120. try {
  121. in = new ByteArrayInputStream(vo.getXml().getBytes(StandardCharsets.UTF_8));
  122. flowDefinitionService.importFile(vo.getName(), vo.getCategory(), in);
  123. } catch (Exception e) {
  124. log.error("导入失败:", e);
  125. return AjaxResult.error(e.getMessage());
  126. } finally {
  127. try {
  128. if (in != null) {
  129. in.close();
  130. }
  131. } catch (IOException e) {
  132. log.error("关闭输入流出错", e);
  133. }
  134. }
  135. return AjaxResult.success("导入成功");
  136. }
  137. /*@ApiOperation(value = "发起流程")
  138. @PostMapping("/start/{procDefId}")
  139. public AjaxResult start(@ApiParam(value = "流程定义id") @PathVariable(value = "procDefId") String procDefId,
  140. @ApiParam(value = "变量集合,json对象") @RequestBody Map<String, Object> variables) {
  141. return flowDefinitionService.startProcessInstanceById(procDefId, variables);
  142. }*/
  143. @ApiOperation(value = "发起流程")
  144. @PostMapping("/start")
  145. public AjaxResult start(@ApiParam(value = "变量集合,json对象") @RequestBody Map<String, Object> variables) {
  146. return flowDefinitionService.startProcessInstanceById("", variables);
  147. }
  148. @ApiOperation(value = "激活或挂起流程定义")
  149. @PutMapping(value = "/updateState")
  150. public AjaxResult updateState(@ApiParam(value = "1:激活,2:挂起", required = true) @RequestParam Integer state,
  151. @ApiParam(value = "流程部署ID", required = true) @RequestParam String deployId) {
  152. flowDefinitionService.updateState(state, deployId);
  153. return AjaxResult.success();
  154. }
  155. @ApiOperation(value = "删除流程")
  156. @DeleteMapping(value = "/{deployIds}")
  157. public AjaxResult delete(@PathVariable String[] deployIds) {
  158. for (String deployId : deployIds) {
  159. flowDefinitionService.delete(deployId);
  160. }
  161. return AjaxResult.success();
  162. }
  163. @ApiOperation(value = "指定流程办理人员列表")
  164. @GetMapping("/userList")
  165. public AjaxResult userList(SysUser user) {
  166. List<SysUser> list = userService.selectUserList(user);
  167. return AjaxResult.success(list);
  168. }
  169. @ApiOperation(value = "指定流程办理组列表")
  170. @GetMapping("/roleList")
  171. public AjaxResult roleList(SysRole role) {
  172. List<SysRole> list = sysRoleService.selectRoleList(role);
  173. return AjaxResult.success(list);
  174. }
  175. @ApiOperation(value = "指定流程达式列表")
  176. @GetMapping("/expList")
  177. public AjaxResult expList(SysExpression sysExpression) {
  178. List<SysExpression> list = sysExpressionService.selectSysExpressionList(sysExpression);
  179. return AjaxResult.success(list);
  180. }
  181. }