package com.fs.company.controller;

import java.util.List;

import com.fs.company.vo.CompanyVoiceListVO;
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.company.domain.CompanyVoice;
import com.fs.company.service.ICompanyVoiceService;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.common.core.page.TableDataInfo;

/**
 * 企业通话Controller
 *
 * @author fs
 * @date 2023-02-23
 */
@RestController
@RequestMapping("/company/companyVoice")
public class CompanyVoiceController extends BaseController
{
    @Autowired
    private ICompanyVoiceService companyVoiceService;

    /**
     * 查询企业通话列表
     */
    @PreAuthorize("@ss.hasPermi('company:companyVoice:list')")
    @GetMapping("/list")
    public TableDataInfo list(CompanyVoice companyVoice)
    {
        startPage();
        List<CompanyVoiceListVO> list = companyVoiceService.selectCompanyVoiceListVO(companyVoice);
        for (CompanyVoiceListVO vo : list){
            vo.setUseTimes(vo.getTotalTimes()-vo.getTimes());
        }
        return getDataTable(list);
    }

    /**
     * 导出企业通话列表
     */
    @PreAuthorize("@ss.hasPermi('company:companyVoice:export')")
    @Log(title = "企业通话", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(CompanyVoice companyVoice)
    {
        List<CompanyVoice> list = companyVoiceService.selectCompanyVoiceList(companyVoice);
        ExcelUtil<CompanyVoice> util = new ExcelUtil<CompanyVoice>(CompanyVoice.class);
        return util.exportExcel(list, "companyVoice");
    }

    /**
     * 获取企业通话详细信息
     */
    @PreAuthorize("@ss.hasPermi('company:companyVoice:query')")
    @GetMapping(value = "/{voiceId}")
    public AjaxResult getInfo(@PathVariable("voiceId") Long voiceId)
    {
        return AjaxResult.success(companyVoiceService.selectCompanyVoiceById(voiceId));
    }

    /**
     * 新增企业通话
     */
    @PreAuthorize("@ss.hasPermi('company:companyVoice:add')")
    @Log(title = "企业通话", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CompanyVoice companyVoice)
    {
        return toAjax(companyVoiceService.insertCompanyVoice(companyVoice));
    }

    /**
     * 修改企业通话
     */
    @PreAuthorize("@ss.hasPermi('company:companyVoice:edit')")
    @Log(title = "企业通话", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CompanyVoice companyVoice)
    {
        return toAjax(companyVoiceService.updateCompanyVoice(companyVoice));
    }

    /**
     * 删除企业通话
     */
    @PreAuthorize("@ss.hasPermi('company:companyVoice:remove')")
    @Log(title = "企业通话", businessType = BusinessType.DELETE)
	@DeleteMapping("/{voiceIds}")
    public AjaxResult remove(@PathVariable Long[] voiceIds)
    {
        return toAjax(companyVoiceService.deleteCompanyVoiceByIds(voiceIds));
    }
}
