基于jeecgboot-vue3的Flowable流程-自定義業(yè)務(wù)表單處理(一)支持同一個(gè)業(yè)務(wù)多個(gè)關(guān)聯(lián)流程的選擇支持

admin2024-06-21  12

因為這個(gè)項目license問(wèn)題無(wú)法開(kāi)源,更多技術(shù)支持與服務(wù)請加入我的知識星球。

基于jeecgboot-vue3的Flowable流程-自定義業(yè)務(wù)表單處理(一)支持同一個(gè)業(yè)務(wù)多個(gè)關(guān)聯(lián)流程的選擇支持,第1張

這部分先講講支持自定義業(yè)務(wù)表單一個(gè)業(yè)務(wù)服務(wù)表單多個(gè)流程的支持處理

1、后端mapper部分

如下,修改selectSysCustomFormByServiceName為list對象,以便支持多個(gè)

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.jeecg.modules.flowable.mapper.SysCustomFormMapper">
	<resultMap type="org.jeecg.modules.flowable.entity.SysCustomForm" id="sysCustomFormResult">
        <result property="id" column="id"/>
        <result property="businessName" column="business_name"/>
        <result property="businessService" column="business_service"/>
        <result property="flowName" column="flow_name"/>
        <result property="deployId" column="deploy_id"/>
        <result property="routeName" column="route_name"/>
        <result property="component" column="component"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="sysOrgCode" column="sys_org_code"/>
    </resultMap>
	
    <select id="selectSysCustomFormById" parameterType="String" resultType="org.jeecg.modules.flowable.entity.SysCustomForm">
         select id, business_name, business_service, deploy_id, route_name,component,create_time, update_time, create_by, update_by, sys_org_code 
         from sys_custom_form where id = #{formId}
    </select>
    
    <select id="selectSysCustomFormByServiceName" parameterType="String" resultMap="sysCustomFormResult">
         select id, business_name, business_service, flow_name, deploy_id, route_name,component,create_time, update_time, create_by, update_by, sys_org_code 
         from sys_custom_form where business_service = #{serviceName}
    </select>
    
    <update id="updateCustom" parameterType="Object">
         update sys_custom_form set deploy_id= #{customFormVo.deployId}, flow_name=#{customFormVo.flowName} where id = #{customFormVo.id}
    </update>
    
    <select id="selectBussinessKeyByDeployId" parameterType="String" resultType="String">
         select id from sys_custom_form where deploy_id = #{deployid}
    </select>
    
</mapper>

2、對流程啟動(dòng)也要修改,因為根據用戶(hù)選擇出來(lái)的id進(jìn)行處理

 public Result startProcessInstanceByDataId(String dataId, String selectFlowId, String serviceName, Map<String, Object> variables) {
    	//提交審批的時(shí)候進(jìn)行流程實(shí)例關(guān)聯(lián)初始化
    	if (StringUtils.isEmpty(selectFlowId)){
            return Result.error("未找到關(guān)聯(lián)流程selectFlowId:"+selectFlowId);
        }
    	/*
        if (serviceName==null){
             return Result.error("未找到serviceName:"+serviceName);
        }*/
        SysCustomForm sysCustomForm = sysCustomFormService.getById(selectFlowId);
        if(sysCustomForm ==null){
        	 return Result.error("未找到sysCustomForm:"+serviceName);
        }
        //優(yōu)先考慮自定義業(yè)務(wù)表是否關(guān)聯(lián)流程,再看通用的表單流程關(guān)聯(lián)表
        ProcessDefinition processDefinition;
        String deployId = sysCustomForm.getDeployId();
        if(StringUtils.isEmpty(deployId)) {
        	SysDeployForm sysDeployForm  = sysDeployFormService.selectSysDeployFormByFormId(sysCustomForm.getId());
            if(sysDeployForm ==null){          	
       	       return Result.error("自定義表單也沒(méi)關(guān)聯(lián)流程定義表,流程沒(méi)定義關(guān)聯(lián)自定義表單"+sysCustomForm.getId());
            }
            processDefinition = repositoryService.createProcessDefinitionQuery()
        		.parentDeploymentId(sysDeployForm.getDeployId()).latestVersion().singleResult();
        }
        else {
        	processDefinition = repositoryService.createProcessDefinitionQuery()
            		.parentDeploymentId(deployId).latestVersion().singleResult();
        }
        
        LambdaQueryWrapper<FlowMyBusiness> flowMyBusinessLambdaQueryWrapper = new LambdaQueryWrapper<>();
        flowMyBusinessLambdaQueryWrapper.eq(FlowMyBusiness::getDataId, dataId);
        FlowMyBusiness business = flowMyBusinessService.getOne(flowMyBusinessLambdaQueryWrapper);
        if (business==null){
        	if(processDefinition==null) {
        		return Result.error("自定義表單也沒(méi)關(guān)聯(lián)流程定義表,流程沒(méi)定義關(guān)聯(lián)自定義表單"+sysCustomForm.getId());
        	}
        	boolean binit = flowCommonService.initActBusiness(sysCustomForm.getBusinessName(), dataId, serviceName, 
        	processDefinition.getKey(), processDefinition.getId(), sysCustomForm.getRouteName());
        	if(!binit) {
        		return Result.error("自定義表單也沒(méi)關(guān)聯(lián)流程定義表,流程沒(méi)定義關(guān)聯(lián)自定義表單"+sysCustomForm.getId());
        	}
            FlowMyBusiness businessnew = flowMyBusinessService.getOne(flowMyBusinessLambdaQueryWrapper);
           //流程實(shí)例關(guān)聯(lián)初始化結束
            if (StrUtil.isNotBlank(businessnew.getProcessDefinitionId())){
              return this.startProcessInstanceById(businessnew.getProcessDefinitionId(),variables);
            }
            return this.startProcessInstanceByKey(businessnew.getProcessDefinitionKey(),variables);
        }
        else {
        	 return Result.error("已經(jīng)存在這個(gè)dataid實(shí)例,不要重復申請:"+dataId);
        }
        
    }

