|
|
@@ -1,272 +1,31 @@
|
|
|
package com.uas.eis;
|
|
|
|
|
|
-import com.alibaba.fastjson.JSON;
|
|
|
-import com.alibaba.fastjson.serializer.SerializeConfig;
|
|
|
-import com.alibaba.fastjson.serializer.SerializerFeature;
|
|
|
-import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
-import com.uas.eis.beans.result.CrmQueryResult;
|
|
|
-import com.uas.eis.beans.result.Goods;
|
|
|
-import com.uas.eis.entity.HQPODATALIST;
|
|
|
-import com.uas.eis.entity.HQPO_INFO;
|
|
|
-import com.uas.eis.entity.HQVendPurExecplanReq;
|
|
|
-import com.uas.eis.exception.AccessTokenException;
|
|
|
-import com.uas.eis.listener.UasProdInOutListener;
|
|
|
-import com.uas.eis.manager.CustomerManager;
|
|
|
-import com.uas.eis.manager.ProductManager;
|
|
|
-import com.uas.eis.sdk.core.HttpRequest;
|
|
|
+
|
|
|
+import com.uas.eis.beans.result.Result;
|
|
|
+import com.uas.eis.sdk.dto.QueryReq;
|
|
|
+import com.uas.eis.service.ERPService;
|
|
|
import org.junit.Test;
|
|
|
import org.junit.runner.RunWith;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.boot.test.context.SpringBootTest;
|
|
|
import org.springframework.test.context.junit4.SpringRunner;
|
|
|
|
|
|
-import java.io.BufferedReader;
|
|
|
-import java.io.InputStreamReader;
|
|
|
-import java.io.OutputStream;
|
|
|
-import java.net.HttpURLConnection;
|
|
|
-import java.net.URI;
|
|
|
-import java.net.URL;
|
|
|
-import java.nio.charset.StandardCharsets;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Base64;
|
|
|
-import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
-
|
|
|
-import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
-import com.fasterxml.jackson.databind.PropertyNamingStrategy;
|
|
|
-
|
|
|
-import com.alibaba.fastjson.JSONObject;
|
|
|
-
|
|
|
@RunWith(SpringRunner.class)
|
|
|
@SpringBootTest(classes = {UasEisApplication.class})
|
|
|
public class UasEisApplicationTests {
|
|
|
@Autowired
|
|
|
- private UasProdInOutListener uasProdInOutListener;
|
|
|
+ private ERPService erpService;
|
|
|
|
|
|
- @Autowired
|
|
|
- private ProductManager productManager;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private CustomerManager customerManager;
|
|
|
|
|
|
@Test
|
|
|
- public void testHQPOInfoSerialization() {
|
|
|
- System.out.println("FastJSON版本: " + com.alibaba.fastjson.JSON.VERSION);
|
|
|
-
|
|
|
- // 直接测试HQPO_INFO类的序列化
|
|
|
- HQPO_INFO hqpoInfo = new HQPO_INFO();
|
|
|
- hqpoInfo.setORIGIN_PO_NO("STOCK");
|
|
|
-
|
|
|
- // 添加WriteNonStringKeyAsString特性
|
|
|
- String json = JSON.toJSONString(hqpoInfo,
|
|
|
- SerializerFeature.WriteMapNullValue,
|
|
|
- SerializerFeature.PrettyFormat,
|
|
|
- SerializerFeature.DisableCircularReferenceDetect,
|
|
|
- SerializerFeature.WriteNonStringKeyAsString); // 这个特性很重要
|
|
|
-
|
|
|
- System.out.println("使用完整特性序列化: " + json);
|
|
|
-
|
|
|
- // 手动构建JSON对象 - 这是一个更可靠的备选方案
|
|
|
- JSONObject manualJson = new JSONObject();
|
|
|
- manualJson.put("AAA", hqpoInfo.getORIGIN_PO_NO());
|
|
|
- String manualJsonString = manualJson.toJSONString();
|
|
|
- System.out.println("手动构建JSON: " + manualJsonString);
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- @Test
|
|
|
- public void testHQVendPurExecplanManualJson() {
|
|
|
- // 创建对象
|
|
|
- HQVendPurExecplanReq hqVendPurExecplanReq = new HQVendPurExecplanReq();
|
|
|
- hqVendPurExecplanReq.setVENDOR_NAME("睿智科技发展有限公司");
|
|
|
- hqVendPurExecplanReq.setVENDOR_CODE("19149");
|
|
|
-
|
|
|
- HQPODATALIST hqPODATALIST = new HQPODATALIST();
|
|
|
- hqPODATALIST.setOU_NAME("华勤通讯香港有限公司");
|
|
|
- hqPODATALIST.setPO_NUMBER("110306037");
|
|
|
- hqPODATALIST.setPO_LINE("1.1");
|
|
|
- hqPODATALIST.setHQ_PN("HQ11430351000");
|
|
|
- hqPODATALIST.setORDERED_QUANTITY(12000.0);
|
|
|
- hqPODATALIST.setREQUIRE_DATE("2025/08/01");
|
|
|
-
|
|
|
- HQPO_INFO hqpoInfo = new HQPO_INFO();
|
|
|
- hqpoInfo.setORIGIN_PO_NO("STOCK");
|
|
|
-
|
|
|
- // 手动构建完整的JSON结构
|
|
|
- JSONObject root = new JSONObject();
|
|
|
- root.put("VENDOR_NAME", hqVendPurExecplanReq.getVENDOR_NAME());
|
|
|
- root.put("VENDOR_CODE", hqVendPurExecplanReq.getVENDOR_CODE());
|
|
|
-
|
|
|
- JSONArray podatalistArray = new JSONArray();
|
|
|
- JSONObject podatalistObj = new JSONObject();
|
|
|
- podatalistObj.put("OU_NAME", hqPODATALIST.getOU_NAME());
|
|
|
- podatalistObj.put("PO_NUMBER", hqPODATALIST.getPO_NUMBER());
|
|
|
- podatalistObj.put("PO_LINE", hqPODATALIST.getPO_LINE());
|
|
|
- podatalistObj.put("HQ_PN", hqPODATALIST.getHQ_PN());
|
|
|
- podatalistObj.put("ORDERED_QUANTITY", hqPODATALIST.getORDERED_QUANTITY());
|
|
|
- podatalistObj.put("REQUIRE_DATE", hqPODATALIST.getREQUIRE_DATE());
|
|
|
-
|
|
|
- JSONArray originInfoArray = new JSONArray();
|
|
|
- JSONObject originInfoObj = new JSONObject();
|
|
|
- originInfoObj.put("AAA", hqpoInfo.getORIGIN_PO_NO()); // 这里直接设置为"AAA"
|
|
|
- originInfoArray.add(originInfoObj);
|
|
|
-
|
|
|
- podatalistObj.put("ORIGIN_MANUFACTURER_PO_INFO", originInfoArray);
|
|
|
- podatalistArray.add(podatalistObj);
|
|
|
-
|
|
|
- root.put("PODATALIST", podatalistArray);
|
|
|
-
|
|
|
- String manualFullJson = root.toJSONString();
|
|
|
- System.out.println("手动构建完整JSON: " + manualFullJson);
|
|
|
+ public void testQuery(){
|
|
|
+ QueryReq queryReq = new QueryReq();
|
|
|
+ queryReq.setFormId("MES_BOM");
|
|
|
+ queryReq.setStartRow(0);
|
|
|
+ queryReq.setLimit(100);
|
|
|
+ Map<String,Object> res = erpService.getList(queryReq,"prod");
|
|
|
+ System.out.println(res.toString());
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
- @Test
|
|
|
- public void TestHQ() {
|
|
|
- // 请求URL
|
|
|
- String url = "https://editst.huaqin.com:10443/httpsync/agent-vendor-api/poData";
|
|
|
- String userName = "19149";
|
|
|
- String pwd = "f7E]Rb(9Ce";
|
|
|
- // JSON请求体
|
|
|
- HQVendPurExecplanReq hqVendPurExecplanReq = new HQVendPurExecplanReq();
|
|
|
- hqVendPurExecplanReq.setVENDOR_NAME("睿智科技发展有限公司");
|
|
|
- hqVendPurExecplanReq.setVENDOR_CODE("19149");
|
|
|
- List<HQPODATALIST> PODATALIST = new ArrayList<>();
|
|
|
- HQPODATALIST hqPODATALIST = new HQPODATALIST();
|
|
|
- hqPODATALIST.setOU_NAME("华勤通讯香港有限公司");
|
|
|
- hqPODATALIST.setPO_NUMBER("110306037");
|
|
|
- hqPODATALIST.setPO_LINE("1.1");
|
|
|
- hqPODATALIST.setHQ_PN("HQ11430351000");
|
|
|
- hqPODATALIST.setORDERED_QUANTITY(12000.0);
|
|
|
- hqPODATALIST.setREQUIRE_DATE("2025/08/01");
|
|
|
-
|
|
|
- List<HQPO_INFO> hqPO_INFOS = new ArrayList<>();
|
|
|
- HQPO_INFO hqpoInfo = new HQPO_INFO();
|
|
|
- hqpoInfo.setORIGIN_PO_NO("STOCK");
|
|
|
-// hqpoInfo.setORIGIN_PO_LINE("1");
|
|
|
-// hqpoInfo.setMANUFACTURER_PN("BF1109-A2R4NCCT/LF");
|
|
|
-// hqpoInfo.setHQ_PN("HQ11430351000");
|
|
|
-// hqpoInfo.setSUPPLIER_ORDER_DATE("2999/12/31");
|
|
|
-// hqpoInfo.setQUANTITY(12000.0);
|
|
|
-// hqpoInfo.setESTIMATE_SHIP_DATE("2025/08/01");
|
|
|
- hqPO_INFOS.add(hqpoInfo);
|
|
|
- hqPODATALIST.setORIGIN_MANUFACTURER_PO_INFO(hqPO_INFOS);
|
|
|
-
|
|
|
- PODATALIST.add(hqPODATALIST);
|
|
|
- hqVendPurExecplanReq.setPODATALIST(PODATALIST);
|
|
|
-
|
|
|
- // 使用SerializeConfig强制配置HQPO_INFO的序列化器
|
|
|
- SerializeConfig config = new SerializeConfig();
|
|
|
- // 确保使用Fastjson的ASM序列化器
|
|
|
- config.put(HQPO_INFO.class, config.createASMSerializer(HQPO_INFO.class));
|
|
|
- config.put(HQPODATALIST.class, config.createASMSerializer(HQPODATALIST.class));
|
|
|
- config.put(HQVendPurExecplanReq.class, config.createASMSerializer(HQVendPurExecplanReq.class));
|
|
|
-
|
|
|
- String jsonBody = JSON.toJSONString(hqVendPurExecplanReq, config,
|
|
|
- SerializerFeature.WriteMapNullValue,
|
|
|
- SerializerFeature.PrettyFormat,
|
|
|
- SerializerFeature.DisableCircularReferenceDetect,
|
|
|
- SerializerFeature.WriteNonStringKeyAsString).replace("null","\"\"");
|
|
|
- //"{\"key1\":\"value1\",\"key2\":\"value2\"}";
|
|
|
- System.out.println("jsonBody: "+jsonBody);
|
|
|
- try {
|
|
|
-// String response = sendPostRequest(url,userName,pwd, jsonBody);
|
|
|
-// System.out.println("响应结果: " + response);
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public static String sendPostRequest(String url,String userName,String pwd, String jsonBody) throws Exception {
|
|
|
- // 创建URL对象
|
|
|
- URL obj = new URL(url);
|
|
|
- HttpURLConnection connection = (HttpURLConnection) obj.openConnection();
|
|
|
-
|
|
|
- // 设置请求方法
|
|
|
- connection.setRequestMethod("POST");
|
|
|
-
|
|
|
- // 设置Basic Auth认证头
|
|
|
- String auth = userName+":"+pwd;
|
|
|
- String encodedAuth = Base64.getEncoder().encodeToString(auth.getBytes(StandardCharsets.UTF_8));
|
|
|
- String authHeader = "Basic " + encodedAuth;
|
|
|
- connection.setRequestProperty("Authorization", authHeader);
|
|
|
-
|
|
|
- // 设置请求头
|
|
|
- connection.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
|
|
|
- connection.setRequestProperty("Accept", "application/json");
|
|
|
-
|
|
|
- // 启用输出流,用于发送请求体
|
|
|
- connection.setDoOutput(true);
|
|
|
-
|
|
|
- // 发送JSON请求体
|
|
|
- try (OutputStream os = connection.getOutputStream()) {
|
|
|
- byte[] input = jsonBody.getBytes(StandardCharsets.UTF_8);
|
|
|
- os.write(input, 0, input.length);
|
|
|
- }
|
|
|
-
|
|
|
- // 获取响应码
|
|
|
- int responseCode = connection.getResponseCode();
|
|
|
- System.out.println("响应码: " + responseCode);
|
|
|
-
|
|
|
- // 读取响应
|
|
|
- StringBuilder response = new StringBuilder();
|
|
|
- try (BufferedReader br = new BufferedReader(
|
|
|
- new InputStreamReader(connection.getInputStream(), StandardCharsets.UTF_8))) {
|
|
|
- String responseLine;
|
|
|
- while ((responseLine = br.readLine()) != null) {
|
|
|
- response.append(responseLine.trim());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 断开连接
|
|
|
- connection.disconnect();
|
|
|
-
|
|
|
- return response.toString();
|
|
|
- }
|
|
|
-
|
|
|
- @Test
|
|
|
- public void Test() {
|
|
|
-
|
|
|
- //客户下载
|
|
|
- List<String> field_values = new ArrayList<>();
|
|
|
- field_values.add("1641895200000");
|
|
|
-
|
|
|
- //商品新增
|
|
|
- /*List<Map<String,Object>> sku = new ArrayList<>();
|
|
|
- Map<String,Object> map = new HashMap<>();
|
|
|
- List spec_and_value = new ArrayList();
|
|
|
- map.put("spec_and_value",spec_and_value);
|
|
|
- map.put("product_status","1");
|
|
|
- map.put("unit","PCS");
|
|
|
- sku.add(map);
|
|
|
- Goods goods = new Goods();
|
|
|
- goods.setDataObjectApiName("SPUObj");
|
|
|
- goods.setUnit("PCS");
|
|
|
- goods.setIs_spec(false);
|
|
|
- goods.setStandard_price(2.26);
|
|
|
- goods.setProduct_line("1");
|
|
|
- goods.setName("测试新增202201210077");
|
|
|
- goods.setCategory("6");
|
|
|
- //新增时
|
|
|
- //goods.setSku(sku);*/
|
|
|
-
|
|
|
- //修改时必要参数
|
|
|
- //goods.set_id("61ea66a4f6c2910001540093");
|
|
|
- try {
|
|
|
- CrmQueryResult crmQueryResult = customerManager.queryCustomer(field_values);
|
|
|
- Map<String, Object> data = crmQueryResult.getData();
|
|
|
- List<Map<String,Object>> dataList = (List<Map<String,Object>>) data.get("dataList");
|
|
|
- Object name = dataList.get(0).get("name");
|
|
|
- Object id = dataList.get(0).get("_id");
|
|
|
- System.out.println(name);
|
|
|
- System.out.println(id);
|
|
|
- //productManager.addGoods(goods);
|
|
|
- //productManager.updateGoods(goods);
|
|
|
- }catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-}
|
|
|
+}
|