package com.ruoyi.ai.service.impl;

import java.util.List;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.ai.mapper.AiCustomerServiceMapper;
import com.ruoyi.ai.domain.AiCustomerService;
import com.ruoyi.ai.service.IAiCustomerServiceService;

/**
 * 客服管理Service业务层处理
 * 
 * @author shi
 * @date 2025-11-13
 */
@Service
public class AiCustomerServiceServiceImpl implements IAiCustomerServiceService {

    @Autowired
    private AiCustomerServiceMapper aiCustomerServiceMapper;

    /**
     * 查询客服管理
     * 
     * @param id 客服管理主键
     * @return 客服管理
     */
    @Override
    public AiCustomerService selectAiCustomerServiceById(Long id) {
        return aiCustomerServiceMapper.selectById(id);
    }

    /**
     * 查询客服管理列表
     * 
     * @param aiCustomerService 客服管理
     * @return 客服管理
     */
    @Override
    public List<AiCustomerService> selectAiCustomerServiceList(AiCustomerService aiCustomerService) {
        LambdaQueryWrapper<AiCustomerService> query = Wrappers.lambdaQuery(aiCustomerService);
        query.orderByDesc(AiCustomerService::getId);
        query.eq(AiCustomerService::getDelFlag, "0");
        return aiCustomerServiceMapper.selectList(query);
    }

    /**
     * 分页查询客服管理列表
     *
     * @param aiCustomerService 客服管理
     * @return 客服管理
     */
    @Override
    public IPage<AiCustomerService> selectAiCustomerServicePage(Page page, AiCustomerService aiCustomerService) {
        LambdaQueryWrapper<AiCustomerService> query = Wrappers.lambdaQuery(aiCustomerService);
        query.eq(AiCustomerService::getDelFlag, "0");
        return aiCustomerServiceMapper.selectPage(page, query);
    }

    /**
     * 新增客服管理
     * 
     * @param aiCustomerService 客服管理
     * @return 结果
     */
    @Override
    public int insertAiCustomerService(AiCustomerService aiCustomerService) {
        aiCustomerService.setDelFlag("0");
        aiCustomerService.setCreateBy(SecurityUtils.getUsername());
        aiCustomerService.setCreateTime(DateUtils.getNowDate());
        return aiCustomerServiceMapper.insert(aiCustomerService);
    }

    /**
     * 修改客服管理
     * 
     * @param aiCustomerService 客服管理
     * @return 结果
     */
    @Override
    public int updateAiCustomerService(AiCustomerService aiCustomerService) {
        aiCustomerService.setUpdateBy(SecurityUtils.getUsername());
        aiCustomerService.setUpdateTime(DateUtils.getNowDate());
        return aiCustomerServiceMapper.updateById(aiCustomerService);
    }

    /**
     * 批量删除客服管理
     * 
     * @param ids 需要删除的客服管理主键
     * @return 结果
     */
    @Override
    public int deleteAiCustomerServiceByIds(Long[] ids)
    {
        return aiCustomerServiceMapper.deleteAiCustomerServiceByIds(ids);
    }

    /**
     * 删除客服管理信息
     * 
     * @param id 客服管理主键
     * @return 结果
     */
    @Override
    public int deleteAiCustomerServiceById(Long id)
    {
        return aiCustomerServiceMapper.deleteAiCustomerServiceById(id);
    }
}
