通过文件流InputStream部署流程成功,但是act_re_procdef表没有数据
原方案:
1.资源名称和流程名称都使用的中文
2.中间还测试了使用英文名的资源名称和使用上传文件的文件名,依然不成功
注:这里的文件名是ruoyi框架上传后的文件名,ruoyi框架3.8.5版本后上传的文件名不再是随机字符串,而是在原名称的后缀前增加“_”+随机字符串+流水号的方式作为上传文件名,所以没有成功
public AjaxResult deployProcess(@RequestBody JSONObject process) {
try {
String name = process.getString("name");// 流程名称:审批流程
String filePath = process.getString("filePath");
String fullPath = filePath.replace(Constants.RESOURCE_PREFIX, RuoYiConfig.getProfile());
InputStream inputStream = new FileInputStream(fullPath);
if (activitiService.deployByInputStream(inputStream, name)) {
inputStream.close();
FileUtils.deleteFile(fullPath);
}
} catch (IOException e) {
e.printStackTrace();
}
return success();
}
public boolean deployByInputStream(InputStream inputStream, String processName) {
Deployment deployment = repService.createDeployment().addInputStream(processName, inputStream).name(processName).deploy();
return deployment != null;
}
修改方案:
资源名称必须携带文件格式,且后缀必须是.bpmn20.xml(亲测)或.bpmn(未测试,仅根据activiti的设定猜测)才可识别流程文件的文件类型
public AjaxResult deployProcess(@RequestBody JSONObject process) {
try {
String name = process.getString("name");// 流程名称:审批流程
String filePath = process.getString("filePath");// 文件路径
String suffix = filePath.substring(filePath.lastIndexOf("."));// 文件后缀
String fileName = filePath.substring(filePath.lastIndexOf("/") + 1, filePath.lastIndexOf("_"));// 这是去掉ruoyi框架上传文件后,文件名添加的随机数据
String fullPath = filePath.replace(Constants.RESOURCE_PREFIX, RuoYiConfig.getProfile());
InputStream inputStream = new FileInputStream(fullPath);
if (activitiService.deployByInputStream(inputStream, name, fileName + suffix)) {
inputStream.close();
FileUtils.deleteFile(fullPath);
}
} catch (IOException e) {
e.printStackTrace();
}
return success();
}
public boolean deployByInputStream(InputStream inputStream, String processName, String fileName) {
Deployment deployment = repService.createDeployment().addInputStream(fileName, inputStream).name(processName).deploy();
return deployment != null;
}