WarehouseU8ServiceImpl.java
12.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
package com.huaheng.pc.config.warehouse.service;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huaheng.common.redis.service.IRedisService;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.common.utils.Wrappers;
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.WarehouseU8;
import com.huaheng.pc.config.warehouse.domain.WorkOrderComponent;
import com.huaheng.pc.config.warehouse.domain.WorkOrderList;
import com.huaheng.pc.config.warehouse.mapper.WarehouseU8Mapper;
import com.huaheng.pc.config.warehouse.mapper.WorkOrderListMapper;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Service("warehouseWu")
public class WarehouseU8ServiceImpl extends ServiceImpl<WarehouseU8Mapper, WarehouseU8> implements WarehouseU8Service {
@Resource
private AddressService addressService;
@Resource
private IRedisService iRedisService;
@Resource
private WorkOrderListMapper workOrderListMapper;
@Override
public AjaxResult GetCurrentStock(WorkOrderComponent data, String type) throws Exception {
Address address = getU8Address();
if (address == null){
throw new Exception("未配置U8 API地址");
}
String url = address.getUrl() + "GetMoallocateMes";
StringBuilder param = new StringBuilder();
param.append("cCompanyCode=").append(data.getCCompanyCode())
// param.append("cCompanyCode=").append("UFDATA_807_2018")
.append("&Mocode=").append(data.getMocode())
.append("&Moseq=").append(data.getMoseq())
.append("&CInvcode=").append(data.getCInvcode())
.append("&MaterialCode=").append(data.getMaterialCode());
String result = HttpUtils.sendPost(url, param.toString());
if (StringUtils.isEmpty(result)){
throw new Exception("未查询到工单子件数据!");
}
JSONObject json = JSONObject.parseObject(result);
JSONArray array = json.getJSONArray("data");
if (array == null || array.size() == 0){
throw new Exception(json.getString("msg"));
}
List<WorkOrderList> list = this.dataFiltering(array, type);
final int i = (int) (Math.random()* 10);
if(type.equals("1")&&i==7){
WorkOrderList w=new WorkOrderList();
w.setWorkOrderNumber(list.get(0).getWorkOrderNumber());
List<WorkOrderList> workOrderLists = workOrderListMapper.selectByOption(w);
if(workOrderLists!=null&&workOrderLists.size()>0){
workOrderListMapper.deleteList(workOrderLists.get(0).getWorkOrderNumber());
}
for(WorkOrderList workOrderList:list){
workOrderListMapper.insert(workOrderList);
}
}
List<WorkOrderList> workOrderLists = this.optionData(list, data.getOption());
if (list.size() == 0){
throw new Exception("未查询到工单子件数据!");
}
AjaxResult ajax = AjaxResult.success();
ajax.setData(workOrderLists);
iRedisService.put("CS_work_order_list", list, -1);
return ajax;
}
@Override
public Address getU8Address() {
Address address = addressService.getOne(new LambdaQueryWrapper<Address>()
.eq(Address::getParam, "QITAO")
.eq(Address::getWarehouseCode, "KS0001"));
return address;
}
@Override
public List dataFiltering(JSONArray array, String type) {
List<WorkOrderList> list = new ArrayList<>();
for (int i = 0; i< array.size(); i++){
BigDecimal needQuantity = null;
if (array.getJSONObject(i).containsKey("应领数量")){
needQuantity = array.getJSONObject(i).getBigDecimal("应领数量");
}
BigDecimal workOrderQuantity = null;
if (array.getJSONObject(i).containsKey("工单数量")){
workOrderQuantity = array.getJSONObject(i).getBigDecimal("工单数量");
}
BigDecimal receiveQuantity = null;
if (array.getJSONObject(i).containsKey("已领数量")){
receiveQuantity = array.getJSONObject(i).getBigDecimal("已领数量");
}
if ("0".equals(type) && needQuantity !=null && receiveQuantity != null && needQuantity.compareTo(receiveQuantity) == 0){
continue;
}
String materialCode = array.getJSONObject(i).getString("材料编码");
if (StringUtils.isEmpty(materialCode)){
continue;
}
WorkOrderList workOrderList = new WorkOrderList();
workOrderList.setMaterialName(array.getJSONObject(i).getString("材料名称"));
workOrderList.setOrderDate(array.getJSONObject(i).getString("订单日期"));
workOrderList.setOrderBomCode(array.getJSONObject(i).getString("订单物料编码"));
workOrderList.setNeedQuantity(needQuantity);
workOrderList.setMaterialCode(materialCode);
workOrderList.setSpecification1(array.getJSONObject(i).getString("规格1"));
workOrderList.setName(array.getJSONObject(i).getString("名称"));
workOrderList.setSpecification(array.getJSONObject(i).getString("规格"));
workOrderList.setLineNumber(array.getJSONObject(i).getString("行号"));
workOrderList.setWorkOrderQuantity(workOrderQuantity);
workOrderList.setWorkOrderNumber(array.getJSONObject(i).getString("工单号"));
workOrderList.setWorkOrderId(array.getJSONObject(i).getInteger("工单ID"));
workOrderList.setWorkOrderSonId(array.getJSONObject(i).getInteger("工单子件行ID"));
workOrderList.setReceiveQuantity(receiveQuantity);
list.add(workOrderList);
}
return list;
}
private List<WorkOrderList> optionData(List<WorkOrderList> list,String option){
Iterator<WorkOrderList> iterator = list.iterator();
if(iterator.hasNext()){
WorkOrderList next = iterator.next();
WorkOrderList workOrderList1=new WorkOrderList();
workOrderList1.setWorkOrderNumber(next.getWorkOrderNumber());
workOrderList1.setMaterialCode(next.getMaterialCode());
workOrderList1.setUserDef1(option);
List<WorkOrderList> workOrderLists = workOrderListMapper.selectByOption(workOrderList1);
if(workOrderLists!=null&& workOrderLists.size()>1){
for(WorkOrderList workOrderList:workOrderLists){
final String materialCode = workOrderList.getMaterialCode();
if(materialCode.equals(next.getMaterialCode())){
iterator.remove();
}
}
}
}
return list;
}
@Override
public List<Map<String, Object>> getName() {
LambdaQueryWrapper<WarehouseU8> lambda = Wrappers.lambdaQuery();
lambda.select(WarehouseU8::getUWarehouseCode, WarehouseU8::getId, WarehouseU8::getUWarehouseName, WarehouseU8::getCompanyCode, WarehouseU8::getErpCode)
.eq(WarehouseU8::getWarehouseCode, ShiroUtils.getWarehouseCode());
List<Map<String, Object>> list=this.listMaps(lambda);
List<Map<String, Object>> collect = list.stream().map(item -> {
Map<String, Object> map = item;
map.put("uWarehouseName",item.get("uWarehouseCode")+"-"+item.get("uWarehouseName"));
return map;
}).collect(Collectors.toList());
return collect;
}
@Override
public List<WarehouseU8> selectList() {
return this.list(new LambdaQueryWrapper<WarehouseU8>().eq(WarehouseU8::getWarehouseCode,ShiroUtils.getWarehouseCode()));
}
@Override
public List<WarehouseU8> selectListAndCode() {
LambdaQueryWrapper<WarehouseU8> lambda = Wrappers.lambdaQuery();
lambda.eq(WarehouseU8::getWarehouseCode, ShiroUtils.getWarehouseCode());
List<WarehouseU8> list=this.list(lambda);
List<WarehouseU8> collect = list.stream().map(item -> {
WarehouseU8 warehouseU8 = item;
warehouseU8.setUWarehouseName(item.getUWarehouseCode()+"-"+item.getUWarehouseName());
return warehouseU8;
}).collect(Collectors.toList());
return collect;
}
@Override
public WarehouseU8 getWarehouseU8ByUCompanyUWarehouseCode(String uCompanyCode, String uWarehouseCode,String warehouseCode) {
LambdaQueryWrapper<WarehouseU8> query = Wrappers.lambdaQuery();
query.eq(WarehouseU8::getUWarehouseCode,uWarehouseCode)
.eq(WarehouseU8::getUCompanyCode,uCompanyCode)
.eq(WarehouseU8::getWarehouseCode,warehouseCode);
return this.getOne(query);
}
@Override
public List<WarehouseU8> getByDomain(WarehouseU8 warehouseU8) {
LambdaQueryWrapper<WarehouseU8> lambda = Wrappers.lambdaQuery();
lambda.eq(StringUtils.isNotEmpty(warehouseU8.getWarehouseCode()),WarehouseU8::getWarehouseCode, warehouseU8.getWarehouseCode());
lambda.eq(StringUtils.isNotEmpty(warehouseU8.getUCompanyCode()),WarehouseU8::getUCompanyCode, warehouseU8.getUCompanyCode());
lambda.eq(StringUtils.isNotEmpty(warehouseU8.getUWarehouseCode()),WarehouseU8::getUWarehouseCode, warehouseU8.getUWarehouseCode());
return this.list(lambda);
}
@Override
public Map<String, List<WarehouseU8>> getAllWarehouseWu(){
LambdaQueryWrapper<WarehouseU8> lambda = Wrappers.lambdaQuery();
List<WarehouseU8> list = list(lambda);
Map<String, List<WarehouseU8>> map = list.stream().collect(Collectors.groupingBy(WarehouseU8::getUCompanyCode));
return map;
}
@Override
public List<WarehouseU8> findByWareAndCompany(String warehouseCode,String companyCode) {
LambdaQueryWrapper<WarehouseU8> lambda = new LambdaQueryWrapper<>();
lambda.eq(WarehouseU8::getWarehouseCode,warehouseCode);
lambda.eq(WarehouseU8::getCompanyCode,companyCode);
List<WarehouseU8> list = list(lambda);
return list;
}
@Override
public String getWarehouseErpCode(String warehouseCode,String companyCode,String uwarehosueCode) {
LambdaQueryWrapper<WarehouseU8> lambda = new LambdaQueryWrapper<>();
lambda.eq(WarehouseU8::getWarehouseCode,warehouseCode);
lambda.eq(WarehouseU8::getCompanyCode,companyCode);
lambda.eq(WarehouseU8::getUWarehouseCode,uwarehosueCode);
lambda.last("limit 1");
WarehouseU8 warehouseU8 = getOne(lambda);
if(warehouseU8==null){
return null;
}
return warehouseU8.getErpCode();
}
@Override
public String getWarehouseErpCodeUCompany(String warehouseCode,String ucompanyCode,String uwarehosueCode) {
LambdaQueryWrapper<WarehouseU8> lambda = new LambdaQueryWrapper<>();
lambda.eq(WarehouseU8::getWarehouseCode,warehouseCode);
lambda.eq(WarehouseU8::getUCompanyCode,ucompanyCode);
lambda.eq(WarehouseU8::getUWarehouseCode,uwarehosueCode);
lambda.last("limit 1");
WarehouseU8 warehouseU8 = getOne(lambda);
if(warehouseU8==null){
return null;
}
return warehouseU8.getErpCode();
}
// @Override
public WarehouseU8 getWarehouseErpCodeU(String warehouseCode,String ucompanyCode,String uwarehosueCode) {
LambdaQueryWrapper<WarehouseU8> lambda = new LambdaQueryWrapper<>();
lambda.eq(WarehouseU8::getWarehouseCode,warehouseCode);
lambda.eq(WarehouseU8::getUCompanyCode,ucompanyCode);
lambda.eq(WarehouseU8::getUWarehouseCode,uwarehosueCode);
lambda.last("limit 1");
WarehouseU8 warehouseU8 = getOne(lambda);
return warehouseU8;
}
@Override
public WarehouseU8 getWarehouseCode(String warehouseCode,String erpCode) {
LambdaQueryWrapper<WarehouseU8> lambda = new LambdaQueryWrapper<>();
lambda.eq(WarehouseU8::getWarehouseCode,warehouseCode);
lambda.eq(WarehouseU8::getErpCode,erpCode);
lambda.last("limit 1");
WarehouseU8 warehouseU8 = getOne(lambda);
if(warehouseU8==null){
return null;
}
return warehouseU8;
}
}