| | |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.zy.acs.common.constant.RedisConstant; |
| | | import com.zy.acs.common.utils.RedisSupport; |
| | | import com.zy.acs.framework.common.Cools; |
| | | import com.zy.acs.framework.common.SnowflakeIdWorker; |
| | | import com.zy.acs.framework.exception.CoolException; |
| | | import com.zy.acs.common.constant.RedisConstant; |
| | | import com.zy.acs.common.utils.RedisSupport; |
| | | import com.zy.acs.manager.common.utils.MapDataUtils; |
| | | import com.zy.acs.manager.core.domain.TaskPosDto; |
| | | import com.zy.acs.manager.core.domain.TrafficJamDto; |
| | |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.transaction.interceptor.TransactionAspectSupport; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Comparator; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * Wavefront |
| | |
| | | Travel travel = travelService.getById(segment.getTravelId()); |
| | | Agv agv = agvService.getById(travel.getAgvId()); |
| | | AgvDetail agvDetail = agvDetailService.selectByAgvId(travel.getAgvId()); |
| | | |
| | | long endNode = segment.getEndNode(); |
| | | Code startCode = codeService.getById(agvDetail.getRecentCode()); |
| | | Code endCode = codeService.getById(endNode); |
| | | |
| | | // valid ---------------------------------------------------- |
| | | if (!agvService.judgeEnable(agv.getId())) { |
| | | return; |
| | | } |
| | | if (!Cools.isEmpty(segmentService.getByAgvAndState(agv.getId(), SegmentStateType.RUNNING.toString()))) { |
| | | return; |
| | | } |
| | | |
| | | List<Segment> waitingSegList = segmentService.getByAgvAndState(agv.getId(), SegmentStateType.WAITING.toString()); |
| | | if (!Cools.isEmpty(waitingSegList)) { |
| | | for (Segment seg : waitingSegList) { |
| | | if (!seg.getId().equals(segment.getId())) { |
| | | for (Segment waitingSeg : waitingSegList) { |
| | | if (!waitingSeg.getId().equals(segment.getId())) { |
| | | return; |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (jamService.count(new LambdaQueryWrapper<Jam>() |
| | | .eq(Jam::getJamAgv, agv.getId()) |
| | | .eq(Jam::getJamSeg, segment.getId()) |
| | |
| | | return; |
| | | } |
| | | |
| | | // execute ----------------------------------------------- |
| | | // ArrayList<List<TaskPosDto>> list = JSON.parseObject(travel.getTaskContent(), new TypeReference<ArrayList<List<TaskPosDto>>>() {}); |
| | | |
| | | List<Segment> segmentList = new ArrayList<>(); |
| | | segmentList.add(segment); |
| | | |
| | | // get path list |
| | | avoidWaveCalculator.calcWaveScope(); // * sync wave scope |
| | | List<String> pathList = this.checkoutPath(agv, startCode, endCode, segment); |
| | | |
| | | // checkout path |
| | | Code startCode = codeService.getById(agvDetail.getRecentCode()); |
| | | Code endCode = codeService.getById(endNode); |
| | | List<String> pathList = this.checkoutPath(agv, startCode, endCode, segment); |
| | | if (Cools.isEmpty(pathList)) { |
| | | return; |
| | | } |
| | | |
| | | String lastCodeData = pathList.get(pathList.size() - 1); |
| | | List<Segment> segmentList = new ArrayList<>(); |
| | | segmentList.add(segment); |
| | | |
| | | // slice |
| | | String lastCodeData = pathList.get(pathList.size() - 1); |
| | | if (!endCode.getData().equals(lastCodeData)) { |
| | | // slice |
| | | Code lastCode = codeService.selectByData(lastCodeData); |
| | | |
| | | // if (pathList.size() <= MIN_SLICE_PATH_LENGTH) { |
| | | // return; |
| | |
| | | segment.setState(SegmentStateType.INIT.toString()); |
| | | segment.setUpdateTime(now); |
| | | if (!segmentService.updateById(segment)) { |
| | | log.error("Segment [{}] 更新失败 !!!", segment.getTravelId() + " - " + segment.getSerial()); |
| | | log.error("Segment [{}] failed to update !!!", segment.getGroupId() + " - " + segment.getSerial()); |
| | | } |
| | | segmentList.clear(); |
| | | |
| | | Code lastCode = codeService.selectByData(lastCodeData); |
| | | |
| | | // new move seg |
| | | Segment insertSeg = new Segment(); |
| | |
| | | if (!segmentService.save(insertSeg)) { |
| | | log.error("Segment [{}] 保存失败 !!!", segment.getTravelId() + " - " + segment.getSerial()); |
| | | } |
| | | |
| | | segmentList.add(insertSeg); |
| | | |
| | | } else { |
| | |
| | | List<String> lockPathList = mapService.checkoutPath(agvNo, startCode, endCode, true); |
| | | |
| | | if (!Cools.isEmpty(lockPathList) && // 存在避让解 |
| | | Math.abs(lockPathList.size() - unlockPathList.size()) <= Math.max((mapDataDispatcher.getCodeMatrix(lev)[0].length / 2), 5)) { |
| | | Math.abs(lockPathList.size() - unlockPathList.size()) <= Arrays.stream(mapDataDispatcher.getCodeMatrix(lev)).mapToInt(row -> row.length).sum() / 10 |
| | | ) { |
| | | |
| | | pathList = lockPathList; |
| | | } else { |