MOMService.java
7.24 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
package com.huaheng.api.erp.service;
import com.alibaba.fastjson.JSON;
import com.huaheng.api.erp.domain.mom.MOMMaterial;
import com.huaheng.common.constant.QuantityConstant;
import com.huaheng.pc.config.material.domain.Material;
import com.huaheng.pc.config.materialGroup.domain.ERPMaterialGroup;
import com.huaheng.api.erp.domain.mom.MOMResult;
import com.huaheng.api.erp.domain.mom.QueryParam;
import com.huaheng.api.general.service.BasicDataApiService;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.common.utils.http.HttpUtils;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.pc.config.address.service.AddressService;
import com.huaheng.pc.config.materialGroup.service.MaterialGroupService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
@Service
public class MOMService {
@Resource
private AddressService addressService;
@Resource
private BasicDataApiService basicDataApiService;
@Resource
private MaterialGroupService materialGroupService;
public AjaxResult pullMaterialInfo(QueryParam queryParam){
String filterString = "";
String groupname = queryParam.getGroupname();
queryParam.setGroupname("");
if(queryParam!=null){
filterString = queryParam.toJson();
}
// String url = "http://42.236.3.82:31789/api/MaterielInfo/GetMaterielInfo";
String url = addressService.selectAddress(QuantityConstant.ERP_PULL_MATERIALINFO, QuantityConstant.DEFAULT_WAREHOUSE, null);
String result = HttpUtils.sendGet(url, filterString);
if(StringUtils.isEmpty(result)){
return AjaxResult.error("返回为空");
}
MOMResult MOMResult = JSON.parseObject(result, MOMResult.class);
if(MOMResult.hasError()){
return AjaxResult.error(MOMResult.getMessage());
}
Object[] rows = MOMResult.getRows();
if(rows.length==0){
return AjaxResult.success();
}
String s = JSON.toJSONString(rows);
MOMMaterial[] MOMMaterials = JSON.parseObject(s, MOMMaterial[].class);
for (MOMMaterial MOMMaterial : MOMMaterials) {
Material material = new Material();
material.setWarehouseCode(QuantityConstant.DEFAULT_WAREHOUSE);
material.setCompanyCode(QuantityConstant.DEFAULT_COMPANY);
material.setType(MOMMaterial.getMaterialtype());
material.setCode(MOMMaterial.getErpcode());
material.setName(groupname + " " + MOMMaterial.getMaterialname());
material.setSpec(MOMMaterial.getSpecification());
material.setUnit(MOMMaterial.getMaterialunit());
material.setMaterialguid(MOMMaterial.getMaterialguid());
material.setBrand(MOMMaterial.getMateriallog());
material.setTexture(MOMMaterial.getTexture());
basicDataApiService.material(material);
}
return AjaxResult.success();
}
private ERPMaterialGroup[] pullMaterialGroup(){
ERPMaterialGroup[] materialGroups = null;
String url = addressService.selectAddress(QuantityConstant.ERP_PULL_MATERIALGROUP, QuantityConstant.DEFAULT_WAREHOUSE, null);
// String url = "http://42.236.3.82:31789/api/MaterielGroup/GetMaterielGroup";
String res = HttpUtils.sendGet(url,null);
// String res = "{\"success\":true,\"rows\":[{\"iid\":9597,\"createtime\":\"2022-05-21T00:00:00\",\"createuser\":null,\"groupguid\":\"6426a90f-0699-4586-9297-47c0f8646a57\",\"erpguidguid\":\"100623\",\"erppareneguid\":\"0\",\"groupname\":\"标准机械\",\"groupcode\":\"41\",\"isdelete\":0,\"parentguid\":\"0\",\"children\":[{\"iid\":9565,\"createtime\":\"2022-05-21T00:00:00\",\"createuser\":null,\"groupguid\":\"a063dc24-045e-43f0-9c66-67600173258d\",\"erpguidguid\":\"102818\",\"erppareneguid\":\"100623\",\"groupname\":\"过滤器\",\"groupcode\":\"41.10\",\"isdelete\":0,\"parentguid\":\"6426a90f-0699-4586-9297-47c0f8646a57\",\"children\":[{\"iid\":9561,\"createtime\":\"2022-05-21T00:00:00\",\"createuser\":null,\"groupguid\":\"1109c6c9-da25-4e70-a745-d508210444b0\",\"erpguidguid\":\"127116\",\"erppareneguid\":\"102818\",\"groupname\":\"浸没式超滤膜组件\",\"groupcode\":\"41.10.105\",\"isdelete\":0,\"parentguid\":\"a063dc24-045e-43f0-9c66-67600173258d\",\"children\":[]},{\"iid\":9562,\"createtime\":\"2022-05-21T00:00:00\",\"createuser\":null,\"groupguid\":\"d374ba2e-6d82-4a23-82ec-0b46d95dd584\",\"erpguidguid\":\"127126\",\"erppareneguid\":\"102818\",\"groupname\":\"浸没式超滤膜组件\",\"groupcode\":\"41.10.106\",\"isdelete\":0,\"parentguid\":\"a063dc24-045e-43f0-9c66-67600173258d\",\"children\":[]},{\"iid\":9563,\"createtime\":\"2022-05-21T00:00:00\",\"createuser\":null,\"groupguid\":\"8ad69e5d-9040-4a54-8e5e-c137bc709cf6\",\"erpguidguid\":\"127127\",\"erppareneguid\":\"102818\",\"groupname\":\"Y型过滤器 UPVC\",\"groupcode\":\"41.10.451\",\"isdelete\":0,\"parentguid\":\"a063dc24-045e-43f0-9c66-67600173258d\",\"children\":[]},{\"iid\":9564,\"createtime\":\"2022-05-21T00:00:00\",\"createuser\":null,\"groupguid\":\"2d867697-bb11-4471-9386-8db835b56fb5\",\"erpguidguid\":\"130029\",\"erppareneguid\":\"102818\",\"groupname\":\"NF膜组件\",\"groupcode\":\"41.10.211\",\"isdelete\":0,\"parentguid\":\"a063dc24-045e-43f0-9c66-67600173258d\",\"children\":[]}]}]}]}";
if(StringUtils.isEmpty(res)){
return materialGroups;
}
MOMResult result = JSON.parseObject(res, MOMResult.class);
Object[] rows = result.getRows();
String s = JSON.toJSONString(rows);
materialGroups = JSON.parseObject(s, ERPMaterialGroup[].class);
return materialGroups;
}
public AjaxResult pullMaterialGroups(){
ERPMaterialGroup[] erpMaterialGroups = pullMaterialGroup();
if(erpMaterialGroups == null || erpMaterialGroups.length==0){
return AjaxResult.error();
}
List<ERPMaterialGroup> erpMaterialGroups1 = getArrays(Arrays.asList(erpMaterialGroups));
materialGroupService.truncateTable();
int i = materialGroupService.insertBatch(erpMaterialGroups1);
if(i<=0){
return AjaxResult.error();
}
return AjaxResult.success();
}
private List<ERPMaterialGroup> getArrays(List<ERPMaterialGroup> erpMaterialGroups){
List<ERPMaterialGroup> arrayList = new ArrayList<>();
for (ERPMaterialGroup erpMaterialGroup : erpMaterialGroups) {
if(erpMaterialGroup.getChildren().size()==0){
arrayList.add(erpMaterialGroup);
continue;
}
arrayList.addAll(erpMaterialGroup.getChildren());
erpMaterialGroup.setChildren(Collections.emptyList());
arrayList.add(erpMaterialGroup);
arrayList = getArrays(arrayList);
}
return arrayList;
}
public void sycMaterial(){
List<ERPMaterialGroup> list = materialGroupService.list();
if(list==null || list.size()==0){
return;
}
for (ERPMaterialGroup erpMaterialGroup : list) {
pullMaterialInfo(new QueryParam().setGroupguid(erpMaterialGroup.getGroupguid()).setGroupname(erpMaterialGroup.getGroupname()));
}
}
}