提交 183ff408 authored 作者: zhoushaopan's avatar zhoushaopan

[工作流模块] 校验bpmn文件

上级 e9aba5d6
......@@ -16,6 +16,7 @@ import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
......@@ -34,7 +35,6 @@ public class ModelController {
@Autowired
private ModelService modelService;
/**
* @param
* @return java.util.List<com.tykj.workflowcore.model_layer.model.TableInfo>
......
......@@ -16,6 +16,7 @@ import org.springframework.data.domain.Page;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import javax.xml.stream.XMLStreamException;
import java.io.FileNotFoundException;
......@@ -61,7 +62,7 @@ public class FlowsInfoController {
@PostMapping("/saveXml")
@ApiOperation(value = "保存xml以及其他流程信息")
public ResponseEntity saveXml(@RequestBody FlowsInfoVo flowsInfoVo) {
public ResponseEntity saveXml(@RequestBody FlowsInfoVo flowsInfoVo) throws FileNotFoundException, XMLStreamException {
//保存节点信息
nodeInfoService.saveNodeInfoList(flowsInfoVo.getNodeInfoList());
//保存xml信息
......
......@@ -6,7 +6,7 @@ import com.tykj.workflowcore.workflow_editer.entity.FormPage;
//import com.tykj.workflowcore.workflow_editer.entity.PageEntity;
import com.tykj.workflowcore.workflow_editer.service.FormPageService;
//import com.tykj.workflowcore.workflow_editer.service.PageEntityService;
import com.tykj.workflowcore.workflow_editer.entity.vo.InFormPageVo;
import com.tykj.workflowcore.workflow_editer.entity.vo.FormPageVo;
import com.tykj.workflowcore.workflow_editer.entity.vo.PageFormPageVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
......@@ -35,7 +35,7 @@ public class FormPageController {
@ApiOperation("保存页面")
@PostMapping("/savePage")
public ResponseEntity savePage(@RequestBody InFormPageVo inFormPageVo){
public ResponseEntity savePage(@RequestBody FormPageVo inFormPageVo){
if (inFormPageVo.getId() == null){
Integer pageId = formPageService.savePage(inFormPageVo);
return ResultUtil.success(pageId,"页面保存成功");
......@@ -48,7 +48,7 @@ public class FormPageController {
}
@ApiOperation("回显页面")
@GetMapping("/EchoPage")
public FormPage EchoPage(Integer id){
public FormPageVo EchoPage(Integer id){
return formPageService.getPage(id);
}
......@@ -66,6 +66,7 @@ public class FormPageController {
return ResultUtil.success("删除页面成功");
}
@ApiOperation("通过页面id查询所对应的数据模型")
@PostMapping("/findByPages")
public List<TableInfo> findByPages(@RequestBody List<Integer> pageIds){
return formPageService.findByPageIds(pageIds);
......
......@@ -2,7 +2,7 @@ package com.tykj.workflowcore.workflow_editer.entity;
import com.tykj.workflowcore.base.entity.BaseEntity;
import com.tykj.workflowcore.model_layer.annotations.WorkFlowCoreNoScan;
import com.tykj.workflowcore.workflow_editer.entity.vo.OutFormPageVo;
import com.tykj.workflowcore.workflow_editer.entity.vo.FormPageVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
......@@ -13,7 +13,8 @@ import org.hibernate.annotations.Where;
import org.springframework.beans.BeanUtils;
import javax.persistence.*;
import java.util.Date;
import java.util.Arrays;
import java.util.List;
/**
* ClassName: FormPage
......@@ -52,21 +53,20 @@ public class FormPage extends BaseEntity {
@Lob
private String css;
// @ApiModelProperty("创建的时间")
// private Date createTime;
//
// @ApiModelProperty("修改的时间")
// private Date updateTime;
@ApiModelProperty("json描述文件")
private String descFile;
@ApiModelProperty("实体类id")
private String entityId;
public OutFormPageVo toEntityVo(){
OutFormPageVo outFormPageVo = new OutFormPageVo();
BeanUtils.copyProperties(this,outFormPageVo);
return outFormPageVo;
public FormPageVo toEntityVo(){
FormPageVo inFormPageVo = new FormPageVo();
BeanUtils.copyProperties(this,inFormPageVo);
//将string还原成list
String entityId = this.getEntityId();
String str[] = entityId.split(",");
List<String> entityIds = Arrays.asList(str);
inFormPageVo.setEntityIds(entityIds);
return inFormPageVo;
}
}
......@@ -22,7 +22,7 @@ import java.util.List;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class InFormPageVo {
public class FormPageVo {
@ApiModelProperty("页面id")
private Integer id;
......@@ -59,6 +59,13 @@ public class InFormPageVo {
public FormPage toEntity(){
FormPage formPage = new FormPage();
StringBuffer IdStr = new StringBuffer();
for (String entityId : entityIds) {
IdStr.append(entityId);
IdStr.append(",");
}
formPage.setEntityId(IdStr.toString());
BeanUtils.copyProperties(this,formPage);
return formPage;
}
......
......@@ -2,10 +2,9 @@ package com.tykj.workflowcore.workflow_editer.service;
import com.tykj.workflowcore.model_layer.entity.TableInfo;
import com.tykj.workflowcore.workflow_editer.entity.FormPage;
import com.tykj.workflowcore.workflow_editer.entity.vo.InFormPageVo;
import com.tykj.workflowcore.workflow_editer.entity.vo.FormPageVo;
import com.tykj.workflowcore.workflow_editer.entity.vo.PageFormPageVo;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import java.util.List;
......@@ -25,7 +24,7 @@ public interface FormPageService {
* @param inFormPageVo 页面实体
* @return 主键id
*/
Integer savePage(@RequestBody InFormPageVo inFormPageVo);
Integer savePage(@RequestBody FormPageVo inFormPageVo);
/**
* 更新页面
......@@ -38,7 +37,7 @@ public interface FormPageService {
* @param id 页面id
* @return 页面信息
*/
FormPage getPage(Integer id);
FormPageVo getPage(Integer id);
/**
* 根据页面id删除页面
......
......@@ -7,6 +7,7 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import javax.xml.stream.XMLStreamException;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.List;
......@@ -35,7 +36,7 @@ public interface WorkFlowService {
* 接收前端的流程文件
* @param flowsInfoVo
*/
void flowXml(@RequestBody FlowsInfoVo flowsInfoVo);
void flowXml(@RequestBody FlowsInfoVo flowsInfoVo) throws XMLStreamException, FileNotFoundException;
/**
* 创建流程
......
......@@ -8,17 +8,18 @@ import com.tykj.workflowcore.model_layer.entity.TableInfo;
import com.tykj.workflowcore.workflow_editer.entity.FormPage;
import com.tykj.workflowcore.workflow_editer.dao.FormPageMapper;
import com.tykj.workflowcore.workflow_editer.service.FormPageService;
import com.tykj.workflowcore.workflow_editer.entity.vo.InFormPageVo;
import com.tykj.workflowcore.workflow_editer.entity.vo.FormPageVo;
import com.tykj.workflowcore.workflow_editer.entity.vo.PageFormPageVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
/**
* ClassName: PageEntityServiceImpl
......@@ -36,7 +37,7 @@ public class FormPageServiceImpl implements FormPageService {
@Autowired
private TableInfoDao tableInfoDao;
@Override
public Integer savePage(@RequestBody InFormPageVo inFormPageVo) {
public Integer savePage(@RequestBody FormPageVo inFormPageVo) {
inFormPageVo.setCreateTime(new Date());
FormPage formPage = inFormPageVo.toEntity();
FormPage formPage1 = formPageMapper.save(formPage);
......@@ -50,18 +51,17 @@ public class FormPageServiceImpl implements FormPageService {
}
@Override
public FormPage getPage(Integer id) {
public FormPageVo getPage(Integer id) {
FormPage formPage = formPageMapper.findById(id).get();
//时间排序
return formPage;
return formPage.toEntityVo();
}
@Override
public void deletePage(Integer id) {
FormPage formPage = formPageMapper.findById(id).get();
formPage.setDeleted(1);
formPageMapper.save(formPage);
formPageMapper.delete(formPage);
}
@Override
......@@ -77,18 +77,23 @@ public class FormPageServiceImpl implements FormPageService {
return formPagePage;
}
@Override
@Override
public List<TableInfo> findByPageIds(List<Integer> pageIds) {
ArrayList<TableInfo> list = new ArrayList<>();
for (Integer pageId : pageIds) {
//通过pageId 查询出表id
String entityId = formPageMapper.findById(pageId).get().getEntityId();
//根据entityId查询出表
PredicateBuilder<TableInfo> builder = Specifications.and();
builder.eq("id",entityId);
List<TableInfo> tableInfoList = tableInfoDao.findAll(builder.build());
list.addAll(tableInfoList);
PredicateBuilder<FormPage> builder = Specifications.and();
builder.in("id", pageIds);
List<FormPage> tableInfoList = formPageMapper.findAll(builder.build());
StringBuffer entityIds = new StringBuffer();
for (FormPage formPage : tableInfoList) {
String entityId = formPage.getEntityId();
entityIds.append(entityId);
entityIds.append(",");
}
String[] split = entityIds.toString().split(",");
List<String> lastEntityIds = Arrays.asList(split).stream().distinct().collect(Collectors.toList());
//todo
return list;
}
......
package com.tykj.workflowcore.workflow_editer.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.tykj.workflowcore.api.entity.InvokeRequest;
import com.tykj.workflowcore.api.entity.Parameter;
import com.tykj.workflowcore.api.service.SpringBeanService;
import com.tykj.workflowcore.base.result.ApiException;
import com.tykj.workflowcore.base.util.FileUtil;
import com.tykj.workflowcore.workflow_editer.validate.ProcessValidatorFactoryExt;
import com.tykj.workflowcore.workflow_editer.entity.*;
import com.tykj.workflowcore.workflow_editer.dao.FlowsInfoMapper;
import com.tykj.workflowcore.workflow_editer.entity.vo.*;
......@@ -20,32 +18,31 @@ import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import org.flowable.bpmn.converter.BpmnXMLConverter;
import org.flowable.bpmn.model.*;
import org.flowable.common.engine.api.delegate.Expression;
import org.flowable.common.engine.impl.identity.Authentication;
import org.flowable.engine.*;
import org.flowable.engine.impl.cfg.ProcessEngineConfigurationImpl;
import org.flowable.engine.impl.persistence.entity.ExecutionEntity;
import org.flowable.engine.repository.Deployment;
import org.flowable.engine.runtime.Execution;
import org.flowable.engine.runtime.ProcessInstance;
import org.flowable.image.ProcessDiagramGenerator;
import org.flowable.task.api.Task;
import org.flowable.task.api.TaskQuery;
import org.flowable.task.api.history.HistoricTaskInstance;
import org.hibernate.engine.transaction.internal.TransactionImpl;
import org.flowable.validation.ProcessValidator;
import org.flowable.validation.ValidationError;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
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.*;
import java.util.*;
import java.util.regex.Pattern;
/**
* ClassName: FlowableServiceImpl
......@@ -69,6 +66,8 @@ public class WorkFlowServiceImpl implements WorkFlowService {
private final ProcessEngine processEngine;
private final VariableStorageService variableStorageService;
@Autowired
ProcessValidatorFactoryExt processValidatorFactoryExt;
final
ClassLoader classLoader;
......@@ -156,14 +155,15 @@ public class WorkFlowServiceImpl implements WorkFlowService {
}
@Override
public void flowXml(@RequestBody FlowsInfoVo flowsInfoVo) {
public void flowXml(@RequestBody FlowsInfoVo flowsInfoVo) throws XMLStreamException, FileNotFoundException {
String basePath = System.getProperty("user.dir") + "\\xml\\";
Integer id = flowsInfoVo.getId();
String flowKey = flowsInfoVo.getFlowKey();
String fileXml = flowsInfoVo.getFileXml();
//生成xml文件
FileUtil.createFileByString(basePath + flowKey + "bpmn20.xml", flowsInfoVo.getFileXml().replaceAll("\\[\\?\\?[^\\]]+\\?\\?\\]", ""));
File file = FileUtil.createFileByString(basePath + flowKey + "bpmn20.xml",
flowsInfoVo.getFileXml().replaceAll("\\[\\?\\?[^\\]]+\\?\\?\\]", ""));
FileUtil.createFileByString(basePath + flowKey + "bpmnCustom20.xml", flowsInfoVo.getFileXml());
FlowsInfo flowsInfo = new FlowsInfo();
......@@ -174,8 +174,32 @@ public class WorkFlowServiceImpl implements WorkFlowService {
flowsInfo.setId(id);
//更新并保存
FlowsInfo save = flowsInfoMapper.save(flowsInfo);
//自动部署
deployXml(save);
//进行第一部的校验
InputStream inputStream = new FileInputStream(file);//实例化FileInputStream
BpmnXMLConverter converter = new BpmnXMLConverter();
XMLInputFactory factory = XMLInputFactory.newInstance();
XMLStreamReader reader = factory.createXMLStreamReader(inputStream);//createXmlStreamReader
//将xml文件转换成BpmnModel
BpmnModel bpmnModel = converter.convertToBpmnModel(reader);
//做校验
ProcessValidator defaultProcessValidator = processValidatorFactoryExt.createDefaultProcessValidator();
List<ValidationError> validate = defaultProcessValidator.validate(bpmnModel);
StringBuffer message = new StringBuffer();
if (validate.size()!=0){
for (int i =0;i<validate.size();i++){
ValidationError validationError = validate.get(i);
String problem = validationError.getProblem();
message.append(i+1+problem);
message.append("\r\n");
}
throw new ApiException(null,message.toString());
}else {
//自动部署
deployXml(save);
}
}
......@@ -346,7 +370,7 @@ public class WorkFlowServiceImpl implements WorkFlowService {
flowsInfoMapper.deleteById(id);
}
} else {
throw new ApiException("流程不存在");
throw new ApiException(null,"流程不存在");
}
}
......
package com.tykj.workflowcore.workflow_editer.util;
import java.util.List;
/**
* ClassName: PageUtil
* Package: com.tykj.util
* Description:
* Datetime: 2021/3/2 20:39
*
* @Author: zsp
*/
public class PageUtil {
/**
* 开始分页
* @param list
* @param pageNum 页码
* @param pageSize 每页多少条数据
* @return
*/
public static List startPage(List list, Integer pageNum,
Integer pageSize) {
if (list == null) {
return null;
}
if (list.size() == 0) {
return null;
}
Integer count = list.size(); // 记录总数
Integer pageCount = 0; // 页数
if (count % pageSize == 0) {
pageCount = count / pageSize;
} else {
pageCount = count / pageSize + 1;
}
int fromIndex = 0; // 开始索引
int toIndex = 0; // 结束索引
if (pageNum > pageCount){
return null;
}
if (pageNum != pageCount) {
System.out.println("pageNum====>"+pageNum);
fromIndex = (pageNum - 1) * pageSize;
System.out.println("fromindex===>"+fromIndex);
toIndex = fromIndex + pageSize;
} else {
System.out.println("from====>"+fromIndex);
fromIndex = (pageNum - 1) * pageSize;
toIndex = count;
}
List pageList = list.subList(fromIndex, toIndex);
return pageList;
}
}
......@@ -251,4 +251,22 @@ class WorkflowCoreApplicationTests_workflow {
.andDo(print());//打印输出结果
}
@Test
void complteTask() throws Exception {
JSONObject jsonObject = new JSONObject();
jsonObject.put("userId","1");
jsonObject.put("handlingOpinion",0);
request = get("/workFlow/completeTask/")
.contentType(MediaType.APPLICATION_JSON)
.content(jsonObject.toJSONString())
// .param("taskId","2563cd2d-8c72-11eb-9463-005056c00001")//参数
// 设置返回值类型为utf-8,否则默认为ISO-8859-1
.accept(MediaType.APPLICATION_JSON_UTF8_VALUE);
mockMvc.perform(request).andExpect(status().isOk())
.andExpect(content().string(not(""))) //条件
// .andExpect(content().string(not("[]")))
.andDo(print());//打印输出结果
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论