tjx
2025-10-29 b93dbb8f077b5415a0002c66973b716f874f1953
src/test/java/com/gs/xiaomi/XiaomiApplicationTests.java
@@ -1,13 +1,22 @@
package com.gs.xiaomi;
import cn.hutool.crypto.digest.DigestUtil;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.gs.xiaomi.dto.BCS101Request;
import com.gs.xiaomi.dto.BCS101Response;
import com.gs.xiaomi.dto.NumbericalDto;
import com.gs.xiaomi.entity.DeliveryMain;
import com.gs.xiaomi.service.BCS101ApiService;
import com.gs.xiaomi.service.DeliveryMainService;
import com.gs.xiaomi.service.Xm104Service;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import java.io.IOException;
import java.util.List;
import java.util.stream.Collectors;
@SpringBootTest
class XiaomiApplicationTests {
@@ -18,6 +27,9 @@
    @Autowired
    private BCS101ApiService bcs101ApiService;
    @Autowired
    private DeliveryMainService deliveryMainService;
    @Test
    void contextLoads() throws Exception {
        xm104Service.getDb();
@@ -27,7 +39,7 @@
    @Test
    void contextLoads1() throws Exception {
        NumbericalDto barcode = new NumbericalDto();
        barcode.setAsn("9316692923");
        barcode.setAsn("9316702418");
        xm104Service.manualSynchronization(barcode);
    }
@@ -43,16 +55,36 @@
    @Test
    void testBCS101ApiService() throws Exception {
        // 创建测试请求参数
        BCS101Request request = new BCS101Request();
        request.setSupplierId("177301");
        request.setDocNo("9311036039");
        request.setDocType("ASNGR");
        request.setPageNo(1);
        request.setPageSize(1000);
        String bcs101Data = bcs101ApiService.getBCS101Data(request);
        System.out.println(bcs101Data);
        List<DeliveryMain> list = deliveryMainService.list();
        List<String> collect = list.stream().map(DeliveryMain::getZzasn).collect(Collectors.toList());
        collect.forEach(s->{
            // 创建测试请求参数
            BCS101Request request = new BCS101Request();
            request.setSupplierId("177301");
            request.setDocNo("9316692708");
            request.setDocType("ASNGR");
            request.setPageNo(1);
            request.setPageSize(1000);
            // 调用API获取原始JSON字符串
            String bcs101Data = null;
            try {
                bcs101Data = bcs101ApiService.getBCS101Data(request);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            System.out.println("原始响应: " + bcs101Data);
            // 解析JSON为BCS101Response对象
            ObjectMapper objectMapper = new ObjectMapper();
            try {
                BCS101Response response = objectMapper.readValue(bcs101Data, BCS101Response.class);
            } catch (JsonProcessingException e) {
                throw new RuntimeException(e);
            }
        });
    }
}