|
@@ -17,6 +17,7 @@ import org.apache.commons.io.FilenameUtils;
|
|
|
import org.hsweb.ezorm.core.PropertyWrapper;
|
|
|
import org.hsweb.ezorm.core.SimplePropertyWrapper;
|
|
|
import org.hsweb.ezorm.core.param.TermType;
|
|
|
+import org.hswebframework.web.NotFoundException;
|
|
|
import org.hswebframework.web.commons.entity.PagerResult;
|
|
|
import org.hswebframework.web.commons.entity.param.QueryParamEntity;
|
|
|
import org.hswebframework.web.controller.message.ResponseMessage;
|
|
@@ -25,6 +26,7 @@ import org.hswebframework.web.workflow.flowable.service.BpmProcessService;
|
|
|
import org.hswebframework.web.workflow.flowable.service.BpmTaskService;
|
|
|
import org.hswebframework.web.workflow.flowable.utils.FlowableAbstract;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.util.StreamUtils;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
@@ -32,10 +34,14 @@ import javax.servlet.http.HttpServletResponse;
|
|
|
import javax.xml.stream.XMLInputFactory;
|
|
|
import javax.xml.stream.XMLStreamException;
|
|
|
import javax.xml.stream.XMLStreamReader;
|
|
|
+import java.io.IOException;
|
|
|
import java.io.InputStream;
|
|
|
import java.io.InputStreamReader;
|
|
|
import java.io.UnsupportedEncodingException;
|
|
|
+import java.util.Collections;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
import java.util.zip.ZipInputStream;
|
|
|
|
|
|
/**
|
|
@@ -43,26 +49,26 @@ import java.util.zip.ZipInputStream;
|
|
|
* @Date 2017/8/10.
|
|
|
*/
|
|
|
@RestController
|
|
|
-@RequestMapping("/workflow/procDef")
|
|
|
+@RequestMapping("/workflow/process/definition")
|
|
|
public class FlowableDeploymentController extends FlowableAbstract {
|
|
|
|
|
|
- private final static String MODEL_ID = "modelId";
|
|
|
- private final static String MODEL_NAME = "name";
|
|
|
- private final static String MODEL_REVISION = "revision";
|
|
|
+ private final static String MODEL_ID = "modelId";
|
|
|
+ private final static String MODEL_NAME = "name";
|
|
|
+ private final static String MODEL_REVISION = "revision";
|
|
|
private final static String MODEL_DESCRIPTION = "description";
|
|
|
- private final static String MODEL_KEY = "key";
|
|
|
+ private final static String MODEL_KEY = "key";
|
|
|
|
|
|
@Autowired
|
|
|
- BpmTaskService bpmTaskService;
|
|
|
+ BpmTaskService bpmTaskService;
|
|
|
@Autowired
|
|
|
- BpmProcessService bpmProcessService;
|
|
|
+ BpmProcessService bpmProcessService;
|
|
|
@Autowired
|
|
|
BpmActivityService bpmActivityService;
|
|
|
|
|
|
/**
|
|
|
* 流程定义列表
|
|
|
*/
|
|
|
- @GetMapping("/list")
|
|
|
+ @GetMapping
|
|
|
public ResponseMessage<PagerResult<ProcessDefinition>> processList(QueryParamEntity param) {
|
|
|
ProcessDefinitionQuery processDefinitionQuery = repositoryService.createProcessDefinitionQuery();
|
|
|
param.getTerms().forEach((term) -> {
|
|
@@ -97,16 +103,15 @@ public class FlowableDeploymentController extends FlowableAbstract {
|
|
|
param.rePaging(total);
|
|
|
List<ProcessDefinition> models = processDefinitionQuery.listPage(param.getPageIndex(), param.getPageSize() * (param.getPageIndex() + 1));
|
|
|
return ResponseMessage.ok(new PagerResult<>(total, models))
|
|
|
- .exclude(ProcessDefinitionEntity.class,"identityLinks");
|
|
|
+ .exclude(ProcessDefinitionEntity.class, "identityLinks");
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 部署流程资源
|
|
|
* 加载ZIP文件中的流程
|
|
|
*/
|
|
|
- @RequestMapping(value="/deploy")
|
|
|
- public String deploy(@RequestParam(value = "file", required = true) MultipartFile file) {
|
|
|
-
|
|
|
+ @PostMapping(value = "/deploy")
|
|
|
+ public ResponseMessage<Object> deploy(@RequestParam(value = "file") MultipartFile file) {
|
|
|
// 获取上传的文件名
|
|
|
String fileName = file.getOriginalFilename();
|
|
|
|
|
@@ -131,7 +136,7 @@ public class FlowableDeploymentController extends FlowableAbstract {
|
|
|
// logger.error("部署流程错误,获取文件流失败");
|
|
|
}
|
|
|
|
|
|
- return "redirect:list";
|
|
|
+ return ResponseMessage.ok();
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -140,21 +145,23 @@ public class FlowableDeploymentController extends FlowableAbstract {
|
|
|
* @param processDefinitionId 流程定义ID
|
|
|
* @param resourceName 资源名称
|
|
|
*/
|
|
|
- @GetMapping(value = "/read-resource")
|
|
|
- public void readResource(@RequestParam("pdid") String processDefinitionId, @RequestParam("resourceName") String resourceName, HttpServletResponse response)
|
|
|
+ @GetMapping(value = "/{processDefinitionId}/resource/{resourceName}")
|
|
|
+ public void readResource(@PathVariable String processDefinitionId
|
|
|
+ , @PathVariable String resourceName, HttpServletResponse response)
|
|
|
throws Exception {
|
|
|
ProcessDefinitionQuery pdq = repositoryService.createProcessDefinitionQuery();
|
|
|
ProcessDefinition pd = pdq.processDefinitionId(processDefinitionId).singleResult();
|
|
|
|
|
|
// 通过接口读取
|
|
|
InputStream resourceAsStream = repositoryService.getResourceAsStream(pd.getDeploymentId(), resourceName);
|
|
|
+ StreamUtils.copy(resourceAsStream, response.getOutputStream());
|
|
|
|
|
|
- // 输出资源内容到相应对象
|
|
|
- byte[] b = new byte[1024];
|
|
|
- int len = -1;
|
|
|
- while ((len = resourceAsStream.read(b, 0, 1024)) != -1) {
|
|
|
- response.getOutputStream().write(b, 0, len);
|
|
|
- }
|
|
|
+// // 输出资源内容到相应对象
|
|
|
+// byte[] b = new byte[1024];
|
|
|
+// int len = -1;
|
|
|
+// while ((len = resourceAsStream.read(b, 0, 1024)) != -1) {
|
|
|
+// response.getOutputStream().write(b, 0, len);
|
|
|
+// }
|
|
|
}
|
|
|
|
|
|
/***
|
|
@@ -164,11 +171,13 @@ public class FlowableDeploymentController extends FlowableAbstract {
|
|
|
* @throws UnsupportedEncodingException
|
|
|
* @throws XMLStreamException
|
|
|
*/
|
|
|
- @RequestMapping(value = "/convert-to-model/{processDefinitionId}")
|
|
|
- public ResponseMessage<String> convertToModel(@PathVariable("processDefinitionId") String processDefinitionId)
|
|
|
+ @PutMapping(value = "/convert-to-model/{processDefinitionId}")
|
|
|
+ public ResponseMessage<Map<String, Object>> convertToModel(@PathVariable("processDefinitionId") String processDefinitionId)
|
|
|
throws UnsupportedEncodingException, XMLStreamException {
|
|
|
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery()
|
|
|
.processDefinitionId(processDefinitionId).singleResult();
|
|
|
+ if (null == processDefinition)
|
|
|
+ throw new NotFoundException();
|
|
|
InputStream bpmnStream = repositoryService.getResourceAsStream(processDefinition.getDeploymentId(),
|
|
|
processDefinition.getResourceName());
|
|
|
XMLInputFactory xif = XMLInputFactory.newInstance();
|
|
@@ -180,7 +189,7 @@ public class FlowableDeploymentController extends FlowableAbstract {
|
|
|
com.fasterxml.jackson.databind.node.ObjectNode modelNode = converter.convertToJson(bpmnModel);
|
|
|
org.activiti.engine.repository.Model modelData = repositoryService.newModel();
|
|
|
modelData.setKey(processDefinition.getKey());
|
|
|
- modelData.setName(processDefinition.getResourceName().substring(0,processDefinition.getResourceName().indexOf(".")));
|
|
|
+ modelData.setName(processDefinition.getResourceName().substring(0, processDefinition.getResourceName().indexOf(".")));
|
|
|
modelData.setCategory(processDefinition.getDeploymentId());
|
|
|
|
|
|
ObjectNode modelObjectNode = new ObjectMapper().createObjectNode();
|
|
@@ -192,9 +201,7 @@ public class FlowableDeploymentController extends FlowableAbstract {
|
|
|
repositoryService.saveModel(modelData);
|
|
|
|
|
|
repositoryService.addModelEditorSource(modelData.getId(), modelNode.toString().getBytes("utf-8"));
|
|
|
- JSONObject jsonObject = new JSONObject();
|
|
|
- jsonObject.put(MODEL_ID,modelData.getId());
|
|
|
- return ResponseMessage.ok(jsonObject.toJSONString());
|
|
|
+ return ResponseMessage.ok(Collections.singletonMap(MODEL_ID, modelData.getId()));
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -202,65 +209,55 @@ public class FlowableDeploymentController extends FlowableAbstract {
|
|
|
*
|
|
|
* @param deploymentId 流程部署ID
|
|
|
*/
|
|
|
- @RequestMapping(value = "/delete-deployment")
|
|
|
- public String deleteProcessDefinition(@RequestParam("deploymentId") String deploymentId) {
|
|
|
- repositoryService.deleteDeployment(deploymentId);
|
|
|
- return "redirect:index";
|
|
|
+ @DeleteMapping(value = "/deployment/{deploymentId}")
|
|
|
+ public ResponseMessage<String> deleteProcessDefinition(
|
|
|
+ @PathVariable("deploymentId") String deploymentId
|
|
|
+ , @RequestParam(defaultValue = "false") boolean cascade) {
|
|
|
+ repositoryService.deleteDeployment(deploymentId, cascade);
|
|
|
+ return ResponseMessage.ok();
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 删除部署的流程,级联删除流程实例
|
|
|
- *
|
|
|
- * @param deploymentId 流程部署ID
|
|
|
- */
|
|
|
- @RequestMapping(value = "/delete-deploy")
|
|
|
- public String deleteProcess(@RequestParam("deploymentId") String deploymentId) {
|
|
|
- repositoryService.deleteDeployment(deploymentId, true);
|
|
|
- return "redirect:index";
|
|
|
- }
|
|
|
+// /**
|
|
|
+// * 删除部署的流程,级联删除流程实例
|
|
|
+// *
|
|
|
+// * @param deploymentId 流程部署ID
|
|
|
+// */
|
|
|
+// @DeleteMapping(value = "/deploy")
|
|
|
+// public ResponseMessage<String> deleteProcess(@RequestParam("deploymentId") String deploymentId) {
|
|
|
+// repositoryService.deleteDeployment(deploymentId, true);
|
|
|
+// return ResponseMessage.ok();
|
|
|
+// }
|
|
|
|
|
|
/**
|
|
|
* 查看当前节点流程图
|
|
|
+ *
|
|
|
* @param processInstanceId
|
|
|
- * @return 当前节点
|
|
|
- * window.open('/showImage?processInstanceId=' + processInstanceId, 'newwindow', 'height=500, width=1000, top=100,left=200, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no');
|
|
|
- * <div>
|
|
|
- <#if message??>
|
|
|
- <h1>${message!}</h1>
|
|
|
- <#else>
|
|
|
- <img src="${application.getContextPath()}/workflow/document/alldoc/findPic/${procDefId!}">
|
|
|
- <!-- 给执行的节点加框 -->
|
|
|
- <div style="position:absolute; border:2px solid red;left:${activity.x+6 }px;
|
|
|
- top:${activity.y+6 }px;width:${activity.width }px;height:${activity.height }px;"></div>
|
|
|
- </#if>
|
|
|
- </div>
|
|
|
+ * @return 当前节点
|
|
|
*/
|
|
|
- @GetMapping("/showImage/{processInstanceId}")
|
|
|
- public Object showImage(@PathVariable String processInstanceId){
|
|
|
- JSONObject jsonObject = new JSONObject();
|
|
|
+ @GetMapping("/{processInstanceId}/activity")
|
|
|
+ public ResponseMessage<Map<String, Object>> getProcessInstanceActivity(@PathVariable String processInstanceId) {
|
|
|
HistoricProcessInstance processInstance = bpmTaskService.selectHisProInst(processInstanceId);
|
|
|
- if(processInstance!=null){
|
|
|
- ActivityImpl activity = bpmActivityService.getActivityByProcInstId(processInstance.getProcessDefinitionId(),processInstance.getId());
|
|
|
- jsonObject.put("activity",activity);
|
|
|
- jsonObject.put("procDefId",processInstance.getProcessDefinitionId());
|
|
|
- }else{
|
|
|
- jsonObject.put("message","获取流程图失败");
|
|
|
-// logger.debug("获取流程节点,processInstanceId:"+processInstanceId);
|
|
|
+ if (processInstance != null) {
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ ActivityImpl activity = bpmActivityService.getActivityByProcInstId(processInstance.getProcessDefinitionId(), processInstance.getId());
|
|
|
+ jsonObject.put("activity", activity);
|
|
|
+ jsonObject.put("procDefId", processInstance.getProcessDefinitionId());
|
|
|
+ return ResponseMessage.ok(jsonObject);
|
|
|
+ } else {
|
|
|
+ throw new NotFoundException("获取流程图失败");
|
|
|
+// jsonObject.put("message", "获取流程图失败");
|
|
|
}
|
|
|
- return jsonObject;
|
|
|
}
|
|
|
|
|
|
- @GetMapping("/findPic/{procDefId}")
|
|
|
- public void findPic(@PathVariable String procDefId,HttpServletResponse response){
|
|
|
- try{
|
|
|
- InputStream inputStream = bpmProcessService.findProcessPic(procDefId);
|
|
|
- byte[] b = new byte[1024];
|
|
|
- int len = 0;
|
|
|
- while ((len = inputStream.read(b,0,1024))!=-1){
|
|
|
- response.getOutputStream().write(b, 0, len);
|
|
|
- }
|
|
|
- }catch (Exception e){
|
|
|
-// logger.debug("获取流程图失败,procDefId:"+procDefId);
|
|
|
- }
|
|
|
+ @GetMapping("/{processInstanceId}/image")
|
|
|
+ public void findPic(@PathVariable String processInstanceId, HttpServletResponse response) throws IOException {
|
|
|
+ InputStream inputStream = bpmProcessService.findProcessPic(processInstanceId);
|
|
|
+ StreamUtils.copy(inputStream, response.getOutputStream());
|
|
|
+
|
|
|
+// byte[] b = new byte[1024];
|
|
|
+// int len;
|
|
|
+// while ((len = inputStream.read(b, 0, 1024)) != -1) {
|
|
|
+// response.getOutputStream().write(b, 0, len);
|
|
|
+// }
|
|
|
}
|
|
|
}
|