package com.zy.asrs.service.impl; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.core.common.Cools; import com.core.exception.CoolException; import com.zy.asrs.entity.*; import com.zy.asrs.mapper.*; import com.zy.asrs.service.*; import com.zy.asrs.utils.Utils; import com.zy.common.model.*; import com.zy.common.model.enums.NavigationMapType; import com.zy.common.service.CommonService; import com.zy.common.service.erp.ErpService; import com.zy.common.utils.*; import com.zy.core.DevpThread; import com.zy.core.News; import com.zy.core.cache.MessageQueue; import com.zy.core.cache.SlaveConnection; import com.zy.core.enums.*; import com.zy.core.model.*; import com.zy.core.model.command.*; import com.zy.core.model.protocol.*; import com.zy.core.properties.SlaveProperties; import com.zy.core.thread.*; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.interceptor.TransactionAspectSupport; import java.util.*; import java.util.stream.Collectors; /** * 立体仓库WCS系统主流程业务 * Created by vincent on 2020/8/6 */ @Slf4j @Service("mainService") @Transactional public class MainServiceImpl { @Value("${wms.url}") private String wmsUrl; @Autowired private SlaveProperties slaveProperties; @Autowired private WrkMastMapper wrkMastMapper; @Autowired private WrkMastService wrkMastService; @Autowired private WrkDetlService wrkDetlService; @Autowired private LocMastService locMastService; @Autowired private LocDetlService locDetlService; @Autowired private StaDescService staDescService; @Autowired private BasDevpService basDevpService; @Autowired private BasErrLogService basErrLogService; @Autowired private BasSteErrLogService basSteErrLogService; @Autowired private BasShuttleService basShuttleService; @Autowired private BasShuttleErrLogService basShuttleErrLogService; @Autowired private BasShuttleErrService basShuttleErrService; @Autowired private BasCrnErrorMapper basCrnErrorMapper; @Autowired private BasSteService basSteService; @Autowired private WrkChargeService wrkChargeService; @Autowired private BasSteErrService basSteErrService; @Autowired private CommonService commonService; @Autowired private WrkChargeMapper wrkChargeMapper; @Autowired private BasMapService basMapService; @Autowired private ErpService erpService; @Autowired private OrderMapper orderMapper; @Autowired private OrderDetlMapper orderDetlMapper; @Autowired private BasLiftService basLiftService; @Autowired private RedisUtil redisUtil; /** * 组托 * 入库站,根据条码扫描生成入库工作档,工作状态 2 */ public void generateStoreWrkFile() { // 根据输送线plc遍历 for (DevpSlave devp : slaveProperties.getDevp()) { // 遍历入库口 for (DevpSlave.Sta inSta : devp.getInSta()) { // 获取入库站信息 DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId()); StaProtocol staProtocol = devpThread.getStation().get(inSta.getStaNo()); if (staProtocol == null) { continue; } else { staProtocol = staProtocol.clone(); } Short workNo = staProtocol.getWorkNo(); // 尺寸检测异常 boolean back = false; String errMsg = "异常:"; if (staProtocol.isFrontErr()) { errMsg = errMsg+"前超限;"; back = true; } if (staProtocol.isBackErr()) { errMsg = errMsg+"后超限"; back = true; } if (staProtocol.isHighErr()) { errMsg = errMsg+"高超限"; back = true; } if (staProtocol.isLeftErr()) { errMsg = errMsg+"左超限"; back = true; } if (staProtocol.isRightErr()) { errMsg = errMsg+"右超限"; back = true; } if (staProtocol.isWeightErr()) { errMsg = errMsg+"超重"; back = true; } if (staProtocol.isBarcodeErr()) { errMsg = errMsg+"扫码失败"; back = true; } // 退回 if (back) { // led 异常显示 LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, inSta.getLed()); if (ledThread != null) { MessageQueue.offer(SlaveType.Led, inSta.getLed(), new Task(3, errMsg)); } continue; } // 判断是否满足入库条件 if (staProtocol.isAutoing() && staProtocol.isLoading() && staProtocol.isInEnable() && !staProtocol.isEmptyMk() && (workNo == 0 || (workNo >= 9990 && workNo <= 9999)) ) { // 获取条码扫描仪信息 BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, inSta.getBarcode()); if (barcodeThread == null) { continue; } String barcode = barcodeThread.getBarcode(); if(!Cools.isEmpty(barcode)) { // News.info("{}号条码扫描器检测条码信息:{}", inSta.getBarcode(), barcode); if("NG".endsWith(barcode) || "NoRead".equals(barcode) || "empty".equals(barcode)|| "00000000".equals(barcode)) { // staProtocol.setWorkNo((short) 32002); // staProtocol.setStaNo(inSta.getBackSta().shortValue()); // devpThread.setPakMk(staProtocol.getSiteId(), false); // MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol)); // led 异常显示 LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, inSta.getLed()); if (ledThread != null) { String errorMsg = "扫码失败,请重试"; MessageQueue.offer(SlaveType.Led, inSta.getLed(), new Task(3, errorMsg)); } continue; } } else { // staProtocol.setWorkNo((short) 32002); // staProtocol.setStaNo(inSta.getBackSta().shortValue()); // devpThread.setPakMk(staProtocol.getSiteId(), false); // MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol)); // led 异常显示 LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, inSta.getLed()); if (ledThread != null) { String errorMsg = "扫码失败,请重试"; MessageQueue.offer(SlaveType.Led, inSta.getLed(), new Task(3, errorMsg)); } continue; } // 过滤盘点/拣料/并板任务 WrkMast wrkMast1 = wrkMastMapper.selectPickStepByBarcode(barcode); if (null != wrkMast1) { continue; } // 判断重复工作档 WrkMast wrkMast2 = wrkMastMapper.selectPakInStep1(inSta.getStaNo(), barcode); if (wrkMast2 != null) { News.error("工作档中已存在该站状态为( 2.设备上走 )的数据,工作号={}", wrkMast2.getWrkNo()); continue; } try { LocTypeDto locTypeDto = new LocTypeDto(staProtocol); SearchLocParam param = new SearchLocParam(); param.setBarcode(barcode); param.setIoType(1); param.setSourceStaNo(inSta.getStaNo()); // param.setLocType1(locTypeDto.getLocType1()); String response = new HttpHandler.Builder() .setUri(wmsUrl) .setPath("/rpc/pakin/loc/v1") .setJson(JSON.toJSONString(param)) .build() .doPost(); JSONObject jsonObject = JSON.parseObject(response); LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, inSta.getLed()); Integer code = jsonObject.getInteger("code"); if (code.equals(200)) { StartupDto dto = jsonObject.getObject("data", StartupDto.class); // plc 处理 barcodeThread.setBarcode(""); staProtocol.setWorkNo(dto.getWorkNo().shortValue()); staProtocol.setStaNo(dto.getStaNo().shortValue()); devpThread.setPakMk(staProtocol.getSiteId(), false); boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol)); if (!result) { throw new CoolException("更新plc站点信息失败"); } // 判断重复工作档 WrkMast wrkMast = wrkMastMapper.selectPakInStep11(inSta.getStaNo()); if (wrkMast == null) { continue; } // 更新工作主档 wrkMast.setWrkSts(2L); // 工作状态:2.设备上走 wrkMast.setModiTime(new Date()); if (wrkMastMapper.updateById(wrkMast) == 0) { News.error("更新工作档失败!!! [工作号:{}]", wrkMast.getWrkNo()); } } else if (code == 500){ if (ledThread != null) { String errorMsg = jsonObject.getString("msg"); if (!Cools.isEmpty(errorMsg)) { MessageQueue.offer(SlaveType.Led, inSta.getLed(), new Task(3, errorMsg)); } } News.error("请求接口失败!!!url:{};request:{};response:{}", wmsUrl + "/rpc/pakin/loc/v1", JSON.toJSONString(param), response); } else if (code == 700) { staProtocol.setWorkNo((short) 32002); staProtocol.setRollback102(1);//102站回退信号 devpThread.setPakMk(staProtocol.getSiteId(), false); MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(5, staProtocol)); // led 异常显示 if (ledThread != null) { String errorMsg = barcode + "托盘识别异常,请先进行组托!"; MessageQueue.offer(SlaveType.Led, inSta.getLed(), new Task(3, errorMsg)); } } } catch (Exception e) { e.printStackTrace(); TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); } } } } } /** * wms入库 * 入库站,根据条码扫描生成入库工作档,工作状态 1 ==>> 2 */ @Deprecated public void generateStoreWrkFile0() { // 根据输送线plc遍历 for (DevpSlave devp : slaveProperties.getDevp()) { // 遍历入库口 for (DevpSlave.Sta inSta : devp.getInSta()) { // 获取入库站信息 DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId()); StaProtocol staProtocol = devpThread.getStation().get(inSta.getStaNo()); if (staProtocol == null) { continue; } else { staProtocol = staProtocol.clone(); } Short workNo = staProtocol.getWorkNo(); // 判断是否满足入库条件 if (staProtocol.isAutoing() && staProtocol.isLoading() && staProtocol.isInEnable() && !staProtocol.isEmptyMk() && (workNo == 0 || (workNo >= 9990 && workNo <= 9999)) && staProtocol.isPakMk()) { // 尺寸检测异常 boolean back = false; String errMsg = ""; if (staProtocol.isFrontErr()) { errMsg = "前超限"; back = true; } if (!back && staProtocol.isBackErr()) { errMsg = "后超限"; back = true; } if (!back && staProtocol.isHighErr()) { errMsg = "高超限"; back = true; } if (!back && staProtocol.isLeftErr()) { errMsg = "左超限"; back = true; } if (!back && staProtocol.isRightErr()) { errMsg = "右超限"; back = true; } if (!back && staProtocol.isWeightErr()) { errMsg = "超重"; back = true; } if (!back && staProtocol.isBarcodeErr()) { errMsg = "扫码失败"; back = true; } // 退回 if (back) { News.warn("扫码入库失败,{}入库站因{}异常,托盘已被退回", inSta.getStaNo(), errMsg); staProtocol.setWorkNo((short) 32002); staProtocol.setStaNo(inSta.getBackSta().shortValue()); devpThread.setPakMk(staProtocol.getSiteId(), false); MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol)); // led 异常显示 LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, inSta.getLed()); if (ledThread != null) { MessageQueue.offer(SlaveType.Led, inSta.getLed(), new Task(3, errMsg)); } continue; } // 判断重复工作档 WrkMast wrkMast = wrkMastMapper.selectPakInStep11(inSta.getStaNo()); if (wrkMast == null) { continue; } // 命令下发区 -------------------------------------------------------------------------- // 更新站点信息 且 下发plc命令 staProtocol.setWorkNo(wrkMast.getWrkNo().shortValue()); staProtocol.setStaNo(wrkMast.getStaNo().shortValue()); devpThread.setPakMk(staProtocol.getSiteId(), false); boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol)); if (result) { // 更新工作主档 wrkMast.setWrkSts(2L); // 工作状态:2.设备上走 wrkMast.setModiTime(new Date()); if (wrkMastMapper.updateById(wrkMast) == 0) { News.error("更新工作档失败!!! [工作号:{}]", wrkMast.getWrkNo()); } } else { News.error("发布命令至输送线队列失败!!! [plc编号:{}]", devp.getId()); } } } } } /** * 拣料、并板、盘点再入库 */ @Transactional public synchronized void stnToCrnStnPick(){ for (DevpSlave devp : slaveProperties.getDevp()) { // 遍历拣料入库口 for (DevpSlave.Sta pickSta : devp.getPickInSta()) { // 获取拣料入库站信息 DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId()); StaProtocol staProtocol = devpThread.getStation().get(pickSta.getStaNo()); if (staProtocol == null) { continue; } else { staProtocol = staProtocol.clone(); } if (staProtocol.isAutoing() && staProtocol.isLoading() && (staProtocol.getWorkNo() > 0 && staProtocol.getWorkNo() < 9999) && staProtocol.getStaNo().equals(staProtocol.getSiteId().shortValue()) && staProtocol.isPakMk()){ // 获取条码扫描仪信息 BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, pickSta.getBarcode()); if (barcodeThread == null) { continue; } String barcode = barcodeThread.getBarcode(); WrkMast wrkMast = null; wrkMast = wrkMastMapper.selectPickStepByBarcode(barcode); if (wrkMast == null) { continue; } // if (staProtocol.getWorkNo() == 9996) { // String barcode = barcodeThread.getBarcode(); // if(!Cools.isEmpty(barcode)) { // News.info("{}号条码扫描器检测条码信息:{}", pickSta.getBarcode(), barcode); // if("NG".endsWith(barcode) || "NoRead".equals(barcode) || "empty".equals(barcode)) { // staProtocol.setWorkNo((short) 32002); // staProtocol.setStaNo(pickSta.getBackSta().shortValue()); // devpThread.setPakMk(staProtocol.getSiteId(), false); // MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol)); // // // led 异常显示 // LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, pickSta.getLed()); // if (ledThread != null) { // String errorMsg = "扫码失败,请重试"; // MessageQueue.offer(SlaveType.Led, pickSta.getLed(), new Task(3, errorMsg)); // } // continue; // } // } else { // staProtocol.setWorkNo((short) 32002); // staProtocol.setStaNo(pickSta.getBackSta().shortValue()); // devpThread.setPakMk(staProtocol.getSiteId(), false); // MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol)); // // // led 异常显示 // LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, pickSta.getLed()); // if (ledThread != null) { // String errorMsg = "扫码失败,请重试"; // MessageQueue.offer(SlaveType.Led, pickSta.getLed(), new Task(3, errorMsg)); // } // continue; // } // wrkMast = wrkMastMapper.selectPickStepByBarcode(barcode); // if (null == wrkMast) { // News.error("{}条码错误,暂无拣料任务!", barcode); // } // } if ((wrkMast.getIoType() != 103 && wrkMast.getIoType() != 104 && wrkMast.getIoType() != 107) || Cools.isEmpty(wrkMast.getStaNo()) || Cools.isEmpty(wrkMast.getSourceStaNo()) ) { continue; } try { // 访问 WMS 获取入库库位 LocTypeDto locTypeDto = new LocTypeDto(staProtocol); SearchLocParam param = new SearchLocParam(); param.setWrkNo(wrkMast.getWrkNo()); param.setIoType(wrkMast.getIoType()); param.setSourceStaNo(pickSta.getStaNo()); // param.setLocType1(locTypeDto.getLocType1()); String response = new HttpHandler.Builder() .setUri(wmsUrl) .setPath("/rpc/pakin/loc/v1") .setJson(JSON.toJSONString(param)) .build() .doPost(); JSONObject jsonObject = JSON.parseObject(response); LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, pickSta.getLed()); Integer code = jsonObject.getInteger("code"); if (code.equals(200)) { StartupDto dto = jsonObject.getObject("data", StartupDto.class); // // 获取目标站 // Wrapper wrapper = new EntityWrapper() // .eq("type_no", wrkMast.getIoType() - 50) // .eq("stn_no", pickSta.getStaNo()) // 作业站点 = 拣料出库的目标站 // .eq("crn_no", dto.getCrnNo()); // 堆垛机号 // StaDesc staDesc = staDescService.selectOne(wrapper); // if (Cools.isEmpty(staDesc)) { // News.error("入库路径不存在!type_no={},stn_no={},crn_no={}", wrkMast.getIoType(), pickSta.getStaNo(), wrkMast.getCrnNo()); // continue; // } // // 堆垛机站点(目标站) // Integer staNo = staDesc.getCrnStn(); // 保存工作明细档历史档 // if (wrkMastMapper.saveWrkDetlLog(wrkMast.getWrkNo()) == 0) { // throw new CoolException("保存工作明细档历史档失败"); // } // 保存工作主档历史档 if (wrkMastMapper.saveWrkMastLog(wrkMast.getWrkNo()) == 0) { throw new CoolException(wrkMast.getWrkNo() + "保存工作主档历史档失败"); } String sourceLocNo = wrkMast.getSourceLocNo().trim(); // 更新工作档数据状态 wrkMast.setIoType(wrkMast.getIoType() - 50); // 入出库类型: 103->53,104->54,107->57 wrkMast.setWrkSts(2L); // 工作状态: 2.设备上走 wrkMast.setSourceStaNo(pickSta.getStaNo()); // 源站 wrkMast.setStaNo(dto.getStaNo()); // 目标站 wrkMast.setCrnNo(dto.getCrnNo()); wrkMast.setLocNo(sourceLocNo); // 目标库位 = 出库时的源库位 wrkMast.setShuttleNo(null); // 穿梭车清空 wrkMast.setModiTime(new Date()); if (wrkMastMapper.updateById(wrkMast) == 0) { throw new CoolException(wrkMast.getWrkNo() + "更新工作档数据状态失败"); } if (wrkMastMapper.setSteEmpty(wrkMast.getWrkNo()) == 0) { throw new CoolException(wrkMast.getWrkNo() + "更新工作档数据状态失败"); } // 修改库位状态 Q.拣料/盘点/并板再入库 LocMast locMast = locMastService.selectById(sourceLocNo); locMast.setLocSts("Q"); locMast.setModiTime(new Date()); if (!locMastService.updateById(locMast)) { throw new CoolException("修改库位状态失败"); } // 更新站点信息 且 下发plc命令 staProtocol.setWorkNo(wrkMast.getWrkNo().shortValue()); staProtocol.setStaNo(wrkMast.getStaNo().shortValue()); devpThread.setPakMk(staProtocol.getSiteId(), false); boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol)); if (!result) { News.error("发布命令至输送线队列失败!!! [plc编号:{}]", devp.getId()); } } else if (code == 500){ if (ledThread != null) { String errorMsg = jsonObject.getString("msg"); if (!Cools.isEmpty(errorMsg)) { MessageQueue.offer(SlaveType.Led, pickSta.getLed(), new Task(3, errorMsg)); } } News.error("请求接口失败!!!url:{};request:{};response:{}", wmsUrl + "/rpc/pakin/loc/v1", JSON.toJSONString(param), response); } else { staProtocol.setWorkNo((short) 32002); staProtocol.setStaNo(pickSta.getBackSta().shortValue()); devpThread.setPakMk(staProtocol.getSiteId(), false); MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol)); // led 异常显示 if (ledThread != null) { String errorMsg = jsonObject.getString("msg"); // String errorMsg = barcode + "托盘识别异常,请先进行组托!"; MessageQueue.offer(SlaveType.Led, pickSta.getLed(), new Task(3, errorMsg)); } } } catch (Exception e) { e.printStackTrace(); TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); } } } } } /** * 初始化实时地图 */ public synchronized void initRealtimeBasMap() { for (int i = 1; i <= 10; i++) {//总共四层楼 Object data = redisUtil.get("realtimeBasMap_" + i); if (data == null) {//redis地图数据为空,从数据库中获取 BasMap basMap = basMapService.selectLatestMap(i); if (basMap == null) { //数据库中也不存在地图数据,从地图文件中获取 //载入地图 NavigateMapData mapData = new NavigateMapData(i); List> lists = mapData.getJsonData(-1, null, null);//获取完整地图(包括入库出库) //存入数据库 basMap = new BasMap(); basMap.setData(JSON.toJSONString(lists)); basMap.setCreateTime(new Date()); basMap.setUpdateTime(new Date()); basMap.setLev(i); if (!basMapService.insert(basMap)) { log.info("地图数据存储失败"); } } //将数据库地图数据存入redis redisUtil.set("realtimeBasMap_" + i, JSON.toJSONString(basMap)); } } } /** * 从redis中重启任务 */ public synchronized void restartTaskFromRedis() { HashMap map = redisUtil.getRedis(); for (Object key : map.keySet()) { if (key.toString().contains("lift_wrk_no_")) {//提升机任务 LiftRedisCommand redisCommand = JSON.parseObject(map.get(key).toString(), LiftRedisCommand.class); if (redisCommand == null) { continue; } Short liftNo = redisCommand.getLiftNo(); LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, liftNo.intValue()); if (liftThread == null) { continue; } LiftProtocol liftProtocol = liftThread.getLiftProtocol(); if (liftProtocol == null) { continue; } if (!liftProtocol.isIdle()) { continue; } //提升机处于空闲状态,进行任务的恢复 liftProtocol.setTaskNo(redisCommand.getWrkNo());//将提升机线程分配任务号 liftProtocol.setProtocolStatus(LiftProtocolStatusType.WORKING);//工作状态 }else if(key.toString().contains("shuttle_wrk_no_")){//四向穿梭车任务 ShuttleRedisCommand redisCommand = JSON.parseObject(map.get(key).toString(), ShuttleRedisCommand.class); if (redisCommand == null) { continue; } Short shuttleNo = redisCommand.getShuttleNo(); ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttleNo.intValue()); if (shuttleThread == null) { continue; } ShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol(); if (shuttleProtocol == null) { continue; } if (!shuttleProtocol.isIdle()) { continue; } //四向穿梭车处于空闲状态,进行任务的恢复 shuttleProtocol.setTaskNo(redisCommand.getWrkNo());//将四向穿梭车线程分配任务号 shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.WORKING);//工作状态 } } } /** * 入库 ===>> 四向穿梭车入库作业下发 */ public synchronized void shuttleInExecute() { // 根据输送线plc遍历 for (DevpSlave devp : slaveProperties.getDevp()) { // 遍历入库站 for (DevpSlave.StaRack staRack : devp.getRackInStn()) { // 获取入库站信息 DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId()); StaProtocol staProtocol = devpThread.getStation().get(staRack.getStaNo()); if (staProtocol == null) { continue; } else { staProtocol = staProtocol.clone(); } Short workNo = staProtocol.getWorkNo(); BasDevp basDevp = basDevpService.selectById(staProtocol.getSiteId()); if (basDevp == null) { continue;//站点信息不存在 } // 判断是否满足入库条件,自动、有物、四向穿梭车可取信号 if (!(staProtocol.isAutoing() && staProtocol.isLoading() && staProtocol.isShuttleTakeEnable())) { continue; } WrkMast wrkMast = wrkMastMapper.selectRackInStep4(workNo, staProtocol.getSiteId()); if (wrkMast == null) { continue; } boolean step1 = this.shuttleInExecuteStep1(wrkMast, basDevp);//小车搬入库中 if (!step1) { continue; } } } } /** * 入库-小车搬入库中 * 如需主方法执行continue,请返回false * ps:返回值true并不代表该方法执行成功,返回值仅做标记用于主方法是否执行continue */ public boolean shuttleInExecuteStep1(WrkMast wrkMast, BasDevp basDevp) { if (wrkMast.getWrkSts() == 4) { if (wrkMast.getShuttleNo() == null) {//没有绑定小车,进行调度 dispatchShuttle(wrkMast.getWrkNo(), basDevp.getLocNo());//调度小车到货物所在输送站点进行取货 return false; } //获取四向穿梭车线程 ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, wrkMast.getShuttleNo()); if (shuttleThread == null) { return false; } ShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol(); if (shuttleProtocol == null) { return false; } if (!shuttleProtocol.isIdle()) { return false; } //判断小车是否到达输送站点库位 if (!shuttleProtocol.getCurrentLocNo().equals(basDevp.getLocNo())) { //小车不在输送站点位置 dispatchShuttle(wrkMast.getWrkNo(), basDevp.getLocNo(), wrkMast.getShuttleNo());//调度小车到货物所在输送站点进行取货 return false; } //小车已抵达输送站点位置,进行搬运货物 NyShuttleOperaResult result = NyShuttleOperaUtils.getShuttleTransportCommands(wrkMast.getShuttleNo(), wrkMast.getWrkNo(), shuttleProtocol.getCurrentLocNo(), basDevp.getLocNo(), wrkMast.getLocNo()); if (result == null) {//路径计算失败 return false; } //创建分配命令 ShuttleAssignCommand assignCommand = new ShuttleAssignCommand(); assignCommand.setShuttleNo(shuttleProtocol.getShuttleNo());//四向穿梭车号 assignCommand.setTaskNo(wrkMast.getWrkNo().shortValue());//任务号 assignCommand.setTaskMode(ShuttleTaskModeType.PAK_IN.id.shortValue());//入库模式 assignCommand.setSourceLocNo(shuttleProtocol.getCurrentLocNo());//源库位(小车当前位置) assignCommand.setCommands(result.getCommands());//运行命令 assignCommand.setNodes(result.getNodes());//路径节点 wrkMast.setWrkSts(5L);//4.提升机搬运完成 => 5.小车搬运中 wrkMast.setModiTime(new Date()); if (wrkMastMapper.updateById(wrkMast) > 0) { //下发任务 MessageQueue.offer(SlaveType.Shuttle, assignCommand.getShuttleNo().intValue(), new Task(3, assignCommand)); } return false; } return true; } //获取起点-终点指令 public synchronized List shuttleAssignCommand(String startLocNo, String locNo, Integer mapType, ShuttleAssignCommand assignCommand, ShuttleThread shuttleThread) { //获取小车移动速度 BasShuttle basShuttle = basShuttleService.selectById(assignCommand.getShuttleNo()); Integer runSpeed = 1000; // if (basShuttle != null) { // Integer runSpeed1 = basShuttle.getRunSpeed(); // if (runSpeed1 != null) { // runSpeed = runSpeed1; // } // } //计算小车起点到中点所需命令 List calc = NavigateUtils.calc(startLocNo, locNo, mapType, Utils.getShuttlePoints(shuttleThread.getSlave().getId(), Utils.getLev(startLocNo))); List commands = new ArrayList<>(); if (calc == null) { return null; } if (!Utils.checkShuttlePath(calc, shuttleThread.getSlave().getId())) {//检测穿梭车行走路径,是否存在其他小车,如有其他小车则进行调离 return null; } List allNode = new ArrayList<>(); allNode.addAll(calc); //获取分段路径 ArrayList> data = NavigateUtils.getSectionPath(calc); //将每一段路径分成command指令 for (ArrayList nodes : data) { //开始路径 NavigateNode startPath = nodes.get(0); //中间路径 NavigateNode middlePath = null; //通过xy坐标小车二维码 Short middleCodeNum = null; Integer middleToDistDistance = null;//计算中间点到目标点行走距离 if (nodes.size() > 10) {//中段码传倒数第三个 //中间路径 middlePath = nodes.get(nodes.size() - 3); //通过xy坐标小车二维码 middleCodeNum = NavigatePositionConvert.xyToPosition(middlePath.getX(), middlePath.getY(), middlePath.getZ()); middleToDistDistance = NavigateUtils.getMiddleToDistDistance(nodes, middlePath);//计算中间点到目标点行走距离 } else if (nodes.size() > 5) {//中段码传倒数第二个 //中间路径 middlePath = nodes.get(nodes.size() - 2); //通过xy坐标小车二维码 middleCodeNum = NavigatePositionConvert.xyToPosition(middlePath.getX(), middlePath.getY(), middlePath.getZ()); middleToDistDistance = NavigateUtils.getMiddleToDistDistance(nodes, middlePath);//计算中间点到目标点行走距离 } //目标路径 NavigateNode endPath = nodes.get(nodes.size() - 1); Integer allDistance = NavigateUtils.getCurrentPathAllDistance(nodes);//计算当前路径行走总距离 //通过xy坐标小车二维码 Short startCodeNum = NavigatePositionConvert.xyToPosition(startPath.getX(), startPath.getY(), startPath.getZ()); //通过xy坐标小车二维码 Short distCodeNum = NavigatePositionConvert.xyToPosition(endPath.getX(), endPath.getY(), endPath.getZ()); //获取移动命令 ShuttleCommand command = shuttleThread.getMoveCommand(startCodeNum, distCodeNum, allDistance, ShuttleRunDirection.get(startPath.getDirection()).id, middleCodeNum, middleToDistDistance, runSpeed); commands.add(command); } assignCommand.setNodes(allNode);//当前任务所占用的节点list //所使用的路径进行锁定禁用 NavigateMapData navigateMapData = new NavigateMapData(Utils.getLev(startLocNo)); navigateMapData.writeNavigateNodeToRedisMap(allNode, true);////所使用的路径进行锁定禁用 return commands; } //获取起点-中点-终点指令 public synchronized List shuttleAssignCommand(String startLocNo, String middleLocNo, String locNo, ShuttleAssignCommand assignCommand, ShuttleThread shuttleThread) { //获取小车移动速度 BasShuttle basShuttle = basShuttleService.selectById(assignCommand.getShuttleNo()); Integer runSpeed = 1000; // if (basShuttle != null) { // Integer runSpeed1 = basShuttle.getRunSpeed(); // if (runSpeed1 != null) { // runSpeed = runSpeed1; // } // } List allNode = new ArrayList<>(); //计算小车起点到中点所需命令 List calc = NavigateUtils.calc(startLocNo, middleLocNo, NavigationMapType.NORMAL.id, null);//小车无货,走正常库位通道 List commands = new ArrayList<>(); if (calc != null) { if (!Utils.checkShuttlePath(calc, shuttleThread.getSlave().getId())) {//检测穿梭车行走路径,是否存在其他小车,如有其他小车则进行调离 return null; } allNode.addAll(calc); //获取分段路径 ArrayList> data = NavigateUtils.getSectionPath(calc); //将每一段路径分成command指令 for (ArrayList nodes : data) { //开始路径 NavigateNode startPath = nodes.get(0); //中间路径 NavigateNode middlePath = null; //通过xy坐标小车二维码 Short middleCodeNum = null; Integer middleToDistDistance = null;//计算中间点到目标点行走距离 if (nodes.size() > 10) {//中段码传倒数第三个 //中间路径 middlePath = nodes.get(nodes.size() - 3); //通过xy坐标小车二维码 middleCodeNum = NavigatePositionConvert.xyToPosition(middlePath.getX(), middlePath.getY(), middlePath.getZ()); middleToDistDistance = NavigateUtils.getMiddleToDistDistance(nodes, middlePath);//计算中间点到目标点行走距离 } else if (nodes.size() > 5) {//中段码传倒数第二个 //中间路径 middlePath = nodes.get(nodes.size() - 2); //通过xy坐标小车二维码 middleCodeNum = NavigatePositionConvert.xyToPosition(middlePath.getX(), middlePath.getY(), middlePath.getZ()); middleToDistDistance = NavigateUtils.getMiddleToDistDistance(nodes, middlePath);//计算中间点到目标点行走距离 } //目标路径 NavigateNode endPath = nodes.get(nodes.size() - 1); Integer allDistance = NavigateUtils.getCurrentPathAllDistance(nodes);//计算当前路径行走总距离 //通过xy坐标小车二维码 Short startCodeNum = NavigatePositionConvert.xyToPosition(startPath.getX(), startPath.getY(), startPath.getZ()); //通过xy坐标小车二维码 Short distCodeNum = NavigatePositionConvert.xyToPosition(endPath.getX(), endPath.getY(), endPath.getZ()); //获取移动命令 ShuttleCommand command = shuttleThread.getMoveCommand(startCodeNum, distCodeNum, allDistance, ShuttleRunDirection.get(startPath.getDirection()).id, middleCodeNum, middleToDistDistance, runSpeed); commands.add(command); } } //小车指令到达目标位置后,再发出一条顶升指令 commands.add(shuttleThread.getPalletCommand((short) 1)); //计算小车中点到终点所需命令 List calc2 = NavigateUtils.calc(middleLocNo, locNo, NavigationMapType.DFX.id, null);//小车有货,走禁用过DFX库位的地图通道 if (calc2 == null) { return null; } if (!Utils.checkShuttlePath(calc2, shuttleThread.getSlave().getId())) {//检测穿梭车行走路径,是否存在其他小车,如有其他小车则进行调离 return null; } allNode.addAll(calc2); //获取分段路径 ArrayList> data2 = NavigateUtils.getSectionPath(calc2); for (ArrayList nodes : data2) { //开始路径 NavigateNode startPath = nodes.get(0); //中间路径 NavigateNode middlePath = null; //通过xy坐标小车二维码 Short middleCodeNum = null; Integer middleToDistDistance = null;//计算中间点到目标点行走距离 if (nodes.size() > 10) {//中段码传倒数第三个 //中间路径 middlePath = nodes.get(nodes.size() - 3); //通过xy坐标小车二维码 middleCodeNum = NavigatePositionConvert.xyToPosition(middlePath.getX(), middlePath.getY(), middlePath.getZ()); middleToDistDistance = NavigateUtils.getMiddleToDistDistance(nodes, middlePath);//计算中间点到目标点行走距离 } else if (nodes.size() > 5) {//中段码传倒数第二个 //中间路径 middlePath = nodes.get(nodes.size() - 2); //通过xy坐标小车二维码 middleCodeNum = NavigatePositionConvert.xyToPosition(middlePath.getX(), middlePath.getY(), middlePath.getZ()); middleToDistDistance = NavigateUtils.getMiddleToDistDistance(nodes, middlePath);//计算中间点到目标点行走距离 } //目标路径 NavigateNode endPath = nodes.get(nodes.size() - 1); Integer allDistance = NavigateUtils.getCurrentPathAllDistance(nodes);//计算当前路径行走总距离 //通过xy坐标小车二维码 Short startCodeNum = NavigatePositionConvert.xyToPosition(startPath.getX(), startPath.getY(), startPath.getZ()); //通过xy坐标小车二维码 Short distCodeNum = NavigatePositionConvert.xyToPosition(endPath.getX(), endPath.getY(), endPath.getZ()); ShuttleCommand moveCommand = shuttleThread.getMoveCommand(startCodeNum, distCodeNum, allDistance, ShuttleRunDirection.get(startPath.getDirection()).id, middleCodeNum, middleToDistDistance, runSpeed); commands.add(moveCommand); } //小车指令到达目标位置后,再发出一条托盘下降指令 commands.add(shuttleThread.getPalletCommand((short) 2)); assignCommand.setNodes(allNode);//当前任务所占用的节点list //所使用的路径进行锁定禁用 NavigateMapData navigateMapData = new NavigateMapData(Utils.getLev(startLocNo)); navigateMapData.writeNavigateNodeToRedisMap(allNode, true);////所使用的路径进行锁定禁用 return commands; } /** * 出库 ===>> 四向穿梭车出库作业下发 */ public synchronized void shuttleOutExecute() { for (WrkMast wrkMast : wrkMastMapper.selectBy2125()) { boolean step1 = this.shuttleOutExecuteStep1(wrkMast);//小车搬出库中 if (!step1) { continue; } } } /** * 出库-小车搬出库中 * 如需主方法执行continue,请返回false * ps:返回值true并不代表该方法执行成功,返回值仅做标记用于主方法是否执行continue */ public boolean shuttleOutExecuteStep1(WrkMast wrkMast) { //21.生成出库任务 => 22.小车搬运中 if (wrkMast.getWrkSts() == 21) { if (wrkMast.getShuttleNo() == null) {//没有绑定小车,进行调度 dispatchShuttle(wrkMast.getWrkNo(), wrkMast.getSourceLocNo());//调度小车到货物所在库位进行取货 return false; } //获取四向穿梭车线程 ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, wrkMast.getShuttleNo()); if (shuttleThread == null) { return false; } ShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol(); if (shuttleProtocol == null) { return false; } if (!shuttleProtocol.isIdle()) { return false; } //获取目标站对应的输送站点 BasDevp targetBasDevp = basDevpService.selectByLevAndLiftNo(Utils.getLev(wrkMast.getSourceLocNo()), wrkMast.getLiftNo()); if (targetBasDevp == null) { return false;//缺少站点信息 } //判断小车是否到达货物库位 if (!shuttleProtocol.getCurrentLocNo().equals(wrkMast.getSourceLocNo())) { //小车不在输送站点位置 dispatchShuttle(wrkMast.getWrkNo(), wrkMast.getSourceLocNo(), wrkMast.getShuttleNo());//调度小车到货物所在输送站点进行取货 return false; } //小车已抵达货物位置,进行搬运货物 NyShuttleOperaResult result = NyShuttleOperaUtils.getShuttleTransportCommands(wrkMast.getShuttleNo(), wrkMast.getWrkNo(), shuttleProtocol.getCurrentLocNo(), wrkMast.getSourceLocNo(), targetBasDevp.getLocNo()); if (result == null) {//出库路径计算失败 return false; } //创建分配命令 ShuttleAssignCommand assignCommand = new ShuttleAssignCommand(); assignCommand.setShuttleNo(shuttleProtocol.getShuttleNo());//四向穿梭车号 assignCommand.setTaskNo(wrkMast.getWrkNo().shortValue());//任务号 assignCommand.setTaskMode(ShuttleTaskModeType.PAK_OUT.id.shortValue());//出库模式 assignCommand.setSourceLocNo(shuttleProtocol.getCurrentLocNo());//源库位(小车当前位置) assignCommand.setCommands(result.getCommands());//运行命令 assignCommand.setNodes(result.getNodes());//路径节点 wrkMast.setWrkSts(22L);//21.生成出库任务 => 22.小车搬运中 wrkMast.setModiTime(new Date()); if (wrkMastMapper.updateById(wrkMast) > 0) { //下发任务 MessageQueue.offer(SlaveType.Shuttle, assignCommand.getShuttleNo().intValue(), new Task(3, assignCommand)); } return false; } return true; } /** * 搜索空闲且最近的四向穿梭车(以工作档目标库位为基点计算最近且空闲的车) */ public HashMap searchIdleShuttle(WrkMast wrkMast) { HashMap map = new HashMap<>(); String locNo = wrkMast.getIoType() < 101 ? wrkMast.getLocNo() : wrkMast.getSourceLocNo();//库位号 LocMast locMast = locMastService.queryByLoc(locNo);//找到库位记录 int lev = Utils.getLev(locNo);//当前工作档库位层高 ShuttleThread recentShuttle = null;//当前距离最近的四向穿梭车线程 ArrayList sameLev = new ArrayList<>();//相同楼层的穿梭车 ArrayList diffLev = new ArrayList<>();//不同楼层的穿梭车 //判断其他空闲穿梭车是否离任务最近 String distLocNo = null;//目标地点,入库=》提升机口,出库=》货物库位号 if (wrkMast.getIoType() < 101 && wrkMast.getIoType() != 11) { //入库 distLocNo = Utils.levToOutInStaLocNo(lev); }else if(wrkMast.getIoType() >= 101){ //出库 distLocNo = locNo; } else if (wrkMast.getIoType() == 11) { //库位移转 distLocNo = wrkMast.getSourceLocNo(); } //判断当前任务所在楼层是否有其他任务已经分配了小车,如有则直接用该小车(一层楼仅分配一台车) List wrkMasts = wrkMastService.selectShuttleWrkByLev(lev);//判断当前穿梭车楼层是否已有分配车辆的任务,如果有则分配这辆车 if (wrkMasts.size() > 0) { //存在其他任务,分配这辆车 WrkMast wrkMast1 = wrkMasts.get(0); ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, wrkMast1.getShuttleNo()); map.put("sameLay", true);//同层 map.put("result", shuttleThread); return map; } for (ShuttleSlave shuttle : slaveProperties.getShuttle()) { //获取四向穿梭车线程 ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttle.getId()); ShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol(); if (shuttleProtocol == null || shuttleProtocol.getShuttleNo() == null) { continue; } if (!shuttleProtocol.isIdle()) { continue; } String shuttleLocNo = shuttleProtocol.getCurrentLocNo();//二维码对应库位号 if (shuttleLocNo == null) { continue; } if (shuttleLocNo.equals(distLocNo)) { //车辆当前位置已经是目标库位,无需计算 map.put("sameLay", true);//同层 map.put("result", shuttleThread); return map; } int shuttleLocNoLey = Utils.getLev(shuttleLocNo);//库位号对应层高 if (lev == shuttleLocNoLey) { //工作档楼层相同的穿梭车 sameLev.add(shuttleThread); }else { //工作档不同楼层的穿梭车 diffLev.add(shuttleThread); } } Integer recentAllDistance = 9999999; if (sameLev.size() > 0) { //同一楼层有空闲穿梭车,则只在工作档楼层寻找 //寻找离任务最近的穿梭车 for (ShuttleThread shuttleThread : sameLev) { //当前穿梭车库位号 String currentLocNo = shuttleThread.getShuttleProtocol().getCurrentLocNo(); //当前穿梭车线程到目标地点距离 List currentShuttlePath = NavigateUtils.calc(currentLocNo, distLocNo, NavigationMapType.NORMAL.id, Utils.getShuttlePoints(shuttleThread.getSlave().getId(), Utils.getLev(currentLocNo)));//搜索空闲穿梭车,使用正常通道地图 if (currentShuttlePath == null) { continue; } Integer currentAllDistance = NavigateUtils.getOriginPathAllDistance(currentShuttlePath);//计算当前路径行走总距离 if (currentAllDistance < recentAllDistance) { //如果当前楼层的车路径更小,则更新最近穿梭车 recentShuttle = shuttleThread; } } map.put("sameLay", true);//同层 map.put("result", recentShuttle); }else { //同一楼层,没有空闲穿梭车,只能从其他楼层调度 //寻找离任务最近的穿梭车 for (ShuttleThread shuttleThread : diffLev) { //当前穿梭车库位号 String currentLocNo = shuttleThread.getShuttleProtocol().getCurrentLocNo(); int currentLev = Utils.getLev(currentLocNo); List wrkMasts1 = wrkMastService.selectNoShuttleWrkByLev(currentLev);//判断当前穿梭车楼层是否有待分配车辆的任务,如果有则不分配这辆车 if (wrkMasts1.size() > 0) { //存在其他任务,跳过这辆车 continue; } //当前穿梭车线程到当前车子所在楼层的提升机口距离 List currentShuttlePath = NavigateUtils.calc(currentLocNo, Utils.levToOutInStaLocNo(currentLev), NavigationMapType.NORMAL.id, Utils.getShuttlePoints(shuttleThread.getSlave().getId(), currentLev));//搜索空闲穿梭车,使用正常通道地图 if (currentShuttlePath == null) { continue; } Integer currentAllDistance = NavigateUtils.getOriginPathAllDistance(currentShuttlePath);//计算当前路径行走总距离 if (currentAllDistance < recentAllDistance) { //如果当前楼层的车路径更小,则更新最近穿梭车 recentShuttle = shuttleThread; } } map.put("sameLay", false);//不同层 map.put("result", recentShuttle); } return map; } /** * 四向穿梭车任务完成 */ public synchronized void shuttleFinished() { for (ShuttleSlave shuttle : slaveProperties.getShuttle()) { //获取四向穿梭车信息 NyShuttleThread shuttleThread = (NyShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttle.getId()); NyShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol(); if (shuttleProtocol == null) { continue; } //四向穿梭车状态为等待确认、小车处于空闲状态 if (shuttleProtocol.getProtocolStatus() == ShuttleProtocolStatusType.WAITING.id //任务完成等待确认 && shuttleProtocol.getTaskNo() != 0 && shuttleProtocol.getFree() == ShuttleStatusType.IDLE.id ) { //将任务档标记为完成 WrkMast wrkMast = wrkMastMapper.selectByWorkNo(shuttleProtocol.getTaskNo().intValue()); if (wrkMast != null) { switch (wrkMast.getWrkSts().intValue()) { case 5://5.小车搬运中 ==> 9.入库完成 wrkMast.setWrkSts(9L); //任务号清零 shuttleProtocol.setTaskNo(0); break; case 22://22.小车搬运中 ==> 23.小车搬运完成 wrkMast.setWrkSts(23L); break; case 102://102.小车到提升机中 ==> 103.小车到提升机完成 wrkMast.setWrkSts(103L); break; case 106://106.小车迁出提升机中 ==> 107.小车迁出提升机完成 wrkMast.setWrkSts(107L); break; case 108://108.小车移动中 ==> 109.小车移动完成 wrkMast.setWrkSts(109L); break; default: } if (wrkMastMapper.updateById(wrkMast) > 0) { //设置四向穿梭车为空闲状态 shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.IDLE); //源库位清零 shuttleProtocol.setSourceLocNo(null); //目标库位清零 shuttleProtocol.setLocNo(null); //任务指令清零 shuttleProtocol.setAssignCommand(null); News.info("四向穿梭车已确认且任务完成状态,复位。四向穿梭车号={}", shuttleProtocol.getShuttleNo()); } else { News.error("四向穿梭车已确认且任务完成状态,复位失败,但未找到工作档。四向穿梭车号={},工作号={}", shuttleProtocol.getShuttleNo(), shuttleProtocol.getTaskNo()); } } } } } /** * 提升机任务 */ public synchronized void liftIoExecute() { for (LiftSlave liftSlave : slaveProperties.getLift()) { LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, liftSlave.getId()); if (liftThread == null) { continue; } LiftProtocol liftProtocol = liftThread.getLiftProtocol(); if (liftProtocol == null) { continue; } if (!liftProtocol.isIdle()) { continue; } //搜索是否有待处理的任务 List wrkMasts = wrkMastMapper.selectLiftStep223103(); if (wrkMasts.isEmpty()) { continue; } for (WrkMast wrkMast : wrkMasts) { //搜索是否有其他任务占用了提升机,如果占用提升机的任务和当前任务相同,则运行执行 WrkMast wrkMast1 = wrkMastMapper.selectLiftWrkMast(liftProtocol.getLiftNo().intValue()); if (wrkMast1 != null && wrkMast1.getWrkNo().intValue() != wrkMast.getWrkNo().intValue()) { continue; } boolean stepIn = this.liftIoExecuteStepIn(wrkMast);//提升机入库 if (!stepIn) { continue; } boolean stepOut = this.liftIoExecuteStepOut(wrkMast);//提升机出库 if (!stepOut) { continue; } } } } /** * 提升机入库 * 如需主方法执行continue,请返回false * ps:返回值true并不代表该方法执行成功,返回值仅做标记用于主方法是否执行continue */ private boolean liftIoExecuteStepIn(WrkMast wrkMast) { //--------------------------------------提升机入库-----------------------------------------// Date now = new Date(); //2.设备上走 ==> 3.提升机搬运中 if (wrkMast.getWrkSts() == 2) { LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, wrkMast.getLiftNo()); if (liftThread == null) { return false; } LiftProtocol liftProtocol = liftThread.getLiftProtocol(); if (liftProtocol == null) { return false; } if (!liftProtocol.isIdle(wrkMast.getWrkNo().shortValue())) { return false; } //判断提升机是否有其他任务 WrkMast liftWrkMast = wrkMastMapper.selectLiftWrkMast(liftThread.getSlave().getId()); if (liftWrkMast != null) { return false;//当前提升机存在未完成任务,等待下一次轮询 } //获取源站对应的输送站点 BasDevp sourceBasDevp = basDevpService.selectById(wrkMast.getSourceStaNo()); //获取目标站对应的输送站点 BasDevp targetBasDevp = basDevpService.selectById(wrkMast.getStaNo()); if (sourceBasDevp == null || targetBasDevp == null) { return false;//缺少站点信息 } //获取提升机命令 NyLiftCommand liftCommand = NyLiftUtils.getLiftCommand(liftProtocol.getLiftNo().intValue(), NyLiftTaskModelType.MOVE_TRAY.id, sourceBasDevp.getDevNo(), targetBasDevp.getDevNo(), wrkMast.getWrkNo()); ArrayList commands = new ArrayList<>(); commands.add(liftCommand); //提交到线程去工作 LiftAssignCommand assignCommand = new LiftAssignCommand(); assignCommand.setCommands(commands); assignCommand.setLiftNo(liftProtocol.getLiftNo()); assignCommand.setTaskNo(wrkMast.getWrkNo().shortValue()); assignCommand.setTaskMode(NyLiftTaskModelType.MOVE_TRAY.id.shortValue()); wrkMast.setWrkSts(3L);//2.设备上走 ==> 3.提升机搬运中 wrkMast.setLiftNo(liftThread.getSlave().getId());//任务档绑定提升机号 wrkMast.setModiTime(now); if (wrkMastMapper.updateById(wrkMast) > 0) { //下发任务 MessageQueue.offer(SlaveType.Lift, liftProtocol.getLiftNo().intValue(), new Task(3, assignCommand)); } return false; } return true; } /** * 提升机出库 * 如需主方法执行continue,请返回false * ps:返回值true并不代表该方法执行成功,返回值仅做标记用于主方法是否执行continue */ private boolean liftIoExecuteStepOut(WrkMast wrkMast) { //--------------------------------------提升机出库-----------------------------------------// Date now = new Date(); //23.小车搬运完成 ==> 24.提升机搬运中 if (wrkMast.getWrkSts() == 23) { LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, wrkMast.getLiftNo()); if (liftThread == null) { return false; } LiftProtocol liftProtocol = liftThread.getLiftProtocol(); if (liftProtocol == null) { return false; } if (!liftProtocol.isIdle(wrkMast.getWrkNo().shortValue())) { return false; } //判断提升机是否有其他任务 WrkMast liftWrkMast = wrkMastMapper.selectLiftWrkMast(liftThread.getSlave().getId()); if (liftWrkMast != null) { return false;//当前提升机存在未完成任务,等待下一次轮询 } //获取源站对应的输送站点 BasDevp sourceBasDevp = basDevpService.selectByLevAndLiftNo(Utils.getLev(wrkMast.getSourceLocNo()), liftProtocol.getLiftNo().intValue()); //获取目标站对应的输送站点 BasDevp targetBasDevp = basDevpService.selectById(wrkMast.getSourceStaNo()); if (sourceBasDevp == null || targetBasDevp == null) { return false;//缺少站点信息 } //获取提升机命令 NyLiftCommand liftCommand = NyLiftUtils.getLiftCommand(liftProtocol.getLiftNo().intValue(), NyLiftTaskModelType.MOVE_TRAY.id, sourceBasDevp.getDevNo(), targetBasDevp.getDevNo(), wrkMast.getWrkNo()); ArrayList commands = new ArrayList<>(); commands.add(liftCommand); //提交到线程去工作 LiftAssignCommand assignCommand = new LiftAssignCommand(); assignCommand.setCommands(commands); assignCommand.setLiftNo(liftProtocol.getLiftNo()); assignCommand.setTaskNo(wrkMast.getWrkNo().shortValue()); assignCommand.setTaskMode(NyLiftTaskModelType.MOVE_TRAY.id.shortValue()); wrkMast.setWrkSts(24L);//23.小车搬运完成 ==> 24.提升机搬运中 wrkMast.setLiftNo(liftThread.getSlave().getId());//任务档绑定提升机号 wrkMast.setModiTime(now); if (wrkMastMapper.updateById(wrkMast) > 0) { //下发任务 MessageQueue.offer(SlaveType.Lift, liftProtocol.getLiftNo().intValue(), new Task(3, assignCommand)); } return false; } return true; } /** * 提升机任务完成 */ public synchronized void liftFinished() { for (LiftSlave liftSlave : slaveProperties.getLift()) { //获取提升机信息 LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, liftSlave.getId()); LiftProtocol liftProtocol = liftThread.getLiftProtocol(); if (liftProtocol == null) { continue; } //提升机为等待确认且空闲 if (liftProtocol.getProtocolStatus() == LiftProtocolStatusType.WAITING.id && liftProtocol.getTaskNo() != 0 && !liftProtocol.getBusy() ) { //将任务档标记为完成 WrkMast wrkMast = wrkMastMapper.selectByWorkNo324104(liftProtocol.getTaskNo().intValue()); if (wrkMast != null) { switch (wrkMast.getWrkSts().intValue()) { case 3://3.提升机搬运中 ==> 4.提升机搬运完成 wrkMast.setWrkSts(4L); wrkMast.setLiftNo(null);//释放提升机 break; case 24://24.提升机搬运中 ==> 25.提升机搬运完成 wrkMast.setWrkSts(25L); break; case 104://104.提升机搬运中 ==> 105.提升机搬运完成 wrkMast.setWrkSts(105L); break; default: } if (wrkMastMapper.updateById(wrkMast) > 0) { //设置提升机为空闲状态 liftProtocol.setProtocolStatus(LiftProtocolStatusType.IDLE); //任务指令清零 liftProtocol.setAssignCommand(null); News.info("提升机已确认且任务完成状态。提升机号={}", liftProtocol.getLiftNo()); } else { News.error("提升机已确认且任务完成状态,复位失败,但未找到工作档。提升机号={},工作号={}", liftProtocol.getLiftNo(), liftProtocol.getTaskNo()); } } } } } /** * 库位移转 */ public synchronized void locToLocExecute() { //获取出入库工作档 List wrkMasts = wrkMastMapper.selectInOutWrkMast(); if (wrkMasts.size() > 0) { //有出入库任务,必须等待任务执行完毕再执行库位移转 return; } //查询库位移转工作档 List wrkMasts1 = wrkMastMapper.selectLocToLocWrkMast(); for (WrkMast wrkMast : wrkMasts1) { boolean step1 = this.locToLocExecuteStep1(wrkMast);//绑定小车 if (!step1) { continue; } boolean step2 = this.locToLocExecuteStep2(wrkMast);//调度小车到目标楼层 if (!step2) { continue; } boolean step3 = this.locToLocExecuteStep3(wrkMast);//同楼层库位移转 if (!step3) { continue; } } } /** * 绑定小车并调度车 * 如需主方法执行continue,请返回false * ps:返回值true并不代表该方法执行成功,返回值仅做标记用于主方法是否执行continue */ private boolean locToLocExecuteStep1(WrkMast wrkMast) { if (wrkMast.getShuttleNo() == null) {//给库位移转绑定穿梭车号 //寻找最近且空闲的四向穿梭车 HashMap searchIdleShuttle = this.searchIdleShuttle(wrkMast); ShuttleThread shuttleThread = (ShuttleThread) searchIdleShuttle.get("result"); if (shuttleThread == null) { //没有找到空闲穿梭车 return false; } wrkMast.setShuttleNo(shuttleThread.getSlave().getId());//给工作档分配四向穿梭车号 wrkMastMapper.updateById(wrkMast); } return true; } /** * 调度小车到目标楼层 * 如需主方法执行continue,请返回false * ps:返回值true并不代表该方法执行成功,返回值仅做标记用于主方法是否执行continue */ private boolean locToLocExecuteStep2(WrkMast wrkMast) { if (wrkMast.getWrkSts() == 1 && wrkMast.getShuttleNo() != null) { ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, wrkMast.getShuttleNo()); ShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol(); if (!shuttleProtocol.isIdle(wrkMast.getWrkNo().shortValue())) { return false;//小车处于不空闲状态 } String currentLocNo = shuttleProtocol.getCurrentLocNo();//小车当前库位号 int shuttleLev = Utils.getLev(currentLocNo);//小车所在楼层 LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, 1); LiftProtocol liftProtocol = liftThread.getLiftProtocol(); //判断小车是否再目标楼层 if (shuttleLev != Utils.getLev(wrkMast.getLocNo())) { //小车和目标不在同一楼层 //提升机口站点库位号 String liftSiteLocNo = Utils.levToOutInStaLocNo(shuttleLev); //创建分配命令 ShuttleAssignCommand assignCommand = new ShuttleAssignCommand(); assignCommand.setShuttleNo(shuttleProtocol.getShuttleNo());//四向穿梭车号 assignCommand.setTaskNo(wrkMast.getWrkNo().shortValue());//任务号 assignCommand.setTaskMode(ShuttleTaskModeType.PAK_IN.id.shortValue());//入出库模式 assignCommand.setSourceLocNo(currentLocNo);//源库位(小车当前位置) //小车移动到提升机口,计算路径 List commands = this.shuttleAssignCommand(shuttleProtocol.getLocNo(), liftSiteLocNo, NavigationMapType.NONE.id, assignCommand, shuttleThread); if (commands == null) { return false;//未找到路径 } //获取当前小车所在楼层的站点信息 BasDevp basDevp = basDevpService.queryByLocNo(liftSiteLocNo); Short endStartCode = Short.parseShort(basDevp.getQrCodeValue());//站点二维码 // //增加移动进提升机命令 // ShuttleCommand moveCommand = shuttleThread.getMoveCommand(endStartCode, liftProtocol.getBarcode(), 1600, ShuttleRunDirection.TOP.id, null, null, 500); // commands.add(moveCommand); //分配目标库位 shuttleProtocol.setLocNo(liftSiteLocNo); //目标库位 assignCommand.setLocNo(liftSiteLocNo); // assignCommand.setCommands(commands); wrkMast.setWrkSts(5L);//小车迁移状态 if (wrkMastMapper.updateById(wrkMast) > 0) { //下发任务 MessageQueue.offer(SlaveType.Shuttle, assignCommand.getShuttleNo().intValue(), new Task(3, assignCommand)); } } } return true; } /** * 同楼层库位移转 * 如需主方法执行continue,请返回false * ps:返回值true并不代表该方法执行成功,返回值仅做标记用于主方法是否执行continue */ private boolean locToLocExecuteStep3(WrkMast wrkMast) { if (wrkMast.getShuttleNo() == null) { return false; } ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, wrkMast.getShuttleNo()); ShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol(); if (!shuttleProtocol.isIdle(wrkMast.getWrkNo().shortValue())) { return false;//小车处于不空闲状态 } LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, 1); LiftProtocol liftProtocol = liftThread.getLiftProtocol(); DevpThread devpThread = null; for (DevpSlave devp : slaveProperties.getDevp()){ // 获取入库站信息 devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId()); } //判断小车是否在工作档任务目标楼层 String currentLocNo = shuttleProtocol.getCurrentLocNo();//小车当前库位号 int shuttleLev = Utils.getLev(currentLocNo);//小车所在楼层 if (shuttleLev != Utils.getLev(wrkMast.getLocNo())) { return false;//不在同一楼层 } if (wrkMast.getWrkSts() == 1 || wrkMast.getWrkSts() == 8) { //调度小车执行同楼层移库任务 //创建分配命令 ShuttleAssignCommand assignCommand = new ShuttleAssignCommand(); assignCommand.setShuttleNo(shuttleProtocol.getShuttleNo());//四向穿梭车号 assignCommand.setTaskNo(wrkMast.getWrkNo().shortValue());//任务号 assignCommand.setTaskMode(ShuttleTaskModeType.PAK_IN.id.shortValue());//入出库模式 assignCommand.setSourceLocNo(currentLocNo);//源库位(小车当前位置) List commands = new ArrayList<>(); if (wrkMast.getWrkSts() == 8) {//8.提升机迁移小车完成,需要将小车移出提升机 //判断提升机是否空闲 if (!liftProtocol.isIdleNoTask()) { return false;//提升机忙 } //判断提升机任务号和当前工作档任务号是否一致 if (liftProtocol.getTaskNo().intValue() != 0 && liftProtocol.getTaskNo().intValue() != wrkMast.getWrkNo()) { return false; } //判断提升机楼层是否到位,判断站点是否给出提升机到位信号 String locNo = wrkMast.getLocNo(); int lev = Utils.getLev(locNo);//目标二维码所在楼层 int liftLev = liftProtocol.getLev().intValue();//提升机所在楼层 if (liftLev != lev) { return false;//提升机不在目标楼层跳过 } Integer staNo = Utils.levToOutInStaNo(lev >= 2 ? lev + 1 : lev); //获取目标站信息 StaProtocol staProtocol1 = devpThread.getStation().get(staNo); if (staProtocol1 == null) { return false;//站点信息不存在 } if (!staProtocol1.isLiftArrival()) { return false;//站点提升机到位信号false } // BasDevp basDevp = basDevpService.selectById(staNo); // short startCode = liftProtocol.getBarcode();//提升机内部二维码 // Short distCode = Short.parseShort(basDevp.getQrCodeValue());//提升机口站点二维码 // Short runDirection = ShuttleRunDirection.BOTTOM.id;//运行方向 // //获取命令 // ShuttleCommand moveCommand = shuttleThread.getMoveCommand(startCode, distCode, 1600, runDirection, null, null, 500); // commands.add(0, moveCommand);//将该指令添加到队头 // currentLocNo = basDevp.getLocNo();//使用输送站点口作为起点坐标 } //直接计算车到源库位到目标库位路径 List commands1 = this.shuttleAssignCommand(currentLocNo, wrkMast.getSourceLocNo(), wrkMast.getLocNo(), assignCommand, shuttleThread); if (commands1 == null) { return false;//找不到路径等待下一次 } commands.addAll(commands1); //分配任务号 shuttleProtocol.setTaskNo(wrkMast.getWrkNo().shortValue()); //分配源库位 shuttleProtocol.setSourceLocNo(wrkMast.getSourceLocNo()); // assignCommand.setCommands(commands); //分配目标库位 shuttleProtocol.setLocNo(wrkMast.getLocNo()); //目标库位 assignCommand.setLocNo(wrkMast.getLocNo()); wrkMast.setWrkSts(9L);//小车入库中 if (wrkMastMapper.updateById(wrkMast) > 0) { //下发任务 MessageQueue.offer(SlaveType.Shuttle, assignCommand.getShuttleNo().intValue(), new Task(3, assignCommand)); } } return true; } /** * 异常信息记录 */ public void recErr() { try { this.recShuttleErr(); } catch (Exception e) { News.error("recErr fail", e); } } /** * 四向穿梭车异常信息记录 */ private void recShuttleErr() { Date now = new Date(); for (ShuttleSlave shuttleSlave : slaveProperties.getShuttle()) { // 获取堆垛机信息 ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttleSlave.getId()); if (shuttleThread == null) { continue; } ShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol(); if (shuttleProtocol == null) { continue; } if (shuttleProtocol.getTaskNo() != 0) { //有任务 BasShuttleErrLog latest = basShuttleErrLogService.findLatestByTaskNo(shuttleSlave.getId(), shuttleProtocol.getTaskNo().intValue()); // 有异常 if (latest == null) { if (shuttleProtocol.getStatusErrorCode() != null && shuttleProtocol.getStatusErrorCode() > 0) { WrkMast wrkMast = wrkMastMapper.selectById(shuttleProtocol.getTaskNo()); if (wrkMast == null) { continue; } BasShuttleErr basShuttleErr = basShuttleErrService.queryByCode(shuttleProtocol.getStatusErrorCode().intValue()); String errName = basShuttleErr==null? "未知异常":basShuttleErr.getErrName(); BasShuttleErrLog basShuttleErrLog = new BasShuttleErrLog( null, // 编号 wrkMast.getWrkNo(), // 工作号 now, // 发生时间 null, // 结束时间 wrkMast.getWrkSts(), // 工作状态 wrkMast.getIoType(), // 入出库类型 shuttleSlave.getId(), // 四向穿梭车 null, // plc wrkMast.getLocNo(), // 目标库位 wrkMast.getStaNo(), // 目标站 wrkMast.getSourceStaNo(), // 源站 wrkMast.getSourceLocNo(), // 源库位 wrkMast.getBarcode(), // 条码 (int) shuttleProtocol.getStatusErrorCode(), // 异常码 errName, // 异常 1, // 异常情况 now, // 添加时间 null, // 添加人员 now, // 修改时间 null, // 修改人员 "任务中异常" // 备注 ); if (!basShuttleErrLogService.insert(basShuttleErrLog)) { News.error("四向穿梭车plc异常记录失败 ===>> [id:{}] [error:{}]", shuttleSlave.getId(), errName); } } } else { // 异常修复 if (shuttleProtocol.getStatusErrorCode() == null || shuttleProtocol.getStatusErrorCode() == 0) { latest.setEndTime(now); latest.setUpdateTime(now); latest.setStatus(2); if (!basShuttleErrLogService.updateById(latest)) { News.error("四向穿梭车plc异常记录修复失败 ===>> [id:{}] [errLogId:{}]", shuttleSlave.getId(), latest.getId()); } } } }else { //无任务 BasShuttleErrLog latest = basShuttleErrLogService.findLatest(shuttleSlave.getId()); // 有异常 if (shuttleProtocol.getStatusErrorCode() != null && shuttleProtocol.getStatusErrorCode() > 0) { // 记录新异常 if (latest == null || (latest.getErrCode() != shuttleProtocol.getStatusErrorCode().intValue())) { BasShuttleErr basShuttleErr = basShuttleErrService.queryByCode(shuttleProtocol.getStatusErrorCode().intValue()); String errName = basShuttleErr==null? "未知异常":basShuttleErr.getErrName(); BasShuttleErrLog basShuttleErrLog = new BasShuttleErrLog( null, // 编号 null, // 工作号 now, // 发生时间 null, // 结束时间 null, // 工作状态 null, // 入出库类型 shuttleSlave.getId(), // 四向穿梭车 null, // plc null, // 目标库位 null, // 目标站 null, // 源站 null, // 源库位 null, // 条码 (int)shuttleProtocol.getStatusErrorCode(), // 异常码 errName, // 异常 1, // 异常情况 now, // 添加时间 null, // 添加人员 now, // 修改时间 null, // 修改人员 "无任务异常" // 备注 ); if (!basShuttleErrLogService.insert(basShuttleErrLog)) { News.error("四向穿梭车plc异常记录失败 ===>> [id:{}] [error:{}]", shuttleSlave.getId(), errName); } } // 无异常 } else { // 异常修复 if (latest != null && latest.getStatus() == 1) { latest.setEndTime(now); latest.setUpdateTime(now); latest.setStatus(2); if (!basShuttleErrLogService.updateById(latest)) { News.error("四向穿梭车plc异常记录修复失败 ===>> [id:{}] [errLogId:{}]", shuttleSlave.getId(), latest.getId()); } } } } } } // ------------------------------------------------------------------------------- /** * 空栈板初始化入库,叉车入库站放货 */ public void storeEmptyPlt(){ for (DevpSlave devp : slaveProperties.getDevp()) { // 遍历空板入库口 for (DevpSlave.Sta emptyInSta : devp.getEmptyInSta()) { // 获取空板入库站信息 DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId()); StaProtocol staProtocol = devpThread.getStation().get(emptyInSta.getStaNo()); if (staProtocol == null) { continue; } else { staProtocol = staProtocol.clone(); } // 站点条件判断 if (staProtocol.isAutoing() && staProtocol.isLoading() && staProtocol.isInEnable() && staProtocol.isEmptyMk() && (staProtocol.getWorkNo() == 0 || (staProtocol.getWorkNo() >= 9990 || staProtocol.getWorkNo() <= 9999)) && staProtocol.isPakMk()) { // 获取条码扫描仪信息 String barcode = null; BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, emptyInSta.getBarcode()); if (barcodeThread != null) { String barcode0 = barcodeThread.getBarcode(); if(!Cools.isEmpty(barcode0)) { // News.info("{}号条码扫描器检测条码信息:{}", emptyInSta.getBarcode(), barcode0); if(!"NG".endsWith(barcode0) && !"NoRead".equals(barcode0) && !"empty".equals(barcode0)) { barcode = barcode0; } } } LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, emptyInSta.getLed()); try { LocTypeDto locTypeDto = new LocTypeDto(staProtocol); SearchLocParam param = new SearchLocParam(); param.setIoType(10); if (!Cools.isEmpty(barcode)) { param.setBarcode(barcode); } param.setSourceStaNo(emptyInSta.getStaNo()); // param.setLocType1(locTypeDto.getLocType1()); String response = new HttpHandler.Builder() .setUri(wmsUrl) .setPath("/rpc/pakin/loc/v1") .setJson(JSON.toJSONString(param)) .build() .doPost(); JSONObject jsonObject = JSON.parseObject(response); Integer code = jsonObject.getInteger("code"); if (code.equals(200)) { StartupDto dto = jsonObject.getObject("data", StartupDto.class); // 更新站点信息 且 下发plc命令 staProtocol.setWorkNo(dto.getWorkNo().shortValue()); staProtocol.setStaNo(dto.getStaNo().shortValue()); devpThread.setPakMk(staProtocol.getSiteId(), false); boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol)); if (!result) { throw new CoolException("更新plc站点信息失败"); } } else { if (ledThread != null) { String errorMsg = jsonObject.getString("msg"); if (!Cools.isEmpty(errorMsg)) { MessageQueue.offer(SlaveType.Led, emptyInSta.getLed(), new Task(3, errorMsg)); } } News.error("请求接口失败!!!url:{};request:{};response:{}", wmsUrl + "/rpc/pakin/loc/v1", JSON.toJSONString(param), response); } } catch (Exception e) { e.printStackTrace(); TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); } } } } } /** * 出库 ===>> 工作档信息写入led显示器 */ public void ledExecute() { for (LedSlave led : slaveProperties.getLed()) { // 获取输送线plc线程 DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, led.getDevpPlcId()); // 命令集合 List commands = new ArrayList<>(); // 工作档集合 List wrkMasts = new ArrayList<>(); for (Integer staNo : led.getStaArr()) { // 获取叉车站点 StaProtocol staProtocol = devpThread.getStation().get(staNo); if (null == staProtocol || null == staProtocol.getWorkNo() || 0 == staProtocol.getWorkNo() || !staProtocol.isLoading()) { continue; } else { staProtocol = staProtocol.clone(); } // 获取工作档数据 WrkMast wrkMast = wrkMastMapper.selectById(staProtocol.getWorkNo()); if (null == wrkMast || wrkMast.getWrkSts() < 14 || wrkMast.getIoType() < 100) { continue; } wrkMasts.add(wrkMast); // 组装命令 LedCommand ledCommand = new LedCommand(); ledCommand.setWorkNo(wrkMast.getWrkNo()); ledCommand.setIoType(wrkMast.getIoType()); // 出库模式 switch (wrkMast.getIoType()) { case 101: ledCommand.setTitle("全板出库"); break; case 103: ledCommand.setTitle("拣料出库"); break; case 104: ledCommand.setTitle("并板出库"); break; case 107: ledCommand.setTitle("盘点出库"); break; case 110: ledCommand.setTitle("空板出库"); ledCommand.setEmptyMk(true); break; default: News.error("任务入出库类型错误!!![工作号:{}] [入出库类型:{}]", wrkMast.getWrkNo(), wrkMast.getIoType()); break; } ledCommand.setSourceLocNo(wrkMast.getSourceLocNo()); ledCommand.setLocNo(wrkMast.getLocNo()); ledCommand.setStaNo(wrkMast.getStaNo()); if (wrkMast.getIoType() != 110 && wrkMast.getIoType() != 10) { List wrkDetls = wrkDetlService.findByWorkNo(wrkMast.getWrkNo()); wrkDetls.forEach(wrkDetl -> ledCommand.getMatDtos().add(new MatDto(wrkDetl.getMatnr(), wrkDetl.getMaktx(), wrkDetl.getAnfme(),wrkDetl.getSpecs()))); } commands.add(ledCommand); } Set workNos = wrkMasts.stream().map(WrkMast::getWrkNo).collect(Collectors.toSet()); // 获取LED线程 LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, led.getId()); // 相同工作号集合则过滤 if (CollectionUtils.equals(ledThread.getWorkNos(), workNos)) { continue; } // 命令下发 ------------------------------------------------------------------------------- if (!commands.isEmpty()) { if (led.getId()>3){ if (!MessageQueue.offer(SlaveType.Led, led.getId()-3, new Task(1, commands))) { log.error("{}号LED命令下发失败!!![ip:{}] [port:{}]", led.getId()-3, led.getIp(), led.getPort()); continue; }else { ledThread.setLedMk(false); } }else { if (!MessageQueue.offer(SlaveType.Led, led.getId(), new Task(1, commands))) { log.error("{}号LED命令下发失败!!![ip:{}] [port:{}]", led.getId(), led.getIp(), led.getPort()); continue; }else { ledThread.setLedMk(false); } } } try { // 修改主档led标记 for (WrkMast wrkMast : wrkMasts) { wrkMast.setOveMk("Y"); wrkMast.setModiTime(new Date()); if (wrkMastMapper.updateById(wrkMast) == 0) { throw new CoolException("更新工作档失败"); } } // 更新线程当前工作号集合 ledThread.setWorkNos(workNos); } catch (Exception e) { e.printStackTrace(); TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); } } } /** * 其他 ===>> LED显示器复位,显示默认信息 */ public void ledReset() { for (LedSlave led : slaveProperties.getLed()) { // 获取输送线plc线程 DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, led.getDevpPlcId()); // 命令集合 boolean reset = true; for (Integer staNo : led.getStaArr()) { // 获取叉车站点 StaProtocol staProtocol = devpThread.getStation().get(staNo); if (staProtocol == null) { continue; } if (staProtocol.getWorkNo() != 0 && staProtocol.isLoading()) { reset = false; break; } } // 获取led线程 LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, led.getId()); // led显示默认内容 if (reset && !ledThread.isLedMk()) { ledThread.setLedMk(true); if (!MessageQueue.offer(SlaveType.Led, led.getId(), new Task(4, new ArrayList<>()))) { News.error(" - {}号LED命令下发失败!!![ip:{}] [port:{}]", led.getId(), led.getIp(), led.getPort()); } else { } } } for (LedSlave led : slaveProperties.getLed()) { // 获取输送线plc线程 DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, led.getDevpPlcId()); // 命令集合 boolean reset = true; for (Integer staNo : led.getStaArr()) { // 获取叉车站点 StaProtocol staProtocol = devpThread.getStation().get(staNo); if (staProtocol == null) { continue; } if (staProtocol.getWorkNo() != 0) { reset = false; break; } } // 获取led线程 LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, led.getId()); // led显示默认内容 if (reset && !ledThread.isLedMk()) { ledThread.setLedMk(true); if (!MessageQueue.offer(SlaveType.Led, led.getId(), new Task(2, new ArrayList<>()))) { News.error("{}号LED命令下发失败!!![ip:{}] [port:{}]", led.getId(), led.getIp(), led.getPort()); } } } } /** * 四向穿梭车电量检测 ===>> 发起充电 */ public synchronized void loopShuttleCharge() { for (ShuttleSlave shuttle : slaveProperties.getShuttle()) { //获取四向穿梭车线程 ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttle.getId()); ShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol(); if (shuttleProtocol == null) { continue; } //判断当前小车是否满足需要充电要求 if (!shuttleProtocol.isRequireCharge()) { continue; } WrkCharge wrkCharge = wrkChargeService.selectWorking(shuttleProtocol.getShuttleNo().intValue()); if (wrkCharge != null) {//已有充电任务 continue; } ShuttleChargeType shuttleCharge = null; for (ShuttleChargeType chargeType : ShuttleChargeType.values()) { if (wrkChargeService.selectWorkingOfCharge(chargeType.id) == null) { shuttleCharge = chargeType; break; } } if (shuttleCharge == null) { continue; } String chargeLocNo = shuttleCharge.locNo; wrkCharge = new WrkCharge(); wrkCharge.setShuttleNo(shuttle.getId()); wrkCharge.setCharge(shuttleCharge.id); wrkCharge.setWrkNo(commonService.getChargeWorkNo(4)); wrkCharge.setWrkSts(51L); // 21.准备充电 wrkCharge.setIoPri((double) 10); wrkCharge.setLocNo(chargeLocNo); wrkCharge.setMemo("charge"); wrkCharge.setAppeTime(new Date()); if (!wrkChargeService.insert(wrkCharge)) { News.error("保存{}号四向穿梭车充电任务失败!!!", shuttle.getId()); continue; } shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.CHARGING);//充电中 News.info("保存{}号四向穿梭车充电任务成功!!!", shuttle.getId()); } } /** * 执行四向穿梭车充电任务 */ public synchronized void executeShuttleCharge() { for (ShuttleSlave shuttle : slaveProperties.getShuttle()) { WrkCharge wrkCharge = wrkChargeService.selectWorking(shuttle.getId()); if (wrkCharge == null) { continue; } ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, wrkCharge.getShuttleNo()); if (shuttleThread == null) { continue; } ShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol(); if (shuttleProtocol == null) { continue; } //获取提升机 LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, 1); if (liftThread == null) { continue; } LiftProtocol liftProtocol = liftThread.getLiftProtocol(); if (liftProtocol == null) { continue; } //充电库位号 String chargeLocNo = wrkCharge.getLocNo(); //充电库位层高 Integer chargeLocNoLev = Utils.getLev(chargeLocNo); if (wrkCharge.getWrkSts() == 51) { //当前穿梭车库位号 String currentLocNo = shuttleProtocol.getCurrentLocNo(); if (currentLocNo == null) { continue; } //小车当前层高 Integer currentLev = Utils.getLev(currentLocNo); if (currentLev == chargeLocNoLev) { //同一层无需经过提升机 //直接计算车到充电库位 ShuttleAssignCommand assignCommand = new ShuttleAssignCommand(); //获取小车到充电库位路径指令 List commands = this.shuttleAssignCommand(currentLocNo, chargeLocNo, NavigationMapType.NONE.id, assignCommand, shuttleThread); if (commands == null) { continue;//未找到路径 } //进行充电中 shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.CHARGING); assignCommand.setShuttleNo(shuttleProtocol.getShuttleNo()); assignCommand.setTaskMode(ShuttleTaskModeType.CHARGE.id.shortValue());//充电 assignCommand.setTaskNo(wrkCharge.getWrkNo().shortValue()); assignCommand.setCharge(true);//充电任务 //创建充电指令 ShuttleCommand command = shuttleThread.getChargeSwitchCommand((short) 1);//开始充电 commands.add(command); //指令集分配 // assignCommand.setCommands(commands); wrkCharge.setWrkSts(56L);//充电中状态 if (wrkChargeMapper.updateById(wrkCharge) > 0) { //下发任务 MessageQueue.offer(SlaveType.Shuttle, assignCommand.getShuttleNo().intValue(), new Task(3, assignCommand)); } }else { //不同层,调度小车到充电桩目标层 ShuttleAssignCommand assignCommand = new ShuttleAssignCommand(); //获取小车当前楼层的站点号 String liftSiteLocNo = Utils.levToOutInStaLocNo(currentLev); //小车移动到提升机口站点,计算路径 List commands = this.shuttleAssignCommand(currentLocNo, liftSiteLocNo, NavigationMapType.NONE.id, assignCommand, shuttleThread); if (commands == null) { continue;//未找到路径 } //获取当前小车所在楼层的站点信息 BasDevp basDevp = basDevpService.queryByLocNo(liftSiteLocNo); if (basDevp == null) { continue;//找不到站点信息 } Short basDevpQrCode = Short.parseShort(basDevp.getQrCodeValue());//站点二维码 // //增加移动进提升机命令 // ShuttleCommand moveCommand = shuttleThread.getMoveCommand(basDevpQrCode, liftProtocol.getBarcode(), 1600, ShuttleRunDirection.TOP.id, basDevpQrCode, 1600, 500); // commands.add(moveCommand); //分配目标库位 shuttleProtocol.setLocNo(chargeLocNo); assignCommand.setShuttleNo(shuttleProtocol.getShuttleNo()); assignCommand.setTaskMode(ShuttleTaskModeType.CHARGE.id.shortValue());//充电 assignCommand.setTaskNo(wrkCharge.getWrkNo().shortValue()); assignCommand.setCharge(true);//充电任务 //目标库位 assignCommand.setLocNo(chargeLocNo); //源库位 assignCommand.setSourceLocNo(currentLocNo); // assignCommand.setCommands(commands); wrkCharge.setWrkSts(52L);//小车迁移状态 if (wrkChargeMapper.updateById(wrkCharge) > 0) { //下发任务 MessageQueue.offer(SlaveType.Shuttle, assignCommand.getShuttleNo().intValue(), new Task(3, assignCommand)); } } }else if(wrkCharge.getWrkSts() == 53){ //小车已经达到提升机内 //判断提升机是否处于空闲状态 if (!liftProtocol.isIdle(wrkCharge.getWrkNo().shortValue())) { continue; } // //判断小车是否在提升机内 // if (shuttleProtocol.getCurrentCode().intValue() != liftProtocol.getBarcode().intValue()) { // //小车不在提升机内 // continue; // } //给提升机分配任务 liftProtocol.setTaskNo(wrkCharge.getWrkNo().shortValue());//设置任务号 liftProtocol.setShuttleNo(wrkCharge.getShuttleNo().shortValue());//设置四向穿梭车号 liftProtocol.setProtocolStatus(LiftProtocolStatusType.WORKING);//设置提升机状态为工作中 //命令list ArrayList commands = new ArrayList<>(); // //提升机前往目标楼层 // //获取充电库位目标楼层命令 // LiftCommand command1 = liftThread.getLiftUpDownCommand(liftProtocol.getLiftNo(), liftProtocol.getTaskNo(), chargeLocNoLev >= 2 ? chargeLocNoLev + 1 : chargeLocNoLev); // commands.add(command1);//将命令添加进list wrkCharge.setWrkSts(54L);//提升机搬运中 //所需命令组合完毕,更新数据库,提交到线程去工作 LiftAssignCommand assignCommand = new LiftAssignCommand(); // assignCommand.setCommands(commands); assignCommand.setLiftNo(liftProtocol.getLiftNo()); assignCommand.setTaskNo(liftProtocol.getTaskNo()); if (wrkChargeMapper.updateById(wrkCharge) > 0) { //下发任务 MessageQueue.offer(SlaveType.Lift, liftProtocol.getLiftNo().intValue(), new Task(3, assignCommand)); } }else if(wrkCharge.getWrkSts() == 55){//55.提升机迁移小车完成 //直接计算车到充电库位 ShuttleAssignCommand assignCommand = new ShuttleAssignCommand(); Short liftLev = liftProtocol.getLev(); if (liftLev == null) { continue; } //判断提升机楼层是否到达目标楼层 if (liftLev.intValue() != chargeLocNoLev) { continue;//没有到达目标楼层 } //此时车在提升机内部,下达一步指令让车移动到提升机口 Integer staNo = Utils.levToOutInStaNo(liftLev >= 2 ? liftLev + 1 : liftLev);//站点号 BasDevp basDevp = basDevpService.selectById(staNo); if (basDevp == null) { continue;//站点不存在 } //获取提升机口到充电库位路径指令 List commands = this.shuttleAssignCommand(basDevp.getLocNo(), chargeLocNo, NavigationMapType.NONE.id, assignCommand, shuttleThread); if (commands == null) { continue;//未找到路径 } // short startCode = liftProtocol.getBarcode();//提升机内部二维码 // Short distCode = Short.parseShort(basDevp.getQrCodeValue());//提升机口站点二维码 // Short runDirection = ShuttleRunDirection.BOTTOM.id;//运行方向 // //获取命令 // ShuttleCommand moveCommand = shuttleThread.getMoveCommand(startCode, distCode, 1600, runDirection, startCode, 1600, 500); // commands.add(0, moveCommand);//将该指令添加到队头 //进行充电中 shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.CHARGING); assignCommand.setShuttleNo(shuttleProtocol.getShuttleNo()); assignCommand.setTaskMode(ShuttleTaskModeType.CHARGE.id.shortValue());//充电 assignCommand.setTaskNo(wrkCharge.getWrkNo().shortValue()); assignCommand.setCharge(true);//充电任务 //创建充电指令 ShuttleCommand command = shuttleThread.getChargeSwitchCommand((short) 1);//开始充电 commands.add(command); //指令集分配 // assignCommand.setCommands(commands); wrkCharge.setWrkSts(56L);//充电中状态 if (wrkChargeMapper.updateById(wrkCharge) > 0) { //下发任务 MessageQueue.offer(SlaveType.Shuttle, assignCommand.getShuttleNo().intValue(), new Task(3, assignCommand)); } }else if (wrkCharge.getWrkSts() == 57) {//57.小车到达充电桩 //充电中 //判断小车是否充满电量,满电1000或电压54V以上 if (shuttleProtocol.getBatteryPower() == null || shuttleProtocol.getCurrentVoltage() == null) { continue; } if (shuttleProtocol.getBatteryPower() >= 1000 && shuttleProtocol.getCurrentVoltage() >= 54000) { //充满,断开充电 // List commands = new ArrayList<>(); // ShuttleAssignCommand assignCommand = new ShuttleAssignCommand(); // assignCommand.setShuttleNo(shuttleProtocol.getShuttleNo()); // assignCommand.setTaskMode((short) 0); // assignCommand.setTaskNo(wrkCharge.getWrkNo().shortValue()); // assignCommand.setCharge(true); // // //创建充电指令 // ShuttleCommand command = shuttleThread.getChargeSwitchCommand((short) 2);//断开充电 // commands.add(command); // // //指令集分配 // assignCommand.setCommands(commands); // // shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.CHARGING_WAITING); //将小车移动到空闲的巷道 ShuttleAssignCommand assignCommand = Utils.searchEmptyGroupToMoveShuttle(Utils.getLev(shuttleProtocol.getLocNo()), shuttleProtocol.getShuttleNo().intValue(), shuttleThread, null); if (assignCommand == null) { continue; } wrkCharge.setWrkSts(60L);//60.充电任务完成 if (wrkChargeMapper.updateById(wrkCharge) > 0) { //下发任务 MessageQueue.offer(SlaveType.Shuttle, assignCommand.getShuttleNo().intValue(), new Task(3, assignCommand)); } } if (shuttleProtocol.getProtocolStatus() == ShuttleProtocolStatusType.CHARGING_WAITING.id) { shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.CHARGING); } } } } /** * 调度车辆-调度指定穿梭车 */ public void dispatchShuttle(Integer wrkNo, String locNo, Integer shuttleNo) { shuttleMoveGenerate(wrkNo, locNo, shuttleNo); } /** * 调度车辆 */ public void dispatchShuttle(Integer wrkNo, String locNo) { ArrayList sameLev = new ArrayList<>();//相同楼层的穿梭车 ArrayList diffLev = new ArrayList<>();//不同楼层的穿梭车 for (ShuttleSlave shuttle : slaveProperties.getShuttle()) { //获取四向穿梭车线程 NyShuttleThread shuttleThread = (NyShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttle.getId()); NyShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol(); if (shuttleProtocol == null || shuttleProtocol.getShuttleNo() == null) { continue; } if (!shuttleProtocol.isIdle()) { continue; } int currentLev = shuttleProtocol.getPoint().getZ();//小车当前层高 String currentLocNo = shuttleProtocol.getCurrentLocNo();//小车当前库位号 if (currentLocNo.equals(locNo)) { //车辆当前位置已经是目标库位,调度该车 shuttleMoveGenerate(wrkNo, locNo, shuttleProtocol.getShuttleNo().intValue()); break; } if (currentLev == Utils.getLev(locNo)) { //工作档楼层相同的穿梭车 sameLev.add(shuttleThread); }else { //工作档不同楼层的穿梭车 diffLev.add(shuttleThread); } } Integer recentAllDistance = 9999999; NyShuttleThread recentShuttle = null;//当前距离最近的四向穿梭车线程 if (sameLev.size() > 0) { //同一楼层有空闲穿梭车,则只在工作档楼层寻找 //寻找离任务最近的穿梭车 for (NyShuttleThread shuttleThread : sameLev) { //当前穿梭车库位号 String currentLocNo = shuttleThread.getShuttleProtocol().getCurrentLocNo(); //当前穿梭车线程到目标地点距离 List currentShuttlePath = NavigateUtils.calc(currentLocNo, locNo, NavigationMapType.NORMAL.id, Utils.getShuttlePoints(shuttleThread.getSlave().getId(), Utils.getLev(currentLocNo)));//搜索空闲穿梭车,使用正常通道地图 if (currentShuttlePath == null) { continue; } Integer currentAllDistance = NavigateUtils.getOriginPathAllDistance(currentShuttlePath);//计算当前路径行走总距离 if (currentAllDistance < recentAllDistance) { //如果当前楼层的车路径更小,则更新最近穿梭车 recentShuttle = shuttleThread; } } }else { //同一楼层,没有空闲穿梭车,只能从其他楼层调度 //寻找离任务最近的穿梭车 for (NyShuttleThread shuttleThread : diffLev) { //当前穿梭车库位号 String currentLocNo = shuttleThread.getShuttleProtocol().getCurrentLocNo(); int currentLev = Utils.getLev(currentLocNo); List wrkMasts1 = wrkMastService.selectNoShuttleWrkByLev(currentLev);//判断当前穿梭车楼层是否有待分配车辆的任务,如果有则不分配这辆车 if (wrkMasts1.size() > 0) { //存在其他任务,跳过这辆车 continue; } //当前穿梭车线程到当前车子所在楼层的提升机口距离 List currentShuttlePath = NavigateUtils.calc(currentLocNo, Utils.levToOutInStaLocNo(currentLev), NavigationMapType.NORMAL.id, Utils.getShuttlePoints(shuttleThread.getSlave().getId(), currentLev));//搜索空闲穿梭车,使用正常通道地图 if (currentShuttlePath == null) { continue; } Integer currentAllDistance = NavigateUtils.getOriginPathAllDistance(currentShuttlePath);//计算当前路径行走总距离 if (currentAllDistance < recentAllDistance) { //如果当前楼层的车路径更小,则更新最近穿梭车 recentShuttle = shuttleThread; } } } if (recentShuttle == null) {//没有搜索到可用穿梭车 return; } //搜索到可用穿梭车,调度该车 shuttleMoveGenerate(wrkNo, locNo, recentShuttle.getSlave().getId()); } /** * 小车迁移任务生成 */ @Transactional public boolean shuttleMoveGenerate(Integer wrkNo, String locNo, Integer shuttleNo) { Date now = new Date(); //获取四向穿梭车线程 NyShuttleThread shuttleThread = (NyShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttleNo); if (shuttleThread == null) { return false; } NyShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol(); if (shuttleProtocol == null) { return false; } //小车处于空闲状态 if (!shuttleProtocol.isIdleNoCharge()) { return false; } //判断穿梭车是否存在未完成的小车移库任务 WrkMast hasMoveWorking = wrkMastMapper.selectShuttleHasMoveWorking(shuttleNo); if (hasMoveWorking != null) {//小车存在移库任务,等待执行完成后再生成新的任务 return false; } //判断是否有其他任务正在使用穿梭车 WrkMast wrkMast2 = wrkMastMapper.selectShuttleWorking(shuttleNo); if (wrkMast2 != null) {//小车存在其他工作档任务,等待执行完成后再生成新的任务 return false; } //判断是否有充电任务正在使用穿梭车 WrkCharge wrkCharge = wrkChargeMapper.selectWorking(shuttleNo); if (wrkCharge != null) {//小车存在充电任务,等待执行完成后再生成新的任务 return false; } // 获取工作号 int workNo = commonService.getWorkNo(0); // 保存工作档 WrkMast wrkMast = new WrkMast(); wrkMast.setWrkNo(workNo); wrkMast.setIoTime(now); wrkMast.setWrkSts(101L); // 工作状态:101.移动到近点等待迁出 wrkMast.setIoType(200); // 入出库状态: 200.小车移库 wrkMast.setIoPri(20D); wrkMast.setShuttleNo(shuttleNo);//穿梭车号 wrkMast.setSourceLocNo(shuttleProtocol.getCurrentLocNo()); // 源库位 => 小车当前库位号 wrkMast.setLocNo(locNo); // 目标库位 wrkMast.setPicking("N"); // 拣料 wrkMast.setExitMk("N"); // 退出 wrkMast.setLinkMis("N"); wrkMast.setAppeTime(now); wrkMast.setModiTime(now); int res = wrkMastMapper.insert(wrkMast); if (res == 0) { News.error("小车迁移 --- 保存工作档失败! 穿梭车号:" + shuttleNo); throw new CoolException("保存工作档失败"); } //给工作档绑定小车号 WrkMast wrkMast1 = wrkMastMapper.selectByWorkNo(wrkNo); if (wrkMast1 != null) { wrkMast1.setShuttleNo(shuttleNo); wrkMastMapper.updateById(wrkMast1); } return true; } /** * 执行小车移库任务 */ public synchronized void shuttleMoveExecute() { //查询小车移库任务 List wrkMasts = wrkMastMapper.selectShuttleMoveWrk(); for (WrkMast wrkMast : wrkMasts) { boolean step1 = this.shuttleMoveExecuteStep1(wrkMast);//小车移动到提升机中 if (!step1) { continue; } boolean step2 = this.shuttleMoveExecuteStep2(wrkMast);//提升机搬运中 if (!step2) { continue; } boolean step3 = this.shuttleMoveExecuteStep3(wrkMast);//小车迁出提升机中 if (!step3) { continue; } boolean step4 = this.shuttleMoveExecuteStep4(wrkMast);//小车移动到目标库位中 if (!step4) { continue; } } } /** * 小车迁移-小车移动到提升机中 * 如需主方法执行continue,请返回false * ps:返回值true并不代表该方法执行成功,返回值仅做标记用于主方法是否执行continue */ private boolean shuttleMoveExecuteStep1(WrkMast wrkMast) { //--------------------------------------小车移动到提升机中-----------------------------------------// Date now = new Date(); //小车移动到提升机中 101.生成小车移库任务 ==> 102.小车到提升机中 if (wrkMast.getWrkSts() == 101) { //获取四向穿梭车线程 NyShuttleThread shuttleThread = (NyShuttleThread) SlaveConnection.get(SlaveType.Shuttle, wrkMast.getShuttleNo()); if (shuttleThread == null) { return false; } NyShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol(); if (shuttleProtocol == null) { return false; } //小车处于空闲状态 if (!shuttleProtocol.isIdleNoCharge()) { return false; } if (Utils.getLev(wrkMast.getLocNo()) == shuttleProtocol.getPoint().getZ()) { //目标库位和小车库位处于同一楼层,需要通过提升机调度 return true;//直接进入108.小车移动中 } //计算距离小车最近的提升机站点 //查询小车所在楼层提升机输送站点 int recentAllDistance = 9999999;//默认最近距离 BasDevp recentDevp = null;//最近站点 List basDevps = basDevpService.selectHasLiftNoByLev(shuttleProtocol.getPoint().getZ()); for (BasDevp basDevp : basDevps) { LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, basDevp.getLiftNo()); if (liftThread == null) { continue; } LiftProtocol liftProtocol = liftThread.getLiftProtocol(); if (liftProtocol == null) { continue; } if (!liftProtocol.isIdle()) { continue; } //计算路径 List calc = NavigateUtils.calc(shuttleProtocol.getCurrentLocNo(), basDevp.getLocNo(), NavigationMapType.NORMAL.id, Utils.getShuttlePoints(shuttleThread.getSlave().getId(), Utils.getLev(shuttleProtocol.getCurrentLocNo()))); if (calc == null) { continue;//计算失败,找下一个站点 } Integer allDistance = NavigateUtils.getOriginPathAllDistance(calc);//根据原始节点结果,计算总行走距离 if (recentAllDistance > allDistance) { recentAllDistance = allDistance;//更新距离 recentDevp = basDevp;//更新输送站点 } } if (recentDevp == null) { //没有找到可用输送站点 return false;//等待下一次轮询 } //获取提升机数据 BasLift basLift = basLiftService.selectById(recentDevp.getLiftNo()); if (basLift == null) { return false;//没有提升机数据 } if (basLift.getPoint() == null) { return false;//没有设置提升机点位坐标 } //判断提升机是否有其他任务 WrkMast liftWrkMast = wrkMastMapper.selectLiftWrkMast(basLift.getLiftNo()); if (liftWrkMast != null) { return false;//当前提升机存在未完成任务,等待下一次轮询 } NavigateNode liftNode = new NavigateNode(basLift.getPoint().getX(), basLift.getPoint().getY()); liftNode.setZ(basLift.getPoint().getZ()); //获取小车到输送站点行走命令 NyShuttleOperaResult result = NyShuttleOperaUtils.getStartToTargetCommands(shuttleThread.getSlave().getId(), wrkMast.getWrkNo(), shuttleProtocol.getCurrentLocNo(), recentDevp.getLocNo()); //获取小车进提升机行走命令 NyShuttleHttpCommand moveCommand = NyHttpUtils.getInOutLiftCommand(shuttleThread.getSlave().getId(), wrkMast.getWrkNo(), NavigatePositionConvert.locNoToNode(recentDevp.getLocNo()), liftNode, true); if (result.getCommands() == null) { return false;//路径计算失败 } List commands = result.getCommands(); commands.add(moveCommand);//添加小车迁入提升机命令 ShuttleAssignCommand assignCommand = new ShuttleAssignCommand(); assignCommand.setShuttleNo(shuttleProtocol.getShuttleNo()); // 四向穿梭车编号 assignCommand.setTaskMode(ShuttleTaskModeType.SHUTTLE_MOVE_LOC_NO.id.shortValue());//小车移库任务 assignCommand.setTaskNo(wrkMast.getWrkNo().shortValue());//任务号 assignCommand.setAuto(true);//自动模式 assignCommand.setCommands(commands); assignCommand.setNodes(result.getNodes()); wrkMast.setWrkSts(102L);//小车移动到提升机中 101.生成小车移库任务 ==> 102.小车到提升机中 wrkMast.setLiftNo(basLift.getLiftNo());//提升机号(锁定提升机防止被其他任务抢占) wrkMast.setModiTime(now); if (wrkMastMapper.updateById(wrkMast) > 0) { //下发任务 MessageQueue.offer(SlaveType.Shuttle, assignCommand.getShuttleNo().intValue(), new Task(3, assignCommand)); } } return true; } /** * 小车迁移-提升机搬运中 * 如需主方法执行continue,请返回false * ps:返回值true并不代表该方法执行成功,返回值仅做标记用于主方法是否执行continue */ private boolean shuttleMoveExecuteStep2(WrkMast wrkMast) { //--------------------------------------提升机搬运中-----------------------------------------// Date now = new Date(); //提升机搬运中 103.小车到提升机完成 ==> 104.提升机搬运中 if (wrkMast.getWrkSts() == 103) { LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, wrkMast.getLiftNo()); if (liftThread == null) { return false; } LiftProtocol liftProtocol = liftThread.getLiftProtocol(); if (liftProtocol == null) { return false; } if (!liftProtocol.isIdle(wrkMast.getWrkNo().shortValue())) { return false; } //获取四向穿梭车线程 NyShuttleThread shuttleThread = (NyShuttleThread) SlaveConnection.get(SlaveType.Shuttle, wrkMast.getShuttleNo()); if (shuttleThread == null) { return false; } NyShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol(); if (shuttleProtocol == null) { return false; } //小车处于空闲状态 if (!shuttleProtocol.isIdleNoCharge()) { return false; } //获取源站对应的输送站点 BasDevp sourceBasDevp = basDevpService.selectByLevAndLiftNo(Utils.getLev(wrkMast.getSourceLocNo()), liftProtocol.getLiftNo().intValue()); //获取目标站对应的输送站点 BasDevp targetBasDevp = basDevpService.selectByLevAndLiftNo(Utils.getLev(wrkMast.getLocNo()), liftProtocol.getLiftNo().intValue()); if (sourceBasDevp == null || targetBasDevp == null) { return false;//缺少站点信息 } //获取提升机命令 NyLiftCommand liftCommand = NyLiftUtils.getLiftCommand(liftProtocol.getLiftNo().intValue(), NyLiftTaskModelType.MOVE_CAR.id, sourceBasDevp.getDevNo(), targetBasDevp.getDevNo(), wrkMast.getWrkNo()); ArrayList commands = new ArrayList<>(); commands.add(liftCommand); //提交到线程去工作 LiftAssignCommand assignCommand = new LiftAssignCommand(); assignCommand.setCommands(commands); assignCommand.setLiftNo(liftProtocol.getLiftNo()); assignCommand.setTaskNo(wrkMast.getWrkNo().shortValue()); assignCommand.setTaskMode(NyLiftTaskModelType.MOVE_CAR.id.shortValue()); wrkMast.setWrkSts(104L);//提升机搬运中 103.小车到提升机完成 ==> 104.提升机搬运中 wrkMast.setLiftNo(liftThread.getSlave().getId());//锁定提升机防止被占用 wrkMast.setModiTime(now); if (wrkMastMapper.updateById(wrkMast) > 0) { //下发任务 MessageQueue.offer(SlaveType.Lift, liftProtocol.getLiftNo().intValue(), new Task(3, assignCommand)); } } return true; } /** * 小车迁移-小车迁出提升机中 * 如需主方法执行continue,请返回false * ps:返回值true并不代表该方法执行成功,返回值仅做标记用于主方法是否执行continue */ private boolean shuttleMoveExecuteStep3(WrkMast wrkMast) { //--------------------------------------小车迁出提升机中-----------------------------------------// Date now = new Date(); //小车迁出提升机中 105.提升机搬运完成 ==> 106.小车迁出提升机中 if (wrkMast.getWrkSts() == 105) { LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, wrkMast.getLiftNo()); if (liftThread == null) { return false; } LiftProtocol liftProtocol = liftThread.getLiftProtocol(); if (liftProtocol == null) { return false; } if (!liftProtocol.isIdle(wrkMast.getWrkNo().shortValue())) { return false; } //获取四向穿梭车线程 NyShuttleThread shuttleThread = (NyShuttleThread) SlaveConnection.get(SlaveType.Shuttle, wrkMast.getShuttleNo()); if (shuttleThread == null) { return false; } NyShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol(); if (shuttleProtocol == null) { return false; } //小车处于空闲状态 if (!shuttleProtocol.isIdleNoCharge()) { return false; } //获取目标站对应的输送站点 BasDevp targetBasDevp = basDevpService.selectByLevAndLiftNo(Utils.getLev(wrkMast.getLocNo()), liftProtocol.getLiftNo().intValue()); if (targetBasDevp == null) { return false;//缺少站点信息 } //获取提升机数据 BasLift basLift = basLiftService.selectById(targetBasDevp.getLiftNo()); if (basLift == null) { return false;//没有提升机数据 } if (basLift.getPoint() == null) { return false;//没有设置提升机点位坐标 } NavigateNode liftNode = new NavigateNode(basLift.getPoint().getX(), basLift.getPoint().getY()); liftNode.setZ(basLift.getPoint().getZ()); List commands = new ArrayList<>(); //获取小车出提升机行走命令 NyShuttleHttpCommand moveCommand = NyHttpUtils.getInOutLiftCommand(shuttleThread.getSlave().getId(), wrkMast.getWrkNo(), liftNode, NavigatePositionConvert.locNoToNode(targetBasDevp.getLocNo()), false); commands.add(moveCommand);//添加小车迁出提升机命令 ShuttleAssignCommand assignCommand = new ShuttleAssignCommand(); assignCommand.setShuttleNo(shuttleProtocol.getShuttleNo()); // 四向穿梭车编号 assignCommand.setTaskMode(ShuttleTaskModeType.SHUTTLE_MOVE_LOC_NO.id.shortValue());//小车移库任务 assignCommand.setTaskNo(wrkMast.getWrkNo().shortValue());//任务号 assignCommand.setAuto(true);//自动模式 assignCommand.setCommands(commands); assignCommand.setNodes(null); wrkMast.setWrkSts(106L);//小车迁出提升机中 105.提升机搬运完成 ==> 106.小车迁出提升机中 wrkMast.setModiTime(now); if (wrkMastMapper.updateById(wrkMast) > 0) { //下发任务 MessageQueue.offer(SlaveType.Shuttle, assignCommand.getShuttleNo().intValue(), new Task(3, assignCommand)); } } return true; } /** * 小车迁移-小车移动到目标库位中 * 如需主方法执行continue,请返回false * ps:返回值true并不代表该方法执行成功,返回值仅做标记用于主方法是否执行continue */ private boolean shuttleMoveExecuteStep4(WrkMast wrkMast) { //--------------------------------------小车移动到目标库位中-----------------------------------------// Date now = new Date(); //小车移动到目标库位中 107.小车迁出提升机完成 ==> 108.小车移动中 if (wrkMast.getWrkSts() == 107) { //获取四向穿梭车线程 NyShuttleThread shuttleThread = (NyShuttleThread) SlaveConnection.get(SlaveType.Shuttle, wrkMast.getShuttleNo()); if (shuttleThread == null) { return false; } NyShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol(); if (shuttleProtocol == null) { return false; } //小车处于空闲状态 if (!shuttleProtocol.isIdleNoCharge()) { return false; } //获取目标站对应的输送站点 BasDevp targetBasDevp = basDevpService.selectByLevAndLiftNo(Utils.getLev(wrkMast.getLocNo()), wrkMast.getLiftNo()); if (targetBasDevp == null) { return false;//缺少站点信息 } //获取提升机数据 BasLift basLift = basLiftService.selectById(targetBasDevp.getLiftNo()); if (basLift == null) { return false;//没有提升机数据 } if (basLift.getPoint() == null) { return false;//没有设置提升机点位坐标 } NavigateNode liftNode = new NavigateNode(basLift.getPoint().getX(), basLift.getPoint().getY()); liftNode.setZ(basLift.getPoint().getZ()); //获取小车从输送站到目标库位命令 NyShuttleOperaResult result = NyShuttleOperaUtils.getStartToTargetCommands(shuttleThread.getSlave().getId(), wrkMast.getWrkNo(), targetBasDevp.getLocNo(), wrkMast.getLocNo()); if (result.getCommands() == null) { return false;//路径计算失败 } List commands = result.getCommands(); ShuttleAssignCommand assignCommand = new ShuttleAssignCommand(); assignCommand.setShuttleNo(shuttleProtocol.getShuttleNo()); // 四向穿梭车编号 assignCommand.setTaskMode(ShuttleTaskModeType.SHUTTLE_MOVE_LOC_NO.id.shortValue());//小车移库任务 assignCommand.setTaskNo(wrkMast.getWrkNo().shortValue());//任务号 assignCommand.setAuto(true);//自动模式 assignCommand.setCommands(commands); assignCommand.setNodes(result.getNodes()); wrkMast.setWrkSts(108L);//小车移动到目标库位中 107.小车迁出提升机完成 ==> 108.小车移动中 wrkMast.setLiftNo(null);//释放提升机 wrkMast.setModiTime(now); if (wrkMastMapper.updateById(wrkMast) > 0) { //下发任务 MessageQueue.offer(SlaveType.Shuttle, assignCommand.getShuttleNo().intValue(), new Task(3, assignCommand)); } } return true; } /** * 出入库模式切换 */ public synchronized void outAndIn() { try { // 根据输送线plc遍历 for (DevpSlave devp : slaveProperties.getDevp()) { for (DevpSlave.Sta inSta : devp.getInSta()) { Thread.sleep(500); boolean a=true,b=true; List wrkMasts = wrkMastMapper.selectAll(inSta.getStaNo()); if (Cools.isEmpty(wrkMasts)){ b=false; }else { for (WrkMast wrkMast:wrkMasts){ if (wrkMast.getSourceStaNo() > wrkMast.getStaNo()){ a=false; break; } } } switch (inSta.getStaNo()) { case 102://1F if (a && b){ MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(3, 11)); }else if (b){ MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(3, 12)); }else { MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(3, 10)); } break; case 202://2F if (a && b){ MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(3, 21)); }else if (b){ MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(3, 22)); }else { MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(3, 20)); } break; case 302://3F if (a && b){ MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(3, 31)); }else if (b){ MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(3, 32)); }else { MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(3, 30)); } break; } } } } catch (Exception e) { e.printStackTrace(); } } }