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.IBdDefdocDao;
import com.hzya.frame.plugin.lets.entity.BdDefdocEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @Author：liuyang
 * @Package：com.hzya.frame.plugin.lets.util
 * @Project：kangarooDataCenterV3
 * @name：ShopTobOrToCUtil
 * @Date：2024/8/19 15:20
 * @Filename：ShopTobOrToCUtil
 */
@Component
public class ShopTobOrToCUtil {

    @Autowired
    private IBdDefdocDao iBdDefdocDao;

    /**
     * 查询TOB或者TOC对应的销售订单店铺
     *
     * @param memo TOB、TOC请传这个
     */
    public List<BdDefdocEntity> queryU8cShop(String memo) {
        //查询U8C店铺档案
        String platformZdyId2 = OverallConstant.getOverAllValue("u8c自定义项档案-店铺主键");

        BdDefdocEntity bdDefdocEntity2 = new BdDefdocEntity();
        bdDefdocEntity2.setPkDefdoclist(platformZdyId2);
        bdDefdocEntity2.setDr(0);
        bdDefdocEntity2.setDataSourceCode("lets_u8c");
        bdDefdocEntity2.setMemo(memo);
        List<BdDefdocEntity> bdDefdocEntityList2 = iBdDefdocDao.query(bdDefdocEntity2);
        if (bdDefdocEntityList2.size() == 0) {
            Assert.state(false, "根据O店铺编码{}，无法匹配到U8C店铺自定义档案 备注类型:{}", memo);
        }
        return bdDefdocEntityList2;
    }

    public String getCommaShop(String memo) {
        List<BdDefdocEntity> bdDefdocEntityList = queryU8cShop(memo);
        return bdDefdocEntityList.stream().map(BdDefdocEntity::getDoccode).collect(Collectors.joining(","));
    }
}