|
|
@@ -8,13 +8,14 @@ import com.uas.eis.dao.*;
|
|
|
import com.uas.eis.entity.vwms.req.*;
|
|
|
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;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* @author wuyx
|
|
|
@@ -38,34 +39,80 @@ public class ERPServiceImpl implements ERPService {
|
|
|
Map<String,Object> retMap = new HashMap<>();
|
|
|
retMap.put("success",true);
|
|
|
logger.info("sendProd-Begin:master {} ids {}",master,ids);
|
|
|
- SpObserver.putSp(master);
|
|
|
- SqlRowList outMsg = baseDao.queryForRowSet(" select pr_id,pr_code,pr_ycxh,pr_detail,pr_orispeccode,pr_brand,pr_unit,pr_zxbzs from product left join productbrand on pb_name = pr_brand where pr_id in ("+ids+") and pb_sendwms = -1 ");
|
|
|
+// SpObserver.putSp(master);//没有用
|
|
|
+ // 执行查询
|
|
|
+ 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()){
|
|
|
+ retMap.put("success",false);
|
|
|
+ retMap.put("message","没有需要同步的商品。");
|
|
|
+ return retMap;
|
|
|
+ }
|
|
|
+ List<Map<String, Object>> docMsgResultList = docMsg.getResultList();
|
|
|
+ // 按 pr_sendwmsflag 分组
|
|
|
+ Map<Object, List<Map<String, Object>>> groupedByFlag = docMsgResultList.stream()
|
|
|
+ .collect(Collectors.groupingBy(map -> map.get("pr_sendwmsflag")));
|
|
|
+ StringBuffer errMsg = new StringBuffer();
|
|
|
+ // 处理分组后的数据
|
|
|
+ groupedByFlag.forEach((sendflag, list) -> {
|
|
|
+ logger.info("Flag: {}, Count: {}", sendflag, list.size());
|
|
|
+ // 其他处理逻辑
|
|
|
+ String actionType = "update";
|
|
|
+ String actionTypeName = "更新";
|
|
|
+ if("0".equals(sendflag)){
|
|
|
+ actionType = "add";
|
|
|
+ actionTypeName = "创建";
|
|
|
+ }
|
|
|
+ Map<String, Object> res = sendProdSigle(master,actionType,list);
|
|
|
+ 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("sendProd-End:master {} ids {}",master,ids);
|
|
|
+ retMap.put("message","同步成功。");
|
|
|
+ return retMap;
|
|
|
+ }
|
|
|
+ private Map<String, Object> sendProdSigle(String master,String actionType,List<Map<String, Object>> list){
|
|
|
List<ProductReq> productReqList = new ArrayList<>();
|
|
|
- while (outMsg.next()) {
|
|
|
- logger.info("sendProd-test:master {} id {} code {}",master,outMsg.getGeneralInt("pr_id"),outMsg.getGeneralString("pr_code"));
|
|
|
+ List<Object> docIds = new ArrayList<>();
|
|
|
+ String joinedIds = "";
|
|
|
+ Map<String, Object> retMap = new HashMap<>();
|
|
|
+ if(CollectionUtil.isEmpty(list)){
|
|
|
+ retMap.put("success",false);
|
|
|
+ retMap.put("message","没有需要同步的商品。");
|
|
|
+ return retMap;
|
|
|
+ }
|
|
|
+ for (Map<String, Object> map : list) {
|
|
|
+ // 创建ProductReq对象
|
|
|
+ docIds.add(map.get("pr_id"));
|
|
|
+ logger.info("sendProd-test: id {} code {}",map.get("pr_id"),map.get("pr_code"));
|
|
|
// 创建ProductReq对象
|
|
|
ProductReq productReq = new ProductReq.Builder()
|
|
|
- .itemId(outMsg.getGeneralString("pr_code"))
|
|
|
- .itemCode(outMsg.getGeneralString("pr_code"))
|
|
|
- .barCode(outMsg.getGeneralString("pr_ycxh"))
|
|
|
- .itemName(outMsg.getGeneralString("pr_detail"))
|
|
|
- .goodsCode(outMsg.getGeneralString("pr_orispeccode"))
|
|
|
- .categoryName(outMsg.getGeneralString("pr_brand"))
|
|
|
- .stockUnit(outMsg.getGeneralString("pr_unit"))
|
|
|
+ .itemId(map.get("pr_code").toString())
|
|
|
+ .itemCode(map.get("pr_code").toString())
|
|
|
+ .barCode(StringUtil.nvl(map.get("pr_ycxh")," "))
|
|
|
+ .itemName(StringUtil.nvl(map.get("pr_detail")," "))
|
|
|
+ .goodsCode(StringUtil.nvl(map.get("pr_orispeccode")," "))
|
|
|
+ .categoryName(StringUtil.nvl(map.get("pr_brand")," "))
|
|
|
+ .stockUnit(StringUtil.nvl(map.get("pr_unit")," "))
|
|
|
.ExtendProps(new ProductReq.ExtendProps() {{
|
|
|
- setKey1(String.valueOf(outMsg.getGeneralDouble("pr_zxbzs")));
|
|
|
+ setKey1(StringUtil.nvl(map.get("pr_zxbzs"),"0.0"));
|
|
|
}})
|
|
|
.build();
|
|
|
productReqList.add(productReq);
|
|
|
}
|
|
|
- if(CollectionUtil.isEmpty(productReqList)){
|
|
|
- retMap.put("success",false);
|
|
|
- retMap.put("message","没有需要同步的商品。");
|
|
|
- return retMap;
|
|
|
- }
|
|
|
// 创建BaseReq对象
|
|
|
BaseVastReq<ProductReq> baseVastReq = new BaseVastReq.Builder<ProductReq>()
|
|
|
- .actionType("add")
|
|
|
+ .actionType(actionType)
|
|
|
.warehouseCode(vwmsConfig.getWarehouseCode())
|
|
|
.ownerCode(vwmsConfig.getOwnerCode())
|
|
|
.items(productReqList)
|
|
|
@@ -82,17 +129,26 @@ public class ERPServiceImpl implements ERPService {
|
|
|
// &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+")");
|
|
|
+ //TODO 考虑记录日志
|
|
|
} catch (JsonProcessingException e) {
|
|
|
- logger.error("Failed to convert request to JSON", e);
|
|
|
+ e.printStackTrace();
|
|
|
+ logger.info("sendProd-Error:JSON转换失败 ids {} ",joinedIds);
|
|
|
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+")");
|
|
|
throw new RuntimeException(e);
|
|
|
}
|
|
|
- logger.info("sendProd-End:master {} ids {}",master,ids);
|
|
|
- retMap.put("message","同步成功。");
|
|
|
+ retMap.put("success", true);
|
|
|
return retMap;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
}
|