StatusBean.java
13.6 KB
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
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
package com.myproject.bean.utils;
import com.google.common.base.Strings;
import com.myproject.bean.Language;
import com.myproject.bean.update.AlarmInfo;
import com.myproject.util.StorageConstants;
import java.util.*;
/**
* 类型,内容,详情,Msg
0,消息,"1=原点返回 2=复位",
1,总体错误,"1=急停 2=没有气压信号 3=盘错乱",
2,运动轴错误,"1=第一轴(旋转)2=第二轴(上下轴)3=第三轴(前进轴)4=第四轴(压紧轴)",
3,IO报警,信号超时,io电器定义(电器定义),
4,电钢报警,1=上下电钢,
*/
public class StatusBean {
/// <summary>
/// 料仓唯一标识
/// </summary>;
private String cid;
/// <summary>
/// 请求序列号
/// </summary>
private int seq;
/// <summary>
/// 操作码(0无操作(发送料仓状态给服务器),1扫码入库(扫码成功后发送给服务器),2 出库(服务器发送) )
/// </summary>
private int op;
/// <summary>
/// 操作相关数据,
/// op=1时,客户端发送 code 二维码给服务器,服务器返回时有:posId库位编号,plateW:料盘宽度,plateH:料盘高度
/// 如果需要更新温湿度的报警值,服务器会发送alarmTemperature,alarmHumidity给客户端,客户端缓存,如果没有发送,不处理
/// </summary>
//数据还放入data那个map里面,客户端收到服务器openLock为doit时,执行打开门锁动作;startBatchIn为doit时,执行开始批量入库动作;closeLock为doit时,执行关闭门锁;takeOutReel为doit时,执行取出出库料盘动作;confirmReelOut为doit时,执行门口料盘已取出;
//当服务器收到客户端:doorStatus为门锁状态(如开门中,或关闭中);openLock为enable时,此按钮状态为可用;startBatchIn为enable时此按钮状态为可用;closeLock为enable时此按钮状态为可用;takeOutReel为enable时此按钮状态为可用;confirmReelOut为enable时此按钮状态为可用;
//服务器默认这些按钮都为不可用状态,只有收到对应的enable时,按钮才可以进行点击
private Map<String, String> data = new HashMap<>();
/**
* 提示消息,key为en, zh_CN, jp等,消息为对应语言的消息
*/
private Map<String, String> msgData = new HashMap<>();
/// <summary>
/// 整体料仓状态
/// 1=正常运行中
/// 2=急停中
/// 3=故障(气压检测不到等,用msg发送详细故障说明)
/// 4=警告(用msg发送提醒,如出库到达工位但是没有工人操作)
/// </summary>
private int status;
/// <summary>
/// 提示消息
/// 出入库错误: BOX正在调试中,不能出入库
/// 出入库错误: 急停了不能出入库
/// 入库错误:料盘过大,放不到指定的位置中去
/// 故障:气压信号检测不到
/// 警告:出库盘到达工位但是没有工人操作
/// </summary>
public String msg = "";
/**
* 英文提示消息
*/
public String msgEn = "";
/// <summary>
/// 包含的多个 BOX 的状态信息
/// </summary>
private Map<Integer,BoxStatusBean> boxStatus = new HashMap<>();
/**
* 报警集合
*/
private List<AlarmInfo> alarmList = new ArrayList<>();
private long time = System.currentTimeMillis();
/**
* 上次保存时间
*/
private long lastSaveTime = System.currentTimeMillis();
/**
* 获取已经结束(缓存中存在,但新的报警列表不存在)的报警列表,同时将新的报警加入到缓存中
*/
public List<AlarmInfo> getEndAlarmList(String storageName, List<AlarmInfo> newAlarmList){
List<AlarmInfo> endAlarmList = new ArrayList<>();
Map<String,AlarmInfo> map = new HashMap<>();
if(newAlarmList != null){
for (AlarmInfo newAlarm : newAlarmList){
map.put(newAlarm.getKey(), newAlarm);
}
}
if(alarmList == null){
alarmList = new ArrayList<>();
}
for (AlarmInfo cacheAlarm : alarmList){
AlarmInfo existAlarm = map.get(cacheAlarm.getKey());
if(existAlarm == null){//客户端新上传的报警列表中不存在,说明该报警已经结束
//如果结束时间超过20秒就存到数据库中
Date endDate = cacheAlarm.getEndTime();
if(endDate != null){
if(System.currentTimeMillis() - endDate.getTime() >= 20 * 1000){
cacheAlarm.setStorageName(storageName);
endAlarmList.add(cacheAlarm);
}
}else{
//设置结束时间
cacheAlarm.setEndTime(new Date());
}
}else{//报警还在继续维持
cacheAlarm.setEndTime(null);
//从map 中移除,剩余的就是本次新增的报警信息
map.remove(cacheAlarm.getKey());
}
}
//将已经结束的报警信息从缓存列表中移除
for (AlarmInfo endAlarm : endAlarmList){
alarmList.remove(endAlarm);
}
//新增加的报警信息添加到缓存列表中
for(AlarmInfo newAlarm : map.values()){
newAlarm.setStartTime(new Date());
alarmList.add(newAlarm);
}
return endAlarmList;
}
/**
* 是否超时(3秒)
*/
public boolean timeOut(){
return System.currentTimeMillis() - time > 10 * 1000;
}
/**
* 获取客户端发送上来的二维码
*/
public String getCode(){
return data.get("code");
}
/**
* 获取库位信息
*/
public String getPosId(){
return data.get("posId");
}
/**
* 门口是否有料盘,如果
* @return
*/
public String hasTrayAtDoor(){
return getFromData("TrayCheck_Door");
}
/**
* 从Data中获取数据
*/
public String getFromData(String key){
return data.get(key);
}
/**
* 获取客户端发送上来的二维码对应的 boxId
*/
public String getCodeBoxId(){
return data.get("boxId");
}
public void setCode(String barcode){
data.put("code",barcode);
}
public void setTemperature(float temperature) {
data.put("temp",String.valueOf(temperature));
}
public void setHumidity(float humidity) {
data.put("humi", String.valueOf(humidity));
}
public List<AlarmInfo> getAlarmList() {
return alarmList;
}
public void setAlarmList(List<AlarmInfo> alarmList) {
this.alarmList = alarmList;
}
/**
* 添加一些服务器的操作发送到客户端(批量入库)
* @param opMap
*/
public void addOp(Map<String, String> opMap){
if(opMap != null && !opMap.isEmpty()){
for (Map.Entry<String, String> op : opMap.entrySet()) {
data.put(op.getKey(), op.getValue());
}
}
}
public void addData(String key, String value){
String oldValue = data.get(key);
String valueStr = value;
if(!Strings.isNullOrEmpty(oldValue)){
valueStr = valueStr + "|" + oldValue;
}
data.put(key, valueStr);
}
/**
* 入库时添加仓位及料盘大小信息(posId库位编号,plateW:料盘宽度,plateH:料盘高度,singleOut:是否出库到料仓门口)
*/
public void addPosInfo(String posId, int plateW, int plateH, boolean isSingleOut){
String originalPosId = data.get("posId");
String originalPlateW = data.get("plateW");
String originalPlateH = data.get("plateH");
String posIdStr = posId;
String plateWStr = plateW + "";
String plateHStr = plateH + "";
if(!Strings.isNullOrEmpty(originalPosId)){
posIdStr = originalPosId + "|" + posId;
}
if(!Strings.isNullOrEmpty(originalPlateW)){
plateWStr = originalPlateW + "|" + plateW;
}
if(!Strings.isNullOrEmpty(originalPlateH)){
plateHStr = originalPlateH + "|" + plateH;
}
data.put("posId",posIdStr);
data.put("plateW",plateWStr);
data.put("plateH",plateHStr);
data.put("singleOut", isSingleOut+"");
}
/**
* 是否需要往数据库保存(5分钟保存一次)
*/
public boolean needSaveToMongo(){
return System.currentTimeMillis() - lastSaveTime >= 5 * 60 * 1000;
}
public long getLastSaveTime() {
return lastSaveTime;
}
public void setLastSaveTime(long lastSaveTime) {
this.lastSaveTime = lastSaveTime;
}
public long getTime() {
return time;
}
public void setTime(long time) {
this.time = time;
}
public String getCid() {
return cid;
}
public void setCid(String cid) {
this.cid = cid;
}
public int getSeq() {
return seq;
}
public void setSeq(int seq) {
this.seq = seq;
}
public int getOp() {
return op;
}
public void setOp(int op) {
this.op = op;
}
public Map<String, String> getData() {
return data;
}
public void setData(Map<String, String> data) {
this.data = data;
}
public int getStatus() {
return status;
}
public void setStatus(int status) {
this.status = status;
}
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
public void setShowMsg(Locale local){
String lang = local.getLanguage();
String showMsg = msgData.get(lang);
if(showMsg == null){
if(Language.ENGLISH.getLabel().contains(lang)){
showMsg = msgEn;
}else{
showMsg = msg;
}
}
this.msg = showMsg;
}
public Map<Integer, BoxStatusBean> getBoxStatus() {
return boxStatus;
}
public void setBoxStatus(Map<Integer, BoxStatusBean> boxStatus) {
this.boxStatus = boxStatus;
}
public boolean isAvailable(){
if(!timeOut()){
return status != StorageConstants.BOX_STATUS.EMERGENCY && status != StorageConstants.BOX_STATUS.PROBLEM && status != StorageConstants.BOX_STATUS.DEBUG;
}
return false;
}
public List<Integer> allIdleBoxIds(){
List<Integer> idleBoxIds = new ArrayList<>();
if(!timeOut()){//在线
if(StorageConstants.STATUS.OFFLINE != status){//在线
for (BoxStatusBean boxStatusBean : boxStatus.values()) {
if(boxStatusBean.boxIsIdle()){
idleBoxIds.add(boxStatusBean.getBoxId());
}
}
}
}
return idleBoxIds;
}
/**
* 所有可以出库的 box
*/
public List<Integer> allCanCheckoutBoxIds(){
List<Integer> canCheckoutBoxIds = new ArrayList<>();
if(StorageConstants.STATUS.OFFLINE != status){//在线
for (BoxStatusBean boxStatusBean : boxStatus.values()) {
if(boxStatusBean.boxCanCheckout()){
canCheckoutBoxIds.add(boxStatusBean.getBoxId());
}
}
}
return canCheckoutBoxIds;
}
/**
* 获取所有可以入库的 BOXID(用正则的|线隔开),即 BOX 可以正常使用(没有急停,故障,调试等)并且不是出库状态(正在出库时如果再分配入库有可能会出现卡死的情况,即出库要等空托盘,但入库的托盘卡在移载处)
*/
public List<Integer> allCanPutInBoxIds(){
List<Integer> canPutInBoxIds = new ArrayList<>();
String idleBoxIds = "";
for (BoxStatusBean boxStatusBean : boxStatus.values()) {
//可正常使用,且未在出库执行中
if(boxStatusBean.boxIsAvailable() && !boxStatusBean.boxIsCheckingOut()){
canPutInBoxIds.add(boxStatusBean.getBoxId());
}
}
return canPutInBoxIds;
}
/**
* 判断某个 box 是否可以执行入库操作
*/
public boolean isBoxCanPutIn(int boxId){
if(timeOut()){
return false;
}
for (BoxStatusBean boxStatusBean : boxStatus.values()) {
//可正常使用,且未在出库执行中
int bid = boxStatusBean.getBoxId();
if(bid == boxId){
if(boxStatusBean.boxIsAvailable() && !boxStatusBean.boxIsCheckingOut()){
return true;
}
return false;
}
}
return false;
}
public void updateBoxStatus(String posName, int boxStatusToChange){
int index = posName.indexOf("#");
if(index > 0){
int boxId = Integer.valueOf(posName.substring(0,index));
for (BoxStatusBean boxStatusBean : boxStatus.values()) {
if(boxStatusBean.getBoxId() == boxId){
boxStatusBean.setStatus(boxStatusToChange);
break;
}
}
}
}
public String getMsgEn() {
return msgEn;
}
public void setMsgEn(String msgEn) {
this.msgEn = msgEn;
}
public Map<String, String> getMsgData() {
return msgData;
}
public void setMsgData(Map<String, String> msgData) {
this.msgData = msgData;
}
public String getDoorReelSingnal() {
String doorReelSignal = getFromData("doorReelSignal");
if(Strings.isNullOrEmpty(doorReelSignal)){
doorReelSignal = "-1";
}
return doorReelSignal;
}
}