package com.fs.company.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fs.common.utils.DateUtils;
import com.fs.company.domain.CompanyVoiceRoboticCallLogAddwx;
import com.fs.company.domain.CompanyWxClient;
import com.fs.company.mapper.CompanyVoiceRoboticBusinessMapper;
import com.fs.company.mapper.CompanyVoiceRoboticCallLogAddwxMapper;
import com.fs.company.mapper.CompanyWxClientMapper;
import com.fs.company.service.ICompanyVoiceRoboticCallLogAddwxService;
import com.fs.company.vo.CompanyVoiceRoboticCallLogAddwxVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 调用日志_加微信Service业务层处理
 * 
 * @author fs
 * @date 2026-01-15
 */
@Service
@Slf4j
public

class CompanyVoiceRoboticCallLogAddwxServiceImpl extends ServiceImpl<CompanyVoiceRoboticCallLogAddwxMapper, CompanyVoiceRoboticCallLogAddwx> implements ICompanyVoiceRoboticCallLogAddwxService {


    @Autowired
    CompanyVoiceRoboticBusinessMapper companyVoiceRoboticBusinessMapper;
    /**
     * 查询调用日志_加微信
     * 
     * @param logId 调用日志_加微信主键
     * @return 调用日志_加微信
     */
    @Override
    public CompanyVoiceRoboticCallLogAddwx selectCompanyVoiceRoboticCallLogAddwxByLogId(Long logId)
    {
        return baseMapper.selectCompanyVoiceRoboticCallLogAddwxByLogId(logId);
    }

    /**
     * 查询调用日志_加微信列表
     * 
     * @param companyVoiceRoboticCallLogAddwx 调用日志_加微信
     * @return 调用日志_加微信
     */
    @Override
    public List<CompanyVoiceRoboticCallLogAddwx> selectCompanyVoiceRoboticCallLogAddwxList(CompanyVoiceRoboticCallLogAddwx companyVoiceRoboticCallLogAddwx)
    {
        return baseMapper.selectCompanyVoiceRoboticCallLogAddwxList(companyVoiceRoboticCallLogAddwx);
    }

    /**
     * 新增调用日志_加微信
     * 
     * @param companyVoiceRoboticCallLogAddwx 调用日志_加微信
     * @return 结果
     */
    @Override
    public int insertCompanyVoiceRoboticCallLogAddwx(CompanyVoiceRoboticCallLogAddwx companyVoiceRoboticCallLogAddwx)
    {
        companyVoiceRoboticCallLogAddwx.setCreateTime(DateUtils.getNowDate());
        return baseMapper.insertCompanyVoiceRoboticCallLogAddwx(companyVoiceRoboticCallLogAddwx);
    }

    /**
     * 修改调用日志_加微信
     * 
     * @param companyVoiceRoboticCallLogAddwx 调用日志_加微信
     * @return 结果
     */
    @Override
    public int updateCompanyVoiceRoboticCallLogAddwx(CompanyVoiceRoboticCallLogAddwx companyVoiceRoboticCallLogAddwx)
    {
        return baseMapper.updateCompanyVoiceRoboticCallLogAddwx(companyVoiceRoboticCallLogAddwx);
    }

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

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

    @Async("callLogExcutor")
    public void asyncInsertCompanyVoiceRoboticCallLog(CompanyVoiceRoboticCallLogAddwx companyVoiceRoboticCallLog) {
        try{
            companyVoiceRoboticCallLog.setCreateTime(DateUtils.getNowDate());
            baseMapper.insertCompanyVoiceRoboticCallLogAddwx(companyVoiceRoboticCallLog);
            companyVoiceRoboticBusinessMapper.updateActionCount(1,companyVoiceRoboticCallLog.getRoboticId(),null,companyVoiceRoboticCallLog.getWxClientId());
        } catch (Exception e) {
            log.error("记录任务执行日志失败:失败数据：{}",companyVoiceRoboticCallLog, e);
        }
    }


    @Autowired
    CompanyWxClientMapper companyWxClientMapper;
    /**
     * 查询用户调用日志记录 1、查询client信息
     * @param customerId
     * @param roboticId
     * @return
     */
    @Override
    public CompanyWxClient getWxClientInfoByCustomerIdAndRoboticId(Long customerId, Long roboticId){
        CompanyWxClient client = companyWxClientMapper.selectOneByRoboticIdAndUserId(roboticId, customerId);
        return client;
    }
    @Override
    public List<CompanyVoiceRoboticCallLogAddwxVO> listByCustomerIdAndRoboticId(CompanyVoiceRoboticCallLogAddwx companyVoiceRoboticCallLogAddwx){

        return baseMapper.listByCustomerIdAndRoboticId(companyVoiceRoboticCallLogAddwx);
    }

    @Override
    public List<CompanyVoiceRoboticCallLogAddwxVO> listByCustomerId(CompanyVoiceRoboticCallLogAddwx companyVoiceRoboticCallLogAddwx){
        return baseMapper.listByCustomerId(companyVoiceRoboticCallLogAddwx);
    }

    /**
     * 查询用户微信信息
     * @param customerId
     * @return
     */
    @Override
    public  List<CompanyWxClient> getWxClientInfoByCustomerId(Long customerId){
        return companyWxClientMapper.getWxClientInfoByCustomerId(customerId);
    }

    @Override
    public List<CompanyVoiceRoboticCallLogAddwxVO> listAll(CompanyVoiceRoboticCallLogAddwx companyVoiceRoboticCallLogAddwx){
        return baseMapper.listAll(companyVoiceRoboticCallLogAddwx);
    }

    @Override
    public Map<String, Long> countListAll(CompanyVoiceRoboticCallLogAddwx companyVoiceRoboticCallLogAddwx){
        return baseMapper.countListAll(companyVoiceRoboticCallLogAddwx);
    }

}
