EmptyContainerController.java
12.2 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
package com.huaheng.api.wcs.controller;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.huaheng.api.wcs.domain.ManyEmptyDomain;
import com.huaheng.api.wcs.domain.WcsTask;
import com.huaheng.api.wcs.domain.WmsTask;
import com.huaheng.api.wcs.service.taskAssignService.TaskAssignService;
import com.huaheng.api.wcs.service.warecellAllocation.LocationAllocationService;
import com.huaheng.common.constant.QuantityConstant;
import com.huaheng.common.exception.service.ServiceException;
import com.huaheng.common.support.Convert;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.common.utils.http.HttpUtils;
import com.huaheng.common.utils.security.ShiroUtils;
import com.huaheng.framework.aspectj.lang.annotation.ApiLogger;
import com.huaheng.framework.aspectj.lang.annotation.Log;
import com.huaheng.framework.aspectj.lang.constant.BusinessType;
import com.huaheng.framework.web.controller.BaseController;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.framework.web.domain.RetCode;
import com.huaheng.framework.web.service.ConfigService;
import com.huaheng.pc.config.address.service.AddressService;
import com.huaheng.pc.config.container.domain.Container;
import com.huaheng.pc.config.container.service.ContainerService;
import com.huaheng.pc.config.containerType.service.ContainerTypeService;
import com.huaheng.pc.config.location.domain.Location;
import com.huaheng.pc.config.location.service.LocationService;
import com.huaheng.pc.config.locationHigh.domain.LocationHigh;
import com.huaheng.pc.config.locationHigh.service.LocationHighService;
import com.huaheng.pc.config.locationType.domain.LocationType;
import com.huaheng.pc.config.locationType.service.LocationTypeService;
import com.huaheng.pc.config.zone.domain.Zone;
import com.huaheng.pc.config.zone.service.ZoneService;
import com.huaheng.pc.inventory.inventoryHeader.service.InventoryHeaderService;
import com.huaheng.pc.system.config.service.IConfigService;
import com.huaheng.pc.task.taskHeader.domain.TaskHeader;
import com.huaheng.pc.task.taskHeader.service.ReceiptTaskService;
import com.huaheng.pc.task.taskHeader.service.TaskHeaderService;
import com.huaheng.pc.task.taskHeader.service.WorkTaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
@RestController
@RequestMapping("/API/WMS/v2")
public class EmptyContainerController extends BaseController {
@Resource
private ZoneService zoneService;
@Resource
private ContainerService containerService;
@Resource
private InventoryHeaderService inventoryHeaderService;
@Resource
private ReceiptTaskService receiptTaskService;
@Resource
private TaskHeaderService taskHeaderService;
@Resource
private IConfigService iConfigService;
@Resource
private AddressService addressService;
/**
* 生成空托入库任务
* @return
*/
@PostMapping("/wcsCallEmptyIn")
@Log(title = "任务-任务管理", operating = "生成空托入库任务", action = BusinessType.INSERT)
@ResponseBody
@ApiLogger(apiName = "生成空托入库任务", from="WCS")
public AjaxResult wcsCallEmptyIn(@RequestBody ManyEmptyDomain manyEmptyDomain) {
if(StringUtils.isEmpty(manyEmptyDomain.getContainerCode())){
throw new ServiceException("容器不能有空值!");
}
String [] data=getPltCheck(manyEmptyDomain.getContainerCode(),manyEmptyDomain.getFromLocationCode());
if (data.length<0){
return AjaxResult.error("调用三一wms空托盘校验失败");
} else{
Integer id =receiptTaskService.emptyAudoIn(manyEmptyDomain.getContainerCode(),200,data[0]);
//更新托盘是否为空
containerService.updateemptyPallet(manyEmptyDomain.getContainerCode(),data[1], ShiroUtils.getWarehouseCode());
if(id!=null){//创建任务成功,直接下发wcs
try{
taskHeaderService.sendTaskToWcs(Convert.toIntArray(id.toString()));
return AjaxResult.success("任务:"+id+":执行下发成功");
}catch(Exception e){
return AjaxResult.error("任务:"+id+":执行下发失败");
}
}else{
return AjaxResult.error("任务生产失败");
}
}
}
/**
* 生成空托出库任务
* @return
*/
@PostMapping("/wcsCallEmptyOut")
@Log(title = "任务-任务管理", operating = "生成空托出库任务", action = BusinessType.INSERT)
@ResponseBody
@ApiLogger(apiName = "生成空托出库任务", from="WCS")
public AjaxResult wcsCallEmptyOut(@RequestBody ManyEmptyDomain manyEmptyDomain) {
AjaxResult ajaxResult = handleMultiProcess(new MultiProcessListener() {
@Override
public AjaxResult doProcess() {
AjaxResult ajaxResult = innerWcsCallEmptyOut(manyEmptyDomain);
return ajaxResult;
}
});
if(ajaxResult.getCode()==200){//创建任务成功,直接下发wcs
Integer[] taskIds= {Integer.parseInt(ajaxResult.getData().toString())};
ajaxResult= taskHeaderService.sendTaskToWcs(taskIds);
}else{
return ajaxResult;
}
return ajaxResult;
}
private AjaxResult innerWcsCallEmptyOut(ManyEmptyDomain manyEmptyDomain) {
String warehouseCode = manyEmptyDomain.getWarehouseCode();
String area = manyEmptyDomain.getArea();
String port = manyEmptyDomain.getPort();
if(warehouseCode == null) {
return AjaxResult.error("warehouseCode 不能为空");
}
if(area == null) {
return AjaxResult.error("area 不能为空");
}
if(port == null) {
return AjaxResult.error("port 不能为空");
}
LambdaQueryWrapper<Zone> zoneLambdaQueryWrapper = Wrappers.lambdaQuery();
zoneLambdaQueryWrapper.eq(Zone::getWarehouseCode, warehouseCode)
.eq(Zone::getArea, area);
Zone zone = zoneService.getOne(zoneLambdaQueryWrapper);
if(zone == null) {
return AjaxResult.error("area不正确,没有找到对应区域");
}
String zoneCode = zone.getCode();
// List<Location> list = containerService.getEmptyContainerInLocation(zoneCode,
// "","", warehouseCode);
List<Container> list = containerService.getEmptyContainerOut("LK",
"","", "ZH0001");
if(list == null || list.size() <= 0) {
return AjaxResult.error("没有找到空托盘");
}
Container container = list.get(0);
String containerCode = container.getCode();
String locationCode = container.getLocationCode();
return inventoryHeaderService.createEmptyOut(containerCode, locationCode, port, warehouseCode);
}
@PostMapping("/emptyContainerJudge")
@Log(title = "任务-任务管理", operating = "判断是否为空托盘", action = BusinessType.INSERT)
@ResponseBody
@Transactional
public AjaxResult emptyContainerJudge(@RequestBody ManyEmptyDomain manyEmptyDomain) {
JSONObject data = new JSONObject();
if(manyEmptyDomain.getContainerCode() == null){
data.put("code", RetCode.FAIL);
data.put("msg", "容器编号为空");
throw new ServiceException("容器编号为空!");
}
else if(containerExit(manyEmptyDomain.getContainerCode())==false){
data.put("code", RetCode.FAIL);
data.put("msg", "库位没有该容器");
throw new ServiceException("库位没有该容器!");
}else{
//1:空托盘,0:非空托盘
String emptyPallet=getPltCheckIn(manyEmptyDomain.getContainerCode());
if(emptyPallet.equals("1")){
data.put("code", RetCode.SUCCESS);
data.put("msg", manyEmptyDomain.getContainerCode()+":校验通过");
data.put("emptyPallet", emptyPallet);
return AjaxResult.success(data);
}else{
// data.put("msg", manyEmptyDomain.getContainerCode()+":校验未通过");
// data.put("code", RetCode.FAIL);
// data.put("emptyPallet", emptyPallet);
return AjaxResult.error(manyEmptyDomain.getContainerCode()+":校验未通过");
}
}
}
/**
* 方法描述 判断容器是否存在
* @param: [containercode]
* @return: java.lang.Integer
* @author: chenao
* @date: 2021/11/12
*/
public boolean containerExit(String containercode){
LambdaQueryWrapper<Container> lambdaQueryWrapper = Wrappers.lambdaQuery();
lambdaQueryWrapper.eq(Container::getCode, containercode);
List<Container> list = containerService.list(lambdaQueryWrapper);
return list.size()>0?true:false;
}
public String [] getPltCheck(String containercode,String fromLocationCode){
WmsTask wmsTask=new WmsTask();
String emptyPallet="";
String taskNo="";
JSONObject json=new JSONObject();
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
wmsTask.setContainerCode(containercode);
wmsTask.setReqID(iConfigService.getRegId());
wmsTask.setRequestTime(df.format(new Date()));
wmsTask.setContainerCode(containercode);
wmsTask.setFromLocationCode(fromLocationCode);
String JsonParam = JSON.toJSONString(wmsTask);
String url = addressService.selectAddress(QuantityConstant.ADDRESS_WMS_EMPTY_JUDGE, "ZH0001", "1");
String result = HttpUtils.bodypost(url, JsonParam);
json=JSONObject.parseObject(result);
String [] data;
System.out.println("aaaaaaaaa:"+json.getString("data"));
if (json.getString("code").equals("1")){
JSONObject jsondata=JSONObject.parseObject(json.getString("data"));
taskNo=jsondata.getString("taskNo");
emptyPallet=jsondata.getString("emptyPallet");
data=new String[2];
data[0]=taskNo;
data[1]=emptyPallet;
}else{
data=null;
}
return data;
}
public String getPltCheckIn(String containercode){
//根据托盘号查询刚下发的任务 站台
LambdaQueryWrapper<TaskHeader>queryWrapper=Wrappers.lambdaQuery();
queryWrapper.eq(TaskHeader::getContainerCode,containercode)
.eq(TaskHeader::getStatus,1)
.last("limit 1");
TaskHeader task=taskHeaderService.getOne(queryWrapper);
String port="";
if (task!=null){
if(StringUtils.isNotEmpty(task.getPort())){
port=task.getPort();
}
}
WmsTask wmsTask=new WmsTask();
String emptyPallet="";
JSONObject json=new JSONObject();
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
wmsTask.setContainerCode(containercode);
wmsTask.setReqID(iConfigService.getRegId());
wmsTask.setRequestTime(df.format(new Date()));
wmsTask.setContainerCode(containercode);
wmsTask.setFromLocationCode(port);
String JsonParam = JSON.toJSONString(wmsTask);
String url = addressService.selectAddress(QuantityConstant.ADDRESS_WMS_EMPTY_JUDGE, "ZH0001", "1");
String result = HttpUtils.bodypost(url, JsonParam);
json=JSONObject.parseObject(result);
String code=json.getString("code");
if (code.equals("1")){
JSONObject jsondata=JSONObject.parseObject(json.getString("data"));
//taskNo=jsondata.getString("taskNo");
emptyPallet=jsondata.getString("emptyPallet");
//更新托盘是否为空
containerService.updateemptyPallet(containercode,emptyPallet,ShiroUtils.getWarehouseCode());
}
return code;
}
}