流程相关
This commit is contained in:
3
pom.xml
3
pom.xml
@ -817,6 +817,9 @@
|
||||
<includes>
|
||||
<include>**/*.xml</include>
|
||||
<include>**/*.properties</include>
|
||||
<include>**/*.json</include>
|
||||
<include>**/*.bpmn</include>
|
||||
<include>**/*.png</include>
|
||||
</includes>
|
||||
<filtering>false</filtering>
|
||||
</resource>
|
||||
|
||||
@ -10,6 +10,7 @@ import com.sipai.entity.activiti.ProcessType;
|
||||
import com.sipai.entity.activiti.TaskModel;
|
||||
import com.sipai.entity.user.Company;
|
||||
import com.sipai.entity.user.User;
|
||||
import com.sipai.service.activiti.BpmnImportService;
|
||||
import com.sipai.service.activiti.ProcessModelService;
|
||||
import com.sipai.service.business.BusinessUnitService;
|
||||
import com.sipai.service.user.JobService;
|
||||
@ -79,6 +80,8 @@ public class ModelController {
|
||||
@Resource
|
||||
private ProcessModelService processModelService;
|
||||
@Resource
|
||||
private BpmnImportService bpmnImportService;
|
||||
@Resource
|
||||
private BusinessUnitService businessUnitService;
|
||||
@Resource
|
||||
private UnitService unitService;
|
||||
@ -729,23 +732,23 @@ public class ModelController {
|
||||
json.put("businessunit", businessUnitService.selectById(documentation));
|
||||
String resourceId = json.get("resourceId").toString();
|
||||
List<ModelNodeJob> list = this.jobService.selectModelNodeJobListByWhere(" where resource_id='"+resourceId+"' and model_id ='"+modelData.getId()+"' ");
|
||||
String jobNames="";
|
||||
String jobIds = "";
|
||||
if(list != null && list.size()>0){
|
||||
StringBuilder jobNames= new StringBuilder();
|
||||
StringBuilder jobIds = new StringBuilder();
|
||||
if(list != null && !list.isEmpty()){
|
||||
for(int j=0;j<list.size();j++){
|
||||
if(list.get(j)!=null){
|
||||
if(list.get(j).getName() != null && list.get(j).getName() !="" && list.get(j).getName() != "null"){
|
||||
jobNames +=list.get(j).getName()+",";
|
||||
jobIds +=list.get(j).getJobId()+",";
|
||||
jobNames.append(list.get(j).getName()).append(",");
|
||||
jobIds.append(list.get(j).getJobId()).append(",");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
if(jobNames != null && jobNames !=""){
|
||||
json.put("jobNames", jobNames);
|
||||
json.put("jobIds", jobIds);
|
||||
if(!jobNames.toString().isEmpty()){
|
||||
json.put("jobNames", jobNames.toString());
|
||||
json.put("jobIds", jobIds.toString());
|
||||
|
||||
}
|
||||
|
||||
@ -754,13 +757,11 @@ public class ModelController {
|
||||
}
|
||||
}
|
||||
}
|
||||
if(jsonArray != null){
|
||||
String result="{\"total\":"+jsonArray.size()+",\"rows\":"+jsonArray+"}";
|
||||
model.addAttribute("result",result);
|
||||
}
|
||||
|
||||
|
||||
} catch (JsonProcessingException e) {
|
||||
String result = "{\"total\":" + jsonArray.size() + ",\"rows\":" + jsonArray + "}";
|
||||
model.addAttribute("result",result);
|
||||
|
||||
|
||||
} catch (JsonProcessingException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
@ -1046,6 +1047,216 @@ public class ModelController {
|
||||
return "result";
|
||||
}
|
||||
|
||||
// ==================== BPMN文件管理功能 ====================
|
||||
|
||||
|
||||
/**
|
||||
* 显示BPMN文件列表页面
|
||||
*/
|
||||
@RequestMapping("/showBpmnFileList.do")
|
||||
public String showBpmnFileList(HttpServletRequest request, Model model) {
|
||||
return "/activiti/bpmnFileList";
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取BPMN文件列表
|
||||
*/
|
||||
@RequestMapping("/getBpmnFileList.do")
|
||||
public ModelAndView getBpmnFileList(HttpServletRequest request, Model model) {
|
||||
List<Map<String, Object>> bpmnFiles = bpmnImportService.listBpmnFiles();
|
||||
JSONArray json = JSONArray.fromObject(bpmnFiles);
|
||||
String result = "{\"total\":" + bpmnFiles.size() + ",\"rows\":" + json + "}";
|
||||
model.addAttribute("result", result);
|
||||
return new ModelAndView("result");
|
||||
}
|
||||
|
||||
/**
|
||||
* 导入BPMN文件到模型编辑器
|
||||
*/
|
||||
@RequestMapping(value = "/importBpmnFile.do", method = RequestMethod.POST)
|
||||
public String importBpmnFile(HttpServletRequest request, Model model,
|
||||
@RequestParam(value = "bpmnFilePath") String bpmnFilePath,
|
||||
@RequestParam(value = "modelName", required = false) String modelName,
|
||||
@RequestParam(value = "description", required = false) String description,
|
||||
@RequestParam(value = "companyId", required = false) String companyId) {
|
||||
|
||||
// 构建模型Key
|
||||
String modelKey = null;
|
||||
User cu = (User)request.getSession().getAttribute("cu");
|
||||
if (companyId != null && !companyId.isEmpty()) {
|
||||
modelKey = "imported-" + companyId;
|
||||
} else if (cu != null && !cu.getId().equals(CommString.ID_Admin)) {
|
||||
List<Company> companies = unitService.getCompaniesByUserId(cu.getId());
|
||||
if (companies != null && companies.size() > 0) {
|
||||
modelKey = "imported-" + companies.get(0).getId();
|
||||
}
|
||||
}
|
||||
|
||||
String modelId = bpmnImportService.importBpmnFile(bpmnFilePath, modelName, description, modelKey);
|
||||
int result = modelId != null ? 1 : 0;
|
||||
|
||||
JSONObject resObj = new JSONObject();
|
||||
resObj.put("res", result);
|
||||
resObj.put("modelId", modelId);
|
||||
|
||||
model.addAttribute("result", resObj.toString());
|
||||
return "result";
|
||||
}
|
||||
|
||||
/**
|
||||
* 直接部署BPMN文件
|
||||
*/
|
||||
@RequestMapping(value = "/deployBpmnFile.do", method = RequestMethod.POST)
|
||||
public String deployBpmnFile(HttpServletRequest request, Model model,
|
||||
@RequestParam(value = "bpmnFilePath") String bpmnFilePath,
|
||||
@RequestParam(value = "deploymentName", required = false) String deploymentName) {
|
||||
|
||||
String deploymentId = bpmnImportService.deployBpmnFile(bpmnFilePath, deploymentName);
|
||||
int result = deploymentId != null ? 1 : 0;
|
||||
|
||||
JSONObject resObj = new JSONObject();
|
||||
resObj.put("res", result);
|
||||
resObj.put("deploymentId", deploymentId);
|
||||
|
||||
model.addAttribute("result", resObj.toString());
|
||||
return "result";
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传BPMN文件并导入
|
||||
*/
|
||||
@RequestMapping(value = "/uploadBpmnFile.do", method = RequestMethod.POST)
|
||||
public String uploadBpmnFile(@RequestParam MultipartFile[] file, HttpServletRequest request,
|
||||
Model model) {
|
||||
int result = 0;
|
||||
String modelId = null;
|
||||
|
||||
try {
|
||||
// 获取当前用户和公司信息
|
||||
User cu = (User)request.getSession().getAttribute("cu");
|
||||
String processTypeId = request.getParameter("processTypeId");
|
||||
String companyId = request.getParameter("companyId");
|
||||
String maintenanceType = request.getParameter("maintenanceType");
|
||||
|
||||
for (MultipartFile myfile : file) {
|
||||
if (!myfile.isEmpty()) {
|
||||
String originalFilename = myfile.getOriginalFilename();
|
||||
String modelName = originalFilename;
|
||||
if (originalFilename != null && originalFilename.contains(".")) {
|
||||
modelName = originalFilename.substring(0, originalFilename.lastIndexOf("."));
|
||||
}
|
||||
|
||||
// 构建模型Key(格式:processTypeId-companyId-maintenanceType)
|
||||
String modelKey = null;
|
||||
if (companyId != null && !companyId.isEmpty()) {
|
||||
StringBuilder keyBuilder = new StringBuilder();
|
||||
if (processTypeId != null && !processTypeId.isEmpty()) {
|
||||
keyBuilder.append(processTypeId);
|
||||
} else {
|
||||
keyBuilder.append("imported");
|
||||
}
|
||||
keyBuilder.append("-").append(companyId);
|
||||
if (maintenanceType != null && !maintenanceType.isEmpty()) {
|
||||
keyBuilder.append("-").append(maintenanceType);
|
||||
}
|
||||
modelKey = keyBuilder.toString();
|
||||
} else if (cu != null && !cu.getId().equals(CommString.ID_Admin)) {
|
||||
// 非管理员用户,自动关联其所属公司
|
||||
List<Company> companies = unitService.getCompaniesByUserId(cu.getId());
|
||||
if (companies != null && companies.size() > 0) {
|
||||
modelKey = "imported-" + companies.get(0).getId();
|
||||
}
|
||||
}
|
||||
|
||||
modelId = bpmnImportService.importBpmnFromInputStream(
|
||||
myfile.getInputStream(), modelName, "Uploaded from " + originalFilename, modelKey);
|
||||
|
||||
if (modelId != null) {
|
||||
result = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("Error uploading BPMN file", e);
|
||||
}
|
||||
|
||||
JSONObject resObj = new JSONObject();
|
||||
resObj.put("res", result);
|
||||
resObj.put("modelId", modelId);
|
||||
|
||||
model.addAttribute("result", resObj.toString());
|
||||
return "result";
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取BPMN文件内容
|
||||
*/
|
||||
@RequestMapping("/getBpmnFileContent.do")
|
||||
public void getBpmnFileContent(HttpServletRequest request, HttpServletResponse response,
|
||||
@RequestParam(value = "bpmnFilePath") String bpmnFilePath) {
|
||||
try {
|
||||
String content = bpmnImportService.getBpmnFileContent(bpmnFilePath);
|
||||
if (content != null) {
|
||||
response.setContentType("application/xml");
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
response.getWriter().write(content);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("Error getting BPMN file content", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量导入所有BPMN文件到模型
|
||||
*/
|
||||
@RequestMapping(value = "/importAllBpmnFiles.do", method = RequestMethod.POST)
|
||||
public String importAllBpmnFiles(HttpServletRequest request, Model model) {
|
||||
List<Map<String, Object>> bpmnFiles = bpmnImportService.listBpmnFiles();
|
||||
int successCount = 0;
|
||||
int failCount = 0;
|
||||
List<String> importedModels = new ArrayList<>();
|
||||
|
||||
for (Map<String, Object> fileInfo : bpmnFiles) {
|
||||
String path = (String) fileInfo.get("path");
|
||||
String processName = (String) fileInfo.get("processName");
|
||||
String processId = (String) fileInfo.get("processId");
|
||||
|
||||
// 提取相对路径
|
||||
String relativePath = path;
|
||||
if (path != null && path.contains("diagrams/")) {
|
||||
relativePath = path.substring(path.indexOf("diagrams/") + 9);
|
||||
}
|
||||
|
||||
String modelName = processName != null ? processName : fileInfo.get("filename").toString();
|
||||
String modelId = bpmnImportService.importBpmnFile(relativePath, modelName, "");
|
||||
|
||||
if (modelId != null) {
|
||||
successCount++;
|
||||
importedModels.add(modelName + ":" + modelId);
|
||||
} else {
|
||||
failCount++;
|
||||
}
|
||||
}
|
||||
|
||||
JSONObject resObj = new JSONObject();
|
||||
resObj.put("res", 1);
|
||||
resObj.put("successCount", successCount);
|
||||
resObj.put("failCount", failCount);
|
||||
resObj.put("importedModels", importedModels);
|
||||
|
||||
model.addAttribute("result", resObj.toString());
|
||||
return "result";
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示流程编辑器页面(整合的编辑页面)
|
||||
*/
|
||||
@RequestMapping("/showFlowEditor.do")
|
||||
public String showFlowEditor(HttpServletRequest request, Model model) {
|
||||
String modelId = request.getParameter("modelId");
|
||||
if (modelId != null && !modelId.isEmpty()) {
|
||||
org.activiti.engine.repository.Model modelData = repositoryService.getModel(modelId);
|
||||
model.addAttribute("modelData", modelData);
|
||||
}
|
||||
return "/activiti/flowEditor";
|
||||
}
|
||||
}
|
||||
|
||||
367
src/main/java/com/sipai/service/activiti/BpmnImportService.java
Normal file
367
src/main/java/com/sipai/service/activiti/BpmnImportService.java
Normal file
@ -0,0 +1,367 @@
|
||||
package com.sipai.service.activiti;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
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.Deployment;
|
||||
import org.activiti.engine.repository.Model;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.xml.stream.XMLInputFactory;
|
||||
import javax.xml.stream.XMLStreamReader;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* BPMN文件导入服务
|
||||
* 用于导入现有的BPMN文件到Activiti模型编辑器
|
||||
*
|
||||
* @author system
|
||||
*/
|
||||
@Service
|
||||
public class BpmnImportService {
|
||||
|
||||
protected Logger logger = LoggerFactory.getLogger(getClass());
|
||||
|
||||
@Autowired
|
||||
protected RepositoryService repositoryService;
|
||||
|
||||
// BPMN文件存储的基础路径(文件系统路径)
|
||||
private static final String DIAGRAMS_BASE_PATH = "src/main/resources/diagrams";
|
||||
|
||||
/**
|
||||
* 获取所有BPMN文件列表
|
||||
*/
|
||||
public List<Map<String, Object>> listBpmnFiles() {
|
||||
List<Map<String, Object>> result = new ArrayList<>();
|
||||
|
||||
// 首先尝试从文件系统读取
|
||||
File diagramsDir = new File(DIAGRAMS_BASE_PATH);
|
||||
if (diagramsDir.exists() && diagramsDir.isDirectory()) {
|
||||
listBpmnFilesFromFileSystem(diagramsDir, "", result);
|
||||
if (!result.isEmpty()) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
// 如果文件系统路径不存在,尝试从classpath读取
|
||||
try {
|
||||
PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
|
||||
Resource[] resources = resolver.getResources("classpath:diagrams/**/*.bpmn");
|
||||
|
||||
for (Resource resource : resources) {
|
||||
Map<String, Object> fileInfo = new HashMap<>();
|
||||
String filename = resource.getFilename();
|
||||
String path = resource.getURL().getPath();
|
||||
|
||||
fileInfo.put("filename", filename);
|
||||
fileInfo.put("path", path);
|
||||
fileInfo.put("size", resource.contentLength());
|
||||
fileInfo.put("lastModified", System.currentTimeMillis());
|
||||
|
||||
// 尝试解析BPMN获取流程名称
|
||||
try (InputStream is = resource.getInputStream()) {
|
||||
BpmnModel model = parseBpmnFromInputStream(is);
|
||||
if (model != null && model.getMainProcess() != null) {
|
||||
fileInfo.put("processId", model.getMainProcess().getId());
|
||||
fileInfo.put("processName", model.getMainProcess().getName());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.warn("Failed to parse BPMN file: {}", filename);
|
||||
}
|
||||
|
||||
result.add(fileInfo);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.warn("Could not load BPMN files from classpath, trying file system: {}", e.getMessage());
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 从文件系统递归获取BPMN文件列表
|
||||
*/
|
||||
private void listBpmnFilesFromFileSystem(File dir, String relativePath, List<Map<String, Object>> result) {
|
||||
File[] files = dir.listFiles();
|
||||
if (files == null) return;
|
||||
|
||||
for (File file : files) {
|
||||
if (file.isDirectory()) {
|
||||
listBpmnFilesFromFileSystem(file, relativePath + file.getName() + "/", result);
|
||||
} else if (file.getName().endsWith(".bpmn")) {
|
||||
Map<String, Object> fileInfo = new HashMap<>();
|
||||
fileInfo.put("filename", file.getName());
|
||||
fileInfo.put("path", relativePath + file.getName());
|
||||
fileInfo.put("size", file.length());
|
||||
fileInfo.put("lastModified", file.lastModified());
|
||||
|
||||
// 尝试解析BPMN获取流程名称
|
||||
try (InputStream is = new FileInputStream(file)) {
|
||||
BpmnModel model = parseBpmnFromInputStream(is);
|
||||
if (model != null && model.getMainProcess() != null) {
|
||||
fileInfo.put("processId", model.getMainProcess().getId());
|
||||
fileInfo.put("processName", model.getMainProcess().getName());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.warn("Failed to parse BPMN file: {}", file.getName());
|
||||
}
|
||||
|
||||
result.add(fileInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 从classpath路径导入BPMN文件创建模型
|
||||
*
|
||||
* @param bpmnFilePath BPMN文件路径(相对于diagrams目录)
|
||||
* @param modelName 模型名称
|
||||
* @param description 模型描述
|
||||
* @return 模型ID
|
||||
*/
|
||||
public String importBpmnFile(String bpmnFilePath, String modelName, String description) {
|
||||
return importBpmnFile(bpmnFilePath, modelName, description, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 从classpath路径导入BPMN文件创建模型(带自定义Key)
|
||||
*
|
||||
* @param bpmnFilePath BPMN文件路径(相对于diagrams目录)
|
||||
* @param modelName 模型名称
|
||||
* @param description 模型描述
|
||||
* @param modelKey 模型Key(格式:processTypeId-companyId-maintenanceType)
|
||||
* @return 模型ID
|
||||
*/
|
||||
public String importBpmnFile(String bpmnFilePath, String modelName, String description, String modelKey) {
|
||||
InputStream is = null;
|
||||
try {
|
||||
// 首先尝试从文件系统读取
|
||||
File file = new File(DIAGRAMS_BASE_PATH + "/" + bpmnFilePath);
|
||||
if (file.exists()) {
|
||||
is = new FileInputStream(file);
|
||||
} else {
|
||||
// 如果文件系统不存在,尝试从classpath读取
|
||||
PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
|
||||
Resource resource = resolver.getResource("classpath:diagrams/" + bpmnFilePath);
|
||||
if (resource.exists()) {
|
||||
is = resource.getInputStream();
|
||||
}
|
||||
}
|
||||
|
||||
if (is == null) {
|
||||
logger.error("BPMN file not found: {}", bpmnFilePath);
|
||||
return null;
|
||||
}
|
||||
|
||||
return importBpmnFromInputStream(is, modelName, description, modelKey);
|
||||
} catch (Exception e) {
|
||||
logger.error("Error importing BPMN file: {}", bpmnFilePath, e);
|
||||
return null;
|
||||
} finally {
|
||||
if (is != null) {
|
||||
try { is.close(); } catch (Exception e) { }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 从输入流导入BPMN创建模型
|
||||
*
|
||||
* @param inputStream BPMN文件输入流
|
||||
* @param modelName 模型名称
|
||||
* @param description 模型描述
|
||||
* @return 模型ID
|
||||
*/
|
||||
public String importBpmnFromInputStream(InputStream inputStream, String modelName, String description) {
|
||||
return importBpmnFromInputStream(inputStream, modelName, description, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 从输入流导入BPMN创建模型(带自定义Key)
|
||||
*
|
||||
* @param inputStream BPMN文件输入流
|
||||
* @param modelName 模型名称
|
||||
* @param description 模型描述
|
||||
* @param modelKey 模型Key(格式:processTypeId-companyId-maintenanceType)
|
||||
* @return 模型ID
|
||||
*/
|
||||
public String importBpmnFromInputStream(InputStream inputStream, String modelName, String description, String modelKey) {
|
||||
try {
|
||||
// 解析BPMN XML
|
||||
BpmnModel bpmnModel = parseBpmnFromInputStream(inputStream);
|
||||
if (bpmnModel == null) {
|
||||
logger.error("Failed to parse BPMN model");
|
||||
return null;
|
||||
}
|
||||
|
||||
// 获取流程信息
|
||||
String processId = bpmnModel.getMainProcess().getId();
|
||||
String processName = bpmnModel.getMainProcess().getName();
|
||||
if (modelName == null || modelName.isEmpty()) {
|
||||
modelName = processName != null ? processName : processId;
|
||||
}
|
||||
|
||||
// 转换为JSON格式
|
||||
BpmnJsonConverter jsonConverter = new BpmnJsonConverter();
|
||||
ObjectNode modelNode = jsonConverter.convertToJson(bpmnModel);
|
||||
|
||||
// 创建模型
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
ObjectNode editorNode = objectMapper.createObjectNode();
|
||||
editorNode.put("id", "canvas");
|
||||
editorNode.put("resourceId", "canvas");
|
||||
|
||||
ObjectNode stencilSetNode = objectMapper.createObjectNode();
|
||||
stencilSetNode.put("namespace", "http://b3mn.org/stencilset/bpmn2.0#");
|
||||
editorNode.put("stencilset", stencilSetNode);
|
||||
|
||||
// 合并转换后的模型数据
|
||||
editorNode.setAll(modelNode);
|
||||
|
||||
// 创建模型元数据
|
||||
Model modelData = repositoryService.newModel();
|
||||
ObjectNode modelObjectNode = objectMapper.createObjectNode();
|
||||
modelObjectNode.put(ModelDataJsonConstants.MODEL_NAME, modelName);
|
||||
modelObjectNode.put(ModelDataJsonConstants.MODEL_REVISION, 1);
|
||||
modelObjectNode.put(ModelDataJsonConstants.MODEL_DESCRIPTION,
|
||||
description != null ? description : "");
|
||||
modelData.setMetaInfo(modelObjectNode.toString());
|
||||
modelData.setName(modelName);
|
||||
// 如果提供了自定义Key则使用,否则使用processId
|
||||
modelData.setKey(modelKey != null && !modelKey.isEmpty() ? modelKey : processId);
|
||||
|
||||
// 保存模型
|
||||
repositoryService.saveModel(modelData);
|
||||
repositoryService.addModelEditorSource(modelData.getId(),
|
||||
editorNode.toString().getBytes("UTF-8"));
|
||||
|
||||
logger.info("Successfully imported BPMN model: {} with ID: {} and Key: {}", modelName, modelData.getId(), modelData.getKey());
|
||||
return modelData.getId();
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("Error importing BPMN from input stream", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 直接部署BPMN文件
|
||||
*
|
||||
* @param bpmnFilePath BPMN文件路径
|
||||
* @param deploymentName 部署名称
|
||||
* @return 部署ID
|
||||
*/
|
||||
public String deployBpmnFile(String bpmnFilePath, String deploymentName) {
|
||||
try {
|
||||
byte[] bpmnBytes = null;
|
||||
String filename = bpmnFilePath;
|
||||
|
||||
// 首先尝试从文件系统读取
|
||||
File file = new File(DIAGRAMS_BASE_PATH + "/" + bpmnFilePath);
|
||||
if (file.exists()) {
|
||||
try (InputStream is = new FileInputStream(file)) {
|
||||
bpmnBytes = IOUtils.toByteArray(is);
|
||||
filename = file.getName();
|
||||
}
|
||||
} else {
|
||||
// 如果文件系统不存在,尝试从classpath读取
|
||||
PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
|
||||
Resource resource = resolver.getResource("classpath:diagrams/" + bpmnFilePath);
|
||||
if (resource.exists()) {
|
||||
try (InputStream is = resource.getInputStream()) {
|
||||
bpmnBytes = IOUtils.toByteArray(is);
|
||||
filename = resource.getFilename();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (bpmnBytes == null) {
|
||||
logger.error("BPMN file not found: {}", bpmnFilePath);
|
||||
return null;
|
||||
}
|
||||
|
||||
if (deploymentName == null || deploymentName.isEmpty()) {
|
||||
deploymentName = filename;
|
||||
if (deploymentName.endsWith(".bpmn")) {
|
||||
deploymentName = deploymentName.substring(0, deploymentName.length() - 5);
|
||||
}
|
||||
}
|
||||
|
||||
String processName = deploymentName + ".bpmn20.xml";
|
||||
Deployment deployment = repositoryService.createDeployment()
|
||||
.name(deploymentName)
|
||||
.addString(processName, new String(bpmnBytes, "UTF-8"))
|
||||
.deploy();
|
||||
|
||||
logger.info("Successfully deployed BPMN: {} with deployment ID: {}",
|
||||
deploymentName, deployment.getId());
|
||||
return deployment.getId();
|
||||
} catch (Exception e) {
|
||||
logger.error("Error deploying BPMN file: {}", bpmnFilePath, e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析BPMN XML文件
|
||||
*/
|
||||
private BpmnModel parseBpmnFromInputStream(InputStream inputStream) {
|
||||
try {
|
||||
XMLInputFactory xif = XMLInputFactory.newInstance();
|
||||
InputStreamReader in = new InputStreamReader(inputStream, "UTF-8");
|
||||
XMLStreamReader xtr = xif.createXMLStreamReader(in);
|
||||
|
||||
BpmnXMLConverter converter = new BpmnXMLConverter();
|
||||
return converter.convertToBpmnModel(xtr);
|
||||
} catch (Exception e) {
|
||||
logger.error("Error parsing BPMN", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取BPMN文件内容
|
||||
*/
|
||||
public String getBpmnFileContent(String bpmnFilePath) {
|
||||
try {
|
||||
// 首先尝试从文件系统读取
|
||||
File file = new File(DIAGRAMS_BASE_PATH + "/" + bpmnFilePath);
|
||||
if (file.exists()) {
|
||||
try (InputStream is = new FileInputStream(file)) {
|
||||
return IOUtils.toString(is, "UTF-8");
|
||||
}
|
||||
}
|
||||
|
||||
// 如果文件系统不存在,尝试从classpath读取
|
||||
PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
|
||||
Resource resource = resolver.getResource("classpath:diagrams/" + bpmnFilePath);
|
||||
if (resource.exists()) {
|
||||
try (InputStream is = resource.getInputStream()) {
|
||||
return IOUtils.toString(is, "UTF-8");
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
} catch (Exception e) {
|
||||
logger.error("Error reading BPMN file: {}", bpmnFilePath, e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
311
src/main/webapp/jsp/activiti/bpmnFileList.jsp
Normal file
311
src/main/webapp/jsp/activiti/bpmnFileList.jsp
Normal file
@ -0,0 +1,311 @@
|
||||
<%@ page language="java" pageEncoding="UTF-8"%>
|
||||
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
|
||||
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
|
||||
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
|
||||
<%@ page import="com.sipai.entity.base.ServerObject"%>
|
||||
<%@ page import="com.sipai.entity.user.User"%>
|
||||
<%@ page import="com.sipai.entity.user.Company"%>
|
||||
<%@ page import="com.sipai.service.user.UnitService"%>
|
||||
<%@ page import="org.springframework.web.context.WebApplicationContext"%>
|
||||
<%@ page import="org.springframework.web.context.support.WebApplicationContextUtils"%>
|
||||
<%@ page import="java.util.List" %>
|
||||
<%@ taglib uri="http://www.springsecurity.org/jsp" prefix="security"%>
|
||||
<%
|
||||
String contextPath = request.getContextPath();
|
||||
User cu = (User)request.getSession().getAttribute("cu");
|
||||
WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(request.getServletContext());
|
||||
UnitService unitService = (UnitService)ctx.getBean("unitService");
|
||||
List<Company> companies = null;
|
||||
if (cu != null) {
|
||||
companies = unitService.getCompaniesByUserId(cu.getId());
|
||||
}
|
||||
%>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title><%= ServerObject.atttable.get("TOPTITLE")%> - BPMN流程文件管理</title>
|
||||
<jsp:include page="/jsp/inc.jsp"></jsp:include>
|
||||
<script type="text/javascript">
|
||||
var importBpmnFun = function(path, processName) {
|
||||
// 弹出对话框让用户选择公司
|
||||
var companyId = $('#companyIdSelect').val() || '';
|
||||
var companyHtml = '<select id="dialogCompanyId" class="form-control input-sm">';
|
||||
companyHtml += '<option value="">-- 不指定公司 --</option>';
|
||||
$('#companyIdSelect option').each(function() {
|
||||
companyHtml += '<option value="' + $(this).val() + '">' + $(this).text() + '</option>';
|
||||
});
|
||||
companyHtml += '</select>';
|
||||
|
||||
swal({
|
||||
title: '导入BPMN文件',
|
||||
html: '<div class="form-group">' +
|
||||
'<label>模型名称:</label><input type="text" id="dialogModelName" class="form-control input-sm" value="' + (processName || '') + '">' +
|
||||
'</div>' +
|
||||
'<div class="form-group">' +
|
||||
'<label>所属公司:</label>' + companyHtml +
|
||||
'</div>',
|
||||
showCancelButton: true,
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
preConfirm: function() {
|
||||
return new Promise(function(resolve) {
|
||||
resolve({
|
||||
modelName: $('#dialogModelName').val(),
|
||||
companyId: $('#dialogCompanyId').val()
|
||||
});
|
||||
});
|
||||
}
|
||||
}).then(function(result) {
|
||||
if (result && result.value) {
|
||||
$.post(ext.contextPath + '/activiti/workflow/model/importBpmnFile.do', {
|
||||
bpmnFilePath: path,
|
||||
modelName: result.value.modelName,
|
||||
description: "",
|
||||
companyId: result.value.companyId
|
||||
}, function(data) {
|
||||
if (data.res == 1) {
|
||||
showAlert('s', '导入成功!模型ID: ' + data.modelId);
|
||||
$("#table").bootstrapTable('refresh');
|
||||
} else {
|
||||
showAlert('d', '导入失败!');
|
||||
}
|
||||
}, 'json');
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
var deployBpmnFun = function(path, filename) {
|
||||
swal({
|
||||
text: "确定要直接部署此BPMN文件吗?",
|
||||
dangerMode: true,
|
||||
buttons: {
|
||||
cancel: {
|
||||
text: "取消",
|
||||
value: null,
|
||||
visible: true,
|
||||
className: "btn btn-default btn-sm",
|
||||
closeModal: true,
|
||||
},
|
||||
confirm: {
|
||||
text: "确定",
|
||||
value: true,
|
||||
visible: true,
|
||||
className: "btn btn-danger btn-sm",
|
||||
closeModal: true
|
||||
}
|
||||
}
|
||||
}).then(function(willDelete) {
|
||||
if (willDelete) {
|
||||
$.post(ext.contextPath + '/activiti/workflow/model/deployBpmnFile.do', {
|
||||
bpmnFilePath: path,
|
||||
deploymentName: filename
|
||||
}, function(data) {
|
||||
if (data.res == 1) {
|
||||
showAlert('s', '部署成功!部署ID: ' + data.deploymentId);
|
||||
} else {
|
||||
showAlert('d', '部署失败!');
|
||||
}
|
||||
}, 'json');
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
var viewBpmnFun = function(path) {
|
||||
window.open(ext.contextPath + '/activiti/workflow/model/getBpmnFileContent.do?bpmnFilePath=' + encodeURIComponent(path), '_blank');
|
||||
};
|
||||
|
||||
var importAllFun = function() {
|
||||
swal({
|
||||
text: "确定要导入所有BPMN文件到模型编辑器吗?",
|
||||
dangerMode: true,
|
||||
buttons: {
|
||||
cancel: {
|
||||
text: "取消",
|
||||
value: null,
|
||||
visible: true,
|
||||
className: "btn btn-default btn-sm",
|
||||
closeModal: true,
|
||||
},
|
||||
confirm: {
|
||||
text: "确定",
|
||||
value: true,
|
||||
visible: true,
|
||||
className: "btn btn-danger btn-sm",
|
||||
closeModal: true
|
||||
}
|
||||
}
|
||||
}).then(function(willDelete) {
|
||||
if (willDelete) {
|
||||
$.post(ext.contextPath + '/activiti/workflow/model/importAllBpmnFiles.do', {}, function(data) {
|
||||
if (data.res == 1) {
|
||||
showAlert('s', '批量导入完成!成功: ' + data.successCount + ', 失败: ' + data.failCount);
|
||||
$("#table").bootstrapTable('refresh');
|
||||
} else {
|
||||
showAlert('d', '批量导入失败!');
|
||||
}
|
||||
}, 'json');
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
function showTable() {
|
||||
$("#table").bootstrapTable({
|
||||
url: ext.contextPath + '/activiti/workflow/model/getBpmnFileList.do',
|
||||
cache: false,
|
||||
striped: true,
|
||||
pagination: true,
|
||||
pageList: [10, 20, 50],
|
||||
pageSize: 20,
|
||||
pageNumber: 1,
|
||||
sidePagination: 'client',
|
||||
columns: [
|
||||
{
|
||||
field: 'filename',
|
||||
title: '文件名',
|
||||
align: 'left',
|
||||
valign: 'middle'
|
||||
}, {
|
||||
field: 'processId',
|
||||
title: '流程ID',
|
||||
align: 'center',
|
||||
valign: 'middle'
|
||||
}, {
|
||||
field: 'processName',
|
||||
title: '流程名称',
|
||||
align: 'center',
|
||||
valign: 'middle'
|
||||
}, {
|
||||
field: 'path',
|
||||
title: '文件路径',
|
||||
align: 'left',
|
||||
valign: 'middle',
|
||||
formatter: function(value, row) {
|
||||
if (value && value.indexOf('diagrams/') >= 0) {
|
||||
return value.substring(value.indexOf('diagrams/'));
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}, {
|
||||
title: "操作",
|
||||
align: 'center',
|
||||
valign: 'middle',
|
||||
width: 280,
|
||||
formatter: function(value, row, index) {
|
||||
var path = row.path;
|
||||
if (path && path.indexOf('diagrams/') >= 0) {
|
||||
path = path.substring(path.indexOf('diagrams/') + 9);
|
||||
}
|
||||
var str = '';
|
||||
str += '<button class="btn btn-default btn-sm" onclick="importBpmnFun(\'' + path + '\', \'' + (row.processName || row.filename) + '\')" title="导入到模型编辑器"><i class="fa fa-download"></i> 导入</button>';
|
||||
str += '<button class="btn btn-default btn-sm" onclick="deployBpmnFun(\'' + path + '\', \'' + row.filename + '\')" title="直接部署"><i class="fa fa-play"></i> 部署</button>';
|
||||
str += '<button class="btn btn-default btn-sm" onclick="viewBpmnFun(\'' + path + '\')" title="查看XML"><i class="fa fa-eye"></i> 查看</button>';
|
||||
return '<div class="btn-group">' + str + '</div>';
|
||||
}
|
||||
}
|
||||
],
|
||||
onLoadSuccess: function() {
|
||||
adjustBootstrapTableView("table");
|
||||
},
|
||||
onLoadError: function() {
|
||||
console.info("加载数据失败");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 上传BPMN文件
|
||||
var uploadBpmnFun = function() {
|
||||
var formData = new FormData($('#uploadForm')[0]);
|
||||
$.ajax({
|
||||
url: ext.contextPath + '/activiti/workflow/model/uploadBpmnFile.do',
|
||||
type: 'POST',
|
||||
data: formData,
|
||||
processData: false,
|
||||
contentType: false,
|
||||
success: function(data) {
|
||||
if (data.res == 1) {
|
||||
showAlert('s', '上传导入成功!模型ID: ' + data.modelId);
|
||||
window.location.href = ext.contextPath + '/activiti/workflow/model/showModelList.do';
|
||||
} else {
|
||||
showAlert('d', '上传导入失败!');
|
||||
}
|
||||
},
|
||||
error: function() {
|
||||
showAlert('d', '上传失败!');
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
$(function() {
|
||||
showTable();
|
||||
});
|
||||
</script>
|
||||
</head>
|
||||
<body class="hold-transition ${cu.themeclass} sidebar-mini">
|
||||
<div class="wrapper">
|
||||
<div class="content-wrapper">
|
||||
<section class="content container-fluid">
|
||||
<div id="alertDiv"></div>
|
||||
<!-- 隐藏的公司选择器 -->
|
||||
<select id="companyIdSelect" style="display:none;">
|
||||
<% if (companies != null) { for (Company company : companies) { %>
|
||||
<option value="<%= company.getId() %>"><%= company.getName() %></option>
|
||||
<% } } %>
|
||||
</select>
|
||||
|
||||
<div class="form-group" style="padding:0;">
|
||||
<div class="btn-group" style="padding-bottom:10px;">
|
||||
<!-- 上传按钮 -->
|
||||
<button type="button" class="btn btn-success btn-sm" data-toggle="modal" data-target="#uploadModal">
|
||||
<i class="fa fa-upload"></i> 上传BPMN
|
||||
</button>
|
||||
<button type="button" class="btn btn-primary btn-sm" onclick="importAllFun();">
|
||||
<i class="fa fa-download"></i> 批量导入所有
|
||||
</button>
|
||||
<a href="<%=contextPath%>/activiti/workflow/model/showModelList.do" class="btn btn-default btn-sm">
|
||||
<i class="fa fa-list"></i> 模型列表
|
||||
</a>
|
||||
</div>
|
||||
<div class="form-group pull-right">
|
||||
<span class="help-block">BPMN文件目录: src/main/resources/diagrams/</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 上传对话框 -->
|
||||
<div class="modal fade" id="uploadModal" tabindex="-1" role="dialog">
|
||||
<div class="modal-dialog" role="document">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal"><span>×</span></button>
|
||||
<h4 class="modal-title">上传BPMN文件</h4>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<form id="uploadForm" enctype="multipart/form-data">
|
||||
<div class="form-group">
|
||||
<label>选择BPMN文件:</label>
|
||||
<input type="file" name="file" class="form-control" accept=".bpmn,.bpmn20.xml" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>所属公司:</label>
|
||||
<select name="companyId" class="form-control">
|
||||
<option value="">-- 请选择 --</option>
|
||||
<% if (companies != null) { for (Company company : companies) { %>
|
||||
<option value="<%= company.getId() %>"><%= company.getName() %></option>
|
||||
<% } } %>
|
||||
</select>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
|
||||
<button type="button" class="btn btn-primary" onclick="uploadBpmnFun()">上传并导入</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<table id="table"></table>
|
||||
</section>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@ -72,16 +72,19 @@ var companyId = "${param.unitId}";
|
||||
alert(); // 执行一些动作...
|
||||
}); */
|
||||
|
||||
/* var editFlowFun = function(id) {
|
||||
var w = window.screen.width*0.7;
|
||||
var h = window.screen.height*0.7;
|
||||
var l = window.screen.width*(1-0.7)/2;
|
||||
window.open(ext.contextPath + '/modeler.html?modelId=' + id,'_black',
|
||||
/* 编辑流程图 - 打开Activiti Modeler */
|
||||
var editFlowFun = function(id) {
|
||||
var w = window.screen.width*0.8;
|
||||
var h = window.screen.height*0.8;
|
||||
var l = window.screen.width*(1-0.8)/2;
|
||||
var t = window.screen.height*(1-0.8)/2;
|
||||
window.open(ext.contextPath + '/modeler.html?modelId=' + id,'_blank',
|
||||
"left="+ l
|
||||
+ ",top=50,scrollbars=yes,location=no,status=no,toolbar=no,resizable=yes"
|
||||
+ ",top="+ t
|
||||
+ ",scrollbars=yes,location=no,status=no,toolbar=no,resizable=yes"
|
||||
+ ",width="+w
|
||||
+ ",height="+h);
|
||||
}; */
|
||||
};
|
||||
var copyFun = function(id) {
|
||||
swal({
|
||||
text: "您确定要为该模型生成副本?",
|
||||
@ -287,11 +290,12 @@ var companyId = "${param.unitId}";
|
||||
title: "操作",
|
||||
align: 'center',
|
||||
valign: 'middle',
|
||||
width: 240, // 定义列的宽度,单位为像素px
|
||||
width: 320, // 定义列的宽度,单位为像素px
|
||||
formatter: function (value, row, index) {
|
||||
var str = '';
|
||||
str += '<security:authorize buttonUrl="activiti/workflow/model/edit.do">';
|
||||
str += '<button class="btn btn-default btn-sm" onclick="editFun(\'' + row.id + '\')" data-toggle="tooltip" title="编辑"><i class="fa fa-edit"></i><span class="hidden-md hidden-lg"> 编辑</span></button>';
|
||||
str += '<button class="btn btn-default btn-sm" onclick="editFlowFun(\'' + row.id + '\')" data-toggle="tooltip" title="流程图编辑"><i class="fa fa-project-diagram"></i><span class="hidden-md hidden-lg"> 流程图</span></button>';
|
||||
str += '<button class="btn btn-default btn-sm" onclick="copyFun(\'' + row.id + '\')" data-toggle="tooltip" title="复制"><i class="fa fa-copy"></i><span class="hidden-md hidden-lg"> 复制</span></button>';
|
||||
str += '<button class="btn btn-default btn-sm" onclick="deployFun(\'' + row.id + '\')" data-toggle="tooltip" title="部署"><i class="fa fa-play"></i><span class="hidden-md hidden-lg"> 部署</span></button>';
|
||||
str += '</security:authorize>';
|
||||
@ -413,10 +417,13 @@ var companyId = "${param.unitId}";
|
||||
</li>
|
||||
</ul> -->
|
||||
<div class="form-group " style="padding:0;">
|
||||
<div class="btn-group" style="width: 220px;padding-bottom:10px;">
|
||||
<div class="btn-group" style="padding-bottom:10px;">
|
||||
<security:authorize buttonUrl="activiti/workflow/model/add.do">
|
||||
<button type="button" class="btn btn-default btn-sm" onclick="addFun();"><i class="fa fa-plus"></i> 新增</button>
|
||||
</security:authorize>
|
||||
<a href="<%=contextPath%>/activiti/workflow/model/showBpmnFileList.do" class="btn btn-default btn-sm">
|
||||
<i class="fa fa-file-code-o"></i> BPMN文件
|
||||
</a>
|
||||
</div>
|
||||
<div class="form-group pull-right" >
|
||||
<div class="input-group input-group-sm" style="width: 250px;">
|
||||
|
||||
Reference in New Issue
Block a user