ERPServiceImpl.java
11.4 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
package com.huaheng.api.erp.service;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.google.gson.Gson;
import com.huaheng.api.erp.domain.jind.ERPLoginResult;
import com.huaheng.api.erp.domain.jind.ErpLogin;
import com.huaheng.common.constant.QuantityConstant;
import com.huaheng.common.exception.service.ServiceException;
import com.huaheng.common.utils.http.OkHttpUtils;
import com.huaheng.framework.aspectj.ApiLogAspect;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.framework.web.service.ConfigService;
import com.huaheng.pc.config.address.service.AddressService;
import com.huaheng.pc.monitor.apilog.domain.ApiLog;
import com.huaheng.pc.receipt.receiptDetail.domain.ReceiptDetail;
import com.huaheng.pc.receipt.receiptDetail.service.ReceiptDetailService;
import com.huaheng.pc.receipt.receiptHeader.domain.ReceiptHeader;
import com.huaheng.pc.receipt.receiptHeader.service.ReceiptHeaderService;
import com.huaheng.pc.system.config.domain.Config;
import org.springframework.http.HttpHeaders;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/***
* @author tongzonghao
*
*/
@Service
public class ERPServiceImpl implements ERPService {
@Resource
private AddressService addressService;
@Resource
private ConfigService configService;
@Resource
private ReceiptHeaderService receiptHeaderService;
@Resource
private ReceiptDetailService receiptDetailService;
@Override
public AjaxResult innerLoginERP() {
ErpLogin erpLogin = new ErpLogin();
erpLogin.setAcctID(QuantityConstant.ERP_AcctID);
erpLogin.setAppID(QuantityConstant.ERP_AppID);
erpLogin.setAppSec(QuantityConstant.ERP_AppSec);
erpLogin.setUserName(QuantityConstant.ERP_UserName);
erpLogin.setPassword(QuantityConstant.ERP_PASSWORD);
erpLogin.setLCID(QuantityConstant.ERP_LCID);
String url = addressService.selectAddress(QuantityConstant.ERP_K3CLOUD_LOGIN,
QuantityConstant.DEFAULT_WAREHOUSE, "");
String jsonParam = JSON.toJSONString(erpLogin);
String result = OkHttpUtils.bodypost(url, jsonParam);
ERPLoginResult erpLoginResult = JSON.parseObject(result, ERPLoginResult.class);
String sessionId = erpLoginResult.getKDSVCSessionId();
Config config1 = new Config();
config1.setConfigKey(QuantityConstant.ERP_SESSION_ID);
Config config = configService.selectConfigList(config1).get(0);
config.setConfigValue(sessionId);
int ret = configService.updateConfig(config);
return AjaxResult.success();
}
@Override
public AjaxResult receiptMethod(int receiptHeaderId) {
ReceiptHeader header = receiptHeaderService.getById(receiptHeaderId);
return receiptMethod(header);
}
/**
* 回传入库单数据
* @param receiptHeader 任务头
*/
@Transactional
public AjaxResult receiptMethod(ReceiptHeader receiptHeader){
//
// innerLoginERP();
// ApiLog log = null;
// String jsonParam = null;
// SaveResult spInStock = null;
// HttpHeaders headers = new HttpHeaders();
// Map<String, Object> receipMap = new HashMap<String, Object>();
// receipMap.put("Numbers", "CS0001");
// jsonParam=JSON.toJSONString(receipMap);
//
//
// log = ApiLogAspect.initApiLog("post", QuantityConstant.ERP_ServerUrl+QuantityConstant.STK_MISCELLANEOUS,
// jsonParam, headers, QuantityConstant.DEFAULT_WAREHOUSE);
// String okResult = OkHttpUtils.bodypost("http://117.158.214.140:5580/k3cloud/", jsonParam, "63f9ba5be6e724");
// spInStock = JSON.parseObject(okResult, SaveResult.class);
//
//
//// if(receiptHeader==null){
//// return AjaxResult.error("入库单为空");
//// }
//// String msg = "WMS请求发送成功,接收返回内容是空的";
//// if(receiptHeader.getFirstStatus() == 800 &&
//// receiptHeader.getLastStatus() == 800){
//// //入库数据
//// Object receiptData;
//// //回传标识
//// String formId = "";
//// //获取回传入库信息
//// receiptData = param(receiptHeader,receiptHeader.getReceiptType());
//// ExtSaveParam saveParam = new ExtSaveParam<>(receiptData);
////
//// //返回结果
//// SaveResult spInStock = null;
//// Gson gson = new Gson();
//// ApiLog log = null;
//// String body = null;
//// HttpHeaders headers = new HttpHeaders();
////
//// try {
//// String url = addressService.selectAddress(QuantityConstant.ERP_K3CLOUD_SAVE,
//// QuantityConstant.DEFAULT_WAREHOUSE, "");
//// String sessionId = configService.getKey(QuantityConstant.ERP_SESSION_ID);
//// if(StringUtils.isEmpty(sessionId)){
//// return AjaxResult.error("sessionId不能为空");
//// }
////
//// formId = QuantityConstant.STK_MISCELLANEOUS;
//// Object[] objects = new Object[]{formId, saveParam.toJson()};
//// ErpSaveObject erpSaveObject = new ErpSaveObject();
//// erpSaveObject.setParameters(objects);
//// body = gson.toJson(erpSaveObject);
////
////
//// log = ApiLogAspect.initApiLog("post", QuantityConstant.ERP_ServerUrl+QuantityConstant.STK_MISCELLANEOUS,
//// body, headers, QuantityConstant.DEFAULT_WAREHOUSE);
//// String okResult = OkHttpUtils.bodypost(url, body, sessionId);
//// spInStock = JSON.parseObject(okResult, SaveResult.class);
////
////
//// if (spInStock.getResult().getResponseStatus().isIsSuccess()) {
//// SuccessEntity success = spInStock.getResult().
//// getResponseStatus().getSuccessEntitys().get(0);
//// Integer referId = Integer.valueOf(success.getId());
//// String referCode = success.getNumber();
//// //更新 入库单明细状态
//// LambdaQueryWrapper<ReceiptDetail> queryWrapper = Wrappers.lambdaQuery();
//// queryWrapper.eq(ReceiptDetail::getReceiptId, receiptHeader.getId());
//// List<ReceiptDetail> receiptDetails = receiptDetailService.list(queryWrapper);
//// for (ReceiptDetail receiptDetail : receiptDetails) {
//// receiptDetail.setReferId(referId);
//// receiptDetail.setReferCode(referCode);
//// receiptDetail.setQty(receiptDetail.getTaskQty());
//// receiptDetailService.updateById(receiptDetail);
//// }
//// receiptHeader.setReferId(referId);
//// receiptHeader.setReferCode(referCode);
//// receiptHeaderService.updateById(receiptHeader);
//// //修改回传后状态
//// editReceiveStatus(receiptHeader.getId());
//// receiptHeader = receiptHeaderService.getById(receiptHeader.getId());
//// receiptDetailService.updateReceiptHeader(receiptHeader);
//// //更新 入库单明细状态
//// msg = "回传成功";
//// return AjaxResult.success("回传成功");
//// } else {
//// ArrayList<RepoError> errors = spInStock.getResult().getResponseStatus().getErrors();
//// String errorStr = "";
//// for (RepoError error : errors) {
//// errorStr = error.getFieldName() + "==" + error.getMessage() + "==";
//// }
//// msg = errorStr;
//// return AjaxResult.error(errorStr);
//// }
//// }catch (Exception e) {
//// e.printStackTrace();
//// ApiLogAspect.setApiLogException(log, e);
//// } finally {
//// ApiLogAspect.finishApiLog(log, headers, msg);
//// }
//// }
return AjaxResult.success("回传成功");
}
/**
* 判断入库单类型返回 回传入库信息
* @param receiptHeader 入库头
* @param billType 单据类型
* @return 回传入库信息
*/
private Object param(ReceiptHeader receiptHeader,String billType){
// Object returnReceipt;
// switch (billType) {
// //简单生产入库单
// case QuantityConstant.RECEIPT_BILL_TYPE_SC:
// returnReceipt = buildSingleReceiptHead(receiptHeader);
// break;
// //其他生产入库单
// case QuantityConstant.RECEIPT_BILL_TYPE_OR:
// returnReceipt = buildOtherReceiptHead(receiptHeader);
// break;
// default:
// throw new ServiceException("不支持的任务类型");
// }
// //获取入库单数据
// LambdaQueryWrapper<ReceiptDetail> queryWrapper = Wrappers.lambdaQuery();
// queryWrapper.eq(ReceiptDetail::getReceiptId,receiptHeader.getId());
// //入库明细集合
// List<ReceiptDetail> details = receiptDetailService.list(queryWrapper);
//
// //回传入库明细集
// List<ReceiptBillEntity> receiptInfos = getReceiptEntities(details);
//
// //设置回传入库明细集
// Class<?> receiptCls = returnReceipt.getClass();
//
// if(OtherReceipt.class.isAssignableFrom(receiptCls)){
// OtherReceipt otherReceipt = (OtherReceipt)returnReceipt;
// otherReceipt.setEntity(receiptInfos);
// //重新赋值给 returnReceipt
// returnReceipt = otherReceipt;
// }else if(SingleReceipt.class.isAssignableFrom(receiptCls)){
// SingleReceipt singleReceipt = (SingleReceipt)returnReceipt;
// singleReceipt.setEntity(receiptInfos);
// //重新赋值给 returnReceipt
// returnReceipt = singleReceipt;
// }
// return returnReceipt;
return null;
}
private AjaxResult editReceiveStatus(Integer id) {
ReceiptHeader receiptHeader = new ReceiptHeader();
receiptHeader.setId(id);
receiptHeader.setFirstStatus(900);
receiptHeader.setLastStatus(900);
if (!receiptHeaderService.updateById(receiptHeader)) {
throw new ServiceException("更新头表状态失败");
} else {
LambdaQueryWrapper<ReceiptDetail> lambdaQueryWrapper = Wrappers.lambdaQuery();
lambdaQueryWrapper.eq(ReceiptDetail::getReceiptId, id);
List<ReceiptDetail> receiptDetails = receiptDetailService.list(lambdaQueryWrapper);
for (ReceiptDetail receiptDetail : receiptDetails) {
receiptDetail.setProcessStamp("900");
}
if (!receiptDetailService.updateBatchById(receiptDetails)) {
throw new ServiceException("更新明细失败");
}
}
return AjaxResult.success("");
}
}