activiti实战三(流程部署)

本文介绍了一个基于RESTful API实现的工作流部署方法,包括文件上传、流程部署、获取部署列表及删除流程部署等功能。通过示例代码详细展示了如何利用Spring Boot进行流程定义文件的上传与部署,并提供了流程部署信息的查询及删除操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

流程文件部署:

@ResponseBody
public AjaxJson deployProcess(@RequestParam("deployFileUpload") MultipartFile uploadFile,
HttpServletRequest request, HttpServletResponse response, String deployName)
throws IllegalStateException, IOException {
AjaxJson json = new AjaxJson();
String realPath = request.getSession().getServletContext().getRealPath("/") + "upload\\";
String filePath = getFilePath(uploadFile.getOriginalFilename(), realPath);
File newFile = new File(filePath);
uploadFile.transferTo(newFile);
InputStream inputStream = uploadFile.getInputStream();
/** 创建部署构建对象 */
DeploymentBuilder builder = repositoryService.createDeployment();
if (uploadFile.getOriginalFilename().endsWith(".bpmn")) {
builder.addInputStream(uploadFile.getOriginalFilename(), inputStream);
} else if (uploadFile.getOriginalFilename().endsWith(".zip")) {
builder.addZipInputStream(new ZipInputStream(inputStream));
}
/** 添加需要部署的文件 */
/** 添加name */
builder.name(deployName);
/** 添加种类 */
builder.category("xxx");
/** 进行部署 */
builder.deploy();
inputStream.close();
json.setSuccess(true);
json.setMsg("上传成功");
return json;
}

private String getFilePath(String sourceFileName, String realPath) {
String baseFolder = realPath + File.separator + "deploys";
Date nowDate = new Date();
// yyyy/MM/dd
String fileFolder = baseFolder + File.separator + new DateTime(nowDate).toString("yyyy") + File.separator
+ new DateTime(nowDate).toString("MM") + File.separator + new DateTime(nowDate).toString("dd");
File file = new File(fileFolder);
if (!file.isDirectory()) {
// 如果目录不存在,则创建目录
file.mkdirs();
}
// 生成新的文件名
String fileName = new DateTime(nowDate).toString("yyyyMMddhhmmssSSSS") + RandomUtils.nextInt(100, 9999) + "."
+ StringUtils.substringAfterLast(sourceFileName, ".");
return fileFolder + File.separator + fileName;
}

获取流程部署列表:

//注意:使用模糊查询时,要使用"%"+xxx+"%"字符串

public AjaxJson getProcessDeployInfo(String name, Integer start, Integer limit) {
// 由于Deployment是接口,所以ajax返回json时会有异常,因此必须用实体类接收
AjaxJson ajaxJson = new AjaxJson();
List<Deployment> list = repositoryService.createDeploymentQuery().orderByDeploymenTime().desc().listPage(start,
limit);
ajaxJson.setTotalCount(repositoryService.createDeploymentQuery().list().size());
if (!StringUtils.isEmpty(name)) {
list = repositoryService.createDeploymentQuery().orderByDeploymenTime().desc()
.deploymentNameLike("%" + name + "%")
.listPage(start, limit);
ajaxJson.setTotalCount(
repositoryService.createDeploymentQuery().deploymentNameLike("%" + name + "%").list().size());
}


List<DeploymentEntity> l2 = new ArrayList<>();


for (Deployment deployment : list) {
DeploymentEntity d = new DeploymentEntity();
d.setCategory(deployment.getCategory());


DateTime dateTime = new DateTime(deployment.getDeploymentTime());
d.setDeploymentTime(dateTime.toString("yyyy-MM-dd HH:mm:ss"));
d.setId(deployment.getId());
d.setName(deployment.getName());
d.setTenantId(deployment.getTenantId());
l2.add(d);
}
ajaxJson.setData(l2);
return ajaxJson;
}

删除流程部署时,强制删除流程实例

repositoryService.deleteDeployment(deploymentId, true);


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值