| | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.baomidou.mybatisplus.mapper.Wrapper; |
| | | import com.core.common.Cools; |
| | | import com.core.common.SpringUtils; |
| | | import com.core.exception.CoolException; |
| | | import com.zy.asrs.entity.*; |
| | | import com.zy.asrs.mapper.*; |
| | | import com.zy.asrs.service.*; |
| | |
| | | import org.springframework.transaction.interceptor.TransactionAspectSupport; |
| | | |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * 立体仓库WCS系统主流程业务 |
| | |
| | | */ |
| | | @Slf4j |
| | | @Service("mainService") |
| | | @Transactional |
| | | public class MainServiceImpl { |
| | | |
| | | @Value("${wms.url}") |
| | |
| | | @Autowired |
| | | private WrkMastService wrkMastService; |
| | | @Autowired |
| | | private WrkDetlService wrkDetlService; |
| | | @Autowired |
| | | private LocMastService locMastService; |
| | | @Autowired |
| | | private LocDetlService locDetlService; |
| | | @Autowired |
| | | private StaDescService staDescService; |
| | | @Autowired |
| | |
| | | @Autowired |
| | | private ErpService erpService; |
| | | @Autowired |
| | | private OrderMapper orderMapper; |
| | | @Autowired |
| | | private OrderDetlMapper orderDetlMapper; |
| | | @Autowired |
| | | private BasLiftService basLiftService; |
| | | @Autowired |
| | | private ShuttleDispatchUtils shuttleDispatchUtils; |
| | |
| | | @Autowired |
| | | private NavigateMapUtils navigateMapUtils; |
| | | @Autowired |
| | | private WrkDetlLogService wrkDetlLogService; |
| | | private NavigateMapData navigateMapData; |
| | | |
| | | |
| | | /** |
| | |
| | | * 入库站,根据条码扫描生成入库工作档,工作状态 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)); |
| | | try { |
| | | // 根据输送线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(); |
| | | } |
| | | 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) { |
| | | 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; |
| | | } |
| | | String barcode = barcodeThread.getBarcode(); |
| | | if(!Cools.isEmpty(barcode)) { |
| | | |
| | | // 判断是否满足入库条件 |
| | | 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)) { |
| | | 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)); |
| | | // 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; |
| | | } |
| | | continue; |
| | | } |
| | | } else { |
| | | } else { |
| | | // staProtocol.setWorkNo((short) 32002); |
| | | // staProtocol.setStaNo(inSta.getBackSta().shortValue()); |
| | | // devpThread.setPakMk(staProtocol.getSiteId(), false); |
| | |
| | | // String errorMsg = "扫码失败,请重试"; |
| | | // MessageQueue.offer(SlaveType.Led, inSta.getLed(), new Task(3, errorMsg)); |
| | | // } |
| | | continue; |
| | | } |
| | | continue; |
| | | } |
| | | |
| | | // 过滤盘点/拣料/并板任务 |
| | | WrkMast wrkMast1 = wrkMastMapper.selectPickStepByBarcode(barcode); |
| | | if (null != wrkMast1) { |
| | | 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; |
| | | } |
| | | // 判断重复工作档 |
| | | 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/v2") |
| | | .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(""); |
| | | 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/v2") |
| | | .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); |
| | |
| | | // 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)); |
| | | ledThread.setLedMk(false); |
| | | // 判断重复工作档 |
| | | WrkMast wrkMast = wrkMastMapper.selectPakInStep11(inSta.getStaNo()); |
| | | if (wrkMast == null) { |
| | | continue; |
| | | } |
| | | } |
| | | News.error("请求接口失败!!!url:{};request:{};response:{}", wmsUrl + "/rpc/pakin/loc/v2", JSON.toJSONString(param), response); |
| | | } else if (code == 700) { |
| | | |
| | | // 更新工作主档 |
| | | 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)); |
| | | ledThread.setLedMk(false); |
| | | } |
| | | } |
| | | News.error("请求接口失败!!!url:{};request:{};response:{}", wmsUrl + "/rpc/pakin/loc/v2", 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)); |
| | | ledThread.setLedMk(false); |
| | | // led 异常显示 |
| | | if (ledThread != null) { |
| | | String errorMsg = barcode + "托盘识别异常,请先进行组托!"; |
| | | MessageQueue.offer(SlaveType.Led, inSta.getLed(), new Task(3, errorMsg)); |
| | | ledThread.setLedMk(false); |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); |
| | | } |
| | | } 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()); |
| | | } |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 拣料、并板再入库(325、331、333、339) |
| | | */ |
| | | @Transactional |
| | | public synchronized void stnToCrnStnPick2(){ |
| | | try { |
| | | for (DevpSlave devp : slaveProperties.getDevp()) { |
| | | // 遍历拣料入库口 |
| | | for (DevpSlave.Sta pickSta : devp.getPickInSta2()) { |
| | | // 获取拣料入库站信息 |
| | | 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.isInEnable() |
| | | && (staProtocol.getWorkNo() > 0) |
| | | && staProtocol.isPakMk()) { |
| | | |
| | | WrkMast wrkMast = wrkMastMapper.selectByWorkNo(staProtocol.getWorkNo().intValue()); |
| | | if (wrkMast == null) { |
| | | continue; |
| | | } |
| | | if (wrkMast.getSteNo() == null) { |
| | | wrkMast.setSteNo(1); |
| | | wrkMastMapper.updateById(wrkMast); |
| | | staProtocol.setStaNo((short) 341);//写入目标站 |
| | | staProtocol.setPakMk(false); |
| | | MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol)); |
| | | } |
| | | } |
| | | } |
| | |
| | | ////// devpThread.setPakMk(staProtocol.getSiteId(), false); |
| | | ////// boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol)); |
| | | ////// if (!result) { |
| | | ////// News.error("发布命令至输送线队列失败!!! [plc编号:{}]", devp.getId()); |
| | | ////// News.error("发布命令至输送线队列失败!!! [plc编号{}]", devp.getId()); |
| | | ////// } |
| | | //// |
| | | //// barcodeThread.setBarcode("");//清理条码 |
| | |
| | | if (basMap == null) { |
| | | //数据库中也不存在地图数据,从地图文件中获取 |
| | | //载入地图 |
| | | NavigateMapData mapData = new NavigateMapData(i); |
| | | List<List<MapNode>> lists = mapData.getJsonData(-1, null, null);//获取完整地图(包括入库出库) |
| | | List<List<MapNode>> lists = navigateMapData.getJsonData(i, -1, null, null);//获取完整地图(包括入库出库) |
| | | |
| | | //存入数据库 |
| | | basMap = new BasMap(); |
| | |
| | | } |
| | | |
| | | /** |
| | | * AGV补货 => 生成入库通知档 |
| | | */ |
| | | public void robotGenerateAgvTask() { |
| | | try { |
| | | //检测300站是否自动、有物、工作号 |
| | | for (DevpSlave devp : slaveProperties.getDevp()) { |
| | | // 获取入库站信息 |
| | | DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId()); |
| | | StaProtocol staProtocol = devpThread.getStation().get(300); |
| | | if (staProtocol == null) { |
| | | continue; |
| | | } |
| | | if (staProtocol.isAutoing() && staProtocol.isLoading() && staProtocol.getWorkNo() != 0) { |
| | | //查询是否有工作档 |
| | | WrkMast wrkMast = wrkMastMapper.selectByWorkNo(staProtocol.getWorkNo().intValue()); |
| | | if (wrkMast == null) { |
| | | continue; |
| | | } |
| | | |
| | | if (wrkMast.getWrkSts() != 25) {//25.提升机搬运完成 |
| | | continue; |
| | | } |
| | | |
| | | if (wrkMast.getMk() != null && wrkMast.getMk().equals("Y")) {//标记为Y表示需要用到机械臂拣料 |
| | | Short targetSta = null;//目标站 |
| | | //判断机械臂拣料站是否空闲 |
| | | StaProtocol staProtocol303 = devpThread.getStation().get(303); |
| | | StaProtocol staProtocol317 = devpThread.getStation().get(317); |
| | | if (staProtocol303.isAutoing() && !staProtocol303.isLoading()) { |
| | | //自动、无物 |
| | | targetSta = (short) 303; |
| | | } else if (staProtocol317.isAutoing() && !staProtocol317.isLoading()) { |
| | | //自动、无物 |
| | | targetSta = (short) 317; |
| | | } else { |
| | | continue;//没有空闲站点 |
| | | } |
| | | |
| | | if (wrkMast.getStaNo() != 303 && wrkMast.getStaNo() != 317) { |
| | | //向AGV发起组托请求 |
| | | try { |
| | | HashMap<String, Object> param = new HashMap<>(); |
| | | param.put("wrkNo", wrkMast.getWrkNo()); |
| | | String response = new HttpHandler.Builder() |
| | | .setUri(wmsUrl) |
| | | .setPath("/rpc/replenishment") |
| | | .setJson(JSON.toJSONString(param)) |
| | | .build() |
| | | .doPost(); |
| | | JSONObject jsonObject = JSON.parseObject(response); |
| | | Integer code = jsonObject.getInteger("code"); |
| | | if (code.equals(200)) {//AGV组托成功 |
| | | //覆盖工作档目标站 |
| | | wrkMast.setStaNo(targetSta.intValue()); |
| | | wrkMast.setShuttleNo(null);//释放小车 |
| | | wrkMast.setLiftNo(null);//释放提升机 |
| | | if (wrkMastMapper.updateById(wrkMast) > 0) { |
| | | //向300站写入目标站 |
| | | staProtocol = staProtocol.clone(); |
| | | staProtocol.setStaNo(targetSta);//移动到目标站 |
| | | boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol)); |
| | | try { |
| | | Thread.sleep(500); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | continue; |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); |
| | | } |
| | | |
| | | // //覆盖工作档目标站 |
| | | // wrkMast.setStaNo(targetSta.intValue()); |
| | | // wrkMast.setShuttleNo(null);//释放小车 |
| | | // wrkMast.setLiftNo(null);//释放提升机 |
| | | // if (wrkMastMapper.updateById(wrkMast) > 0) { |
| | | // //向300站写入目标站 |
| | | // staProtocol = staProtocol.clone(); |
| | | // staProtocol.setStaNo(targetSta);//移动到目标站 |
| | | // boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol)); |
| | | // try { |
| | | // Thread.sleep(500); |
| | | // } catch (Exception e) { |
| | | // e.printStackTrace(); |
| | | // } |
| | | // continue; |
| | | // } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * AGV补货 => 机械臂拣料 |
| | | */ |
| | | public void agvRestockByRobot() { |
| | | try { |
| | | //检测300站是否自动、有物、工作号 |
| | | for (DevpSlave devp : slaveProperties.getDevp()) { |
| | | // 获取入库站信息 |
| | | DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId()); |
| | | StaProtocol staProtocol303 = devpThread.getStation().get(303); |
| | | StaProtocol staProtocol317 = devpThread.getStation().get(317); |
| | | if (staProtocol303 == null || staProtocol317 == null) { |
| | | continue; |
| | | } |
| | | |
| | | if (staProtocol303.isAutoing() && staProtocol303.isLoading() && staProtocol303.getWorkNo() != 0) { |
| | | //调度机械臂 |
| | | //查询是否有工作档 |
| | | WrkMast wrkMast = wrkMastMapper.selectByWorkNo(staProtocol303.getWorkNo().intValue()); |
| | | if (wrkMast == null) { |
| | | continue; |
| | | } |
| | | List<WrkDetl> wrkDetls = wrkDetlService.findByWorkNo(wrkMast.getWrkNo()); |
| | | if (wrkDetls.isEmpty()) { |
| | | continue; |
| | | } |
| | | |
| | | if (wrkMast.getInvWh() == null) { |
| | | boolean result = RobotUtils.sendTask(staProtocol303.getWorkNo().toString(), wrkDetls.size(), "303"); |
| | | if (result) { |
| | | wrkMast.setInvWh("Y");//标记已经下发机械臂任务 |
| | | wrkMastMapper.updateById(wrkMast); |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (staProtocol317.isAutoing() && staProtocol317.isLoading() && staProtocol317.getWorkNo() != 0) { |
| | | //调度机械臂 |
| | | //查询是否有工作档 |
| | | WrkMast wrkMast = wrkMastMapper.selectByWorkNo(staProtocol317.getWorkNo().intValue()); |
| | | if (wrkMast == null) { |
| | | continue; |
| | | } |
| | | List<WrkDetl> wrkDetls = wrkDetlService.findByWorkNo(wrkMast.getWrkNo()); |
| | | if (wrkDetls.isEmpty()) { |
| | | continue; |
| | | } |
| | | if (wrkMast.getInvWh() == null) { |
| | | boolean result = RobotUtils.sendTask(staProtocol317.getWorkNo().toString(), wrkDetls.size(), "317"); |
| | | if (result) { |
| | | wrkMast.setInvWh("Y");//标记已经下发机械臂任务 |
| | | wrkMastMapper.updateById(wrkMast); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * AGV补货(通知AGV取货) |
| | | */ |
| | | public void agvRestockInto() { |
| | | try { |
| | | //检测309和312站是否自动、有物 |
| | | for (DevpSlave devp : slaveProperties.getDevp()) { |
| | | // 获取入库站信息 |
| | | DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId()); |
| | | StaProtocol staProtocol309 = devpThread.getStation().get(309); |
| | | StaProtocol staProtocol312 = devpThread.getStation().get(312); |
| | | if (staProtocol309 == null || staProtocol312 == null) { |
| | | continue; |
| | | } |
| | | |
| | | if (staProtocol309.isAutoing() && staProtocol309.isLoading() && staProtocol309.isInEnable()) { |
| | | // 获取条码扫描仪信息 |
| | | BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, 9);//308站条码器 |
| | | if (barcodeThread == null) { |
| | | continue; |
| | | } |
| | | String barcode = barcodeThread.getBarcode(); |
| | | if (!Cools.isEmpty(barcode)) { |
| | | //通知AGV取货 |
| | | agvRestockCall("301-1", barcode); |
| | | log.info("通知AGV取货,条码号:" + barcode); |
| | | } |
| | | } |
| | | |
| | | if (staProtocol312.isAutoing() && staProtocol312.isLoading() && staProtocol312.isInEnable()) { |
| | | // 获取条码扫描仪信息 |
| | | BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, 10);//311站条码器 |
| | | if (barcodeThread == null) { |
| | | continue; |
| | | } |
| | | String barcode = barcodeThread.getBarcode(); |
| | | if (!Cools.isEmpty(barcode)) { |
| | | //通知AGV取货 |
| | | agvRestockCall("302-1", barcode); |
| | | log.info("通知AGV取货,条码号:" + barcode); |
| | | } |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | //通知AGV取货 |
| | | private boolean agvRestockCall(String staNo, String barcode) { |
| | | try { |
| | | HashMap<String, Object> param = new HashMap<>(); |
| | | param.put("devNo", staNo); |
| | | param.put("containerCode", barcode); |
| | | String response = new HttpHandler.Builder() |
| | | .setUri(wmsUrl) |
| | | .setPath("/rpc/start") |
| | | .setJson(JSON.toJSONString(param)) |
| | | .build() |
| | | .doPost(); |
| | | JSONObject jsonObject = JSON.parseObject(response); |
| | | News.info("悬挂线,WMS返回结果:" + jsonObject); |
| | | Integer code = jsonObject.getInteger("code"); |
| | | if (code.equals(200)) {//呼叫AGV |
| | | return true; |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | //通知WMS当前拣料站点信息 |
| | | private boolean agvCureentCall(String staNo, String barcode) { |
| | | try { |
| | | HashMap<String, Object> param = new HashMap<>(); |
| | | param.put("devNo", staNo); |
| | | param.put("containerCode", barcode); |
| | | String response = new HttpHandler.Builder() |
| | | .setUri(wmsUrl) |
| | | .setPath("/rpc/current/containerCode") |
| | | .setJson(JSON.toJSONString(param)) |
| | | .build() |
| | | .doPost(); |
| | | JSONObject jsonObject = JSON.parseObject(response); |
| | | News.info("悬挂线,WMS返回结果:" + jsonObject); |
| | | Integer code = jsonObject.getInteger("code"); |
| | | if (code.equals(200)) {//呼叫AGV |
| | | return true; |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | /** |
| | | * AGV补货(悬挂线通知AGV取货) |
| | | */ |
| | | public void agvRestockIntoByHangingWire() { |
| | | try { |
| | | //检测350和351扫码器 |
| | | int[] barcodeStaNo = {11, 12,14,16,18,20};//11 => 350站扫码器,12 => 351站扫码器 |
| | | for (int staNo : barcodeStaNo) { |
| | | // 获取条码扫描仪信息 |
| | | BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, staNo); |
| | | if (barcodeThread == null) { |
| | | continue; |
| | | } |
| | | String barcode = barcodeThread.getBarcode(); |
| | | if (!Cools.isEmpty(barcode)) { |
| | | if (barcode.contains("NoRead")) { |
| | | continue; |
| | | } |
| | | |
| | | String agvStaNo = null; |
| | | if (staNo == 11) { |
| | | agvStaNo = "303-1"; |
| | | } else if(staNo == 12){ |
| | | agvStaNo = "304-1"; |
| | | } else if(staNo == 14){ |
| | | agvStaNo = "311-1"; |
| | | } else if(staNo == 16){ |
| | | agvStaNo = "313-1"; |
| | | } else if(staNo == 18){ |
| | | agvStaNo = "315-1"; |
| | | } else if(staNo == 20){ |
| | | agvStaNo = "317-1"; |
| | | } |
| | | //通知AGV取货 |
| | | boolean result = agvRestockCall(agvStaNo, barcode); |
| | | if (result) { |
| | | barcodeThread.setBarcode(""); |
| | | } |
| | | log.info(barcodeThread.getSlave().getId() + "号扫码器,通知AGV取货,条码号:" + barcode); |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * AGV拣料站点信息 |
| | | */ |
| | | public void agvCurrentContainerCodeInfoWire() { |
| | | try { |
| | | //检测350和351扫码器 |
| | | int[] barcodeStaNo = {13, 15,17,19};//11 => 350站扫码器,12 => 351站扫码器 |
| | | for (int staNo : barcodeStaNo) { |
| | | // 获取条码扫描仪信息 |
| | | BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, staNo); |
| | | if (barcodeThread == null) { |
| | | continue; |
| | | } |
| | | String barcode = barcodeThread.getBarcode(); |
| | | if (!Cools.isEmpty(barcode)) { |
| | | if (barcode.contains("NoRead")) { |
| | | continue; |
| | | } |
| | | |
| | | String agvStaNo = null; |
| | | if (staNo == 13) { |
| | | agvStaNo = "CS-310"; |
| | | } else if(staNo == 15){ |
| | | agvStaNo = "CS-311"; |
| | | } else if(staNo == 17){ |
| | | agvStaNo = "CS-312"; |
| | | } else if(staNo == 19){ |
| | | agvStaNo = "CS-313"; |
| | | } |
| | | //通知WMS当前容器码 |
| | | boolean result = agvCureentCall(agvStaNo, barcode); |
| | | if (result) { |
| | | barcodeThread.setBarcode(""); |
| | | } |
| | | log.info(barcodeThread.getSlave().getId() + "号扫码器,通知AGV取货,条码号:" + barcode); |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | // 300站拣料 |
| | | public void pick300() { |
| | | try { |
| | | //检测300站是否自动、有物、工作号 |
| | | for (DevpSlave devp : slaveProperties.getDevp()) { |
| | | // 获取入库站信息 |
| | | DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId()); |
| | | StaProtocol staProtocol = devpThread.getStation().get(300); |
| | | if (staProtocol == null) { |
| | | continue; |
| | | } |
| | | if (staProtocol.isAutoing() && staProtocol.isLoading() && staProtocol.getWorkNo() != 0) { |
| | | //查询是否有工作档 |
| | | WrkMast wrkMast = wrkMastMapper.selectByWorkNo(staProtocol.getWorkNo().intValue()); |
| | | if (wrkMast == null) { |
| | | continue; |
| | | } |
| | | |
| | | if (wrkMast.getWrkSts() != 29) {//29.出库完成 |
| | | continue; |
| | | } |
| | | |
| | | if (wrkMast.getMk() == null) { |
| | | Integer sourceStaNo = wrkMast.getSourceStaNo();//源站 |
| | | Integer staNo = wrkMast.getStaNo();//目标站 |
| | | //覆盖工作档目标站 |
| | | wrkMast.setStaNo(sourceStaNo); |
| | | wrkMast.setSourceStaNo(staNo); |
| | | wrkMast.setMk("N"); |
| | | if (wrkMastMapper.updateById(wrkMast) > 0) { |
| | | //向300站写入目标站 |
| | | staProtocol = staProtocol.clone(); |
| | | staProtocol.setStaNo(wrkMast.getStaNo().shortValue());//移动到目标站 |
| | | boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol)); |
| | | try { |
| | | Thread.sleep(500); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 出库 ===>> 工作档信息写入led显示器 |
| | | */ |
| | | public void ledExecute() { |
| | | try { |
| | | for (LedSlave led : slaveProperties.getLed()) { |
| | | // 获取输送线plc线程 |
| | | DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, led.getDevpPlcId()); |
| | | // 命令集合 |
| | | List<LedCommand> commands = new ArrayList<>(); |
| | | // 工作档集合 |
| | | List<WrkMast> wrkMasts = new ArrayList<>(); |
| | | List<WrkMastLog> wrkMastLogs = 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()); |
| | | Integer wrkNo = staProtocol.getWorkNo().intValue(); |
| | | Integer ioType = null; |
| | | String sourceLocNo = null; |
| | | String locNo = null; |
| | | Integer wrkStaNo = null; |
| | | String barcode = null; |
| | | if (wrkMast == null) { |
| | | //查询历史档 |
| | | WrkMastLog wrkMastLog = wrkMastLogMapper.selectLatestByWorkNo(staProtocol.getWorkNo().intValue()); |
| | | if (wrkMastLog == null) { |
| | | continue; |
| | | } |
| | | ioType = wrkMastLog.getIoType(); |
| | | sourceLocNo = wrkMastLog.getSourceLocNo(); |
| | | locNo = wrkMastLog.getLocNo(); |
| | | wrkStaNo = wrkMastLog.getStaNo(); |
| | | barcode = wrkMastLog.getBarcode(); |
| | | wrkMastLogs.add(wrkMastLog); |
| | | }else { |
| | | if (wrkMast.getWrkSts() < 14 || wrkMast.getIoType() < 100) { |
| | | continue; |
| | | } |
| | | ioType = wrkMast.getIoType(); |
| | | sourceLocNo = wrkMast.getSourceLocNo(); |
| | | locNo = wrkMast.getLocNo(); |
| | | wrkStaNo = wrkMast.getStaNo(); |
| | | barcode = wrkMast.getBarcode(); |
| | | wrkMasts.add(wrkMast); |
| | | } |
| | | // 组装命令 |
| | | LedCommand ledCommand = new LedCommand(); |
| | | ledCommand.setWorkNo(wrkNo); |
| | | ledCommand.setIoType(ioType); |
| | | // 出库模式 |
| | | switch (ioType) { |
| | | 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("任务入出库类型错误!!![工作号:{}] [入出库类型:{}]", wrkNo, ioType); |
| | | break; |
| | | } |
| | | ledCommand.setSourceLocNo(sourceLocNo); |
| | | ledCommand.setLocNo(locNo); |
| | | ledCommand.setStaNo(wrkStaNo); |
| | | ledCommand.setBarcode(barcode); |
| | | if (ioType != 110 && ioType != 10) { |
| | | List<LocDetl> locDetls = locDetlService.selectList(new EntityWrapper<LocDetl>().eq("loc_no", sourceLocNo)); |
| | | if (ioType == 101) { |
| | | List<WrkDetl> wrkDetls = wrkDetlService.selectList(new EntityWrapper<WrkDetl>().eq("wrk_no", wrkNo)); |
| | | wrkDetls.forEach(wrkDetl -> { |
| | | ledCommand.getMatDtos().add(new MatDto(wrkDetl.getMatnr(), wrkDetl.getMaktx(), wrkDetl.getAnfme(), 0D, wrkDetl.getSpecs(), wrkDetl.getSuppCode())); |
| | | }); |
| | | // locDetls.forEach(locDetl -> { |
| | | // Wrapper<WrkDetl> wrapper = new EntityWrapper<WrkDetl>().eq("matnr", locDetl.getMatnr()).eq("wrk_no", wrkNo); |
| | | // Utils.wapperSetCondition(wrapper, "batch", locDetl.getBatch()); |
| | | // Utils.wapperSetCondition(wrapper, "three_code", locDetl.getThreeCode()); |
| | | // Utils.wapperSetCondition(wrapper, "dead_time", locDetl.getDeadTime()); |
| | | // Utils.wapperSetCondition(wrapper, "supp_code", locDetl.getSuppCode());//料箱码 |
| | | // List<WrkDetl> detl = wrkDetlService.selectList(wrapper); |
| | | // if (Cools.isEmpty(detl)) { |
| | | // String suppCode = ""; |
| | | // if (locDetl.getSuppCode() != null) { |
| | | // suppCode = locDetl.getSuppCode(); |
| | | // } |
| | | // ledCommand.getMatDtos().add(new MatDto(locDetl.getMatnr(), locDetl.getMaktx(), 0D, locDetl.getAnfme(), locDetl.getSpecs(), suppCode)); |
| | | // } else { |
| | | // //出库数量累计 |
| | | // Double conut = 0.0; |
| | | // for (WrkDetl wrkDetl : detl) { |
| | | // conut = conut + wrkDetl.getAnfme(); |
| | | // } |
| | | // |
| | | // for (WrkDetl wrkDetl : detl) { |
| | | // String suppCode = ""; |
| | | // if (wrkDetl.getSuppCode() != null) { |
| | | // suppCode = wrkDetl.getSuppCode(); |
| | | // } |
| | | // ledCommand.getMatDtos().add(new MatDto(wrkDetl.getMatnr(), wrkDetl.getMaktx(), wrkDetl.getAnfme(), (locDetl.getAnfme() - conut), wrkDetl.getSpecs(), suppCode, wrkDetl.getOrderNo())); |
| | | // try { |
| | | // for (LedSlave led : slaveProperties.getLed()) { |
| | | // // 获取输送线plc线程 |
| | | // DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, led.getDevpPlcId()); |
| | | // // 命令集合 |
| | | // List<LedCommand> commands = new ArrayList<>(); |
| | | // // 工作档集合 |
| | | // List<WrkMast> wrkMasts = new ArrayList<>(); |
| | | // List<WrkMastLog> wrkMastLogs = 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()); |
| | | // Integer wrkNo = staProtocol.getWorkNo().intValue(); |
| | | // Integer ioType = null; |
| | | // String sourceLocNo = null; |
| | | // String locNo = null; |
| | | // Integer wrkStaNo = null; |
| | | // String barcode = null; |
| | | // if (wrkMast == null) { |
| | | // //查询历史档 |
| | | // WrkMastLog wrkMastLog = wrkMastLogMapper.selectLatestByWorkNo(staProtocol.getWorkNo().intValue()); |
| | | // if (wrkMastLog == null) { |
| | | // continue; |
| | | // } |
| | | // ioType = wrkMastLog.getIoType(); |
| | | // sourceLocNo = wrkMastLog.getSourceLocNo(); |
| | | // locNo = wrkMastLog.getLocNo(); |
| | | // wrkStaNo = wrkMastLog.getStaNo(); |
| | | // barcode = wrkMastLog.getBarcode(); |
| | | // wrkMastLogs.add(wrkMastLog); |
| | | // }else { |
| | | // if (wrkMast.getWrkSts() < 14 || wrkMast.getIoType() < 100) { |
| | | // continue; |
| | | // } |
| | | // ioType = wrkMast.getIoType(); |
| | | // sourceLocNo = wrkMast.getSourceLocNo(); |
| | | // locNo = wrkMast.getLocNo(); |
| | | // wrkStaNo = wrkMast.getStaNo(); |
| | | // barcode = wrkMast.getBarcode(); |
| | | // wrkMasts.add(wrkMast); |
| | | // } |
| | | // // 组装命令 |
| | | // LedCommand ledCommand = new LedCommand(); |
| | | // ledCommand.setWorkNo(wrkNo); |
| | | // ledCommand.setIoType(ioType); |
| | | // // 出库模式 |
| | | // switch (ioType) { |
| | | // 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("任务入出库类型错误!!![工作号:{}] [入出库类型:{}]", wrkNo, ioType); |
| | | // break; |
| | | // } |
| | | // ledCommand.setSourceLocNo(sourceLocNo); |
| | | // ledCommand.setLocNo(locNo); |
| | | // ledCommand.setStaNo(wrkStaNo); |
| | | // ledCommand.setBarcode(barcode); |
| | | // if (ioType != 110 && ioType != 10) { |
| | | // List<WrkDetl> wrkDetls = wrkDetlService.selectList(new EntityWrapper<WrkDetl>().eq("wrk_no", wrkNo)); |
| | | // if (!wrkDetls.isEmpty()) { |
| | | // wrkDetls.forEach(wrkDetl -> { |
| | | // double remainNum = wrkDetl.getStock() - wrkDetl.getAnfme();//剩余数量 |
| | | // if (remainNum < 0) { |
| | | // remainNum = 0; |
| | | // } |
| | | // String matnr = wrkDetl.getMatnr(); |
| | | // Mat mat = matService.selectByMatnr(wrkDetl.getMatnr()); |
| | | // if (mat != null) { |
| | | // if (!mat.getMatnr().equals(mat.getMatnr2())) { |
| | | // matnr += " - " + mat.getMatnr2(); |
| | | // } |
| | | // } |
| | | // |
| | | // ledCommand.getMatDtos().add(new MatDto(matnr, wrkDetl.getMaktx(), wrkDetl.getAnfme(), remainNum, wrkDetl.getSpecs(), wrkDetl.getSuppCode(), wrkDetl.getOrderNo())); |
| | | // }); |
| | | } else { |
| | | locDetls.forEach(locDetl -> { |
| | | Wrapper<WrkDetl> wrapper = new EntityWrapper<WrkDetl>().eq("matnr", locDetl.getMatnr()).eq("wrk_no", wrkNo); |
| | | Utils.wapperSetCondition(wrapper, "batch", locDetl.getBatch()); |
| | | Utils.wapperSetCondition(wrapper, "three_code", locDetl.getThreeCode()); |
| | | Utils.wapperSetCondition(wrapper, "dead_time", locDetl.getDeadTime()); |
| | | Utils.wapperSetCondition(wrapper, "supp_code", locDetl.getSuppCode());//料箱码 |
| | | List<WrkDetl> detl = wrkDetlService.selectList(wrapper); |
| | | if (Cools.isEmpty(detl)) { |
| | | String suppCode = ""; |
| | | if (locDetl.getSuppCode() != null) { |
| | | suppCode = locDetl.getSuppCode(); |
| | | } |
| | | ledCommand.getMatDtos().add(new MatDto(locDetl.getMatnr(), locDetl.getMaktx(), 0D, locDetl.getAnfme(), locDetl.getSpecs(), suppCode)); |
| | | } else { |
| | | //出库数量累计 |
| | | Double conut = 0.0; |
| | | for (WrkDetl wrkDetl : detl) { |
| | | conut = conut + wrkDetl.getAnfme(); |
| | | } |
| | | |
| | | for (WrkDetl wrkDetl : detl) { |
| | | String suppCode = ""; |
| | | if (wrkDetl.getSuppCode() != null) { |
| | | suppCode = wrkDetl.getSuppCode(); |
| | | } |
| | | if (wrkDetl.getAnfme() > 0D) { |
| | | ledCommand.getMatDtos().add(new MatDto(wrkDetl.getMatnr(), wrkDetl.getMaktx(), wrkDetl.getAnfme(), (wrkDetl.getStock() - conut), wrkDetl.getSpecs(), suppCode, wrkDetl.getOrderNo())); |
| | | } |
| | | } |
| | | } |
| | | |
| | | }); |
| | | } |
| | | |
| | | |
| | | if (ioType == 107) { |
| | | locDetls = new ArrayList<>(); |
| | | ledCommand.setMatDtos(new ArrayList<>()); |
| | | } |
| | | |
| | | if (locDetls.isEmpty() && ioType != 101) { |
| | | List<WrkDetl> wrkDetls = wrkDetlService.selectList(new EntityWrapper<WrkDetl>().eq("wrk_no", wrkNo)); |
| | | wrkDetls.forEach(wrkDetl -> { |
| | | if (wrkDetl.getAnfme() > 0D) { |
| | | ledCommand.getMatDtos().add(new MatDto(wrkDetl.getMatnr(), wrkDetl.getMaktx(), wrkDetl.getAnfme(), wrkDetl.getAnfme(), wrkDetl.getSpecs(), wrkDetl.getSuppCode())); |
| | | } |
| | | }); |
| | | |
| | | if (wrkDetls.isEmpty()) {//从历史档查询 |
| | | List<WrkDetlLog> wrkDetlLogs = wrkDetlLogService.selectLatestByWorkNo(wrkNo, barcode); |
| | | for (WrkDetlLog wrkDetlLog : wrkDetlLogs) { |
| | | if (wrkDetlLog.getAnfme() > 0D) { |
| | | ledCommand.getMatDtos().add(new MatDto(wrkDetlLog.getMatnr(), wrkDetlLog.getMaktx(), wrkDetlLog.getAnfme(), wrkDetlLog.getAnfme(), wrkDetlLog.getSpecs(), wrkDetlLog.getSuppCode())); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | commands.add(ledCommand); |
| | | } |
| | | Set<Integer> workNos = null; |
| | | if (!wrkMasts.isEmpty()) { |
| | | workNos = wrkMasts.stream().map(WrkMast::getWrkNo).collect(Collectors.toSet()); |
| | | }else { |
| | | workNos = wrkMastLogs.stream().map(WrkMastLog::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 (!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(); |
| | | } |
| | | |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | // }else { |
| | | // List<WrkDetlLog> wrkDetlLogs = wrkDetlLogService.selectLatestByWorkNo(wrkNo, barcode); |
| | | // for (WrkDetlLog wrkDetlLog : wrkDetlLogs) { |
| | | // double remainNum = wrkDetlLog.getStock() - wrkDetlLog.getAnfme();//剩余数量 |
| | | // if (remainNum < 0) { |
| | | // remainNum = 0; |
| | | // } |
| | | // String matnr = wrkDetlLog.getMatnr(); |
| | | // Mat mat = matService.selectByMatnr(wrkDetlLog.getMatnr()); |
| | | // if (mat != null) { |
| | | // if (!mat.getMatnr().equals(mat.getMatnr2())) { |
| | | // matnr += " - " + mat.getMatnr2(); |
| | | // } |
| | | // } |
| | | // ledCommand.getMatDtos().add(new MatDto(matnr, wrkDetlLog.getMaktx(), wrkDetlLog.getAnfme(), remainNum, wrkDetlLog.getSpecs(), wrkDetlLog.getSuppCode())); |
| | | // } |
| | | // } |
| | | // commands.add(ledCommand); |
| | | // } |
| | | // Set<Integer> workNos = null; |
| | | // if (!wrkMasts.isEmpty()) { |
| | | // workNos = wrkMasts.stream().map(WrkMast::getWrkNo).collect(Collectors.toSet()); |
| | | // }else { |
| | | // workNos = wrkMastLogs.stream().map(WrkMastLog::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 (!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(); |
| | | // } |
| | | // |
| | | // } |
| | | // } catch (Exception e) { |
| | | // e.printStackTrace(); |
| | | // } |
| | | } |
| | | |
| | | /** |
| | |
| | | |
| | | //扫描设备PakMk标记是否超时 |
| | | public synchronized void scanDevicePakMk() { |
| | | //扫描小车 |
| | | for (ShuttleSlave slave : slaveProperties.getShuttle()) { |
| | | NyShuttleThread shuttleThread = (NyShuttleThread) SlaveConnection.get(SlaveType.Shuttle, slave.getId()); |
| | | NyShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol(); |
| | | if (shuttleProtocol == null) { |
| | | continue; |
| | | try { |
| | | //扫描小车 |
| | | for (ShuttleSlave slave : slaveProperties.getShuttle()) { |
| | | NyShuttleThread shuttleThread = (NyShuttleThread) SlaveConnection.get(SlaveType.Shuttle, slave.getId()); |
| | | NyShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol(); |
| | | if (shuttleProtocol == null) { |
| | | continue; |
| | | } |
| | | |
| | | if ((System.currentTimeMillis() - shuttleProtocol.getSendTime() > (1000 * 60 * 5)) && shuttleProtocol.getPakMk()) { |
| | | //设备超过5分钟还没复位标记 |
| | | shuttleProtocol.setPakMk(false);//复位标记 |
| | | } |
| | | } |
| | | |
| | | if ((System.currentTimeMillis() - shuttleProtocol.getSendTime() > (1000*60*5)) && shuttleProtocol.getPakMk()) { |
| | | //设备超过5分钟还没复位标记 |
| | | shuttleProtocol.setPakMk(false);//复位标记 |
| | | } |
| | | } |
| | | //扫描提升机 |
| | | for (LiftSlave slave : slaveProperties.getLift()) { |
| | | LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, slave.getId()); |
| | | LiftProtocol liftProtocol = liftThread.getLiftProtocol(); |
| | | if (liftProtocol == null) { |
| | | continue; |
| | | } |
| | | |
| | | //扫描提升机 |
| | | for (LiftSlave slave : slaveProperties.getLift()) { |
| | | LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, slave.getId()); |
| | | LiftProtocol liftProtocol = liftThread.getLiftProtocol(); |
| | | if (liftProtocol == null) { |
| | | continue; |
| | | if ((System.currentTimeMillis() - liftProtocol.getSendTime() > (1000 * 60 * 5)) && liftProtocol.getPakMk()) { |
| | | //设备超过5分钟还没复位标记 |
| | | liftProtocol.setPakMk(false);//复位标记 |
| | | } |
| | | } |
| | | |
| | | if ((System.currentTimeMillis() - liftProtocol.getSendTime() > (1000*60*5)) && liftProtocol.getPakMk()) { |
| | | //设备超过5分钟还没复位标记 |
| | | liftProtocol.setPakMk(false);//复位标记 |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | } |