From 2ecae81fb3ab4057d367650045acc6697567c765 Mon Sep 17 00:00:00 2001
From: tjx <t2856754968@163.com>
Date: 星期四, 30 十月 2025 18:16:59 +0800
Subject: [PATCH] 增加条码的持久化逻辑

---
 src/main/java/com/gs/xiaomi/service/SnListItemService.java          |   10 
 src/main/java/com/gs/xiaomi/entity/SnListItem.java                  |  117 ++++++++++
 src/main/java/com/gs/xiaomi/dto/SnListItemDto.java                  |   97 ++++++++
 src/main/java/com/gs/xiaomi/service/impl/SnListItemServiceImpl.java |   14 +
 src/main/resources/mapper/SnListItemMapper.xml                      |   33 +++
 src/main/java/com/gs/xiaomi/util/SnListItemConverter.java           |  113 ++++++++++
 src/main/java/com/gs/xiaomi/mapper/SnListItemMapper.java            |   12 +
 src/test/java/com/gs/xiaomi/XiaomiApplicationTests.java             |   49 ++++
 src/main/java/com/gs/xiaomi/example/SnListItemUsageExample.java     |  166 +++++++++++++++
 src/main/java/com/gs/xiaomi/dto/BCS101ResponseBody.java             |    5 
 10 files changed, 612 insertions(+), 4 deletions(-)

