Activiti工作流管理系统(五)完结篇

前言

本系列在之前的章节中介绍了Activiti工作流管理系统的所有基本操作,包括发布、启动、执行、查看实例等操作。这一篇将是系列的完结篇,介绍最后一个主要功能:流程图的查看。该功能旨在能够实时查看当前流程图所在环节,使得用户能够更加清楚的掌握当前工作流的流转进度,也可以说是本系统的一个必不可少的功能点。闲话少说,进入正题。

系列五内容

流程图的查看

界面展示

活动实例列表.png
活动实例中查看流程图.png

流程定义列表.png

流程定义列表查看流程图.png

说明:以上两处截图,功能模块分别位于流程定义列表和运行实例中的查看流程功能,二者功能主体完全一样,只是传参不同,以下贴出代码并对于不同的部分进行区分,完全相同的部分不再重复贴出代码。

正在运行中实例查看流程图

前端代码

API:activityManagement.js

/**查看流程图(流程运行中)**/
export const showImageActive = params => {
  return axios.request({
    url:'workflow/showImageActive',
    params:params,
    method:'get',
    headers: {
      'Content-Type': 'application/json'
    },
    responseType: 'arraybuffer'
  })
}

/**查看流程图(流程定义列表)**/
export const showImage = params => {
  return axios.request({
    url:'workflow/showImage',
    params:params,
    method:'get',
    headers: {
      'Content-Type': 'application/json'
    },
    responseType: 'arraybuffer'
  })
}

ActiveProcess.vue

<Button type="primary" size="small" @click="showImageActive(row)">查看流程图</Button>
<Modal :closable="false" :mask-closable="false" v-model="imageModal">
      <Card>
        <div style="display: flex ; align-items: center ;justify-content: center">
          <img :src="fileField " width="100%">
        </div>
      </Card>
      <div slot="footer" style="text-align: center">
        <Button type="primary" @click="imageModal=false">确定</Button>
      </div>
</Modal>
<script>
showImageActive(row){
        //不同点:这里是通过流程实例ID进行查询
        const processInstanceId = row.processInstanceId ;
        //在这执行查看流程图图片操作,打开Modal
        showImageActive({
          processInstanceId: processInstanceId
        }).then(res => {
          const data = res.data
          this.fileField = 'data:image/png;base64,' + btoa(new Uint8Array(data).reduce((data, byte) => data + String.fromCharCode(byte), ''))
          this.imageModal = true ;
        }).catch(function (reason) {
          that.$Message.error('获取数据异常,打开失败!');
        })
      }
</script>

后端代码

WorkflowController

