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.CompanyVoiceRoboticCallLogSendmsg;
import com.fs.company.service.ICompanyVoiceRoboticCallLogCallphoneService;
import com.fs.company.service.ICompanyVoiceRoboticCallLogSendmsgService;
import com.fs.company.vo.CompanyVoiceRoboticCallLogCount;
import com.fs.company.vo.CompanyVoiceRoboticCallLogSendmsgVO;
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;

/**
 * 调用日志_发送短信Controller
 * 
 * @author fs
 * @date 2026-01-15
 */
@RestController
@RequestMapping("/company/sendmsgLog")
public class CompanyVoiceRoboticCallLogSendmsgController extends BaseController
{
    @Autowired
    private ICompanyVoiceRoboticCallLogSendmsgService companyVoiceRoboticCallLogSendmsgService;

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

    /**
     * 查询调用日志_发送短信列表
     */
    @PreAuthorize("@ss.hasPermi('company:sendmsglog:list')")
    @GetMapping("/listByCallerIdAndRoboticId")
    public TableDataInfo listByCallerIdAndRoboticId(CompanyVoiceRoboticCallLogSendmsg companyVoiceRoboticCallLogSendmsg)
    {
        if (null == companyVoiceRoboticCallLogSendmsg.getRoboticId() && null == companyVoiceRoboticCallLogSendmsg.getCallerId()) {
            if (companyVoiceRoboticCallLogSendmsg.getCustomerId() != null) {
                List<Long> calleeIds = companyVoiceRoboticCallLogCallphoneService.getCallerIdsByCustomerId(companyVoiceRoboticCallLogSendmsg.getCustomerId());
                if(null == calleeIds || calleeIds.isEmpty()){
                    return getDataTable(new ArrayList<>());
                }
                companyVoiceRoboticCallLogSendmsg.setCallerIds(calleeIds);
                List<CompanyVoiceRoboticCallLogSendmsgVO> list = companyVoiceRoboticCallLogSendmsgService.listByCallerIdAndRoboticId(companyVoiceRoboticCallLogSendmsg);
                return getDataTable(list);
            } else{
                return getDataTable(new ArrayList<>());
            }
        }else{
            startPage();
            List<CompanyVoiceRoboticCallLogSendmsgVO> list = companyVoiceRoboticCallLogSendmsgService.listByCallerIdAndRoboticId(companyVoiceRoboticCallLogSendmsg);
            return getDataTable(list);
        }
    }

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

    /**
     * 导出调用日志_发送短信列表
     */
    @PreAuthorize("@ss.hasPermi('company:sendmsglog:export')")
    @Log(title = "调用日志_发送短信", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(CompanyVoiceRoboticCallLogSendmsg companyVoiceRoboticCallLogSendmsg)
    {
        List<CompanyVoiceRoboticCallLogSendmsg> list = companyVoiceRoboticCallLogSendmsgService.selectCompanyVoiceRoboticCallLogSendmsgList(companyVoiceRoboticCallLogSendmsg);
        ExcelUtil<CompanyVoiceRoboticCallLogSendmsg> util = new ExcelUtil<CompanyVoiceRoboticCallLogSendmsg>(CompanyVoiceRoboticCallLogSendmsg.class);
        return util.exportExcel(list, "调用日志_发送短信数据");
    }
//
//    /**
//     * 获取调用日志_发送短信详细信息
//     */
//    @PreAuthorize("@ss.hasPermi('company:sendmsglog:query')")
//    @GetMapping(value = "/{logId}")
//    public AjaxResult getInfo(@PathVariable("logId") Long logId)
//    {
//        return AjaxResult.success(companyVoiceRoboticCallLogSendmsgService.selectCompanyVoiceRoboticCallLogSendmsgByLogId(logId));
//    }
//
//    /**
//     * 新增调用日志_发送短信
//     */
//    @PreAuthorize("@ss.hasPermi('company:sendmsglog:add')")
//    @Log(title = "调用日志_发送短信", businessType = BusinessType.INSERT)
//    @PostMapping
//    public AjaxResult add(@RequestBody CompanyVoiceRoboticCallLogSendmsg companyVoiceRoboticCallLogSendmsg)
//    {
//        return toAjax(companyVoiceRoboticCallLogSendmsgService.insertCompanyVoiceRoboticCallLogSendmsg(companyVoiceRoboticCallLogSendmsg));
//    }
//
//    /**
//     * 修改调用日志_发送短信
//     */
//    @PreAuthorize("@ss.hasPermi('company:sendmsglog:edit')")
//    @Log(title = "调用日志_发送短信", businessType = BusinessType.UPDATE)
//    @PutMapping
//    public AjaxResult edit(@RequestBody CompanyVoiceRoboticCallLogSendmsg companyVoiceRoboticCallLogSendmsg)
//    {
//        return toAjax(companyVoiceRoboticCallLogSendmsgService.updateCompanyVoiceRoboticCallLogSendmsg(companyVoiceRoboticCallLogSendmsg));
//    }

//    /**
//     * 删除调用日志_发送短信
//     */
//    @PreAuthorize("@ss.hasPermi('company:sendmsglog:remove')")
//    @Log(title = "调用日志_发送短信", businessType = BusinessType.DELETE)
//	@DeleteMapping("/{logIds}")
//    public AjaxResult remove(@PathVariable Long[] logIds)
//    {
//        return toAjax(companyVoiceRoboticCallLogSendmsgService.deleteCompanyVoiceRoboticCallLogSendmsgByLogIds(logIds));
//    }
}
