| | |
| | | package com.zy.asrs.service.impl; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.core.common.Cools; |
| | | import com.core.common.R; |
| | |
| | | import com.zy.asrs.domain.enums.WorkNoType; |
| | | import com.zy.asrs.domain.param.CrnOperatorParam; |
| | | import com.zy.asrs.entity.*; |
| | | import com.zy.asrs.entity.param.TaskOverToWms; |
| | | import com.zy.asrs.entity.wms.StorageEscalationParam; |
| | | import com.zy.asrs.entity.wms.WmsResult; |
| | | import com.zy.asrs.mapper.BasCrnErrorMapper; |
| | |
| | | import com.zy.asrs.utils.CommandUtils; |
| | | import com.zy.asrs.utils.Utils; |
| | | import com.zy.common.service.CommonService; |
| | | import com.zy.common.utils.HttpHandler; |
| | | import com.zy.core.CrnThread; |
| | | import com.zy.core.DevpThread; |
| | | import com.zy.core.cache.MessageQueue; |
| | |
| | | import com.zy.core.properties.SlaveProperties; |
| | | import com.zy.core.thread.BarcodeThread; |
| | | import com.zy.core.thread.SiemensDevpThread; |
| | | import com.zy.system.entity.Config; |
| | | import com.zy.system.service.ConfigService; |
| | | 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.io.IOException; |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * 立体仓库WCS系统主流程业务 |
| | |
| | | private TaskWrkMapper taskWrkMapper; |
| | | @Autowired |
| | | private TaskWrkService taskWrkService; |
| | | @Autowired |
| | | private ConfigService configService; |
| | | |
| | | @Autowired |
| | | private StaDescMapper staDescMapper; |
| | | @Autowired |
| | | private CommandInfoService commandInfoService; |
| | | |
| | | |
| | | @Autowired |
| | | private StaDescService staDescService; |
| | | |
| | | @Autowired |
| | | private ApiLogService apiLogService; |
| | | |
| | | @Autowired |
| | | private CommonService commonService; |
| | | |
| | | @Autowired |
| | | private ToWmsService toWmsService; |
| | | |
| | | @Value("${wms.url}") |
| | | private String wmsUrl; |
| | | |
| | | @Value("${wms.inboundTaskApplyPath}") |
| | | private String inboundTaskApplyPath; |
| | | |
| | | @Value("${wms.taskExecCallback}") |
| | | private String taskExecCallback; |
| | | |
| | | @Value("${wms.taskStatusFeedbackPath}") |
| | | private String taskStatusFeedbackPath; |
| | | |
| | | @Autowired |
| | | private CrnController crnController; |
| | | |
| | | @Value("${wms.code}") |
| | | private String code; |
| | | |
| | | @Value("${wms.successCode}") |
| | | private String successCode; |
| | | |
| | | @Value("${wms.msg}") |
| | | private String msg; |
| | | |
| | | @Value("${wms.data}") |
| | | private String data; |
| | | |
| | | @Autowired |
| | | private ConfigService configService; |
| | | |
| | | public void generateStoreWrkFile1() throws IOException, InterruptedException { |
| | | try { |
| | |
| | | } |
| | | log.info("组托入库={}", storageEscalationParam); |
| | | storageEscalationParam.setBarcode(BoxNo); |
| | | String response = ""; |
| | | Boolean success = false; |
| | | try { |
| | | WmsResult result = toWmsService.getLocNoFromWms(storageEscalationParam); |
| | | if (back) { |
| | | staProtocol.setStaNo(inSta.getBackSta().shortValue()); |
| | | devpThread.setPakMk(staProtocol.getSiteId(), false); |
| | | MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol)); |
| | | } else { |
| | | if (result != null) { |
| | | |
| | | |
| | | |
| | | // 创新一个入库工作档 |
| | | TaskWrk taskWrk = taskWrkService.selectByTaskNo(result.getTaskNo()); |
| | | if (Cools.isEmpty(taskWrk)) { |
| | | taskWrk = createInTask(result, BoxNo, inSta.getStaNo()); |
| | | if (Cools.isEmpty(taskWrk)) { |
| | | log.error("库位异常,库位号:={}", taskWrk.getOriginTargetPoint()); |
| | | } else { |
| | | taskWrkService.insert(taskWrk); |
| | | StaDesc staDesc = staDescService.selectOne(new EntityWrapper<StaDesc>() |
| | | .eq("crn_no", taskWrk.getCrnNo()).eq("type_no", 1).eq("stn_no", staProtocol.getSiteId())); |
| | | staProtocol.setWorkNo(taskWrk.getWrkNo().shortValue()); |
| | | staProtocol.setStaNo(staDesc.getCrnStn().shortValue()); |
| | | MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol)); |
| | | HashMap<String, Object> hashMap = new HashMap<>(); |
| | | hashMap.put("TaskNo", taskWrk.getTaskNo()); |
| | | try { |
| | | //开始上报,任务开始时,WCS回调WMS |
| | | response = new HttpHandler.Builder() |
| | | .setUri(wmsUrl) |
| | | .setPath(taskStatusFeedbackPath) |
| | | .setJson(JSON.toJSONString(hashMap)) |
| | | .build() |
| | | .doPost(); |
| | | JSONObject jsonObject1 = JSON.parseObject(response); |
| | | Boolean bool = false; |
| | | if (jsonObject1.get("ReturnStatus").equals(0)) { |
| | | bool = true; |
| | | } |
| | | apiLogService.save("wcs开始入库任务上报wms" |
| | | , wmsUrl + taskExecCallback |
| | | , null |
| | | , "127.0.0.1" |
| | | , JSON.toJSONString(hashMap) |
| | | , response |
| | | , bool |
| | | ); |
| | | } catch (Exception e) { |
| | | |
| | | } |
| | | } |
| | | } else { |
| | | staProtocol.setStaNo(inSta.getBackSta().shortValue()); |
| | | devpThread.setPakMk(staProtocol.getSiteId(), false); |
| | | MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol)); |
| | | } |
| | | |
| | | WmsResult result = toWmsService.getLocNoFromWms(storageEscalationParam); |
| | | if (back) { |
| | | log.info("托盘退回==>{},{}", BoxNo, errMsg); |
| | | staProtocol.setStaNo(inSta.getBackSta().shortValue()); |
| | | devpThread.setPakMk(staProtocol.getSiteId(), false); |
| | | MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol)); |
| | | } else { |
| | | if (result != null) { |
| | | // 创新一个入库工作档 |
| | | TaskWrk taskWrk = taskWrkService.selectByTaskNo(result.getTaskNo()); |
| | | if (Cools.isEmpty(taskWrk)) { |
| | | taskWrk = createInTask(result, BoxNo, inSta.getStaNo()); |
| | | taskWrkService.insert(taskWrk); |
| | | StaDesc staDesc = staDescService.selectOne(new EntityWrapper<StaDesc>() |
| | | .eq("crn_no", taskWrk.getCrnNo()).eq("type_no", 1).eq("stn_no", staProtocol.getSiteId())); |
| | | staProtocol.setWorkNo(taskWrk.getWrkNo().shortValue()); |
| | | staProtocol.setStaNo(staDesc.getCrnStn().shortValue()); |
| | | MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol)); |
| | | //添加上报日志 |
| | | toWmsService.addReportLog(taskWrk); |
| | | } else { |
| | | log.info("创建工作档失败==>{}", taskWrk.getTaskNo()); |
| | | staProtocol.setStaNo(inSta.getBackSta().shortValue()); |
| | | devpThread.setPakMk(staProtocol.getSiteId(), false); |
| | | MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol)); |
| | | } |
| | | } else { |
| | | log.info("请求wms获取库位失败==>{}", BoxNo); |
| | | staProtocol.setStaNo(inSta.getBackSta().shortValue()); |
| | | devpThread.setPakMk(staProtocol.getSiteId(), false); |
| | | MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol)); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("请求入库调用接口失败"); |
| | | log.error("异常信息打印:" + e); |
| | | try { |
| | | BasDevp basDevp = basDevpService.selectById(inSta.getStaNo()); |
| | | if (Cools.isEmpty(basDevp)) { |
| | | log.error("站点号异常" + inSta.getStaNo()); |
| | | } else if (basDevp.getStaErr() != 0) { |
| | | basDevp.setStaErr(2); |
| | | basDevpService.updateById(basDevp); |
| | | } |
| | | } catch (Exception e1) { |
| | | // 退回 |
| | | log.error("扫码检测程序异常" + inSta.getStaNo() + "异常信息" + e1); |
| | | } |
| | | } finally { |
| | | apiLogService.save("wms请求入库货位接口" |
| | | , wmsUrl + inboundTaskApplyPath |
| | | , null |
| | | , "127.0.0.1" |
| | | , JSON.toJSONString(storageEscalationParam) |
| | | , response |
| | | , success |
| | | ); |
| | | } |
| | | log.info("入库请求参数=" + JSON.toJSONString(BoxNo)); |
| | | log.info("入库请求返回参数=" + JSON.toJSONString(response)); |
| | | log.info("入库请求返回参数=" + JSON.toJSONString(result)); |
| | | } |
| | | } |
| | | } |
| | |
| | | crnProtocol.setLastIo("O"); |
| | | } |
| | | } |
| | | |
| | | // 库位移转 |
| | | this.locToLoc(crn, crnProtocol); |
| | | } |
| | |
| | | command.setCommand((short) 1); |
| | | |
| | | if (Cools.isEmpty(taskWrk.getMarkStart()) || taskWrk.getMarkStart() == 0) { |
| | | HashMap<String, Object> hashMap = new HashMap<>(); |
| | | hashMap.put("TaskNo", taskWrk.getTaskNo()); |
| | | String response = ""; |
| | | try { |
| | | //开始上报,出库任务开始时,WCS回调WMS |
| | | response = new HttpHandler.Builder() |
| | | .setUri(wmsUrl) |
| | | .setPath(taskStatusFeedbackPath) |
| | | .setJson(JSON.toJSONString(hashMap)) |
| | | .build() |
| | | .doPost(); |
| | | JSONObject jsonObject = JSON.parseObject(response); |
| | | Boolean bool = false; |
| | | if (jsonObject.get(code).equals(0)) { |
| | | bool = true; |
| | | taskWrk.setMarkStart(1); |
| | | } |
| | | apiLogService.save("wcs开始任务上报wms" |
| | | , wmsUrl + TaskExecCallback |
| | | , null |
| | | , "127.0.0.1" |
| | | , JSON.toJSONString(hashMap) |
| | | , response |
| | | , bool |
| | | ); |
| | | } catch (Exception e) { |
| | | } |
| | | toWmsService.addReportLog(taskWrk); |
| | | taskWrk.setMarkStart(1); |
| | | } |
| | | |
| | | if (!CommandUtils.offer(SlaveType.Crn, taskWrk.getCrnNo(), new Task(2, command), false)) { |
| | |
| | | log.error("修改工作档状态 11.生成出库ID => 12.吊车出库中 失败!!,工作号={}", taskWrk.getWrkNo()); |
| | | log.error("修改工作档状态 11.生成出库ID => 12.吊车出库中 失败!!,异常:" + e); |
| | | } |
| | | // try { |
| | | // HashMap<String, Object> headParam = new HashMap<>(); |
| | | // headParam.put("taskNo", taskWrk.getTaskNo()); |
| | | // headParam.put("status", taskWrk.getStatus()); |
| | | // headParam.put("ioType", taskWrk.getIoType()); |
| | | // headParam.put("barcode", taskWrk.getBarcode()); |
| | | // String response; |
| | | // response = new HttpHandler.Builder() |
| | | // // .setHeaders(headParam) |
| | | // .setUri(wmsUrl) |
| | | // .setPath(taskStatusFeedbackPath) |
| | | // .setJson(JSON.toJSONString(headParam)) |
| | | // .build() |
| | | // .doPost(); |
| | | // JSONObject jsonObject = JSON.parseObject(response); |
| | | // apiLogService.save("wcs派发出库任务上报wms" |
| | | // , wmsUrl + taskStatusFeedbackPath |
| | | // , null |
| | | // , "127.0.0.1" |
| | | // , JSON.toJSONString(headParam) |
| | | // , response |
| | | // , true |
| | | // ); |
| | | // } catch (Exception e) { |
| | | // log.error("wcs派发出库任务上报wms失败", JSON.toJSONString(taskWrk)); |
| | | //// throw new CoolException("wcs派发入库任务上报wms失败"); |
| | | // } |
| | | } |
| | | } |
| | | } |
| | |
| | | if (taskWrkMapper.updateById(taskWrk) == 0) { |
| | | log.error("修改工作档状态 11.生成出库ID => 12.吊车出库中 失败!!,工作号={}", taskWrk.getWrkNo()); |
| | | } |
| | | try { |
| | | HashMap<String, Object> headParam = new HashMap<>(); |
| | | headParam.put("taskNo", taskWrk.getTaskNo()); |
| | | String response; |
| | | response = new HttpHandler.Builder() |
| | | // .setHeaders(headParam) |
| | | .setUri(wmsUrl) |
| | | .setPath(taskStatusFeedbackPath) |
| | | .setJson(JSON.toJSONString(headParam)) |
| | | .build() |
| | | .doPost(); |
| | | JSONObject jsonObject = JSON.parseObject(response); |
| | | apiLogService.save("wcs派发移库任务上报wms" |
| | | , wmsUrl + taskStatusFeedbackPath |
| | | , null |
| | | , "127.0.0.1" |
| | | , JSON.toJSONString(headParam) |
| | | , response |
| | | , true |
| | | ); |
| | | } catch (Exception e) { |
| | | log.error("wcs派发移库库任务上报wms失败", taskWrk); |
| | | // throw new CoolException("wcs派发移库库任务上报wms失败"); |
| | | } |
| | | |
| | | toWmsService.addReportLog(taskWrk); |
| | | } |
| | | return; |
| | | } |
| | |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 执行对工作档的完成操作 |
| | | */ |
| | | // public void storeFinished() { |
| | | // for (CrnSlave crn : slaveProperties.getCrn()) { |
| | | // // 获取堆垛机信息 |
| | | // CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, crn.getId()); |
| | | // CrnProtocol crnProtocol = crnThread.getCrnProtocol(); |
| | | // if (crnProtocol == null) { continue; } |
| | | // |
| | | // // 状态:等待确认 并且 任务完成位 = 1 |
| | | // if (crnProtocol.getTaskFinish() == 0 && crnProtocol.statusType == CrnStatusType.HANDLING_COMPLETED && crnProtocol.getTaskNo() != 0) { |
| | | // //获取入库待确认工作档 |
| | | // TaskWrk taskWrk = taskWrkMapper.selectCrnNoInWorking(crn.getId(),crnProtocol.getTaskNo().intValue()); |
| | | // if (Cools.isEmpty(taskWrk)) { |
| | | //// log.error("堆垛机处于等待确认且任务完成状态,但未找到工作档。堆垛机号={},工作号={}", crn.getId(), crnProtocol.getTaskNo()); |
| | | // continue; |
| | | // } |
| | | // |
| | | // //获取指令ID |
| | | // Integer commandId = crnProtocol.getCommandId(); |
| | | // CommandInfo commandInfo = new CommandInfo(); |
| | | // if (Cools.isEmpty(commandId)){ |
| | | // commandInfo = commandInfoService.selectOne(new EntityWrapper<CommandInfo>() |
| | | // .eq("wrk_no",crnProtocol.getTaskNo()) |
| | | // .eq("device","Crn")); |
| | | // }else { |
| | | // commandInfo = commandInfoService.selectById(commandId); |
| | | // } |
| | | // |
| | | // |
| | | // if (commandInfo == null) { |
| | | // //指令不存在 |
| | | // continue; |
| | | // } |
| | | // if (commandInfo.getCommandStatus() == 3){ |
| | | // continue; |
| | | // } |
| | | // commandInfo.setCommandStatus(CommandStatusType.COMPLETE.id);//指令完成 |
| | | // commandInfo.setCompleteTime(new Date());//指令完成时间 |
| | | // if (commandInfoService.updateById(commandInfo)) {//修改成功后复位堆垛机 |
| | | // // 堆垛机复位 |
| | | // crnThread.setResetFlag(true); |
| | | // } |
| | | // } |
| | | // } |
| | | // } |
| | | |
| | | /** |
| | | * 执行对工作档的完成操作 |
| | |
| | | } |
| | | } |
| | | |
| | | //自动派发任务 |
| | | public void autoDistribute() { |
| | | Config config = configService.selectByCode("autoDistribute"); |
| | | if (config == null) { |
| | | return; |
| | | } |
| | | |
| | | if (config.getValue().equals("false")) {//判断是否开启自动派发任务 |
| | | return; |
| | | } |
| | | |
| | | for (TaskWrk taskWrk : taskWrkService.selectReceive()) { |
| | | |
| | | try { |
| | | taskWrkService.distribute(taskWrk.getTaskNo(), 9527L); |
| | | } catch (CoolException e) { |
| | | log.info(e.getMessage()); |
| | | } |
| | | } |
| | | } |
| | | |
| | | //agv取放货任务完成 |
| | | public synchronized void autoCompleteAGV() { |
| | |
| | | } |
| | | } |
| | | |
| | | public synchronized void autoCompleteTask() { |
| | | List<TaskWrk> taskWrks = taskWrkMapper.selectWorkingTask(); |
| | | for (TaskWrk taskWrk : taskWrks) { |
| | | //获取命令集合 |
| | | List<CommandInfo> commandInfos = commandInfoService.selectByTaskNo(taskWrk.getTaskNo()); |
| | | if (taskWrk.getCommandStep() < commandInfos.size()) { |
| | | continue;//当前步序没有到达最后一条命令 |
| | | } |
| | | |
| | | //判断末端命令是否执行完成 |
| | | CommandInfo commandInfo = commandInfos.get(commandInfos.size() - 1); |
| | | if (commandInfo.getCommandStatus() != CommandStatusType.COMPLETE.id) { |
| | | continue;//指令未完成 |
| | | } |
| | | |
| | | Date now = new Date(); |
| | | //指令已完成,更新任务 |
| | | if (taskWrk.getIoType() == 1) { |
| | | //入库任务 |
| | | taskWrk.setWrkSts(4);//3.吊车入库中 => 4.入库完成 |
| | | //taskWrk.setStatus(TaskStatusType.COMPLETE.id); |
| | | taskWrk.setModiTime(now); |
| | | taskWrkService.updateById(taskWrk); |
| | | |
| | | //更新库位状态 |
| | | LocMast locMast = locMastService.selectByLocNo(taskWrk.getTargetPoint()); |
| | | locMast.setLocSts("F");//F.在库 |
| | | locMast.setBarcode(taskWrk.getBarcode());//托盘码 |
| | | locMast.setModiTime(now); |
| | | locMast.setModiUser(9999L); |
| | | locMastService.updateById(locMast); |
| | | } else if (taskWrk.getIoType() == 2) { |
| | | //出库任务 |
| | | taskWrk.setWrkSts(14);//12.吊车出库中 => 14.出库完成 |
| | | // taskWrk.setStatus(TaskStatusType.COMPLETE.id); |
| | | taskWrk.setModiTime(now); |
| | | taskWrkService.updateById(taskWrk); |
| | | |
| | | //更新库位状态 |
| | | LocMast locMast = locMastService.selectByLocNo(taskWrk.getStartPoint()); |
| | | locMast.setLocSts("O");//O.空库位 |
| | | locMast.setBarcode("");//托盘码 |
| | | locMast.setModiTime(now); |
| | | locMast.setModiUser(9999L); |
| | | locMastService.updateById(locMast); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | public synchronized String CrnStartRunning(TaskWrk taskWrk) { |
| | | String tasktype = null; |
| | | switch (taskWrk.getIoType()) { |
| | | case 1: |
| | | tasktype = "RK"; |
| | | break; |
| | | case 2: |
| | | tasktype = "CK"; |
| | | break; |
| | | case 3: |
| | | tasktype = "YK"; |
| | | break; |
| | | default: |
| | | tasktype = "未知"; |
| | | } |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("x-api-key", "7a15b5db-29b6-552c-8cff-0cfec3756da2"); |
| | | TaskOverToWms taskOverToWms = new TaskOverToWms(); |
| | | taskOverToWms.setFeedbackFrom("WCS"); //来源 |
| | | taskOverToWms.setWarehouseId("1688469798893297665"); //仓库标识 |
| | | taskOverToWms.setTaskNo(taskWrk.getTaskNo()); //任务号 |
| | | taskOverToWms.setTaskType(tasktype); // 任务类型 |
| | | taskOverToWms.setContainerCode(taskWrk.getBarcode()); // 容器编码 |
| | | if (taskWrk.getIoType() == 1 || taskWrk.getIoType() == 3) { |
| | | taskOverToWms.setEquipmentCode(String.valueOf(taskWrk.getCrnNo())); //设备编码 |
| | | taskOverToWms.setTargetLocationCode(taskWrk.getOriginTargetPoint()); //目标库位 |
| | | } else if (taskWrk.getIoType() == 2) { |
| | | Map<Integer, String> map1 = new HashMap<>(); |
| | | map1.put(102, "J-1101"); |
| | | map1.put(106, "J-1103"); |
| | | map1.put(110, "J-1105"); |
| | | map1.put(114, "J-1107"); |
| | | map1.put(118, "J-1109"); |
| | | map1.put(122, "J-1111"); |
| | | map1.put(305, "H-1101"); |
| | | map1.put(405, "G-1101"); |
| | | taskOverToWms.setEquipmentCode(map1.get(taskWrk.getTargetPoint())); //设备编码 |
| | | taskOverToWms.setSourceLocationCode(taskWrk.getOriginStartPoint()); //源库位 |
| | | } |
| | | |
| | | taskOverToWms.setTaskStatus("executing"); //任务状态 |
| | | String response = null; |
| | | try { |
| | | response = new HttpHandler.Builder() |
| | | .setHeaders(map) |
| | | .setUri(wmsUrl) |
| | | .setPath("wcsManager/wcsInterface/taskStatusFeedback") |
| | | .setJson(JSON.toJSONString(taskOverToWms)) |
| | | .build() |
| | | .doPost(); |
| | | } catch (Exception e) { |
| | | log.error("堆垛机任务完成,请求wms任务完成接口失败"); |
| | | } |
| | | apiLogService.save("堆垛机开始运行" |
| | | , wmsUrl + "wcsManager/wcsInterface/taskStatusFeedback" |
| | | , null |
| | | , "127.0.0.1" |
| | | , JSON.toJSONString(taskOverToWms) |
| | | , response |
| | | , true |
| | | ); |
| | | return response; |
| | | } |
| | | |
| | | private TaskWrk createInTask(WmsResult result, String barcode, Integer startPoint) { |
| | | //String locNo = Utils.Fusion(result.getRow(), result.getFloor(), result.getColumn()); |