GreeDeviceController.java
5.9 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
package com.myproject.webapp.controller.webService;
import com.google.common.collect.Lists;
import com.myproject.bean.qisda.InquiryShelfBean;
import com.myproject.bean.qisda.ResultBean;
import com.myproject.bean.qisda.ShelfInfo;
import com.myproject.bean.qisda.ShelfLoc;
import com.myproject.bean.update.DataLog;
import com.myproject.bean.update.Storage;
import com.myproject.bean.update.qisda.OutInfo;
import com.myproject.util.StorageConstants;
import com.myproject.webapp.controller.qisda.util.OutInfoCache;
import org.apache.cxf.jaxws.handler.types.CString;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.util.Strings;
import org.apache.poi.util.Internal;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Controller
@RequestMapping(value = "/rest/api/dcs/device")
public class GreeDeviceController {
@Autowired
protected ITaskService taskService;
@Autowired
private OutInfoCache outInfoCache;
protected final static Logger log = LogManager.getLogger(QisdaDeviceController.class);
/**
* 获取当前任务数及料架的剩余空位
* 参数:rfids 料架rfid列表,逗号分割,未发送rfids只返回当前剩余任务数量
*/
@RequestMapping(value = "/getShelfEmptySlot")
@ResponseBody
public Object getTaskInfo(HttpServletRequest request) {
String rfids = request.getParameter("rfids");
try{
List<DataLog> allTasks = taskService.getAllTasks();
Map<String,Integer> hSerialTaskMap = new HashMap<>();
for (DataLog task : allTasks) {
if (!task.isFinished() && !task.isCancel() && task.isCheckOutTask()) {
String hSerial = task.getAppendInfo().gethSerial();
Integer taskCount = hSerialTaskMap.get(hSerial);
if(taskCount == null){
taskCount = 0;
}
taskCount ++;
hSerialTaskMap.put(hSerial,taskCount);
}
}
String hSerial = QisdaCache.getCurrentOrderHSerial();
List<String> usedRfidList = InquiryShelfBean.getUsedRfidList(hSerial);
Map<String,Integer> rfidMap = new HashMap<>();
if (!Strings.isBlank(rfids)) {
Integer emptyPos=0;
for (String rfid : rfids.split(",")) {
ShelfInfo shelfInfo = InquiryShelfBean.findShelfByRealRfid(rfid);
if(shelfInfo != null){
Map<Integer, ShelfLoc> locMap = shelfInfo.getLocMap();
for (ShelfLoc shelfLoc : locMap.values()) {
if(shelfLoc.isEmpty()){
emptyPos++;
}
}
}else{
//空料架
emptyPos = 100;
}
Integer hSerialTaskCount = hSerialTaskMap.get(shelfInfo.gethSerial());
if(hSerialTaskCount == null){
emptyPos = 0;
}
rfidMap.put(rfid,emptyPos);
}
}
return ResultBean.newOkResult(rfidMap);
}catch(Exception e){
log.error("获取剩余任务数出错:rfids="+rfids,e);
return ResultBean.newErrorResult(500,e.getMessage());
}
}
/**
* 获取rfid目的地出错
* 参数:rfid 料架rfid
*/
@RequestMapping(value = "/getRfidTargetP")
@ResponseBody
public Object getRfidTargetP(HttpServletRequest request) {
String rfid = request.getParameter("rfid");
try {
if (!Strings.isBlank(rfid)) {
ShelfInfo shelf = InquiryShelfBean.findShelfByRealRfid(rfid);
if (shelf != null) {
String hSerial = shelf.gethSerial();
OutInfo outInfo = outInfoCache.getOutInfoFromCache(hSerial);
if (outInfo != null) {
String line= outInfo.getLine();
log.error("获取rfid目的地成功:rfid=" + rfid + ",line=" + line + "");
return ResultBean.newOkResult(line);
} else {
log.error("获取rfid目的地失败:rfid=" + rfid + ",hSerial=" + hSerial + ",未找到工单信息");
return ResultBean.newErrorResult(3001,"未找到工单信息");
}
} else {
log.error("获取rfid目的地失败:rfid=" + rfid + ",未找到料架信息");
return ResultBean.newErrorResult(3002,"未找到料架信息");
}
}
} catch (Exception e) {
log.error("获取rfid目的地出错:rfid=" + rfid, e);
return ResultBean.newErrorResult(500,e.getMessage());
}
return ResultBean.newErrorResult(3003,"位置获取失败");
}
/**
* 料架放上AGV时,根据RFID清理料架的缓存信息,使料架可以重复使用
*/
@RequestMapping(value = "/agvRemoveRfid")
@ResponseBody
public ResultBean agvRemoveRfid(HttpServletRequest request){
String realRfid = request.getParameter("rfid");
log.info("料架放上AGV时,清理["+realRfid+"]的缓存信息");
if(Strings.isNotBlank(realRfid)){
InquiryShelfBean.agvRemoveRfid(realRfid);
}
return ResultBean.newOkResult("料架放上AGV时,清理["+realRfid+"]的缓存信息成功");
}
}