ShipmentU8ContainerHeaderServiceImpl.java
13.7 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
package com.huaheng.pc.receipt.U8.service;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.huaheng.api.U8.controller.ICSShipmentApi;
import com.huaheng.common.exception.service.ServiceException;
import com.huaheng.common.redis.service.IRedisService;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.common.utils.http.HttpUtils;
import com.huaheng.common.utils.security.ShiroUtils;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.pc.config.address.domain.Address;
import com.huaheng.pc.config.address.service.AddressService;
import com.huaheng.pc.config.warehouse.domain.WorkOrderList;
import com.huaheng.pc.config.warehouse.mapper.WorkOrderListMapper;
import com.huaheng.pc.config.warehouse.service.WarehouseU8Service;
import com.huaheng.pc.inventory.inventoryDetail.domain.InventoryDetail;
import com.huaheng.pc.inventory.inventoryDetail.service.InventoryDetailService;
import com.huaheng.pc.inventory.inventoryHeader.domain.InventoryHeader;
import com.huaheng.pc.receipt.U8.domain.U8Material;
import com.huaheng.pc.receipt.U8.domain.U8OutParameters;
import com.huaheng.pc.receipt.U8.domain.U8Stock;
import com.huaheng.pc.receipt.U8.domain.U8StockQuery;
import com.huaheng.pc.system.user.domain.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* u8出库单据 服务层实现
*
* @author huaheng
* @date 2022-03-23
*/
@Service
public class ShipmentU8ContainerHeaderServiceImpl implements IShipmentU8ContainerHeaderService {
private static final Logger logger = LoggerFactory.getLogger(ShipmentU8ContainerHeaderServiceImpl.class);
@Resource
private AddressService addressService;
@Resource
private WarehouseU8Service warehouseWuService;
@Resource
private IRedisService iRedisService;
@Resource
private InventoryDetailService inventoryDetailService;
@Resource
private ICSShipmentApi icsShipmentApi;
@Resource
private WorkOrderListMapper workOrderListMapper;
@Override
public List getStockcData(U8StockQuery u8StockQuery) throws Exception {
Address address = warehouseWuService.getU8Address();
String url = this.getStockcUrl(address);
StringBuilder param = new StringBuilder();
// param.append("cCompanyCode=").append(u8StockQuery.getCCompanyCode())
param.append("cCompanyCode=").append("UFDATA_807_2018")
.append("&cWHCode=").append(u8StockQuery.getCWHCode())
.append("&cInvCode=").append(u8StockQuery.getCInvCode());
String result = HttpUtils.sendPost(url, param.toString());
if (StringUtils.isEmpty(result)){
throw new Exception("未查询到U8库存数据!");
}
JSONObject json = JSONObject.parseObject(result);
List<U8Stock> u8StockList = JSONArray.parseArray(json.getString("data"), U8Stock.class);
if (u8StockList == null || u8StockList.size() == 0){
throw new Exception("未查询到U8库存数据!");
}
// List<U8Stock> resultList = new ArrayList<>();
// u8StockList.forEach(item->{
// // 工单行ID
// item.setModID(u8StockQuery.getModID());
// // 工单子件行ID
// item.setAllocateId(u8StockQuery.getAllocateId());
// // 应领数量
// item.setNeedQuantity(u8StockQuery.getNeedQuantity());
// // 已领数量
// item.setReceiveQuantity(u8StockQuery.getReceiveQuantity());
// String cInvCode = item.getCInvCode();
// // 查询wms库存
// List<Inventory> inventories = inventoryService.selectListEntityByMaterialCode(cInvCode);
// if (inventories == null || inventories.size() == 0){
// return;
// }
// int index = 0;
//
// for (Inventory inventory :inventories){
// U8Stock u8Stock = new U8Stock();
// BeanUtils.copyProperties(item, u8Stock);
// // 库存id
// u8Stock.setInventoryId(inventory.getId());
// // 库存数量
// u8Stock.setQty(inventory.getQty());
// // 执行预定数量
// u8Stock.setTaskQty(inventory.getTaskQty());
// // 库区编码
// u8Stock.setZoneCode(inventory.getZoneCode());
// // 行号
// u8Stock.setSerialNumber(index++);
// resultList.add(u8Stock);
// }
// });
return this.getConvertU8Stock(u8StockList, u8StockQuery);
}
@Override
public List getStockcDataAll(String json) throws Exception {
if (StringUtils.isEmpty(json)){
throw new Exception("请勿提交空数据!");
}
List<U8StockQuery> u8StockQueryList = JSON.parseArray(json, U8StockQuery.class);
if (u8StockQueryList != null && u8StockQueryList.size() == 0){
throw new Exception("请勿提交空数据!");
}
Address address = warehouseWuService.getU8Address();
String url = this.getStockcUrl(address);
List<U8Stock> resultList = new ArrayList<>();
for (U8StockQuery u8StockQuery : u8StockQueryList){
StringBuilder param = new StringBuilder();
// param.append("cCompanyCode=").append(u8StockQuery.getCCompanyCode())
param.append("cCompanyCode=").append("UFDATA_807_2018")
.append("&cWHCode=").append(u8StockQuery.getCWHCode())
.append("&cInvCode=").append(u8StockQuery.getCInvCode());
String result = HttpUtils.sendPost(url, param.toString());
if (StringUtils.isEmpty(result)){
continue;
}
JSONObject jsonData = JSONObject.parseObject(result);
List<U8Stock> u8StockList = JSONArray.parseArray(jsonData.getString("data"),U8Stock.class);
if (u8StockList == null || u8StockList.size() == 0){
continue;
}
List<U8Stock> temp = this.getConvertU8Stock(u8StockList, u8StockQuery);
if (temp!= null && temp.size() > 0){
resultList.addAll(temp);
}
}
return resultList;
}
@Override
public List getConvertU8Stock(List<U8Stock> list, U8StockQuery u8StockQuery) {
List<U8Stock> resultList = new ArrayList<>();
list.forEach(item->{
// 工单行ID
item.setModID(u8StockQuery.getModID());
// 工单子件行ID
item.setAllocateId(u8StockQuery.getAllocateId());
// 应领数量
item.setNeedQuantity(u8StockQuery.getNeedQuantity());
// 已领数量
item.setReceiveQuantity(u8StockQuery.getReceiveQuantity());
String cInvCode = item.getCInvCode();
// 查询wms库存
// List<InventoryHeader> inventories = inventoryDetailService.selectListEntityByMaterialCode(cInvCode);
List<InventoryDetail> inventories = inventoryDetailService.list(new LambdaQueryWrapper<InventoryDetail>()
.eq(InventoryDetail::getMaterialCode, cInvCode)
.eq(InventoryDetail::getWarehouseCode, ShiroUtils.getWarehouseCode()));
if (inventories == null || inventories.size() == 0){
return;
}
int index = 0;
for (InventoryDetail inventory :inventories){
U8Stock u8Stock = new U8Stock();
BeanUtils.copyProperties(item, u8Stock);
// 库存id
u8Stock.setInventoryId(inventory.getId());
// 库存数量
u8Stock.setQty(inventory.getQty());
// 执行预定数量
u8Stock.setTaskQty(inventory.getTaskQty());
// 库区编码
u8Stock.setZoneCode(inventory.getZoneCode());
// 行号
u8Stock.setSerialNumber(index++);
resultList.add(u8Stock);
}
});
return resultList;
}
@Override
public String getStockcUrl(Address address) {
return address.getUrl() + "GetCurrentStock";
}
@Override
public String getMaterialOutStock() throws Exception {
Address address = new Address();
address.setParam("U8");
address.setWarehouseCode("KS0001");
address = addressService.selectEntity(address);
if (address == null){
throw new Exception("未获取到address数据,请联系管理员!");
}
if (StringUtils.isEmpty(address.getUrl())){
throw new Exception("未获取到出库URL,请检查url地址配置是否完整!");
}
return address.getUrl() + "CreateICSRdRecord_11";
}
@Override
public void queryStockcDataAll(String cCompanyCode, String cWHCode) throws Exception {
String key = "CS_work_order_list";
if (!iRedisService.isKeyExists(key)){
throw new Exception("请先查询工单在进行出库!");
}
List<WorkOrderList> workOrderLists = JSON.parseArray(JSON.toJSON(iRedisService.get(key)).toString(),WorkOrderList.class);
workOrderLists.forEach(item->{
U8StockQuery query = new U8StockQuery();
query.setCWHCode(cWHCode);
query.setCCompanyCode(cCompanyCode);
query.setCInvCode(item.getMaterialCode());
try {
this.getStockcData(query);
} catch (Exception e) {
e.printStackTrace();
}
});
}
@Override
public AjaxResult outStock(U8OutParameters u8OutParameters) throws Exception {
String jsonString = JSONObject.toJSONString(u8OutParameters);
logger.info("出库信息:"+jsonString);
String url = this.getMaterialOutStock();
String result = "";
// String result = HttpUtils.bodypost(url, jsonString,ShiroUtils.getWarehouseCode());
if (StringUtils.isEmpty(result)){
throw new Exception("出库失败!");
}
AjaxResult ajaxResult = JSON.parseObject(result, AjaxResult.class);
// JSONObject json = JSONObject.parseObject(result);
// String code = json.getString("code");
// String msg = json.getString("msg");
// if (!"200".equals(code)){
// throw new Exception(msg);
// }
if(ajaxResult.hasErr()){
return ajaxResult;
}
if (u8OutParameters.getHandler() == null){
return AjaxResult.success("材料出库成功,已生成开立状态U8材料出库单据!");
}
return AjaxResult.success("材料出库成功,已生成U8单据!");
}
@Override
public U8OutParameters dataConversion(String jsonData) throws Exception {
if (StringUtils.isEmpty(jsonData)){
throw new Exception("请勿提交空数据!");
}
U8OutParameters outParameters = JSONObject.parseObject(jsonData, U8OutParameters.class);
// 用户名称
User user = ShiroUtils.getUser();
outParameters.setUser(user.getUserName());
for (U8Material u8Material : outParameters.getList()){
// Inventory inventory = inventoryDetailService.selectEntityById(u8Material.getInventoryId());
InventoryDetail inventory = inventoryDetailService.getById(u8Material.getInventoryId());
// 判断wms库存是否存在
if (inventory == null){
throw new Exception("查询不到WMS库存数据,请联系管理员!");
}
// 判断单据是否需要审核
if (("XN".equals(inventory.getZoneCode()) || "PK".equals(inventory.getZoneCode()))){
outParameters.setHandler(user.getUserName());
}
if (u8Material.getQty().compareTo(BigDecimal.valueOf(0)) == 0){
throw new Exception("出库数量不能为0!");
}
if (inventory.getQty().subtract(inventory.getTaskQty()).compareTo(u8Material.getQty()) < 0){
throw new Exception("出库数量大于库存数量!");
}
}
return outParameters;
}
@Override
public Boolean importData(List<Map<String, Object>> maps, Boolean num) {
//实体转换
int number = 0;
for (Map<String, Object> map : maps) {
WorkOrderList workOrderList = new WorkOrderList();
if(StringUtils.isNull(map.get("存货编码"))) {
throw new ServiceException("存货编码为空");
}
if(StringUtils.isNull(map.get("领料数量"))) {
throw new ServiceException("领料数量为空");
}
if(StringUtils.isNull(map.get("工作令号"))){
throw new ServiceException("工作令号空");
}
if(StringUtils.isNull(map.get("备注"))){
throw new ServiceException("备注空");
}
workOrderList.setMaterialCode(map.get("存货编码").toString());
workOrderList.setNeedQuantity(BigDecimal.valueOf(((Long)map.get("领料数量")).intValue()));
workOrderList.setWorkOrderNumber(map.get("工作令号").toString());
workOrderList.setUserDef1(map.get("备注").toString());
List<WorkOrderList> workOrderLists = workOrderListMapper.selectByOption(workOrderList);
if(workOrderLists!=null && workOrderLists.size()>0){
return true;
}
workOrderListMapper.insert(workOrderList);
}
return true;
}
}