ZwServiceImpl.java 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. package com.malk.zhiwei.service.impl;
  2. import cn.hutool.http.HttpUtil;
  3. import com.alibaba.fastjson.JSONArray;
  4. import com.alibaba.fastjson.JSONObject;
  5. import com.malk.server.aliwork.YDConf;
  6. import com.malk.server.aliwork.YDParam;
  7. import com.malk.service.aliwork.YDClient;
  8. import com.malk.service.aliwork.YDService;
  9. import com.malk.utils.PublicUtil;
  10. import com.malk.utils.UtilMap;
  11. import com.malk.zhiwei.service.ZwService;
  12. import lombok.extern.slf4j.Slf4j;
  13. import org.springframework.beans.factory.annotation.Autowired;
  14. import org.springframework.stereotype.Service;
  15. import javax.rmi.CORBA.Util;
  16. import java.util.*;
  17. @Service
  18. @Slf4j
  19. public class ZwServiceImpl implements ZwService {
  20. private static String ERP_URL="http://10.0.0.208:80";
  21. private static String ERP_NAME="064";
  22. private static String ERP_PASSWORD="";
  23. private static String ERP_PILOT="PILOT2001";
  24. // http://10.0.0.208:30104/MobileService.asmx?op=GETPILOTLIST
  25. // {"PILOTLIST":[
  26. // {"NAME":"PILOT2001","ZTNAME":"2001测试"},
  27. // {"NAME":"PILOT2002","ZTNAME":"2002CS-BYD"},
  28. // {"NAME":"PILOT2023","ZTNAME":"20232023"},
  29. // {"NAME":"PILOT2024","ZTNAME":"20242024"}]}
  30. private static String ERP_LOGIN_KEY="2025062710430311152101098";
  31. private static String ERP_OP_PRODUCT="Anyv_View_PRODUCT";
  32. private static String ERP_OP_PRODCLAS="Anyv_View_PRODCLAS";
  33. private static String ERP_OP_CUSTOMER="Anyv_View_CUSTOMER";
  34. public static void main(String[] args) {
  35. // {"CODE":"CP000201","clasName":"成品","CNAME":"MPP-20P","SPEC":"600*500*1.8±0.3"},{"CODE":"CP000809","clasName":"成品","CNAME":"阻燃MPP-25P-灰色","SPEC":"1400*1100*3+1-0.5"},{"CODE":"CP001362","clasName":"成品","CNAME":"阻燃MPP-15P","SPEC":"2480*222*3.5±0.2"},{"CODE":"TCP000023","clasName":"成品","CNAME":"POE05灰(李宁)","SPEC":"1850*800*6"}
  36. JSONObject jsonObject = queryData(ERP_OP_PRODUCT,"clasName = '成品'",ERP_PILOT);
  37. // {"CODE":"KH0681","CNAME":"耐玛体育","ABBR":"耐玛体育"},{"CODE":"KH0022","CNAME":"上海浩魁材料科技有限公司","ABBR":"浩魁"}
  38. // JSONObject jsonObject = queryData(ERP_OP_CUSTOMER,"");
  39. // saveSaleOrder("{\"CODE\":\"KH0681\",\"SUPP\":\"KH0681\",\"STAFFCODE\":\"admin\",\"VERIFICATION\":\"False\",\"PRODLIST\":[{\"ERI\":\"0GZ29ZUKV401HCBI\",\"CODE\":\"O220902002\",\"CODE1\":\"\",\"PROD\":\"CP000201\",\"GWN\":\"WXYL\",\"VPNO\":\"X220703\",\"QTY\":1,\"confirm\":0}]}");
  40. // saveDeliveryOrder("{\"CODE\":\"KH0681\",\"STAFFCODE\":\"admin\",\"VERIFICATION\":\"False\",\"PRODLIST\":[{\"ERI\":\"\",\"CODE\":\"O250627010\",\"PROD\":\"CP000201\",\"GWN\":\"WXYL\",\"VPNO\":\"X220703\",\"QTY\":1,\"confirm\":0}]}");
  41. }
  42. private static String erpLogin(String erpPilot){
  43. String xmlResponse=HttpUtil.get(ERP_URL+"/MobileService.asmx/login?name="+ERP_NAME+"&password="+ERP_PASSWORD+"&pilot="+erpPilot);
  44. int jsonStart = xmlResponse.indexOf("{");
  45. int jsonEnd = xmlResponse.lastIndexOf("}");
  46. String jsonStr = xmlResponse.substring(jsonStart, jsonEnd + 1);
  47. JSONObject jsonObject = JSONObject.parseObject(jsonStr);
  48. log.info("登录结果:{}",jsonObject);
  49. return jsonObject.getJSONObject("USER").getString("Key");
  50. }
  51. private static JSONObject queryData(String op,String where,String erpPilot){
  52. String xmlResponse=HttpUtil.get(ERP_URL+"/MobileService.asmx/"+op+"?KEY="+erpLogin(erpPilot)+"&field=&userid="+ERP_NAME+"&where="+where+"&pilot="+erpPilot);
  53. int jsonStart = xmlResponse.indexOf("{");
  54. int jsonEnd = xmlResponse.lastIndexOf("}");
  55. String jsonStr = xmlResponse.substring(jsonStart, jsonEnd + 1);
  56. JSONObject jsonObject = JSONObject.parseObject(jsonStr);
  57. log.info("查询结果:{}",jsonObject);
  58. return jsonObject;
  59. }
  60. private static JSONObject saveSaleOrder(String data,String erpPilot){
  61. String xmlResponse=HttpUtil.get(ERP_URL+"/MobileService.asmx/Anyv_GenForm_ORDCORD1?KEY="+erpLogin(erpPilot)+"&userid="+ERP_NAME+"&Data="+data+"&pilot="+erpPilot);
  62. System.out.println(xmlResponse);
  63. int jsonStart = xmlResponse.indexOf("{");
  64. int jsonEnd = xmlResponse.lastIndexOf("}");
  65. String jsonStr = xmlResponse.substring(jsonStart, jsonEnd + 1);
  66. JSONObject jsonObject = JSONObject.parseObject(jsonStr);
  67. log.info("保存结果:{}",jsonObject);
  68. return jsonObject;
  69. }
  70. @Override
  71. public JSONObject saveSaleOrder(Map formData) {
  72. // 数据转换
  73. JSONObject dataObj = new JSONObject();
  74. dataObj.put("CODE", UtilMap.getString(formData,"textField_mcefftni"));// 单号
  75. dataObj.put("SUPP",UtilMap.getString(formData,"textField_mcefftni"));// 客户代码
  76. dataObj.put("STAFFCODE",UtilMap.getString(formData,"textField_mcefftnj"));
  77. dataObj.put("VERIFICATION","False");
  78. List<Map> list=UtilMap.getList(formData,"tableField_mcefftnk");
  79. List<Map> dataList=new ArrayList<>();
  80. for (Map map : list) {
  81. Map tempMap=new HashMap();
  82. tempMap.put("ERI",""); // 销售订单副档ERI或出货通知单副档ERI
  83. tempMap.put("CODE", UtilMap.getString(map,"textField_mcefftnl")); // 销售订单编号
  84. tempMap.put("CODE1", "");// 出货通知单编号
  85. tempMap.put("PROD", UtilMap.getString(map,"textField_mcefftnn"));// 产品代码
  86. tempMap.put("GWN", UtilMap.getString(map,"textField_mcefftno"));// 仓库代码
  87. tempMap.put("VPNO", UtilMap.getString(map,"textField_mcefftnp"));// 产品批号
  88. tempMap.put("QTY", UtilMap.getString(map,"numberField_mcefftnr"));// 产品数量
  89. tempMap.put("confirm", "0");
  90. dataList.add(tempMap);
  91. }
  92. dataObj.put("PRODLIST",dataList);
  93. String data=JSONObject.toJSONString(dataObj);
  94. log.info("入参:{}",data);
  95. // 调用接口
  96. JSONObject result=saveSaleOrder(UtilMap.getString(formData,"textField_mcefftni"),UtilMap.getString(formData,"textField_mdr1v1di"));
  97. JSONArray codes=result.getJSONArray("page");
  98. for (int i = 0; i < list.size(); i++) {
  99. Map tempMap=new HashMap();
  100. tempMap.put("textField_mdqsatd4",UtilMap.getString(list.get(i),"textField_mdqs9oqa"));
  101. if(codes.size() >= i){
  102. tempMap.put("textField_mdqsatd5",codes.getJSONObject(i).getString("CODE"));
  103. }
  104. ydClient.operateData(YDParam.builder().formUuid("FORM-E999482BC03547D89A435F5441A46F1ANR0R").formDataJson(JSONObject.toJSONString(tempMap)).build(), YDConf.FORM_OPERATION.create);
  105. }
  106. return result;
  107. }
  108. private static JSONObject saveDeliveryOrder(String data,String erpPilot){
  109. String xmlResponse=HttpUtil.get(ERP_URL+"/MobileService.asmx/Anyv_GenForm_STKSHIPNOTE1?KEY="+erpLogin(erpPilot)+"&userid="+ERP_NAME+"&Data="+data+"&pilot="+erpPilot);
  110. System.out.println(xmlResponse);
  111. int jsonStart = xmlResponse.indexOf("{");
  112. int jsonEnd = xmlResponse.lastIndexOf("}");
  113. String jsonStr = xmlResponse.substring(jsonStart, jsonEnd + 1);
  114. JSONObject jsonObject = JSONObject.parseObject(jsonStr);
  115. log.info("保存结果:{}",jsonObject);
  116. return jsonObject;
  117. }
  118. @Override
  119. public JSONObject saveDeliveryOrder(Map formData) {
  120. // 数据转换
  121. JSONObject dataObj = new JSONObject();
  122. dataObj.put("CODE", UtilMap.getString(formData,"textField_mcefftni"));// 客户代码
  123. dataObj.put("STAFFCODE",UtilMap.getString(formData,"textField_mcefftnj"));
  124. dataObj.put("VERIFICATION","False");
  125. List<Map> list=UtilMap.getList(formData,"tableField_mcefftnk");
  126. List<Map> dataList=new ArrayList<>();
  127. for (Map map : list) {
  128. Map tempMap=new HashMap();
  129. tempMap.put("ERI",""); // 销售订单副档ERI或出货通知单副档ERI
  130. tempMap.put("CODE", UtilMap.getString(map,"textField_mcefftnl")); // 销售订单编号
  131. tempMap.put("PROD", UtilMap.getString(map,"textField_mcefftnn"));// 产品代码
  132. tempMap.put("GWN", UtilMap.getString(map,"textField_mcefftno"));// 仓库代码
  133. tempMap.put("VPNO", UtilMap.getString(map,"textField_mcefftnp"));// 产品批号
  134. tempMap.put("QTY", UtilMap.getString(map,"numberField_mcefftnr"));// 产品数量
  135. tempMap.put("confirm", "0");
  136. dataList.add(tempMap);
  137. }
  138. dataObj.put("PRODLIST",dataList);
  139. String data=JSONObject.toJSONString(dataObj);
  140. log.info("入参:{}",data);
  141. // 调用接口
  142. return saveDeliveryOrder(data,UtilMap.getString(formData,"textField_mdr1v1di"));
  143. }
  144. @Autowired
  145. private YDClient ydClient;
  146. @Override
  147. public void syncProduct(String id,String erpPilot) {
  148. JSONObject jsonObject = queryData(ERP_OP_PRODUCT,"clasName = '成品'"+ (PublicUtil.isNull(id)?"":("and CODE = '"+id+"'")),erpPilot);
  149. JSONArray data = jsonObject.getJSONArray("data");
  150. log.info("data.size():{}",data.size());
  151. for (int i = 0; i < data.size(); i++) {
  152. JSONObject dataObj = data.getJSONObject(i);
  153. String productId=UtilMap.getString(dataObj,"CODE");
  154. Map saveMap=UtilMap.map("textField_mcijetil, textField_l43jpnsf, textField_l43jpnsh",productId,dataObj.getString("CNAME"),dataObj.getString("SPEC"));
  155. ydClient.operateData(YDParam.builder().formUuid("FORM-4A7B1A62CCFC4D758AB98ADE3F97D40COYO2")
  156. .searchCondition(JSONObject.toJSONString(UtilMap.map("textField_mcijetil", productId)))
  157. .formDataJson(JSONObject.toJSONString(saveMap)).build(), YDConf.FORM_OPERATION.upsert);
  158. }
  159. }
  160. }