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销售订单转换
 *
 * @Author：liuyang
 * @Package：com.hzya.frame.plugin.lets.util
 * @Project：kangarooDataCenterV3
 * @name：BasicArchivesCacheUtil
 * @Date：2024/7/31 11:27
 * @Filename：BasicArchivesCacheUtil
 */
@Component
public class TocReturnBasicArchivesCacheUtil {

    @Autowired
    private IBdCorpDao iBdCorpDao;

    @Autowired
    private IBdStordocDao iBdStordocDao;

    @Autowired
    private IBdCalbodyDao iBdCalbodyDao;

    @Autowired
    private IBdSalestruDao iBdSalestruDao;

    @Autowired
    private IBdDeptdocDao iBdDeptdocDao;

    @Autowired
    private IBdCumandocDao iBdCumandocDao;

    @Autowired
    private IBdInvmandocDao iBdInvmandocDao;

    @Autowired
    private IBdInvbasdocDao iBdInvbasdocDao;

    @Autowired
    private IBdTaxitemsDao iBdTaxitemsDao;

    @Autowired
    private IBdCubasdocDao iBdCubasdocDao;

    @Autowired
    private IBdDefdocDao iBdDefdocDao;

    @Autowired
    private IBdRdclDao iBdRdclDao;

//    public static  Map<String, BdCorpEntity> stringBdCorpEntityMap = new HashMap<>();

    /**
     * 初始化公司档案-表头公司
     * 2024年7月31日 11:16:23
     */
    private Map<String, BdCorpEntity> initShop() throws Exception {
        Map<String, BdCorpEntity> stringBdCorpEntityMap = new HashMap<>();
        BdCorpEntity bdCorpEntity = new BdCorpEntity();
        bdCorpEntity.setDr(0);
        bdCorpEntity.setDataSourceCode("lets_u8c");
        List<BdCorpEntity> bdCorpEntityList = iBdCorpDao.query(bdCorpEntity);
        if (bdCorpEntityList != null && bdCorpEntityList.size() > 0) {
            for (int i = 0; i < bdCorpEntityList.size(); i++) {
                BdCorpEntity bdCorpEntity1 = bdCorpEntityList.get(i);
                stringBdCorpEntityMap.put(bdCorpEntity1.getUnitcode(), bdCorpEntity1);
            }
        }
        return stringBdCorpEntityMap;
    }

    //    public static Map<String, BdStordocEntity> stringBdStordocEntityMap = new HashMap<>();

    /**
     * 初始化发货仓库
     * 2024年7月31日 11:16:27
     * 202403011513：仓库根据仓库编码+库存组织编码去查询，之前是仓库编码+公司主键，和李佳妮确认好了
     */
    private Map<String, BdStordocEntity> initBdStordoc() throws Exception {
        Map<String, BdStordocEntity> stringBdStordocEntityMap = new HashMap<>();
        BdStordocEntity bdStordocEntity = new BdStordocEntity();
        bdStordocEntity.setDr(0L);
        bdStordocEntity.setDataSourceCode("lets_u8c");
        List<BdStordocEntity> bdStordocEntityList = iBdStordocDao.query(bdStordocEntity);
        if (bdStordocEntityList != null && bdStordocEntityList.size() > 0) {
            for (int i = 0; i < bdStordocEntityList.size(); i++) {
                BdStordocEntity bdStordocEntity1 = bdStordocEntityList.get(i);
                stringBdStordocEntityMap.put(bdStordocEntity1.getStorcode() + bdStordocEntity1.getPkCalbody(), bdStordocEntity1);
            }
        }
        return stringBdStordocEntityMap;
    }

    /**
     * 2024年7月31日 11:09:12 查询发货库存组织
     */
//    public static Map<String, BdCalbodyEntity> stringBdCalbodyEntityMap = new HashMap<>();
    private Map<String, BdCalbodyEntity> initBdCalbody() throws Exception {
        Map<String, BdCalbodyEntity> stringBdCalbodyEntityMap = new HashMap<>();
        BdCalbodyEntity bdCalbodyEntity = new BdCalbodyEntity();
        bdCalbodyEntity.setDr(0);
        bdCalbodyEntity.setDataSourceCode("lets_u8c");
        List<BdCalbodyEntity> bdCalbodyEntities = iBdCalbodyDao.query(bdCalbodyEntity);
        if (bdCalbodyEntities != null && bdCalbodyEntities.size() > 0) {
            for (int i = 0; i < bdCalbodyEntities.size(); i++) {
                BdCalbodyEntity bdCalbodyEntity1 = bdCalbodyEntities.get(i);
                stringBdCalbodyEntityMap.put(bdCalbodyEntity1.getPkCorp(), bdCalbodyEntity1);
            }
        }
        return stringBdCalbodyEntityMap;
    }

