package com.fs.company.controller.company;

import com.fs.common.annotation.Log;
import com.fs.common.core.controller.BaseController;
import com.fs.common.core.domain.AjaxResult;
import com.fs.common.core.page.TableDataInfo;
import com.fs.common.enums.BusinessType;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.company.domain.CompanyVoiceRoboticCallLogCallphone;
import com.fs.company.service.ICompanyVoiceRoboticCallLogCallphoneService;
import com.fs.company.vo.CompanyVoiceRoboticCallLogCallPhoneVO;
import com.fs.company.vo.CompanyVoiceRoboticCallLogCount;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * 调用日志_ai打电话Controller
 * 
 * @author fs
 * @date 2026-01-15
 */
@RestController
@RequestMapping("/company/callphoneLog")
public class CompanyVoiceRoboticCallLogCallphoneController extends BaseController
{
    @Autowired
    private ICompanyVoiceRoboticCallLogCallphoneService companyVoiceRoboticCallLogCallphoneService;

    /**
     * 查询调用日志_ai打电话列表
     */
    @PreAuthorize("@ss.hasPermi('company:callphonelog:list')")
    @GetMapping("/list")
    public TableDataInfo list(CompanyVoiceRoboticCallLogCallphone companyVoiceRoboticCallLogCallphone) {
        if (null == companyVoiceRoboticCallLogCallphone.getRoboticId() && null == companyVoiceRoboticCallLogCallphone.getCallerId()) {
            if (companyVoiceRoboticCallLogCallphone.getCustomerId() != null) {
                List<Long> calleeIds = companyVoiceRoboticCallLogCallphoneService.getCallerIdsByCustomerId(companyVoiceRoboticCallLogCallphone.getCustomerId());
                if(null == calleeIds || calleeIds.isEmpty()){
                    return getDataTable(new ArrayList<>());
                }
                companyVoiceRoboticCallLogCallphone.setCallerIds(calleeIds);
                startPage();
                List<CompanyVoiceRoboticCallLogCallphone> list = companyVoiceRoboticCallLogCallphoneService.selectCompanyVoiceRoboticCallLogCallphoneListData(companyVoiceRoboticCallLogCallphone);
                return getDataTable(list);
            } else {
                return getDataTable(new ArrayList<>());
            }
        } else {
            startPage();
            List<CompanyVoiceRoboticCallLogCallphone> list = companyVoiceRoboticCallLogCallphoneService.selectCompanyVoiceRoboticCallLogCallphoneListData(companyVoiceRoboticCallLogCallphone);
            return getDataTable(list);
        }
    }

    @PreAuthorize("@ss.hasPermi('company:sendmsglog:list')")
    @GetMapping("/listByCallerIdAndRoboticId")
    public TableDataInfo listByCallerIdAndRoboticId(CompanyVoiceRoboticCallLogCallphone companyVoiceRoboticCallLogCallphone) {
        startPage();
        List<CompanyVoiceRoboticCallLogCallPhoneVO> list = companyVoiceRoboticCallLogCallphoneService.listByRoboticId(companyVoiceRoboticCallLogCallphone);
        return getDataTable(list);

    }


    /**
     * 查询调用日志_发送短信列表(按照任务id分组，任务id-任务名称-查询总任务数量-成功数量)
     */
    @PreAuthorize("@ss.hasPermi('company:sendmsglog:list')")
    @GetMapping("/groupList")
    public TableDataInfo groupList(CompanyVoiceRoboticCallLogCallphone companyVoiceRoboticCallLogCallphone)
    {
        startPage();
        List<CompanyVoiceRoboticCallLogCallphone> list = companyVoiceRoboticCallLogCallphoneService.selectCompanyVoiceRoboticCallPhoneLogGroupList(companyVoiceRoboticCallLogCallphone);
        return getDataTable(list);
    }

    /**
     * 查询调用日志_发送短信列表统计数据
     */
    @PreAuthorize("@ss.hasPermi('company:sendmsglog:list')")
    @GetMapping("/count")
    public AjaxResult selectCompanyVoiceRoboticCallPhoneLogCount()
    {
        CompanyVoiceRoboticCallLogCount companyVoiceRoboticCallLogCount = companyVoiceRoboticCallLogCallphoneService.selectCompanyVoiceRoboticCallPhoneLogCount();
        return AjaxResult.success(companyVoiceRoboticCallLogCount);
    }

