本地测试后放到服务器上测试

This commit is contained in:
彭枝刚 2024-11-07 21:07:08 +08:00
parent 3644f90c0b
commit 014fa92813
2 changed files with 145 additions and 0 deletions

View File

@ -21,6 +21,7 @@ import io.seata.spring.annotation.GlobalTransactional;
import lombok.AllArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.time.LocalDateTime;

View File

@ -0,0 +1,144 @@
package com.foreverwin.iep.integration.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.http.HttpHeaders;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.List;
class SalesOrderItfServiceImplTest {
public static final String origin = "http://127.0.0.1:8091";
public static final String mesOrigin = "http://localhost:8080";
@Test
public void testPost() throws Exception {
CloseableHttpClient httpClient = HttpClients.createDefault();
HttpPost postRequest = new HttpPost(mesOrigin + "/iep-int/salesOrderItf/saveSalesOrderData");
String token = getToken();
postRequest.setHeader(HttpHeaders.AUTHORIZATION, "Bearer "+ token);
postRequest.setHeader("TENANT-ID", "2031");
postRequest.setHeader(HttpHeaders.CONTENT_TYPE, "application/json; charset=UTF-8");
postRequest.setEntity(new StringEntity(msgBody));
// 调用登陆接口获取token
HttpResponse response = httpClient.execute(postRequest);
String responseString = EntityUtils.toString(response.getEntity());
// 解析返回的 JSON 数据
ObjectMapper objectMapper = new ObjectMapper();
JsonNode responseJson = objectMapper.readTree(responseString);
System.out.println(responseJson);
}
public String getToken() throws Exception {
CloseableHttpClient httpClient = HttpClients.createDefault();
HttpPost postRequest = new HttpPost(mesOrigin + "/auth/oauth/token?randomStr=blockPuzzle&grant_type=password");
// 构建请求参数
List<NameValuePair> pair = new ArrayList<>();
pair.add(new BasicNameValuePair("username", "snow"));
pair.add(new BasicNameValuePair("password", "fCmq1pBbOzM="));
postRequest.setHeader(HttpHeaders.AUTHORIZATION, "Basic bW9tOm1vbQ==");
postRequest.setHeader("TENANT-ID", "2031");
postRequest.setHeader(HttpHeaders.CONTENT_TYPE, "application/x-www-form-urlencoded");
postRequest.setEntity(new UrlEncodedFormEntity(pair, "UTF-8"));
// 调用登陆接口获取token
HttpResponse response = httpClient.execute(postRequest);
String responseString = EntityUtils.toString(response.getEntity());
// 解析返回的 JSON 数据
ObjectMapper objectMapper = new ObjectMapper();
JsonNode responseJson = objectMapper.readTree(responseString);
String accessToken = responseJson.get("access_token").asText();
System.out.println(responseJson);
return accessToken;
}
static String msgBody = "[\n" +
" {\n" +
" \"SO_NUMBER\": \"JI\",\n" +
" \"SO_CREATOR\": \"80\",\n" +
" \"SO_CREATE_TIME\": \"2024-11-01 12:30:57\",\n" +
" \"SO_REASON\": \"测试\",\n" +
" \"SO_TYPE\": \"A\",\n" +
" \"SO_CATEGORY\": \"A\",\n" +
" \"SO_CURRENCY\": \"20\",\n" +
" \"SO_SALES_ORG\": \"中\",\n" +
" \"SO_SALES_DISTRIBUTOR\": \"8089888-80\",\n" +
" \"SO_SALES_OFFICE\": \"8089888-80\",\n" +
" \"SO_SALES_GROUP\": \"8089888-80\",\n" +
" \"SO_SALES_PARTNER\": \"8089888-80\",\n" +
" \"SO_SALES_PARTNER_CODE\": \"8089888-80\",\n" +
" \"SO_MANAGER\": \"8089888-80\",\n" +
" \"SO_ASSISTANT\": \"SO销售助理\",\n" +
" \"SO_CUSTOMER\": \"APP\",\n" +
" \"SO_CUSTOMER_CODE\": \"43\",\n" +
" \"SO_CREDIT_STATUS\": \"OK\",\n" +
" \"SO_PAYMENT_STATUS\": \"Y\",\n" +
" \"LINE_INFO\": [\n" +
" {\n" +
" \"SO_LINE_ID\": \"1\",\n" +
" \"CATEGORY\": \"B\",\n" +
" \"REASON\": \"SO拒绝原因\",\n" +
" \"ITEM\": \"BJ0\",\n" +
" \"QTY\": \"999\",\n" +
" \"OVER_QTY\": \"100\",\n" +
" \"DELIVERY_DATE\": \"2024-11-07\",\n" +
" \"UOM\": \"PCS\",\n" +
" \"SALES_UOM\": \"EM\",\n" +
" \"DELIVERY_PLANT\": \"2023\",\n" +
" \"PRICE_STATUS\": \"Y\",\n" +
" \"DELIVERY_STATUS\": \"N\",\n" +
" \"CONFIG_ID\": \"001\",\n" +
" \"CONFIG_INFO\": [\n" +
" {\n" +
" \"CONFIG_ITEM\": \"BM\",\n" +
" \"CONFIG_ITEM_DESC\": \"SO配置项描述\",\n" +
" \"CONFIG_ITEM_VALUE\": \"23\",\n" +
" \"CONFIG_ITEM_VALUE_DESC\": \"SO配置值描述\"\n" +
" },\n" +
" {\n" +
" \"CONFIG_ITEM\": \"CM\",\n" +
" \"CONFIG_ITEM_DESC\": \"第二笔\",\n" +
" \"CONFIG_ITEM_VALUE\": \"43\",\n" +
" \"CONFIG_ITEM_VALUE_DESC\": \"测试\"\n" +
" }\n" +
" ]\n" +
" },\n" +
" {\n" +
" \"SO_LINE_ID\": \"2\",\n" +
" \"CATEGORY\": \"C\",\n" +
" \"REASON\": \"销售订单第二行\",\n" +
" \"ITEM\": \"BJ0\",\n" +
" \"QTY\": \"999\",\n" +
" \"OVER_QTY\": \"100\",\n" +
" \"DELIVERY_DATE\": \"2024-11-07\",\n" +
" \"UOM\": \"PCS\",\n" +
" \"SALES_UOM\": \"EM\",\n" +
" \"DELIVERY_PLANT\": \"2023\",\n" +
" \"PRICE_STATUS\": \"Y\",\n" +
" \"DELIVERY_STATUS\": \"N\",\n" +
" \"CONFIG_ID\": \"002\",\n" +
" \"CONFIG_INFO\": [\n" +
"\n" +
" ]\n" +
" }\n" +
" ]\n" +
" }\n" +
"]";
}