diff --git a/src/main/java/com/gs/xiaomi/dto/BCS101ResponseBody.java b/src/main/java/com/gs/xiaomi/dto/BCS101ResponseBody.java
index bb51dd1..730f6c3 100644
--- a/src/main/java/com/gs/xiaomi/dto/BCS101ResponseBody.java
+++ b/src/main/java/com/gs/xiaomi/dto/BCS101ResponseBody.java
@@ -8,8 +8,11 @@
 @Data
 public class BCS101ResponseBody {
 
+    /**
+     * SN鍒楄〃
+     */
     @JsonProperty("snList")
-    private List<String> snList;
+    private List<SnListItemDto> snList;
 
     @JsonProperty("reelList")
     private List<String> reelList;
diff --git a/src/main/java/com/gs/xiaomi/dto/SnListItemDto.java b/src/main/java/com/gs/xiaomi/dto/SnListItemDto.java
new file mode 100644
index 0000000..8d93b40
--- /dev/null
+++ b/src/main/java/com/gs/xiaomi/dto/SnListItemDto.java
@@ -0,0 +1,97 @@
+package com.gs.xiaomi.dto;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import lombok.Data;
+
+/**
+ * SN鍒楄〃椤笵TO
+ * 鐢ㄤ簬BCS101鎺ュ彛鐨勮姹傚拰鍝嶅簲鏁版嵁浼犺緭
+ */
+@Data
+public class SnListItemDto {
+
+    /**
+     * SN鎴栬�匯EELID (蹇呭~)
+     */
+    @JsonProperty("snNo")
+    private String snNo;
+
+    /**
+     * REEL涓墿鍝佺殑鏁伴噺 (蹇呭~)
+     */
+    @JsonProperty("qty")
+    private Integer qty;
+
+    /**
+     * SN銆丷EELID鐗╂枡瀵瑰簲瑁呯鍙� (闈炲繀濉�)
+     */
+    @JsonProperty("cartonId")
+    private String cartonId;
+
+    /**
+     * SN銆丷EELID瀵瑰簲鐨勭敓浜ф棩鏈� (蹇呭~)
+     * 鏂欑洏鐨凞C瀛楁
+     */
+    @JsonProperty("dateCode")
+    private String dateCode;
+
+    /**
+     * SN銆丷EELID瀵瑰簲鐨勭敓浜ф壒娆� (闈炲繀濉�)
+     * 鏂欑洏鐨刲ot瀛楁
+     */
+    @JsonProperty("lotNo")
+    private String lotNo;
+
+    /**
+     * 灏忕背鏂欏彿 (蹇呭~)
+     */
+    @JsonProperty("mpnId")
+    private String mpnId;
+
+    /**
+     * 浜у湴 (闈炲繀濉�)
+     * 濉啓鍐呭闇�涓哄瓧姣嶇粍鍚堟棤鏁板瓧銆佹眽瀛�
+     */
+    @JsonProperty("place")
+    private String place;
+
+    /**
+     * 鍝佺墝 (闈炲繀濉�)
+     * 榛樿涓虹┖锛屽惎鐢ㄥ繀濉紑鍏冲悗锛屼负蹇呭~
+     */
+    @JsonProperty("brand")
+    private String brand;
+
+    /**
+     * 鍒堕�犲晢鏂欏彿 (闈炲繀濉�)
+     */
+    @JsonProperty("mpn")
+    private String mpn;
+
+    /**
+     * 鍨嬪彿 (闈炲繀濉�)
+     * 榛樿涓虹┖锛屽惎鐢ㄥ繀濉紑鍏冲悗锛屼负蹇呭~
+     */
+    @JsonProperty("model")
+    private String model;
+
+    /**
+     * 搴撳瓨缁勭粐 (闈炲繀濉�)
+     * VMI杞嚜鏈夐渶涓婁紶锛屽瓧娈�
+     */
+    @JsonProperty("stockOrg")
+    private String stockOrg;
+
+    /**
+     * 鍘熷渚涘簲鍟� (闈炲繀濉�)
+     */
+    @JsonProperty("originSupplierId")
+    private String originSupplierId;
+
+    /**
+     * 璐ㄦ鍗曞彿 (闈炲繀濉�)
+     * 澶粨璋冩嫧鐗╂枡鍏嶆鏃朵娇鐢�
+     */
+    @JsonProperty("inspInvoNo")
+    private String inspInvoNo;
+}
diff --git a/src/main/java/com/gs/xiaomi/entity/SnListItem.java b/src/main/java/com/gs/xiaomi/entity/SnListItem.java
new file mode 100644
index 0000000..19a16e9
--- /dev/null
+++ b/src/main/java/com/gs/xiaomi/entity/SnListItem.java
@@ -0,0 +1,117 @@
+package com.gs.xiaomi.entity;
+
+import com.baomidou.mybatisplus.annotation.DbType;
+import com.baomidou.mybatisplus.annotation.KeySequence;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.Data;
+
+import java.util.Date;
+
+/**
+ * SN/REELID鏉$爜淇℃伅瀹炰綋绫�
+ * @TableName SN_LIST_ITEM
+ */
+@TableName(value = "SN_LIST_ITEM")
+@Data
+@KeySequence(value = "SEQ_SN_LIST_ITEM", dbType = DbType.ORACLE)
+public class SnListItem {
+
+    /**
+     * 涓婚敭ID (浣跨敤SEQ_SN_LIST_ITEM搴忓垪)
+     */
+    @TableId
+    private Long id;
+
+    /**
+     * SN鎴栬�匯EELID (蹇呭~)
+     */
+    private String snNo;
+
+    /**
+     * REEL涓墿鍝佺殑鏁伴噺 (蹇呭~)
+     */
+    private Integer qty;
+
+    /**
+     * SN銆丷EELID鐗╂枡瀵瑰簲瑁呯鍙� (闈炲繀濉�)
+     */
+    private String cartonId;
+
+    /**
+     * SN銆丷EELID瀵瑰簲鐨勭敓浜ф棩鏈� (蹇呭~)
+     * 鏂欑洏鐨凞C瀛楁
+     */
+    private String dateCode;
+
+    /**
+     * SN銆丷EELID瀵瑰簲鐨勭敓浜ф壒娆� (闈炲繀濉�)
+     * 鏂欑洏鐨刲ot瀛楁
+     */
+    private String lotNo;
+
+    /**
+     * 灏忕背鏂欏彿 (蹇呭~)
+     */
+    private String mpnId;
+
+    /**
+     * 浜у湴 (闈炲繀濉�)
+     * 濉啓鍐呭闇�涓哄瓧姣嶇粍鍚堟棤鏁板瓧銆佹眽瀛�
+     */
+    private String place;
+
+    /**
+     * 鍝佺墝 (闈炲繀濉�)
+     * 榛樿涓虹┖锛屽惎鐢ㄥ繀濉紑鍏冲悗锛屼负蹇呭~
+     */
+    private String brand;
+
+    /**
+     * 鍒堕�犲晢鏂欏彿 (闈炲繀濉�)
+     */
+    private String mpn;
+
+    /**
+     * 鍨嬪彿 (闈炲繀濉�)
+     * 榛樿涓虹┖锛屽惎鐢ㄥ繀濉紑鍏冲悗锛屼负蹇呭~
+     */
+    private String model;
+
+    /**
+     * 搴撳瓨缁勭粐 (闈炲繀濉�)
+     * VMI杞嚜鏈夐渶涓婁紶锛屽瓧娈�
+     */
+    private String stockOrg;
+
+    /**
+     * 鍘熷渚涘簲鍟� (闈炲繀濉�)
+     */
+    private String originSupplierId;
+
+    /**
+     * 璐ㄦ鍗曞彿 (闈炲繀濉�)
+     * 澶粨璋冩嫧鐗╂枡鍏嶆鏃朵娇鐢�
+     */
+    private String inspInvoNo;
+
+    /**
+     * 鍏宠仈閫佽揣鍗曚富琛↖D (澶栭敭鍏宠仈DELIVERY_MAIN琛�)
+     */
+    private Long deliveryMainId;
+
+    /**
+     * 閫佽揣鍗曞彿 (鍐椾綑瀛楁渚夸簬鏌ヨ)
+     */
+    private String zzasn;
+
+    /**
+     * 鍒涘缓鏃堕棿
+     */
+    private Date createdTime;
+
+    /**
+     * 鏇存柊鏃堕棿
+     */
+    private Date updatedTime;
+}
diff --git a/src/main/java/com/gs/xiaomi/example/SnListItemUsageExample.java b/src/main/java/com/gs/xiaomi/example/SnListItemUsageExample.java
new file mode 100644
index 0000000..d63421f
--- /dev/null
+++ b/src/main/java/com/gs/xiaomi/example/SnListItemUsageExample.java
@@ -0,0 +1,166 @@
+package com.gs.xiaomi.example;
+
+import com.gs.xiaomi.dto.BCS101Response;
+import com.gs.xiaomi.dto.SnListItemDto;
+import com.gs.xiaomi.entity.SnListItem;
+import com.gs.xiaomi.service.SnListItemService;
+import com.gs.xiaomi.util.SnListItemConverter;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.util.List;
+
+/**
+ * SnListItem浣跨敤绀轰緥
+ * 婕旂ず濡備綍浣跨敤DTO鍜孍ntity杩涜鏁版嵁澶勭悊鍜屾寔涔呭寲
+ */
+@Component
+public class SnListItemUsageExample {
+
+    @Autowired
+    private SnListItemService snListItemService;
+
+    /**
+     * 绀轰緥1: 浠嶣CS101鎺ュ彛鍝嶅簲涓繚瀛楽N鍒楄〃鏁版嵁
+     *
+     * @param response       BCS101鎺ュ彛鍝嶅簲
+     * @param deliveryMainId 閫佽揣鍗曚富琛↖D
+     * @param zzasn          閫佽揣鍗曞彿
+     */
+    public void saveSNListFromResponse(BCS101Response response, Long deliveryMainId, String zzasn) {
+        // 1. 浠庡搷搴斾腑鑾峰彇DTO鍒楄〃
+        List<SnListItemDto> dtoList = response.getBody().getSnList();
+
+        // 2. 灏咲TO鍒楄〃杞崲涓篍ntity鍒楄〃锛屽悓鏃惰缃叧鑱斾俊鎭�
+        List<SnListItem> entityList = SnListItemConverter.toEntityList(dtoList, deliveryMainId, zzasn);
+
+        // 3. 鎵归噺淇濆瓨鍒版暟鎹簱
+        snListItemService.saveBatch(entityList);
+    }
+
+    /**
+     * 绀轰緥2: 鏍规嵁閫佽揣鍗曞彿鏌ヨSN鍒楄〃骞惰浆鎹负DTO
+     *
+     * @param zzasn 閫佽揣鍗曞彿
+     * @return DTO鍒楄〃
+     */
+    public List<SnListItemDto> querySnListByZzasn(String zzasn) {
+        // 1. 浠庢暟鎹簱鏌ヨEntity鍒楄〃
+        List<SnListItem> entityList = snListItemService.lambdaQuery()
+                .eq(SnListItem::getZzasn, zzasn)
+                .list();
+
+        // 2. 灏咵ntity鍒楄〃杞崲涓篋TO鍒楄〃
+        return SnListItemConverter.toDtoList(entityList);
+    }
+
+    /**
+     * 绀轰緥3: 鍗曚釜DTO淇濆瓨
+     *
+     * @param dto            SN鏉$爜DTO
+     * @param deliveryMainId 閫佽揣鍗曚富琛↖D
+     * @param zzasn          閫佽揣鍗曞彿
+     */
+    public void saveSingleSNItem(SnListItemDto dto, Long deliveryMainId, String zzasn) {
+        // 1. DTO杞珽ntity
+        SnListItem entity = SnListItemConverter.toEntity(dto, deliveryMainId, zzasn);
+
+        // 2. 淇濆瓨鍒版暟鎹簱
+        snListItemService.save(entity);
+    }
+
+    /**
+     * 绀轰緥4: 鏍规嵁SN鍙锋煡璇㈣缁嗕俊鎭�
+     *
+     * @param snNo SN鍙�
+     * @return Entity瀵硅薄
+     */
+    public SnListItem queryBySnNo(String snNo) {
+        return snListItemService.lambdaQuery()
+                .eq(SnListItem::getSnNo, snNo)
+                .one();
+    }
+
+    /**
+     * 绀轰緥5: 鏍规嵁灏忕背鏂欏彿鍜岄�佽揣鍗曞彿鏌ヨ
+     *
+     * @param mpnId 灏忕背鏂欏彿
+     * @param zzasn 閫佽揣鍗曞彿
+     * @return Entity鍒楄〃
+     */
+    public List<SnListItem> queryByMpnIdAndZzasn(String mpnId, String zzasn) {
+        return snListItemService.lambdaQuery()
+                .eq(SnListItem::getMpnId, mpnId)
+                .eq(SnListItem::getZzasn, zzasn)
+                .list();
+    }
+
+    /**
+     * 绀轰緥6: 鏍规嵁瑁呯鍙锋煡璇㈡墍鏈塖N
+     *
+     * @param cartonId 瑁呯鍙�
+     * @return Entity鍒楄〃
+     */
+    public List<SnListItem> queryByCartonId(String cartonId) {
+        return snListItemService.lambdaQuery()
+                .eq(SnListItem::getCartonId, cartonId)
+                .orderByAsc(SnListItem::getCreatedTime)
+                .list();
+    }
+
+    /**
+     * 绀轰緥7: 鏇存柊SN鏉$爜淇℃伅
+     *
+     * @param id  璁板綍ID
+     * @param dto 鏇存柊鐨凞TO鏁版嵁
+     * @return 鏄惁鏇存柊鎴愬姛
+     */
+    public boolean updateSnItem(Long id, SnListItemDto dto) {
+        // 1. DTO杞珽ntity
+        SnListItem entity = SnListItemConverter.toEntity(dto);
+        entity.setId(id);
+
+        // 2. 鏇存柊鍒版暟鎹簱
+        return snListItemService.updateById(entity);
+    }
+
+    /**
+     * 绀轰緥8: 鍒犻櫎鎸囧畾閫佽揣鍗曠殑鎵�鏈塖N鏁版嵁
+     *
+     * @param zzasn 閫佽揣鍗曞彿
+     * @return 鏄惁鍒犻櫎鎴愬姛
+     */
+    public boolean deleteByZzasn(String zzasn) {
+        return snListItemService.lambdaUpdate()
+                .eq(SnListItem::getZzasn, zzasn)
+                .remove();
+    }
+
+    /**
+     * 绀轰緥9: 缁熻鏌愪釜閫佽揣鍗曠殑SN鏁伴噺
+     *
+     * @param zzasn 閫佽揣鍗曞彿
+     * @return SN鏁伴噺
+     */
+    public long countByZzasn(String zzasn) {
+        return snListItemService.lambdaQuery()
+                .eq(SnListItem::getZzasn, zzasn)
+                .count();
+    }
+
+    /**
+     * 绀轰緥10: 鍒嗛〉鏌ヨSN鍒楄〃
+     *
+     * @param zzasn    閫佽揣鍗曞彿
+     * @param pageNum  椤电爜
+     * @param pageSize 姣忛〉澶у皬
+     * @return Entity鍒楄〃
+     */
+    public List<SnListItem> queryByPage(String zzasn, int pageNum, int pageSize) {
+        return snListItemService.lambdaQuery()
+                .eq(SnListItem::getZzasn, zzasn)
+                .orderByDesc(SnListItem::getCreatedTime)
+                .last("OFFSET " + (pageNum - 1) * pageSize + " ROWS FETCH NEXT " + pageSize + " ROWS ONLY")
+                .list();
+    }
+}
diff --git a/src/main/java/com/gs/xiaomi/mapper/SnListItemMapper.java b/src/main/java/com/gs/xiaomi/mapper/SnListItemMapper.java
new file mode 100644
index 0000000..580ba4f
--- /dev/null
+++ b/src/main/java/com/gs/xiaomi/mapper/SnListItemMapper.java
@@ -0,0 +1,12 @@
+package com.gs.xiaomi.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.gs.xiaomi.entity.SnListItem;
+import org.apache.ibatis.annotations.Mapper;
+
+/**
+ * SN/REELID鏉$爜淇℃伅Mapper鎺ュ彛
+ */
+@Mapper
+public interface SnListItemMapper extends BaseMapper<SnListItem> {
+}
diff --git a/src/main/java/com/gs/xiaomi/service/SnListItemService.java b/src/main/java/com/gs/xiaomi/service/SnListItemService.java
new file mode 100644
index 0000000..f2cc7bd
--- /dev/null
+++ b/src/main/java/com/gs/xiaomi/service/SnListItemService.java
@@ -0,0 +1,10 @@
+package com.gs.xiaomi.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.gs.xiaomi.entity.SnListItem;
+
+/**
+ * SN/REELID鏉$爜淇℃伅Service鎺ュ彛
+ */
+public interface SnListItemService extends IService<SnListItem> {
+}
diff --git a/src/main/java/com/gs/xiaomi/service/impl/SnListItemServiceImpl.java b/src/main/java/com/gs/xiaomi/service/impl/SnListItemServiceImpl.java
new file mode 100644
index 0000000..30a335c
--- /dev/null
+++ b/src/main/java/com/gs/xiaomi/service/impl/SnListItemServiceImpl.java
@@ -0,0 +1,14 @@
+package com.gs.xiaomi.service.impl;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.gs.xiaomi.entity.SnListItem;
+import com.gs.xiaomi.mapper.SnListItemMapper;
+import com.gs.xiaomi.service.SnListItemService;
+import org.springframework.stereotype.Service;
+
+/**
+ * SN/REELID鏉$爜淇℃伅Service瀹炵幇绫�
+ */
+@Service
+public class SnListItemServiceImpl extends ServiceImpl<SnListItemMapper, SnListItem> implements SnListItemService {
+}
diff --git a/src/main/java/com/gs/xiaomi/util/SnListItemConverter.java b/src/main/java/com/gs/xiaomi/util/SnListItemConverter.java
new file mode 100644
index 0000000..2947772
--- /dev/null
+++ b/src/main/java/com/gs/xiaomi/util/SnListItemConverter.java
@@ -0,0 +1,113 @@
+package com.gs.xiaomi.util;
+
+import com.gs.xiaomi.dto.SnListItemDto;
+import com.gs.xiaomi.entity.SnListItem;
+import org.springframework.beans.BeanUtils;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.stream.Collectors;
+
+/**
+ * SnListItem DTO鍜孍ntity杞崲宸ュ叿绫�
+ */
+public class SnListItemConverter {
+
+    /**
+     * DTO杞珽ntity
+     *
+     * @param dto DTO瀵硅薄
+     * @return Entity瀵硅薄
+     */
+    public static SnListItem toEntity(SnListItemDto dto) {
+        if (dto == null) {
+            return null;
+        }
+        SnListItem entity = new SnListItem();
+        BeanUtils.copyProperties(dto, entity);
+        entity.setCreatedTime(new Date());
+        entity.setUpdatedTime(new Date());
+        return entity;
+    }
+
+    /**
+     * DTO杞珽ntity锛屽甫鍏宠仈淇℃伅
+     *
+     * @param dto             DTO瀵硅薄
+     * @param deliveryMainId  閫佽揣鍗曚富琛↖D
+     * @param zzasn           閫佽揣鍗曞彿
+     * @return Entity瀵硅薄
+     */
+    public static SnListItem toEntity(SnListItemDto dto, Long deliveryMainId, String zzasn) {
+        if (dto == null) {
+            return null;
+        }
+        SnListItem entity = toEntity(dto);
+        entity.setDeliveryMainId(deliveryMainId);
+        entity.setZzasn(zzasn);
+        return entity;
+    }
+
+    /**
+     * Entity杞珼TO
+     *
+     * @param entity Entity瀵硅薄
+     * @return DTO瀵硅薄
+     */
+    public static SnListItemDto toDto(SnListItem entity) {
+        if (entity == null) {
+            return null;
+        }
+        SnListItemDto dto = new SnListItemDto();
+        BeanUtils.copyProperties(entity, dto);
+        return dto;
+    }
+
+    /**
+     * DTO鍒楄〃杞珽ntity鍒楄〃
+     *
+     * @param dtoList DTO鍒楄〃
+     * @return Entity鍒楄〃
+     */
+    public static List<SnListItem> toEntityList(List<SnListItemDto> dtoList) {
+        if (dtoList == null || dtoList.isEmpty()) {
+            return new ArrayList<>();
+        }
+        return dtoList.stream()
+                .map(SnListItemConverter::toEntity)
+                .collect(Collectors.toList());
+    }
+
+    /**
+     * DTO鍒楄〃杞珽ntity鍒楄〃锛屽甫鍏宠仈淇℃伅
+     *
+     * @param dtoList         DTO鍒楄〃
+     * @param deliveryMainId  閫佽揣鍗曚富琛↖D
+     * @param zzasn           閫佽揣鍗曞彿
+     * @return Entity鍒楄〃
+     */
+    public static List<SnListItem> toEntityList(List<SnListItemDto> dtoList, Long deliveryMainId, String zzasn) {
+        if (dtoList == null || dtoList.isEmpty()) {
+            return new ArrayList<>();
+        }
+        return dtoList.stream()
+                .map(dto -> toEntity(dto, deliveryMainId, zzasn))
+                .collect(Collectors.toList());
+    }
+
+    /**
+     * Entity鍒楄〃杞珼TO鍒楄〃
+     *
+     * @param entityList Entity鍒楄〃
+     * @return DTO鍒楄〃
+     */
+    public static List<SnListItemDto> toDtoList(List<SnListItem> entityList) {
+        if (entityList == null || entityList.isEmpty()) {
+            return new ArrayList<>();
+        }
+        return entityList.stream()
+                .map(SnListItemConverter::toDto)
+                .collect(Collectors.toList());
+    }
+}
diff --git a/src/main/resources/mapper/SnListItemMapper.xml b/src/main/resources/mapper/SnListItemMapper.xml
new file mode 100644
index 0000000..e860ef7
--- /dev/null
+++ b/src/main/resources/mapper/SnListItemMapper.xml
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper
+        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.gs.xiaomi.mapper.SnListItemMapper">
+
+    <resultMap id="BaseResultMap" type="com.gs.xiaomi.entity.SnListItem">
+        <id property="id" column="ID" jdbcType="DECIMAL"/>
+        <result property="snNo" column="SN_NO" jdbcType="VARCHAR"/>
+        <result property="qty" column="QTY" jdbcType="DECIMAL"/>
+        <result property="cartonId" column="CARTON_ID" jdbcType="VARCHAR"/>
+        <result property="dateCode" column="DATE_CODE" jdbcType="VARCHAR"/>
+        <result property="lotNo" column="LOT_NO" jdbcType="VARCHAR"/>
+        <result property="mpnId" column="MPN_ID" jdbcType="VARCHAR"/>
+        <result property="place" column="PLACE" jdbcType="VARCHAR"/>
+        <result property="brand" column="BRAND" jdbcType="VARCHAR"/>
+        <result property="mpn" column="MPN" jdbcType="VARCHAR"/>
+        <result property="model" column="MODEL" jdbcType="VARCHAR"/>
+        <result property="stockOrg" column="STOCK_ORG" jdbcType="VARCHAR"/>
+        <result property="originSupplierId" column="ORIGIN_SUPPLIER_ID" jdbcType="VARCHAR"/>
+        <result property="inspInvoNo" column="INSP_INVO_NO" jdbcType="VARCHAR"/>
+        <result property="deliveryMainId" column="DELIVERY_MAIN_ID" jdbcType="DECIMAL"/>
+        <result property="zzasn" column="ZZASN" jdbcType="VARCHAR"/>
+        <result property="createdTime" column="CREATED_TIME" jdbcType="TIMESTAMP"/>
+        <result property="updatedTime" column="UPDATED_TIME" jdbcType="TIMESTAMP"/>
+    </resultMap>
+
+    <sql id="Base_Column_List">
+        ID, SN_NO, QTY, CARTON_ID, DATE_CODE, LOT_NO, MPN_ID, PLACE, BRAND, MPN, MODEL,
+        STOCK_ORG, ORIGIN_SUPPLIER_ID, INSP_INVO_NO, DELIVERY_MAIN_ID, ZZASN, CREATED_TIME, UPDATED_TIME
+    </sql>
+
+</mapper>
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