Browse Source

[fix]:修复流程模型、流程定义功能

dev
youjianchi 10 months ago
parent
commit
6a969b946c
  1. 90
      ruoyi-activiti/src/main/java/com/ruoyi/process/definition/controller/ProcessDefinitionController.java
  2. 11
      ruoyi-activiti/src/main/java/com/ruoyi/process/definition/service/ProcessDefinitionService.java
  3. 17
      ruoyi-activiti/src/main/resources/templates/process/definition/definition.html
  4. 3
      ruoyi-admin/src/main/resources/application.yml

90
ruoyi-activiti/src/main/java/com/ruoyi/process/definition/controller/ProcessDefinitionController.java

@ -1,6 +1,8 @@
package com.ruoyi.process.definition.controller;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.config.RuoYiConfig;
import com.ruoyi.common.constant.Constants;
@ -13,6 +15,14 @@ import com.ruoyi.common.utils.file.FileUploadUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.process.definition.domain.ProcessDefinition;
import com.ruoyi.process.definition.service.ProcessDefinitionService;
import org.activiti.bpmn.converter.BpmnXMLConverter;
import org.activiti.bpmn.model.BpmnModel;
import org.activiti.editor.constants.ModelDataJsonConstants;
import org.activiti.editor.language.json.converter.BpmnJsonConverter;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.repository.Model;
import org.activiti.engine.repository.ProcessDefinitionQuery;
import org.apache.ibatis.annotations.Param;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -21,6 +31,13 @@ import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.List;
@Controller
@ -34,6 +51,9 @@ public class ProcessDefinitionController extends BaseController {
@Autowired
private ProcessDefinitionService processDefinitionService;
@Autowired
private RepositoryService repositoryService;
@RequiresPermissions("process:definition:view")
@GetMapping
public String processDefinition() {
@ -104,4 +124,74 @@ public class ProcessDefinitionController extends BaseController {
return util.exportExcel(list, "流程定义数据");
}
@PostMapping( "/suspendOrActiveApply")
@ResponseBody
public AjaxResult suspendOrActiveApply(String id, String suspendState) {
processDefinitionService.suspendOrActiveApply(id, suspendState);
return success();
}
/**
* 读取流程资源
*
* @param processDefinitionId 流程定义ID
* @param resourceName 资源名称
*/
@RequestMapping(value = "/readResource")
public void readResource(@RequestParam("pdid") String processDefinitionId, @RequestParam("resourceName") String resourceName, HttpServletResponse response)
throws Exception {
ProcessDefinitionQuery pdq = repositoryService.createProcessDefinitionQuery();
org.activiti.engine.repository.ProcessDefinition pd = pdq.processDefinitionId(processDefinitionId).singleResult();
// 通过接口读取
InputStream resourceAsStream = repositoryService.getResourceAsStream(pd.getDeploymentId(), resourceName);
// 输出资源内容到相应对象
byte[] b = new byte[1024];
int len = -1;
while ((len = resourceAsStream.read(b, 0, 1024)) != -1) {
response.getOutputStream().write(b, 0, len);
}
}
/**
* 转换流程定义为模型
* @param processDefinitionId
* @return
* @throws UnsupportedEncodingException
* @throws XMLStreamException
*/
@PostMapping(value = "/convert2Model")
@ResponseBody
public AjaxResult convertToModel(@Param("processDefinitionId") String processDefinitionId)
throws UnsupportedEncodingException, XMLStreamException {
org.activiti.engine.repository.ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery()
.processDefinitionId(processDefinitionId).singleResult();
InputStream bpmnStream = repositoryService.getResourceAsStream(processDefinition.getDeploymentId(),
processDefinition.getResourceName());
XMLInputFactory xif = XMLInputFactory.newInstance();
InputStreamReader in = new InputStreamReader(bpmnStream, "UTF-8");
XMLStreamReader xtr = xif.createXMLStreamReader(in);
BpmnModel bpmnModel = new BpmnXMLConverter().convertToBpmnModel(xtr);
BpmnJsonConverter converter = new BpmnJsonConverter();
ObjectNode modelNode = converter.convertToJson(bpmnModel);
Model modelData = repositoryService.newModel();
modelData.setKey(processDefinition.getKey());
modelData.setName(processDefinition.getResourceName());
modelData.setCategory(processDefinition.getDeploymentId());
ObjectNode modelObjectNode = new ObjectMapper().createObjectNode();
modelObjectNode.put(ModelDataJsonConstants.MODEL_NAME, processDefinition.getName());
modelObjectNode.put(ModelDataJsonConstants.MODEL_REVISION, 1);
modelObjectNode.put(ModelDataJsonConstants.MODEL_DESCRIPTION, processDefinition.getDescription());
modelData.setMetaInfo(modelObjectNode.toString());
repositoryService.saveModel(modelData);
repositoryService.addModelEditorSource(modelData.getId(), modelNode.toString().getBytes("utf-8"));
return success();
}
}

11
ruoyi-activiti/src/main/java/com/ruoyi/process/definition/service/ProcessDefinitionService.java

@ -140,4 +140,15 @@ public class ProcessDefinitionService {
return counter;
}
public void suspendOrActiveApply(String id, String suspendState) {
if ("1".equals(suspendState)) {
// 当流程定义被挂起时,已经发起的该流程定义的流程实例不受影响(如果选择级联挂起则流程实例也会被挂起)。
// 当流程定义被挂起时,无法发起新的该流程定义的流程实例。
// 直观变化:act_re_procdef 的 SUSPENSION_STATE_ 为 2
repositoryService.suspendProcessDefinitionById(id);
} else if ("2".equals(suspendState)) {
repositoryService.activateProcessDefinitionById(id);
}
}
}

17
ruoyi-activiti/src/main/resources/templates/process/definition/definition.html

@ -112,6 +112,7 @@
formatter: function(value, row, index) {
var actions = [];
actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.deploymentId + '\')"><i class="fa fa-remove"></i> 删除</a>');
actions.push('<a class="btn btn-primary btn-xs" href="javascript:void(0)" onclick="convert2Model(\'' + row.id + '\')"><i class="fa fa-exchange"></i> 转模型</a>');
return actions.join('');
}
}]
@ -139,6 +140,22 @@
})
});
}
function suspendOrActiveApply(id, suspendState) {
var suspendOrActive = suspendState === '2' ? '激活' : '挂起' ;
$.modal.confirm("确认要" + suspendOrActive + "流程定义吗?", function() {
var url = prefix + "/suspendOrActiveApply";
var data = { "id": id, "suspendState": suspendState };
$.operate.submit(url, "post", "json", data);
});
}
function convert2Model(id) {
$.modal.confirm("确认要转换成流程模型吗?", function() {
var url = prefix + "/convert2Model";
var data = { "processDefinitionId": id };
$.operate.submit(url, "post", "json", data);
});
}
</script>
</body>

3
ruoyi-admin/src/main/resources/application.yml

@ -10,7 +10,8 @@ ruoyi:
demoEnabled: false
# 文件路径 示例( Windows配置c:/ruoyi/uploadPath,Linux配置 /home/ruoyi/uploadPath)
# profile: /Users/xiguniang/Documents/ruoyi/uploadPath
profile: /home/ruoyi/uploadPath
# profile: /home/ruoyi/uploadPath
profile: D:/ruoyi/uploadPath
# 获取ip地址开关
addressEnabled: false

Loading…
Cancel
Save