package com.fs.company.service.impl;

import java.util.List;

import com.fs.company.vo.CompanyVoiceListVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.fs.company.mapper.CompanyVoiceMapper;
import com.fs.company.domain.CompanyVoice;
import com.fs.company.service.ICompanyVoiceService;
import cn.hutool.core.util.ObjectUtil;
import com.fs.company.cache.ICompanyCacheService;
import com.fs.company.cache.impl.ICompanyCacheServiceImpl;
import com.fs.company.domain.Company;
/**
 * 企业通话Service业务层处理
 *
 * @author fs
 * @date 2023-02-23
 */
@Service
public class CompanyVoiceServiceImpl implements ICompanyVoiceService
{
    @Autowired
    private CompanyVoiceMapper companyVoiceMapper;
    @Autowired
    private ICompanyCacheService companyCacheService;

    /**
     * 查询企业通话
     *
     * @param voiceId 企业通话ID
     * @return 企业通话
     */
    @Override
    public CompanyVoice selectCompanyVoiceById(Long voiceId)
    {
        return companyVoiceMapper.selectCompanyVoiceById(voiceId);
    }

    /**
     * 查询企业通话列表
     *
     * @param companyVoice 企业通话
     * @return 企业通话
     */
    @Override
    public List<CompanyVoice> selectCompanyVoiceList(CompanyVoice companyVoice)
    {
        List<CompanyVoice> companyVoices = companyVoiceMapper.selectCompanyVoiceList(companyVoice);
        for (CompanyVoice voice : companyVoices) {
            if(ObjectUtil.isNotNull(voice.getCompanyId())){
                Company company = companyCacheService.selectCompanyById(voice.getCompanyId());
                if(ObjectUtil.isNotNull(company)){
                    voice.setCompanyName(company.getCompanyName());
                }
            }
        }
        return companyVoices;
    }

    /**
     * 新增企业通话
     *
     * @param companyVoice 企业通话
     * @return 结果
     */
    @Override
    public int insertCompanyVoice(CompanyVoice companyVoice)
    {
        return companyVoiceMapper.insertCompanyVoice(companyVoice);
    }

    /**
     * 修改企业通话
     *
     * @param companyVoice 企业通话
     * @return 结果
     */
    @Override
    public int updateCompanyVoice(CompanyVoice companyVoice)
    {
        return companyVoiceMapper.updateCompanyVoice(companyVoice);
    }

    /**
     * 批量删除企业通话
     *
     * @param voiceIds 需要删除的企业通话ID
     * @return 结果
     */
    @Override
    public int deleteCompanyVoiceByIds(Long[] voiceIds)
    {
        return companyVoiceMapper.deleteCompanyVoiceByIds(voiceIds);
    }

    /**
     * 删除企业通话信息
     *
     * @param voiceId 企业通话ID
     * @return 结果
     */
    @Override
    public int deleteCompanyVoiceById(Long voiceId)
    {
        return companyVoiceMapper.deleteCompanyVoiceById(voiceId);
    }

    @Override
    public CompanyVoice selectCompanyVoiceByCompanyId(Long companyId) {
        return companyVoiceMapper.selectCompanyVoiceByCompanyId(companyId);
    }

    @Override
    public int updateCompanyVoiceTimes(Long companyId, long times) {
        return companyVoiceMapper.updateCompanyVoiceTimes(companyId,times);
    }

    @Override
    public int updateCompanyVoiceRemainTimes(Long companyId, long times) {
        return companyVoiceMapper.updateCompanyVoiceRemainTimes(companyId,times);
    }

    @Override
    public List<CompanyVoiceListVO> selectCompanyVoiceListVO(CompanyVoice companyVoice) {
        return companyVoiceMapper.selectCompanyVoiceListVO(companyVoice);
    }
}
