package com.ruoyi.web.controller.ss;

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

import com.ruoyi.common.utils.ServiceUtil;
import com.ruoyi.ss.mchApply.domain.MchApplyQuery;
import com.ruoyi.ss.mchApply.domain.MchApplyVO;
import io.swagger.annotations.ApiParam;
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.ss.mchApply.domain.MchApply;
import com.ruoyi.ss.mchApply.service.IMchApplyService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商家合作申请Controller
 *
 * @author ruoyi
 * @date 2024-04-28
 */
@RestController
@RequestMapping("/ss/mchApply")
public class MchApplyController extends BaseController
{
    @Autowired
    private IMchApplyService mchApplyService;

    /**
     * 查询商家合作申请列表
     */
    @PreAuthorize("@ss.hasPermi('ss:mchApply:list')")
    @GetMapping("/list")
    public TableDataInfo list(MchApplyQuery mchApply)
    {
        startPage();
        List<MchApplyVO> list = mchApplyService.selectMchApplyList(mchApply);
        return getDataTable(list);
    }

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

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

    /**
     * 新增商家合作申请
     */
    @PreAuthorize("@ss.hasPermi('ss:mchApply:add')")
    @Log(title = "商家合作申请", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MchApply mchApply)
    {
        return toAjax(mchApplyService.insertMchApply(mchApply));
    }

    /**
     * 修改商家合作申请
     */
    @PreAuthorize("@ss.hasPermi('ss:mchApply:edit')")
    @Log(title = "商家合作申请", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MchApply mchApply)
    {
        return toAjax(mchApplyService.updateMchApply(mchApply));
    }

    /**
     * 删除商家合作申请
     */
    @PreAuthorize("@ss.hasPermi('ss:mchApply:remove')")
    @Log(title = "商家合作申请", businessType = BusinessType.DELETE)
	@DeleteMapping("/{applyIds}")
    public AjaxResult remove(@PathVariable Long[] applyIds)
    {
        return toAjax(mchApplyService.deleteMchApplyByApplyIds(applyIds));
    }

    @PreAuthorize("@ss.hasPermi('ss:mchApply:verify')")
    @Log(title = "商家合作申请", businessType = BusinessType.VERIFY)
    @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));
    }

}
