tjx
2025-10-30 2ecae81fb3ab4057d367650045acc6697567c765
src/test/java/com/gs/xiaomi/XiaomiApplicationTests.java
@@ -6,10 +6,14 @@
import com.gs.xiaomi.dto.BCS101Request;
import com.gs.xiaomi.dto.BCS101Response;
import com.gs.xiaomi.dto.NumbericalDto;
import com.gs.xiaomi.dto.SnListItemDto;
import com.gs.xiaomi.entity.DeliveryMain;
import com.gs.xiaomi.entity.SnListItem;
import com.gs.xiaomi.service.BCS101ApiService;
import com.gs.xiaomi.service.DeliveryMainService;
import com.gs.xiaomi.service.SnListItemService;
import com.gs.xiaomi.service.Xm104Service;
import com.gs.xiaomi.util.SnListItemConverter;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
@@ -29,6 +33,9 @@
    @Autowired
    private DeliveryMainService deliveryMainService;
    @Autowired
    private SnListItemService snListItemService;
    @Test
    void contextLoads() throws Exception {
@@ -60,11 +67,11 @@
        //List<String> collect = list.stream().map(DeliveryMain::getZzasn).collect(Collectors.toList());
        list.forEach(s->{
            System.out.println(String.valueOf(Integer.parseInt(s.getLifnr()))+":"+s.getZzasn());
        list.forEach(s -> {
            System.out.println(String.valueOf(Integer.parseInt(s.getLifnr())) + ":" + s.getZzasn());
            // 创建测试请求参数
            BCS101Request request = new BCS101Request();
            request.setSupplierId(String.valueOf(Integer.parseInt(s.getLifnr())) );
            request.setSupplierId(String.valueOf(Integer.parseInt(s.getHubLifnr())));
            request.setDocNo(s.getZzasn());
            request.setDocType("ASNGR");
            request.setPageNo(1);
@@ -83,6 +90,42 @@
            ObjectMapper objectMapper = new ObjectMapper();
            try {
                BCS101Response response = objectMapper.readValue(bcs101Data, BCS101Response.class);
                // 检查响应是否成功
                if (response.isSuccess()) {
                    // 获取snList数据
                    List<SnListItemDto> snList = response.getBody().getSnList();
                    if (snList != null && !snList.isEmpty()) {
                        System.out.println("获取到 " + snList.size() + " 条SN数据,开始持久化...");
                        // 转换DTO为Entity,并设置关联信息
                        List<SnListItem> entityList = SnListItemConverter.toEntityList(
                            snList,
                            s.getId(),      // deliveryMainId - 送货单主表ID
                            s.getZzasn()    // zzasn - 送货单号
                        );
                        // 先删除该送货单已有的SN数据(避免重复)
                        snListItemService.lambdaUpdate()
                            .eq(SnListItem::getZzasn, s.getZzasn())
                            .remove();
                        // 批量保存到数据库
                        boolean saved = snListItemService.saveBatch(entityList);
                        if (saved) {
                            System.out.println("成功保存 " + entityList.size() + " 条SN数据到数据库");
                        } else {
                            System.err.println("保存SN数据失败!");
                        }
                    } else {
                        System.out.println("响应中没有SN数据");
                    }
                } else {
                    System.err.println("BCS101接口调用失败: " + response.getErrorDesc());
                }
            } catch (JsonProcessingException e) {
                throw new RuntimeException(e);
            }