From 42ef86c3898c5a59d36855d52d44db99a764a09e Mon Sep 17 00:00:00 2001
From: liuy <37787198+LiuyCodes@users.noreply.github.com>
Date: Wed, 18 Sep 2024 18:40:34 +0800
Subject: [PATCH] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=BA=93=E6=9F=A5=E8=AF=A2?=
 =?UTF-8?q?=E5=92=8C=E7=BC=93=E5=AD=98=E5=88=9D=E5=A7=8B=E5=8C=96=E4=BC=98?=
 =?UTF-8?q?=E5=8C=96-=20=E4=BF=AE=E6=AD=A3=E4=BA=86BdCubasdocEntity?=
 =?UTF-8?q?=E5=92=8CBdTaxitemsEntity=E4=B8=AD=E7=9A=84=E6=95=B0=E6=8D=AE?=
 =?UTF-8?q?=E5=BA=93=E6=9F=A5=E8=AF=A2=E9=80=BB=E8=BE=91=EF=BC=8C=E4=BB=A5?=
 =?UTF-8?q?=E6=8F=90=E9=AB=98=E6=9F=A5=E8=AF=A2=E6=95=88=E7=8E=87=E3=80=82?=
 =?UTF-8?q?=20-=20=E5=9C=A8TocReturnBasicArchivesCacheUtil=E4=B8=AD?=
 =?UTF-8?q?=E9=87=8D=E6=9E=84=E4=BA=86=E7=BC=93=E5=AD=98=E5=88=9D=E5=A7=8B?=
 =?UTF-8?q?=E5=8C=96=E6=96=B9=E6=B3=95=EF=BC=8C=E4=BB=A5=E6=94=AF=E6=8C=81?=
 =?UTF-8?q?=E5=8F=82=E6=95=B0=E5=8C=96=E6=9F=A5=E8=AF=A2=E5=B9=B6=E5=87=8F?=
 =?UTF-8?q?=E5=B0=91=E6=95=B0=E6=8D=AE=E5=BA=93=E8=B4=9F=E6=8B=85=E3=80=82?=
 =?UTF-8?q?=20-=20=E8=B0=83=E6=95=B4=E4=BA=86SoSaleReturnPluginInitializer?=
 =?UTF-8?q?ToC=E4=B8=AD=E6=B5=8B=E8=AF=95=E4=BB=A3=E7=A0=81=EF=BC=8C?=
 =?UTF-8?q?=E4=BB=A5=E9=AA=8C=E8=AF=81=E6=96=B0=E7=9A=84=E7=BC=93=E5=AD=98?=
 =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96=E9=80=BB=E8=BE=91=E3=80=82=E6=AD=A4?=
 =?UTF-8?q?=E6=9B=B4=E6=94=B9=E9=80=9A=E8=BF=87=E4=BC=98=E5=8C=96=E6=95=B0?=
 =?UTF-8?q?=E6=8D=AE=E5=BA=93=E6=9F=A5=E8=AF=A2=E5=92=8C=E6=94=B9=E8=BF=9B?=
 =?UTF-8?q?=E7=BC=93=E5=AD=98=E7=AD=96=E7=95=A5=EF=BC=8C=E6=8F=90=E9=AB=98?=
 =?UTF-8?q?=E4=BA=86=E7=B3=BB=E7=BB=9F=E7=9A=84=E6=95=B4=E4=BD=93=E6=80=A7?=
 =?UTF-8?q?=E8=83=BD=E5=92=8C=E5=8F=AF=E9=9D=A0=E6=80=A7=E3=80=82?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../plugin/lets/entity/BdCubasdocEntity.xml   |   4 +
 .../plugin/lets/entity/BdTaxitemsEntity.xml   |   2 +-
 .../TocofsReturngoodsDetailedEntity.xml       |   2 +-
 .../SoSaleReturnPluginInitializerToC.java     |  42 ++-
 .../util/TocOrderBasicArchivesCacheUtil.java  |   4 +
 .../util/TocReturnBasicArchivesCacheUtil.java | 307 ++++++++++++++----
 .../SoSaleReturnPluginInitializerToCTest.java |   4 +-
 7 files changed, 285 insertions(+), 80 deletions(-)

diff --git a/buildpackage/src/main/java/com/hzya/frame/plugin/lets/entity/BdCubasdocEntity.xml b/buildpackage/src/main/java/com/hzya/frame/plugin/lets/entity/BdCubasdocEntity.xml
index c5c502bb..1f413919 100644
--- a/buildpackage/src/main/java/com/hzya/frame/plugin/lets/entity/BdCubasdocEntity.xml
+++ b/buildpackage/src/main/java/com/hzya/frame/plugin/lets/entity/BdCubasdocEntity.xml
@@ -232,6 +232,10 @@
 
             <if test="modifytime_start_time!=null and modifytime_start_time!=''">and ts >= #{modifytime_start_time}</if>
             <if test="modifytime_end_time!=null and modifytime_end_time!=''">and ts &lt;= #{modifytime_end_time}</if>
+
+            <if test="custcodes!=null and custcodes!=''">
+                and custcode in (${custcodes})
+            </if>
         </trim>
         <if test=" sort == ''.toString() "> order by sorts asc</if>
         <if test=" sort !='' and sort!=null and order !='' and order!=null ">order by ${sort} ${order}</if>
diff --git a/buildpackage/src/main/java/com/hzya/frame/plugin/lets/entity/BdTaxitemsEntity.xml b/buildpackage/src/main/java/com/hzya/frame/plugin/lets/entity/BdTaxitemsEntity.xml
index a9f53b6c..2c50dc57 100644
--- a/buildpackage/src/main/java/com/hzya/frame/plugin/lets/entity/BdTaxitemsEntity.xml
+++ b/buildpackage/src/main/java/com/hzya/frame/plugin/lets/entity/BdTaxitemsEntity.xml
@@ -207,7 +207,7 @@
             and bd_invbasdoc.invcode = #{invcode}
           </if>
           <if test="invcodes!=null and invcodes!=''">
-              and bd_invbasdoc.invcode in ${invcodes}
+              and bd_invbasdoc.invcode in (${invcodes})
           </if>
     </select>
 
