公司项目用到了工作流,之前没有接触过,闲暇时间自学一下,写个demo,这里记录一下,方便后期回忆
@RequestMapping("/uploadStreamAndDeployment")
public AjaxResponse uploadStreamAndDeployment(@RequestParam("processFile") MultipartFile multipartFile,
@RequestParam("deploymentName") String deploymentName){
String filename = multipartFile.getOriginalFilename();
try {
InputStream inputStream = multipartFile.getInputStream();
String extension = FilenameUtils.getExtension(filename);
Deployment deployment = null;
if (extension.equals("zip")){
ZipInputStream zipInputStream = new ZipInputStream(inputStream);
deployment = repositoryService.createDeployment()
.addZipInputStream(zipInputStream)
.name(deploymentName)
.deploy();
}else {
deployment = repositoryService.createDeployment()
.addInputStream(filename,inputStream)
.name(deploymentName)
.deploy();
}
return AjaxResponse.AjaxData(GlobalConfig.ResponseCode.SUCCESS.getCode(),
GlobalConfig.ResponseCode.SUCCESS.getDes(),
deployment.getId() + ":" + filename);
} catch (Exception e) {
e.printStackTrace();
return AjaxResponse.AjaxData(GlobalConfig.ResponseCode.ERROR.getCode(),
"部署流程失败",e.getMessage());
}
}
@PostMapping("/addDeploymentByFileNameBPMN")
public AjaxResponse addDeploymentByFileNameBPMN(@RequestParam("deploymentFileUUID") String deploymentFileUUID,
@RequestParam("deploymentName") String deploymentName){
try {
String filename = "resources/bpmn" + deploymentFileUUID;
Deployment deployment = repositoryService.createDeployment()
.addClasspathResource(filename)
.name(deploymentName)
.deploy();
return AjaxResponse.AjaxData(GlobalConfig.ResponseCode.SUCCESS.getCode(),
GlobalConfig.ResponseCode.SUCCESS.getDes(),
deployment.getId() + ":" + filename);
}catch (Exception e){
e.printStackTrace();
return AjaxResponse.AjaxData(GlobalConfig.ResponseCode.ERROR.getCode(),
"部署流程失败",e.getMessage());
}
}
@PostMapping("/addDeploymentByString")
public AjaxResponse addDeploymentByString(@RequestParam("stringBPMN") String stringBPMN
){
try {
Deployment deployment = repositoryService.createDeployment()
.addString("CreateWithBPMNJS.bpmn", stringBPMN)
.name("写死字符串")
.deploy();
return AjaxResponse.AjaxData(GlobalConfig.ResponseCode.SUCCESS.getCode(),
GlobalConfig.ResponseCode.SUCCESS.getDes(),deployment.getId());
}catch (Exception e){
return AjaxResponse.AjaxData(GlobalConfig.ResponseCode.ERROR.getCode(),
"string部署流程失败",e.getMessage());
}
}