    /**
     * 导出调用日志_ai打电话列表
     */
    @PreAuthorize("@ss.hasPermi('company:callphonelog:export')")
    @Log(title = "调用日志_ai打电话", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(CompanyVoiceRoboticCallLogCallphone companyVoiceRoboticCallLogCallphone)
    {
        List<CompanyVoiceRoboticCallLogCallPhoneVO> list = companyVoiceRoboticCallLogCallphoneService.listByRoboticId(companyVoiceRoboticCallLogCallphone);
        ExcelUtil<CompanyVoiceRoboticCallLogCallPhoneVO> util = new ExcelUtil<CompanyVoiceRoboticCallLogCallPhoneVO>(CompanyVoiceRoboticCallLogCallPhoneVO.class);
        return util.exportExcel(list, "调用日志_ai打电话数据");
    }

//    /**
//     * 导出调用日志_ai打电话列表
//     */
//    @PreAuthorize("@ss.hasPermi('company:callphonelog:export')")
//    @Log(title = "调用日志_ai打电话", businessType = BusinessType.EXPORT)
//    @GetMapping("/export")
//    public AjaxResult export(CompanyVoiceRoboticCallLogCallphone companyVoiceRoboticCallLogCallphone)
//    {
//        List<CompanyVoiceRoboticCallLogCallphone> list = companyVoiceRoboticCallLogCallphoneService.selectCompanyVoiceRoboticCallLogCallphoneList(companyVoiceRoboticCallLogCallphone);
//        ExcelUtil<CompanyVoiceRoboticCallLogCallphone> util = new ExcelUtil<CompanyVoiceRoboticCallLogCallphone>(CompanyVoiceRoboticCallLogCallphone.class);
//        return util.exportExcel(list, "调用日志_ai打电话数据");
//    }
//
//    /**
//     * 获取调用日志_ai打电话详细信息
//     */
//    @PreAuthorize("@ss.hasPermi('company:callphonelog:query')")
//    @GetMapping(value = "/{logId}")
//    public AjaxResult getInfo(@PathVariable("logId") Long logId)
//    {
//        return AjaxResult.success(companyVoiceRoboticCallLogCallphoneService.selectCompanyVoiceRoboticCallLogCallphoneByLogId(logId));
//    }
//
//    /**
//     * 新增调用日志_ai打电话
//     */
//    @PreAuthorize("@ss.hasPermi('company:callphonelog:add')")
//    @Log(title = "调用日志_ai打电话", businessType = BusinessType.INSERT)
//    @PostMapping
//    public AjaxResult add(@RequestBody CompanyVoiceRoboticCallLogCallphone companyVoiceRoboticCallLogCallphone)
//    {
//        return toAjax(companyVoiceRoboticCallLogCallphoneService.insertCompanyVoiceRoboticCallLogCallphone(companyVoiceRoboticCallLogCallphone));
//    }
//
//    /**
//     * 修改调用日志_ai打电话
//     */
//    @PreAuthorize("@ss.hasPermi('company:callphonelog:edit')")
//    @Log(title = "调用日志_ai打电话", businessType = BusinessType.UPDATE)
//    @PutMapping
//    public AjaxResult edit(@RequestBody CompanyVoiceRoboticCallLogCallphone companyVoiceRoboticCallLogCallphone)
//    {
//        return toAjax(companyVoiceRoboticCallLogCallphoneService.updateCompanyVoiceRoboticCallLogCallphone(companyVoiceRoboticCallLogCallphone));
//    }
//
//    /**
//     * 删除调用日志_ai打电话
//     */
//    @PreAuthorize("@ss.hasPermi('company:callphonelog:remove')")
//    @Log(title = "调用日志_ai打电话", businessType = BusinessType.DELETE)
//	@DeleteMapping("/{logIds}")
//    public AjaxResult remove(@PathVariable Long[] logIds)
//    {
//        return toAjax(companyVoiceRoboticCallLogCallphoneService.deleteCompanyVoiceRoboticCallLogCallphoneByLogIds(logIds));
//    }
}