/**
     * 在页面获取流程图图片
     * 适用于运行时查看
     * @param processInstanceId
     * @return
     */
    @RequestMapping("/showImageActive")
    public String showImageActive(String processInstanceId, HttpServletResponse response) throws IOException {
        ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
        if(processInstance == null){
            return null ;
        }
        ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionId(processInstance.getProcessDefinitionId()).singleResult();
        //如果为空,则未找到指定的流程定义对象
        if(processDefinition == null){
            return null ;
        }
        List<String> highLightedActivities = runtimeService.getActiveActivityIds(processInstanceId);
        BpmnModel model = repositoryService.getBpmnModel(processDefinition.getId()) ;
        ProcessDiagramGenerator processDiagramGenerator = new DefaultProcessDiagramGenerator();
        //这里需要获取到model
        InputStream inputStream = processDiagramGenerator
                .generateDiagram(
                        model,
                        Globals.ACTIVITY_SUFFIX,
                        highLightedActivities,
                        Collections.<String>emptyList(),
                        Globals.ACTIVITY_FONT, Globals.ACTIVITY_FONT, Globals.ACTIVITY_FONT,
                        null, Globals.ACTIVITY_SCALE_FACTOR
                );
        BufferedInputStream bins = new BufferedInputStream(inputStream);    //放到缓冲流里面
        OutputStream outs = null;               //获取文件输出IO流
        BufferedOutputStream bouts = null ;
        try {
            outs = response.getOutputStream();
            bouts = new BufferedOutputStream(outs);
            int bytesRead = 0;
            byte[] buffer = new byte[8192];
            //开始向网络传输文件流
            while ((bytesRead = bins.read(buffer, 0, 8192)) != -1) {
                bouts.write(buffer, 0, bytesRead);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            inputStream.close();
            bouts.flush();//这里一定要调用flush()方法
            bins.close();
            outs.close();
            bouts.close();
        }
        return null;
    }

流程定义列表中查看流程图

前端代码

TableData.vue

<Button type="primary" @click="showImage">查看流程图</Button>
<Modal :closable="false" :mask-closable="false" v-model="imageModal">
      <Card>
        <div style="display: flex ; align-items: center ;justify-content: center">
          <img :src="fileField " width="100%">
        </div>
      </Card>
      <div slot="footer" style="text-align: center">
        <Button type="primary" @click="imageModal=false">确定</Button>
      </div>
    </Modal>
<script>
showImage(){
        //不同点:这里通过选取行并获取流程定义ID进行查看,其余部分完全一样
        const selectRow = this.$refs.selection.getSelection() ;
        //catch里无法获取this对象,因此在catch外部先将this对象赋值为that并在catch内部使用
        const that = this ;
        if(selectRow.length == 1){
          const defId = selectRow[0].defId ;
          //在这执行查看流程图图片操作,打开Modal
          showImage({
            defId: defId
          }).then(res => {
            const data = res.data
            this.fileField = 'data:image/png;base64,' + btoa(new Uint8Array(data).reduce((data, byte) => data + String.fromCharCode(byte), ''))
            this.imageModal = true ;
          }).catch(function (reason) {
            that.$Message.error('获取数据异常,打开失败!');
          })
        }else{
          this.$Message.warning('请选中且仅选中唯一一条数据进行查看!') ;
        }
      }
</script>

后端代码

WorkflowController

/**
     * 在页面获取流程图图片
     * @param defId
     * @return
     */
    @RequestMapping("/showImage")
    public String showImage(String defId, HttpServletResponse response) throws IOException {
        ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionId(defId).singleResult();
        //如果为空,则未找到指定的流程定义对象
        if(processDefinition == null){
            return null ;
        }
        BpmnModel model = repositoryService.getBpmnModel(processDefinition.getId()) ;
        ProcessDiagramGenerator processDiagramGenerator = new DefaultProcessDiagramGenerator();
        //这里需要获取到model
        InputStream inputStream = processDiagramGenerator.generateDiagram(model, Globals.ACTIVITY_SUFFIX,Globals.ACTIVITY_FONT, Globals.ACTIVITY_FONT, Globals.ACTIVITY_FONT, null, Globals.ACTIVITY_SCALE_FACTOR);
        BufferedInputStream bins = new BufferedInputStream(inputStream);    //放到缓冲流里面
        OutputStream outs = null;               //获取文件输出IO流
        BufferedOutputStream bouts = null ;
        try {
            outs = response.getOutputStream();
            bouts = new BufferedOutputStream(outs);
            int bytesRead = 0;
            byte[] buffer = new byte[8192];
            //开始向网络传输文件流
            while ((bytesRead = bins.read(buffer, 0, 8192)) != -1) {
                bouts.write(buffer, 0, bytesRead);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            inputStream.close();
            bouts.flush();//这里一定要调用flush()方法
            bins.close();
            outs.close();
            bouts.close();
        }
        return null;
    }

总结

至此,整个系列的内容全部展示说明完毕,关于Activiti工作流管理系统的开发也告一段落。总体而言,Activiti工作流引擎是十分好用的,其操作的便捷性,功能完善性都十分出色。并且结合Activiti在线作图应用,使得工作流作图功能在线化和可视化,方便在实际项目中能够更加方便的使用。
感谢各位大佬对本系列内容的支持,希望各位对此有什么意见或建议都可以在下方留言共同讨论,谢谢大家!

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 194,457评论 5 459
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 81,837评论 2 371
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 141,696评论 0 319
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 52,183评论 1 263
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 61,057评论 4 355
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 46,105评论 1 272
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 36,520评论 3 381
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 35,211评论 0 253
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 39,482评论 1 290
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 34,574评论 2 309
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 36,353评论 1 326
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 32,213评论 3 312
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 37,576评论 3 298
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 28,897评论 0 17
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,174评论 1 250
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 41,489评论 2 341
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 40,683评论 2 335

推荐阅读更多精彩内容