| | |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.zy.acs.framework.exception.CoolException; |
| | | import com.zy.acs.manager.manager.entity.Segment; |
| | | import com.zy.acs.manager.manager.entity.Task; |
| | | import com.zy.acs.manager.manager.enums.ActionStsType; |
| | | import com.zy.acs.manager.manager.enums.SegmentStateType; |
| | | import com.zy.acs.manager.manager.enums.TaskStsType; |
| | | import com.zy.acs.manager.manager.mapper.SegmentMapper; |
| | | import com.zy.acs.manager.manager.service.AgvService; |
| | | import com.zy.acs.manager.manager.service.SegmentService; |
| | | import com.zy.acs.manager.manager.service.*; |
| | | import com.zy.acs.framework.common.Cools; |
| | | import com.zy.acs.manager.manager.service.TravelService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Comparator; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | |
| | | private AgvService agvService; |
| | | @Autowired |
| | | private TravelService travelService; |
| | | @Autowired |
| | | private TaskService taskService; |
| | | @Autowired |
| | | private ActionService actionService; |
| | | |
| | | @Override |
| | | public void processNext(List<Segment> segmentList) { |
| | | Date now = new Date(); |
| | | |
| | | segmentList.stream().max(Comparator.comparingInt(Segment::getSerial)).ifPresent(segment -> { |
| | | Segment nextSegment = this.getNextStepOfInit(segment.getTravelId(), segment.getSerial()); |
| | |
| | | if (null != nextSegment) { |
| | | |
| | | nextSegment.setState(SegmentStateType.WAITING.toString()); |
| | | nextSegment.setUpdateTime(now); |
| | | nextSegment.setUpdateTime(new Date()); |
| | | if (!this.updateById(nextSegment)) { |
| | | log.error("Segment [{}] failed to update !!!", nextSegment.getGroupId() + " - " + nextSegment.getSerial()); |
| | | } |
| | |
| | | } |
| | | |
| | | @Override |
| | | public Segment getJustWaitingSeg(Long agvId) { |
| | | public Segment getPreviousStepOfFinish(Long travelId, Integer serial, String memo) { |
| | | return this.getOne(new LambdaQueryWrapper<Segment>() |
| | | .eq(Segment::getTravelId, travelId) |
| | | .eq(Segment::getSerial, serial - 1) |
| | | // .eq(Segment::getState, SegmentStateType.FINISH.toString()) |
| | | .eq(Segment::getMemo, memo) |
| | | ); |
| | | } |
| | | |
| | | @Override |
| | | public List<Segment> getJustWaitingSeg(Long agvId) { |
| | | if (null == agvId) { |
| | | return null; |
| | | } |
| | |
| | | if (waitingSegList.size() > 1) { |
| | | log.error("{}号车辆存在多个等待中的Segment!!!", agvService.getById(agvId).getUuid()); |
| | | } |
| | | return waitingSegList.get(0); |
| | | return waitingSegList; |
| | | } |
| | | } |
| | | |
| | |
| | | return this.baseMapper.getGroupNo(state.toString(), agvId, groupNo); |
| | | } |
| | | |
| | | @Override |
| | | public List<Segment> getRunningByEndCode(Long codeId) { |
| | | if (null == codeId) { |
| | | return new ArrayList<>(); |
| | | } |
| | | return this.list(new LambdaQueryWrapper<Segment>() |
| | | .eq(Segment::getEndNode, codeId) |
| | | .in(Segment::getState, SegmentStateType.WAITING.toString(), SegmentStateType.RUNNING.toString()) |
| | | ); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional |
| | | public Boolean cancel(Long segmentId, Long userId) { |
| | | Date now = new Date(); |
| | | Segment segment = this.getById(segmentId); |
| | | String groupId = segment.getGroupId(); |
| | | // update segment list |
| | | List<Segment> segmentList = this.list(new LambdaQueryWrapper<Segment>().eq(Segment::getGroupId, groupId)); |
| | | for (Segment seg : segmentList) { |
| | | Task task = taskService.getById(segment.getTaskId()); |
| | | if (task != null && |
| | | (!task.getTaskSts().equals(TaskStsType.COMPLETE.val()) && !task.getTaskSts().equals(TaskStsType.CANCEL.val()))) { |
| | | throw new CoolException("the task is not finish"); |
| | | } |
| | | seg.setState(SegmentStateType.FINISH.toString()); |
| | | seg.setUpdateTime(now); |
| | | if (!this.updateById(seg)) { |
| | | throw new CoolException("failed to cancel segment"); |
| | | } |
| | | } |
| | | this.processNext(segmentList); |
| | | // update action list |
| | | actionService.updateStsByGroupId(groupId, ActionStsType.EXPIRED.val()); |
| | | return Boolean.TRUE; |
| | | } |
| | | |
| | | } |