3、前端代碼如下:

<template>
  <span>
    <a-button :type="btnType" @click="applySubmit()" :loading="submitLoading">{{text}}</a-button>
    <a-modal :z-index="100" :title="firstInitiatorTitle" @cancel="firstInitiatorOpen = false" v-model:open="firstInitiatorOpen"
      :width="'50%'" append-to-body>
       <a-descriptions bordered layout="vertical">
         <a-descriptions-item :span="3">
               <a-badge status="processing" text="選擇提醒" />
          </a-descriptions-item>
          <a-descriptions-item label="重新發(fā)起新流程按鈕" labelStyle="{ color: '#fff', fontWeight: 'bold', fontSize='18px'}">
            重新發(fā)起新流程會(huì )刪除之前發(fā)起的任務(wù),重新開(kāi)始.
          </a-descriptions-item>
          <a-descriptions-item label="繼續發(fā)起老流程按鈕">
            繼續發(fā)起流程就在原來(lái)流程基礎上繼續流轉.
          </a-descriptions-item>
       </a-descriptions>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="ReStartByDataId(true)">重新發(fā)起新流程</el-button>
        <el-button type="primary" @click="ReStartByDataId(false)">繼續發(fā)起老流程</el-button>
        <el-button @click="firstInitiatorOpen = false">取 消</el-button>
      </span>
    </a-modal>

    <!--掛載關(guān)聯(lián)多個(gè)流程-->
    <a-modal @cancel="flowOpen = false" :title="flowTitle" v-model:open="flowOpen" width="70%" append-to-body>
      <el-row :gutter="64">
        <el-col :span="20" :xs="64" style="width: 100%">
          <el-table ref="singleTable" :data="processList" border highlight-current-row style="width: 100%">
             <el-table-column type="selection" width="55" align="center" />
             <el-table-column label="主鍵" align="center" prop="id" v-if="true"/>
             <el-table-column label="業(yè)務(wù)表單名稱(chēng)" align="center" prop="businessName" />
             <el-table-column label="業(yè)務(wù)服務(wù)名稱(chēng)" align="center" prop="businessService" />
             <el-table-column label="流程名稱(chēng)" align="center" prop="flowName" />
             <el-table-column label="關(guān)聯(lián)流程發(fā)布主鍵" align="center" prop="deployId" />
             <el-table-column label="前端路由地址" align="center" prop="routeName" />
             <el-table-column label="組件注入方法" align="center" prop="component" />
             <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
               <template #default="scope">
                 <el-button size="small" type="primary" @click="selectProcess(scope.row)">確定</el-button>
               </template>
             </el-table-column>
            </el-table>
        </el-col>
      </el-row>
    </a-modal>

  </span>
</template>

