| | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.zy.asrs.framework.common.Cools; |
| | | import com.zy.asrs.framework.common.SpringUtils; |
| | | import com.zy.asrs.wcs.core.entity.BasLift; |
| | | import com.zy.asrs.wcs.core.entity.Loc; |
| | | import com.zy.asrs.wcs.core.service.BasLiftService; |
| | | import com.zy.asrs.wcs.core.service.LocService; |
| | | import com.zy.asrs.wcs.core.utils.RedisUtil; |
| | | import com.zy.asrs.wcs.core.utils.Utils; |
| | | import com.zy.asrs.wcs.rcs.cache.SlaveConnection; |
| | | import com.zy.asrs.wcs.rcs.constant.DeviceRedisConstant; |
| | | import com.zy.asrs.wcs.rcs.model.enums.ShuttleDeviceStatusType; |
| | | import com.zy.asrs.wcs.rcs.entity.BasShuttleErr; |
| | | import com.zy.asrs.wcs.rcs.model.enums.ShuttleProtocolStatusType; |
| | | import com.zy.asrs.wcs.rcs.entity.Device; |
| | | import com.zy.asrs.wcs.rcs.entity.ShuttleDeviceStatus; |
| | | import com.zy.asrs.wcs.rcs.model.enums.SlaveType; |
| | | import com.zy.asrs.wcs.rcs.service.BasShuttleErrService; |
| | | import com.zy.asrs.wcs.rcs.service.ShuttleDeviceStatusService; |
| | | import com.zy.asrs.wcs.rcs.thread.LiftThread; |
| | | import lombok.Data; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | |
| | |
| | | */ |
| | | @Slf4j |
| | | @Data |
| | | public class ShuttleProtocol { |
| | | public class ShuttleProtocol implements Cloneable{ |
| | | |
| | | //**********************必须存在属性********************** |
| | | /** |
| | | * 四向穿梭车号 |
| | | */ |
| | | private String shuttleNo; |
| | | private Integer shuttleNo; |
| | | |
| | | /** |
| | | * 任务号 |
| | |
| | | private Integer deviceStatus; |
| | | |
| | | /** |
| | | * 小车模式,0:手动 1:自动 |
| | | */ |
| | | private Integer mode; |
| | | |
| | | /** |
| | | * 当前二维码 |
| | | * 0为空 |
| | | */ |
| | |
| | | * 是否顶升 |
| | | */ |
| | | private Boolean hasLift; |
| | | |
| | | /** |
| | | * 是否有托盘 |
| | | */ |
| | | private Boolean hasPallet; |
| | | |
| | | /** |
| | | * 行驶方向 |
| | |
| | | private Long deviceDataLog = System.currentTimeMillis(); |
| | | |
| | | /** |
| | | * 指令下发时间 |
| | | */ |
| | | private Long sendTime = 0L; |
| | | |
| | | /** |
| | | * 最近一次在线时间 |
| | | */ |
| | | private Long lastOnlineTime = System.currentTimeMillis(); |
| | | |
| | | /** |
| | | * 设备信息 |
| | | */ |
| | | private Device device; |
| | | |
| | | /** |
| | | * 扩展字段 |
| | | */ |
| | | private Object extend; |
| | | |
| | | /** |
| | | * 设置小车状态 |
| | |
| | | return ""; |
| | | } |
| | | |
| | | /** |
| | | * 获取小车空闲状态 |
| | | */ |
| | | public Boolean getIdle() { |
| | | if (this.deviceStatus == null) { |
| | | return false; |
| | | public String getErrorCode$() { |
| | | if (this.errorCode == null) { |
| | | return ""; |
| | | } |
| | | |
| | | ShuttleDeviceStatusService shuttleDeviceStatusService = SpringUtils.getBean(ShuttleDeviceStatusService.class); |
| | | ShuttleDeviceStatus status = shuttleDeviceStatusService.getOne(new LambdaQueryWrapper<ShuttleDeviceStatus>() |
| | | .eq(ShuttleDeviceStatus::getHostId, this.device.getHostId()) |
| | | .eq(ShuttleDeviceStatus::getDevicePlc, this.device.getDevicePlc()) |
| | | .eq(ShuttleDeviceStatus::getStatus, 1) |
| | | .eq(ShuttleDeviceStatus::getDeviceStatus, this.deviceStatus)); |
| | | if (status != null) { |
| | | if (status.getFlag() != null && status.getFlag().equals(String.valueOf(ShuttleDeviceStatusType.IDLE))) { |
| | | return true;//空闲中 |
| | | } |
| | | BasShuttleErrService basShuttleErrService = SpringUtils.getBean(BasShuttleErrService.class); |
| | | BasShuttleErr shuttleErr = basShuttleErrService.getOne(new LambdaQueryWrapper<BasShuttleErr>() |
| | | .eq(BasShuttleErr::getErrorCode, this.errorCode) |
| | | .eq(BasShuttleErr::getHostId, this.device.getHostId()) |
| | | .eq(BasShuttleErr::getDevicePlc, this.device.getDevicePlc())); |
| | | if (shuttleErr != null) { |
| | | return this.errorCode + "-" + shuttleErr.getErrName(); |
| | | } |
| | | return false;//默认不空闲 |
| | | return errorCode; |
| | | } |
| | | |
| | | public Integer getTaskNo() { |
| | | RedisUtil redisUtil = SpringUtils.getBean(RedisUtil.class); |
| | | if (null != redisUtil) { |
| | | Object o = redisUtil.get(DeviceRedisConstant.SHUTTLE_FLAG + this.taskNo); |
| | | Object o = redisUtil.get(DeviceRedisConstant.SHUTTLE_FLAG + this.shuttleNo); |
| | | if (!Cools.isEmpty(o)) { |
| | | this.taskNo = Integer.parseInt(String.valueOf(o)); |
| | | } |
| | |
| | | return this.taskNo == null ? 0 : this.taskNo; |
| | | } |
| | | |
| | | public synchronized void setSyncTaskNo(Integer taskNo) { |
| | | RedisUtil redisUtil = SpringUtils.getBean(RedisUtil.class); |
| | | if (null != redisUtil) { |
| | | redisUtil.set(DeviceRedisConstant.SHUTTLE_FLAG + this.shuttleNo, taskNo); |
| | | this.taskNo = taskNo; |
| | | } |
| | | } |
| | | |
| | | //通过当前二维码获取当前库位号 |
| | | public String getCurrentLocNo() { |
| | | LocService locService = SpringUtils.getBean(LocService.class); |
| | | BasLiftService basLiftService = SpringUtils.getBean(BasLiftService.class); |
| | | if (locService == null || basLiftService == null) { |
| | | return null; |
| | | } |
| | | if (this.currentCode == null) { |
| | | return null; |
| | | } |
| | | |
| | | //源库位(小车当前位置) |
| | | LambdaQueryWrapper<Loc> wrapper = new LambdaQueryWrapper<Loc>() |
| | | .eq(Loc::getCode, this.currentCode) |
| | | .eq(Loc::getHostId, this.device.getHostId()); |
| | | Loc currentLoc = locService.getOne(wrapper); |
| | | if (currentLoc == null) { |
| | | //可能是提升机条码 |
| | | BasLift basLift = basLiftService.getOne(new LambdaQueryWrapper<BasLift>().eq(BasLift::getCode, this.currentCode).eq(BasLift::getStatus, 1)); |
| | | if(basLift != null) { |
| | | LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, basLift.getDeviceId().intValue()); |
| | | if (liftThread != null) { |
| | | LiftProtocol liftProtocol = liftThread.getStatus(); |
| | | return Utils.getLocNo(basLift.getRow(), basLift.getBay(), liftProtocol.getLev()); |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | return currentLoc.getLocNo(); |
| | | } |
| | | |
| | | @Override |
| | | public ShuttleProtocol clone() { |
| | | try { |
| | | return (ShuttleProtocol) super.clone(); |
| | | } catch (CloneNotSupportedException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | } |