|
1
2
|
package com.huaheng.pc.u8.service;
|
周鸿
authored
|
3
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
4
|
import com.huaheng.common.constant.QuantityConstant;
|
|
5
|
import com.huaheng.common.utils.StringUtils;
|
周鸿
authored
|
6
|
import com.huaheng.common.utils.Wrappers;
|
|
7
8
9
10
11
12
13
14
15
16
17
|
import com.huaheng.common.utils.security.ShiroUtils;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.pc.config.company.domain.CompanyU8;
import com.huaheng.pc.config.company.service.CompanyU8Service;
import com.huaheng.pc.config.material.domain.Material;
import com.huaheng.pc.config.material.service.MaterialService;
import com.huaheng.pc.config.materialType.domain.MaterialType;
import com.huaheng.pc.config.materialType.service.MaterialTypeService;
import com.huaheng.pc.config.warehouseCompany.domain.WarehouseCompany;
import com.huaheng.pc.config.warehouseCompany.service.WarehouseCompanyService;
|
|
18
|
|
|
19
20
21
22
23
24
25
26
27
28
29
|
import com.huaheng.pc.u8.domain.ICSMaterialModel;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
@Service
public class MaterialAPIService {
|
|
30
|
|
|
31
32
33
34
|
@Resource
private CompanyU8Service companyU8Service;
@Resource
MaterialService materialService;
|
|
35
|
|
|
36
37
38
39
40
41
42
43
44
45
|
@Resource
private WarehouseCompanyService warehouseCompanyService;
@Resource
private MaterialTypeService materialTypeService;
@Transactional
public AjaxResult ICSInventory(List<ICSMaterialModel> iCSInventorys) {
WarehouseCompany warehouseCompany = new WarehouseCompany();
AjaxResult ajaxResult = new AjaxResult();
List<Material> materials=new ArrayList<>();
|
周鸿
authored
|
46
|
List<Material> materialUpdates=new ArrayList<>();
|
|
47
48
|
List<MaterialType> materialTypeList=new ArrayList<>();
for(ICSMaterialModel iCSInventory:iCSInventorys) {
|
|
49
50
51
52
|
String warehouseCode=iCSInventory.getWarehouseCode();
if(StringUtils.isEmpty(warehouseCode)){
return AjaxResult.error("仓库code不存在");
}
|
|
53
54
|
CompanyU8 companyWu=new CompanyU8();
companyWu.setUCompanyCode(iCSInventory.getCompanyCode());
|
|
55
|
companyWu=companyU8Service.getCompanyByU8CodeWarehouseCodeV(iCSInventory.getCompanyCode(),warehouseCode);
|
|
56
57
58
59
60
61
62
63
|
if (companyWu == null) {
return AjaxResult.error("货主不存在");
}
warehouseCompany.setCompanyCode(companyWu.getCompanyCode());
List<WarehouseCompany> list = warehouseCompanyService.getByDoamin(warehouseCompany);
if (list == null || list.size() == 0) {
return AjaxResult.error("系统中没有该货主:" + warehouseCompany.toString() + " 信息,请先录入货主信息!");
}
|
周鸿
authored
|
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
//3、查看此物料在系统是否存在
LambdaQueryWrapper<Material> materialLam = Wrappers.lambdaQuery();
materialLam.eq(Material::getCode,iCSInventory.getcInvCode())
.eq(Material::getWarehouseCode,iCSInventory.getWarehouseCode());
Material entity = materialService.getOne(materialLam);
if(entity!=null){
entity.setBarcode(iCSInventory.getcInvAddCode());
entity.setName(iCSInventory.getcInvName());
entity.setUserDef1(iCSInventory.getcInvAddCode());
entity.setSpec(iCSInventory.getcInvStd());
entity.setUnit(iCSInventory.getcComUnitName());
entity.setWarehouseCode(companyWu.getWarehouseCode());
// material.setAssistUnit(iCSInventory.getcAssComUnitCode());
// material.setConvertRate(iCSInventory.getfConvertRate());
entity.setType(iCSInventory.getcInvCCode());
entity.setLastUpdatedBy(ShiroUtils.getLoginName());
materialUpdates.add(entity);
}else{
|
|
82
83
84
85
86
87
88
|
Material material = new Material();
material.setCode(iCSInventory.getcInvCode());
material.setBarcode(iCSInventory.getcInvAddCode());
material.setName(iCSInventory.getcInvName());
material.setUserDef1(iCSInventory.getcInvAddCode());
material.setSpec(iCSInventory.getcInvStd());
material.setUnit(iCSInventory.getcComUnitName());
|
|
89
|
material.setWarehouseCode(companyWu.getWarehouseCode());
|
|
90
91
92
93
94
|
// material.setAssistUnit(iCSInventory.getcAssComUnitCode());
// material.setConvertRate(iCSInventory.getfConvertRate());
material.setType(iCSInventory.getcInvCCode());
// material.setDictLabel(iCSInventory.getcInvCName());
// material.setCompanyId(item.getCompanyId());
|
|
95
|
// material.setCompanyCode(item.getCompanyCode());
|
|
96
|
// material.setWarehouseId(item.getWarehouseId());
|
|
97
|
material.setWarehouseCode(iCSInventory.getWarehouseCode());
|
|
98
99
100
|
material.setLastUpdatedBy(ShiroUtils.getLoginName());
material.setCreatedBy(ShiroUtils.getLoginName());
|
周鸿
authored
|
101
102
103
104
|
materials.add(material);
// if(materialService.getMaterialByCode(material.getCode(),material.getWarehouseCode())==null) {
// materials.add(material);
// }
|
|
105
106
107
108
109
110
111
112
113
114
|
//查找MaterialType有无该数据
MaterialType materialType=new MaterialType();
materialType.setCode(material.getType());
materialType.setWarehouseCode(material.getWarehouseCode());
List<MaterialType> materialTypelist=materialTypeService.getMaterialTypeByDoamin(materialType);
if(materialTypelist==null||materialTypelist.size()==0){
MaterialType materialType1=createMaterialType(material, iCSInventory);
materialTypeList.add(materialType1);
}
|
周鸿
authored
|
115
116
117
118
|
}
//先查询货主对应的仓库,有几个仓库,就循环几次来添加。
// for (WarehouseCompany item : list) {
|
|
119
120
121
122
|
}
if(materials.size()>0) {
materialService.saveBatch(materials);
}
|
周鸿
authored
|
123
124
125
|
if(materialUpdates.size()>0) {
materialService.updateBatchById(materialUpdates);
}
|
|
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
if(materialTypeList.size()>0) {
materialTypeService.saveBatch(materialTypeList);
}
return AjaxResult.success("成功");
}
public MaterialType createMaterialType(Material material,ICSMaterialModel iCSInventory){
MaterialType materialType=new MaterialType();
materialType.setCode(material.getType());
materialType.setWarehouseCode(material.getWarehouseCode());
materialType.setName(iCSInventory.getcInvCName());
materialType.setCompanyCode(material.getCompanyCode());
materialType.setCreatedBy(ShiroUtils.getUserName());
materialType.setLastUpdatedBy(ShiroUtils.getUserName());
return materialType;
}
}
|