activiti踩过的坑-InputStream部署成功但act_re_procdef表没有数据

通过文件流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;
    }

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值