From f2b62569198d9afd1604a1617ab1e0a3e11f74bf Mon Sep 17 00:00:00 2001
From: tjx <t2856754968@163.com>
Date: 星期四, 30 十月 2025 18:40:22 +0800
Subject: [PATCH] 增加条码的持久化逻辑
---
src/test/java/com/gs/xiaomi/XiaomiApplicationTests.java | 113 +++++++++++++++++++++++++++++++++++++++++++++++++++-----
1 files changed, 103 insertions(+), 10 deletions(-)
diff --git a/src/test/java/com/gs/xiaomi/XiaomiApplicationTests.java b/src/test/java/com/gs/xiaomi/XiaomiApplicationTests.java
index bfbb38d..955ab01 100644
--- a/src/test/java/com/gs/xiaomi/XiaomiApplicationTests.java
+++ b/src/test/java/com/gs/xiaomi/XiaomiApplicationTests.java
@@ -1,13 +1,28 @@
package com.gs.xiaomi;
import cn.hutool.crypto.digest.DigestUtil;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+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.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.BCS101Service;
+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;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.stream.Collectors;
@SpringBootTest
class XiaomiApplicationTests {
@@ -18,6 +33,15 @@
@Autowired
private BCS101ApiService bcs101ApiService;
+ @Autowired
+ private DeliveryMainService deliveryMainService;
+
+ @Autowired
+ private SnListItemService snListItemService;
+
+ @Autowired
+ private BCS101Service bcs101Service;
+
@Test
void contextLoads() throws Exception {
xm104Service.getDb();
@@ -27,7 +51,7 @@
@Test
void contextLoads1() throws Exception {
NumbericalDto barcode = new NumbericalDto();
- barcode.setAsn("9316692923");
+ barcode.setAsn("9316702418");
xm104Service.manualSynchronization(barcode);
}
@@ -43,16 +67,85 @@
@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());
+
+ 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.getHubLifnr())));
+ request.setDocNo(s.getZzasn());
+ 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);
+
+ // 瑙f瀽JSON涓築CS101Response瀵硅薄
+ 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() + " 鏉N鏁版嵁锛屽紑濮嬫寔涔呭寲...");
+
+ // 杞崲DTO涓篍ntity锛屽苟璁剧疆鍏宠仈淇℃伅
+ List<SnListItem> entityList = SnListItemConverter.toEntityList(
+ snList,
+ s.getId(), // deliveryMainId - 閫佽揣鍗曚富琛↖D
+ s.getZzasn() // zzasn - 閫佽揣鍗曞彿
+ );
+
+ // 鍏堝垹闄よ閫佽揣鍗曞凡鏈夌殑SN鏁版嵁锛堥伩鍏嶉噸澶嶏級
+ snListItemService.lambdaUpdate()
+ .eq(SnListItem::getZzasn, s.getZzasn())
+ .remove();
+
+ // 鎵归噺淇濆瓨鍒版暟鎹簱
+ boolean saved = snListItemService.saveBatch(entityList);
+
+ if (saved) {
+ System.out.println("鎴愬姛淇濆瓨 " + entityList.size() + " 鏉N鏁版嵁鍒版暟鎹簱");
+ } else {
+ System.err.println("淇濆瓨SN鏁版嵁澶辫触锛�");
+ }
+ } else {
+ System.out.println("鍝嶅簲涓病鏈塖N鏁版嵁");
+ }
+ } else {
+ System.err.println("BCS101鎺ュ彛璋冪敤澶辫触: " + response.getErrorDesc());
+ }
+
+ } catch (JsonProcessingException e) {
+ throw new RuntimeException(e);
+ }
+ });
+ }
+
+
+ /**
+ * 娴嬭瘯BCS101鏁版嵁鍚屾 - 浣跨敤BCS101Service
+ * @param asn 閫佽揣鍗曞彿
+ * @throws Exception 寮傚父
+ */
+ @Test
+ void testGetBCS101() throws Exception {
+ // 鐩存帴璋冪敤BCS101Service杩涜鏁版嵁鍚屾
+ bcs101Service.syncBCS101DataByAsn("9316702418");
}
}
--
Gitblit v1.9.3