package com.ruoyi.aicall.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.aicall.mapper.CcLlmKbCatMapper;
import com.ruoyi.aicall.domain.CcLlmKbCat;
import com.ruoyi.aicall.service.ICcLlmKbCatService;
import com.ruoyi.common.core.text.Convert;
import org.springframework.util.CollectionUtils;

/**
 * 知识库Service业务层处理
 * 
 * @author ruoyi
 * @date 2026-01-19
 */
@Service
public class CcLlmKbCatServiceImpl implements ICcLlmKbCatService 
{
    @Autowired
    private CcLlmKbCatMapper ccLlmKbCatMapper;

    /**
     * 查询知识库
     * 
     * @param id 知识库主键
     * @return 知识库
     */
    @Override
    public CcLlmKbCat selectCcLlmKbCatById(Long id)
    {
        return ccLlmKbCatMapper.selectCcLlmKbCatById(id);
    }

    /**
     * 查询知识库列表
     * 
     * @param ccLlmKbCat 知识库
     * @return 知识库
     */
    @Override
    public List<CcLlmKbCat> selectCcLlmKbCatList(CcLlmKbCat ccLlmKbCat)
    {
        return ccLlmKbCatMapper.selectCcLlmKbCatList(ccLlmKbCat);
    }

    /**
     * 新增知识库
     * 
     * @param ccLlmKbCat 知识库
     * @return 结果
     */
    @Override
    public int insertCcLlmKbCat(CcLlmKbCat ccLlmKbCat)
    {
        return ccLlmKbCatMapper.insertCcLlmKbCat(ccLlmKbCat);
    }

    /**
     * 修改知识库
     * 
     * @param ccLlmKbCat 知识库
     * @return 结果
     */
    @Override
    public int updateCcLlmKbCat(CcLlmKbCat ccLlmKbCat)
    {
        return ccLlmKbCatMapper.updateCcLlmKbCat(ccLlmKbCat);
    }

    /**
     * 批量删除知识库
     * 
     * @param ids 需要删除的知识库主键
     * @return 结果
     */
    @Override
    public int deleteCcLlmKbCatByIds(String ids)
    {
        return ccLlmKbCatMapper.deleteCcLlmKbCatByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除知识库信息
     * 
     * @param id 知识库主键
     * @return 结果
     */
    @Override
    public int deleteCcLlmKbCatById(Long id)
    {
        return ccLlmKbCatMapper.deleteCcLlmKbCatById(id);
    }

    @Override
    public CcLlmKbCat selectCcLlmKbCatByCat(Long id, String cat) {
        List<CcLlmKbCat> list = ccLlmKbCatMapper.selectCcLlmKbCatList(new CcLlmKbCat().setCat(cat));
        if (!CollectionUtils.isEmpty(list)) {
            if (null == id) {
                return list.get(0);
            } else {
                for (CcLlmKbCat data: list) {
                    if (data.getId() != id) {
                        return data;
                    }
                }
            }
        }
        return null;
    }
}
