|
|
@@ -3,8 +3,11 @@ package com.uas.eis.service.Impl;
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.uas.eis.config.VwmsConfig;
|
|
|
-import com.uas.eis.core.config.SpObserver;
|
|
|
import com.uas.eis.dao.*;
|
|
|
+import com.uas.eis.entity.vwms.entity.Customer;
|
|
|
+import com.uas.eis.entity.vwms.entity.CustomerAddress;
|
|
|
+import com.uas.eis.entity.vwms.entity.VendorContact;
|
|
|
+import com.uas.eis.entity.vwms.entity.Vendor;
|
|
|
import com.uas.eis.entity.vwms.req.*;
|
|
|
import com.uas.eis.entity.vwms.resp.BaseVastResp;
|
|
|
import com.uas.eis.service.ERPService;
|
|
|
@@ -16,6 +19,7 @@ import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@@ -45,7 +49,6 @@ public class ERPServiceImpl implements ERPService {
|
|
|
// 执行查询
|
|
|
SqlRowList docMsg = baseDao.queryForRowSet(" select pr_id,pr_code,pr_ycxh,pr_detail,pr_orispeccode,pr_brand,pr_unit,pr_zxbzs,nvl(pr_sendwmsflag,0) pr_sendwmsflag " +
|
|
|
" from "+master+".product left join "+master+".productbrand on pb_name = pr_brand where pr_id in ("+ids+") and pb_sendwms = -1 ");
|
|
|
- logger.info("Query executed, datasource: {}", SpObserver.getSp());
|
|
|
if(!docMsg.hasNext()){
|
|
|
baseDao.execute("update "+master+".product set pr_sendwmsstatus='同步失败',pr_sendwmserr='没有需要同步的商品(品牌需设置对接MWS)。 where pr_id IN ("+ids+")");
|
|
|
retMap.put("success",false);
|
|
|
@@ -63,7 +66,7 @@ public class ERPServiceImpl implements ERPService {
|
|
|
// 其他处理逻辑
|
|
|
String actionType = "update";
|
|
|
String actionTypeName = "更新";
|
|
|
- if("0".equals(sendflag)){
|
|
|
+ if("0".equals(String.valueOf(sendflag))){
|
|
|
actionType = "add";
|
|
|
actionTypeName = "创建";
|
|
|
}
|
|
|
@@ -210,4 +213,428 @@ public class ERPServiceImpl implements ERPService {
|
|
|
}
|
|
|
|
|
|
|
|
|
+ @Override
|
|
|
+ public Map<String, Object> sendVend(String master, String ids,String emCode) {
|
|
|
+ Map<String,Object> retMap = new HashMap<>();
|
|
|
+ retMap.put("success",true);
|
|
|
+ logger.info("sendVend-Begin:master {} ids {}",master,ids);
|
|
|
+ // 执行查询
|
|
|
+ SqlRowList docMsg = baseDao.queryForRowSet(" select nvl(ve_sendwmsflag,0) sendwmsflag,ve_id,ve_code,ve_name,ve_shortname,ve_add1," +
|
|
|
+ "vc_id,(case when nvl(vc_isvendor,0) = 0 then 0 else 1 end ) vc_isvendor,vc_name,vc_officeemail,vc_mobile " +
|
|
|
+ "from "+master+".vendor left join "+master+".VendorContact on ve_id = vc_veid " +
|
|
|
+ "where ve_id in ("+ids+") order by ve_id,vc_id");
|
|
|
+ if(!docMsg.hasNext()){
|
|
|
+ retMap.put("success",false);
|
|
|
+ retMap.put("message","供应商资料不存在。");
|
|
|
+ return retMap;
|
|
|
+ }
|
|
|
+ List<Map<String, Object>> docMsgResultList = docMsg.getResultList();
|
|
|
+ // 按 sendwmsflag 分组
|
|
|
+ Map<Object, List<Map<String, Object>>> groupedByFlag = docMsgResultList.stream()
|
|
|
+ .collect(Collectors.groupingBy(map -> map.get("sendwmsflag")));
|
|
|
+ StringBuffer errMsg = new StringBuffer();
|
|
|
+ // 处理分组后的数据
|
|
|
+ groupedByFlag.forEach((sendflag, list) -> {
|
|
|
+ logger.info("Flag: {}, Count: {}", sendflag, list.size());
|
|
|
+ // 其他处理逻辑
|
|
|
+ String actionType = "update";
|
|
|
+ String actionTypeName = "更新";
|
|
|
+ if("0".equals(String.valueOf(sendflag))){
|
|
|
+ actionType = "add";
|
|
|
+ actionTypeName = "创建";
|
|
|
+ }
|
|
|
+// // 按ve_id和vc_id升序排序
|
|
|
+// list.sort(Comparator
|
|
|
+// .comparing(m -> (Long) m.get("ve_id"))
|
|
|
+// .thenComparing(m -> (Long) m.get("vc_id")));
|
|
|
+ // 拆分主从表 按ve_id分组
|
|
|
+ // 按ve_id分组
|
|
|
+ Map<Long, Vendor> vendorMap = new HashMap<>();
|
|
|
+ for (Map<String, Object> map : list) {
|
|
|
+ Long veId = ((BigDecimal) map.get("ve_id")).longValue();
|
|
|
+
|
|
|
+ // 获取或创建主表对象
|
|
|
+ Vendor main = vendorMap.computeIfAbsent(veId, k -> {
|
|
|
+ Vendor v = new Vendor();
|
|
|
+ v.setVeId(veId);
|
|
|
+ v.setVeCode((String) map.get("ve_code"));
|
|
|
+ v.setVeName((String) map.get("ve_name"));
|
|
|
+ v.setVeShortname((String) map.get("ve_shortname"));
|
|
|
+ v.setVeAdd1((String) map.get("ve_add1"));
|
|
|
+ return v;
|
|
|
+ });
|
|
|
+
|
|
|
+ // 创建从表对象
|
|
|
+ if(map.get("vc_id") != null){
|
|
|
+ VendorContact contact = new VendorContact();
|
|
|
+ contact.setVcId(((BigDecimal) map.get("vc_id")).longValue());
|
|
|
+ contact.setVcIsvendor(((BigDecimal) map.get("vc_isvendor")).intValue());
|
|
|
+ contact.setVcName((String) map.get("vc_name"));
|
|
|
+ contact.setVcOfficeemail((String) map.get("vc_officeemail"));
|
|
|
+ contact.setVcMobile((String) map.get("vc_mobile"));
|
|
|
+ // 将联系人添加到主表
|
|
|
+ main.getVendorContacts().add(contact);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 返回按ve_id分组的VendorMain列表
|
|
|
+ List<Vendor> vList = new ArrayList<>(vendorMap.values());
|
|
|
+ Map<String, Object> res = sendVendSigle(master,actionType,vList);
|
|
|
+ if(!res.get("success").equals(true)){
|
|
|
+ if(errMsg.length()>0){
|
|
|
+ errMsg.append("</br>");
|
|
|
+ }
|
|
|
+ errMsg.append("执行:"+actionTypeName+"操作失败:"+res.get("message"));
|
|
|
+ }
|
|
|
+ });
|
|
|
+ if(errMsg.length()>0){
|
|
|
+ retMap.put("success",false);
|
|
|
+ retMap.put("message",errMsg.toString());
|
|
|
+ return retMap;
|
|
|
+ }
|
|
|
+ logger.info("sendVend-End:master {} ids {}",master,ids);
|
|
|
+ retMap.put("message","同步成功。");
|
|
|
+ return retMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ private Map<String, Object> sendVendSigle(String master,String actionType,List<Vendor> list){
|
|
|
+ List<PartnersReq> regList = new ArrayList<>();
|
|
|
+ List<Object> docCodes = new ArrayList<>();
|
|
|
+ String codes = "";
|
|
|
+ StringBuffer errMsg = new StringBuffer();
|
|
|
+ String eMsg = "";
|
|
|
+ Map<String, Object> retMap = new HashMap<>();
|
|
|
+ if(CollectionUtil.isEmpty(list)){
|
|
|
+ retMap.put("success",false);
|
|
|
+ retMap.put("message","没有需要同步的商品(品牌需设置对接MWS)。");
|
|
|
+ return retMap;
|
|
|
+ }
|
|
|
+ for (Vendor vend : list) {
|
|
|
+ // 创建Req对象
|
|
|
+ docCodes.add(vend.getVeCode());
|
|
|
+ logger.info("sendVend-test: id {} code {}",vend.getVeId(),vend.getVeCode());
|
|
|
+ // 创建ProductReq对象
|
|
|
+ PartnersReq req = PartnersReq.builder()
|
|
|
+ .partnerCode(vend.getVeCode())
|
|
|
+ .name(vend.getVeName())
|
|
|
+ .cnShortName(vend.getVeShortname())
|
|
|
+ .enCompanyType("supplier")
|
|
|
+ /* .customField1("自定义2")
|
|
|
+ .customField2("自定义2")
|
|
|
+ .customField3("自定义3")
|
|
|
+ .customField4("自定义4")
|
|
|
+ .customField5("自定义5")
|
|
|
+ .remark("备注注")*/
|
|
|
+ .contactsInfos(PartnersReq.ContactsInfos.builder()
|
|
|
+ .contactsInfo(Optional.ofNullable(vend.getVendorContacts())
|
|
|
+ .orElse(Collections.emptyList())
|
|
|
+ .stream()
|
|
|
+ .map(contact -> PartnersReq.ContactsInfo.builder()
|
|
|
+ .isDefault(contact.getVcIsvendor())
|
|
|
+ .name(contact.getVcName())
|
|
|
+ .email(contact.getVcOfficeemail())
|
|
|
+ .mobile(contact.getVcMobile())
|
|
|
+ .address(vend.getVeAdd1())
|
|
|
+ .build())
|
|
|
+ .collect(Collectors.toList()))
|
|
|
+ .build())
|
|
|
+ .build();
|
|
|
+ regList.add(req);
|
|
|
+ }
|
|
|
+ codes = "'"+docCodes.stream()
|
|
|
+ .map(String::valueOf)
|
|
|
+ .collect(Collectors.joining("','"))+"'";
|
|
|
+ // 创建BaseReq对象
|
|
|
+ BaseVastReq<PartnersReq> baseVastReq = new BaseVastReq.Builder<PartnersReq>()
|
|
|
+ .actionType(actionType)
|
|
|
+ .warehouseCode(vwmsConfig.getWarehouseCode())
|
|
|
+ .ownerCode(vwmsConfig.getOwnerCode())
|
|
|
+ .outBizCode("sendVend"+System.currentTimeMillis())
|
|
|
+ .items(new BaseVastItem.Builder<PartnersReq>().item(regList).build())
|
|
|
+ .build();
|
|
|
+ // 创建RequestWrapper对象
|
|
|
+ RequestWrapperVast<PartnersReq> wrapper = new RequestWrapperVast.Builder<PartnersReq>()
|
|
|
+ .request(baseVastReq)
|
|
|
+ .build();
|
|
|
+ try {
|
|
|
+ // 将wrapper对象转换为JSON字符串
|
|
|
+ String json = objectMapper.writeValueAsString(wrapper);
|
|
|
+ logger.info("Request JSON: {}", json);
|
|
|
+ HttpUtil.Response response = HttpUtil.doPostToVWMS("openapi.partners.batchcreate", json,vwmsConfig);
|
|
|
+ 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+".vendor set ve_sendwmsstatus='同步失败',ve_sendwmserr=UNISTR('操作:"+actionType+":"+eMsg.replaceAll("'","''")+"') " +
|
|
|
+ " where ve_code IN ("+codes+")");
|
|
|
+ }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+".vendor set ve_sendwmsstatus='同步成功' ,ve_sendwmserr=null where ve_code in ("+codes+")");
|
|
|
+ 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+".vendor set ve_sendwmsstatus='同步失败',ve_sendwmserr=UNISTR('操作:"+actionType+":"+eMsg.replaceAll("'","''")+"') where ve_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+".vendor set ve_sendwmsstatus='同步失败',ve_sendwmserr=UNISTR('操作:"+actionType+":"+eMsg.replaceAll("'","''")+"') " +
|
|
|
+ " where ve_code IN ("+codes+")");
|
|
|
+ retMap.put("message", eMsg);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ baseDao.execute("update "+master+".vendor set ve_sendwmsflag=-1 where ve_code in ("+codes+") AND NVL(ve_sendwmsflag,0) = 0 AND ve_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转换失败 codes {} ",codes);
|
|
|
+ retMap.put("success", false);
|
|
|
+ retMap.put("message", "JSON转换失败");
|
|
|
+ return retMap;
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ eMsg = StringUtil.nvl(e.getMessage(),"无");
|
|
|
+ baseDao.execute("update "+master+".vendor set ve_sendwmsstatus='同步失败' ,ve_sendwmserr='操作:"+actionType+":"+eMsg+"' where ve_code in ("+codes+")");
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Map<String, Object> sendCust(String master, String ids, String emCode) {
|
|
|
+ Map<String,Object> retMap = new HashMap<>();
|
|
|
+ retMap.put("success",true);
|
|
|
+ logger.info("sendCust-Begin:master {} ids {}",master,ids);
|
|
|
+ // 执行查询
|
|
|
+ SqlRowList docMsg = baseDao.queryForRowSet(" select nvl(cu_sendwmsflag,0) sendwmsflag,cu_id,cu_code,cu_name,cu_shortname," +
|
|
|
+ "ca_id,(case when nvl(ca_remark,' ') = '是' then 1 else 0 end ) isDefault,ca_person,ca_phone,ca_address " +
|
|
|
+ "from "+master+".customer left join "+master+".CustomerAddress on cu_id = ca_cuid " +
|
|
|
+ "where cu_id in ("+ids+") order by cu_id,ca_detno,ca_id");
|
|
|
+ if(!docMsg.hasNext()){
|
|
|
+ retMap.put("success",false);
|
|
|
+ retMap.put("message","客户资料不存在。");
|
|
|
+ return retMap;
|
|
|
+ }
|
|
|
+ List<Map<String, Object>> docMsgResultList = docMsg.getResultList();
|
|
|
+ // 按 sendwmsflag 分组
|
|
|
+ Map<Object, List<Map<String, Object>>> groupedByFlag = docMsgResultList.stream()
|
|
|
+ .collect(Collectors.groupingBy(map -> map.get("sendwmsflag")));
|
|
|
+ StringBuffer errMsg = new StringBuffer();
|
|
|
+ // 处理分组后的数据
|
|
|
+ groupedByFlag.forEach((sendflag, list) -> {
|
|
|
+ logger.info("Flag: {}, Count: {}", sendflag, list.size());
|
|
|
+ // 其他处理逻辑
|
|
|
+ String actionType = "update";
|
|
|
+ String actionTypeName = "更新";
|
|
|
+ if("0".equals(String.valueOf(sendflag))){
|
|
|
+ actionType = "add";
|
|
|
+ actionTypeName = "创建";
|
|
|
+ }
|
|
|
+ // 按cu_id和vc_id升序排序
|
|
|
+ // 按cu_id分组
|
|
|
+ Map<Long, Customer> custMap = new HashMap<>();
|
|
|
+ for (Map<String, Object> map : list) {
|
|
|
+ Long cuId = ((BigDecimal) map.get("cu_id")).longValue();
|
|
|
+
|
|
|
+ // 获取或创建主表对象
|
|
|
+ Customer main = custMap.computeIfAbsent(cuId, k -> {
|
|
|
+ Customer v = new Customer();
|
|
|
+ v.setCuId(cuId);
|
|
|
+ v.setCuCode((String) map.get("cu_code"));
|
|
|
+ v.setCuName((String) map.get("cu_name"));
|
|
|
+ v.setCuShortname((String) map.get("cu_shortname"));
|
|
|
+ return v;
|
|
|
+ });
|
|
|
+
|
|
|
+ // 创建从表对象
|
|
|
+ if(map.get("ca_id") != null){
|
|
|
+ CustomerAddress customerAddress = new CustomerAddress();
|
|
|
+ customerAddress.setCaId(((BigDecimal) map.get("ca_id")).longValue());
|
|
|
+ customerAddress.setIsDefault(((BigDecimal) map.get("isDefault")).intValue());
|
|
|
+ customerAddress.setCaPhone((String) map.get("ca_person"));
|
|
|
+ customerAddress.setCaPhone((String) map.get("ca_phone"));
|
|
|
+ customerAddress.setCaAddress((String) map.get("ca_address"));
|
|
|
+ // 将联系人添加到主表
|
|
|
+ main.getCustomerAddresses().add(customerAddress);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 返回按ve_id分组的VendorMain列表
|
|
|
+ List<Customer> vList = new ArrayList<>(custMap.values());
|
|
|
+ Map<String, Object> res = sendCustSigle(master,actionType,vList);
|
|
|
+ if(!res.get("success").equals(true)){
|
|
|
+ if(errMsg.length()>0){
|
|
|
+ errMsg.append("</br>");
|
|
|
+ }
|
|
|
+ errMsg.append("执行:"+actionTypeName+"操作失败:"+res.get("message"));
|
|
|
+ }
|
|
|
+ });
|
|
|
+ if(errMsg.length()>0){
|
|
|
+ retMap.put("success",false);
|
|
|
+ retMap.put("message",errMsg.toString());
|
|
|
+ return retMap;
|
|
|
+ }
|
|
|
+ logger.info("sendCust-End:master {} ids {}",master,ids);
|
|
|
+ retMap.put("message","同步成功。");
|
|
|
+ return retMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ private Map<String, Object> sendCustSigle(String master,String actionType,List<Customer> list){
|
|
|
+ List<PartnersReq> regList = new ArrayList<>();
|
|
|
+ List<Object> docCodes = new ArrayList<>();
|
|
|
+ String codes = "";
|
|
|
+ StringBuffer errMsg = new StringBuffer();
|
|
|
+ String eMsg = "";
|
|
|
+ Map<String, Object> retMap = new HashMap<>();
|
|
|
+ if(CollectionUtil.isEmpty(list)){
|
|
|
+ retMap.put("success",false);
|
|
|
+ retMap.put("message","没有需要同步的客户。");
|
|
|
+ return retMap;
|
|
|
+ }
|
|
|
+ for (Customer cust : list) {
|
|
|
+ // 创建Req对象
|
|
|
+ docCodes.add(cust.getCuCode());
|
|
|
+ logger.info("sendVend-test: id {} code {}",cust.getCuId(),cust.getCuCode());
|
|
|
+ // 创建ProductReq对象
|
|
|
+ PartnersReq req = PartnersReq.builder()
|
|
|
+ .partnerCode(cust.getCuCode())
|
|
|
+ .name(cust.getCuName())
|
|
|
+ .cnShortName(cust.getCuShortname())
|
|
|
+ .enCompanyType("customer")
|
|
|
+ /* .customField1("自定义2")
|
|
|
+ .customField2("自定义2")
|
|
|
+ .customField3("自定义3")
|
|
|
+ .customField4("自定义4")
|
|
|
+ .customField5("自定义5")
|
|
|
+ .remark("备注注")*/
|
|
|
+ .contactsInfos(PartnersReq.ContactsInfos.builder()
|
|
|
+ .contactsInfo(Optional.ofNullable(cust.getCustomerAddresses())
|
|
|
+ .orElse(Collections.emptyList())
|
|
|
+ .stream()
|
|
|
+ .map(customerAddress -> PartnersReq.ContactsInfo.builder()
|
|
|
+ .isDefault(customerAddress.getIsDefault())
|
|
|
+ .name(customerAddress.getCaPerson())
|
|
|
+ .mobile(customerAddress.getCaPhone() )
|
|
|
+ .address(customerAddress.getCaAddress())
|
|
|
+ .build())
|
|
|
+ .collect(Collectors.toList()))
|
|
|
+ .build())
|
|
|
+ .build();
|
|
|
+ regList.add(req);
|
|
|
+ }
|
|
|
+ codes = "'"+docCodes.stream()
|
|
|
+ .map(String::valueOf)
|
|
|
+ .collect(Collectors.joining("','"))+"'";
|
|
|
+ // 创建BaseReq对象
|
|
|
+ BaseVastReq<PartnersReq> baseVastReq = new BaseVastReq.Builder<PartnersReq>()
|
|
|
+ .actionType(actionType)
|
|
|
+ .warehouseCode(vwmsConfig.getWarehouseCode())
|
|
|
+ .ownerCode(vwmsConfig.getOwnerCode())
|
|
|
+ .outBizCode("sendCust-"+System.currentTimeMillis())
|
|
|
+ .items(new BaseVastItem.Builder<PartnersReq>().item(regList).build())
|
|
|
+ .build();
|
|
|
+ // 创建RequestWrapper对象
|
|
|
+ RequestWrapperVast<PartnersReq> wrapper = new RequestWrapperVast.Builder<PartnersReq>()
|
|
|
+ .request(baseVastReq)
|
|
|
+ .build();
|
|
|
+ try {
|
|
|
+ // 将wrapper对象转换为JSON字符串
|
|
|
+ String json = objectMapper.writeValueAsString(wrapper);
|
|
|
+ logger.info("Request JSON: {}", json);
|
|
|
+ HttpUtil.Response response = HttpUtil.doPostToVWMS("openapi.partners.batchcreate", json,vwmsConfig);
|
|
|
+ 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+".customer set cu_sendwmsstatus='同步失败',cu_sendwmserr=UNISTR('操作:"+actionType+":"+eMsg.replaceAll("'","''")+"') " +
|
|
|
+ " where cu_code IN ("+codes+")");
|
|
|
+ }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+".customer set cu_sendwmsstatus='同步成功' ,cu_sendwmserr=null where cu_code in ("+codes+")");
|
|
|
+ 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+".customer set cu_sendwmsstatus='同步失败',cu_sendwmserr=UNISTR('操作:"+actionType+":"+eMsg.replaceAll("'","''")+"') where cu_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+".customer set cu_sendwmsstatus='同步失败',cu_sendwmserr=UNISTR('操作:"+actionType+":"+eMsg.replaceAll("'","''")+"') " +
|
|
|
+ " where cu_code IN ("+codes+")");
|
|
|
+ retMap.put("message", eMsg);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ baseDao.execute("update "+master+".customer set cu_sendwmsflag=-1 where cu_code in ("+codes+") AND NVL(cu_sendwmsflag,0) = 0 AND cu_sendwmsstatus='同步成功'");
|
|
|
+ }else {
|
|
|
+ retMap.put("success", false);
|
|
|
+ retMap.put("message", "转换失败:"+response.getStatusCode()+":"+response.getResponseText());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return retMap;
|
|
|
+ } catch (JsonProcessingException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ logger.info("sendCust-Error:JSON转换失败 codes {} ",codes);
|
|
|
+ retMap.put("success", false);
|
|
|
+ retMap.put("message", "JSON转换失败");
|
|
|
+ return retMap;
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ eMsg = StringUtil.nvl(e.getMessage(),"无");
|
|
|
+ baseDao.execute("update "+master+".customer set cu_sendwmsstatus='同步失败' ,cu_sendwmserr='操作:"+actionType+":"+eMsg+"' where cu_code in ("+codes+")");
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|