    /**
     * 初始化销售组织
     */
//    public static Map<String, BdSalestruEntity> stringBdSalestruEntityMap = new HashMap<>();
    private Map<String, BdSalestruEntity> initBdSalestru() throws Exception {
        Map<String, BdSalestruEntity> stringBdSalestruEntityMap = new HashMap<>();
        BdSalestruEntity bdSalestruEntity = new BdSalestruEntity();
        bdSalestruEntity.setDr(0);
        bdSalestruEntity.setDataSourceCode("lets_u8c");
        List<BdSalestruEntity> bdSalestruEntityList = iBdSalestruDao.query(bdSalestruEntity);
        if (bdSalestruEntityList != null && bdSalestruEntityList.size() > 0) {
            for (int i = 0; i < bdSalestruEntityList.size(); i++) {
                BdSalestruEntity bdSalestruEntity1 = bdSalestruEntityList.get(i);
                stringBdSalestruEntityMap.put(bdSalestruEntity1.getVsalestruname(), bdSalestruEntity1);
            }
        }
        return stringBdSalestruEntityMap;
    }

    /**
     * 初始化业务部门
     *
     * @author liuyang
     */
//    public static Map<String, BdDeptdocEntity> stringBdDeptdocEntityMap = new HashMap<>();
    private Map<String, BdDeptdocEntity> initDept() {
        Map<String, BdDeptdocEntity> stringBdDeptdocEntityMap = new HashMap<>();

        BdDeptdocEntity bdDeptdocEntity = new BdDeptdocEntity();
        bdDeptdocEntity.setDataSourceCode("lets_u8c");
        bdDeptdocEntity.setDr(0);
        bdDeptdocEntity.setDeptname("其他部门");
        List<BdDeptdocEntity> bdDeptdocEntityList = iBdDeptdocDao.query(bdDeptdocEntity);
        if (bdDeptdocEntityList != null && bdDeptdocEntityList.size() > 0) {
            for (int i = 0; i < bdDeptdocEntityList.size(); i++) {
                BdDeptdocEntity bdDeptdocEntity1 = bdDeptdocEntityList.get(i);
                stringBdDeptdocEntityMap.put(bdDeptdocEntity1.getPkCorp(), bdDeptdocEntity1);
            }
        }
        return stringBdDeptdocEntityMap;
    }

    /**
     * 初始化客商基本档案
     *
     * @author liuyang
     */
//    public static 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);
                bdCubasdocEntity.setCustcodes(codesStr);
                List<BdCubasdocEntity> bdCumandocEntityList = iBdCubasdocDao.query(bdCubasdocEntity);
                allBdCumandocEntityList.addAll(bdCumandocEntityList);
            }
        }
        if (allBdCumandocEntityList.size() > 0) {
            for (int i = 0; i < allBdCumandocEntityList.size(); i++) {
                BdCubasdocEntity bdCubasdocEntity = allBdCumandocEntityList.get(i);
                stringBdCubasdocEntityMap.put(bdCubasdocEntity.getCustcode(), bdCubasdocEntity);
            }
        }
        return stringBdCubasdocEntityMap;
    }

    /**
     * 初始化客商管理档案
     *
     * @author liuyang
     */
//    public static 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;
//    }

    /**
     * 查询客商管理档案
     *
     * @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);
            }
        }
        return stringBdCumandocEntityMap;
    }

    /**
     * 初始化存货管理档案
     */
//    public static Map<String, BdInvmandocEntity> stringBdInvmandocEntityMap = new HashMap<>();
//    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<>();

        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;
    }

    /**
     * 初始化存货基本档案
     * 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<>();
//
//        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;
//    }

    /**
     * 根据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);
            }
        }
        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;
    }

    /**
     * 2024年8月7日 10:59:30
     * 初始化存货税率
     *
     * @author liuyang
     */
//    public static 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();
                bdTaxitemsEntity.setInvcodes(codesStr);
                List<BdTaxitemsEntity> bdTaxitemsEntityList = iBdTaxitemsDao.queryBdInvbasdocByInvcodeV2(bdTaxitemsEntity);
                allBdTaxitemsEntityList.addAll(bdTaxitemsEntityList);
            }
        }
        if (allBdTaxitemsEntityList.size() > 0) {
            for (int i = 0; i < allBdTaxitemsEntityList.size(); i++) {
                BdTaxitemsEntity bdTaxitemsEntity = allBdTaxitemsEntityList.get(i);
                stringBdTaxitemsEntityMap.put(bdTaxitemsEntity.getInvcode(), bdTaxitemsEntity);
            }
        }
        return stringBdTaxitemsEntityMap;
    }

    /**
     * 缓存来源平台逻辑
     *
     * @author liuyang
     */
