package com.fs.company.controller;

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.domain.R;
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.CompanyVoiceApi;
import com.fs.company.service.ICompanyVoiceApiService;
import com.fs.voice.service.IVoiceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 呼叫接口Controller
 *
 * @author fs
 * @date 2021-10-04
 */
@RestController
@RequestMapping("/company/companyVoiceApi")
public class CompanyVoiceApiController extends BaseController {
    @Autowired
    private ICompanyVoiceApiService companyVoiceApiService;
    @Autowired
    private IVoiceService voiceService;

    /**
     * 查询呼叫接口列表
     */
    @PreAuthorize("@ss.hasPermi('company:companyVoiceApi:list')")
    @GetMapping("/list")
    public TableDataInfo list(CompanyVoiceApi companyVoiceApi) {
        startPage();
        List<CompanyVoiceApi> list = companyVoiceApiService.selectCompanyVoiceApiList(companyVoiceApi);
        return getDataTable(list);
    }

    /**
     * 导出呼叫接口列表
     */
    @PreAuthorize("@ss.hasPermi('company:companyVoiceApi:export')")
    @Log(title = "呼叫接口", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(CompanyVoiceApi companyVoiceApi) {
        List<CompanyVoiceApi> list = companyVoiceApiService.selectCompanyVoiceApiList(companyVoiceApi);
        ExcelUtil<CompanyVoiceApi> util = new ExcelUtil<CompanyVoiceApi>(CompanyVoiceApi.class);
        return util.exportExcel(list, "companyVoiceApi");
    }

    /**
     * 获取呼叫接口详细信息
     */
    @PreAuthorize("@ss.hasPermi('company:companyVoiceApi:query')")
    @GetMapping(value = "/{apiId}")
    public AjaxResult getInfo(@PathVariable("apiId") Long apiId) {
        return AjaxResult.success(companyVoiceApiService.selectCompanyVoiceApiById(apiId));
    }

    /**
     * 新增呼叫接口
     */
    @PreAuthorize("@ss.hasPermi('company:companyVoiceApi:add')")
    @Log(title = "呼叫接口", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CompanyVoiceApi companyVoiceApi) {
        return toAjax(companyVoiceApiService.insertCompanyVoiceApi(companyVoiceApi));
    }

    /**
     * 修改呼叫接口
     */
    @PreAuthorize("@ss.hasPermi('company:companyVoiceApi:edit')")
    @Log(title = "呼叫接口", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CompanyVoiceApi companyVoiceApi) {
        return toAjax(companyVoiceApiService.updateCompanyVoiceApi(companyVoiceApi));
    }

    /**
     * 删除呼叫接口
     */
    @PreAuthorize("@ss.hasPermi('company:companyVoiceApi:remove')")
    @Log(title = "呼叫接口", businessType = BusinessType.DELETE)
    @DeleteMapping("/{apiIds}")
    public AjaxResult remove(@PathVariable Long[] apiIds) {
        return toAjax(companyVoiceApiService.deleteCompanyVoiceApiByIds(apiIds));
    }

    @GetMapping("/getVoiceApiList")
    public R getVoiceApiList() {
        CompanyVoiceApi map = new CompanyVoiceApi();
        map.setStatus(1);
        List<CompanyVoiceApi> list = companyVoiceApiService.selectCompanyVoiceApiList(map);
        return R.ok().put("data", list);
    }


}
