|  |  | 
 |  |  | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | 
 |  |  | import com.zy.acs.framework.common.Cools; | 
 |  |  | import com.zy.acs.manager.manager.controller.result.MissionVo; | 
 |  |  | import com.zy.acs.manager.manager.entity.Action; | 
 |  |  | import com.zy.acs.manager.manager.entity.AgvDetail; | 
 |  |  | import com.zy.acs.manager.manager.entity.Code; | 
 |  |  | import com.zy.acs.manager.manager.entity.Segment; | 
 |  |  | import com.zy.acs.manager.manager.entity.*; | 
 |  |  | import com.zy.acs.manager.manager.enums.SegmentStateType; | 
 |  |  | import com.zy.acs.manager.manager.service.*; | 
 |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
 |  |  | 
 |  |  |     private CodeService codeService; | 
 |  |  |     @Autowired | 
 |  |  |     private AgvDetailService agvDetailService; | 
 |  |  |     @Autowired | 
 |  |  |     private TaskService taskService; | 
 |  |  |  | 
 |  |  |     @Override | 
 |  |  |     public List<MissionVo> getList(Long agvId, String groupNo) { | 
 |  |  |         List<MissionVo> result = new ArrayList<>(); | 
 |  |  |         List<String> runningGroupNos = segmentService.getGroupNo(SegmentStateType.RUNNING, agvId, groupNo); | 
 |  |  |         for (String runningGroupNo : runningGroupNos) { | 
 |  |  |             MissionVo vo = generate(runningGroupNo); | 
 |  |  |             MissionVo vo = generateVo(runningGroupNo); | 
 |  |  |             if (null != vo) { | 
 |  |  |                 result.add(vo); | 
 |  |  |             } | 
 |  |  | 
 |  |  |         return result; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     public MissionVo generate(String groupNo) { | 
 |  |  |     @Override | 
 |  |  |     public MissionVo generateVo(String groupNo) { | 
 |  |  |         if (Cools.isEmpty(groupNo)) { | 
 |  |  |             return null; | 
 |  |  |         } | 
 |  |  |         // segment ------------------------------- | 
 |  |  |         List<Segment> list = segmentService.list(new LambdaQueryWrapper<Segment>().eq(Segment::getGroupId, groupNo).orderByAsc(Segment::getSerial)); | 
 |  |  |         if (Cools.isEmpty(list)) { | 
 |  |  |             return null; | 
 |  |  |         } | 
 |  |  |         Segment segment = list.get(0); | 
 |  |  |  | 
 |  |  |         // agv ------------------------------- | 
 |  |  |         AgvDetail agvDetail = agvDetailService.selectByAgvId(segment.getAgvId()); | 
 |  |  |         Long recentCode = agvDetail.getRecentCode(); | 
 |  |  |         String currCode = null; | 
 |  |  |         if (null != recentCode) { | 
 |  |  |             currCode = codeService.getById(recentCode).getData(); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         // action ------------------------------- | 
 |  |  |         List<Action> actionList = actionService.list(new LambdaQueryWrapper<Action>() | 
 |  |  |                 .eq(Action::getGroupId, groupNo).orderByDesc(Action::getPriority)); | 
 |  |  |         if (Cools.isEmpty(actionList)) { | 
 |  |  |             return null; | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         MissionVo vo = new MissionVo(); | 
 |  |  |         vo.setGroupNo(groupNo); | 
 |  |  | 
 |  |  |         vo.setTaskNos(list.stream().map(Segment::getTaskId$).collect(Collectors.toList())); | 
 |  |  |         vo.setBackpack(segment.getBackpack()); | 
 |  |  |         vo.setDestCode(segment.getEndNode$()); | 
 |  |  |         vo.setProgress(calcProgress(groupNo)); | 
 |  |  |         vo.setCurrCode(currCode); | 
 |  |  |         vo.setProgress(calcProgress(currCode, actionList)); | 
 |  |  |         return vo; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     public Double calcProgress(String groupNo) { | 
 |  |  |         double progress = 0D; | 
 |  |  |     @Override | 
 |  |  |     public MissionVo generateVoMoreInfo(String groupNo) { | 
 |  |  |         MissionVo vo = generateVo(groupNo); | 
 |  |  |         if (null == vo) { | 
 |  |  |             return vo; | 
 |  |  |         } | 
 |  |  |         List<Segment> list = segmentService.list(new LambdaQueryWrapper<Segment>().eq(Segment::getGroupId, groupNo).orderByAsc(Segment::getSerial)); | 
 |  |  |         if (Cools.isEmpty(list)) { | 
 |  |  |             return null; | 
 |  |  |         } | 
 |  |  |         List<Action> actionList = actionService.list(new LambdaQueryWrapper<Action>() | 
 |  |  |                 .eq(Action::getGroupId, groupNo). | 
 |  |  |                         orderByDesc(Action::getPriority)); | 
 |  |  |  | 
 |  |  |                 .eq(Action::getGroupId, groupNo).orderByDesc(Action::getPriority)); | 
 |  |  |         if (Cools.isEmpty(actionList)) { | 
 |  |  |             return progress; | 
 |  |  |             return null; | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         Segment segment = list.get(0); | 
 |  |  |         Action action = actionList.get(0); | 
 |  |  |         AgvDetail agvDetail = agvDetailService.selectByAgvId(action.getAgvId()); | 
 |  |  |         Long recentCode = agvDetail.getRecentCode(); | 
 |  |  |         if (null == recentCode) { | 
 |  |  |         Task task = taskService.getById(segment.getTaskId()); | 
 |  |  | //        vo.setSendTime(action.getStartTime()); | 
 |  |  |         vo.setBusNo(task.getBusId$()); | 
 |  |  |         vo.setActionCount(actionList.size()); | 
 |  |  |         vo.setTaskIds(list.stream().map(Segment::getTaskId).collect(Collectors.toList())); | 
 |  |  |         vo.setCodeList(actionList.stream().map(Action::getCode).distinct().collect(Collectors.toList())); | 
 |  |  |         vo.setActionIds(actionList.stream().map(Action::getId).collect(Collectors.toList())); | 
 |  |  |         return vo; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     public Double calcProgress(String currCode, List<Action> actionList) { | 
 |  |  |         double progress = 0D; | 
 |  |  |         if (Cools.isEmpty(actionList, currCode)) { | 
 |  |  |             return progress; | 
 |  |  |         } | 
 |  |  |         Code code = codeService.getById(recentCode); | 
 |  |  |  | 
 |  |  |         List<String> codeList = actionList.stream().map(Action::getCode).collect(Collectors.toList()); | 
 |  |  |         List<String> codeList = actionList.stream().map(Action::getCode).distinct().collect(Collectors.toList()); | 
 |  |  |  | 
 |  |  |         int totalCodes = codeList.size(); | 
 |  |  |         int currentIndex = codeList.indexOf(code.getData()); | 
 |  |  |         int currentIndex = codeList.indexOf(currCode); | 
 |  |  |  | 
 |  |  |         if (currentIndex >= 0) { | 
 |  |  |             progress = (currentIndex + 1) * 100.0 / totalCodes; |