BasicDataApiService.java
30.1 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
561
562
563
564
565
566
567
568
569
570
571
572
573
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
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
package com.huaheng.api.general.service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.huaheng.api.general.domain.ContainerTypeDomain;
import com.huaheng.api.general.domain.InventoryDomain;
import com.huaheng.api.general.domain.InventoryQueryDomain;
import com.huaheng.common.exception.service.ServiceException;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.pc.config.company.domain.Company;
import com.huaheng.pc.config.company.service.CompanyService;
import com.huaheng.pc.config.containerCapacity.domain.ContainerCapacity;
import com.huaheng.pc.config.containerCapacity.service.ContainerCapacityService;
import com.huaheng.pc.config.containerType.domain.ContainerType;
import com.huaheng.pc.config.containerType.service.ContainerTypeService;
import com.huaheng.pc.config.customer.domain.Customer;
import com.huaheng.pc.config.customer.service.CustomerServiceImpl;
import com.huaheng.pc.config.material.domain.Material;
import com.huaheng.pc.config.material.service.MaterialService;
import com.huaheng.pc.config.supplier.domain.Supplier;
import com.huaheng.pc.config.supplier.service.SupplierService;
import com.huaheng.pc.config.warehouse.domain.Warehouse;
import com.huaheng.pc.config.warehouse.service.WarehouseService;
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.inventory.inventoryHeader.service.InventoryHeaderService;
import com.huaheng.pc.system.dept.domain.Dept;
import com.huaheng.pc.system.dept.service.IDeptService;
import com.huaheng.pc.system.dict.domain.DictData;
import com.huaheng.pc.system.dict.domain.DictType;
import com.huaheng.pc.system.dict.mapper.DictDataMapper;
import com.huaheng.pc.system.dict.mapper.DictTypeMapper;
import com.huaheng.pc.system.dict.service.IDictDataService;
import com.huaheng.pc.system.dict.service.IDictTypeService;
import com.huaheng.pc.system.user.domain.User;
import com.huaheng.pc.system.user.service.IUserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Component
@Transactional
public class BasicDataApiService {
@Autowired
IDictTypeService dictTypeService;
@Autowired
IDictDataService dictDataService;
@Autowired
MaterialService materialService;
@Autowired
ContainerTypeService containerTypeService;
@Autowired
InventoryDetailService inventoryDetailService;
@Autowired
InventoryHeaderService inventoryHeaderService;
@Resource
private DictTypeMapper dictTypeMapper;
@Resource
private DictDataMapper dictDataMapper;
@Autowired
IUserService iUserService;
@Autowired
IDeptService iDeptService;
@Autowired
CustomerServiceImpl iCustomerService;
@Autowired
WarehouseService iWarehouseService;
@Autowired
SupplierService iSupplierService;
@Autowired
CompanyService companyService;
@Autowired
private ContainerCapacityService containerCapacityService;
private static final Logger logger = LoggerFactory.getLogger("base-api");
//检查仓库
public Warehouse checkWarehouse(String code) {
LambdaQueryWrapper<Warehouse> warehouseLam = Wrappers.lambdaQuery();
warehouseLam.eq(Warehouse::getCode, code);
Warehouse warehouse = iWarehouseService.getOne(warehouseLam);
if (warehouse == null) {
throw new ServiceException("数据出现问题,系统没有该仓库");
}
return warehouse;
}
/**
* 字典通用接口
* 1、判断必填字段是否为空
* 2、仓库是否正确
* 3、检查字典头表,如果没有就添加
* 4、增新一条字典明细表的记录
* @param dictData
* @return
*/
public AjaxResult dict(DictData dictData) {
//1、判断必填字段是否为空
if(StringUtils.isEmpty(dictData.getWarehouseCode())){
return AjaxResult.error("没有仓库编码");
}
if(StringUtils.isEmpty(dictData.getDictLabel())){
return AjaxResult.error("没有字典标签");
}
if(StringUtils.isEmpty(dictData.getDictType())){
return AjaxResult.error("没有字典类型");
}
if(StringUtils.isEmpty(dictData.getDictValue())){
return AjaxResult.error("没有字典键值");
}
//2、仓库是否正确
int result = 0;
this.checkWarehouse(dictData.getWarehouseCode());
//3、检查字典头表,如果没有就添加
DictData condition = new DictData();
try {
condition.setDictType(dictData.getDictType());
condition.setWarehouseCode(dictData.getWarehouseCode());
condition.setDictValue(dictData.getDictValue());
condition.setEnable(true);
List<DictData> dictDatas = dictDataService.selectDictDataList(dictData);
if (dictDatas.size() < 1) {
//找出字典头表的id
DictType dictType = new DictType();
dictType.setWarehouseCode(dictData.getWarehouseCode());
dictType.setDictType(dictData.getDictType());
List<DictType> dictList = dictTypeService.selectDictTypeList(dictType);
if (dictList.size() < 1) {
dictType.setWarehouseId(dictData.getWarehouseId());
dictType.setCreateBy(dictData.getCreateBy());
dictType.setCreateTime(dictData.getCreateTime());
if(StringUtils.isEmpty(dictType.getCreateBy())) {
result = dictTypeService.insertDictType(dictType);
}else {
result=dictTypeMapper.insertDictType(dictType);
}
dictList.add(dictType);
if (result < 1) {
throw new ServiceException("新增字典类型失败!");
}
}
//4、增新一条字典明细表的记录
dictData.setHeaderId(dictList.get(0).getId());
if(StringUtils.isEmpty(dictData.getCreateBy())) {
result = dictDataService.insertDictData(dictData);
}else {
result=dictDataMapper.insertDictData(dictData);
}
if (result < 1) {
throw new ServiceException("新增字典数据失败!");
}
}
}catch (Exception e){
throw new ServiceException("字典数据有误!!");
}
return AjaxResult.success("新增字典成功");
}
/**
* 检查是否存在物料,如果存在就修改,不存在就新增
* 1、判断必填字段是否为空
* 2、检查仓库和货主
* 3、查看此物料在系统是否存在
* @param material
* @return
*/
@Transactional
public AjaxResult material(Material material) {
//1、判断必填字段是否为空
if(StringUtils.isEmpty(material.getCode())){
return AjaxResult.error("物料编码不能为空!!");
}
if(StringUtils.isEmpty(material.getWarehouseCode())){
return AjaxResult.error("仓库编码不能为空!!");
}
if(StringUtils.isEmpty(material.getCompanyCode())){
return AjaxResult.error("货主编码不能为空!!");
}
if(StringUtils.isEmpty(material.getType())){
return AjaxResult.error("物料类型不能为空!!");
}
if(StringUtils.isEmpty(material.getName())){
return AjaxResult.error("物料名称不能为空!!");
}
if(StringUtils.isEmpty(material.getSpec())){
return AjaxResult.error("物料规格不能为空!!");
}
if(StringUtils.isEmpty(material.getUnit())){
return AjaxResult.error("物料单位不能为空!!");
}
//2、检查仓库和货主
this.checkWarehouse(material.getWarehouseCode());
LambdaQueryWrapper<Company> companyLam = Wrappers.lambdaQuery();
companyLam.eq(Company::getCode,material.getCompanyCode());
Company company=companyService.getOne(companyLam);
if(company==null){
return AjaxResult.error("没有该货主!!");
}
Boolean flag = false;
try {
//3、查看此物料在系统是否存在
LambdaQueryWrapper<Material> materialLam = Wrappers.lambdaQuery();
materialLam.eq(Material::getCode,material.getCode())
.eq(Material::getWarehouseCode,material.getWarehouseCode());
Material entity = materialService.getOne(materialLam);
if (entity == null) {
flag = materialService.save(material);
if (flag == false) {
throw new ServiceException("新增物料失败!");
}
} else {
// return AjaxResult.error("已有该物料,无法进行修改!!");
material.setId(entity.getId());
flag = materialService.updateById(material);
if (flag == false) {
throw new ServiceException("更新物料失败!");
}else {
return AjaxResult.success("更新物流成功!");
}
}
}catch (Exception e){
throw new ServiceException("物料数据问题");
}
return AjaxResult.success("新增物料成功");
}
/**
1,物料同步
2,条件查询
* @param material
* @return
*/
@Transactional
public AjaxResult queryMaterial(Material material) {
if (StringUtils.isEmpty(material.getWarehouseCode())){
return AjaxResult.error("仓库编码不能为空!!");
}
if (StringUtils.isEmpty(material.getCompanyCode())){
return AjaxResult.error("货主编码不能为空!!");
}
LambdaQueryWrapper<Material> lambdaQueryWrapper =Wrappers.lambdaQuery(material);
materialService.list(lambdaQueryWrapper);
return AjaxResult.success(materialService.list(lambdaQueryWrapper));
}
/**
* 人员档案通用接口
* 1、判断必填字段是否为空
* 2、判断系统中是否有该用户,如果有则更新,如果没有则新增
*新增: (1)、默认密码为123456
* (2)默认为普通用户
* (3)默认为长沙仓库
* @param user
* @return
*/
public AjaxResult user(User user){
//1、判断必填字段是否为空
int result = 0;
User user1 = new User();
if(user.getLoginName()==null || user.getLoginName()=="") {
return AjaxResult.error("没有人员编码!!");
}
if (user.getUserName()==null || user.getUserName()==""){
return AjaxResult.error("没有人员名称!!");
}
if(user.getDeptId()==null){
return AjaxResult.error("没有部门ID!!");
}
if(iDeptService.selectDeptById(user.getDeptId())==null){
return AjaxResult.error("系统没有此部门!!");
}
try {
user1.setLoginName(user.getLoginName());
//2、判断系统中是否有该用户,如果有则更新,如果没有则新增
if (iUserService.selectmen(user.getLoginName()) == null) {
//(1)默认密码为123456
if(user.getPassword()==null) {
user.setPassword("123456");
}
//(2)默认为普通用户
if(StringUtils.isEmpty(user.getRoleIds())) {
List<Integer> roleIds=new ArrayList<>();
roleIds.add(2);
user.setRoleIds(roleIds);
}
//(3)默认为长沙仓库
if(StringUtils.isEmpty(user.getCompanyIdList())) {
List<Integer> companyIdList = new ArrayList<>();
companyIdList.add(2);
user.setCompanyIdList(companyIdList);
}
result = iUserService.insertUser(user);
if (result < 1) {
throw new ServiceException("新增人员档案失败!");
} else {
return AjaxResult.success("新增人员档案成功!");
}
} else {
return AjaxResult.error("已有该人员档案,无法进行修改!");
// result = iUserService.updateUser(user);
// if (result < 1) {
// throw new ServiceException("更新人员档案失败!");
// } else {
// return AjaxResult.success("更新人员档案成功!");
// }
}
}catch (Exception e){
throw new ServiceException("数据问题。。。");
}
}
/**
1,用户同步
2,条件查询
* @param user
* @return
*/
@Transactional
public AjaxResult queryUser(User user) {
iUserService.selectUserList(user);
return AjaxResult.success(iUserService.selectUserList(user));
}
/**
* 部门档案通用接口
* 1、判断必填字段是否为空
* 2、部门编码长度应是双数
*
* @param dept
* @return
*/
@Transactional
public AjaxResult dept(Dept dept) {
//1、判断必填字段是否为空
int result = 0;
String code = dept.getCode();
if (code == null || code == "") {
return AjaxResult.error("部门编码不能为空!!");
}
try {
Dept rs = iDeptService.selectDepts(code);
//2、部门编码长度应是双数
if (rs == null) {
int x = code.length() % 2;
if (x != 0) {
return AjaxResult.error("部门编码长度应是双数");
} else {
int y = code.length() / 2;
if (y >= 1) {
String scode = code.substring(0, 2);
if (iDeptService.selectDepts(scode) == null) {
dept.setCode(scode);
dept.setParentId(100);
dept.setAncestors("0,100");
dept.setOrderNum("1");
result = iDeptService.insertDept(dept);
if (result < 1) {
throw new ServiceException("新增部门档案失败!");
}
}
}
for (int z = 1; z <=y; z++) {
//找到上级部门
String sqcode = code.substring(0, 2 * (z - 1));
Dept sdept = iDeptService.selectDepts(sqcode);
String sscode = code.substring(0, 2 * z);
if (iDeptService.selectDepts(sscode) == null) {
dept.setCode(sscode);
dept.setParentId(sdept.getId());
dept.setAncestors(sdept.getAncestors() + "," + sdept.getId());
dept.setOrderNum(String.valueOf(z));
result = iDeptService.insertDept(dept);
if (result < 1) {
throw new ServiceException("新增部门档案失败!");
}
}
}
}
return AjaxResult.success("新增部门成功");
} else {
dept.setId(rs.getId());
int num = iDeptService.updatesDept(dept);
if (num < 1) {
throw new ServiceException("部门修改失败");
} else {
return AjaxResult.success("部门修改成功");
}
}
} catch (Exception e) {
throw new ServiceException("数据问题。。。");
}
}
/**
* 客户档案通用接口
* 1、判断必填字段是否为空
* 2、检查仓库
* 3、查看此客户在系统是否存在
* @param customer
* @return
*/
public AjaxResult customer(Customer customer){
Boolean flag = true;
//1、判断必填字段是否为空
if(customer.getCode()==null||customer.getCode()=="") {
return AjaxResult.error("客户代码不能为空!!");
}
if(StringUtils.isEmpty(customer.getWarehouseCode())){
return AjaxResult.error("没有仓库编码");
}
if(StringUtils.isEmpty(customer.getName())){
return AjaxResult.error("没有客户名称");
}
if(StringUtils.isEmpty(customer.getCompanyCode())){
return AjaxResult.error("没有货主编码");
}
try {
//2、检查仓库
this.checkWarehouse(customer.getWarehouseCode());
//3、查看此客户在系统是否存在
LambdaQueryWrapper<Customer> customerLam = Wrappers.lambdaQuery();
customerLam.eq(Customer::getCode,customer.getCode())
.eq(Customer::getWarehouseCode,customer.getWarehouseCode());
Customer ctr = iCustomerService.getOne(customerLam);
//不存在添加
if ( ctr == null) {
flag = iCustomerService.save(customer);
if (flag == false) {
throw new ServiceException("新增客户档案失败!");
} else {
return AjaxResult.success("新增客户档案成功!");
}
} else {
return AjaxResult.error("已有该客户,无法进行修改!!");
// customer.setId(rs.getId());
// result = iCustomerService.updateByModel(customer);
// if (result < 1) {
// throw new ServiceException("更新客户档案失败!");
// } else {
// return AjaxResult.success("更新客户档案成功!");
// }
}
}catch (Exception e){
throw new ServiceException("数据问题。。。");
}
}
/**
* 仓库档案通用接口
* 1、判断必填字段是否为空
* 2、判断系统中是否有该仓库,若有则更新,若无则新增
* @param warehouse
* @return
*/
public AjaxResult warehouse(Warehouse warehouse){
if(warehouse.getCode()==null||warehouse.getCode()=="") {
return AjaxResult.error("仓库编码不能为空!!");
}
if(warehouse.getName()==null||warehouse.getName()=="") {
return AjaxResult.error("仓库名称不能为空!!");
}
try {
LambdaQueryWrapper<Warehouse> warehouseLam = Wrappers.lambdaQuery();
warehouseLam.eq(Warehouse::getCode,warehouse.getCode());
Warehouse whs = iWarehouseService.getOne(warehouseLam);
//2、判断系统中是否有该仓库,若有则更新,若无则新增
if (whs == null) {
Boolean flag = iWarehouseService.save(warehouse);
if (flag == false) {
throw new ServiceException("新增仓库档案失败!");
} else {
return AjaxResult.success("新增仓库档案成功!");
}
} else {
return AjaxResult.error("已有该仓库,无法进行修改!");
// warehouse.setId(rs.getId());
// result = iWarehouseService.updateByModel(warehouse);
// if (result < 1) {
// throw new ServiceException("更新仓库档案失败!");
// } else {
// return AjaxResult.success("更新仓库档案成功!");
// }
}
}catch (Exception e){
throw new ServiceException("仓库数据问题。。。");
}
}
/**
* 供应商档案通用接口
* 1、判断必填字段是否为空
* 2、检查仓库
* 3、查看此供应商在系统是否存在
* @param supplier
* @return
*/
public AjaxResult supplier(Supplier supplier){
//1、判断必填字段是否为空
if(StringUtils.isEmpty(supplier.getCode())){
return AjaxResult.error("没有供应商代码");
}
if(StringUtils.isEmpty(supplier.getName())){
return AjaxResult.error("没有供应商名称");
}
if(StringUtils.isEmpty(supplier.getWarehouseCode())){
return AjaxResult.error("没有仓库编码");
}
//2、检查仓库
this.checkWarehouse(supplier.getCode());
//3、查看此供应商在系统是否存在
try {
LambdaQueryWrapper<Supplier> supplierLam = Wrappers.lambdaQuery();
supplierLam.eq(Supplier::getCode,supplier.getCode())
.eq(Supplier::getWarehouseCode,supplier.getWarehouseCode());
Supplier spl=iSupplierService.getOne(supplierLam);
if (spl== null) {
Boolean flag = iSupplierService.save(supplier);
if (flag == false) {
throw new ServiceException("新增供应商失败!");
} else {
return AjaxResult.success("新增供应商成功!");
}
} else {
return AjaxResult.error("已有该供应商,无法修改!!");
}
}catch (Exception e){
throw new ServiceException("供应商数据问题。。。");
}
}
/**
* 容器容量通用接口
* 1、判断必填字段是否为空
* 2、检查仓库、物料和容器类型
* 3、检查此容器容量是否存在,不存在则添加
* @param containerCapacity
* @return
*/
public AjaxResult containerCapacity(ContainerCapacity containerCapacity){
Boolean flag = false;
//1、判断必填字段是否为空
if(StringUtils.isEmpty(containerCapacity.getContainerType())){
return AjaxResult.error("没有容器类型");
}
if(StringUtils.isEmpty(containerCapacity.getWarehouseCode())){
return AjaxResult.error("没有仓库编号");
}
if(StringUtils.isEmpty(containerCapacity.getMaterialCode())){
return AjaxResult.error("没有物料编号");
}
if(StringUtils.isNull(containerCapacity.getQty())){
return AjaxResult.error("没有容量上限");
}
// 2、检查仓库、物料和容器类型
this.checkWarehouse(containerCapacity.getWarehouseCode());
//物料检查
LambdaQueryWrapper<Material> materialLam = Wrappers.lambdaQuery();
materialLam.eq(Material::getCode,containerCapacity.getMaterialCode())
.eq(Material::getWarehouseCode,containerCapacity.getWarehouseCode());
Material material = materialService.getOne(materialLam);
if(material == null){
return AjaxResult.error("系统没有此物料编号");
}
//容器类型检查
LambdaQueryWrapper<ContainerType> containerTypeLamb = Wrappers.lambdaQuery();
containerTypeLamb.eq(ContainerType::getCode,containerCapacity.getContainerType())
.eq(ContainerType::getWarehouseCode,containerCapacity.getWarehouseCode());
ContainerType containerType = containerTypeService.getOne(containerTypeLamb);
if(containerType == null){
return AjaxResult.error("系统没有此容器类型");
}
//3、检查此容器容量是否存在,不存在则添加
LambdaQueryWrapper<ContainerCapacity> containerCapacityLambd = Wrappers.lambdaQuery();
containerCapacityLambd.eq(ContainerCapacity::getContainerType,containerCapacity.getContainerType())
.eq(ContainerCapacity::getWarehouseCode,containerCapacity.getWarehouseCode())
.eq(ContainerCapacity::getMaterialCode,containerCapacity.getMaterialCode());
ContainerCapacity capacity = containerCapacityService.getOne(containerCapacityLambd);
if(capacity == null){
flag = containerCapacityService.save(containerCapacity);
if(flag == false){
return AjaxResult.error("新增容器容量失败");
}
}else {
if(capacity.getQty().compareTo(containerCapacity.getQty()) != 0){
capacity.setQty(containerCapacity.getQty());
flag = containerCapacityService.updateById(capacity);
if(flag == false){
return AjaxResult.error("修改容器容量失败");
}
}
}
return AjaxResult.success("新增容器容量成功");
}
public AjaxResult containerType(ContainerTypeDomain containerTypeDomain){
if ("0".equals(containerTypeDomain.getCode())){
if (!containerTypeService.saveBatch(containerTypeDomain.getContainerTypeList())){
logger.error("erp初始化容器类型失败,失败原因:无法插入数据");
return AjaxResult.error("初始化容器类型失败");
}
return AjaxResult.success("容器类型初始化成功");
}else {
LambdaQueryWrapper<ContainerType> lambdaQuery;
for (ContainerType containerType : containerTypeDomain.getContainerTypeList()) {
lambdaQuery = Wrappers.lambdaQuery();
lambdaQuery.eq(ContainerType::getCode,containerType.getCode());
ContainerType srcContainerType = containerTypeService.getOne(lambdaQuery);
if (srcContainerType ==null){
if (!containerTypeService.save(containerType)){
logger.error("erp更新容器类型失败,失败原因:无法插入数据");
return AjaxResult.error("插入容器类型失败");
}
}else {
containerType.setId(srcContainerType.getId());
if (!containerTypeService.updateById(containerType)){
logger.error("erp更新容器类型失败,失败原因:无法更新数据");
return AjaxResult.error("更新容器类型失败");
}
}
}
return AjaxResult.success("容器类型更新成功");
}
}
/**
1,库存同步
2,条件查询
* @param inventoryDetail
* @return
*/
@Transactional
public AjaxResult queryInventoryApi(InventoryDetail inventoryDetail) {
if (StringUtils.isEmpty(inventoryDetail.getWarehouseCode())){
return AjaxResult.error("仓库编码不能为空!!");
}
if (StringUtils.isEmpty(inventoryDetail.getCompanyCode())){
return AjaxResult.error("货主编码不能为空!!");
}
//查询库存明细
LambdaQueryWrapper<InventoryDetail> lambdaQueryWrapper =Wrappers.lambdaQuery(inventoryDetail);
List<InventoryDetail> inventoryDetailList = inventoryDetailService.list(lambdaQueryWrapper);
//查询库存Header表
Map<Integer,InventoryHeader> inventoryHeaderList = new HashMap<>();//map防止出现数据重复
for (InventoryDetail inventoryDetail1:inventoryDetailList) {
LambdaQueryWrapper<InventoryHeader> inventoryHeaderLambdaQueryWrapper =Wrappers.lambdaQuery();
inventoryHeaderLambdaQueryWrapper.eq(InventoryHeader::getId,inventoryDetail1.getInventoryHeaderId());
inventoryHeaderList.put(inventoryDetail1.getInventoryHeaderId(),inventoryHeaderService.getOne(inventoryHeaderLambdaQueryWrapper));
}
InventoryDomain inventoryDomain =new InventoryDomain();
inventoryDomain.setInventoryHeader(inventoryHeaderList);
inventoryDomain.setInventoryDetails(inventoryDetailList);
return AjaxResult.success(inventoryDomain);
}
public AjaxResult queryInventory(InventoryQueryDomain queryDomain){
if (StringUtils.isEmpty(queryDomain.getWarehouseCode())){
return AjaxResult.error("仓库编码不能为空");
}
if (StringUtils.isEmpty(queryDomain.getCompanyCode())){
return AjaxResult.error("货主编码不能为空");
}
if (StringUtils.isEmpty(queryDomain.getContainerCode())&&StringUtils.isEmpty(queryDomain.getLocationCode())&&StringUtils.isEmpty(queryDomain.getMaterialCode())){
return AjaxResult.error("容器、库位与物料至少一样不为空");
}
LambdaQueryWrapper<InventoryDetail> queryWrapper = Wrappers.lambdaQuery();
queryWrapper.eq(InventoryDetail::getWarehouseCode,queryDomain.getWarehouseCode())
.eq(InventoryDetail::getCompanyCode,queryDomain.getCompanyCode());
ArrayList<InventoryDetail> inventoryDetails = new ArrayList<>();
if (StringUtils.isNotEmpty(queryDomain.getContainerCode())){
queryWrapper.eq(InventoryDetail::getContainerCode,queryDomain.getContainerCode());
}
if (StringUtils.isNotEmpty(queryDomain.getLocationCode())){
queryWrapper.eq(InventoryDetail::getLocationCode,queryDomain.getLocationCode());
}
if (StringUtils.isNotEmpty(queryDomain.getMaterialCode())){
queryWrapper.eq(InventoryDetail::getMaterialCode,queryDomain.getMaterialCode());
}
List<InventoryDetail> list = inventoryDetailService.list(queryWrapper);
if (list==null){
return AjaxResult.error("没有符合条件的库存");
}
return AjaxResult.success("获取成功",list);
}
}