¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.jeecg.modules.flowable.service.impl; |
| | | |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.collections4.CollectionUtils; |
| | | import org.apache.shiro.SecurityUtils; |
| | | import org.flowable.common.engine.api.FlowableObjectNotFoundException; |
| | | import org.flowable.engine.history.HistoricProcessInstance; |
| | | import org.flowable.engine.runtime.ProcessInstance; |
| | | import org.flowable.task.api.Task; |
| | | import org.jeecg.common.api.vo.Result; |
| | | import org.jeecg.common.system.vo.LoginUser; |
| | | import org.jeecg.common.util.SpringContextUtils; |
| | | 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.apithird.entity.SysUser; |
| | | import org.jeecg.modules.flowable.apithird.service.FlowCallBackServiceI; |
| | | import org.jeecg.modules.flowable.apithird.service.IFlowThirdService; |
| | | import org.jeecg.modules.flowable.domain.vo.FlowTaskVo; |
| | | import org.jeecg.modules.flowable.factory.FlowServiceFactory; |
| | | import org.jeecg.modules.flowable.service.IFlowInstanceService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Objects; |
| | | |
| | | /** |
| | | * <p>工使µæµç¨å®ä¾ç®¡ç<p> |
| | | * |
| | | */ |
| | | @Service |
| | | @Slf4j |
| | | public class FlowInstanceServiceImpl extends FlowServiceFactory implements IFlowInstanceService { |
| | | @Autowired |
| | | IFlowThirdService iFlowThirdService; |
| | | @Autowired |
| | | FlowMyBusinessServiceImpl flowMyBusinessService; |
| | | |
| | | @Override |
| | | public List<Task> queryListByInstanceId(String instanceId) { |
| | | List<Task> list = taskService.createTaskQuery().processInstanceId(instanceId).active().list(); |
| | | return list; |
| | | } |
| | | |
| | | /** |
| | | * ç»ææµç¨å®ä¾ |
| | | * |
| | | * @param vo |
| | | */ |
| | | @Override |
| | | public void stopProcessInstance(FlowTaskVo vo) { |
| | | String taskId = vo.getTaskId(); |
| | | |
| | | } |
| | | |
| | | /** |
| | | * æ¿æ´»ææèµ·æµç¨å®ä¾ |
| | | * |
| | | * @param state ç¶æ |
| | | * @param instanceId æµç¨å®ä¾ID |
| | | */ |
| | | @Override |
| | | public void updateState(Integer state, String instanceId) { |
| | | |
| | | // æ¿æ´» |
| | | if (state == 1) { |
| | | runtimeService.activateProcessInstanceById(instanceId); |
| | | } |
| | | // æèµ· |
| | | if (state == 2) { |
| | | runtimeService.suspendProcessInstanceById(instanceId); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * å 餿µç¨å®ä¾ID |
| | | * |
| | | * @param instanceId æµç¨å®ä¾ID |
| | | * @param deleteReason å é¤åå |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void delete(String instanceId, String deleteReason) { |
| | | List<Task> task = taskService.createTaskQuery().processInstanceId(instanceId).list(); |
| | | if (CollectionUtils.isEmpty(task)) { |
| | | throw new CustomException("æµç¨æªå¯å¨æå·²æ§è¡å®æï¼åæ¶ç³è¯·å¤±è´¥"); |
| | | } |
| | | // æ¥è¯¢å岿°æ® |
| | | HistoricProcessInstance historicProcessInstance = getHistoricProcessInstanceById(instanceId); |
| | | if (historicProcessInstance.getEndTime() != null) { |
| | | historyService.deleteHistoricProcessInstance(historicProcessInstance.getId()); |
| | | return; |
| | | } |
| | | // å 餿µç¨å®ä¾ |
| | | runtimeService.deleteProcessInstance(instanceId, deleteReason); |
| | | // å é¤å岿µç¨å®ä¾ |
| | | historyService.deleteHistoricProcessInstance(instanceId); |
| | | /*======================æ¤åå é¤ åè°ä»¥åå
³é®æ°æ®ä¿å======================*/ |
| | | LambdaQueryWrapper<FlowMyBusiness> flowMyBusinessLambdaQueryWrapper = new LambdaQueryWrapper<>(); |
| | | flowMyBusinessLambdaQueryWrapper.eq(FlowMyBusiness::getProcessInstanceId,instanceId) |
| | | ; |
| | | //妿ä¿åæ°æ®åæªè°ç¨å¿
è°çFlowCommonService.initActBusinessæ¹æ³ï¼å°±ä¼æé®é¢ |
| | | FlowMyBusiness business = flowMyBusinessService.getOne(flowMyBusinessLambdaQueryWrapper); |
| | | //è®¾ç½®æ°æ® |
| | | String doneUsers = business.getDoneUsers(); |
| | | SysUser sysUser = iFlowThirdService.getLoginUser(); |
| | | // å¤çè¿æµç¨ç人 |
| | | JSONArray doneUserList = new JSONArray(); |
| | | if (StrUtil.isNotBlank(doneUsers)){ |
| | | doneUserList = JSON.parseArray(doneUsers); |
| | | } |
| | | if (!doneUserList.contains(sysUser.getUsername())){ |
| | | doneUserList.add(sysUser.getUsername()); |
| | | } |
| | | business |
| | | // .setActStatus(ActStatus.recall) |
| | | .setTaskId("") |
| | | .setTaskName("å·²æ¤å") |
| | | .setPriority("") |
| | | .setDoneUsers(doneUserList.toJSONString()) |
| | | .setTodoUsers("") |
| | | ; |
| | | flowMyBusinessService.updateById(business); |
| | | //spring容å¨ç±»å |
| | | String serviceImplName = business.getServiceImplName(); |
| | | FlowCallBackServiceI flowCallBackService = (FlowCallBackServiceI) SpringContextUtils.getBean(serviceImplName); |
| | | // æµç¨å¤çå®åï¼è¿è¡åè°ä¸å¡å± |
| | | if (flowCallBackService!=null)flowCallBackService.afterFlowHandle(business); |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void deleteByDataId(String dataId, String deleteReason) { |
| | | LambdaQueryWrapper<FlowMyBusiness> flowMyBusinessLambdaQueryWrapper = new LambdaQueryWrapper<>(); |
| | | flowMyBusinessLambdaQueryWrapper.eq(FlowMyBusiness::getDataId, dataId) |
| | | ; |
| | | //妿ä¿åæ°æ®åæªè°ç¨å¿
è°çFlowCommonService.initActBusinessæ¹æ³ï¼å°±ä¼æé®é¢ |
| | | FlowMyBusiness business = flowMyBusinessService.getOne(flowMyBusinessLambdaQueryWrapper); |
| | | this.delete(business.getProcessInstanceId(),deleteReason); |
| | | } |
| | | |
| | | /** |
| | | * æ ¹æ®å®ä¾IDæ¥è¯¢åå²å®ä¾æ°æ® |
| | | * |
| | | * @param processInstanceId |
| | | * @return |
| | | */ |
| | | @Override |
| | | public HistoricProcessInstance getHistoricProcessInstanceById(String processInstanceId) { |
| | | HistoricProcessInstance historicProcessInstance = |
| | | historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId).singleResult(); |
| | | if (Objects.isNull(historicProcessInstance)) { |
| | | throw new FlowableObjectNotFoundException("æµç¨å®ä¾ä¸åå¨: " + processInstanceId); |
| | | } |
| | | return historicProcessInstance; |
| | | } |
| | | |
| | | /** |
| | | * æ ¹æ®æµç¨å®ä¹IDå¯å¨æµç¨å®ä¾ |
| | | * |
| | | * @param procDefId æµç¨å®ä¹Id |
| | | * @param variables æµç¨åé |
| | | * @return |
| | | */ |
| | | @Override |
| | | public Result startProcessInstanceById(String procDefId, Map<String, Object> variables) { |
| | | |
| | | // 设置æµç¨å起人Idå°æµç¨ä¸ |
| | | LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal(); |
| | | String username = user.getUsername(); |
| | | // identityService.setAuthenticatedUserId(userId.toString()); |
| | | variables.put("initiator",username); |
| | | variables.put("_FLOWABLE_SKIP_EXPRESSION_ENABLED", true); |
| | | ProcessInstance processInstance = runtimeService.startProcessInstanceById(procDefId, variables); |
| | | processInstance.getProcessInstanceId(); |
| | | return Result.OK("æµç¨å¯å¨æå"); |
| | | } |
| | | } |