diff --git a/buildpackage/src/main/java/com/hzya/frame/plugin/lets/ofs/entity/TocofsReturngoodsDetailedEntity.xml b/buildpackage/src/main/java/com/hzya/frame/plugin/lets/ofs/entity/TocofsReturngoodsDetailedEntity.xml
index b3ce7554..17e7a583 100644
--- a/buildpackage/src/main/java/com/hzya/frame/plugin/lets/ofs/entity/TocofsReturngoodsDetailedEntity.xml
+++ b/buildpackage/src/main/java/com/hzya/frame/plugin/lets/ofs/entity/TocofsReturngoodsDetailedEntity.xml
@@ -882,7 +882,7 @@
     insert into tocofs_returngoods_detailed(id,newPushDate3,newTransmitInfo3,newState3,newSystemNumber3,newSystemPrimary3)
     values
     <foreach collection="list" item="entity" separator=",">
-        (#{entity.id},#{entity.newpushdate3},#{entity.newtransmitinfo3},#{entity.newstate3},#{entity.newsystemnumber3},#{entity.newSystemPrimary3})
+        (#{entity.id},#{entity.newpushdate3},#{entity.newtransmitinfo3},#{entity.newstate3},#{entity.newsystemnumber3},#{entity.newsystemprimary3})
     </foreach>
     on duplicate key update
     id = values(id),
diff --git a/buildpackage/src/main/java/com/hzya/frame/plugin/lets/plugin/sales/SoSaleReturnPluginInitializerToC.java b/buildpackage/src/main/java/com/hzya/frame/plugin/lets/plugin/sales/SoSaleReturnPluginInitializerToC.java
index 5ee97c2d..a1f25ab0 100644
--- a/buildpackage/src/main/java/com/hzya/frame/plugin/lets/plugin/sales/SoSaleReturnPluginInitializerToC.java
+++ b/buildpackage/src/main/java/com/hzya/frame/plugin/lets/plugin/sales/SoSaleReturnPluginInitializerToC.java
@@ -962,12 +962,12 @@ public class SoSaleReturnPluginInitializerToC extends PluginBaseEntity {
         if (returnGoodHeaderDetailsDataDtoList1 != null && returnGoodHeaderDetailsDataDtoList1.size() > 0) {
             try {
                 //初始化档案缓存
-                CacheTocMapVoV2 cacheTocMapVoV2 = tocReturnBasicArchivesCacheUtil.initCache();
+                CacheTocMapVoV2 cacheTocMapVoV2 = tocReturnBasicArchivesCacheUtil.initCache(returnGoodHeaderDetailsDataDtoList1);
                 //查询OFS售后入库单对应的售后订单
                 List<RerturnGoodsOrderSearchData> rerturnGoodsOrderSearchData = queryBatchAfterSalesOrder(returnGoodHeaderDetailsDataDtoList1);
                 findAfterSalesOrder(rerturnGoodsOrderSearchData, returnGoodHeaderDetailsDataDtoList1);
                 //查询OFS售后订单对应的OFS销售订单
-                List<com.hzya.frame.ttxofs.dto.ofssalesordersearch.HeaderDetailsDto> headerDetailsDtos = queryBatchOfsOrder(rerturnGoodsOrderSearchData);
+                List<com.hzya.frame.ttxofs.dto.ofssalesordersearch.HeaderDetailsDto> headerDetailsDtos = queryBatchOfsOrder(returnGoodHeaderDetailsDataDtoList1);
                 findOfsOrder(headerDetailsDtos, returnGoodHeaderDetailsDataDtoList1);
 
                 for (int i = 0; i < returnGoodHeaderDetailsDataDtoList1.size(); i++) {
@@ -994,6 +994,8 @@ public class SoSaleReturnPluginInitializerToC extends PluginBaseEntity {
 
                         //表头公司:通过名称匹配U8C公司
 //                    String corpName = "上海丽知品牌管理有限公司";
+                        //TODO 测试SHOF
+                        header.setCompanyCode("SHOF");
                         Assert.notNull(header.getCompanyCode(), "O货主编码不能为空");
                         BdCorpEntity bdCorpEntity = cacheTocMapVoV2.getStringBdCorpEntityMap().get(header.getCompanyCode());
                         Assert.notNull(bdCorpEntity, "根据O公司编码(货主编码)({})没有匹配到U8C公司档案", header.getCompanyCode());
@@ -1058,8 +1060,8 @@ public class SoSaleReturnPluginInitializerToC extends PluginBaseEntity {
                             BdInvmandocEntity bdInvmandocEntity = cacheTocMapVoV2.getStringBdInvmandocEntityMap().get(stockinB.getSkuCode() + bdCorpEntity.getPkCorp());
                             Assert.notNull(bdInvmandocEntity, "无法匹配到存货管理档案 货品sku:{} 公司:{}", stockinB.getSkuCode(), bdCorpEntity.getPkCorp());
                             //存货基本档案
-                            BdInvbasdocEntity bdInvbasdocEntity = cacheTocMapVoV2.getStringBdInvbasdocEntityMap().get(bdInvmandocEntity.getPkInvmandoc() + bdCorpEntity.getPkCorp());
-                            Assert.notNull(bdInvbasdocEntity, "无法匹配到存货基本档案 存货管理主键:{} 公司:{}", bdInvmandocEntity.getPkInvmandoc(), bdCorpEntity.getPkCorp());
+                            BdInvbasdocEntity bdInvbasdocEntity = cacheTocMapVoV2.getStringBdInvbasdocEntityMap().get(stockinB.getSkuCode());
+                            Assert.notNull(bdInvbasdocEntity, "无法匹配到存货基本档案 存货编码:{}", stockinB.getSkuCode());
                             //存货税率
                             BdTaxitemsEntity bdTaxitemsEntity = cacheTocMapVoV2.getStringBdTaxitemsEntityMap().get(bdInvmandocEntity.getInvcode());
                             Assert.notNull(bdTaxitemsEntity, "无法匹配到存货税率 存货编码:{}", bdInvmandocEntity.getInvcode());
@@ -1557,7 +1559,7 @@ public class SoSaleReturnPluginInitializerToC extends PluginBaseEntity {
                         RerturnGoodsOrderSearchData rerturnGoodsOrderSearchData = rerturnGoodsOrderSearchDataList.get(j);
                         RerturnGoodsOrderSearchHeader header1 = rerturnGoodsOrderSearchData.getHeader();
                         List<RerturnGoodsOrderSearchDetails> details1 = rerturnGoodsOrderSearchData.getDetails();
-                        if (header.getId().equals(header1.getRefOrderId())) {
+                        if (header.getRefOrderId().equals(header1.getId())) {
                             header.setRerturnGoodsOrderSearchData(rerturnGoodsOrderSearchData);
                         }
                     }
@@ -1599,25 +1601,31 @@ public class SoSaleReturnPluginInitializerToC extends PluginBaseEntity {
     /**
      * 通过售后订单,匹配OFS销售订单
      *
+     * @param returnGoodHeaderDetailsDataDtoList1 OFS售后入库单集合
      * @author liuyang
      */
-    private List<com.hzya.frame.ttxofs.dto.ofssalesordersearch.HeaderDetailsDto> queryBatchOfsOrder(List<RerturnGoodsOrderSearchData> rerturnGoodsOrderSearchData) throws Exception {
+    private List<com.hzya.frame.ttxofs.dto.ofssalesordersearch.HeaderDetailsDto> queryBatchOfsOrder(List<StockinOrderSearchResponse.StockinOrder> returnGoodHeaderDetailsDataDtoList1) throws Exception {
         List<com.hzya.frame.ttxofs.dto.ofssalesordersearch.HeaderDetailsDto> headerDetailsDtoArrayList = new ArrayList<>();
 
-        if (rerturnGoodsOrderSearchData != null && rerturnGoodsOrderSearchData.size() > 0) {
+        if (returnGoodHeaderDetailsDataDtoList1 != null && returnGoodHeaderDetailsDataDtoList1.size() > 0) {
             try {
                 //每50个作为一批,拆分
-                List<List<RerturnGoodsOrderSearchData>> lists = SplitListByCountUtil.splitListByCount(rerturnGoodsOrderSearchData, 50);
-                for (int i = 0; i < lists.size(); i++) {
-                    List<RerturnGoodsOrderSearchData> rerturnGoodsOrderSearchData1 = lists.get(i);
-                    StringBuffer codes = new StringBuffer();
-                    for (int j = 0; j < rerturnGoodsOrderSearchData.size(); j++) {
-                        RerturnGoodsOrderSearchData rerturnGoodsOrderSearchData2 = rerturnGoodsOrderSearchData.get(j);
-                        RerturnGoodsOrderSearchHeader header = rerturnGoodsOrderSearchData2.getHeader();
-                        List<RerturnGoodsOrderSearchDetails> details = rerturnGoodsOrderSearchData2.getDetails();
+                List<List<StockinOrderSearchResponse.StockinOrder>> splitListByCount = SplitListByCountUtil.splitListByCount(returnGoodHeaderDetailsDataDtoList1, 50);
+                for (int i = 0; i < splitListByCount.size(); i++) {
+                    List<StockinOrderSearchResponse.StockinOrder> stockinOrderList = splitListByCount.get(i);
 
-                        codes.append(header.getCode());
-                        codes.append(",");
+                    StringBuffer codes = new StringBuffer();
+                    for (int j = 0; j < stockinOrderList.size(); j++) {
+                        StockinOrderSearchResponse.StockinOrder stockinOrder = stockinOrderList.get(j);
+                        StockinOrderSearchResponse.StockinOrder.StockinH header = stockinOrder.getHeader();
+                        List<StockinOrderSearchResponse.StockinOrder.StockinB> details = stockinOrder.getDetails();
+                        RerturnGoodsOrderSearchData rerturnGoodsOrderSearchData1 = header.getRerturnGoodsOrderSearchData();//OFS售后订单
+                        if (rerturnGoodsOrderSearchData1 != null) {
+                            RerturnGoodsOrderSearchHeader header1 = rerturnGoodsOrderSearchData1.getHeader();
+                            List<RerturnGoodsOrderSearchDetails> details1 = rerturnGoodsOrderSearchData1.getDetails();
+                            codes.append(header1.getRefOrderCode());
+                            codes.append(",");
+                        }
                     }
                     String codesStr = codes.substring(0, codes.length() - 1);
 
diff --git a/buildpackage/src/main/java/com/hzya/frame/plugin/lets/util/TocOrderBasicArchivesCacheUtil.java b/buildpackage/src/main/java/com/hzya/frame/plugin/lets/util/TocOrderBasicArchivesCacheUtil.java
index 507a9e3f..c46194cc 100644
--- a/buildpackage/src/main/java/com/hzya/frame/plugin/lets/util/TocOrderBasicArchivesCacheUtil.java
+++ b/buildpackage/src/main/java/com/hzya/frame/plugin/lets/util/TocOrderBasicArchivesCacheUtil.java
@@ -1,5 +1,6 @@
 package com.hzya.frame.plugin.lets.util;
 
+import cn.hutool.core.lang.Assert;
 import com.hzya.frame.plugin.lets.constant.OverallConstant;
 import com.hzya.frame.plugin.lets.dao.*;
 import com.hzya.frame.plugin.lets.entity.*;
@@ -508,9 +509,12 @@ public class TocOrderBasicArchivesCacheUtil {
     /**
      * 初始化缓存
      *
+     * @param headerDetailsDtoList OFS销售出库单对象
      * @author liuyang
      */
     public CacheTocMapVo initCache(List<com.hzya.frame.ttxofs.dto.ofssaleorderoutsearch.HeaderDetailsDto> headerDetailsDtoList) throws Exception {
+        Assert.notNull(headerDetailsDtoList, "headerDetailsDtoList不能为空!");
+
 //        clearCache();
         List<DetailsDto> detailsDtos = initOfsDetailsDto(headerDetailsDtoList);
         List<HeaderDto> headerDtoList = initOFsHeadDto(headerDetailsDtoList);
diff --git a/buildpackage/src/main/java/com/hzya/frame/plugin/lets/util/TocReturnBasicArchivesCacheUtil.java b/buildpackage/src/main/java/com/hzya/frame/plugin/lets/util/TocReturnBasicArchivesCacheUtil.java
index 2987f6b2..20fa0535 100644
--- a/buildpackage/src/main/java/com/hzya/frame/plugin/lets/util/TocReturnBasicArchivesCacheUtil.java
+++ b/buildpackage/src/main/java/com/hzya/frame/plugin/lets/util/TocReturnBasicArchivesCacheUtil.java
@@ -1,14 +1,22 @@
 package com.hzya.frame.plugin.lets.util;
 
+import cn.hutool.core.lang.Assert;
+import com.hzya.frame.plugin.lets.constant.OverallConstant;
 import com.hzya.frame.plugin.lets.dao.*;
 import com.hzya.frame.plugin.lets.entity.*;
 import com.hzya.frame.plugin.lets.resultvo.CacheTocMapVoV2;
+import com.hzya.frame.split.SplitListByCountUtil;
+import com.hzya.frame.ttxofs.dto.ofssaleorderoutsearch.DetailsDto;
+import com.hzya.frame.ttxofs.dto.ofssaleorderoutsearch.HeaderDto;
+import com.hzya.frame.ttxofs.dto.stock.StockinOrderSearchResponse;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.stream.Collectors;
 
 /**
  * 档案类缓存,TOC销售订单转换
@@ -169,20 +177,45 @@ public class TocReturnBasicArchivesCacheUtil {
      * @author liuyang
      */
 //    public static Map<String, BdCubasdocEntity> stringBdCubasdocEntityHashMap = new HashMap<>();
-    private Map<String, BdCubasdocEntity> initBdCubasdoc() {
-        Map<String, BdCubasdocEntity> stringBdCubasdocEntityHashMap = new HashMap<>();
+//    private Map<String, BdCubasdocEntity> initBdCubasdoc() {
+//        Map<String, BdCubasdocEntity> stringBdCubasdocEntityHashMap = new HashMap<>();
+//
+//        BdCubasdocEntity bdCubasdocEntity = new BdCubasdocEntity();
+//        bdCubasdocEntity.setDataSourceCode("lets_u8c");
+//        bdCubasdocEntity.setDr(0L);
+//        List<BdCubasdocEntity> bdCumandocEntityList = iBdCubasdocDao.query(bdCubasdocEntity);
+//        if (bdCumandocEntityList != null && bdCumandocEntityList.size() > 0) {
+//            for (int i = 0; i < bdCumandocEntityList.size(); i++) {
+//                BdCubasdocEntity bdCubasdocEntity1 = bdCumandocEntityList.get(i);
+//                stringBdCubasdocEntityHashMap.put(bdCubasdocEntity1.getCustname(), bdCubasdocEntity1);
+//            }
+//        }
+//        return stringBdCubasdocEntityHashMap;
+//    }
+    private Map<String, BdCubasdocEntity> initBdCubasdocV2(List<StockinOrderSearchResponse.StockinOrder.StockinH> headerDtoList) {
+        Map<String, BdCubasdocEntity> stringBdCubasdocEntityMap = new HashMap<>();
+        List<BdCubasdocEntity> allBdCumandocEntityList = new ArrayList<>();
+        if (headerDtoList != null && headerDtoList.size() > 0) {
+            List<List<StockinOrderSearchResponse.StockinOrder.StockinH>> lists = SplitListByCountUtil.splitListByCount(headerDtoList, 500);
+            for (int i = 0; i < lists.size(); i++) {
+                List<StockinOrderSearchResponse.StockinOrder.StockinH> stockinHList = lists.get(i);
+                String codesStr = stockinHList.stream().map(StockinOrderSearchResponse.StockinOrder.StockinH::getStoreCode).map(id -> "'" + id + "'").collect(Collectors.joining(","));
 
-        BdCubasdocEntity bdCubasdocEntity = new BdCubasdocEntity();
-        bdCubasdocEntity.setDataSourceCode("lets_u8c");
-        bdCubasdocEntity.setDr(0L);
-        List<BdCubasdocEntity> bdCumandocEntityList = iBdCubasdocDao.query(bdCubasdocEntity);
-        if (bdCumandocEntityList != null && bdCumandocEntityList.size() > 0) {
-            for (int i = 0; i < bdCumandocEntityList.size(); i++) {
-                BdCubasdocEntity bdCubasdocEntity1 = bdCumandocEntityList.get(i);
-                stringBdCubasdocEntityHashMap.put(bdCubasdocEntity1.getCustname(), bdCubasdocEntity1);
+                BdCubasdocEntity bdCubasdocEntity = new BdCubasdocEntity();
+                bdCubasdocEntity.setDataSourceCode("lets_u8c");
+                bdCubasdocEntity.setDr(0L);
+                bdCubasdocEntity.setCustcodes(codesStr);
+                List<BdCubasdocEntity> bdCumandocEntityList = iBdCubasdocDao.query(bdCubasdocEntity);
+                allBdCumandocEntityList.addAll(bdCumandocEntityList);
             }
         }
-        return stringBdCubasdocEntityHashMap;
+        if (allBdCumandocEntityList.size() > 0) {
+            for (int i = 0; i < allBdCumandocEntityList.size(); i++) {
+                BdCubasdocEntity bdCubasdocEntity = allBdCumandocEntityList.get(i);
+                stringBdCubasdocEntityMap.put(bdCubasdocEntity.getCustcode(), bdCubasdocEntity);
+            }
+        }
+        return stringBdCubasdocEntityMap;
     }
 
     /**
@@ -191,17 +224,49 @@ public class TocReturnBasicArchivesCacheUtil {
      * @author liuyang
      */
 //    public static Map<String, BdCumandocEntity> stringBdCumandocEntityMap = new HashMap<>();
-    private Map<String, BdCumandocEntity> initBdCumandoc() {
-        Map<String, BdCumandocEntity> stringBdCumandocEntityMap = new HashMap<>();
+//    private Map<String, BdCumandocEntity> initBdCumandoc() {
+//        Map<String, BdCumandocEntity> stringBdCumandocEntityMap = new HashMap<>();
+//
+//        BdCumandocEntity bdCumandocEntity1 = new BdCumandocEntity();
+//        bdCumandocEntity1.setDataSourceCode("lets_u8c");
+//        bdCumandocEntity1.setDr(0L);
+////        bdCumandocEntity1.setCustflags(ProfilesActiveConstant.CUSTOMER);//客商:2客户
+//        List<BdCumandocEntity> bdCumandocEntityList = iBdCumandocDao.query(bdCumandocEntity1);
+//        if (bdCumandocEntityList != null && bdCumandocEntityList.size() > 0) {
+//            for (int i = 0; i < bdCumandocEntityList.size(); i++) {
+//                BdCumandocEntity bdCumandocEntity = bdCumandocEntityList.get(i);
+//                stringBdCumandocEntityMap.put(bdCumandocEntity.getPkCubasdoc() + bdCumandocEntity.getPkCorp(), bdCumandocEntity);
+//            }
+//        }
+//        return stringBdCumandocEntityMap;
+//    }
 
-        BdCumandocEntity bdCumandocEntity1 = new BdCumandocEntity();
-        bdCumandocEntity1.setDataSourceCode("lets_u8c");
-        bdCumandocEntity1.setDr(0L);
-//        bdCumandocEntity1.setCustflags(ProfilesActiveConstant.CUSTOMER);//客商:2客户
-        List<BdCumandocEntity> bdCumandocEntityList = iBdCumandocDao.query(bdCumandocEntity1);
-        if (bdCumandocEntityList != null && bdCumandocEntityList.size() > 0) {
-            for (int i = 0; i < bdCumandocEntityList.size(); i++) {
-                BdCumandocEntity bdCumandocEntity = bdCumandocEntityList.get(i);
+    /**
+     * 查询客商管理档案
+     *
+     * @author liuyang
+     */
+    private Map<String, BdCumandocEntity> initBdCumandocV2(List<StockinOrderSearchResponse.StockinOrder.StockinH> headerDtoList) throws Exception {
+        Map<String, BdCumandocEntity> stringBdCumandocEntityMap = new HashMap<>();
+        List<BdCumandocEntity> allBdCumandocEntityList = new ArrayList<>();
+
+        if (headerDtoList != null && headerDtoList.size() > 0) {
+            List<List<StockinOrderSearchResponse.StockinOrder.StockinH>> lists = SplitListByCountUtil.splitListByCount(headerDtoList, 500);
+            for (int i = 0; i < lists.size(); i++) {
+                List<StockinOrderSearchResponse.StockinOrder.StockinH> stockinHList = lists.get(i);
+                String codesStr = stockinHList.stream().map(StockinOrderSearchResponse.StockinOrder.StockinH::getStoreCode).map(id -> "'" + id + "'").collect(Collectors.joining(","));
+
+                BdCumandocEntity bdCumandocEntity = new BdCumandocEntity();
+                bdCumandocEntity.setDataSourceCode("lets_u8c");
+                bdCumandocEntity.setDr(0L);
+                bdCumandocEntity.setCustcodes(codesStr);
+                List<BdCumandocEntity> bdCumandocEntityList = iBdCumandocDao.query(bdCumandocEntity);
+                allBdCumandocEntityList.addAll(bdCumandocEntityList);
+            }
+        }
+        if (allBdCumandocEntityList.size() > 0) {
+            for (int i = 0; i < allBdCumandocEntityList.size(); i++) {
+                BdCumandocEntity bdCumandocEntity = allBdCumandocEntityList.get(i);
                 stringBdCumandocEntityMap.put(bdCumandocEntity.getPkCubasdoc() + bdCumandocEntity.getPkCorp(), bdCumandocEntity);
             }
         }
@@ -212,18 +277,42 @@ public class TocReturnBasicArchivesCacheUtil {
      * 初始化存货管理档案
      */
 //    public static Map<String, BdInvmandocEntity> stringBdInvmandocEntityMap = new HashMap<>();
-    private Map<String, BdInvmandocEntity> initInventoryFile() throws Exception {
+//    private Map<String, BdInvmandocEntity> initInventoryFile() throws Exception {
+//        Map<String, BdInvmandocEntity> stringBdInvmandocEntityMap = new HashMap<>();
+//
+//        BdInvmandocEntity bdInvmandocEntity = new BdInvmandocEntity();
+////        bdInvmandocEntity.setInvcode(copyRowDetailsListVo.getSpec_no());
+////        bdInvmandocEntity.setPkCorp(shippingCompanyBdCorpEntity.getPkCorp());
+//        List<BdInvmandocEntity> bdInvmandocEntity2 = iBdInvmandocDao.queryBdInvmandocByInvcodeList(bdInvmandocEntity);
+//        if (bdInvmandocEntity2 != null && bdInvmandocEntity2.size() > 0) {
+//            for (int i = 0; i < bdInvmandocEntity2.size(); i++) {
+//                BdInvmandocEntity bdInvmandocEntity1 = bdInvmandocEntity2.get(i);
+//                //2024年8月6日 14:27:45 通过存货编码+公司缓存
+//                stringBdInvmandocEntityMap.put(bdInvmandocEntity1.getInvcode() + bdInvmandocEntity1.getPkCorp(), bdInvmandocEntity1);
+//            }
+//        }
+//        return stringBdInvmandocEntityMap;
+//    }
+    public Map<String, BdInvmandocEntity> initInventoryFileV2(List<StockinOrderSearchResponse.StockinOrder.StockinB> detailsDtos) throws Exception {
+        List<BdInvmandocEntity> allBdInvmandocEntity = new ArrayList<>();
         Map<String, BdInvmandocEntity> stringBdInvmandocEntityMap = new HashMap<>();
 
-        BdInvmandocEntity bdInvmandocEntity = new BdInvmandocEntity();
-//        bdInvmandocEntity.setInvcode(copyRowDetailsListVo.getSpec_no());
-//        bdInvmandocEntity.setPkCorp(shippingCompanyBdCorpEntity.getPkCorp());
-        List<BdInvmandocEntity> bdInvmandocEntity2 = iBdInvmandocDao.queryBdInvmandocByInvcodeList(bdInvmandocEntity);
-        if (bdInvmandocEntity2 != null && bdInvmandocEntity2.size() > 0) {
-            for (int i = 0; i < bdInvmandocEntity2.size(); i++) {
-                BdInvmandocEntity bdInvmandocEntity1 = bdInvmandocEntity2.get(i);
-                //2024年8月6日 14:27:45 通过存货编码+公司缓存
-                stringBdInvmandocEntityMap.put(bdInvmandocEntity1.getInvcode() + bdInvmandocEntity1.getPkCorp(), bdInvmandocEntity1);
+        if (detailsDtos != null && detailsDtos.size() > 0) {
+            List<List<StockinOrderSearchResponse.StockinOrder.StockinB>> lists = SplitListByCountUtil.splitListByCount(detailsDtos, 500);
+            for (int i = 0; i < lists.size(); i++) {
+                List<StockinOrderSearchResponse.StockinOrder.StockinB> stockinBList = lists.get(i);
+                String idsStr = stockinBList.stream().map(StockinOrderSearchResponse.StockinOrder.StockinB::getSkuCode).map(id -> "'" + id + "'").collect(Collectors.joining(","));
+
+                BdInvmandocEntity bdInvmandocEntity = new BdInvmandocEntity();
+                bdInvmandocEntity.setInvcodes(idsStr);
+                List<BdInvmandocEntity> bdInvmandocEntity2 = iBdInvmandocDao.queryBdInvmandocByInvcodeList(bdInvmandocEntity);
+                allBdInvmandocEntity.addAll(bdInvmandocEntity2);
+            }
+        }
+        if (allBdInvmandocEntity.size() > 0) {
+            for (int i = 0; i < allBdInvmandocEntity.size(); i++) {
+                BdInvmandocEntity bdInvmandocEntity = allBdInvmandocEntity.get(i);
+                stringBdInvmandocEntityMap.put(bdInvmandocEntity.getInvcode() + bdInvmandocEntity.getPkCorp(), bdInvmandocEntity);
             }
         }
         return stringBdInvmandocEntityMap;
@@ -234,20 +323,47 @@ public class TocReturnBasicArchivesCacheUtil {
      * 2024年8月7日 10:57:55
      */
 //    public static Map<String, BdInvbasdocEntity> stringBdInvbasdocEntityHashMap = new HashMap<>();
-    private Map<String, BdInvbasdocEntity> initBasicInventoryFile() throws Exception {
-        Map<String, BdInvbasdocEntity> stringBdInvbasdocEntityHashMap = new HashMap<>();
+//    private Map<String, BdInvbasdocEntity> initBasicInventoryFile() throws Exception {
+//        Map<String, BdInvbasdocEntity> stringBdInvbasdocEntityHashMap = new HashMap<>();
+//
+//        BdInvbasdocEntity bdInvbasdocEntity = new BdInvbasdocEntity();
+////        bdInvbasdocEntity.setPk_invmandoc(bdInvmandocEntity1.getPkInvmandoc());
+////        bdInvbasdocEntity.setPk_corp(shippingCompanyBdCorpEntity.getPkCorp());
+//        List<BdInvbasdocEntity> bdInvbasdocEntity2 = iBdInvbasdocDao.queryBdInvbasdocByPkInvmandocV2(bdInvbasdocEntity);
+//        if (bdInvbasdocEntity2 != null && bdInvbasdocEntity2.size() > 0) {
+//            for (int i = 0; i < bdInvbasdocEntity2.size(); i++) {
+//                BdInvbasdocEntity bdInvbasdocEntity1 = bdInvbasdocEntity2.get(i);
+//                stringBdInvbasdocEntityHashMap.put(bdInvbasdocEntity1.getPk_invmandoc() + bdInvbasdocEntity1.getPk_corp_man(), bdInvbasdocEntity1);
+//            }
+//        }
+//        return stringBdInvbasdocEntityHashMap;
+//    }
 
-        BdInvbasdocEntity bdInvbasdocEntity = new BdInvbasdocEntity();
-//        bdInvbasdocEntity.setPk_invmandoc(bdInvmandocEntity1.getPkInvmandoc());
-//        bdInvbasdocEntity.setPk_corp(shippingCompanyBdCorpEntity.getPkCorp());
-        List<BdInvbasdocEntity> bdInvbasdocEntity2 = iBdInvbasdocDao.queryBdInvbasdocByPkInvmandocV2(bdInvbasdocEntity);
-        if (bdInvbasdocEntity2 != null && bdInvbasdocEntity2.size() > 0) {
-            for (int i = 0; i < bdInvbasdocEntity2.size(); i++) {
-                BdInvbasdocEntity bdInvbasdocEntity1 = bdInvbasdocEntity2.get(i);
-                stringBdInvbasdocEntityHashMap.put(bdInvbasdocEntity1.getPk_invmandoc() + bdInvbasdocEntity1.getPk_corp_man(), bdInvbasdocEntity1);
+    /**
+     * 根据O存货商家编码初始化存货基本档案
+     *
+     * @author liuyang
+     */
+    private Map<String, BdInvbasdocEntity> initBasicInventoryFileV2(List<StockinOrderSearchResponse.StockinOrder.StockinB> detailsDtoList) throws Exception {
+        List<BdInvbasdocEntity> allBdInvbasdocEntityList = new ArrayList<>();
+        if (detailsDtoList != null && detailsDtoList.size() > 0) {
+            List<List<StockinOrderSearchResponse.StockinOrder.StockinB>> lists = SplitListByCountUtil.splitListByCount(detailsDtoList, 500);
+            for (int i = 0; i < lists.size(); i++) {
+                List<StockinOrderSearchResponse.StockinOrder.StockinB> stockinBList = lists.get(i);
+                String idsStr = stockinBList.stream().map(StockinOrderSearchResponse.StockinOrder.StockinB::getSkuCode).map(id -> "'" + id + "'").collect(Collectors.joining(","));
+
+                BdInvbasdocEntity bdInvbasdocEntity = new BdInvbasdocEntity();
+                bdInvbasdocEntity.setInvcodes(idsStr);
+                List<BdInvbasdocEntity> bdInvbasdocEntities = iBdInvbasdocDao.queryBdInvbasdocByPkInvmandocV3(bdInvbasdocEntity);
+                allBdInvbasdocEntityList.addAll(bdInvbasdocEntities);
             }
         }
-        return stringBdInvbasdocEntityHashMap;
+        Map<String, BdInvbasdocEntity> stringBdInvbasdocEntityMap = new HashMap<>();
+        for (int i = 0; i < allBdInvbasdocEntityList.size(); i++) {
+            BdInvbasdocEntity bdInvbasdocEntity = allBdInvbasdocEntityList.get(i);
+            stringBdInvbasdocEntityMap.put(bdInvbasdocEntity.getInvcode(), bdInvbasdocEntity);
+        }
+        return stringBdInvbasdocEntityMap;
     }
 
     /**
@@ -257,18 +373,41 @@ public class TocReturnBasicArchivesCacheUtil {
      * @author liuyang
      */
 //    public static Map<String, BdTaxitemsEntity> stringBdTaxitemsEntityHashMap = new HashMap<>();
-    private Map<String, BdTaxitemsEntity> initBdTaxitemsEntity() throws Exception {
-        Map<String, BdTaxitemsEntity> stringBdTaxitemsEntityHashMap = new HashMap<>();
+//    private Map<String, BdTaxitemsEntity> initBdTaxitemsEntity() throws Exception {
+//        Map<String, BdTaxitemsEntity> stringBdTaxitemsEntityHashMap = new HashMap<>();
+//
+//        BdTaxitemsEntity bdTaxitemsEntity = new BdTaxitemsEntity();
+//        List<BdTaxitemsEntity> bdTaxitemsEntityList = iBdTaxitemsDao.queryBdInvbasdocByInvcodeV2(bdTaxitemsEntity);
+//        if (bdTaxitemsEntityList != null && bdTaxitemsEntityList.size() > 0) {
+//            for (int i = 0; i < bdTaxitemsEntityList.size(); i++) {
+//                BdTaxitemsEntity bdTaxitemsEntity1 = bdTaxitemsEntityList.get(i);
+//                stringBdTaxitemsEntityHashMap.put(bdTaxitemsEntity1.getInvcode(), bdTaxitemsEntity1);
+//            }
+//        }
+//        return stringBdTaxitemsEntityHashMap;
+//    }
+    private Map<String, BdTaxitemsEntity> initBdTaxitemsEntityV2(List<StockinOrderSearchResponse.StockinOrder.StockinB> detailsDtos) throws Exception {
+        List<BdTaxitemsEntity> allBdTaxitemsEntityList = new ArrayList<>();
+        Map<String, BdTaxitemsEntity> stringBdTaxitemsEntityMap = new HashMap<>();
+        if (detailsDtos != null && detailsDtos.size() > 0) {
+            List<List<StockinOrderSearchResponse.StockinOrder.StockinB>> lists = SplitListByCountUtil.splitListByCount(detailsDtos, 500);
+            for (int i = 0; i < lists.size(); i++) {
+                List<StockinOrderSearchResponse.StockinOrder.StockinB> stockinBList = lists.get(i);
+                String codesStr = stockinBList.stream().map(StockinOrderSearchResponse.StockinOrder.StockinB::getSkuCode).map(id -> "'" + id + "'").collect(Collectors.joining(","));
 
-        BdTaxitemsEntity bdTaxitemsEntity = new BdTaxitemsEntity();
-        List<BdTaxitemsEntity> bdTaxitemsEntityList = iBdTaxitemsDao.queryBdInvbasdocByInvcodeV2(bdTaxitemsEntity);
-        if (bdTaxitemsEntityList != null && bdTaxitemsEntityList.size() > 0) {
-            for (int i = 0; i < bdTaxitemsEntityList.size(); i++) {
-                BdTaxitemsEntity bdTaxitemsEntity1 = bdTaxitemsEntityList.get(i);
-                stringBdTaxitemsEntityHashMap.put(bdTaxitemsEntity1.getInvcode(), bdTaxitemsEntity1);
+                BdTaxitemsEntity bdTaxitemsEntity = new BdTaxitemsEntity();
+                bdTaxitemsEntity.setInvcodes(codesStr);
+                List<BdTaxitemsEntity> bdTaxitemsEntityList = iBdTaxitemsDao.queryBdInvbasdocByInvcodeV2(bdTaxitemsEntity);
+                allBdTaxitemsEntityList.addAll(bdTaxitemsEntityList);
             }
         }
-        return stringBdTaxitemsEntityHashMap;
+        if (allBdTaxitemsEntityList.size() > 0) {
+            for (int i = 0; i < allBdTaxitemsEntityList.size(); i++) {
+                BdTaxitemsEntity bdTaxitemsEntity = allBdTaxitemsEntityList.get(i);
+                stringBdTaxitemsEntityMap.put(bdTaxitemsEntity.getInvcode(), bdTaxitemsEntity);
+            }
+        }
+        return stringBdTaxitemsEntityMap;
     }
 
     /**
@@ -280,8 +419,10 @@ public class TocReturnBasicArchivesCacheUtil {
     private Map<String, BdDefdocEntity> initSourcePlatform() {
         Map<String, BdDefdocEntity> stringBdDefdocEntityHashMap = new HashMap<>();
 
+        String platformZdyId2 = OverallConstant.getOverAllValue("u8c自定义项档案-平台主键");
         BdDefdocEntity bdDefdocEntity = new BdDefdocEntity();
-        bdDefdocEntity.setPkDefdoclist("0001A210000000000JUD");
+//        bdDefdocEntity.setPkDefdoclist("0001A210000000000JUD");
+        bdDefdocEntity.setPkDefdoclist(platformZdyId2);
         bdDefdocEntity.setDr(0);
         bdDefdocEntity.setDataSourceCode("lets_u8c");
         List<BdDefdocEntity> bdDefdocEntityList = iBdDefdocDao.query(bdDefdocEntity);
@@ -301,8 +442,10 @@ public class TocReturnBasicArchivesCacheUtil {
     private Map<String, BdDefdocEntity> initShopDiy() {
         Map<String, BdDefdocEntity> shopDefdocEntityHashMap = new HashMap<>();
 
+        String platformZdyId2 = OverallConstant.getOverAllValue("u8c自定义项档案-店铺主键");
         BdDefdocEntity bdDefdocEntity = new BdDefdocEntity();
-        bdDefdocEntity.setPkDefdoclist("0001A210000000000XZX");
+//        bdDefdocEntity.setPkDefdoclist("0001A210000000000XZX");
+        bdDefdocEntity.setPkDefdoclist(platformZdyId2);
         bdDefdocEntity.setDr(0);
         bdDefdocEntity.setDataSourceCode("lets_u8c");
         List<BdDefdocEntity> bdDefdocEntityList = iBdDefdocDao.query(bdDefdocEntity);
@@ -360,20 +503,26 @@ public class TocReturnBasicArchivesCacheUtil {
     /**
      * 初始化缓存
      *
+     * @param returnGoodHeaderDetailsDataDtoList OFS售后入库单
      * @author liuyang
      */
-    public CacheTocMapVoV2 initCache() throws Exception {
+    public CacheTocMapVoV2 initCache(List<StockinOrderSearchResponse.StockinOrder> returnGoodHeaderDetailsDataDtoList) throws Exception {
+        Assert.notNull(returnGoodHeaderDetailsDataDtoList, "returnGoodHeaderDetailsDataDtoList不能为空!");
+
+        List<StockinOrderSearchResponse.StockinOrder.StockinB> stockinBList = initOfsDetailsDto(returnGoodHeaderDetailsDataDtoList);
+        List<StockinOrderSearchResponse.StockinOrder.StockinH> stockinHList = initOFsHeadDto(returnGoodHeaderDetailsDataDtoList);
+
 //        clearCache();
         Map<String, BdCorpEntity> stringBdCorpEntityMap = initShop();
         Map<String, BdStordocEntity> stringBdStordocEntityMap = initBdStordoc();
         Map<String, BdCalbodyEntity> stringBdCalbodyEntityMap = initBdCalbody();
         Map<String, BdSalestruEntity> stringBdSalestruEntityMap = initBdSalestru();
         Map<String, BdDeptdocEntity> stringBdDeptdocEntityMap = initDept();
-        Map<String, BdCubasdocEntity> stringBdCubasdocEntityMap = initBdCubasdoc();
-        Map<String, BdCumandocEntity> stringBdCumandocEntityMap = initBdCumandoc();
-        Map<String, BdInvmandocEntity> stringBdInvmandocEntityMap = initInventoryFile();
-        Map<String, BdInvbasdocEntity> stringBdInvbasdocEntityMap = initBasicInventoryFile();
-        Map<String, BdTaxitemsEntity> stringBdTaxitemsEntityMap = initBdTaxitemsEntity();
+        Map<String, BdCubasdocEntity> stringBdCubasdocEntityMap = initBdCubasdocV2(stockinHList);
+        Map<String, BdCumandocEntity> stringBdCumandocEntityMap = initBdCumandocV2(stockinHList);
+        Map<String, BdInvmandocEntity> stringBdInvmandocEntityMap = initInventoryFileV2(stockinBList);
+        Map<String, BdInvbasdocEntity> stringBdInvbasdocEntityMap = initBasicInventoryFileV2(stockinBList);
+        Map<String, BdTaxitemsEntity> stringBdTaxitemsEntityMap = initBdTaxitemsEntityV2(stockinBList);
         Map<String, BdDefdocEntity> stringBdDefdocEntityMap = initSourcePlatform();
         Map<String, BdDefdocEntity> stringBdDefdocEntityMap1 = initShopDiy();
         Map<String, BdRdclEntity> stringBdRdclEntityMap = initBdRdcl();
@@ -394,4 +543,44 @@ public class TocReturnBasicArchivesCacheUtil {
         cacheTocMapVoV2.setStringBdRdclEntityMap(stringBdRdclEntityMap);
         return cacheTocMapVoV2;
     }
+
+    /**
+     * 整理出明细集合
+     *
+     * @author liuyang
+     */
+    private List<StockinOrderSearchResponse.StockinOrder.StockinB> initOfsDetailsDto(List<StockinOrderSearchResponse.StockinOrder> returnGoodHeaderDetailsDataDtoLis) {
+        List<StockinOrderSearchResponse.StockinOrder.StockinB> stockinBList = new ArrayList<>();
+
+        if (returnGoodHeaderDetailsDataDtoLis != null && returnGoodHeaderDetailsDataDtoLis.size() > 0) {
+            for (int i = 0; i < returnGoodHeaderDetailsDataDtoLis.size(); i++) {
+                StockinOrderSearchResponse.StockinOrder stockinOrder = returnGoodHeaderDetailsDataDtoLis.get(i);
+                StockinOrderSearchResponse.StockinOrder.StockinH header = stockinOrder.getHeader();
+                List<StockinOrderSearchResponse.StockinOrder.StockinB> details = stockinOrder.getDetails();
+
+                stockinBList.addAll(details);
+            }
+        }
+        return stockinBList;
+    }
+
+    /**
+     * 整理出表头集合
+     *
+     * @author liuyang
+     */
+    private List<StockinOrderSearchResponse.StockinOrder.StockinH> initOFsHeadDto(List<StockinOrderSearchResponse.StockinOrder> returnGoodHeaderDetailsDataDtoLis) throws Exception {
+        List<StockinOrderSearchResponse.StockinOrder.StockinH> stockinHList = new ArrayList<>();
+
+        if (returnGoodHeaderDetailsDataDtoLis != null && returnGoodHeaderDetailsDataDtoLis.size() > 0) {
+            for (int i = 0; i < returnGoodHeaderDetailsDataDtoLis.size(); i++) {
+                StockinOrderSearchResponse.StockinOrder stockinOrder = returnGoodHeaderDetailsDataDtoLis.get(i);
+                List<StockinOrderSearchResponse.StockinOrder.StockinB> details = stockinOrder.getDetails();
+                StockinOrderSearchResponse.StockinOrder.StockinH header = stockinOrder.getHeader();
+                stockinHList.add(header);
+            }
+        }
+
+        return stockinHList;
+    }
 }
\ No newline at end of file
diff --git a/buildpackage/src/test/java/com/hzya/frame/plugin/lets/plugin/sales/SoSaleReturnPluginInitializerToCTest.java b/buildpackage/src/test/java/com/hzya/frame/plugin/lets/plugin/sales/SoSaleReturnPluginInitializerToCTest.java
index 98313087..2a500cad 100644
--- a/buildpackage/src/test/java/com/hzya/frame/plugin/lets/plugin/sales/SoSaleReturnPluginInitializerToCTest.java
+++ b/buildpackage/src/test/java/com/hzya/frame/plugin/lets/plugin/sales/SoSaleReturnPluginInitializerToCTest.java
@@ -26,8 +26,8 @@ public class SoSaleReturnPluginInitializerToCTest {
     public void startImplement() {
 //        soSaleReturnPluginInitializerToC.startImplement(null, null);
         try {
-            String code = "LETS-RE2022080200000036";
-            soSaleReturnPluginInitializerToC.startImplementByCode(code, null);
+            String code = "LETS-RE2024091400000001";
+            soSaleReturnPluginInitializerToC.startImplementByCode(code, "tran");
         } catch (Exception e) {
             e.printStackTrace();
         }