package com.ruoyi.mall.controller;

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

import com.ruoyi.common.annotation.RepeatSubmit;
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.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.mall.domain.MallAcceptRule;
import com.ruoyi.mall.service.IMallAcceptRuleService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 录取原则Controller
 *
 * @author Lsm
 * @date 2023-10-19
 */
@RestController
@RequestMapping("/mall/mallAcceptRule")
public class MallAcceptRuleController extends BaseController
{
    @Autowired
    private IMallAcceptRuleService mallAcceptRuleService;

    /**
     * 查询录取原则列表
     */
    @PreAuthorize("@ss.hasPermi('mall:mallAcceptRule:list')")
    @GetMapping("/list")
    public TableDataInfo list(MallAcceptRule mallAcceptRule)
    {
        startPage();
        List<MallAcceptRule> list = mallAcceptRuleService.selectMallAcceptRuleList(mallAcceptRule);
        return getDataTable(list);
    }

    /**
     * 导出录取原则列表
     */
    @PreAuthorize("@ss.hasPermi('mall:mallAcceptRule:export')")
    @Log(title = "录取原则", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MallAcceptRule mallAcceptRule)
    {
        List<MallAcceptRule> list = mallAcceptRuleService.selectMallAcceptRuleList(mallAcceptRule);
        ExcelUtil<MallAcceptRule> util = new ExcelUtil<MallAcceptRule>(MallAcceptRule.class);
        util.exportExcel(response, list, "录取原则数据");
    }

    /**
     * 获取录取原则详细信息
     */
    @PreAuthorize("@ss.hasPermi('mall:mallAcceptRule:query')")
    @GetMapping(value = "/{acceptRuleId}")
    public AjaxResult getInfo(@PathVariable("acceptRuleId") Long acceptRuleId)
    {
        return AjaxResult.success(mallAcceptRuleService.selectMallAcceptRuleByAcceptRuleId(acceptRuleId));
    }

    /**
     * 新增录取原则
     */
    @PreAuthorize("@ss.hasPermi('mall:mallAcceptRule:add')")
    @Log(title = "录取原则", businessType = BusinessType.INSERT)
    @RepeatSubmit
    @PostMapping
    public AjaxResult add(@RequestBody MallAcceptRule mallAcceptRule)
    {
        return mallAcceptRuleService.insertMallAcceptRule(mallAcceptRule);
    }

    /**
     * 修改录取原则
     */
    @PreAuthorize("@ss.hasPermi('mall:mallAcceptRule:edit')")
    @Log(title = "录取原则", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MallAcceptRule mallAcceptRule)
    {
        return toAjax(mallAcceptRuleService.updateMallAcceptRule(mallAcceptRule));
    }

    /**
     * 删除录取原则
     */
    @PreAuthorize("@ss.hasPermi('mall:mallAcceptRule:remove')")
    @Log(title = "录取原则", businessType = BusinessType.DELETE)
	@DeleteMapping("/{acceptRuleIds}")
    public AjaxResult remove(@PathVariable Long[] acceptRuleIds)
    {
        return toAjax(mallAcceptRuleService.deleteMallAcceptRuleByAcceptRuleIds(acceptRuleIds));
    }

    /**
     * 录取规则列表
     * @return 结果
     */
    @GetMapping("/selectNewAcceptRuleList")
    public AjaxResult selectNewAcceptRuleList(){
        Long ruleClass = null;
        return AjaxResult.success(mallAcceptRuleService.selectNewAcceptRuleList(ruleClass));
    }
}
