| | |
| | | package com.zy.asrs.wcs.core.utils; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.zy.asrs.framework.common.Cools; |
| | | import com.zy.asrs.framework.common.SnowflakeIdWorker; |
| | | import com.zy.asrs.framework.exception.CoolException; |
| | | import com.zy.asrs.wcs.core.entity.BasShuttle; |
| | | import com.zy.asrs.wcs.core.entity.Task; |
| | | import com.zy.asrs.wcs.core.kernel.AnalyzeService; |
| | | import com.zy.asrs.wcs.core.model.NavigateNode; |
| | | import com.zy.asrs.wcs.core.model.enums.LiftCodeType; |
| | | import com.zy.asrs.wcs.core.model.enums.NavigationMapType; |
| | | import com.zy.asrs.wcs.core.service.BasShuttleService; |
| | | import com.zy.asrs.wcs.core.service.TaskService; |
| | | import com.zy.asrs.wcs.rcs.cache.SlaveConnection; |
| | | import com.zy.asrs.wcs.rcs.entity.Device; |
| | |
| | | private DeviceService deviceService; |
| | | @Autowired |
| | | private DeviceTypeService deviceTypeService; |
| | | @Autowired |
| | | private BasShuttleService basShuttleService; |
| | | |
| | | public ShuttleThread queryShuttleWhichConvenient(Task task, Integer liftNo) { |
| | | String locNo = taskService.judgeInbound(task) ? task.getDestLoc() : task.getOriginLoc(); |
| | |
| | | continue; |
| | | } |
| | | |
| | | // //检测是否存在充电任务 |
| | | // WrkCharge wrkCharge = wrkChargeService.selectWorking(shuttle.getId()); |
| | | // if (wrkCharge != null) { |
| | | // continue; |
| | | // } |
| | | //检测是否存在充电任务 |
| | | Task taskCharge = taskService.selectChargeWorking(Integer.valueOf(device.getDeviceNo())); |
| | | if (taskCharge != null) { |
| | | continue; |
| | | } |
| | | |
| | | // 有没有被其他任务调度 |
| | | int currentLev = Utils.getLev(shuttleProtocol.getCurrentLocNo());//小车当前层高 |
| | |
| | | currDistance += WEIGHT; |
| | | } |
| | | |
| | | // // 挂载任务权重 |
| | | // List<Task> tasks = taskService.selectWorkingByShuttle(shuttle.getId()); |
| | | // if (!Cools.isEmpty(tasks)) { |
| | | // currDistance += tasks.size() * WEIGHT; |
| | | // } |
| | | // 挂载任务权重 |
| | | List<Task> tasks = taskService.selectWorkingByShuttle(Integer.valueOf(device.getDeviceNo())); |
| | | if (!Cools.isEmpty(tasks)) { |
| | | currDistance += tasks.size() * WEIGHT; |
| | | } |
| | | |
| | | if (currDistance < finalDistance) { |
| | | finalDistance = currDistance; |
| | |
| | | return resThread; |
| | | } |
| | | |
| | | // /** |
| | | // * 生成穿梭车迁移任务 |
| | | // */ |
| | | // public WrkCharge generateShuttleChargeWrkComplete(Integer shuttleNo, String locNo) { |
| | | // WrkCharge wrkCharge = new WrkCharge(); |
| | | // wrkCharge.setShuttleNo(shuttleNo); |
| | | // wrkCharge.setWrkNo(commonService.getChargeWorkNo(4)); |
| | | // wrkCharge.setUuid(String.valueOf(snowflakeIdWorker.nextId())); |
| | | // wrkCharge.setWrkSts(WrkMastStsType.NEW_MOVE.sts); // 迁移任务 |
| | | // wrkCharge.setIoType(WrkIoTypeType.MOVE.sts); |
| | | // wrkCharge.setIoPri((double) 10); |
| | | // wrkCharge.setLocNo(locNo); |
| | | // wrkCharge.setMemo("reset"); |
| | | // wrkCharge.setAppeTime(new Date()); |
| | | // |
| | | // // generate motion list |
| | | // List<Motion> motionList = analyzeService.generateShuttleChargeWrkComplete(wrkCharge); |
| | | // if (Cools.isEmpty(motionList)) { |
| | | // News.error("保存{}号四向穿梭车迁移任务失败!!!", shuttleNo); |
| | | // return null; |
| | | // } |
| | | // motionService.batchInsert(motionList, wrkCharge.getUuid(), wrkCharge.getWrkNo()); |
| | | // |
| | | // wrkCharge.setWrkSts(WrkMastStsType.ANALYZE_MOVE.sts); |
| | | // |
| | | // if (!wrkChargeService.insert(wrkCharge)) { |
| | | // News.error("保存{}号四向穿梭车迁移任务失败!!!", shuttleNo); |
| | | // return null; |
| | | // } |
| | | // |
| | | // return wrkCharge; |
| | | // } |
| | | /** |
| | | * 搜索避让库位,通过小车号和目标库位 |
| | | */ |
| | | public String searchStandByLocNo(Integer shuttleNo, Long hostId, String locNo) { |
| | | BasShuttle basShuttle = basShuttleService.getOne(new LambdaQueryWrapper<BasShuttle>() |
| | | .eq(BasShuttle::getShuttleNo, shuttleNo) |
| | | .eq(BasShuttle::getHostId, hostId)); |
| | | if (basShuttle == null) { |
| | | throw new CoolException("小车基础数据不存在"); |
| | | } |
| | | |
| | | String idleLoc = basShuttle.getIdleLoc(); |
| | | if (Cools.isEmpty(idleLoc)) { |
| | | throw new CoolException("小车避让数据不存在"); |
| | | } |
| | | |
| | | int lev = Utils.getLev(locNo);//当前楼层 |
| | | JSONArray standbyLoc = JSON.parseArray(idleLoc); |
| | | if (lev > standbyLoc.size()) { |
| | | throw new CoolException("避让数据异常"); |
| | | } |
| | | |
| | | Object object = standbyLoc.get(lev - 1); |
| | | List<String> locs = JSON.parseArray(object.toString(), String.class); |
| | | if (locs.isEmpty()) { |
| | | throw new CoolException("避让数据为空"); |
| | | } |
| | | |
| | | Integer finalDistance = ShuttleDispatcher.INF; |
| | | String recentLoc = null; |
| | | for (String loc : locs) { |
| | | //当前穿梭车到避让位计算 |
| | | List<NavigateNode> currentShuttlePath = NavigateUtils.calc( |
| | | locNo |
| | | , loc |
| | | , NavigationMapType.NORMAL.id |
| | | , Utils.getShuttlePoints(shuttleNo, lev) |
| | | );//使用正常通道地图 |
| | | if (currentShuttlePath == null) { |
| | | continue; |
| | | } |
| | | |
| | | Integer currDistance = NavigateUtils.getOriginPathAllDistance(currentShuttlePath);//计算当前路径行走总距离 |
| | | if (currDistance < finalDistance) { |
| | | finalDistance = currDistance; |
| | | recentLoc = loc; |
| | | } |
| | | } |
| | | |
| | | if (recentLoc == null) { |
| | | throw new CoolException("搜索避让位置失败"); |
| | | } |
| | | |
| | | return recentLoc; |
| | | } |
| | | |
| | | |
| | | } |