MaterialAPIService.java
6.87 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
package com.huaheng.pc.u8.service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.huaheng.common.constant.QuantityConstant;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.common.utils.Wrappers;
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;
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 {
@Resource
private CompanyU8Service companyU8Service;
@Resource
MaterialService materialService;
@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<>();
List<Material> materialUpdates=new ArrayList<>();
List<MaterialType> materialTypeList=new ArrayList<>();
for(ICSMaterialModel iCSInventory:iCSInventorys) {
String warehouseCode=iCSInventory.getWarehouseCode();
if(StringUtils.isEmpty(warehouseCode)){
return AjaxResult.error("仓库code不存在");
}
CompanyU8 companyWu=new CompanyU8();
companyWu.setUCompanyCode(iCSInventory.getCompanyCode());
companyWu=companyU8Service.getCompanyByU8CodeWarehouseCodeV(iCSInventory.getCompanyCode(),warehouseCode);
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() + " 信息,请先录入货主信息!");
}
//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{
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());
material.setWarehouseCode(companyWu.getWarehouseCode());
// material.setAssistUnit(iCSInventory.getcAssComUnitCode());
// material.setConvertRate(iCSInventory.getfConvertRate());
material.setType(iCSInventory.getcInvCCode());
// material.setDictLabel(iCSInventory.getcInvCName());
// material.setCompanyId(item.getCompanyId());
// material.setCompanyCode(item.getCompanyCode());
// material.setWarehouseId(item.getWarehouseId());
material.setWarehouseCode(iCSInventory.getWarehouseCode());
material.setLastUpdatedBy(ShiroUtils.getLoginName());
material.setCreatedBy(ShiroUtils.getLoginName());
materials.add(material);
// if(materialService.getMaterialByCode(material.getCode(),material.getWarehouseCode())==null) {
// materials.add(material);
// }
//查找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);
}
}
//先查询货主对应的仓库,有几个仓库,就循环几次来添加。
// for (WarehouseCompany item : list) {
}
if(materials.size()>0) {
materialService.saveBatch(materials);
}
if(materialUpdates.size()>0) {
materialService.updateBatchById(materialUpdates);
}
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;
}
}