流程文件部署:
@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);