From 2ecae81fb3ab4057d367650045acc6697567c765 Mon Sep 17 00:00:00 2001
From: tjx <t2856754968@163.com>
Date: 星期四, 30 十月 2025 18:16:59 +0800
Subject: [PATCH] 增加条码的持久化逻辑
---
src/test/java/com/gs/xiaomi/XiaomiApplicationTests.java | 49 ++++++++++++++++++++++++++++++++++++++++++++++---
1 files changed, 46 insertions(+), 3 deletions(-)
diff --git a/src/test/java/com/gs/xiaomi/XiaomiApplicationTests.java b/src/test/java/com/gs/xiaomi/XiaomiApplicationTests.java
index c6362b1..3e6e966 100644
--- a/src/test/java/com/gs/xiaomi/XiaomiApplicationTests.java
+++ b/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() + " 鏉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);
}
--
Gitblit v1.9.3