package com.fs.aiob.controller;

import java.util.List;

import com.fs.aicall.domain.TaskInfo;
import com.fs.aicall.utils.AiobApiUtils;
import com.fs.aicall.vo.RobotVo;
import com.fs.common.core.domain.R;
import com.fs.common.utils.PubFun;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.fs.common.annotation.Log;
import com.fs.common.core.controller.BaseController;
import com.fs.common.core.domain.AjaxResult;
import com.fs.common.enums.BusinessType;
import com.fs.aiob.domain.AiobBaiduTask;
import com.fs.aiob.service.IAiobBaiduTaskService;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.common.core.page.TableDataInfo;

/**
 * 百度AI外呼任务Controller
 * 
 * @author fs
 * @date 2025-03-20
 */
@RestController
@RequestMapping("/aiob/AiobBaiduTask")
@AllArgsConstructor
public class AiobBaiduTaskController extends BaseController {

    private final IAiobBaiduTaskService aiobBaiduTaskService;
    private final AiobApiUtils aiobApiUtils;

    /**
     * 查询百度AI外呼任务列表
     */
    @PreAuthorize("@ss.hasPermi('aiob:AiobBaiduTask:list')")
    @GetMapping("/list")
    public TableDataInfo list(AiobBaiduTask aiobBaiduTask)
    {
        startPage();
        List<AiobBaiduTask> list = aiobBaiduTaskService.selectAiobBaiduTaskList(aiobBaiduTask);
        return getDataTable(list);
    }

    /**
     * 导出百度AI外呼任务列表
     */
    @PreAuthorize("@ss.hasPermi('aiob:AiobBaiduTask:export')")
    @Log(title = "百度AI外呼任务", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(AiobBaiduTask aiobBaiduTask)
    {
        List<AiobBaiduTask> list = aiobBaiduTaskService.selectAiobBaiduTaskList(aiobBaiduTask);
        ExcelUtil<AiobBaiduTask> util = new ExcelUtil<AiobBaiduTask>(AiobBaiduTask.class);
        return util.exportExcel(list, "百度AI外呼任务数据");
    }

    /**
     * 获取百度AI外呼任务详细信息
     */
    @PreAuthorize("@ss.hasPermi('aiob:AiobBaiduTask:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(aiobBaiduTaskService.selectAiobBaiduTaskById(id));
    }

    /**
     * 新增百度AI外呼任务
     */
    @PreAuthorize("@ss.hasPermi('aiob:AiobBaiduTask:add')")
    @Log(title = "百度AI外呼任务", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AiobBaiduTask aiobBaiduTask)
    {
        return toAjax(aiobBaiduTaskService.insertAiobBaiduTask(aiobBaiduTask));
    }

    /**
     * 修改百度AI外呼任务
     */
    @PreAuthorize("@ss.hasPermi('aiob:AiobBaiduTask:edit')")
    @Log(title = "百度AI外呼任务", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AiobBaiduTask aiobBaiduTask)
    {
        return toAjax(aiobBaiduTaskService.updateAiobBaiduTask(aiobBaiduTask));
    }

    /**
     * 删除百度AI外呼任务
     */
    @PreAuthorize("@ss.hasPermi('aiob:AiobBaiduTask:remove')")
    @Log(title = "百度AI外呼任务", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(aiobBaiduTaskService.deleteAiobBaiduTaskByIds(ids));
    }
    /**
     * 获取机器人列表
     */
	@GetMapping("/robotList")
    public R robotList(){
        List<RobotVo> robotList = aiobApiUtils.getRobotList();
        return R.ok().put("data", PubFun.listToMapByGroupList(robotList, RobotVo::getIndustryName));
    }


    /**
     * 启动任务
     */
    @GetMapping("/startRobotic")
    public R startRobotic(String taskId){
        aiobBaiduTaskService.changeStatus(taskId, 2);
        return R.ok();
    }
    /**
     * 停止任务
     */
    @GetMapping("/stopRobotic")
    public R stopRobotic(String taskId){
        aiobBaiduTaskService.changeStatus(taskId, 3);
        return R.ok();
    }
}