//    public static Map<String, BdDefdocEntity> stringBdDefdocEntityHashMap = new HashMap<>();
    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(platformZdyId2);
        bdDefdocEntity.setDr(0);
        bdDefdocEntity.setDataSourceCode("lets_u8c");
        List<BdDefdocEntity> bdDefdocEntityList = iBdDefdocDao.query(bdDefdocEntity);
        if (bdDefdocEntityList != null && bdDefdocEntityList.size() > 0) {
            for (int i = 0; i < bdDefdocEntityList.size(); i++) {
                BdDefdocEntity bdDefdocEntity1 = bdDefdocEntityList.get(i);
                stringBdDefdocEntityHashMap.put(bdDefdocEntity1.getDoccode(), bdDefdocEntity1);
            }
        }
        return stringBdDefdocEntityHashMap;
    }

    /**
     * 2024年8月14日 15:17:48 缓存U8C店铺自定义档案逻辑
     */
//    public static Map<String, BdDefdocEntity> shopDefdocEntityHashMap = new HashMap<>();
    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(platformZdyId2);
        bdDefdocEntity.setDr(0);
        bdDefdocEntity.setDataSourceCode("lets_u8c");
        List<BdDefdocEntity> bdDefdocEntityList = iBdDefdocDao.query(bdDefdocEntity);
        if (bdDefdocEntityList != null && bdDefdocEntityList.size() > 0) {
            for (int i = 0; i < bdDefdocEntityList.size(); i++) {
                BdDefdocEntity bdDefdocEntity1 = bdDefdocEntityList.get(i);
                shopDefdocEntityHashMap.put(bdDefdocEntity1.getDoccode(), bdDefdocEntity1);
            }
        }
        return shopDefdocEntityHashMap;
    }

//    public static Map<String, BdRdclEntity> stringBdRdclEntityHashMap = new HashMap<>();

    /**
     * 初始化收发类别
     */
    private Map<String, BdRdclEntity> initBdRdcl() {
        Map<String, BdRdclEntity> stringBdRdclEntityHashMap = new HashMap<>();

        BdRdclEntity bdRdclEntity = new BdRdclEntity();
        bdRdclEntity.setDr(0);
        bdRdclEntity.setDataSourceCode("lets_u8c");
        List<BdRdclEntity> bdRdclEntityList = iBdRdclDao.query(bdRdclEntity);
        if (bdRdclEntityList != null && bdRdclEntityList.size() > 0) {
            for (int i = 0; i < bdRdclEntityList.size(); i++) {
                BdRdclEntity bdRdclEntity1 = bdRdclEntityList.get(i);
                stringBdRdclEntityHashMap.put(bdRdclEntity1.getRdcode(), bdRdclEntity1);
            }
        }
        return stringBdRdclEntityHashMap;
    }

    /**
     * 清理缓存
     *
     * @author liuyang
     */
//    public void clearCache() throws Exception {
//        stringBdCorpEntityMap.clear();
//        stringBdStordocEntityMap.clear();
//        stringBdCalbodyEntityMap.clear();
//        stringBdSalestruEntityMap.clear();
//        stringBdDeptdocEntityMap.clear();
//        stringBdCumandocEntityMap.clear();
//        stringBdInvmandocEntityMap.clear();
//        stringBdInvbasdocEntityHashMap.clear();
//        stringBdTaxitemsEntityHashMap.clear();
//        stringBdCubasdocEntityHashMap.clear();
//        stringBdDefdocEntityHashMap.clear();
//        shopDefdocEntityHashMap.clear();
//        stringBdRdclEntityHashMap.clear();
//    }

    /**
     * 初始化缓存
     *
     * @param returnGoodHeaderDetailsDataDtoList OFS售后入库单
     * @author liuyang
     */
    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 = 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();

        CacheTocMapVoV2 cacheTocMapVoV2 = new CacheTocMapVoV2();
        cacheTocMapVoV2.setStringBdCorpEntityMap(stringBdCorpEntityMap);
        cacheTocMapVoV2.setStringBdStordocEntityMap(stringBdStordocEntityMap);
        cacheTocMapVoV2.setStringBdCalbodyEntityMap(stringBdCalbodyEntityMap);
        cacheTocMapVoV2.setStringBdSalestruEntityMap(stringBdSalestruEntityMap);
        cacheTocMapVoV2.setStringBdDeptdocEntityMap(stringBdDeptdocEntityMap);
        cacheTocMapVoV2.setStringBdCubasdocEntityMap(stringBdCubasdocEntityMap);
        cacheTocMapVoV2.setStringBdCumandocEntityMap(stringBdCumandocEntityMap);
        cacheTocMapVoV2.setStringBdInvmandocEntityMap(stringBdInvmandocEntityMap);
        cacheTocMapVoV2.setStringBdInvbasdocEntityMap(stringBdInvbasdocEntityMap);
        cacheTocMapVoV2.setStringBdTaxitemsEntityMap(stringBdTaxitemsEntityMap);
        cacheTocMapVoV2.setStringBdDefdocEntityMap(stringBdDefdocEntityMap);
        cacheTocMapVoV2.setStringBdDefdocEntityMap1(stringBdDefdocEntityMap1);
        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;
    }
}