|
|
@@ -6,8 +6,10 @@ import com.uas.eis.config.VwmsConfig;
|
|
|
import com.uas.eis.core.config.SpObserver;
|
|
|
import com.uas.eis.dao.*;
|
|
|
import com.uas.eis.entity.vwms.req.*;
|
|
|
+import com.uas.eis.entity.vwms.resp.BaseVastResp;
|
|
|
import com.uas.eis.service.ERPService;
|
|
|
import com.uas.eis.utils.CollectionUtil;
|
|
|
+import com.uas.eis.utils.HttpUtil;
|
|
|
import com.uas.eis.utils.StringUtil;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
@@ -83,8 +85,10 @@ public class ERPServiceImpl implements ERPService {
|
|
|
}
|
|
|
private Map<String, Object> sendProdSigle(String master,String actionType,List<Map<String, Object>> list){
|
|
|
List<ProductReq> productReqList = new ArrayList<>();
|
|
|
- List<Object> docIds = new ArrayList<>();
|
|
|
- String joinedIds = "";
|
|
|
+ List<Object> docCodes = new ArrayList<>();
|
|
|
+ String prCodes = "";
|
|
|
+ StringBuffer errMsg = new StringBuffer();
|
|
|
+ String eMsg = "";
|
|
|
Map<String, Object> retMap = new HashMap<>();
|
|
|
if(CollectionUtil.isEmpty(list)){
|
|
|
retMap.put("success",false);
|
|
|
@@ -93,15 +97,16 @@ public class ERPServiceImpl implements ERPService {
|
|
|
}
|
|
|
for (Map<String, Object> map : list) {
|
|
|
// 创建ProductReq对象
|
|
|
- docIds.add(map.get("pr_id"));
|
|
|
+ docCodes.add(map.get("pr_code"));
|
|
|
logger.info("sendProd-test: id {} code {}",map.get("pr_id"),map.get("pr_code"));
|
|
|
// 创建ProductReq对象
|
|
|
ProductReq productReq = new ProductReq.Builder()
|
|
|
.itemId(map.get("pr_code").toString())
|
|
|
.itemCode(map.get("pr_code").toString())
|
|
|
- .barCode(StringUtil.nvl(map.get("pr_ycxh")," "))
|
|
|
+ .barCode(StringUtil.nvl(map.get("pr_ycxh"),StringUtil.nvl(map.get("pr_orispeccode"),map.get("pr_code").toString())))
|
|
|
.itemName(StringUtil.nvl(map.get("pr_detail")," "))
|
|
|
.goodsCode(StringUtil.nvl(map.get("pr_orispeccode")," "))
|
|
|
+ .brandName(StringUtil.nvl(map.get("pr_brand")," "))
|
|
|
.categoryName(StringUtil.nvl(map.get("pr_brand")," "))
|
|
|
.stockUnit(StringUtil.nvl(map.get("pr_unit")," "))
|
|
|
.ExtendProps(new ProductReq.ExtendProps() {{
|
|
|
@@ -110,12 +115,16 @@ public class ERPServiceImpl implements ERPService {
|
|
|
.build();
|
|
|
productReqList.add(productReq);
|
|
|
}
|
|
|
+ prCodes = "'"+docCodes.stream()
|
|
|
+ .map(String::valueOf)
|
|
|
+ .collect(Collectors.joining("','"))+"'";
|
|
|
// 创建BaseReq对象
|
|
|
BaseVastReq<ProductReq> baseVastReq = new BaseVastReq.Builder<ProductReq>()
|
|
|
.actionType(actionType)
|
|
|
.warehouseCode(vwmsConfig.getWarehouseCode())
|
|
|
.ownerCode(vwmsConfig.getOwnerCode())
|
|
|
- .items(productReqList)
|
|
|
+ .outBizCode("sendProd-"+System.currentTimeMillis())
|
|
|
+ .items(new BaseVastItem.Builder<ProductReq>().item(productReqList).build())
|
|
|
.build();
|
|
|
// 创建RequestWrapper对象
|
|
|
RequestWrapperVast<ProductReq> wrapper = new RequestWrapperVast.Builder<ProductReq>()
|
|
|
@@ -128,26 +137,75 @@ public class ERPServiceImpl implements ERPService {
|
|
|
//{{testapiurl}}?method=openapi.singleitem.synchronize×tamp=2025-03-04 15:45:00
|
|
|
// &format={{format}}&app_key={{app_key}}&v=2.0&sign=B21FFFE48507569E72D573359856B19B
|
|
|
// &sign_method=md5&customerId={{customerId}}
|
|
|
-// HttpUtil.Response response = HttpUtil.doPostToVWMS("openapi.items.synchronize", json,vwmsConfig);
|
|
|
- joinedIds = docIds.stream()
|
|
|
- .map(String::valueOf)
|
|
|
- .collect(Collectors.joining(","));
|
|
|
- baseDao.execute("update "+master+".product set pr_sendwmsstatus='同步成功' ,pr_sendwmsflag=-1,pr_sendwmserr=null where pr_id in ("+joinedIds+")");
|
|
|
+ HttpUtil.Response response = HttpUtil.doPostToVWMS("openapi.items.synchronize", json,vwmsConfig);
|
|
|
+// logger.info("response code: {} text: {}", response.getStatusCode(),response.getResponseText());
|
|
|
+ if(!String.valueOf(response.getStatusCode()).startsWith("2")){
|
|
|
+ eMsg = StringUtil.nvl(response.getResponseText(),"未知");
|
|
|
+ retMap.put("success", false);
|
|
|
+ retMap.put("message", "请求失败:"+response.getStatusCode()+":"+eMsg);
|
|
|
+ baseDao.execute("update "+master+".product set pr_sendwmsstatus='同步失败',pr_sendwmserr=UNISTR('操作:"+actionType+":"+eMsg.replaceAll("'","''")+"') " +
|
|
|
+ " where pr_code IN ("+prCodes+")");
|
|
|
+ }else {
|
|
|
+ retMap.put("success",true);
|
|
|
+ List<String> sqls = new ArrayList<>();
|
|
|
+ BaseVastResp baseVastResp = new ObjectMapper().readValue(response.getResponseText(), BaseVastResp.class);
|
|
|
+ BaseVastResp.Response baseVastRespResponse= baseVastResp.getResponse();
|
|
|
+ if(baseVastRespResponse!=null){
|
|
|
+ //默认成功
|
|
|
+ baseDao.execute("update "+master+".product set pr_sendwmsstatus='同步成功' ,pr_sendwmserr=null where pr_code in ("+prCodes+")");
|
|
|
+ if("success".equals(baseVastRespResponse.getFlag())){
|
|
|
+ logger.info("response-success code: {} message: {}", baseVastRespResponse.getCode(),baseVastRespResponse.getMessage());
|
|
|
+ }else {
|
|
|
+ retMap.put("success",false);
|
|
|
+ logger.info("response-failure code: {} message: {}", baseVastRespResponse.getCode(),baseVastRespResponse.getMessage());
|
|
|
+ //不一定全部失败,此处只会返回失败提示
|
|
|
+ BaseVastResp.Items items = baseVastRespResponse.getItems();
|
|
|
+ if(items!=null&&!CollectionUtil.isEmpty(items.getItem())){
|
|
|
+ for (BaseVastResp.Item item : items.getItem()) {
|
|
|
+ eMsg = item.getMessage();
|
|
|
+ if(!eMsg.equals("The goods don't exists, you can't update it.")){//提示异常但是实际会自动创建 可以认定为请求成功
|
|
|
+ logger.info("response-failure-item code: {} message: {}", item.getItemCode(),item.getMessage());
|
|
|
+ sqls.add("update "+master+".product set pr_sendwmsstatus='同步失败',pr_sendwmserr=UNISTR('操作:"+actionType+":"+eMsg.replaceAll("'","''")+"') where pr_code ='"+item.getItemCode()+"'");
|
|
|
+ if(errMsg.length()>0){
|
|
|
+ errMsg.append("</br>");
|
|
|
+ errMsg.append("物料编号:"+item.getItemCode()+",失败原因:"+eMsg);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(!CollectionUtil.isEmpty(sqls)){
|
|
|
+ baseDao.execute(sqls);
|
|
|
+ retMap.put("message", errMsg.toString());
|
|
|
+ }else {
|
|
|
+ logger.info("response-failure-item all message: {}", "The goods don't exists, you can't update it.");
|
|
|
+ retMap.put("success",true);//全部提示失败但实际创建成功
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ eMsg = StringUtil.nvl(baseVastRespResponse.getMessage(),"无");
|
|
|
+ baseDao.execute("update "+master+".product set pr_sendwmsstatus='同步失败',pr_sendwmserr=UNISTR('操作:"+actionType+":"+eMsg.replaceAll("'","''")+"') " +
|
|
|
+ " where pr_code IN ("+prCodes+")");
|
|
|
+ retMap.put("message", eMsg);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ baseDao.execute("update "+master+".product set pr_sendwmsflag=-1 where pr_code in ("+prCodes+") AND NVL(pr_sendwmsflag,0) = 0 AND pr_sendwmsstatus='同步成功'");
|
|
|
+ }else {
|
|
|
+ retMap.put("success", false);
|
|
|
+ retMap.put("message", "转换失败:"+response.getStatusCode()+":"+response.getResponseText());
|
|
|
+ }
|
|
|
+ }
|
|
|
//TODO 考虑记录日志
|
|
|
+ return retMap;
|
|
|
} catch (JsonProcessingException e) {
|
|
|
e.printStackTrace();
|
|
|
- logger.info("sendProd-Error:JSON转换失败 ids {} ",joinedIds);
|
|
|
+ logger.info("sendProd-Error:JSON转换失败 codes {} ",prCodes);
|
|
|
retMap.put("success", false);
|
|
|
retMap.put("message", "JSON转换失败");
|
|
|
return retMap;
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
- String eMsg = StringUtil.nvl(e.getMessage(),"无");
|
|
|
- baseDao.execute("update "+master+".product set pr_sendwmsstatus='同步失败' ,pr_sendwmserr='操作:"+actionType+":"+eMsg+"' where pr_id in ("+joinedIds+")");
|
|
|
+ eMsg = StringUtil.nvl(e.getMessage(),"无");
|
|
|
+ baseDao.execute("update "+master+".product set pr_sendwmsstatus='同步失败' ,pr_sendwmserr='操作:"+actionType+":"+eMsg+"' where pr_code in ("+prCodes+")");
|
|
|
throw new RuntimeException(e);
|
|
|
}
|
|
|
- retMap.put("success", true);
|
|
|
- return retMap;
|
|
|
}
|
|
|
|
|
|
|