zhangherong
2025-06-25 23855599412c4d61b38d78f0f3abd3430a48b5b1
lxzn-module-flowable/src/main/java/org/jeecg/modules/flowable/apithird/service/FlowCommonService.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,87 @@
package org.jeecg.modules.flowable.apithird.service;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.jeecg.modules.flowable.apithird.business.entity.FlowMyBusiness;
import org.jeecg.modules.flowable.apithird.business.service.impl.FlowMyBusinessServiceImpl;
import org.jeecg.modules.flowable.apithird.common.exception.CustomException;
import org.jeecg.modules.flowable.service.impl.FlowInstanceServiceImpl;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
/**
 *业务模块调用API的集合
 *@author PanMeiCheng
 *@date 2021/11/22
 *@version 1.0
 */
@Service
public class FlowCommonService {
    @Resource
    FlowMyBusinessServiceImpl flowMyBusinessService;
    @Resource
    FlowInstanceServiceImpl flowInstanceService;
    /**
     * åˆå§‹ç”Ÿæˆæˆ–修改业务与流程的关联信息<br/>
     * å½“业务模块新增一条数据后调用,此时业务数据关联一个流程定义,以备后续流程使用
     * @return æ˜¯å¦æˆåŠŸ
     * @param title å¿…填。流程业务简要描述。例:2021å¹´11月26日xxxxx申请
     * @param dataId å¿…填。业务数据Id,如果是一对多业务关系,传入主表的数据Id
     * @param serviceImplName å¿…填。业务service注入spring容器的名称。
*                        ä¾‹å¦‚:@Service("demoService")则传入 demoService
     * @param processDefinitionKey å¿…填。流程定义Key,传入此值,未来启动的会是该类流程的最新一个版本
     * @param processDefinitionId é€‰å¡«ã€‚流程定义Id,传入此值,未来启动的为指定版本的流程
     */
    public boolean initActBusiness(String title,String dataId, String serviceImplName, String processDefinitionKey, String processDefinitionId){
        boolean hasBlank = StrUtil.hasBlank(title,dataId, serviceImplName, processDefinitionKey);
        if (hasBlank) throw new CustomException("流程关键参数未填完全!dataId, serviceImplName, processDefinitionKey");
        LambdaQueryWrapper<FlowMyBusiness> flowMyBusinessLambdaQueryWrapper = new LambdaQueryWrapper<>();
        flowMyBusinessLambdaQueryWrapper.eq(FlowMyBusiness::getDataId, dataId)
        ;
        FlowMyBusiness flowMyBusiness = new FlowMyBusiness();
        FlowMyBusiness business = flowMyBusinessService.getOne(flowMyBusinessLambdaQueryWrapper);
        if (business!=null){
            flowMyBusiness = business;
        } else {
            flowMyBusiness.setId(IdUtil.fastSimpleUUID());
        }
        if (processDefinitionId==null){
            // ä»¥ä¾¿æ›´æ–°æµç¨‹
            processDefinitionId = "";
        }
        flowMyBusiness.setTitle(title)
                .setDataId(dataId)
                .setServiceImplName(serviceImplName)
                .setProcessDefinitionKey(processDefinitionKey)
                .setProcessDefinitionId(processDefinitionId)
                ;
        if (business!=null){
            return flowMyBusinessService.updateById(flowMyBusiness);
        } else {
            return flowMyBusinessService.save(flowMyBusiness);
        }
    }
    /**
     * åˆ é™¤æµç¨‹
     * @param dataId
     * @return
     */
    public boolean delActBusiness(String dataId){
        boolean hasBlank = StrUtil.hasBlank(dataId);
        if (hasBlank) throw new CustomException("流程关键参数未填完全!dataId");
        LambdaQueryWrapper<FlowMyBusiness> flowMyBusinessQueryWrapper = new LambdaQueryWrapper<>();
        flowMyBusinessQueryWrapper.eq(FlowMyBusiness::getDataId,dataId);
        FlowMyBusiness one = flowMyBusinessService.getOne(flowMyBusinessQueryWrapper);
        if (one.getProcessInstanceId()!=null){
            try {
                flowInstanceService.delete(one.getProcessInstanceId(),"删除流程");
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return flowMyBusinessService.remove(flowMyBusinessQueryWrapper);
    }
}