| | |
| | | import com.core.common.Cools; |
| | | import com.core.common.DateUtils; |
| | | import com.core.exception.CoolException; |
| | | import com.zy.entity.*; |
| | | import com.zy.mapper.*; |
| | | import com.zy.service.*; |
| | | import com.zy.utils.RouteUtils; |
| | | import com.zy.utils.Utils; |
| | | import com.zy.utils.VersionUtils; |
| | | import com.zy.common.model.LocTypeDto; |
| | | import com.zy.common.model.MatDto; |
| | | import com.zy.common.model.SearchLocParam; |
| | | import com.zy.common.model.StartupDto; |
| | | import com.zy.common.service.CommonService; |
| | | import com.zy.utils.CollectionUtils; |
| | | import com.zy.utils.HttpHandler; |
| | | import com.zy.utils.News; |
| | | import com.zy.core.CrnThread; |
| | | import com.zy.core.DevpThread; |
| | | 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.CrnSlave; |
| | | import com.zy.core.model.DevpSlave; |
| | | import com.zy.core.model.LedSlave; |
| | | import com.zy.core.model.Task; |
| | | import com.zy.core.model.command.CrnCommand; |
| | | import com.zy.core.model.command.LedCommand; |
| | | import com.zy.core.model.command.RgvCommand; |
| | |
| | | import com.zy.core.thread.LedThread; |
| | | import com.zy.core.thread.RgvThread; |
| | | import com.zy.core.thread.SiemensDevpThread; |
| | | import com.zy.entity.*; |
| | | import com.zy.mapper.*; |
| | | import com.zy.service.*; |
| | | import com.zy.utils.*; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | |
| | | @Value("${wms.url}") |
| | | private String wmsUrl; |
| | | |
| | | public Integer wrkNo = 10000; |
| | | public Integer wrkNo = 9901; |
| | | |
| | | /** |
| | | * 组托 |
| | |
| | | // 尺寸检测异常 |
| | | boolean back = false; |
| | | String errMsg = ""; |
| | | if ((staProtocol.getSiteId() == 101 && devpThread.ioModeOf101 == IoModeType.PAKOUT_MODE) |
| | | ||(staProtocol.getSiteId() == 103 && devpThread.ioModeOf103 == IoModeType.PAKOUT_MODE) |
| | | ||(staProtocol.getSiteId() == 305 && devpThread.ioModeOf305 == IoModeType.PAKOUT_MODE)) { |
| | | errMsg = "当前为出库模式"; |
| | | back = true; |
| | | } |
| | | if (!back && staProtocol.isFrontErr()) { |
| | | // if ((staProtocol.getSiteId() == 101 && devpThread.ioModeOf101 == IoModeType.PAKOUT_MODE) |
| | | // ||(staProtocol.getSiteId() == 103 && devpThread.ioModeOf103 == IoModeType.PAKOUT_MODE) |
| | | // ||(staProtocol.getSiteId() == 305 && devpThread.ioModeOf305 == IoModeType.PAKOUT_MODE)) { |
| | | // errMsg = "当前为出库模式"; |
| | | // back = true; |
| | | // } |
| | | // if (!back && staProtocol.isFrontErr()) { |
| | | if (staProtocol.isFrontErr()) { |
| | | errMsg = "前超限"; |
| | | back = true; |
| | | } |
| | |
| | | } |
| | | staProtocol.setWorkNo(wrkNo); |
| | | News.info("{}入库回退:{},任务号:{}", inSta.getStaNo(), errMsg,wrkNo); |
| | | wrkNo++; |
| | | staProtocol.setStaNo(inSta.getBackSta().shortValue()); |
| | | devpThread.setPakMk(staProtocol.getSiteId(), false); |
| | | MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol)); |
| | |
| | | |
| | | staProtocol.setWorkNo(wrkNo); |
| | | News.info("{}入库回退:{},任务号:{}", inSta.getStaNo(), errMsg,wrkNo); |
| | | wrkNo++; |
| | | staProtocol.setStaNo(inSta.getBackSta().shortValue()); |
| | | devpThread.setPakMk(staProtocol.getSiteId(), false); |
| | | MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol)); |
| | |
| | | .build() |
| | | .doPost(); |
| | | JSONObject jsonObject = JSON.parseObject(response); |
| | | log.info("组托wms返回:" + jsonObject); |
| | | if (jsonObject.getInteger("code").equals(200)) { |
| | | StartupDto dto = jsonObject.getObject("data", StartupDto.class); |
| | | barcodeThread.setBarcode(""); |
| | |
| | | } |
| | | } else { |
| | | staProtocol.setWorkNo(wrkNo); |
| | | wrkNo++; |
| | | staProtocol.setStaNo(inSta.getBackSta().shortValue()); |
| | | devpThread.setPakMk(staProtocol.getSiteId(), false); |
| | | MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol)); |
| | |
| | | StaDesc staDesc = staDescService.selectOne(wrapper); |
| | | if (Cools.isEmpty(staDesc)) { |
| | | News.error(""+mark+" - 2"+" - 入库路径不存在!type_no={},stn_no={},crn_no={}", wrkMast.getIoType(), pickSta.getStaNo(), wrkMast.getCrnNo()); |
| | | staProtocol.setWorkNo(wrkNo++); |
| | | staProtocol.setWorkNo(wrkNo); |
| | | staProtocol.setStaNo((short) (pickSta.getStaNo().shortValue()-(short)1)); |
| | | devpThread.setPakMk(staProtocol.getSiteId(), false); |
| | | MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol)); |
| | |
| | | if(!Cools.isEmpty(barcode)) { |
| | | // log.info("{}号条码扫描器检测条码信息:{}", pickSta.getBarcode(), barcode); |
| | | if("NG".endsWith(barcode) || "NoRead".equals(barcode) || "empty".equals(barcode)) { |
| | | staProtocol.setWorkNo(wrkNo++); |
| | | staProtocol.setWorkNo(wrkNo); |
| | | staProtocol.setStaNo(pickSta.getBackSta().shortValue()); |
| | | devpThread.setPakMk(staProtocol.getSiteId(), false); |
| | | MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol)); |
| | |
| | | continue; |
| | | } |
| | | } else { |
| | | staProtocol.setWorkNo(wrkNo++); |
| | | staProtocol.setWorkNo(wrkNo); |
| | | staProtocol.setStaNo(pickSta.getBackSta().shortValue()); |
| | | devpThread.setPakMk(staProtocol.getSiteId(), false); |
| | | MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol)); |
| | |
| | | } |
| | | } |
| | | } else { |
| | | staProtocol.setWorkNo(wrkNo++); |
| | | staProtocol.setWorkNo(wrkNo); |
| | | staProtocol.setStaNo(pickSta.getBackSta().shortValue()); |
| | | devpThread.setPakMk(staProtocol.getSiteId(), false); |
| | | MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol)); |
| | |
| | | |
| | | // 下发站点信息 |
| | | staProtocol.setWorkNo(wrkMast.getWrkNo()); |
| | | staProtocol.setStaNo(RouteUtils.CrnStaEnd(wrkMast.getStaNo(),wrkMast.getSourceStaNo())); |
| | | staProtocol.setStaNo(wrkMast.getStaNo().shortValue()); |
| | | if (!MessageQueue.offer(SlaveType.Devp, crnStn.getDevpPlcId(), new Task(2, staProtocol))) { |
| | | continue; |
| | | } |
| | | |
| | | // 更新工作档状态为14失败 |
| | | wrkMast.setWrkSts(14L); |
| | | if (wrkMast.getSourceStaNo() == 106 && wrkMast.getWrkSts() == 12L) { |
| | | wrkMast.setWrkSts(16L); |
| | | } |
| | | wrkMast.setCrnEndTime(new Date()); |
| | | if (wrkMastMapper.updateById(wrkMast) != 0) { |
| | | // 复位堆垛机 |
| | |
| | | // continue; |
| | | // } |
| | | // 入出库模式判断 |
| | | if ((staProtocol.getSiteId() == 101 && devpThread.ioModeOf101 != IoModeType.PAKOUT_MODE) |
| | | || (staProtocol.getSiteId() == 103 && devpThread.ioModeOf103 != IoModeType.PAKOUT_MODE) |
| | | || (staProtocol.getSiteId() == 305 && devpThread.ioModeOf305 != IoModeType.PAKOUT_MODE)) { |
| | | continue; |
| | | } |
| | | // if ((staProtocol.getSiteId() == 101 && devpThread.ioModeOf101 != IoModeType.PAKOUT_MODE) |
| | | // || (staProtocol.getSiteId() == 103 && devpThread.ioModeOf103 != IoModeType.PAKOUT_MODE) |
| | | // || (staProtocol.getSiteId() == 305 && devpThread.ioModeOf305 != IoModeType.PAKOUT_MODE)) { |
| | | // continue; |
| | | // } |
| | | |
| | | // 查询站点详细信息 |
| | | BasDevp staDetl = basDevpService.selectById(crnStn.getStaNo()); |
| | |
| | | // continue; |
| | | } |
| | | // 判断堆垛机出库站状态 |
| | | if (staProtocol.isAutoing() && !staProtocol.isLoading() && staDetl.getCanouting() != null && staDetl.getCanouting().equals("Y") |
| | | if (staProtocol.isAutoing() && staProtocol.isLoading() && staDetl.getCanouting() != null && staDetl.getCanouting().equals("Y") |
| | | && staProtocol.getWorkNo() == 0 && staProtocol.isOutEnable()) { |
| | | // 命令下发区 -------------------------------------------------------------------------- |
| | | |
| | |
| | | if (wrkMastMapper.selectWorking(slave.getId()) != null) { |
| | | break; |
| | | // return; |
| | | } |
| | | if(crnStn.getStaNo() == 105) { |
| | | continue; |
| | | } |
| | | |
| | | News.warnNoLog(""+mark+" - 2"+" - 12"+" - 命令下发 : 工作号={},源排={},源列={},源层={},目标排={},目标列={},目标层={}",wrkMast.getWrkNo().shortValue() |
| | |
| | | ledCommand.setStaNo(wrkMast.getStaNo()); |
| | | ledCommand.setBarcode(wrkMast.getBarcode()); |
| | | if (wrkMast.getIoType() != 110 && wrkMast.getIoType() != 10) { |
| | | List<WrkDetl> wrkDetls = wrkDetlService.findByWorkNo(wrkMast.getWrkNo()); |
| | | |
| | | wrkDetls.forEach(wrkDetl -> { |
| | | Double total = 0.0; |
| | | EntityWrapper<LocDetl> wrapper = new EntityWrapper<>(); |
| | | LocDetl locDetl = locDetlService.selectOne(wrapper.eq("zpallet", wrkDetl.getZpallet()).eq("matnr", wrkDetl.getMatnr())); |
| | | if (Cools.isEmpty(locDetl)) { |
| | | total = wrkDetl.getAnfme(); |
| | | } else { |
| | | total = locDetl.getAnfme(); |
| | | } |
| | | if (wrkMast.getIoType() == 101 || wrkMast.getIoType() == 1) { |
| | | ledCommand.getMatDtos().add(new MatDto(wrkDetl.getMatnr(), wrkDetl.getMaktx(), wrkDetl.getBatch(), wrkDetl.getSpecs(), wrkDetl.getManu(), wrkDetl.getMemo(), wrkDetl.getAnfme(),total)); |
| | | } |
| | | if (wrkMast.getIoType() == 103 && (null == wrkDetl.getInspect() || 0 == wrkDetl.getInspect())) { |
| | | ledCommand.getMatDtos().add(new MatDto(wrkDetl.getMatnr(), wrkDetl.getMaktx(), wrkDetl.getBatch(), wrkDetl.getSpecs(), wrkDetl.getManu(), wrkDetl.getMemo(), wrkDetl.getAnfme(),total)); |
| | | } |
| | | if (wrkMast.getIoType() == 107) { |
| | | ledCommand.getMatDtos().add(new MatDto(wrkDetl.getMatnr(), wrkDetl.getMaktx(), wrkDetl.getBatch(), wrkDetl.getSpecs(), wrkDetl.getManu(), wrkDetl.getMemo(), wrkDetl.getAnfme(),total)); |
| | | } |
| | | }); |
| | | List<WrkDetl> wrkDetls = wrkDetlService.selectList(new EntityWrapper<WrkDetl>().eq("wrk_no", wrkMast.getWrkNo())); |
| | | // List<WrkDetl> wrkDetls = wrkDetlService.findByWorkNo(wrkMast.getWrkNo()); |
| | | wrkDetls.forEach(wrkDetl -> ledCommand.getMatDtos().add(new MatDto(wrkDetl.getMatnr(), wrkDetl.getBatch(), wrkDetl.getSpecs(),wrkDetl.getManuDate(),wrkDetl.getModel(),wrkDetl.getWeight(),wrkDetl.getLength(),wrkDetl.getVolume()))); |
| | | // wrkDetls.forEach(wrkDetl -> { |
| | | // Double total = 0.0; |
| | | // EntityWrapper<LocDetl> wrapper = new EntityWrapper<>(); |
| | | // LocDetl locDetl = locDetlService.selectOne(wrapper.eq("zpallet", wrkDetl.getZpallet()).eq("matnr", wrkDetl.getMatnr())); |
| | | // if (Cools.isEmpty(locDetl)) { |
| | | // total = wrkDetl.getAnfme(); |
| | | // } else { |
| | | // total = locDetl.getAnfme(); |
| | | // } |
| | | // if (wrkMast.getIoType() == 101 || wrkMast.getIoType() == 1) { |
| | | // ledCommand.getMatDtos().add(new MatDto(wrkDetl.getMatnr(), wrkDetl.getMaktx(), wrkDetl.getBatch(), wrkDetl.getSpecs(), wrkDetl.getManu(), wrkDetl.getMemo(), wrkDetl.getAnfme(),total)); |
| | | // } |
| | | // if (wrkMast.getIoType() == 103 && (null == wrkDetl.getInspect() || 0 == wrkDetl.getInspect())) { |
| | | // ledCommand.getMatDtos().add(new MatDto(wrkDetl.getMatnr(), wrkDetl.getMaktx(), wrkDetl.getBatch(), wrkDetl.getSpecs(), wrkDetl.getManu(), wrkDetl.getMemo(), wrkDetl.getAnfme(),total)); |
| | | // } |
| | | // if (wrkMast.getIoType() == 107) { |
| | | // ledCommand.getMatDtos().add(new MatDto(wrkDetl.getMatnr(), wrkDetl.getMaktx(), wrkDetl.getBatch(), wrkDetl.getSpecs(), wrkDetl.getManu(), wrkDetl.getMemo(), wrkDetl.getAnfme(),total)); |
| | | // } |
| | | // }); |
| | | } |
| | | commands.add(ledCommand); |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 判断106站点状态,有物+有任务号,则生成移库任务 |
| | | */ |
| | | public synchronized void generateOutbound() { |
| | | WrkMast wrkMast = wrkMastMapper.selectBy104(); |
| | | if (wrkMast == null) { |
| | | return; |
| | | } |
| | | BasCrnp basCrnp = basCrnpService.selectById(1); |
| | | if (!basCrnp.getInEnable().equals("Y") && !basCrnp.getOutEnable().equals("Y")) { |
| | | return; |
| | | } |
| | | CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, 1); |
| | | CrnProtocol crnProtocol = crnThread.getCrnProtocol(); |
| | | if (crnProtocol == null) { |
| | | return; |
| | | } |
| | | // 堆垛机控制过滤 |
| | | if (!crnProtocol.getStatusType().equals(CrnStatusType.IDLE) || crnProtocol.getTaskNo() != 0) { |
| | | return; |
| | | } |
| | | |
| | | // 已经存在吊车执行任务时,则过滤 |
| | | if (wrkMastMapper.selectWorking(1) != null) { |
| | | return; |
| | | } |
| | | |
| | | LocMast sourceSta = locMastService.selectById(wrkMast.getSourceLocNo()); |
| | | // 1.堆垛机开始移动 |
| | | CrnCommand crnCommand = new CrnCommand(); |
| | | crnCommand.setCrnNo(1); // 堆垛机编号 |
| | | crnCommand.setTaskNo(wrkMast.getWrkNo().shortValue()); // 工作号 |
| | | // crnCommand.setAckFinish((short) 0); // 任务完成确认位 |
| | | crnCommand.setTaskMode(CrnTaskModeType.LOC_MOVE); // 任务模式: 库位移转 |
| | | crnCommand.setSourcePosX(sourceSta.getRow1().shortValue()); // 源库位排 |
| | | crnCommand.setSourcePosY(sourceSta.getBay1().shortValue()); // 源库位列 |
| | | crnCommand.setSourcePosZ(sourceSta.getLev1().shortValue()); // 源库位层 |
| | | crnCommand.setDestinationPosX((short) 3); // 目标库位排 |
| | | crnCommand.setDestinationPosY((short) 3); // 目标库位列 |
| | | crnCommand.setDestinationPosZ((short) 1); // 目标库位层 |
| | | crnCommand.setTraySize(sourceSta.getLocType1() == 2); //库位类型 |
| | | if (!MessageQueue.offer(SlaveType.Crn, wrkMast.getCrnNo(), new Task(2, crnCommand))) { |
| | | News.error("到106站点堆垛机命令下发失败,堆垛机号={},任务数据={}", wrkMast.getCrnNo(), JSON.toJSON(crnCommand)); |
| | | } else { |
| | | // 修改工作档状态 11.生成出库ID => 12.吊车出库中 |
| | | Date now = new Date(); |
| | | wrkMast.setWrkSts(12L); |
| | | wrkMast.setCrnStrTime(now); |
| | | wrkMast.setModiTime(now); |
| | | if (wrkMastMapper.updateById(wrkMast) == 0) { |
| | | News.error("到106站点修改工作档状态 11.生成出库ID => 12.吊车出库中 失败!!,工作号={}", wrkMast.getWrkNo()); |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | public synchronized void autoMoveLoc() { |
| | | WrkMast wrkMast = wrkMastService.selectOne(new EntityWrapper<WrkMast>().eq("wrk_sts", 16L)); |
| | | |
| | | // 判断源站点情况 有任务号,有物,自动 |
| | | SiemensDevpThread devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, 1); |
| | | StaProtocol staProtocol106 = devpThread.getStation().get(106); |
| | | if (staProtocol106 == null) { |
| | | return; |
| | | } else { |
| | | staProtocol106 = staProtocol106.clone(); |
| | | } |
| | | // if (staProtocol105 == null) { |
| | | // return; |
| | | // } else { |
| | | // staProtocol105 = staProtocol105.clone(); |
| | | // } |
| | | |
| | | |
| | | // 判断出库站点情况 |
| | | |
| | | |
| | | // 获取堆垛机信息 并 判断是否可入出 |
| | | CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, 1); |
| | | CrnProtocol crnProtocol = crnThread.getCrnProtocol(); |
| | | if (crnProtocol == null) { |
| | | return; |
| | | } |
| | | BasCrnp basCrnp = basCrnpService.selectById(1); |
| | | if (!basCrnp.getInEnable().equals("Y") && !basCrnp.getOutEnable().equals("Y")) { |
| | | return; |
| | | } |
| | | |
| | | // 堆垛机控制过滤 |
| | | if (!crnProtocol.getStatusType().equals(CrnStatusType.IDLE) || crnProtocol.getTaskNo() != 0) { |
| | | return; |
| | | } |
| | | |
| | | // 已经存在吊车执行任务时,则过滤 |
| | | if (wrkMastMapper.selectWorking(1) != null) { |
| | | return; |
| | | } |
| | | // 命令下发区 -------------------------------------------------------------------------- |
| | | CrnCommand crnCommand = new CrnCommand(); |
| | | crnCommand.setCrnNo(1); // 堆垛机编号 |
| | | crnCommand.setTaskNo(wrkMast.getWrkNo().shortValue()); // 工作号 |
| | | crnCommand.setAckFinish((short) 0); // 任务完成确认位 |
| | | crnCommand.setTaskMode(CrnTaskModeType.LOC_MOVE); // 任务模式: 库位移转 |
| | | crnCommand.setSourcePosX((short) 3); // 源库位排 |
| | | crnCommand.setSourcePosY((short) 28); // 源库位列 |
| | | crnCommand.setSourcePosZ((short) 1); // 源库位层 |
| | | crnCommand.setDestinationPosX((short) 2); // 目标库位排 |
| | | crnCommand.setDestinationPosY((short) 28); // 目标库位列 |
| | | crnCommand.setDestinationPosZ((short) 1); // 目标库位层 |
| | | if(wrkMast.getStaNo() == 104) { // 目标站104,出到105位置 |
| | | crnCommand.setDestinationPosX((short) 2); // 目标库位排 |
| | | crnCommand.setDestinationPosY((short) 4); // 目标库位列 |
| | | crnCommand.setDestinationPosZ((short) 1); // 目标库位层 |
| | | } |
| | | crnCommand.setTraySize(true); //库位类型 |
| | | if (!MessageQueue.offer(SlaveType.Crn, wrkMast.getCrnNo(), new Task(2, crnCommand))) { |
| | | News.error("106移库1号堆垛机命令下发失败,堆垛机号={},任务数据={}", wrkMast.getCrnNo(), JSON.toJSON(crnCommand)); |
| | | } |
| | | // else { |
| | | // wrkMast.setCrnNo(2); |
| | | // wrkMastMapper.updateById(wrkMast); |
| | | // } |
| | | News.infoNoLog("106移库2号堆垛机入出库作业下发:库位移转完成"); |
| | | } |
| | | } |