package com.zy.asrs.wcs.rcs.model.protocol;
|
|
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.Loc;
|
import com.zy.asrs.wcs.core.service.LocService;
|
import com.zy.asrs.wcs.core.utils.RedisUtil;
|
import com.zy.asrs.wcs.rcs.constant.DeviceRedisConstant;
|
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.service.BasShuttleErrService;
|
import com.zy.asrs.wcs.rcs.service.ShuttleDeviceStatusService;
|
import lombok.Data;
|
import lombok.extern.slf4j.Slf4j;
|
|
/**
|
* 四向穿梭车
|
*/
|
@Slf4j
|
@Data
|
public class ShuttleProtocol implements Cloneable{
|
|
//**********************必须存在属性**********************
|
/**
|
* 四向穿梭车号
|
*/
|
private Integer shuttleNo;
|
|
/**
|
* 任务号
|
*/
|
private Integer taskNo;
|
|
/**
|
* 当前小车状态(内部自我维护)
|
*/
|
private Integer protocolStatus;
|
|
/**
|
* 当前小车作业状态枚举
|
*/
|
private ShuttleProtocolStatusType protocolStatusType;
|
|
/**
|
* 源库位
|
*/
|
private String sourceLocNo;
|
|
/**
|
* 目标库位
|
*/
|
private String locNo;
|
|
/**
|
* 小车设备状态
|
*/
|
private Integer deviceStatus;
|
|
/**
|
* 小车模式,0:手动 1:自动
|
*/
|
private Integer mode;
|
|
/**
|
* 当前二维码
|
* 0为空
|
*/
|
private String currentCode;
|
|
/**
|
* 电池电量
|
*/
|
private String batteryPower;
|
|
/**
|
* 错误编号
|
*/
|
private String errorCode;
|
|
|
//**********************非必须属性,实际使用中可能存在空值**********************
|
|
/**
|
* 电池温度
|
*/
|
private String batteryTemp;
|
|
/**
|
* 是否顶升
|
*/
|
private Boolean hasLift;
|
|
/**
|
* 是否有托盘
|
*/
|
private Boolean hasPallet;
|
|
/**
|
* 行驶方向
|
*/
|
private String runDirection;
|
|
/**
|
* 是否为充电状态
|
*/
|
private Boolean hasCharge;
|
|
/**
|
* 电池电压
|
*/
|
private Integer batteryVoltage;
|
|
|
//**********************系统自身所需属性**********************
|
/**
|
* 作业标记 false表示正在作业
|
*/
|
private Boolean pakMk = true;
|
|
/**
|
* 跑库状态
|
*/
|
private Boolean moveLoc = false;
|
|
/**
|
* 跑库类型,0:跑轨道,1:跑库位
|
*/
|
private Integer moveType = 0;
|
|
/**
|
* 跑库X起点
|
*/
|
private Integer xStart = 0;
|
|
/**
|
* 跑库X终点
|
*/
|
private Integer xTarget = 0;
|
|
/**
|
* 跑库X当前点位
|
*/
|
private Integer xCurrent = 0;
|
|
/**
|
* 跑库Y起点
|
*/
|
private Integer yStart = 0;
|
|
/**
|
* 跑库Y终点
|
*/
|
private Integer yTarget = 0;
|
|
/**
|
* 跑库Y当前点位
|
*/
|
private Integer yCurrent = 0;
|
|
/**
|
* 日志采集时间
|
*/
|
private Long deviceDataLog = System.currentTimeMillis();
|
|
/**
|
* 指令下发时间
|
*/
|
private Long sendTime = 0L;
|
|
/**
|
* 最近一次在线时间
|
*/
|
private Long lastOnlineTime = System.currentTimeMillis();
|
|
/**
|
* 设备信息
|
*/
|
private Device device;
|
|
/**
|
* 扩展字段
|
*/
|
private Object extend;
|
|
/**
|
* 设置小车状态
|
*/
|
public void setProtocolStatus(Integer status) {
|
this.protocolStatus = status;
|
this.protocolStatusType = ShuttleProtocolStatusType.get(status);
|
}
|
|
/**
|
* 设置小车状态
|
*/
|
public void setProtocolStatus(ShuttleProtocolStatusType status) {
|
this.protocolStatus = status.id;
|
this.protocolStatusType = status;
|
}
|
|
/**
|
* 获取小车设备状态
|
*/
|
public String getDeviceStatus$() {
|
if (this.deviceStatus == 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) {
|
return status.getName();
|
}
|
return "";
|
}
|
|
public String getErrorCode$() {
|
if (this.errorCode == null) {
|
return "";
|
}
|
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 errorCode;
|
}
|
|
public Integer getTaskNo() {
|
RedisUtil redisUtil = SpringUtils.getBean(RedisUtil.class);
|
if (null != redisUtil) {
|
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);
|
if (locService == 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) {
|
return null;
|
}
|
|
return currentLoc.getLocNo();
|
}
|
|
@Override
|
public ShuttleProtocol clone() {
|
try {
|
return (ShuttleProtocol) super.clone();
|
} catch (CloneNotSupportedException e) {
|
e.printStackTrace();
|
}
|
return null;
|
}
|
|
}
|