¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.jeecg.modules.flowable.apithird.business.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import org.apache.commons.collections4.CollectionUtils; |
| | | import org.flowable.engine.HistoryService; |
| | | import org.flowable.engine.history.HistoricActivityInstance; |
| | | import org.jeecg.modules.flowable.apithird.business.dto.FlowMyBusinessDto; |
| | | import org.jeecg.modules.flowable.apithird.business.entity.FlowMyBusiness; |
| | | import org.jeecg.modules.flowable.apithird.business.mapper.FlowMyBusinessMapper; |
| | | import org.jeecg.modules.flowable.apithird.business.service.IFlowMyBusinessService; |
| | | import org.jeecg.modules.flowable.domain.dto.FlowTaskDto; |
| | | import org.jeecg.modules.flowable.util.TimeUtil; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.Collections; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * @Description: æµç¨ä¸å¡æ©å±è¡¨ |
| | | * @Author: jeecg-boot |
| | | * @Date: 2021-11-25 |
| | | * @Version: V1.0 |
| | | */ |
| | | @Service |
| | | public class FlowMyBusinessServiceImpl extends ServiceImpl<FlowMyBusinessMapper, FlowMyBusiness> implements IFlowMyBusinessService { |
| | | @Resource |
| | | private FlowMyBusinessMapper flowMyBusinessMapper; |
| | | |
| | | @Autowired |
| | | private HistoryService historyService; |
| | | |
| | | public HistoricActivityInstance getPreviousNode(String taskId) { |
| | | // è·åå½åä»»å¡çæ§è¡å®ä¾ ID |
| | | String processInstanceId = historyService.createHistoricTaskInstanceQuery() |
| | | .taskId(taskId) |
| | | .singleResult() |
| | | .getProcessInstanceId(); |
| | | |
| | | // æ¥è¯¢å岿´»å¨å®ä¾ |
| | | List<HistoricActivityInstance> historicActivityInstances = historyService.createHistoricActivityInstanceQuery() |
| | | .processInstanceId(processInstanceId) |
| | | .activityType("userTask") |
| | | .finished() |
| | | .orderByHistoricActivityInstanceEndTime() |
| | | .desc() |
| | | .list(); |
| | | |
| | | // å第ä¸ä¸ªç»æï¼å³ä¸ä¸çº§èç¹ |
| | | if (!historicActivityInstances.isEmpty()) { |
| | | return historicActivityInstances.get(0); |
| | | } |
| | | |
| | | return null; |
| | | } |
| | | |
| | | @Transactional // éä½éç¦»çº§å« |
| | | public FlowMyBusiness getByDataId(String dataId) { |
| | | //妿ä¿åæ°æ®åæªè°ç¨å¿
è°çFlowCommonService.initActBusinessæ¹æ³ï¼å°±ä¼æé®é¢ |
| | | FlowMyBusiness business = flowMyBusinessMapper.selectByDataId(dataId); |
| | | return business; |
| | | } |
| | | |
| | | |
| | | public FlowMyBusiness getByProcessInstanceId(String processInstanceId) { |
| | | LambdaQueryWrapper<FlowMyBusiness> flowMyBusinessLambdaQueryWrapper = new LambdaQueryWrapper<>(); |
| | | flowMyBusinessLambdaQueryWrapper.eq(FlowMyBusiness::getProcessInstanceId,processInstanceId) |
| | | ; |
| | | //妿ä¿åæ°æ®åæªè°ç¨å¿
è°çFlowCommonService.initActBusinessæ¹æ³ï¼å°±ä¼æé®é¢ |
| | | FlowMyBusiness business = this.getOne(flowMyBusinessLambdaQueryWrapper); |
| | | return business; |
| | | } |
| | | |
| | | /** |
| | | * æµç¨-æçå·²å |
| | | * @param flowMyBusinessDto |
| | | * @return |
| | | */ |
| | | public List<FlowTaskDto> ListMyBusiness(FlowMyBusinessDto flowMyBusinessDto){ |
| | | return flowMyBusinessMapper.ListMyBusiness(flowMyBusinessDto); |
| | | } |
| | | |
| | | /** |
| | | * æµç¨æ»å°è´¦ |
| | | * @param flowMyBusinessDto |
| | | * @return |
| | | */ |
| | | public IPage<FlowMyBusinessDto> getPageList(Page page, FlowMyBusinessDto flowMyBusinessDto){ |
| | | IPage<FlowMyBusinessDto> flowMyBusinessDtoIPage =flowMyBusinessMapper.PageList(page,flowMyBusinessDto); |
| | | flowMyBusinessDtoIPage.getRecords().forEach(item -> { |
| | | if (!("").equals(item.getTaskId())&&item.getTaskId()!=null){ |
| | | HistoricActivityInstance historicActivityInstance = getPreviousNode(item.getTaskId()); |
| | | if (historicActivityInstance != null){ |
| | | item.setPreNode(historicActivityInstance.getActivityName()); |
| | | } |
| | | } |
| | | if (item.getTodoUsers() == null){ |
| | | item.setTodoUsers(""); |
| | | }else { |
| | | //å»é¤[] |
| | | item.setTodoUsers(item.getTodoUsers().replaceAll("\\[", "").replaceAll("\\]", "")); |
| | | item.setTodoUsers(item.getTodoUsers().replaceAll("\"", "")); |
| | | } |
| | | |
| | | if (item.getDoneUsers() == null){ |
| | | item.setDoneUsers(""); |
| | | }else { |
| | | //å»é¤[] |
| | | item.setDoneUsers(item.getDoneUsers().replaceAll("\\[", "").replaceAll("\\]", "")); |
| | | item.setDoneUsers(item.getDoneUsers().replaceAll("\"", "")); |
| | | } |
| | | //计ç®å¤çæ¶é¿ |
| | | Date kssj=item.getStartTime(); |
| | | Date jssj; |
| | | if (item.getEndTime() != null){ |
| | | jssj=item.getEndTime(); |
| | | }else { |
| | | jssj=new Date(); |
| | | } |
| | | item.setDuration(TimeUtil.howLong(kssj, jssj,2)); |
| | | }); |
| | | return flowMyBusinessDtoIPage; |
| | | } |
| | | |
| | | @Override |
| | | public FlowMyBusiness getFlowMyBusiness(String instanceId) { |
| | | List<FlowMyBusiness> businessList = super.list( |
| | | new QueryWrapper<FlowMyBusiness>().eq("process_instance_id", instanceId)); |
| | | return businessList.isEmpty() ? null : businessList.get(0); |
| | | } |
| | | |
| | | @Override |
| | | public FlowMyBusiness getFlowMyBusiness(String instanceId, String taskId) { |
| | | List<FlowMyBusiness> businessList = super.list( |
| | | new QueryWrapper<FlowMyBusiness>().eq("process_instance_id", instanceId).eq("task_id", taskId)); |
| | | return businessList.isEmpty() ? null : businessList.get(0); |
| | | } |
| | | |
| | | @Override |
| | | public FlowMyBusiness selectByDataId(String dataId) { |
| | | List<FlowMyBusiness> businessList = super.list( |
| | | new QueryWrapper<FlowMyBusiness>().eq("data_id", dataId)); |
| | | return businessList.isEmpty() ? null : businessList.get(0); |
| | | } |
| | | |
| | | @Override |
| | | public List<FlowMyBusiness> selectListByDataId(String dataId) { |
| | | //妿ä¿åæ°æ®åæªè°ç¨å¿
è°çFlowCommonService.initActBusinessæ¹æ³ï¼å°±ä¼æé®é¢ |
| | | LambdaQueryWrapper<FlowMyBusiness> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.eq(FlowMyBusiness::getDataId, dataId); |
| | | List<FlowMyBusiness> list = flowMyBusinessMapper.selectList(queryWrapper); |
| | | if(CollectionUtils.isEmpty(list)){ |
| | | return Collections.emptyList(); |
| | | } |
| | | return list; |
| | | } |
| | | } |