package com.ruoyi.web.bst;

import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.ruoyi.bst.mchApply.domain.MchApplyQuery;
import com.ruoyi.bst.mchApply.domain.MchApplyVO;
import com.ruoyi.bst.mchApply.service.MchApplyService;
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.enums.LogBizType;
import com.ruoyi.common.utils.poi.ExcelUtil;

import io.swagger.annotations.ApiParam;

/**
 * 招商加盟Controller
 *
 * @author ruoyi
 * @date 2025-04-08
 */
@RestController
@RequestMapping("/bst/mchApply")
public class MchApplyController extends BaseController
{
    @Autowired
    private MchApplyService mchApplyService;

    /**
     * 查询招商加盟列表
     */
    @PreAuthorize("@ss.hasPermi('bst:mchApply:list')")
    @GetMapping("/list")
    public TableDataInfo list(MchApplyQuery query)
    {
        startPage();
        startOrderBy();
        List<MchApplyVO> list = mchApplyService.selectMchApplyList(query);
        return getDataTable(list);
    }

    /**
     * 导出招商加盟列表
     */
    @PreAuthorize("@ss.hasPermi('bst:mchApply:export')")
    @Log(title = "招商加盟", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MchApplyQuery query)
    {
        List<MchApplyVO> list = mchApplyService.selectMchApplyList(query);
        ExcelUtil<MchApplyVO> util = new ExcelUtil<MchApplyVO>(MchApplyVO.class);
        util.exportExcel(response, list, "招商加盟数据");
    }

    /**
     * 获取招商加盟详细信息
     */
    @PreAuthorize("@ss.hasPermi('bst:mchApply:query')")
    @GetMapping(value = "/{applyId}")
    public AjaxResult getInfo(@PathVariable("applyId") Long applyId)
    {
        return success(mchApplyService.selectMchApplyByApplyId(applyId));
    }

    @PreAuthorize("@ss.hasPermi('bst:mchApply:verify')")
    @Log(title = "审核招商加盟", businessType = BusinessType.VERIFY, bizIdName = "arg0", bizType = LogBizType.MCH_APPLY)
    @PutMapping("/{applyId}/verify")
    public AjaxResult verify(@PathVariable @ApiParam("申请id") Long applyId,
                             @RequestParam @ApiParam("是否通过") Boolean pass,
                             @RequestParam @ApiParam("审核意见") String remark) {
        return toAjax(mchApplyService.verify(applyId, pass, remark));
    }
}
