|
1
2
3
4
5
6
7
8
|
package com.huaheng.api.SSP.service;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.huaheng.api.SSP.domain.SSPmaterialModel;
import com.huaheng.common.exception.service.ServiceException;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.common.utils.http.HttpUtils;
|
周鸿
authored
|
9
|
import com.huaheng.common.utils.http.OkHttpUtils;
|
|
10
11
|
import com.huaheng.common.utils.security.ShiroUtils;
import com.huaheng.framework.web.domain.AjaxResult;
|
周鸿
authored
|
12
|
import com.huaheng.framework.web.domain.AjaxResultWCS;
|
|
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
import com.huaheng.pc.config.address.domain.Address;
import com.huaheng.pc.config.address.service.AddressService;
import com.huaheng.pc.config.material.domain.Material;
import com.huaheng.pc.config.material.service.MaterialService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.text.SimpleDateFormat;
import java.util.Date;
//物料信息上传
@Service
@Transactional
public class ItemDownloadApiService {
@Autowired
MaterialService materialService;
@Autowired
private AddressService addressService;
|
周鸿
authored
|
36
37
38
|
public String getQGUrl(String containerCode) {
Address address = new Address();
String number = containerCode.substring(0, 1);
|
|
39
40
41
|
address.setNumber(number);
address.setParam("QG");
address.setWarehouseCode(ShiroUtils.getWarehouseCode());
|
周鸿
authored
|
42
|
String url = addressService.selectEntity(address).getUrl();
|
|
43
44
45
46
47
|
return url;
}
//private static String address="http://172.16.30.238:4322/api/SSP/";
|
周鸿
authored
|
48
49
50
|
public AjaxResult Idls(String url) {
String ur = url.substring(0, 25);
Address address = new Address();
|
|
51
|
address.setUrl(ur);
|
|
52
|
//String warehouseCode=addressService.selectWarehouse(address).getWarehouseCode();
|
周鸿
authored
|
53
54
|
String warehouseCode = addressService.list(new LambdaQueryWrapper<Address>().like(Address::getUrl, ur)).get(0).getWarehouseCode();
if (StringUtils.isEmpty(warehouseCode)) {
|
|
55
56
|
return AjaxResult.success("该地址没找到仓库");
}
|
|
57
58
59
60
61
|
Material material = new Material();
material.setWarehouseCode(warehouseCode);
material.setZoneCode("QG");
material.setUserDef2("0");
Material materials = materialService.list(new LambdaQueryWrapper<Material>()
|
周鸿
authored
|
62
63
|
.eq(Material::getUserDef2, 0)
.eq(Material::getWarehouseCode, warehouseCode)
|
|
64
|
.eq(Material::getZoneCode, "QG")).get(0);
|
|
65
|
//Material materials = materialService.selectFirstEntity(material);
|
周鸿
authored
|
66
|
if (materials == null) {
|
|
67
68
|
return AjaxResult.success("系统中没有钱柜的物料!!或钱柜的物流已全部发完!!");
}
|
|
69
|
|
|
70
71
|
try {
SSPmaterialModel smm = new SSPmaterialModel();
|
|
72
73
74
75
76
77
78
79
|
smm.setSpecification(materials.getSpec());
smm.setCubeCode(materials.getZoneCode());
smm.setCompanyCode(materials.getCompanyCode());
smm.setItemCode(materials.getCode());
smm.setItemName(materials.getName());
smm.setItemBarcode(materials.getCode());
smm.setWarehouseCode(materials.getWarehouseCode());
smm.setItemUnit(materials.getUnit());
|
|
80
81
82
83
|
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:sss");
smm.setcDatetime(df.format(new Date()));
String JsonParam = JSON.toJSONString(smm);
|
周鸿
authored
|
84
|
String result = HttpUtils.bodypost(url, JsonParam, "CS0001");
|
|
85
86
87
|
AjaxResult ajaxResult = JSON.parseObject(result, AjaxResult.class);
Material upm = new Material();
|
|
88
|
upm.setId(materials.getId());
|
|
89
90
91
|
upm.setUserDef2("1");
materialService.updateById(upm);
return ajaxResult;
|
周鸿
authored
|
92
|
} catch (Exception e) {
|
|
93
94
95
96
|
throw new ServiceException("物料信息同步上传失败");
}
}
|
周鸿
authored
|
97
|
public AjaxResult sendMaterial(Material material, String containerCode) {
|
|
98
99
100
101
102
103
104
105
106
107
108
|
SSPmaterialModel smm = new SSPmaterialModel();
smm.setSpecification(material.getSpec());
smm.setCubeCode(material.getZoneCode());
smm.setCompanyCode(material.getCompanyCode());
smm.setItemCode(material.getCode());
smm.setItemName(material.getName());
smm.setItemBarcode(material.getCode());
smm.setWarehouseCode(material.getWarehouseCode());
smm.setItemUnit(material.getUnit());
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:sss");
smm.setcDatetime(df.format(new Date()));
|
周鸿
authored
|
109
|
String url = this.getQGUrl(containerCode) + "ItemDownload";
|
|
110
|
String JsonParam = JSON.toJSONString(smm);
|
周鸿
authored
|
111
112
|
String result = OkHttpUtils.bodypost(url, JsonParam, ShiroUtils.getWarehouseCode());
if (StringUtils.isEmpty(result)) {
|
|
113
114
|
throw new ServiceException("接口地址错误或服务器连接不到或返回为空");
}
|
周鸿
authored
|
115
116
117
118
119
|
AjaxResultWCS ajaxResult = JSON.parseObject(result, AjaxResultWCS.class);
AjaxResult ajaxResult1=new AjaxResult();
ajaxResult1.setCode(ajaxResult.code);
ajaxResult1.setMsg(ajaxResult.getMessage());
return ajaxResult1;
|
|
120
121
122
123
|
}
}
|