#
Junjie
2024-05-18 a7d5e6c4a45ca1f7bb1560ef4e76f4c1680c41db
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
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;
    }
 
}