package com.ruoyi.frequency.auth.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.frequency.auth.entity.Auth;
import com.ruoyi.frequency.auth.model.result.AuthCount;
import com.ruoyi.frequency.auth.service.AuthService;
import com.ruoyi.frequency.vote.entity.Vote;
import com.ruoyi.frequency.vote.model.result.VoteCount;
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 liwenlong
 * @date 2023-10-18
 */
@RestController
@RequestMapping("/frequency/auth")
public class AuthController extends BaseController
{
    @Autowired
    private AuthService authService;

    /**
     * 查询平台认证列表
     */
    @PreAuthorize("@ss.hasPermi('frequency:auth:list')")
    @PostMapping("/list")
    public TableDataInfo<Auth> list(@RequestBody Auth auth)
    {
        startPage();
        List<Auth> list = authService.selectAuthList(auth);
        return getDataTable(list);
    }

    /**
     * 统计
     */
    @PostMapping("/statistics")
    public AjaxResult statistics(@RequestBody Auth auth)
    {
        AuthCount count = authService.statistics(auth);
        return AjaxResult.success(count);
    }

    /**
     * 导出平台认证列表
     */
    @PreAuthorize("@ss.hasPermi('frequency:auth:export')")
    @Log(title = "平台认证", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Auth auth)
    {
        List<Auth> list = authService.selectAuthList(auth);
        ExcelUtil<Auth> util = new ExcelUtil<Auth>(Auth.class);
        return util.exportExcel(list, "平台认证数据");
    }

    /**
     * 获取平台认证详细信息
     */
    @PreAuthorize("@ss.hasPermi('frequency:auth:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult<Auth> getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(authService.selectAuthById(id));
    }

    /**
     * 新增平台认证
     */
    @PreAuthorize("@ss.hasPermi('frequency:auth:add')")
    @Log(title = "平台认证", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Auth auth)
    {
        return toAjax(authService.insertAuth(auth));
    }

    /**
     * 修改平台认证
     */
    @PreAuthorize("@ss.hasPermi('frequency:auth:edit')")
    @Log(title = "平台认证", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Auth auth)
    {
        return toAjax(authService.updateAuth(auth));
    }

    /**
     * 删除平台认证
     */
    @PreAuthorize("@ss.hasPermi('frequency:auth:remove')")
    @Log(title = "平台认证", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(authService.deleteAuthByIds(ids));
    }


    /**
     * 审核
     */
    @PreAuthorize("@ss.hasPermi('frequency:auth:process')")
    @Log(title = "平台认证", businessType = BusinessType.UPDATE)
    @PostMapping("/process")
    public AjaxResult process(@RequestBody Auth auth)
    {
        return toAjax(authService.process(auth));
    }
}
