实现Model 检索、新增、编辑、删除、导出和部署功能。
Activiti 之Model 模型管理页面操作:Model 首页:
Model 检索:
Model 新增:
Model 编辑:
简单设计转正流程,记得点击保存按钮。
Model 导出:
Model 删除:
5001 流程模型已经被删除。
Model 部署:
功能说明:依据流程模型定义发起一次流程实例,由于该功能涉及用户和用户组设置、表单设计。这里仅仅实现在控制台后端输出流程实例Id。
选择模型定义,点击部署:
请教流程实例Id输出:
SpringBoot 之Activiti Model 模型管理后台SpringBoot程序入口排除Activiti自带SpringSecurity 安全框架校验
package com.zzg;
import org.activiti.spring.boot.SecurityAutoConfiguration;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication(exclude={SecurityAutoConfiguration.class})
@MapperScan("com.zzg.mapper")
public class OAApplication {
public static void main(String[] args) {
SpringApplication.run(OAApplication.class, args);
}
}
SpringBoot 引入前端开发框架LayUI
在layUI 开源网站中,下载LayUI。下载地址:Layui - 经典开源模块化前端 UI 框架
在本项目的resource/static文件夹中,引入layui 框架。
SpringBoot 配置SpringMVC 资源路径映射
package com.zzg.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
@Configuration
public class SpringMVCConfig extends WebMvcConfigurerAdapter {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/static
@Autowired
private RepositoryService repositoryService;
@Autowired
private ObjectMapper objectMapper;
@GetMapping("/index")
public ModelAndView index() {
return new ModelAndView("redirect:/model.html");
}
@GetMapping("/page")
public PageList getModels(HttpServletRequest request){
String pageParame = request.getParameter("page");
String sizeParame = request.getParameter("size");
String modelName = request.getParameter("name");
Integer page = StringUtils.isNotEmpty(pageParame) ? Integer.valueOf(pageParame) : 1;
Integer size = StringUtils.isNotEmpty(sizeParame) ? Integer.valueOf(sizeParame) : 10;
// 获取模型查询实例
ModelQuery modelQuery = repositoryService.createModelQuery();
// 根据模型名称模糊查询
Integer total;
List models;
if (StringUtils.isNotEmpty(modelName)) {
// 获取模型总数
total = (int) modelQuery.modelNameLike("%" + modelName + "%").count();
// 获取列表数据
models = modelQuery
.modelNameLike("%" + modelName + "%")
.orderByLastUpdateTime()
.desc()
.listPage((page - 1) * size, size);
} else {
// 获取模型总数
total = (int) modelQuery.count();
// 获取列表数据
models = modelQuery
.orderByLastUpdateTime()
.desc()
.listPage((page - 1) * size, size);
}
//封装到pageList对象中
PageList pageList = new PageList(page,total, size);
pageList.setList(models);
return pageList;
}
@GetMapping("/delete")
public Resp delete(HttpServletRequest request){
String processId = request.getParameter("processId");
System.out.println("processId is:" + processId);
// if(StringUtils.isNotEmpty(processId)){
// return Resp.ERROR(CodeMsgEnum.ERROR);
// }
Model model = repositoryService.getModel(processId);
if(model!=null){
System.out.println("指定模型存在");
repositoryService.deleteModel(processId);
}
return Resp.OK_WITHOUT_DATA();
}
@PostMapping(value = "/insert", produces = "application/json;charset=utf-8")
public Resp insert(@RequestBody Map map) throws UnsupportedEncodingException {
System.out.println("model 参数接受:" + map);
//初始化一个空模型
Model model = repositoryService.newModel();
//设置一些默认信息,可以用参数接收
int revision = 1;
String key = String.valueOf(map.get("processKey"));
String name =String.valueOf(map.get("processName"));;
String description = String.valueOf(map.get("processDesc"));
//ModelEditorSource
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);
ObjectNode modelNode = objectMapper.createObjectNode();
modelNode.put(ModelDataJsonConstants.MODEL_NAME, name);
modelNode.put(ModelDataJsonConstants.MODEL_DESCRIPTION, description);
modelNode.put(ModelDataJsonConstants.MODEL_REVISION, revision);
model.setName(name);
model.setKey(key);
model.setMetaInfo(modelNode.toString());
repositoryService.saveModel(model);
String id = model.getId();
repositoryService.addModelEditorSource(id, editorNode.toString().getBytes("utf-8"));
// return new ModelAndView("redirect:/modeler.html?modelId=" + id);
return Resp.OK(id);
}
@PostMapping(value = "deploy/{modelId}")
public Resp deploy(@PathVariable("modelId") String modelId) {
try {
// 获取模型
Model model = repositoryService.getModel(modelId);
ObjectNode objectNode = (ObjectNode) new ObjectMapper().readTree(repositoryService.getModelEditorSource(model.getId()));
BpmnModel bpmnModel = new BpmnJsonConverter().convertToBpmnModel(objectNode);
String processName = model.getName()+".bpmn20.xml";
byte[] bytes = new BpmnXMLConverter().convertToXML(bpmnModel);
// 部署流程
Deployment deployment = repositoryService
.createDeployment().name(model.getName())
.addString(processName, new String(bytes,"UTF-8"))
.deploy();
System.out.println("流程部署id----"+deployment.getId());
return Resp.OK(deployment.getId());
} catch (Exception e) {
logger.error("根据模型部署流程失败:modelId={}", modelId, e);
return Resp.ERROR(CodeMsgEnum.ERROR);
}
}
@GetMapping(value = "export/{modelId}")
public void export(@PathVariable String modelId, HttpServletResponse response) {
try {
Model modelData = repositoryService.getModel(modelId);
BpmnJsonConverter jsonConverter = new BpmnJsonConverter();
JsonNode editorNode = new ObjectMapper().readTree(repositoryService.getModelEditorSource(modelData.getId()));
BpmnModel bpmnModel = jsonConverter.convertToBpmnModel(editorNode);
BpmnXMLConverter xmlConverter = new BpmnXMLConverter();
byte[] bpmnBytes = xmlConverter.convertToXML(bpmnModel);
ByteArrayInputStream in = new ByteArrayInputStream(bpmnBytes);
OutputStream outputStream = response.getOutputStream();
IOUtils.copy(in, outputStream);
String filename = bpmnModel.getMainProcess().getId() + ".bpmn.xml";
response.setHeader("content-type", "application/octet-stream");
response.setContentType("application/octet-stream;charset=UTF-8");
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(filename, "utf-8"));
outputStream.flush();
outputStream.close();
} catch (Exception e) {
logger.error("导出model的xml文件失败:{}", e.getMessage(), e);
}
}
}
SpringBoot 添加流程模型管理页面
在项目中的resource/static文件夹中添加流程模型管理页面(model.html)
**系统 - Layui
** 系统
- 超级管理员
- 基本资料
- 安全设置
- 退了
- 流程管理
- 流程定义
- 表单定义
- 用户管理
- 查询用户
- 新增用户
- 借阅信息
- 所有记录
- 个人记录
- 帮助
GitHub地址:https://github.com/zhouzhiwengang/SpringBoot-Project.git



