activity7 多种部署流程方式的实现(包括文件部署和zip部署等)

公司项目用到了工作流,之前没有接触过,闲暇时间自学一下,写个demo,这里记录一下,方便后期回忆

/**
     * @Des: 上传文件部署流程
     * @Author: liut 
     * @Date: 2020/11/23 15:50
     */
    @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());
        }
    }
/**
     * @Des: 通过bpmn文件名称部署流程
     * @Author: liut
     * @Date: 2020/11/23 16:18
     */
    @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());
        }
    }
/**
     * @Des: 通stirng部署流程
     * @Author: liut
     * @Date: 2020/11/23 16:11
     */
    @PostMapping("/addDeploymentByString")
    public AjaxResponse addDeploymentByString(@RequestParam("stringBPMN") String stringBPMN
//                                              @RequestParam("deploymentName") String deploymentName
    ){
        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());
        }
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值