| | |
| | | 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.core.exception.CoolException; |
| | | import com.zy.asrs.controller.CrnController; |
| | | import com.zy.asrs.controller.OpenController; |
| | | import com.zy.asrs.controller.SiteController; |
| | | import com.zy.asrs.domain.enums.TaskStatusType; |
| | | 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.Result; |
| | | import com.zy.asrs.entity.param.StorageEscalationParam; |
| | | import com.zy.asrs.entity.param.TaskOverToWms; |
| | | import com.zy.asrs.entity.param.GenerateAgvTaskParam; |
| | | import com.zy.asrs.mapper.*; |
| | | import com.zy.asrs.service.*; |
| | | 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.cache.SlaveConnection; |
| | | import com.zy.core.enums.*; |
| | | import com.zy.core.model.CrnSlave; |
| | | import com.zy.core.model.DevpSlave; |
| | | import com.zy.core.model.Task; |
| | | import com.zy.core.model.command.CommandPackage; |
| | | import com.zy.core.model.command.CrnCommand; |
| | | import com.zy.core.model.protocol.CrnProtocol; |
| | | import com.zy.core.model.protocol.StaProtocol; |
| | | 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 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.*; |
| | | |
| | | /** |
| | | * 立体仓库WCS系统主流程业务 |
| | | * Created by vincent on 2020/8/6 |
| | | */ |
| | | @Slf4j |
| | | @Service("mainService") |
| | |
| | | @Autowired |
| | | private SlaveProperties slaveProperties; |
| | | @Autowired |
| | | private WrkMastMapper wrkMastMapper; |
| | | @Autowired |
| | | private LocMastService locMastService; |
| | | @Autowired |
| | | private BasCrnpService basCrnpService; |
| | | @Autowired |
| | | private BasDevpService basDevpService; |
| | | @Autowired |
| | | private BasErrLogService basErrLogService; |
| | | @Autowired |
| | | private BasCrnErrorMapper basCrnErrorMapper; |
| | | @Autowired |
| | | private TaskWrkMapper taskWrkMapper; |
| | | @Autowired |
| | |
| | | private StaDescMapper staDescMapper; |
| | | @Autowired |
| | | private CommandInfoService commandInfoService; |
| | | |
| | | @Autowired |
| | | private OpenServiceImpl openServiceImpl; |
| | | @Autowired |
| | | private StaDescService staDescService; |
| | | |
| | | @Autowired |
| | | private ApiLogService apiLogService; |
| | | @Autowired |
| | | private OpenService openService; |
| | | @Autowired |
| | | private CommonService commonService; |
| | | |
| | | @Value("${wms.url}") |
| | | private String wmsUrl; |
| | | @Value("${wms.inboundTaskApplyPath}") |
| | | private String inboundTaskApplyPath; |
| | | @Value("${wms.TaskExecCallback}") |
| | | private String TaskExecCallback; |
| | | @Value("${wms.taskStatusFeedbackPath}") |
| | | private String taskStatusFeedbackPath; |
| | | |
| | | @Value("${wcs.urlWcs}") |
| | | private String wcsUrl; |
| | | @Value("${wcs.inboundTaskApplyPathWcs}") |
| | | private String wcsInboundTaskApplyPath; |
| | | @Autowired |
| | | private CrnController crnController; |
| | | @Autowired |
| | | private SiteController siteController; |
| | | |
| | | |
| | | public synchronized void generateStoreWrkFile1() throws IOException, InterruptedException { |
| | | try { |
| | | // 根据输送线plc遍历 |
| | | for (DevpSlave devp : slaveProperties.getDevp()) { |
| | | // 遍历入库口 |
| | | for (DevpSlave.Sta inSta : devp.getInSta()) { |
| | | StorageEscalationParam storageEscalationParam = new StorageEscalationParam(); |
| | | // 获取入库站信息 |
| | | 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(); |
| | | Short stano = staProtocol.getStaNo(); |
| | | |
| | | // 尺寸检测异常 |
| | | 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 (staProtocol.isAutoing() && staProtocol.isLoading() |
| | | && staProtocol.isInEnable() |
| | | && !staProtocol.isEmptyMk() && workNo >= 9790 |
| | | && staProtocol.isPakMk()) { |
| | | // 获取条码扫描仪信息 |
| | | BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, inSta.getBarcode()); |
| | | if (barcodeThread == null) { |
| | | continue; |
| | | } |
| | | String BoxNo = barcodeThread.getBarcode(); |
| | | TaskWrk taskWrk1 = taskWrkService.selectOne(new EntityWrapper<TaskWrk>().eq("barcode", BoxNo)); |
| | | if (!Cools.isEmpty(taskWrk1)) { |
| | | log.info("托盘码:" + BoxNo + "任务档存在"); |
| | | if (taskWrk1.getIoType() == 1 && taskWrk1.getStartPoint().equals(staProtocol.getSiteId().toString())) { |
| | | StaDesc staDesc = staDescService.selectOne(new EntityWrapper<StaDesc>() |
| | | .eq("crn_no", taskWrk1.getCrnNo()).eq("type_no", 1).eq("stn_no", staProtocol.getSiteId())); |
| | | if (Cools.isEmpty(staDesc)) { |
| | | return; |
| | | } else { |
| | | continue; |
| | | } |
| | | } |
| | | } |
| | | if (back) { |
| | | storageEscalationParam.setWCSStatus(1); |
| | | storageEscalationParam.setWCSErrorMessage(storageEscalationParam.getWCSErrorMessage() + errMsg); |
| | | } |
| | | log.info("组托入库={}", storageEscalationParam); |
| | | storageEscalationParam.setBoxNo(BoxNo); |
| | | String response = ""; |
| | | Boolean success = false; |
| | | try { |
| | | response = new HttpHandler.Builder() |
| | | .setUri(wmsUrl) |
| | | .setPath(inboundTaskApplyPath) |
| | | .setJson(JSON.toJSONString(storageEscalationParam)) |
| | | .build() |
| | | .doPost(); |
| | | JSONObject jsonObject = JSON.parseObject(response); |
| | | if (back) { |
| | | if (staProtocol.getWorkNo() >= 9801 && staProtocol.getWorkNo() <= 9825) { |
| | | staProtocol.setStaNo((short) 105); |
| | | } else if (staProtocol.getWorkNo() >= 9826 && staProtocol.getWorkNo() <= 9850) { |
| | | staProtocol.setStaNo((short) 107); |
| | | } else if (staProtocol.getWorkNo() >= 9851 && staProtocol.getWorkNo() <= 9875) { |
| | | staProtocol.setStaNo((short) 109); |
| | | } else { |
| | | staProtocol.setStaNo((short) 110); |
| | | } |
| | | devpThread.setPakMk(staProtocol.getSiteId(), false); |
| | | MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol)); |
| | | } else { |
| | | if (!Cools.isEmpty(response) && !Cools.isEmpty(jsonObject.get("ReturnStatus")) && jsonObject.get("ReturnStatus").equals(0) && !Cools.isEmpty(jsonObject.get("Result").toString())) { |
| | | Result result = JSON.parseObject(jsonObject.get("Result").toString(), Result.class); |
| | | // 创新一个入库工作档 |
| | | TaskWrk taskWrk = taskWrkService.selectByTaskNo(result.getTaskNo()); |
| | | if (Cools.isEmpty(taskWrk)) { |
| | | taskWrk = createTask1(result, BoxNo); |
| | | 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.setWorkNo((short) 9991); |
| | | if (staProtocol.getWorkNo() >= 9801 && staProtocol.getWorkNo() <= 9825) { |
| | | staProtocol.setStaNo((short) 105); |
| | | } else if (staProtocol.getWorkNo() >= 9826 && staProtocol.getWorkNo() <= 9850) { |
| | | staProtocol.setStaNo((short) 107); |
| | | } else if (staProtocol.getWorkNo() >= 9851 && staProtocol.getWorkNo() <= 9875) { |
| | | staProtocol.setStaNo((short) 109); |
| | | } else { |
| | | staProtocol.setStaNo((short) 110); |
| | | } |
| | | devpThread.setPakMk(staProtocol.getSiteId(), false); |
| | | MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol)); |
| | | } |
| | | |
| | | } else { |
| | | // staProtocol.setWorkNo((short) 9991); |
| | | 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)); |
| | | } |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("generateStoreWrkFile e", e); |
| | | TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); |
| | | public synchronized void demo() { |
| | | boolean demoEnable = false; |
| | | Config demoEnableConfig = configService.selectByCode("demoEnable"); |
| | | if(demoEnableConfig != null) { |
| | | demoEnable = Boolean.parseBoolean(demoEnableConfig.getValue()); |
| | | } |
| | | |
| | | if (!demoEnable) { |
| | | return; |
| | | } |
| | | |
| | | //演示模式-AGV出库 |
| | | demoAgvOut(); |
| | | //演示模式-AGV入库 |
| | | demoAgvIn(); |
| | | //演示模式-四向库出库 |
| | | demoShuttleOut(); |
| | | //演示模式-四向库入库 |
| | | demoShuttleIn(); |
| | | } |
| | | |
| | | //演示模式-AGV出库 |
| | | private synchronized void demoAgvOut() { |
| | | LocMast locMast = locMastService.selectByLocNo("1100601"); |
| | | if(locMast == null) { |
| | | return; |
| | | } |
| | | |
| | | if (!locMast.getLocSts().equals("O")) { |
| | | return; |
| | | } |
| | | |
| | | List<LocMast> locMasts = locMastService.selectList(new EntityWrapper<LocMast>() |
| | | .eq("mk", "agv") |
| | | .eq("loc_sts", "F") |
| | | .notIn("loc_no", "0900601") |
| | | ); |
| | | |
| | | if (locMasts.isEmpty()) { |
| | | return; |
| | | } |
| | | |
| | | LocMast originLocMast = locMasts.get(0); |
| | | |
| | | //生成AGV出库任务 |
| | | GenerateAgvTaskParam param = new GenerateAgvTaskParam(); |
| | | param.setOriginPoint(originLocMast.getLocNo()); |
| | | param.setTargetPoint(locMast.getLocNo()); |
| | | openService.generateAgvTask(param); |
| | | } |
| | | |
| | | //演示模式-AGV入库 |
| | | private synchronized void demoAgvIn() { |
| | | LocMast locMast = locMastService.selectByLocNo("0900601"); |
| | | if(locMast == null) { |
| | | return; |
| | | } |
| | | |
| | | if (!locMast.getLocSts().equals("F")) { |
| | | return; |
| | | } |
| | | |
| | | List<LocMast> locMasts = locMastService.selectList(new EntityWrapper<LocMast>() |
| | | .eq("mk", "agv") |
| | | .eq("loc_sts", "O") |
| | | .notIn("loc_no", "1100601") |
| | | ); |
| | | |
| | | if (locMasts.isEmpty()) { |
| | | return; |
| | | } |
| | | |
| | | LocMast targetLocMast = locMasts.get(0); |
| | | |
| | | //生成AGV出库任务 |
| | | GenerateAgvTaskParam param = new GenerateAgvTaskParam(); |
| | | param.setOriginPoint(locMast.getLocNo()); |
| | | param.setTargetPoint(targetLocMast.getLocNo()); |
| | | openService.generateAgvTask(param); |
| | | } |
| | | |
| | | //演示模式-四向库出库 |
| | | private synchronized void demoShuttleOut() { |
| | | LocMast locMast = locMastService.selectByLocNo("0900601"); |
| | | if(locMast == null) { |
| | | return; |
| | | } |
| | | |
| | | if (!locMast.getLocSts().equals("O")) { |
| | | return; |
| | | } |
| | | |
| | | ArrayList<Integer> disableLevList = new ArrayList<>(); |
| | | |
| | | //query in task |
| | | List<TaskWrk> taskWrks = taskWrkService.selectList(new EntityWrapper<TaskWrk>() |
| | | .eq("io_type", 1)); |
| | | for (TaskWrk taskWrk : taskWrks) { |
| | | int lev = Utils.getLev(taskWrk.getTargetPoint()); |
| | | if(!disableLevList.contains(lev)) { |
| | | disableLevList.add(lev); |
| | | } |
| | | } |
| | | |
| | | List<LocMast> locMasts = locMastService.selectList(new EntityWrapper<LocMast>() |
| | | .notIn("lev1", disableLevList) |
| | | .eq("loc_sts", "F") |
| | | ); |
| | | |
| | | if(locMasts.isEmpty()) { |
| | | return; |
| | | } |
| | | |
| | | LocMast locMast1 = locMasts.get(0); |
| | | |
| | | Date now = new Date(); |
| | | TaskWrk taskWrk = new TaskWrk(); |
| | | int workNo1 = commonService.getWorkNo(WorkNoType.PAKOUT.type);//获取入库工作号 |
| | | taskWrk.setTaskNo(String.valueOf(workNo1));//任务号 |
| | | taskWrk.setWrkNo(workNo1); |
| | | taskWrk.setStatus(TaskStatusType.RECEIVE.id);//任务状态:接收 |
| | | taskWrk.setCreateTime(now); |
| | | taskWrk.setIoType(1);//入库 |
| | | taskWrk.setIoPri(100);//优先级 |
| | | taskWrk.setOriginTargetPoint(locMast1.getLocNo()); |
| | | taskWrk.setTargetPoint("1");//终点 |
| | | boolean result = taskWrkService.insert(taskWrk); |
| | | |
| | | locMast1.setLocSts("R"); |
| | | locMast1.setModiTime(now); |
| | | locMastService.updateById(locMast1); |
| | | |
| | | locMast.setLocSts("S"); |
| | | locMast.setModiTime(now); |
| | | locMastService.updateById(locMast); |
| | | } |
| | | |
| | | //演示模式-四向库入库 |
| | | private synchronized void demoShuttleIn() { |
| | | LocMast locMast = locMastService.selectByLocNo("1100601"); |
| | | if(locMast == null) { |
| | | return; |
| | | } |
| | | |
| | | if (!locMast.getLocSts().equals("F")) { |
| | | return; |
| | | } |
| | | |
| | | ArrayList<Integer> disableLevList = new ArrayList<>(); |
| | | |
| | | //query out task |
| | | List<TaskWrk> taskWrks = taskWrkService.selectList(new EntityWrapper<TaskWrk>() |
| | | .eq("io_type", 2)); |
| | | for (TaskWrk taskWrk : taskWrks) { |
| | | int lev = Utils.getLev(taskWrk.getTargetPoint()); |
| | | if(!disableLevList.contains(lev)) { |
| | | disableLevList.add(lev); |
| | | } |
| | | } |
| | | |
| | | List<LocMast> locMasts = locMastService.selectList(new EntityWrapper<LocMast>() |
| | | .notIn("lev1", disableLevList) |
| | | .eq("loc_sts", "O") |
| | | ); |
| | | |
| | | if(locMasts.isEmpty()) { |
| | | return; |
| | | } |
| | | |
| | | LocMast locMast1 = locMasts.get(0); |
| | | |
| | | Date now = new Date(); |
| | | TaskWrk taskWrk = new TaskWrk(); |
| | | int workNo1 = commonService.getWorkNo(WorkNoType.PAKOUT.type);//获取入库工作号 |
| | | taskWrk.setTaskNo(String.valueOf(workNo1));//任务号 |
| | | taskWrk.setWrkNo(workNo1); |
| | | taskWrk.setStatus(TaskStatusType.RECEIVE.id);//任务状态:接收 |
| | | taskWrk.setCreateTime(now); |
| | | taskWrk.setIoType(1);//入库 |
| | | taskWrk.setIoPri(100);//优先级 |
| | | taskWrk.setOriginTargetPoint("101"); |
| | | taskWrk.setTargetPoint(locMast1.getLocNo());//终点 |
| | | boolean result = taskWrkService.insert(taskWrk); |
| | | |
| | | locMast1.setLocSts("S"); |
| | | locMast1.setModiTime(now); |
| | | locMastService.updateById(locMast1); |
| | | |
| | | locMast.setLocSts("R"); |
| | | locMast.setModiTime(now); |
| | | locMastService.updateById(locMast); |
| | | } |
| | | |
| | | /** |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 库位移转 |
| | | */ |
| | | public synchronized void locToLoc(CrnSlave slave, CrnProtocol crnProtocol) { |
| | | for (CrnSlave.CrnStn crnStn : slave.getCrnOutStn()) { |
| | | // 获取工作状态为11(生成出库ID)的移库工作档 |
| | | List<TaskWrk> taskWrks = taskWrkMapper.selectList(new EntityWrapper<TaskWrk>() |
| | | .eq("crn_no", slave.getId()) |
| | | .eq("wrk_sts", 11) |
| | | .eq("io_type", 3) |
| | | .orderBy("io_pri", false)); |
| | | for (TaskWrk taskWrk : taskWrks) { |
| | | |
| | | // 双深库位且浅库位有货,则需先对浅库位进行库位移转 |
| | | // if (Utils.isDeepLoc(slaveProperties, taskWrk.getStartPoint())) { |
| | | // String shallowLocNo = Utils.getShallowLoc(slaveProperties, taskWrk.getStartPoint()); |
| | | // TaskWrk hallowLocNoTask = taskWrkMapper.selectByStartPoint(shallowLocNo); |
| | | // if (!Cools.isEmpty(hallowLocNoTask)){ |
| | | // continue; |
| | | // } |
| | | // } |
| | | // 堆垛机控制过滤 |
| | | if (!crnProtocol.getStatusType().equals(CrnStatusType.IDLE) || crnProtocol.getTaskNo() != 0) { |
| | | continue; |
| | | } |
| | | |
| | | // 已经存在吊车执行任务时,则过滤 |
| | | if (taskWrkMapper.selectCrnWorking(slave.getId()) != null) { |
| | | continue; |
| | | } |
| | | |
| | | if (taskWrk == null || Cools.isEmpty(taskWrk.getTargetPoint()) || taskWrk.getTargetPoint().equals("") || taskWrk.getWrkNo() == null) { |
| | | continue; |
| | | } |
| | | // 工作档状态判断 |
| | | if (taskWrk.getIoType() != 3 || taskWrk.getTargetPoint() == null) { |
| | | log.error("查询工作档数据不符合条件--入出类型/目标库位号, 工作号={},源库位={},入出类型={}", taskWrk.getWrkNo(), taskWrk.getTargetPoint(), taskWrk.getIoType()); |
| | | continue; |
| | | } |
| | | |
| | | // 命令下发区 -------------------------------------------------------------------------- |
| | | |
| | | |
| | | // 1.堆垛机开始移动 |
| | | CrnCommand crnCommand = new CrnCommand(); |
| | | crnCommand.setCrnNo(slave.getId()); // 堆垛机编号 |
| | | crnCommand.setTaskNo(taskWrk.getWrkNo().shortValue()); // 工作号 |
| | | crnCommand.setAckFinish((short) 0); // 任务完成确认位 |
| | | crnCommand.setTaskMode(CrnTaskModeType.LOC_MOVE); // 任务模式: 库位移转 |
| | | crnCommand.setSourcePosX(Utils.getRowShort(taskWrk.getStartPoint())); // 源库位排 |
| | | crnCommand.setSourcePosY(Utils.getBayShort(taskWrk.getStartPoint())); // 源库位列 |
| | | crnCommand.setSourcePosZ(Utils.getLevShort(taskWrk.getStartPoint())); // 源库位层 |
| | | crnCommand.setDestinationPosX(Utils.getRowShort(taskWrk.getTargetPoint())); // 目标库位排 |
| | | crnCommand.setDestinationPosY(Utils.getBayShort(taskWrk.getTargetPoint())); // 目标库位列 |
| | | crnCommand.setDestinationPosZ(Utils.getLevShort(taskWrk.getTargetPoint())); // 目标库位层 |
| | | crnCommand.setCommand((short) 1); |
| | | if (!CommandUtils.offer(SlaveType.Crn, taskWrk.getCrnNo(), new Task(2, crnCommand), false)) { |
| | | log.error("堆垛机命令下发失败,堆垛机号={},任务数据={}", taskWrk.getCrnNo(), JSON.toJSON(crnCommand)); |
| | | } else { |
| | | // 修改工作档状态 11.生成出库ID => 12.吊车出库中 |
| | | Date now = new Date(); |
| | | taskWrk.setWrkSts(12); |
| | | taskWrk.setStatus(2); |
| | | taskWrk.setModiTime(now); |
| | | 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失败"); |
| | | } |
| | | |
| | | } |
| | | 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 synchronized void storeFinished() throws InterruptedException { |
| | | 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) && crnProtocol.getTaskNo() != 999) { |
| | | log.error("堆垛机处于等待确认且任务完成状态,但未找到工作档。堆垛机号={},工作号={}", crn.getId(), crnProtocol.getTaskNo()); |
| | | continue; |
| | | } |
| | | //确认完成信号 |
| | | CrnOperatorParam crnOperatorParam = new CrnOperatorParam(); |
| | | crnOperatorParam.setCrnNo(crn.getId()); |
| | | R r = crnController.crnTaskComplete(crnOperatorParam); |
| | | Thread.sleep(1000); |
| | | if (!r.get("code").equals(200)) { |
| | | return; |
| | | } |
| | | if (!Cools.isEmpty(taskWrk)) { |
| | | if (taskWrk.getIoType() == 1 && taskWrk.getWrkSts() == 3) { |
| | | taskWrk.setWrkSts(4);//入库完成 |
| | | taskWrk.setStatus(5);//完结 |
| | | //更新库位状态 |
| | | LocMast locMast = locMastService.selectByLocNo(taskWrk.getTargetPoint()); |
| | | locMast.setLocSts("F");//F.在库 |
| | | locMast.setBarcode(taskWrk.getBarcode());//托盘码 |
| | | locMast.setModiTime(new Date()); |
| | | locMast.setModiUser(9999L); |
| | | locMastService.updateById(locMast); |
| | | } else if (taskWrk.getIoType() == 2 && taskWrk.getWrkSts() == 12) { |
| | | taskWrk.setWrkSts(13);//出库完成 |
| | | taskWrk.setStatus(5);//完结 |
| | | //更新库位状态 |
| | | LocMast locMast = locMastService.selectByLocNo(taskWrk.getStartPoint()); |
| | | locMast.setLocSts("O");//O.空库位 |
| | | locMast.setBarcode("");//托盘码 |
| | | locMast.setModiTime(new Date()); |
| | | locMast.setModiUser(9999L); |
| | | locMastService.updateById(locMast); |
| | | } else if (taskWrk.getIoType() == 3 && taskWrk.getWrkSts() == 12) { |
| | | taskWrk.setWrkSts(4);//入库完成 |
| | | taskWrk.setStatus(5);//完结 |
| | | //更新库位状态 |
| | | LocMast locMast = locMastService.selectByLocNo(taskWrk.getTargetPoint()); |
| | | locMast.setLocSts("F");//F.在库 |
| | | locMast.setBarcode(taskWrk.getBarcode());//托盘码 |
| | | locMast.setModiTime(new Date()); |
| | | locMast.setModiUser(9999L); |
| | | locMastService.updateById(locMast); |
| | | |
| | | LocMast locMast1 = locMastService.selectByLocNo(taskWrk.getStartPoint()); |
| | | locMast1.setLocSts("O");//O.空库位 |
| | | locMast1.setBarcode("");//托盘码 |
| | | locMast1.setModiTime(new Date()); |
| | | locMast1.setModiUser(9999L); |
| | | locMastService.updateById(locMast1); |
| | | } |
| | | taskWrkService.updateById(taskWrk); |
| | | } |
| | | |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 堆垛机异常信息记录 |
| | | */ |
| | | public synchronized void recCrnErr() { |
| | | Date now = new Date(); |
| | | for (CrnSlave crn : slaveProperties.getCrn()) { |
| | | // 获取堆垛机信息 |
| | | CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, crn.getId()); |
| | | CrnProtocol crnProtocol = crnThread.getCrnProtocol(); |
| | | if (crnProtocol == null) { |
| | | continue; |
| | | } |
| | | if (false) { |
| | | // if (crnProtocol.getModeType() != CrnModeType.STOP) { |
| | | // 有任务 |
| | | if (crnProtocol.getTaskNo() != 0) { |
| | | BasErrLog latest = basErrLogService.findLatestByTaskNo(crn.getId(), crnProtocol.getTaskNo().intValue()); |
| | | // 有异常 |
| | | if (latest == null) { |
| | | if (crnProtocol.getAlarm() != null && crnProtocol.getAlarm() > 0) { |
| | | WrkMast wrkMast = wrkMastMapper.selectById(crnProtocol.getTaskNo()); |
| | | if (wrkMast == null) { |
| | | continue; |
| | | } |
| | | BasCrnError crnError = basCrnErrorMapper.selectById(crnProtocol.getAlarm()); |
| | | String errName = crnError == null ? String.valueOf(crnProtocol.getAlarm()) : crnError.getErrName(); |
| | | BasErrLog basErrLog = new BasErrLog( |
| | | null, // 编号 |
| | | wrkMast.getWrkNo(), // 工作号 |
| | | now, // 发生时间 |
| | | null, // 结束时间 |
| | | wrkMast.getWrkSts(), // 工作状态 |
| | | wrkMast.getIoType(), // 入出库类型 |
| | | crn.getId(), // 堆垛机 |
| | | null, // plc |
| | | wrkMast.getLocNo(), // 目标库位 |
| | | wrkMast.getStaNo(), // 目标站 |
| | | wrkMast.getSourceStaNo(), // 源站 |
| | | wrkMast.getSourceLocNo(), // 源库位 |
| | | wrkMast.getBarcode(), // 条码 |
| | | (int) crnProtocol.getAlarm1(), // 异常码 |
| | | errName, // 异常 |
| | | 1, // 异常情况 |
| | | now, // 添加时间 |
| | | null, // 添加人员 |
| | | now, // 修改时间 |
| | | null, // 修改人员 |
| | | "任务中异常" // 备注 |
| | | ); |
| | | if (!basErrLogService.insert(basErrLog)) { |
| | | log.error("堆垛机plc异常记录失败 ===>> [id:{}] [error:{}]", crn.getId(), errName); |
| | | } |
| | | } |
| | | } else { |
| | | // 异常修复 |
| | | if (crnProtocol.getAlarm1() == null || crnProtocol.getAlarm1() == 0) { |
| | | latest.setEndTime(now); |
| | | latest.setUpdateTime(now); |
| | | latest.setStatus(2); |
| | | if (!basErrLogService.updateById(latest)) { |
| | | log.error("堆垛机plc异常记录修复失败 ===>> [id:{}] [errLogId:{}]", crn.getId(), latest.getId()); |
| | | } |
| | | } |
| | | } |
| | | // 无任务 |
| | | } else { |
| | | BasErrLog latest = basErrLogService.findLatest(crn.getId()); |
| | | // 有异常 |
| | | if (crnProtocol.getAlarm1() != null && crnProtocol.getAlarm() > 0) { |
| | | // 记录新异常 |
| | | if (latest == null || (latest.getErrCode() != crnProtocol.getAlarm().intValue())) { |
| | | BasCrnError crnError = basCrnErrorMapper.selectById(crnProtocol.getAlarm()); |
| | | String errName = crnError == null ? String.valueOf(crnProtocol.getAlarm()) : crnError.getErrName(); |
| | | BasErrLog basErrLog = new BasErrLog( |
| | | null, // 编号 |
| | | null, // 工作号 |
| | | now, // 发生时间 |
| | | null, // 结束时间 |
| | | null, // 工作状态 |
| | | null, // 入出库类型 |
| | | crn.getId(), // 堆垛机 |
| | | null, // plc |
| | | null, // 目标库位 |
| | | null, // 目标站 |
| | | null, // 源站 |
| | | null, // 源库位 |
| | | null, // 条码 |
| | | (int) crnProtocol.getAlarm1(), // 异常码 |
| | | errName, // 异常 |
| | | 1, // 异常情况 |
| | | now, // 添加时间 |
| | | null, // 添加人员 |
| | | now, // 修改时间 |
| | | null, // 修改人员 |
| | | "无任务异常" // 备注 |
| | | ); |
| | | if (!basErrLogService.insert(basErrLog)) { |
| | | log.error("堆垛机plc异常记录失败 ===>> [id:{}] [error:{}]", crn.getId(), errName); |
| | | } |
| | | } |
| | | // 无异常 |
| | | } else { |
| | | // 异常修复 |
| | | if (latest != null && latest.getStatus() == 1) { |
| | | latest.setEndTime(now); |
| | | latest.setUpdateTime(now); |
| | | latest.setStatus(2); |
| | | if (!basErrLogService.updateById(latest)) { |
| | | log.error("堆垛机plc异常记录修复失败 ===>> [id:{}] [errLogId:{}]", crn.getId(), latest.getId()); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | } |
| | | |
| | | //自动派发任务 |
| | | public synchronized void autoDistribute() { |
| | | Config config = configService.selectByCode("autoDistribute"); |
| | |
| | | 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 createTask1(Result result, String barcode) { |
| | | String locNo = Utils.Fusion(result.getRow(), result.getFloor(), result.getColumn()); |
| | | |
| | | |
| | | Date now = new Date(); |
| | | TaskWrk taskWrk = new TaskWrk(); |
| | | int workNo1 = commonService.getWorkNo(WorkNoType.PAKIN.type);//获取入库工作号 |
| | | taskWrk.setTaskNo(result.getTaskNo());//任务号 |
| | | taskWrk.setWrkNo(workNo1); |
| | | taskWrk.setStatus(TaskStatusType.DISTRIBUTE.id);//任务状态:派发 |
| | | taskWrk.setCreateTime(now); |
| | | taskWrk.setIoType(1);//任务类型 |
| | | taskWrk.setIoPri(13);//优先级 |
| | | taskWrk.setBarcode(barcode);//条码 |
| | | LocMast locMast = locMastService.selectByLocNo(locNo); |
| | | taskWrk.setCrnNo(locMast.getCrnNo()); |
| | | taskWrk.setTargetPoint(locNo); |
| | | taskWrk.setStartPoint("116"); |
| | | if (result.getAlley().equals("1")) { |
| | | taskWrk.setCrnNo(1); |
| | | } else { |
| | | taskWrk.setCrnNo(2); |
| | | } |
| | | if (taskWrk.getIoType() == 1) { |
| | | taskWrk.setWrkSts(2); |
| | | if (!Cools.isEmpty(taskWrk.getTargetPoint())) { |
| | | taskWrk.setOriginTargetPoint(taskWrk.getTargetPoint()); |
| | | } |
| | | } |
| | | return taskWrk; |
| | | } |
| | | |
| | | private TaskWrk createTask(GetWmsDto dto, String barcode) { |
| | | String wcsLocNo = dto.getLocNo(); |
| | | if (Cools.isEmpty(wcsLocNo)) { |
| | | return null; |
| | | } |
| | | Date now = new Date(); |
| | | TaskWrk taskWrk = new TaskWrk(); |
| | | int workNo1 = commonService.getWorkNo(WorkNoType.PAKIN.type);//获取入库工作号 |
| | | taskWrk.setTaskNo(dto.getWrkNo());//任务号 |
| | | taskWrk.setWrkNo(workNo1); |
| | | taskWrk.setStatus(TaskStatusType.RECEIVE.id);//任务状态:接收 |
| | | taskWrk.setCreateTime(now); |
| | | taskWrk.setIoType(1);//任务类型 |
| | | taskWrk.setIoPri(Cools.isEmpty(dto.getTaskPriority()) ? 300 : Integer.parseInt(dto.getTaskPriority()));//优先级 |
| | | taskWrk.setBarcode(barcode);//条码 |
| | | LocMast locMast = locMastService.selectByLocNo(wcsLocNo); |
| | | taskWrk.setCrnNo(locMast.getCrnNo()); |
| | | taskWrk.setTargetPoint(wcsLocNo); |
| | | taskWrk.setStartPoint(dto.getStaNo().toString()); |
| | | if (taskWrk.getIoType() == 1) { |
| | | taskWrk.setWrkSts(2); |
| | | if (!Cools.isEmpty(taskWrk.getTargetPoint())) { |
| | | taskWrk.setOriginTargetPoint(taskWrk.getTargetPoint()); |
| | | } |
| | | |
| | | // } else if (param.getIoType() == 2) { |
| | | // taskWrk.setWrkSts(11); |
| | | // if (!Cools.isEmpty(param.getStartPoint())) { |
| | | // taskWrk.setStartPoint(Utils.getWcsLocNo(param.getStartPoint()));//起点 |
| | | // taskWrk.setOriginStartPoint(param.getStartPoint()); |
| | | // } |
| | | // taskWrk.setTargetPoint(param.getTargetPoint()); |
| | | // }else if (param.getIoType() == 3){ |
| | | // taskWrk.setWrkSts(11); |
| | | // if (!Cools.isEmpty(param.getStartPoint())) { |
| | | // taskWrk.setStartPoint(param.getStartPoint());//起点 |
| | | // taskWrk.setOriginStartPoint(param.getStartPoint()); |
| | | // } |
| | | } |
| | | return taskWrk; |
| | | } |
| | | |
| | | } |