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 | 174 ++++++++++++++++++++++++++++++++++++---------------------
1 files changed, 109 insertions(+), 65 deletions(-)
diff --git a/src/test/java/com/gs/xiaomi/XiaomiApplicationTests.java b/src/test/java/com/gs/xiaomi/XiaomiApplicationTests.java
index 3b4e7cd..955ab01 100644
--- a/src/test/java/com/gs/xiaomi/XiaomiApplicationTests.java
+++ b/src/test/java/com/gs/xiaomi/XiaomiApplicationTests.java
@@ -1,25 +1,58 @@
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.XM104Service;
+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 {
@Autowired
- private XM104Service xm104Service;
+ private Xm104Service xm104Service;
@Autowired
private BCS101ApiService bcs101ApiService;
+ @Autowired
+ private DeliveryMainService deliveryMainService;
+
+ @Autowired
+ private SnListItemService snListItemService;
+
+ @Autowired
+ private BCS101Service bcs101Service;
+
@Test
void contextLoads() throws Exception {
xm104Service.getDb();
+ }
+
+ //manualSynchronization
+ @Test
+ void contextLoads1() throws Exception {
+ NumbericalDto barcode = new NumbericalDto();
+ barcode.setAsn("9316702418");
+ xm104Service.manualSynchronization(barcode);
}
@Test
@@ -34,74 +67,85 @@
@Test
void testBCS101ApiService() throws Exception {
- // 鍒涘缓娴嬭瘯璇锋眰鍙傛暟
- BCS101Request request = new BCS101Request();
- request.setSupplierId("100071");
- request.setDocNo("9311991542");
- request.setDocType("ASNGR");
- request.setPageNo(1);
- request.setPageSize(1000);
- //Error: ERROR_IN_MODULECHAIN;ERROR_IN_MODULECHAIN, Sender Channel 'CC_MI_OEM_HTTP_OUT' (ID: a58369adbaa03aafb76d2c02c2ae7cd7): Catching exception calling messaging system
- System.out.println("=== 娴嬭瘯BCS101 API鏈嶅姟锛圔asic Auth鐗堟湰锛� ===");
- try {
- // 璋冪敤鏍囧噯BCS101 API鏈嶅姟锛堝彧浣跨敤Basic Auth锛�
- String response = bcs101ApiService.getBCS101Data(request);
- System.out.println("BCS101 API Response: " + response);
- } catch (Exception e) {
- System.out.println("BCS101 API璋冪敤寮傚父: " + e.getMessage());
- e.printStackTrace();
- }
+ List<DeliveryMain> list = deliveryMainService.list();
- //Error: ERROR_IN_MODULECHAIN;ERROR_IN_MODULECHAIN, Sender Channel 'CC_MI_OEM_HTTP_OUT' (ID: a58369adbaa03aafb76d2c02c2ae7cd7): Catching exception calling messaging system
- System.out.println("\n=== 娴嬭瘯BCS101 API鏈嶅姟锛堝甫X5鍗忚鐗堟湰锛� ===");
- try {
- // 璋冪敤甯5鍗忚鐨凚CS101 API鏈嶅姟
- String responseWithX5 = bcs101ApiService.getBCS101DataWithX5(request, true);
- System.out.println("BCS101 API Response (X5): " + responseWithX5);
- } catch (Exception e) {
- System.out.println("BCS101 API X5璋冪敤寮傚父: " + e.getMessage());
- e.printStackTrace();
- }
+ //List<String> collect = list.stream().map(DeliveryMain::getZzasn).collect(Collectors.toList());
- System.out.println("\n=== 娴嬭瘯BCS101 API鏈嶅姟锛堣皟璇曠増鏈級 ===");
- try {
- // 璋冪敤璋冭瘯鐗堟湰API鏈嶅姟
- String debugResponse = bcs101ApiService.getBCS101DataDebug(request);
- System.out.println("BCS101 API Debug Response: " + debugResponse);
- } catch (Exception e) {
- System.out.println("BCS101 API 璋冭瘯鐗堟湰璋冪敤寮傚父: " + e.getMessage());
- e.printStackTrace();
- }
+ 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);
- System.out.println("\n=== 娴嬭瘯BCS101 API鏈嶅姟锛堢畝鍖栫増鏈級 ===");
- try {
- // 璋冪敤绠�鍖栫増鏈珹PI鏈嶅姟
- String simpleResponse = bcs101ApiService.getBCS101DataSimple(request);
- System.out.println("BCS101 API Simple Response: " + simpleResponse);
- } catch (Exception e) {
- System.out.println("BCS101 API 绠�鍖栫増鏈皟鐢ㄥ紓甯�: " + e.getMessage());
- e.printStackTrace();
- }
+ // 璋冪敤API鑾峰彇鍘熷JSON瀛楃涓�
+ String bcs101Data = null;
+ try {
+ bcs101Data = bcs101ApiService.getBCS101Data(request);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ System.out.println("鍘熷鍝嶅簲: " + bcs101Data);
- System.out.println("\n=== 娴嬭瘯BCS101 API鏈嶅姟锛圶5鍗忚鏍囧噯鐗堟湰锛� ===");
- try {
- // 璋冪敤X5鍗忚鏍囧噯鐗堟湰
- String x5StandardResponse = bcs101ApiService.getBCS101DataX5Standard(request);
- System.out.println("BCS101 API X5Standard Response: " + x5StandardResponse);
- } catch (Exception e) {
- System.out.println("BCS101 API X5鏍囧噯鐗堟湰璋冪敤寮傚父: " + e.getMessage());
- e.printStackTrace();
- }
+ // 瑙f瀽JSON涓築CS101Response瀵硅薄
+ ObjectMapper objectMapper = new ObjectMapper();
+ try {
+ BCS101Response response = objectMapper.readValue(bcs101Data, BCS101Response.class);
- System.out.println("\n=== 娴嬭瘯BCS101 API鏈嶅姟锛圶5鍗忚鍙樹綋鐗堟湰锛� ===");
- try {
- // 璋冪敤X5鍗忚鍙樹綋鐗堟湰
- String x5VariantResponse = bcs101ApiService.getBCS101DataX5Variant(request);
- System.out.println("BCS101 API X5Variant Response: " + x5VariantResponse);
- } catch (Exception e) {
- System.out.println("BCS101 API X5鍙樹綋鐗堟湰璋冪敤寮傚父: " + e.getMessage());
- e.printStackTrace();
- }
+ // 妫�鏌ュ搷搴旀槸鍚︽垚鍔�
+ 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