SrmDetailService.java
27.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
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
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
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
package com.huaheng.pc.srm.service;
import com.alibaba.fastjson.JSON;
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.constant.QuantityConstant;
import com.huaheng.common.exception.service.ServiceException;
import com.huaheng.common.utils.DateUtils;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.common.utils.Wrappers;
import com.huaheng.common.utils.http.HttpUtils;
import com.huaheng.common.utils.http.OkHttpUtils;
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.company.domain.Company;
import com.huaheng.pc.config.company.service.CompanyService;
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.srm.domain.*;
import com.huaheng.pc.srm.mapper.SrmDetailMapper;
import com.huaheng.pc.system.config.service.IConfigService;
import com.huaheng.pc.system.user.domain.User;
import com.huaheng.pc.system.user.service.IUserService;
import com.huaheng.pc.u8.domain.ICSReceiptDetail;
import com.huaheng.pc.u8.domain.ICSReceiptHeader;
import com.huaheng.pc.u8.service.ICSReceiptDetailService;
import com.huaheng.pc.u8.service.ICSReceiptHeaderService;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;
@Service
public class SrmDetailService extends ServiceImpl<SrmDetailMapper, SrmDetail> {
private static final Logger logger = LoggerFactory.getLogger(SrmDetailService.class);
@Resource
private SrmHeaderService srmHeaderService;
@Resource
private ICSITEMLotService icsitemLotService;
@Resource
private CompanyService companyService;
@Resource
private ReceiptHeaderService receiptHeaderService;
@Resource
private ReceiptDetailService receiptDetailService;
@Resource
private ICSReceiptHeaderService icsReceiptHeaderService;
@Resource
private ICSReceiptDetailService icsReceiptDetailService;
@Resource
private AddressService addressService;
@Resource
private SrmDetailService srmDetailService;
@Resource
private IUserService userService;
@Resource
private IConfigService configService;
public SrmDetail selectFirstModel(SrmDetail srmDetail) {
LambdaQueryWrapper<SrmDetail> queryWrapper = Wrappers.lambdaQuery();
queryWrapper.eq(StringUtils.isNotEmpty(srmDetail.getLineCode()), SrmDetail::getLineCode, srmDetail.getLineCode());
queryWrapper.eq(StringUtils.isNotEmpty(srmDetail.getCode()), SrmDetail::getCode, srmDetail.getCode());
queryWrapper.eq(StringUtils.isNotNull(srmDetail.getId()), SrmDetail::getId, srmDetail.getId());
queryWrapper.eq(StringUtils.isNotEmpty(srmDetail.getMark()), SrmDetail::getMark, srmDetail.getMark());
queryWrapper.eq(StringUtils.isNotEmpty(srmDetail.getWarehouseCode()), SrmDetail::getWarehouseCode, srmDetail.getWarehouseCode());
queryWrapper.last("limit 1");
return this.getOne(queryWrapper);
}
public List<SrmDetail> selectBySTNO(List<String> STNOS) {
if (STNOS != null && STNOS.size() > 0) {
String[] split = STNOS.toArray(new String[0]);
LambdaQueryWrapper<SrmDetail> queryWrapper = Wrappers.lambdaQuery();
queryWrapper.in(SrmDetail::getCode, split);
return this.list(queryWrapper);
}
return null;
}
public List<SrmDetail> selectList(SrmDetail srmDetail) {
LambdaQueryWrapper<SrmDetail> queryWrapper = Wrappers.lambdaQuery();
queryWrapper.eq(StringUtils.isNotNull(srmDetail.getHeaderId()), SrmDetail::getHeaderId, srmDetail.getHeaderId());
queryWrapper.eq(StringUtils.isNotEmpty(srmDetail.getWarehouseCode()), SrmDetail::getWarehouseCode, srmDetail.getWarehouseCode());
queryWrapper.eq(StringUtils.isNotEmpty(srmDetail.getCode()), SrmDetail::getCode, srmDetail.getCode());
queryWrapper.eq(StringUtils.isNotNull(srmDetail.getEnable()), SrmDetail::getEnable, srmDetail.getEnable());
queryWrapper.eq(StringUtils.isNotNull(srmDetail.getCheckCode()), SrmDetail::getCheckCode, srmDetail.getCheckCode());
queryWrapper.eq(StringUtils.isNotNull(srmDetail.getUploadStatus1()), SrmDetail::getUploadStatus1, srmDetail.getUploadStatus1());
queryWrapper.eq(StringUtils.isNotNull(srmDetail.getUploadStatus2()), SrmDetail::getUploadStatus2, srmDetail.getUploadStatus2());
queryWrapper.eq(StringUtils.isNotNull(srmDetail.getUploadStatus4()), SrmDetail::getUploadStatus4, srmDetail.getUploadStatus4());
return this.list(queryWrapper);
}
@Transactional
public AjaxResult review(String code) {
ICSITEMLot queryIcsitemLot = new ICSITEMLot();
queryIcsitemLot.setLotNO(code);
ICSITEMLot icsitemLot = icsitemLotService.selectFirstModel(queryIcsitemLot);
if (icsitemLot == null) {
return AjaxResult.error("没有此条码信息,SRM系统未下发或者条码错误");
}
SrmDetail srmDetail = new SrmDetail();
srmDetail.setLineCode(code);
srmDetail = this.selectFirstModel(srmDetail);
if (srmDetail == null) {
return AjaxResult.error("没有此条码的送货单信息,SRM系统未下发或者条码错误");
}
Company company = new Company();
company.setCode(srmDetail.getCompanyCode());
List<Company> companylist = companyService.getByDomain(company);
if (companylist != null && companylist.size() > 0) {
company = companylist.get(0);
srmDetail.setCompanyName(company.getName());
}
srmDetail.setConfirmQty(icsitemLot.getLOTQTY());
return AjaxResult.success(srmDetail);
}
@Transactional
public AjaxResult reviewSrmModel(List<SrmDetail> srmDetails) {
Set<String> codes = new HashSet<>();
for (SrmDetail srmDetail : srmDetails) {
//该明细是否之前送过,送过则新生成一条明细
if (StringUtils.isEmpty(srmDetail.getUWarehouseCode())) {
return AjaxResult.error("仓库为空");
}
SrmDetail model = new SrmDetail();
model.setId(srmDetail.getId());
model = this.selectFirstModel(model);
if (model.getEnable() == 1) {
break;
} else {
srmDetail.setEnable(1);
srmDetail.setLastUpdate(new Date());
srmDetail.setLastUpdateBy(ShiroUtils.getLoginName());
this.updateById(srmDetail);
}
codes.add(model.getCode());
}
if (codes.isEmpty()) {
return AjaxResult.success("该编码已通过扫描确认,无法再次扫描确认");
}
//判断送货单主表,是否全收货
for (String code : codes) {
Integer number = 0;
//查看该单据明细是否全收货
SrmDetail srmDetail = new SrmDetail();
srmDetail.setCode(code);
List<SrmDetail> srmDetailList = this.selectList(srmDetail);
srmDetail.setEnable(1);
List<SrmDetail> details = this.selectList(srmDetail);
if (srmDetailList.size() == details.size()) {
number = 2;
} else {
number = 1;
}
SrmHeader srmHeader = new SrmHeader();
srmHeader.setCode(code);
srmHeader = srmHeaderService.selectFirstModel(srmHeader);
if (srmHeader != null) {
srmHeader.setEnable(number);
srmHeaderService.updateById(srmHeader);
}
}
return AjaxResult.success("复核成功");
}
@Transactional(rollbackFor = Exception.class)
public AjaxResult checkDetail(SrmDetail srmDetail) {
SrmDetail model = new SrmDetail();
model.setId(srmDetail.getId());
model = this.selectFirstModel(model);
if (model.getUploadStatus4() == 0) {
return AjaxResult.success("未获取到erp,不需要提交合格");
}
if (model.getCheckCode() != null && model.getCheckCode() == 2) {
return AjaxResult.success("已提交,不需要重复提交");
}
if (srmDetail.getUnqualifiedQty().compareTo(new BigDecimal(0)) == 1 && StringUtils.isEmpty(srmDetail.getReason())) {
return AjaxResult.error("不合格原因未填写");
}
BigDecimal qty = srmDetail.getConfirmQty().subtract(srmDetail.getQualifiedQty()).subtract(srmDetail.getUnqualifiedQty());
if (qty.compareTo(new BigDecimal(0)) == -1) {
return AjaxResult.error("条码为" + model.getLineCode() + "的物料质检后的总数量大于到货数量");
}
if (qty.compareTo(new BigDecimal(0)) == 1) {
return AjaxResult.error("条码为" + model.getLineCode() + "的物料质检后的总数量小于到货数量");
}
srmDetail.setCheckCode(2);
srmDetail.setCheckUser(ShiroUtils.getLoginName());
srmDetail.setCheckTime(new Date());
this.updateById(srmDetail);
//判断子表是否全部质检完成
SrmDetail detail = new SrmDetail();
detail.setCode(model.getCode());
detail.setEnable(1);
detail.setWarehouseCode(ShiroUtils.getWarehouseCode());
List<SrmDetail> srmDetailList = this.selectList(detail);
detail.setCheckCode(2);
List<SrmDetail> srmDetails = this.selectList(detail);
//修改主表字段
SrmHeader srmHeader = new SrmHeader();
srmHeader.setCode(model.getCode());
srmHeader.setWarehouseCode(ShiroUtils.getWarehouseCode());
srmHeader = srmHeaderService.selectFirstModel(srmHeader);
AjaxResult result = AjaxResult.success();
boolean checkflag=false;
if (srmDetailList.size() == srmDetails.size()) {
srmHeader.setCheckCode(2);
result = checkWhetherQualified(srmDetails, srmHeader);
if(result!=null&&result.hasErr()){
checkflag=true;
}
} else {
srmHeader.setCheckCode(1);
}
List<ReceiptHeader> receiptHeaderList = receiptHeaderService.list(new LambdaQueryWrapper<ReceiptHeader>().eq(ReceiptHeader::getUserDef3, srmHeader.getCode()).eq(ReceiptHeader::getWarehouseCode, ShiroUtils.getWarehouseCode()));
if (receiptHeaderList != null && receiptHeaderList.size() > 0) {
for (ReceiptHeader header : receiptHeaderList) {
LambdaQueryWrapper<ReceiptDetail> receiptDetailLambdaQueryWrapper = Wrappers.lambdaQuery();
receiptDetailLambdaQueryWrapper.eq(ReceiptDetail::getReceiptId, header.getId());
List<ReceiptDetail> list = receiptDetailService.list(receiptDetailLambdaQueryWrapper);
if (CollectionUtils.isNotEmpty(list)) {
List<String> collect = srmDetails.stream().map(s -> s.getMaterialCode()).collect(Collectors.toList());
List<ReceiptDetail> receiptDetails = list.stream().filter(l -> collect.contains(l.getMaterialCode())).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(receiptDetails) && receiptDetails.size() == list.size()) {
header.setDeleted(false);
receiptHeaderService.updateById(header);
} else {
header.setDeleted(true);
receiptHeaderService.updateById(header);
}
}
}
}
// List<SrmDetail> list = this.list(new LambdaQueryWrapper<SrmDetail>()
//// .eq(SrmDetail::getCode, model.getCode())
//// .eq(SrmDetail::getWarehouseCode, ShiroUtils.getWarehouseCode())
//// .eq(SrmDetail::getEnable, 1)
//// .eq(SrmDetail::getCheckCode, 2)
//// .eq(SrmDetail::getUploadStatus1, 0)
//// .eq(SrmDetail::getUploadStatus4, 0)
//// );
// List<SrmDetail> qcList = this.list(new LambdaQueryWrapper<SrmDetail>()
// .eq(SrmDetail::getCode, model.getCode())
// .eq(SrmDetail::getWarehouseCode, ShiroUtils.getWarehouseCode())
// .likeRight(SrmDetail::getMaterialCode, 2)
// .eq(SrmDetail::getQcFlag,1)
// );
// if(CollectionUtils.isNotEmpty(list)&&CollectionUtils.isNotEmpty(qcList)&&list.size()==qcList.size()){
// srmHeaderService.confirmSRMModel(qcList);
// result = srmHeaderService.confirmU8Model(qcList);
// if (result.hasErr()){
// result.setMsg("系统自动获取erp到货单失败请手动获取:" + result.getMsg());
// srmHeader.setUserDef1(result.getMsg());
// srmHeaderService.updateById(srmHeader);
// return result;
// }
// }
if (200 != result.getCode()) {
result.setMsg("创建U8拒收单失败:" + result.getMsg());
if(StringUtils.isEmpty(srmHeader.getUserDef1())||
(StringUtils.isNotEmpty(srmHeader.getUserDef1())&&!srmHeader.getUserDef1().equals("质检成功"))){
srmHeader.setUserDef1(result.getMsg());
srmHeaderService.updateById(srmHeader);
return result;
}
}else{
srmHeader.setUserDef1("质检成功");
}
srmHeaderService.updateById(srmHeader);
return AjaxResult.success("质检成功");
}
// public AjaxResult checkSRMDetail(SrmDetail srmDetail) {
// SrmDetail model = new SrmDetail();
// model.setId(srmDetail.getId());
// model = this.selectFirstModel(model);
// if (srmDetail.getUnqualifiedQty().compareTo(new BigDecimal(0)) == 1 && StringUtils.isEmpty(srmDetail.getReason())) {
// return AjaxResult.error("不合格原因未填写");
// }
// BigDecimal qty = srmDetail.getConfirmQty().subtract(srmDetail.getQualifiedQty()).subtract(srmDetail.getUnqualifiedQty());
// if (qty.compareTo(new BigDecimal(0)) == -1) {
// return AjaxResult.error("条码为" + model.getLineCode() + "的物料质检后的总数量大于到货数量");
// }
// if (qty.compareTo(new BigDecimal(0)) == 1) {
// return AjaxResult.error("条码为" + model.getLineCode() + "的物料质检后的总数量小于到货数量");
// }
// srmDetail.setCheckCode(2);
// srmDetail.setCheckUser(ShiroUtils.getLoginName());
// srmDetail.setCheckTime(new Date());
// this.updateById(srmDetail);
//
// //判断子表是否全部质检完成
// SrmDetail detail = new SrmDetail();
// detail.setCode(model.getCode());
// detail.setEnable(1);
// List<SrmDetail> srmDetailList = this.selectList(detail);
//
// detail.setCheckCode(2);
// List<SrmDetail> srmDetails = this.selectList(detail);
// //修改主表字段
// SrmHeader srmHeader = new SrmHeader();
// srmHeader.setCode(model.getCode());
// srmHeader = srmHeaderService.selectFirstModel(srmHeader);
// AjaxResult result = AjaxResult.success();
// if (srmDetailList.size() == srmDetails.size()) {
// srmHeader.setCheckCode(2);
// List<ReceiptHeader> receiptHeaderList = receiptHeaderService.list(new LambdaQueryWrapper<ReceiptHeader>().eq(ReceiptHeader::getUserDef3, srmHeader.getCode()));
// result = checkWhetherQualified(srmDetails, srmHeader);
// if (receiptHeaderList.size() > 0) {
// receiptHeaderList.forEach(item -> {
// item.setDeleted(false);
// receiptHeaderService.updateById(item);
// });
// }
// } else {
// srmHeader.setCheckCode(1);
// }
// if (200 != result.getCode()) {
// result.setMsg("创建U8拒收单失败:" + result.getMsg());
// srmHeader.setUserDef1(result.getMsg());
// srmHeaderService.updateById(srmHeader);
// return result;
// }
// srmHeaderService.updateById(srmHeader);
// return AjaxResult.success("质检成功");
// }
@Transactional(rollbackFor = Exception.class)
public AjaxResult checkWhetherQualified(List<SrmDetail> list, SrmHeader srmHeader) {
if (list.isEmpty()) {
return AjaxResult.error("送货单明细为空值!");
}
if (srmHeader == null) {
return AjaxResult.error("送货单头表为空!");
}
List<ReceiptDetail> detailList = new ArrayList<>();
// 以主单据id作为主键
Map<Integer, SrmRejectHeader> map = new HashMap<>();
for (SrmDetail srmDetail : list) {
// 判断不合格数量是否大于0
if (srmDetail.getUnqualifiedQty().compareTo(new BigDecimal(0)) == 1) {
List<SrmRejectDetail> rejectDetails = new ArrayList<>();
SrmRejectHeader srmRejectHeader = new SrmRejectHeader();
// 查询入库单子表
// ReceiptDetail receiptDetail = receiptDetailService.getOne(new LambdaQueryWrapper<ReceiptDetail>().eq(ReceiptDetail::getUserDef2, srmDetail.getLineCode()).eq(ReceiptDetail::getWarehouseCode, ShiroUtils.getWarehouseCode()));
// if (receiptDetail == null) {
// return AjaxResult.error("未查询到入库单子表信息!");
// }
// 通过上游系统单号查询出库下发或回传主单
ICSReceiptHeader icsReceiptHeader = new ICSReceiptHeader();
// icsReceiptHeader.setCCode(receiptDetail.getReferCode());
icsReceiptHeader.setCCode(srmHeader.getUserDef2());
icsReceiptHeader = icsReceiptHeaderService.selectModel(icsReceiptHeader);
if (icsReceiptHeader == null) {
return AjaxResult.error("查询出库下发回传主单失败,请检查该单据是否获取erp出货单!");
}
ICSReceiptDetail icsReceiptDetail = new ICSReceiptDetail();
// icsReceiptHeader.setCCode(receiptDetail.getReferCode());
icsReceiptDetail.setCCode(srmHeader.getUserDef2());
icsReceiptDetail.setWarehouseCode(ShiroUtils.getWarehouseCode());
icsReceiptDetail.setCInvCode(srmDetail.getMaterialCode());
icsReceiptDetail = icsReceiptDetailService.selectModel(icsReceiptDetail);
if (icsReceiptDetail == null) {
return AjaxResult.error("查询入库下发回传明细失败,请检查该单据是否获取erp出货单!");
}
// 到货单主表id
srmRejectHeader.setID(icsReceiptHeader.getID());
// 制单人编码
srmRejectHeader.setUsercode(ShiroUtils.getLoginName());
// 修改实际入库数量
// receiptDetail.setQty(srmDetail.getQualifiedQty());
// // 如果实际入库数量为0,删除该条入库单详情
// if (receiptDetail.getQty().compareTo(new BigDecimal(0)) == 0) {
// detailList.add(receiptDetail);
// } else {
// receiptDetailService.updateById(receiptDetail);
// }
if (StringUtils.isEmpty(srmRejectHeader.getCompanyCode())) {
// 账套名称
srmRejectHeader.setCompanyCode(srmDetail.getCompanyCode());
}
SrmRejectDetail rejectDetail = new SrmRejectDetail();
// 到货单子表id
// rejectDetail.setAutoID(receiptDetail.getAutoId());
rejectDetail.setAutoID(icsReceiptDetail.getAutoID());
// 物料编码
rejectDetail.setCInvCode(srmDetail.getMaterialCode());
// 不良数量
rejectDetail.setINGQuantity(srmDetail.getUnqualifiedQty());
// 判断是否为同一个单据
if (map.containsKey(srmRejectHeader.getID())) {
map.get(srmRejectHeader.getID()).getList().add(rejectDetail);
} else {
rejectDetails.add(rejectDetail);
srmRejectHeader.setList(rejectDetails);
srmRejectHeader.setWarehouseCode(srmDetail.getWarehouseCode());
map.put(srmRejectHeader.getID(), srmRejectHeader);
}
if (StringUtils.isNull(srmDetail.getSendOaStatus())) {
toOaMessage(srmDetail);
}
}
}
if (map.size() == 0) {
return AjaxResult.success("质检成功!");
}
//退货单
AjaxResult result = this.sendSrmRejectData(map, list.get(0).getWarehouseCode());
if (!result.hasErr() && detailList.size() > 0) {
for (ReceiptDetail receiptDetail : detailList) {
receiptDetailService.removeById(receiptDetail.getId());
}
}
return result;
}
public AjaxResult sendSrmRejectData(Map<Integer, SrmRejectHeader> map, String warehouseCode) {
if (map.isEmpty()) {
return AjaxResult.error("退货单数据为空!");
}
Address address = new Address();
address.setParam("U8");
address.setWarehouseCode(warehouseCode);
address = addressService.selectEntity(address);
if (address == null) {
return AjaxResult.error("请检查U8地址是否存在!");
}
String url = address.getUrl() + "CreateRF";
for (SrmRejectHeader srmRejectHeader : map.values()) {
List list = new ArrayList<>();
list.add(srmRejectHeader);
String jsonString = JSON.toJSONString(list);
String result = HttpUtils.bodypost(url, jsonString, srmRejectHeader.getWarehouseCode());
logger.info("U8返回信息:" + result);
AjaxResult ajaxResult = JSON.parseObject(result, AjaxResult.class);
if (ajaxResult.hasErr()) {
return ajaxResult;
}
}
return AjaxResult.success("退货单发送成功!");
}
@Transactional(rollbackFor = Exception.class)
public void updateByLineCode(String lineCode) {
// update srmdetail set UploadStatus2 =3 where lineCode=#{lineCode, jdbcType=VARCHAR}
SrmDetail srmDetail = new SrmDetail();
srmDetail.setUploadStatus2(3);
LambdaQueryWrapper<SrmDetail> lambdaQueryWrapper = Wrappers.lambdaQuery();
lambdaQueryWrapper.eq(SrmDetail::getLineCode, lineCode);
this.update(srmDetail, lambdaQueryWrapper);
}
public List checkSrmDetailList(SrmDetail srmDetail) {
LambdaQueryWrapper<SrmDetail> lambdaQueryWrapper = Wrappers.lambdaQuery();
lambdaQueryWrapper.ge(SrmDetail::getUnqualifiedQty, 1);
lambdaQueryWrapper.eq(StringUtils.isNotEmpty(srmDetail.getCode()), SrmDetail::getCode, srmDetail.getCode());
lambdaQueryWrapper.eq(StringUtils.isNotEmpty(srmDetail.getLineCode()), SrmDetail::getLineCode, srmDetail.getLineCode());
lambdaQueryWrapper.eq(StringUtils.isNotEmpty(srmDetail.getMaterialCode()), SrmDetail::getMaterialCode, srmDetail.getMaterialCode());
List<SrmDetail> list = srmDetailService.list(lambdaQueryWrapper);
Iterator<SrmDetail> iterator = list.iterator();
while (iterator.hasNext()) {
SrmDetail detail = iterator.next();
List<SrmHeader> srmHeaders = srmHeaderService.list(new LambdaQueryWrapper<SrmHeader>().eq(SrmHeader::getCode, detail.getCode()));
if (CollectionUtils.isNotEmpty(srmHeaders)) {
String supplierCode = srmHeaders.get(0).getSupplierCode();
detail.setSupplierCode(supplierCode);
if (StringUtils.isNotEmpty(srmDetail.getSupplierCode()) && !srmDetail.getSupplierCode().equals(supplierCode)) {
iterator.remove();
continue;
}
}
String checkUser = detail.getCheckUser();
User user = userService.selectUserByLoginName(checkUser);
detail.setCheckUserName(user.getUserName());
}
return list;
}
public AjaxResult checkBatchHege(String ids) {
List<String> list = Arrays.asList(ids.split(","));
list.forEach(l -> {
SrmDetail one = srmDetailService.getOne(new LambdaQueryWrapper<SrmDetail>().eq(SrmDetail::getId, l));
one.setQualifiedQty(one.getConfirmQty());
AjaxResult ajaxResult = srmDetailService.checkDetail(one);
if (ajaxResult.hasErr()) {
throw new ServiceException(ajaxResult.getMsg());
}
});
return AjaxResult.success("成功");
}
public void toOaMessage(SrmDetail srmDetail) {
try {
SrmHeader srmHeader = srmHeaderService.getOne(new LambdaQueryWrapper<SrmHeader>().eq(SrmHeader::getCode, srmDetail.getCode()).eq(SrmHeader::getWarehouseCode, QuantityConstant.WAREHOUSE_KS));
String operator = srmHeader.getOperator();
User user = userService.selectUserByUserName(operator);
OaMessage oaMessage = new OaMessage();
oaMessage.setSenderLoginName(srmDetail.getCheckUser());
User user2 = userService.selectUserByLoginName(srmDetail.getCheckUser());
List<String> strings = new ArrayList<>();
// strings.add("KS180084");
strings.add(user.getLoginName());
User user3 = new User();
user3.setIsSender("1");
List<User> listUsers = userService.selectUserList(user3);
if (CollectionUtils.isNotEmpty(listUsers)) {
for (User listUser : listUsers) {
strings.add(listUser.getLoginName());
}
}
oaMessage.setLoginNames(strings);
String content = "条码:" + srmDetail.getLineCode() + ";物料编码:" + srmDetail.getMaterialCode() + ";不合格原因:" + srmDetail.getReason() + ";数量:" + srmDetail.getUnqualifiedQty() + ";质检员:" + user2.getUserName() + ";质检时间:" + DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss", srmDetail.getCheckTime());
oaMessage.setContent(content);
oaMessage.setUrl(new ArrayList<>());
String uri = configService.selectConfigByKey("getOaToken", srmDetail.getWarehouseCode());
String url = "http://oa.huahengweld.com/seeyon/rest/message?token=" + uri;
String jsonString = JSONObject.toJSONString(oaMessage);
String s = OkHttpUtils.bodypost(url, jsonString, QuantityConstant.WAREHOUSE_KS, "OA-message");
JSONObject jsonObject = JSONObject.parseObject(s);
Integer result = jsonObject.getInteger("result");
if (result == 1) {
srmDetail.setSendOaStatus(1);
} else if (result == 0) {
srmDetail.setSendOaStatus(0);
} else {
srmDetail.setSendOaStatus(-1);
String errorMessage = jsonObject.getString("errorMessage");
srmDetail.setSendOaMessage(errorMessage);
}
srmDetailService.updateById(srmDetail);
} catch (Exception e) {
}
}
}