|
1
2
|
package com.huaheng.api.mes.controller;
|
|
3
4
|
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
|
|
5
6
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
7
8
9
|
import com.huaheng.api.mes.dto.*;
import com.huaheng.api.mes.dto.otherReceipt.OtherReceiptDetail;
import com.huaheng.api.mes.dto.otherReceipt.OtherReceiptHeader;
|
|
10
|
import com.huaheng.api.mes.result.ReturnInfo;
|
|
11
|
import com.huaheng.api.mes.service.IMesService;
|
|
12
13
|
import com.huaheng.api.mes.utils.CallaMOM;
import com.huaheng.api.mes.utils.SqlServer;
|
|
14
|
import com.huaheng.api.mes.vo.InventoryVO;
|
|
15
|
import com.huaheng.api.mes.vo.InventoryTransactionVO;
|
|
16
|
import com.huaheng.common.constant.QuantityConstant;
|
|
17
|
import com.huaheng.common.exception.service.ServiceException;
|
|
18
|
import com.huaheng.common.utils.StringUtils;
|
|
19
|
import com.huaheng.common.utils.reflect.ReflectUtils;
|
|
20
|
import com.huaheng.common.utils.security.ShiroUtils;
|
|
21
22
23
24
|
import com.huaheng.framework.aspectj.lang.annotation.ApiLogger;
import com.huaheng.framework.web.controller.BaseController;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.framework.web.domain.RetCode;
|
|
25
|
import com.huaheng.pc.config.address.service.AddressService;
|
|
26
|
import com.huaheng.pc.config.material.domain.Material;
|
|
27
|
import com.huaheng.pc.config.material.service.MaterialService;
|
|
28
29
|
import com.huaheng.pc.inventory.inventoryDetail.domain.InventoryDetail;
import com.huaheng.pc.inventory.inventoryDetail.service.InventoryDetailService;
|
|
30
31
|
import com.huaheng.pc.inventory.inventoryTransaction.domain.InventoryTransaction;
import com.huaheng.pc.inventory.inventoryTransaction.service.InventoryTransactionService;
|
|
32
|
import com.huaheng.pc.momLog.service.IMomLogService;
|
|
33
34
35
36
37
38
39
40
|
import com.huaheng.pc.receipt.receiptDetail.domain.ReceiptDetail;
import com.huaheng.pc.receipt.receiptDetail.service.ReceiptDetailService;
import com.huaheng.pc.receipt.receiptHeader.domain.ReceiptHeader;
import com.huaheng.pc.receipt.receiptHeader.service.ReceiptHeaderService;
import com.huaheng.pc.shipment.shipmentDetail.domain.ShipmentDetail;
import com.huaheng.pc.shipment.shipmentDetail.service.ShipmentDetailService;
import com.huaheng.pc.shipment.shipmentHeader.domain.ShipmentHeader;
import com.huaheng.pc.shipment.shipmentHeader.service.ShipmentHeaderService;
|
|
41
42
|
import com.huaheng.pc.shipment.shipmentHeaderHistory.domain.ShipmentHeaderHistory;
import com.huaheng.pc.shipment.shipmentHeaderHistory.service.ShipmentHeaderHistoryService;
|
|
43
44
|
import com.huaheng.pc.system.user.domain.User;
import com.huaheng.pc.system.user.service.IUserService;
|
|
45
46
|
import com.huaheng.pc.task.taskDetail.domain.TaskDetail;
import com.huaheng.pc.task.taskDetail.service.TaskDetailService;
|
|
47
|
import io.swagger.annotations.ApiOperation;
|
|
48
|
import lombok.extern.slf4j.Slf4j;
|
|
49
50
|
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
|
|
51
|
import org.springframework.beans.BeanUtils;
|
|
52
53
54
|
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
|
|
55
|
import java.io.UnsupportedEncodingException;
|
|
56
57
58
59
|
import java.sql.ResultSet;
import java.sql.SQLException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
|
|
60
|
import java.util.*;
|
|
61
|
|
|
62
|
|
|
63
|
@RestController
|
|
64
|
@Slf4j
|
|
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
@RequestMapping("/API/WMS/v2")
public class MesReceiptController extends BaseController {
@Resource
private ReceiptHeaderService receiptHeaderService;
@Resource
private ReceiptDetailService receiptDetailService;
@Resource
private ShipmentHeaderService shipmentHeaderService;
@Resource
private ShipmentDetailService shipmentDetailService;
@Resource
private InventoryDetailService inventoryDetailService;
|
|
83
84
85
|
@Resource
private TaskDetailService taskDetailService;
|
|
86
87
88
89
|
@Resource
private InventoryTransactionService inventoryTransactionService;
@Resource
|
|
90
91
|
private ShipmentHeaderHistoryService shipmentHeaderHistoryService;
@Resource
|
|
92
93
|
private MaterialService materialService;
|
|
94
95
|
@Resource
private IMomLogService momLogService;
|
|
96
97
|
@Resource
private IMesService mesService;
|
|
98
99
|
@Resource
private IUserService userService;
|
|
100
|
|
|
101
102
103
|
@Resource
private AddressService addressService;
|
|
104
|
@PostMapping("/receipt")
|
|
105
|
@ApiLogger(apiName = "添加入库单及其明细", from = "ROBOT")
|
|
106
107
|
@ApiOperation("添加入库单及其明细")
public AjaxResult receipt(@RequestBody ReceiptDTO receiptDTO) {
|
|
108
109
110
|
AjaxResult ajaxResult = handleQuest("receipt", new MultiProcessListener() {
@Override
public AjaxResult doProcess() {
|
|
111
|
return mesService.receipt(receiptDTO);
|
|
112
|
}
|
|
113
114
|
});
return ajaxResult;
|
|
115
116
|
}
|
|
117
|
|
|
118
119
|
/**
* 添加出库单及其明细
|
|
120
|
*
|
|
121
122
123
124
|
* @param receiptDTO
* @return
*/
@PostMapping("/shipment")
|
|
125
|
@ApiLogger(apiName = "添加出库单及其明细", from = "ROBOT")
|
|
126
127
|
@ApiOperation("添加出库单及其明细")
public AjaxResult shipment(@RequestBody ReceiptDTO receiptDTO) {
|
|
128
129
130
|
AjaxResult ajaxResult = handleQuest("shipment", new MultiProcessListener() {
@Override
public AjaxResult doProcess() {
|
|
131
|
return mesService.shipment(receiptDTO);
|
|
132
|
}
|
|
133
|
});
|
|
134
|
return ajaxResult;
|
|
135
136
|
}
|
|
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
|
private JSONObject getJsonObject(Header header, List<Detail> details) {
JSONObject data = new JSONObject();
JSONObject Rd_In_M = new JSONObject();
Rd_In_M.put("MGPK", header.getId());
Rd_In_M.put("cCode", header.getReferCode());
JSONArray Rd_In_S = new JSONArray();
details.forEach(detail -> {
JSONObject json = new JSONObject();
json.put("MGPK", header.getId());
json.put("SGPK", detail.getId());
json.put("cInvCode", detail.getMaterialCode());
Rd_In_S.add(json);
});
data.put("Requester", "WMS");
data.put("Rd_In_M", Rd_In_M);
data.put("Rd_In_S", Rd_In_S);
return data;
}
|
|
156
|
|
|
157
158
|
/**
* 入库单参数_判空处理
|
|
159
|
*
|
|
160
161
162
163
|
* @param ajaxResult
* @param shipmentHeader
* @param shipemtnDetails
*/
|
|
164
|
private boolean enterIsNull(AjaxResult ajaxResult, Header shipmentHeader, List<Detail> shipemtnDetails) {
|
|
165
|
|
|
166
|
if (isNullData(ajaxResult, shipmentHeader, shipemtnDetails)) {
|
|
167
168
|
return true;
}
|
|
169
170
171
172
173
174
175
|
if (StringUtils.isEmpty(shipmentHeader.getRefeCodeType())) {
ajaxResult.setCode(RetCode.FAIL).setMsg("单据类型不能为空!!!");
return true;
} else if (StringUtils.isEmpty(shipmentHeader.getReferCode())) {
ajaxResult.setCode(RetCode.FAIL).setMsg("单据单号不能为空!!!");
return true;
|
|
176
|
} else if (shipmentHeader.getTotalQty() == null || shipmentHeader.getTotalQty().intValue() <= 0) {
|
|
177
|
ajaxResult.setCode(RetCode.FAIL).setMsg("数量不能为空!!!");
|
|
178
179
|
}
|
|
180
|
shipemtnDetails.forEach(shipemtnDetail -> {
|
|
181
182
|
if (StringUtils.isEmpty(shipemtnDetail.getMaterialCode())) {
ajaxResult.setCode(RetCode.FAIL).setMsg("物料编码不能为空!!!");
|
|
183
184
|
} else if (shipemtnDetail.getTotalQty() == null || shipemtnDetail.getQty().intValue() <= 0) {
ajaxResult.setCode(RetCode.FAIL).setMsg("数量不能为空!!!");
|
|
185
186
187
188
189
190
191
|
}
});
return StringUtils.isNotEmpty(ajaxResult.getMsg());
}
/**
* 出库单参数_判空处理
|
|
192
|
*
|
|
193
194
195
196
|
* @param ajaxResult
* @param shipmentHeader
* @param shipemtnDetails
*/
|
|
197
198
|
private boolean outIsNull(AjaxResult ajaxResult, Header shipmentHeader, List<Detail> shipemtnDetails) {
if (isNullData(ajaxResult, shipmentHeader, shipemtnDetails)) {
|
|
199
200
|
return true;
}
|
|
201
202
203
204
205
206
|
if (StringUtils.isEmpty(shipmentHeader.getReferCode())) {
ajaxResult.setCode(RetCode.FAIL).setMsg("单据单号不能为空!!!");
return true;
}
|
|
207
|
shipemtnDetails.forEach(shipemtnDetail -> {
|
|
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
|
if (StringUtils.isEmpty(shipemtnDetail.getMaterialCode())) {
ajaxResult.setCode(RetCode.FAIL).setMsg("物料编码不能为空!!!");
}
});
return StringUtils.isNotEmpty(ajaxResult.getMsg());
}
/**
* 判空处理
*/
private boolean isNullData(AjaxResult ajaxResult, Header shipmentHeader, List<Detail> shipemtnDetails) {
if (shipmentHeader == null) {
ajaxResult.setCode(RetCode.FAIL).setMsg("出库单头表不能为空!!!");
return true;
} else if (shipemtnDetails == null || shipemtnDetails.size() < 1) {
ajaxResult.setCode(RetCode.FAIL).setMsg("出库单明细表集不能为空!!!");
return true;
}
return false;
}
/**
|
|
230
|
* 入库单单据取消
|
|
231
|
*/
|
|
232
233
|
@PostMapping("/cancelEnterWarehouse")
@ApiOperation("入库单单据取消")
|
|
234
|
@ApiLogger(apiName = "入库单单据取消", from = "ROBOT")
|
|
235
|
public AjaxResult cancelEnterWarehouse(@RequestBody ReceiptDTO receiptDTO) {
|
|
236
237
238
239
240
|
AjaxResult ajaxResult = handleQuest("cancelEnterWarehouse", new MultiProcessListener() {
@Override
public AjaxResult doProcess() {
AjaxResult ajaxResult = mesService.cancelEnterWarehouse(receiptDTO);
return ajaxResult;
|
|
241
|
}
|
|
242
243
|
});
return ajaxResult;
|
|
244
245
246
247
248
249
250
251
|
}
/**
* 出库单单据取消
*/
@PostMapping("/cancelOutWarehouse")
@ApiOperation("出库单单据取消")
|
|
252
|
@ApiLogger(apiName = "出库单单据取消", from = "ROBOT")
|
|
253
|
public AjaxResult cancelOutWarehouse(@RequestBody ReceiptDTO receiptDTO) {
|
|
254
255
256
257
258
|
AjaxResult ajaxResult = handleQuest("cancelOutWarehouse", new MultiProcessListener() {
@Override
public AjaxResult doProcess() {
AjaxResult ajaxResult = mesService.cancelOutWarehouse(receiptDTO);
return ajaxResult;
|
|
259
|
}
|
|
260
261
|
});
return ajaxResult;
|
|
262
263
264
265
266
267
268
269
270
271
|
}
private AjaxResult isNull(Header header, List<Detail> details) {
AjaxResult ajaxResult = new AjaxResult();
boolean isNull = outIsNull(ajaxResult, header, details);
details.forEach(detail -> {
if (detail.getTotalQty() == null || detail.getTotalQty().intValue() <= 0) {
ajaxResult.setCode(RetCode.FAIL).setMsg("总数量不能为空!!!");
}
});
|
|
272
|
if (isNull || StringUtils.isNotEmpty(ajaxResult.getMsg())) {
|
|
273
274
|
return ajaxResult;
}
|
|
275
|
return ajaxResult;
|
|
276
277
278
279
280
281
|
}
/**
* 查询库存
*/
@PostMapping("/searchInventory")
|
|
282
|
@ApiLogger(apiName = "查询库存", from = "ROBOT")
|
|
283
284
285
|
@ApiOperation("查询库存")
public AjaxResult searchInventory(@RequestBody Detail detailed) {
|
|
286
287
288
289
290
291
292
293
294
295
296
297
298
|
//List<ShipmentHeader> shipmentHeaders = shipmentHeaderService.list(new LambdaQueryWrapper<ShipmentHeader>()
// .gt(ShipmentHeader::getFirstStatus, QuantityConstant.SHIPMENT_CONTAINER_BUILD)
// .ne(ShipmentHeader::getPushSuccessStatus, 1));
//
//List<ShipmentDetail> shipmentDetails = new ArrayList<>();
//for (ShipmentHeader shipmentHeader : shipmentHeaders) {
// List<ShipmentDetail> details = shipmentDetailService.list(new LambdaQueryWrapper<ShipmentDetail>()
// .gt(ShipmentDetail::getTaskQty, 0)
// .eq(ShipmentDetail::getShipmentId, shipmentHeader.getId()));
// shipmentDetails.addAll(details);
//}
|
|
299
|
String materialName = detailed.getMaterialName();
|
|
300
|
String materialCode = detailed.getMaterialCode();
|
|
301
|
String containerCode = detailed.getContainerCode();
|
|
302
|
|
|
303
304
|
LambdaQueryWrapper<InventoryDetail> lambdaQueryWrapper = Wrappers.lambdaQuery();
// 物料编码
|
|
305
|
if (StringUtils.isNotEmpty(materialName)) {
|
|
306
307
|
lambdaQueryWrapper.eq(InventoryDetail::getMaterialName, materialName);
}
|
|
308
|
// 物料名称
|
|
309
|
if (StringUtils.isNotEmpty(materialCode)) {
|
|
310
311
|
lambdaQueryWrapper.eq(InventoryDetail::getMaterialCode, materialCode);
}
|
|
312
|
// 托盘号
|
|
313
|
if (StringUtils.isNotEmpty(containerCode)) {
|
|
314
315
|
lambdaQueryWrapper.eq(InventoryDetail::getContainerCode, containerCode);
}
|
|
316
|
|
|
317
|
if (StringUtils.isEmpty(materialName) && StringUtils.isEmpty(containerCode) && StringUtils.isEmpty(containerCode)) {
|
|
318
319
|
lambdaQueryWrapper.gt(InventoryDetail::getQty, 0);
}
|
|
320
|
List<InventoryDetail> detailList = inventoryDetailService.list(lambdaQueryWrapper);
|
|
321
|
|
|
322
|
List<InventoryVO> inventoryVOList = new ArrayList<>();
|
|
323
|
detailList.forEach(detail -> {
|
|
324
|
InventoryVO inventoryVO = new InventoryVO();
|
|
325
|
BeanUtils.copyProperties(detail, inventoryVO);
|
|
326
|
inventoryVO.setWarehouse("035");
|
|
327
|
inventoryVOList.add(inventoryVO);
|
|
328
329
|
});
|
|
330
|
return AjaxResult.success(inventoryVOList);
|
|
331
332
333
334
|
}
/**
|
|
335
|
* 获取出入库单明细记录
|
|
336
|
*
|
|
337
338
339
|
* @return AjaxResult
*/
@PostMapping("/getShipmentDetail")
|
|
340
|
@ApiLogger(apiName = "获取出入库单明细记录", from = "ROBOT")
|
|
341
|
@ApiOperation("获取出入库单明细记录")
|
|
342
343
|
public AjaxResult getShipmentDetail(@RequestBody GetOrderHistoryDTO getOrderHistoryDTO) {
|
|
344
|
if (StringUtils.isEmpty(getOrderHistoryDTO.getEndTime()) || StringUtils.isEmpty(getOrderHistoryDTO.getStartTime())) {
|
|
345
346
|
return AjaxResult.error("开始时间和结束时间不能为空!!!");
}
|
|
347
|
LambdaQueryWrapper<InventoryTransaction> lambdaQueryWrapper = Wrappers.lambdaQuery();
|
|
348
|
lambdaQueryWrapper
|
|
349
350
351
352
353
354
355
356
357
358
|
.ge(InventoryTransaction::getCreated, getOrderHistoryDTO.getStartTime())
.le(InventoryTransaction::getCreated, getOrderHistoryDTO.getEndTime());
List<InventoryTransaction> list = inventoryTransactionService.list(lambdaQueryWrapper);
List<InventoryTransactionVO> inventoryTransactionVOList = new ArrayList<>();
list.forEach(inventoryTransaction -> {
InventoryTransactionVO inventoryTransactionVO = new InventoryTransactionVO();
BeanUtils.copyProperties(inventoryTransaction, inventoryTransactionVO);
inventoryTransactionVOList.add(inventoryTransactionVO);
});
return AjaxResult.success(inventoryTransactionVOList);
|
|
359
360
361
362
363
364
365
|
}
/**
* 获取sqlServer数据库中物料信息, 同步到本地数据库中
*/
@PostMapping("/getMaterial")
@ApiOperation("获取外部物料信息")
|
|
366
|
public List<Material> getMaterial() {
|
|
367
|
List<Material> materialList = new ArrayList<>();
|
|
368
|
log.error("开始同步物料信息!!!");
|
|
369
370
371
|
// 获取新增一天以内和修改四个小时以内的物料数据
//DATEDIFF() 函数返回两个日期之间的天数。
|
|
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
|
final String SQL_QUERY = "SELECT\n" +
"\ta.cinvcode AS '存货编码',\n" +
"\ta.cinvname AS '存货名称',\n" +
"\ta.cDefWareHouse AS '仓库',\n" +
"\te.cWhName AS '仓库名称',\n" +
"\ta.cComUnitCode AS '单位编码',\n" +
"\tb.cComUnitName AS '单位名称',\n" +
"\tc.cidefine6 AS '外形尺寸',\n" +
"\tc.cidefine7 AS '托盘类型',\n" +
"\ta.dModifyDate AS '修改时间',\n" +
"\ta.dSDate AS '启用时间',\n" +
"\ta.cinvstd AS '规格',\n" +
"\ta.Iinvweight AS '重量',\n" +
"\tA.CPLANMETHOD AS '属性',\n" +
"\ta.cinvccode AS '存货类别编码',\n" +
"\td.cInvCName AS '存货类别名称',\n" +
"\ta.cSRPolicy AS '供需政策',\n" +
"\tc.cidefine8 AS '是否批次',\n" +
"\tc.cidefine9 AS '是否可燃',\n" +
"\tc.cidefine10 AS '是否平库' \n" +
"FROM\n" +
"\tInventory a\n" +
"\tLEFT JOIN ComputationUnit b ON a.cComUnitCode= b.cComUnitCode\n" +
"\tLEFT JOIN Inventory_extradefine c ON a.cinvcode= c.cinvcode\n" +
"\tLEFT JOIN InventoryClass d ON a.cinvccode= d.cinvccode\n" +
"\tLEFT JOIN Warehouse e ON a.cDefWareHouse = e.cWhCode \n" +
"WHERE\n" +
"\t(\n" +
"\t\tdatediff( DAY, a.dSDate, getdate( ) ) = 0 \n" +
"\t\tOR a.dModifyDate >= DATEADD( HOUR, - 4, GETDATE( ) ) \n" +
"\t) \n" +
"\tAND a.cDefWareHouse IN ( '035', '001', '003' )";
|
|
404
|
|
|
405
|
try {
|
|
406
407
|
ResultSet resultSet = SqlServer.find(SQL_QUERY);
|
|
408
|
if (resultSet == null) {
|
|
409
410
|
return materialList;
}
|
|
411
|
while (resultSet.next()) {
|
|
412
|
// 字段要一致
|
|
413
414
415
|
Material material = new Material();
material.setWarehouseCode("CS0001");
material.setCompanyCode("BHF");
|
|
416
|
|
|
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
|
material.setCode(resultSet.getString("存货编码")); // 物料编码
material.setName(resultSet.getString("存货名称")); // 物料名称
material.setDefWareHouse(resultSet.getString("仓库")); // u8仓库
material.setCWhName(resultSet.getString("仓库名称")); // 单位编码
material.setUnitCode(resultSet.getString("单位编码"));
material.setUnit(resultSet.getString("单位名称"));
material.setPhysicalDimension(resultSet.getString("外形尺寸"));
material.setIsHigh("高托".equals(resultSet.getString("托盘类型")) ? 1 : 0);
material.setSpec(resultSet.getString("规格"));
material.setWeight(resultSet.getString("重量"));
material.setCinvccode(resultSet.getString("存货类别编码"));
material.setCInvCName(resultSet.getString("存货类别名称"));
material.setAttribute(resultSet.getString("属性"));
material.setPolicy(resultSet.getString("供需政策"));
material.setIsBatch(resultSet.getString("是否批次"));
material.setIsFlammable(resultSet.getString("是否可燃"));
material.setIsFlat(resultSet.getString("是否平库"));
|
|
434
435
|
materialList.add(material);
}
|
|
436
437
|
} catch (SQLException e) {
log.error("同步海王物料失败!!!" + e.getMessage());
|
|
438
439
|
}
return materialList;
|
|
440
|
}
|
|
441
|
|
|
442
443
444
|
/**
* 当前时间向推几小时
*/
|
|
445
446
447
448
449
450
451
452
453
454
455
456
457
|
public String dateRoll(int ihour) {
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
// 获取当前时间
LocalDateTime date = LocalDateTime.now();
// 获取当前时间的前几小时时间
LocalDateTime localDateTime = date.minusHours(ihour);
return dateTimeFormatter.format(localDateTime);
}
/**
* 查询站台任务明细列表
*/
|
|
458
|
@ApiLogger(apiName = "查询站台任务明细列表", from = "ROBOT")
|
|
459
|
@PostMapping("/kanbanInfo")
|
|
460
|
@CrossOrigin
|
|
461
|
public AjaxResult kanbanInfo(@RequestBody TaskDetail taskDetail) {
|
|
462
|
String fromLocation = taskDetail.getFromLocation();
|
|
463
|
if (StringUtils.isEmpty(fromLocation)) {
|
|
464
|
return AjaxResult.error("站台不能为空!!!");
|
|
465
|
}
|
|
466
467
|
LambdaQueryWrapper<TaskDetail> wrapper = Wrappers.lambdaQuery();
wrapper.eq(TaskDetail::getFromLocation, fromLocation)
|
|
468
|
.lt(TaskDetail::getStatus, "100");
|
|
469
470
471
472
|
List<TaskDetail> taskDetailList = taskDetailService.list(wrapper);
return AjaxResult.success(taskDetailList);
}
|
|
473
|
/**
|
|
474
|
* post调用E_Rd_In(MOM)入库成功接口
|
|
475
|
*/
|
|
476
|
//@ApiLogger(apiName = "post调用E_Rd_In(MOM)入库接口", from="ROBOT")
|
|
477
|
@PostMapping("/postE_Rd_In")
|
|
478
|
public ReturnInfo postE_Rd_In(@RequestBody ReceiptDetail receiptDetail) {
|
|
479
480
481
482
483
|
if (StringUtils.isNotBlank(receiptDetail.getLastUpdatedBy())) {
receiptDetail.setLastUpdatedBy("PDA");
} else if (StringUtils.isNotEmpty(ShiroUtils.getName())) {
receiptDetail.setLastUpdatedBy(ShiroUtils.getName());
}
|
|
484
|
User user = userService.selectUserByEmail(receiptDetail.getLastUpdatedBy());
|
|
485
486
487
488
489
490
491
|
String loginName = "";
if (user == null) {
loginName = "PDA";
} else {
loginName = user.getLoginName();
}
ReceiptHeader receiptHeader = receiptHeaderService.getById(receiptDetail.getReceiptId());
|
|
492
|
JSONObject Rd_In_M = new JSONObject();
|
|
493
494
|
Rd_In_M.put("mno", receiptHeader.getCode());
Rd_In_M.put("MGPK", receiptHeader.getMOMID());
|
|
495
496
497
|
Rd_In_M.put("cBusType", receiptHeader.getReceiptType());
Rd_In_M.put("TAID", receiptHeader.getTAID());
Rd_In_M.put("FAID", receiptHeader.getFAID());
|
|
498
|
Rd_In_M.put("UserNo", loginName);
|
|
499
|
Rd_In_M.put("warehouse", receiptHeader.getWarehouse());
|
|
500
|
|
|
501
|
JSONArray jsonArray = new JSONArray();
|
|
502
|
JSONObject Rd_In_S = new JSONObject();
|
|
503
504
505
|
List<TaskDetail> taskDetails = taskDetailService.list(new LambdaQueryWrapper<TaskDetail>().eq(TaskDetail::getBillDetailId, receiptDetail.getId()));
if (!taskDetails.isEmpty()) {
if (taskDetails.get(0).getFlat() != null && taskDetails.get(0).getFlat() == 1) {
|
|
506
507
508
509
510
511
|
Rd_In_S.put("cidefine10", "平库");
}
Rd_In_S.put("cidefine10", "立库");
} else {
Rd_In_S.put("cidefine10", "错误:未查询到任务!");
}
|
|
512
513
514
515
|
Rd_In_S.put("MGPK", receiptHeader.getMOMID());
Rd_In_S.put("SGPK", receiptDetail.getMOMID());
Rd_In_S.put("SNNO", receiptDetail.getSNNO());
Rd_In_S.put("cInvCode", receiptDetail.getMaterialCode());
|
|
516
517
|
Rd_In_S.put("Iquantity", receiptDetail.getTaskQty());
Rd_In_S.put("iFQuantity", receiptDetail.getQty());
|
|
518
|
Rd_In_S.put("cwhcode", "035");
|
|
519
520
521
522
523
|
Rd_In_S.put("MOCode", receiptDetail.getNoticeNo());
Rd_In_S.put("ISUrgent", receiptDetail.getIsUrgent());
Rd_In_S.put("receiptBarcode", receiptDetail.getReceiptBarcode());
Rd_In_S.put("warehouse", receiptHeader.getWarehouse());
Rd_In_S.put("warehouseName", receiptHeader.getWarehouseName());
|
|
524
|
Rd_In_S.put("creatorCode", loginName);
|
|
525
|
Rd_In_S.put("creatorName", receiptDetail.getLastUpdatedBy());
|
|
526
527
|
Rd_In_S.put("productionWorker", receiptHeader.getProductionWorker());
Rd_In_S.put("productionWorkerName", receiptHeader.getProductionWorkerName());
|
|
528
529
530
|
Rd_In_S.put("ifrom", receiptDetail.getIfrom());
Rd_In_S.put("LMPKID", receiptDetail.getLMPKID());
Rd_In_S.put("LSPKID", receiptDetail.getLSPKID());
|
|
531
532
533
534
535
536
537
538
|
jsonArray.add(Rd_In_S);
JSONObject data = new JSONObject();
data.put("Rd_In_M", Rd_In_M);
data.put("Rd_In_S", jsonArray);
String action = "E_Rd_In";
JSONObject json = new JSONObject();
json.put("data", data);
|
|
539
|
return postMOM(action, json, "入库回传");
|
|
540
541
542
543
544
545
|
}
/**
* post调用E_Rd_In(MOM)其他入库成功接口
*/
|
|
546
|
//@ApiLogger(apiName = "post调用E_Rd_In(MOM)其他入库接口", from="ROBOT")
|
|
547
|
@PostMapping("/postOther_E_Rd_In")
|
|
548
|
public ReturnInfo postOther_E_Rd_In(@RequestBody List<ReceiptDetail> receiptDetails, ReceiptHeader receiptHeader) {
|
|
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
|
OtherReceiptDomain domain = new OtherReceiptDomain();
OtherReceiptHeader receiptHeader1 = new OtherReceiptHeader();
receiptHeader1.setCode(receiptHeader.getCode());
receiptHeader1.setMomId(receiptHeader.getMOMID());
receiptHeader1.setReceiptType(receiptHeader.getReceiptType());
receiptHeader1.setTaId(receiptHeader.getTAID());
receiptHeader1.setFaId(receiptHeader.getFAID());
receiptHeader1.setLastUpdatedBy(receiptHeader.getLastUpdatedBy());
receiptHeader1.setWarehouse(receiptHeader.getWarehouse());
receiptHeader1.setDepCode(QuantityConstant.DEFAULT_DEPT);
receiptHeader1.setStock(QuantityConstant.DEFAULT_STOCK);
List<OtherReceiptDetail> list = new ArrayList<>();
for (ReceiptDetail receiptDetail : receiptDetails) {
OtherReceiptDetail detail = new OtherReceiptDetail();
|
|
565
566
567
|
List<TaskDetail> taskDetails = taskDetailService.list(new LambdaQueryWrapper<TaskDetail>().eq(TaskDetail::getBillDetailId, receiptDetail.getId()));
if (!taskDetails.isEmpty()) {
if (taskDetails.get(0).getFlat() != null && taskDetails.get(0).getFlat() == 1) {
|
|
568
569
570
571
572
573
|
detail.setIsFlat("平库");
}
detail.setIsFlat("立库");
} else {
detail.setIsFlat("错误:未查询到任务!");
}
|
|
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
|
detail.setMomIdByHeader(receiptHeader.getMOMID());
detail.setMomId(receiptDetail.getMOMID());
detail.setSnNo(receiptDetail.getSNNO());
detail.setMaterialCode(receiptDetail.getMaterialCode());
detail.setTaskQty(receiptDetail.getTaskQty());
detail.setQty(receiptDetail.getQty());
detail.setWarehouseCode(receiptDetail.getWarehouseCode());
detail.setNotice(receiptDetail.getNoticeNo());
detail.setISUrgent(receiptDetail.getIsUrgent());
detail.setReceiptBarcode(receiptDetail.getReceiptBarcode());
detail.setWarehouse(receiptHeader.getWarehouse());
detail.setWarehouseName(receiptHeader.getWarehouseName());
detail.setLastUpdatedBy(receiptDetail.getLastUpdatedBy());
detail.setLastUpdatedByName(receiptDetail.getLastUpdatedByName());
detail.setProductionWorker(receiptHeader.getProductionWorker());
detail.setProductionWorkerName(receiptHeader.getProductionWorkerName());
list.add(detail);
}
domain.setReceiptHeader(receiptHeader1);
domain.setReceiptDetails(list);
//返回实体
ReturnDomain data = new ReturnDomain();
data.setData(domain);
String str = JSONObject.toJSONString(data);
JSONObject jsonObject = JSONObject.parseObject(str);
|
|
600
|
return postMOM("E_Rd_In", jsonObject, "其他入库回传");
|
|
601
602
603
|
}
/**
|
|
604
|
* post调用E_Rd_In(MOM)出库成功接口
|
|
605
|
*/
|
|
606
|
//@ApiLogger(apiName = "post调用E_Rd_Out(MOM)出库接口", from="ROBOT")
|
|
607
|
@PostMapping("/postE_Rd_Out")
|
|
608
|
public Boolean postE_Rd_Out(@RequestBody ShipmentHeader shipmentHeader) {
|
|
609
|
// ShipmentHeader shipmentHeader = shipmentHeaderService.getById(shipmentHeaderID.getId());
|
|
610
|
//StringBuffer keyField = new StringBuffer();
|
|
611
612
|
JSONArray dataArray = new JSONArray();
// 如果订单为合并类型
|
|
613
|
if ("merge".equals(shipmentHeader.getShipmentType())) {
|
|
614
|
// 查询所有子表
|
|
615
|
List<ShipmentDetail> shipmentDetailList = shipmentDetailService.list(new LambdaQueryWrapper<ShipmentDetail>().eq(ShipmentDetail::getShipmentId, shipmentHeader.getId()));
|
|
616
|
// 查询所有合并前的头表
|
|
617
618
619
620
621
622
623
|
StringBuilder ids = new StringBuilder();
for (ShipmentDetail shipmentDetail : shipmentDetailList) {
ids.append(",").append(shipmentDetail.getRecordCode());
}
String codes = ids.substring(1, ids.length());
String[] headerIdArr = codes.split(",");
|
|
624
|
List<ShipmentHeader> shipmentHeaderList = new ArrayList<>();
|
|
625
626
627
628
629
630
631
|
List<ShipmentHeaderHistory> list2 = shipmentHeaderHistoryService.list(new LambdaQueryWrapper<ShipmentHeaderHistory>().in(ShipmentHeaderHistory::getCode, headerIdArr));
for (ShipmentHeaderHistory shipmentHeaderHistory : list2) {
ShipmentHeader shipmentHeader1 = new ShipmentHeader();
BeanUtils.copyProperties(shipmentHeaderHistory, shipmentHeader1);
shipmentHeaderList.add(shipmentHeader1);
}
|
|
632
|
// 根据合并前的头表id分组
|
|
633
|
Map<String, List<ShipmentDetail>> map = new HashMap<>();
|
|
634
|
for (ShipmentDetail detail : shipmentDetailList) {
|
|
635
|
String key = detail.getRecordCode();
|
|
636
637
638
639
640
641
642
|
if (key != null) {
if (map.containsKey(key)) {
map.get(key).add(detail);
} else {
List<ShipmentDetail> list = new ArrayList<>();
list.add(detail);
map.put(key, list);
|
|
643
|
}
|
|
644
|
}
|
|
645
|
}
|
|
646
|
|
|
647
|
for (String key : map.keySet()) {
|
|
648
649
650
651
652
|
JSONObject data = new JSONObject();
// 合并前的头表
ShipmentHeader header = new ShipmentHeader();
// 合并前头表对应的子表
List<ShipmentDetail> detailList = new ArrayList<>();
|
|
653
|
for (ShipmentHeader SH : shipmentHeaderList) {
|
|
654
|
if (key.equals(SH.getCode())) {
|
|
655
656
|
header = SH;
detailList = map.get(key);
|
|
657
|
break;
|
|
658
659
660
|
}
}
// 查询出库单据表头
|
|
661
|
JSONObject Rd_Out_M = getRd_Out_M(header, shipmentHeader.getCreatedBy());
|
|
662
663
664
665
666
|
JSONArray jsonArray = getRd_Out_S(header, detailList);
data.put("Rd_Out_M", Rd_Out_M);
data.put("Rd_Out_S", jsonArray);
dataArray.add(data);
}
|
|
667
|
} else {
|
|
668
|
// 查询出库单据表头
|
|
669
|
JSONObject Rd_Out_M = getRd_Out_M(shipmentHeader, "");
|
|
670
|
// 查询出库单据明细
|
|
671
672
|
List<ShipmentDetail> shipmentDetailList = shipmentDetailService.list(new LambdaQueryWrapper<ShipmentDetail>()
.eq(ShipmentDetail::getShipmentId, shipmentHeader.getId()));
|
|
673
|
JSONArray jsonArray = getRd_Out_S(shipmentHeader, shipmentDetailList);
|
|
674
675
676
677
678
679
680
681
682
|
JSONObject data = new JSONObject();
data.put("Rd_Out_M", Rd_Out_M);
data.put("Rd_Out_S", jsonArray);
dataArray.add(data);
}
String action = "E_Rd_Out";
JSONObject json = new JSONObject();
json.put("data", dataArray);
|
|
683
684
|
ReturnInfo returnInfo = postMOM(action, json, "出库回传");
if (returnInfo == null) {
|
|
685
686
687
|
shipmentHeader.setErrorMsg("出库回传:接口地址错误或返回为空");
shipmentHeader.setPushSuccessStatus(2);
shipmentHeaderService.updateById(shipmentHeader);
|
|
688
|
return false;
|
|
689
|
}
|
|
690
|
shipmentHeader.setPushErrorCount(shipmentHeader.getPushErrorCount() + 1);
|
|
691
|
if (returnInfo.hasError()) {
|
|
692
|
shipmentHeader.setPushSuccessStatus(1);
|
|
693
694
|
shipmentHeader.setFirstStatus(QuantityConstant.SHIPMENT_HEADER_RETURN);
shipmentHeader.setLastStatus(QuantityConstant.SHIPMENT_HEADER_RETURN);
|
|
695
|
} else {
|
|
696
|
shipmentHeader.setPushSuccessStatus(2);
|
|
697
|
shipmentHeader.setErrorMsg(returnInfo.getMsg());
|
|
698
|
}
|
|
699
700
|
shipmentHeaderService.updateById(shipmentHeader);
return true;
|
|
701
702
703
|
}
|
|
704
|
public JSONArray getRd_Out_S(ShipmentHeader shipmentHeader, List<ShipmentDetail> shipmentDetailList) {
|
|
705
|
JSONArray jsonArray = new JSONArray();
|
|
706
|
shipmentDetailList.forEach(shipmentDetail -> {
|
|
707
|
User user = userService.selectUserByEmail(shipmentDetail.getLastUpdatedBy());
|
|
708
709
710
|
if (user == null) {
user = userService.selectUserByEmail(shipmentHeader.getLastUpdatedBy());
}
|
|
711
|
JSONObject Rd_Out_S = new JSONObject();
|
|
712
|
Rd_Out_S.put("MGPK", shipmentHeader.getMOMID());
|
|
713
714
715
|
Rd_Out_S.put("SGPK", shipmentDetail.getMOMID());
Rd_Out_S.put("SNNO", shipmentDetail.getSNNO());
Rd_Out_S.put("cInvCode", shipmentDetail.getMaterialCode());
|
|
716
|
// 实际入库数量
|
|
717
|
Rd_Out_S.put("Iquantity", shipmentDetail.getTaskQty());
|
|
718
|
// MOM传入的入库数量
|
|
719
|
Rd_Out_S.put("iFQuantity", shipmentDetail.getQty());
|
|
720
|
Rd_Out_S.put("cwhcode", "035");
|
|
721
722
723
|
List<TaskDetail> taskDetails = taskDetailService.list(new LambdaQueryWrapper<TaskDetail>().eq(TaskDetail::getBillDetailId, shipmentDetail.getId()));
if (!taskDetails.isEmpty()) {
if (taskDetails.get(0).getFlat() != null && taskDetails.get(0).getFlat() == 1) {
|
|
724
725
726
727
728
729
|
Rd_Out_S.put("cidefine10", "平库");
}
Rd_Out_S.put("cidefine10", "立库");
} else {
Rd_Out_S.put("cidefine10", "错误:未查询到任务!");
}
|
|
730
731
|
Rd_Out_S.put("MOCode", shipmentDetail.getNoticeNo());
Rd_Out_S.put("ISUrgent", shipmentDetail.getIsUrgent());
|
|
732
|
Rd_Out_S.put("updatedByNo", user.getLoginName());
|
|
733
734
735
|
Rd_Out_S.put("updatedBy", shipmentDetail.getLastUpdatedBy());
Rd_Out_S.put("warehouse", shipmentHeader.getWarehouse());
Rd_Out_S.put("warehouseName", shipmentHeader.getWarehouseName());
|
|
736
737
738
739
740
741
|
Rd_Out_S.put("creatorCode", shipmentHeader.getCreatorCode());
Rd_Out_S.put("creatorName", shipmentHeader.getCreatorName());
// Rd_Out_S.put("requestedStartDate", shipmentHeader.getRequestedStartDate());
Rd_Out_S.put("ifrom", shipmentDetail.getIfrom());
Rd_Out_S.put("LMPKID", shipmentDetail.getLMPKID());
Rd_Out_S.put("LSPKID", shipmentDetail.getLSPKID());
|
|
742
743
|
jsonArray.add(Rd_Out_S);
});
|
|
744
745
|
return jsonArray;
}
|
|
746
|
|
|
747
|
public JSONObject getRd_Out_M(@RequestBody ShipmentHeader shipmentHeader, String name) {
|
|
748
|
User user = userService.selectUserByEmail(shipmentHeader.getLastUpdatedBy());
|
|
749
|
JSONObject Rd_Out_M = new JSONObject();
|
|
750
|
Rd_Out_M.put("ISMOM", shipmentHeader.getISMOM());
|
|
751
752
753
754
755
|
Rd_Out_M.put("mno", shipmentHeader.getCode());
Rd_Out_M.put("MGPK", shipmentHeader.getMOMID());
Rd_Out_M.put("cBusType", shipmentHeader.getShipmentType());
Rd_Out_M.put("TAID", shipmentHeader.getTAID());
Rd_Out_M.put("FAID", shipmentHeader.getFAID());
|
|
756
757
758
759
760
761
|
if (user == null) {
String UserNo = userService.selectUserByEmail(name).getLoginName();
Rd_Out_M.put("UserNo", UserNo);
} else {
Rd_Out_M.put("UserNo", user.getLoginName());
}
|
|
762
|
Rd_Out_M.put("warehouse", "035");
|
|
763
764
|
Rd_Out_M.put("cDepCode", "01030101");//部门编码
Rd_Out_M.put("cWhCode", shipmentHeader.getWarehouse());//仓库编码
|
|
765
|
return Rd_Out_M;
|
|
766
767
|
}
|
|
768
769
770
771
772
|
/**
* utf-8 转 GB2312
*/
public String getGB(String action) {
byte[] Rd_Out; //中间用ISO-8859-1过渡
|
|
773
774
775
776
777
778
779
780
781
782
783
|
String data = null;
try {
Rd_Out = action.getBytes("8859_1");
data = new String(Rd_Out, "GB2312"); //转换成GB2312字符
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return data;
}
|
|
784
|
/**
|
|
785
|
* @param action MOM行为
|
|
786
787
788
|
* @param JObject 行为参数
* @return
*/
|
|
789
|
public ReturnInfo postMOM(String action, JSONObject JObject, String apiName) {
|
|
790
|
String url = addressService.selectAddress(QuantityConstant.MOM);
|
|
791
|
return CallaMOM.getMsg(action, JObject, apiName, url);
|
|
792
|
}
|
|
793
|
|
|
794
|
|
|
795
|
}
|