| | |
| | | package com.zy.core.thread.impl; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.core.common.DateUtils; |
| | | import com.core.common.SpringUtils; |
| | | import com.zy.asrs.entity.*; |
| | |
| | | import com.zy.common.utils.RedisUtil; |
| | | import com.zy.core.cache.MessageQueue; |
| | | import com.zy.core.cache.OutputQueue; |
| | | import com.zy.core.enums.CrnModeType; |
| | | import com.zy.core.enums.CrnTaskModeType; |
| | | import com.zy.core.enums.RedisKeyType; |
| | | import com.zy.core.enums.SlaveType; |
| | |
| | | import com.zy.core.network.DeviceConnectPool; |
| | | import com.zy.core.network.ZyCrnV2ConnectDriver; |
| | | import com.zy.core.network.entity.ZyCrnStatusEntity; |
| | | import com.zy.core.service.WrkCommandRollbackService; |
| | | import com.zy.core.thread.CrnThread; |
| | | import com.zy.core.task.DeviceAsyncLogPublisher; |
| | | import lombok.Data; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | |
| | |
| | | private ZyCrnV2ConnectDriver zyCrnConnectDriver; |
| | | private CrnProtocol crnProtocol; |
| | | private int deviceLogCollectTime = 200; |
| | | private final DeviceAsyncLogPublisher deviceAsyncLogPublisher; |
| | | |
| | | public ZySiemensCrnV2Thread(DeviceConfig deviceConfig, RedisUtil redisUtil) { |
| | | this.deviceConfig = deviceConfig; |
| | | this.redisUtil = redisUtil; |
| | | this.deviceAsyncLogPublisher = SpringUtils.getBean(DeviceAsyncLogPublisher.class); |
| | | } |
| | | |
| | | @Override |
| | |
| | | |
| | | } |
| | | if (basCrnpService != null) { |
| | | BasCrnp basCrnp = basCrnpService.selectOne(new EntityWrapper<BasCrnp>().eq("crn_no", deviceConfig.getDeviceNo())); |
| | | BasCrnp basCrnp = basCrnpService.getOne(new QueryWrapper<BasCrnp>().eq("crn_no", deviceConfig.getDeviceNo())); |
| | | if(basCrnp == null) { |
| | | basCrnp = new BasCrnp(); |
| | | basCrnp.setCrnNo(deviceConfig.getDeviceNo()); |
| | |
| | | basCrnp.setMaxInTask(5); |
| | | basCrnp.setMaxOutTask(5); |
| | | basCrnp.setCreateTime(new Date()); |
| | | basCrnpService.insert(basCrnp); |
| | | basCrnpService.save(basCrnp); |
| | | } |
| | | } |
| | | } |
| | |
| | | private void readStatus(){ |
| | | ZyCrnStatusEntity crnStatus = zyCrnConnectDriver.getStatus(); |
| | | if (crnStatus == null) { |
| | | crnProtocol.setMode(CrnModeType.NONE); |
| | | OutputQueue.CRN.offer(MessageFormat.format("【{0}】读取堆垛机plc状态信息失败 ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), deviceConfig.getDeviceNo(), deviceConfig.getIp(), deviceConfig.getPort())); |
| | | return; |
| | | } |
| | |
| | | crnProtocol.setWalkPos(crnStatus.getWalkPos()); |
| | | crnProtocol.setLoaded(crnStatus.getLoaded()); |
| | | crnProtocol.setAlarm(crnStatus.getAlarm()); |
| | | crnProtocol.setLaserValue(crnStatus.getLaserValue()); |
| | | crnProtocol.setTemp1(crnStatus.getTemp1()); |
| | | crnProtocol.setTemp2(crnStatus.getTemp2()); |
| | | crnProtocol.setTemp3(crnStatus.getTemp3()); |
| | |
| | | crnProtocol.setYDistance(crnStatus.getYDistance()); |
| | | crnProtocol.setXDuration(crnStatus.getXDuration()); |
| | | crnProtocol.setYDuration(crnStatus.getYDuration()); |
| | | crnProtocol.setTaskReceive(crnStatus.getTaskReceive()); |
| | | |
| | | OutputQueue.CRN.offer(MessageFormat.format("【{0}】[id:{1}] <<<<< 实时数据更新成功",DateUtils.convert(new Date()), deviceConfig.getDeviceNo())); |
| | | |
| | |
| | | deviceDataLog.setDeviceNo(crnProtocol.getCrnNo()); |
| | | deviceDataLog.setCreateTime(new Date()); |
| | | |
| | | redisUtil.set(RedisKeyType.DEVICE_LOG_KEY.key + System.currentTimeMillis(), deviceDataLog, 60 * 60 * 24); |
| | | deviceAsyncLogPublisher.publishLatest(deviceDataLog); |
| | | //更新采集时间 |
| | | crnProtocol.setDeviceDataLog(System.currentTimeMillis()); |
| | | } |
| | |
| | | log.setStatus(1); |
| | | log.setCreateTime(new Date()); |
| | | log.setSystemStatus(JSON.toJSONString(crnProtocol)); |
| | | errLogService.insert(log); |
| | | errLogService.save(log); |
| | | if (log.getId() != null) { |
| | | redisUtil.set(errFlagKey, log.getId(), 60 * 60 * 24); |
| | | } |
| | |
| | | |
| | | @Override |
| | | public CrnCommand getPickAndPutCommand(String sourceLocNo, String targetLocNo, Integer taskNo, Integer crnNo) { |
| | | BasCrnp basCrnp = getBasCrnp(crnNo); |
| | | CrnCommand crnCommand = new CrnCommand(); |
| | | crnCommand.setCrnNo(crnNo); // 堆垛机编号 |
| | | crnCommand.setTaskNo(taskNo); // 工作号 |
| | | crnCommand.setTaskMode(CrnTaskModeType.LOC_MOVE.id); // 任务模式: 库位移转 |
| | | crnCommand.setSourcePosX(Utils.getRow(sourceLocNo)); // 源库位排 |
| | | crnCommand.setSourcePosX(resolveCommandRow(sourceLocNo, basCrnp)); // 源库位排 |
| | | crnCommand.setSourcePosY(Utils.getBay(sourceLocNo)); // 源库位列 |
| | | crnCommand.setSourcePosZ(Utils.getLev(sourceLocNo)); // 源库位层 |
| | | crnCommand.setDestinationPosX(Utils.getRow(targetLocNo)); // 目标库位排 |
| | | crnCommand.setDestinationPosX(resolveCommandRow(targetLocNo, basCrnp)); // 目标库位排 |
| | | crnCommand.setDestinationPosY(Utils.getBay(targetLocNo)); // 目标库位列 |
| | | crnCommand.setDestinationPosZ(Utils.getLev(targetLocNo)); // 目标库位层 |
| | | crnCommand.setCommand(1); // 任务确认 |
| | |
| | | |
| | | @Override |
| | | public CrnCommand getMoveCommand(String targetLocNo, Integer taskNo, Integer crnNo) { |
| | | Integer targetRow = resolveCommandRow(targetLocNo, crnNo); |
| | | CrnCommand crnCommand = new CrnCommand(); |
| | | crnCommand.setCrnNo(crnNo); // 堆垛机编号 |
| | | crnCommand.setTaskNo(taskNo); // 工作号 |
| | | crnCommand.setAckFinish(0); // 任务完成确认位 |
| | | crnCommand.setTaskMode(CrnTaskModeType.CRN_MOVE.id); // 任务模式: 堆垛机移动 |
| | | crnCommand.setSourcePosX(Utils.getRow(targetLocNo)); // 目标库位排 |
| | | crnCommand.setSourcePosX(targetRow); // 目标库位排 |
| | | crnCommand.setSourcePosY(Utils.getBay(targetLocNo)); // 目标库位列 |
| | | crnCommand.setSourcePosZ(Utils.getLev(targetLocNo)); // 目标库位层 |
| | | crnCommand.setDestinationPosX(Utils.getRow(targetLocNo)); // 目标库位排 |
| | | crnCommand.setDestinationPosX(targetRow); // 目标库位排 |
| | | crnCommand.setDestinationPosY(Utils.getBay(targetLocNo)); // 目标库位列 |
| | | crnCommand.setDestinationPosZ(Utils.getLev(targetLocNo)); // 目标库位层 |
| | | crnCommand.setCommand(1); // 任务确认 |
| | | return crnCommand; |
| | | } |
| | | |
| | | private Integer resolveCommandRow(String locNo, Integer crnNo) { |
| | | return resolveCommandRow(locNo, getBasCrnp(crnNo)); |
| | | } |
| | | |
| | | private Integer resolveCommandRow(String locNo, BasCrnp basCrnp) { |
| | | Integer locationRow = Utils.getRow(locNo); |
| | | if (basCrnp == null) { |
| | | return locationRow; |
| | | } |
| | | return basCrnp.getCommandRow(locationRow); |
| | | } |
| | | |
| | | private BasCrnp getBasCrnp(Integer crnNo) { |
| | | BasCrnpService basCrnpService = SpringUtils.getBean(BasCrnpService.class); |
| | | return basCrnpService.getById(crnNo); |
| | | } |
| | | |
| | | @Override |
| | | public CrnCommand getResetCommand(Integer crnNo) { |
| | | public CrnCommand getResetCommand(Integer taskNo, Integer crnNo) { |
| | | CrnCommand crnCommand = new CrnCommand(); |
| | | crnCommand.setCrnNo(crnNo); // 堆垛机编号 |
| | | crnCommand.setTaskNo(0); // 工作号 |
| | | crnCommand.setTaskNo(taskNo); // 工作号 |
| | | crnCommand.setAckFinish(1); // 任务完成确认位 |
| | | crnCommand.setTaskMode(CrnTaskModeType.NONE.id); // 任务模式 |
| | | crnCommand.setTaskMode(CrnTaskModeType.RESET.id); // 任务模式 |
| | | crnCommand.setSourcePosX(0); // 源库位排 |
| | | crnCommand.setSourcePosY(0); // 源库位列 |
| | | crnCommand.setSourcePosZ(0); // 源库位层 |
| | |
| | | response = zyCrnConnectDriver.sendCommand(command); |
| | | return response; |
| | | } finally { |
| | | String sourceLocNo = Utils.getLocNo(command.getSourcePosX(), command.getSourcePosY(), command.getSourcePosZ()); |
| | | String targetLocNo = Utils.getLocNo(command.getDestinationPosX(), command.getDestinationPosY(), command.getDestinationPosZ()); |
| | | BasCrnpOptService bean = SpringUtils.getBean(BasCrnpOptService.class); |
| | | ZyCrnStatusEntity statusEntity = zyCrnConnectDriver.getStatus(); |
| | | BasCrnpOpt basCrnpOpt = new BasCrnpOpt( |
| | | command.getTaskNo().intValue(), |
| | | command.getCrnNo(), |
| | | new Date(), |
| | | String.valueOf(command.getTaskMode()), |
| | | sourceLocNo, |
| | | targetLocNo, |
| | | null, |
| | | null, |
| | | null, |
| | | JSON.toJSONString(command), |
| | | JSON.toJSONString(statusEntity), |
| | | 1, |
| | | JSON.toJSONString(response) |
| | | ); |
| | | if (bean != null) { |
| | | bean.insert(basCrnpOpt); |
| | | if (command != null) { |
| | | String sourceLocNo = Utils.getLocNo(command.getSourcePosX(), command.getSourcePosY(), command.getSourcePosZ()); |
| | | String targetLocNo = Utils.getLocNo(command.getDestinationPosX(), command.getDestinationPosY(), command.getDestinationPosZ()); |
| | | BasCrnpOptService bean = SpringUtils.getBean(BasCrnpOptService.class); |
| | | ZyCrnStatusEntity statusEntity = zyCrnConnectDriver.getStatus(); |
| | | BasCrnpOpt basCrnpOpt = new BasCrnpOpt( |
| | | command.getTaskNo(), |
| | | command.getCrnNo(), |
| | | new Date(), |
| | | String.valueOf(command.getTaskMode()), |
| | | sourceLocNo, |
| | | targetLocNo, |
| | | null, |
| | | null, |
| | | null, |
| | | JSON.toJSONString(command), |
| | | JSON.toJSONString(statusEntity), |
| | | 1, |
| | | JSON.toJSONString(response) |
| | | ); |
| | | bean.save(basCrnpOpt); |
| | | try { |
| | | WrkCommandRollbackService rollbackService = SpringUtils.getBean(WrkCommandRollbackService.class); |
| | | if (rollbackService != null) { |
| | | rollbackService.handleSingleCrnSendResult(command, response, "单工位堆垛机V2"); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("处理单工位V2命令下发结果失败, wrkNo={}", command.getTaskNo(), e); |
| | | } |
| | | } |
| | | } |
| | | } |