package com.fs.company.service.impl;

import java.util.Collections;
import java.util.List;
import com.fs.common.utils.DateUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fs.company.domain.CompanyVoiceRoboticCallLogCallphone;
import com.fs.company.mapper.CompanyVoiceRoboticBusinessMapper;
import com.fs.company.vo.CompanyVoiceRoboticCallLogCount;
import com.fs.company.vo.CompanyVoiceRoboticCallLogSendmsgVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import com.fs.company.mapper.CompanyVoiceRoboticCallLogSendmsgMapper;
import com.fs.company.domain.CompanyVoiceRoboticCallLogSendmsg;
import com.fs.company.service.ICompanyVoiceRoboticCallLogSendmsgService;

/**
 * 调用日志_发送短信Service业务层处理
 * 
 * @author fs
 * @date 2026-01-15
 */
@Service
@Slf4j
public class CompanyVoiceRoboticCallLogSendmsgServiceImpl extends ServiceImpl<CompanyVoiceRoboticCallLogSendmsgMapper, CompanyVoiceRoboticCallLogSendmsg> implements ICompanyVoiceRoboticCallLogSendmsgService {

    @Autowired
    CompanyVoiceRoboticBusinessMapper companyVoiceRoboticBusinessMapper;
    /**
     * 查询调用日志_发送短信
     * 
     * @param logId 调用日志_发送短信主键
     * @return 调用日志_发送短信
     */
    @Override
    public CompanyVoiceRoboticCallLogSendmsg selectCompanyVoiceRoboticCallLogSendmsgByLogId(Long logId)
    {
        return baseMapper.selectCompanyVoiceRoboticCallLogSendmsgByLogId(logId);
    }

    @Override
    public List<CompanyVoiceRoboticCallLogSendmsg> selectCompanyVoiceRoboticCallLogSendmsgGroupList(CompanyVoiceRoboticCallLogSendmsg companyVoiceRoboticCallLogSendmsg) {
        return baseMapper.selectCompanyVoiceRoboticCallLogSendmsgGroupList(companyVoiceRoboticCallLogSendmsg);
    }

    /**
     * 查询调用日志_发送短信列表
     * 
     * @param companyVoiceRoboticCallLogSendmsg 调用日志_发送短信
     * @return 调用日志_发送短信
     */
    @Override
    public List<CompanyVoiceRoboticCallLogSendmsg> selectCompanyVoiceRoboticCallLogSendmsgList(CompanyVoiceRoboticCallLogSendmsg companyVoiceRoboticCallLogSendmsg)
    {
        return baseMapper.selectCompanyVoiceRoboticCallLogSendmsgList(companyVoiceRoboticCallLogSendmsg);
    }

    /**
     * 新增调用日志_发送短信
     * 
     * @param companyVoiceRoboticCallLogSendmsg 调用日志_发送短信
     * @return 结果
     */
    @Override
    public int insertCompanyVoiceRoboticCallLogSendmsg(CompanyVoiceRoboticCallLogSendmsg companyVoiceRoboticCallLogSendmsg)
    {
        companyVoiceRoboticCallLogSendmsg.setCreateTime(DateUtils.getNowDate());
        return baseMapper.insertCompanyVoiceRoboticCallLogSendmsg(companyVoiceRoboticCallLogSendmsg);
    }

    /**
     * 修改调用日志_发送短信
     * 
     * @param companyVoiceRoboticCallLogSendmsg 调用日志_发送短信
     * @return 结果
     */
    @Override
    public int updateCompanyVoiceRoboticCallLogSendmsg(CompanyVoiceRoboticCallLogSendmsg companyVoiceRoboticCallLogSendmsg)
    {
        return baseMapper.updateCompanyVoiceRoboticCallLogSendmsg(companyVoiceRoboticCallLogSendmsg);
    }

    /**
     * 批量删除调用日志_发送短信
     * 
     * @param logIds 需要删除的调用日志_发送短信主键
     * @return 结果
     */
    @Override
    public int deleteCompanyVoiceRoboticCallLogSendmsgByLogIds(Long[] logIds)
    {
        return baseMapper.deleteCompanyVoiceRoboticCallLogSendmsgByLogIds(logIds);
    }

    /**
     * 删除调用日志_发送短信信息
     * 
     * @param logId 调用日志_发送短信主键
     * @return 结果
     */
    @Override
    public int deleteCompanyVoiceRoboticCallLogSendmsgByLogId(Long logId)
    {
        return baseMapper.deleteCompanyVoiceRoboticCallLogSendmsgByLogId(logId);
    }

    /**
     * 异步记录任务执行日志
     * @param sendMsgLog
     */
    @Async("callLogExcutor")
    public void asyncInsertCompanyVoiceRoboticCallLog(CompanyVoiceRoboticCallLogSendmsg sendMsgLog) {
        try{
            sendMsgLog.setCreateTime(DateUtils.getNowDate());
            baseMapper.insertCompanyVoiceRoboticCallLogSendmsg(sendMsgLog);
            companyVoiceRoboticBusinessMapper.updateActionCount(3,sendMsgLog.getRoboticId(),sendMsgLog.getCallerId(),null);
        } catch (Exception e) {
            log.error("记录任务执行日志失败:失败数据：{}",sendMsgLog, e);
        }
    }

    @Override
    public List<CompanyVoiceRoboticCallLogSendmsgVO> listByCallerIdAndRoboticId(CompanyVoiceRoboticCallLogSendmsg companyVoiceRoboticCallLogSendmsg){
        return baseMapper.listByCallerIdAndRoboticId(companyVoiceRoboticCallLogSendmsg);
    }

    @Override
    public CompanyVoiceRoboticCallLogCount selectCompanyVoiceRoboticCallLogSendMsgCount() {
        return baseMapper.selectCompanyVoiceRoboticCallLogSendMsgCount();
    }
}