<script lang="ts" setup>
  import { ref, reactive  } from 'vue';
  import { useRouter, useRoute } from 'vue-router';
  import {
    definitionStartByDataId,
    isFirstInitiator,
    deleteActivityAndJoin,
    getProcesss
  } from "/@/views/flowable/api/definition";
  
  import { useMessage } from '/@/hooks/web/useMessage';
  
  const { createMessage, createConfirm } = useMessage();

  defineOptions({ name: 'ActApplyBtn' })
  const props = defineProps({
    btnType: {
      type: String,
      default: 'link',
      required: false
    },
    dataId: {
      type: String,
      default: '',
      required: true
    },
    serviceName: {
      type: String,
      default: '',
      required: true
    },
    variables: {
      type: Object,
      default: {},
    },
    text: {
      type: String,
      default: '提交申請',
      required: false
    }
  })

  const emit = defineEmits([
    'success'
  ])

  // 獲取路由器對象 href跳轉用到
  const router = useRouter();
  const route = useRoute();

  const modalVisible = ref(false)
  const submitLoading = ref(false)
  const form = ref<any>({})
  const firstInitiatorOpen = ref(false)
  const firstInitiatorTitle = ref('')
  // 關(guān)聯(lián)流程數據
  const processList = ref<any>([])
  const flowOpen = ref(false)
  const flowTitle = ref('')
  const selectFlowId = ref('')  //選擇或使用的流程ID
  const error = ref('')

  const selectProcess = (row) => {
    selectFlowId.value = row.id;
    flowOpen.value = false;
    var params = Object.assign({
      dataId: props.dataId
    }, props.variables);
    definitionStartByDataId(props.dataId, selectFlowId.value, props.serviceName, params)
      .then(res => {
        //console.log("startByDataId res",res);
        if (res.code == 200 ) {
          createMessage.success(res.msg);
          emit('success');
        } else {
          createMessage.error(res.msg);
        }
      })
      .finally(() => (submitLoading.value = false));
  }
  const ReStartByDataId = (isNewFlow: boolean) => {
    if(isNewFlow) {
      submitLoading.value = true;
      deleteActivityAndJoin(props.dataId,props.variables)
      .then(res => {
        if (res.code == 200 && res.result) { //若刪除成功
          var params = Object.assign({
            dataId: props.dataId
          }, props.variables);
          definitionStartByDataId(props.dataId, selectFlowId.value, props.serviceName, params)
            .then(res => {
              if (res.code == 200) {
                firstInitiatorOpen.value = false;
                createMessage.success(res.message);
                emit('success');
              } else {
                createMessage.error(res.message);
              }
            })
        }
      })
      .finally(() => (submitLoading.value = false));
    }
    else {//繼續原有流程流轉,跳到流程處理界面上
      //console.log("props.variables",props.variables);
      router.push({
        path: '/flowable/task/record/index',
        query: {
          procInsId: props.variables.processInstanceId,
          deployId: props.variables.deployId,
          taskId: props.variables.taskId,
          businessKey: props.dataId,
          nodeType: "",
          appType: "ZDYYW",
          finished: true
        },
      })
    }
  }
  const applySubmit = () => {
    if (props.dataId && props.dataId.length < 1) {
      error.value = '必須傳入參數dataId';
      createMessage.error(error.value);
      return;
    }
    if (props.serviceName && props.serviceName.length < 1) {
      error.value = '必須傳入參數serviceName';
      createMessage.error(error.value);
      return;
    } else {
      error.value = '';
    }
    //對于自定義業(yè)務(wù),判斷是否是駁回或退回的第一個(gè)發(fā)起人節點(diǎn)
    submitLoading.value = true;
    isFirstInitiator(props.dataId, props.variables)
      .then(res => {
        if (res.code === 200 && res.result) { //若是,彈出窗口選擇重新發(fā)起新流程還是繼續老流程
          firstInitiatorTitle.value = "根據自己需要進(jìn)行選擇"
          firstInitiatorOpen.value = true;
        }
        else {
          submitLoading.value = true;
          const processParams = {
             serviceName: props.serviceName
          }
          /**查詢(xún)關(guān)聯(lián)流程信息 */
          getProcesss(processParams).then(res => {
            processList.value = res.result;
              submitLoading.value = false;
              if (processList.value && processList.value.length > 1) {
                flowOpen.value = true;
              }
              else if (processList.value && processList.value.length === 1) {
                selectFlowId.value = res.result[0].id;
                var params = Object.assign({
                  dataId: props.dataId
                }, props.variables);
                definitionStartByDataId(props.dataId, selectFlowId.value, props.serviceName, params)
                  .then(res => {
                    console.log("definitionStartByDataId res",res);
                    if (res.code == 200 ) {
                      createMessage.success(res.message);
                      emit('success');
                    } else {
                      createMessage.error(res.message);
                    }
                  })
                  .finally(() => (submitLoading.value = false));
              } else {
                createMessage.error("檢查該業(yè)務(wù)是否已經(jīng)關(guān)聯(lián)流程!");
              }
          })
          .finally(() => (submitLoading.value = false));
        }
      })
      .finally(() => (submitLoading.value = false));
    }
</script>

4、效果圖如下:

基于jeecgboot-vue3的Flowable流程-自定義業(yè)務(wù)表單處理(一)支持同一個(gè)業(yè)務(wù)多個(gè)關(guān)聯(lián)流程的選擇支持,第2張

基于jeecgboot-vue3的Flowable流程-自定義業(yè)務(wù)表單處理(一)支持同一個(gè)業(yè)務(wù)多個(gè)關(guān)聯(lián)流程的選擇支持,第3張

本文來(lái)自互聯(lián)網(wǎng)用戶(hù)投稿,該文觀(guān)點(diǎn)僅代表作者本人,不代表本站立場(chǎng)。本站僅提供信息存儲空間服務(wù),不擁有所有權,不承擔相關(guān)法律責任。如若轉載,請注明原文出處。如若內容造成侵權/違法違規/事實(shí)不符,請聯(lián)系SD編程學(xué)習網(wǎng):675289112@qq.com進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!
一级毛片在线一区二区-亚洲精品无码专区土豆网在线播放-亚洲无乱码一区二区三区-亚洲一区二区三区精品