package com.ruoyi.web.controller.brewery;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.brewery.domain.WyBrewery;
import com.ruoyi.brewery.service.IWyBreweryService;
import com.ruoyi.web.domain.BreweryAuthApproveVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.brewery.domain.WyBreweryAuth;
import com.ruoyi.brewery.service.IWyBreweryAuthService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 主体认证信息Controller
 *
 * @author ruoyi
 * @date 2024-12-21
 */
@Api(tags = "主体认证信息")
@RestController
@RequestMapping("/system/brewery/auth")
public class WyBreweryAuthController extends BaseController {
    @Autowired
    private IWyBreweryAuthService wyBreweryAuthService;
    @Autowired
    private IWyBreweryService wyBreweryService;

    /**
     * 查询主体认证信息列表
     */
    @CrossOrigin
    @ApiOperation("查询主体认证信息列表")
    @PreAuthorize("@ss.hasPermi('brewery:auth:list')")
    @GetMapping("/list")
    public TableDataInfo list(WyBreweryAuth wyBreweryAuth) {
        startPage();
        List<WyBreweryAuth> list = wyBreweryAuthService.selectWyBreweryAuthList(wyBreweryAuth);
        return getDataTable(list);
    }

    /**
     * 导出主体认证信息列表
     */
    @ApiOperation("导出主体认证信息列表")
    @PreAuthorize("@ss.hasPermi('brewery:auth:export')")
    @Log(title = "主体认证信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WyBreweryAuth wyBreweryAuth) {
        List<WyBreweryAuth> list = wyBreweryAuthService.selectWyBreweryAuthList(wyBreweryAuth);
        ExcelUtil<WyBreweryAuth> util = new ExcelUtil<WyBreweryAuth>(WyBreweryAuth.class);
        util.exportExcel(response, list, "主体认证信息数据");
    }

    /**
     * 获取主体认证信息详细信息
     */
    @ApiOperation("获取主体认证信息详细信息")
    @PreAuthorize("@ss.hasPermi('brewery:auth:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(wyBreweryAuthService.selectWyBreweryAuthById(id));
    }

    /**
     * 新增主体认证信息
     */
//    @ApiOperation("新增主体认证信息")
//    @PreAuthorize("@ss.hasPermi('brewery:auth:add')")
//    @Log(title = "主体认证信息", businessType = BusinessType.INSERT)
//    @PostMapping
//    public AjaxResult add(@RequestBody WyBreweryAuth wyBreweryAuth)
//    {
//        return toAjax(wyBreweryAuthService.insertWyBreweryAuth(wyBreweryAuth));
//    }

    /**
     * 审核主体认证信息
     */
    @ApiOperation("审核主体认证信息")
    @PreAuthorize("@ss.hasPermi('brewery:auth:approve')")
    @Log(title = "审核主体认证信息", businessType = BusinessType.UPDATE)
    @PutMapping("/approval")
    public AjaxResult approval(@RequestBody BreweryAuthApproveVO breweryAuthApprove) {
        WyBreweryAuth wyBreweryAuth = new WyBreweryAuth();
        wyBreweryAuth.setId(breweryAuthApprove.getAuthId());
        wyBreweryAuth.setState(breweryAuthApprove.getApproval());
        wyBreweryAuth.setApprovalReason(breweryAuthApprove.getApprovalReason());
        return toAjax(wyBreweryAuthService.approvalWyBreweryAuth(wyBreweryAuth));
    }

    /**
     * 修改主体认证信息
     */
    @ApiOperation("修改主体认证信息")
    @PreAuthorize("@ss.hasPermi('brewery:auth:edit')")
    @Log(title = "主体认证信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WyBreweryAuth wyBreweryAuth) {
        return toAjax(wyBreweryAuthService.updateWyBreweryAuth(wyBreweryAuth));
    }

    /**
     * 删除主体认证信息
     */
    @ApiOperation("删除主体认证信息")
    @PreAuthorize("@ss.hasPermi('brewery:auth:remove')")
    @Log(title = "主体认证信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(wyBreweryAuthService.deleteWyBreweryAuthByIds(ids));
    }
}
