package com.hzya.frame.plugin.lets.util;

import cn.hutool.core.lang.Assert;
import com.hzya.frame.plugin.lets.dao.IBdRdclDao;
import com.hzya.frame.plugin.lets.entity.BdRdclEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

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

    @Autowired
    private IBdRdclDao iBdRdclDao;

    /**
     * 查询收发类别
     *
     * @author liuyang
     */
    public BdRdclEntity queryRdClObject(String code) {
        Assert.notNull(code, "收发类别编码不能为空");
        Assert.state(!"".equals(code.trim()), "收发类别编码不能为空");

        BdRdclEntity bdRdclEntity = new BdRdclEntity();
        bdRdclEntity.setDr(0);
        bdRdclEntity.setRdcode(code);
        bdRdclEntity.setDataSourceCode("lets_u8c");
        List<BdRdclEntity> bdRdclEntityList = iBdRdclDao.query(bdRdclEntity);
        if (bdRdclEntityList == null || bdRdclEntityList.size() == 0) {
            Assert.state(false, "无法查询到U8C收发类别 收发类别编码：{}", code);
        } else if (bdRdclEntityList.size() >= 2) {
            Assert.state(false, "无询到{}个U8C收发类别，存在歧义 收发类别编码：{}", bdRdclEntityList.size(), code);
        }
        return bdRdclEntityList.get(0);
    }
}
