package com.ruoyi.mall.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.mall.domain.MallConfigLevel;
import com.ruoyi.mall.service.IMallConfigLevelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

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

/**
 * 办学层次设置（985、211）Controller
 *
 * @author Lsm
 * @date 2023-10-18
 */
@RestController
@RequestMapping("/mall/mallConfigLevel")
public class MallConfigLevelController extends BaseController
{
    @Autowired
    private IMallConfigLevelService mallConfigLevelService;

    /**
     * 查询办学层次设置（985、211）列表
     */
    @PreAuthorize("@ss.hasPermi('mall:mallConfigLevel:list')")
    @GetMapping("/list")
    public TableDataInfo list(MallConfigLevel mallConfigLevel)
    {
        startPage();
        List<MallConfigLevel> list = mallConfigLevelService.selectMallConfigLevelList(mallConfigLevel);
        return getDataTable(list);
    }

    /**
     * 导出办学层次设置（985、211）列表
     */
    @PreAuthorize("@ss.hasPermi('mall:mallConfigLevel:export')")
    @Log(title = "办学层次设置（985、211）", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MallConfigLevel mallConfigLevel)
    {
        List<MallConfigLevel> list = mallConfigLevelService.selectMallConfigLevelList(mallConfigLevel);
        ExcelUtil<MallConfigLevel> util = new ExcelUtil<MallConfigLevel>(MallConfigLevel.class);
        util.exportExcel(response, list, "办学层次设置（985、211）数据");
    }

    /**
     * 获取办学层次设置（985、211）详细信息
     */
    @PreAuthorize("@ss.hasPermi('mall:mallConfigLevel:query')")
    @GetMapping(value = "/{configLevelId}")
    public AjaxResult getInfo(@PathVariable("configLevelId") Long configLevelId)
    {
        return AjaxResult.success(mallConfigLevelService.selectMallConfigLevelByConfigLevelId(configLevelId));
    }

    /**
     * 新增办学层次设置（985、211）
     */
    @PreAuthorize("@ss.hasPermi('mall:mallConfigLevel:add')")
    @Log(title = "办学层次设置（985、211）", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MallConfigLevel mallConfigLevel)
    {
        return toAjax(mallConfigLevelService.insertMallConfigLevel(mallConfigLevel));
    }

    /**
     * 修改办学层次设置（985、211）
     */
    @PreAuthorize("@ss.hasPermi('mall:mallConfigLevel:edit')")
    @Log(title = "办学层次设置（985、211）", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MallConfigLevel mallConfigLevel)
    {
        return toAjax(mallConfigLevelService.updateMallConfigLevel(mallConfigLevel));
    }

    /**
     * 删除办学层次设置（985、211）
     */
    @PreAuthorize("@ss.hasPermi('mall:mallConfigLevel:remove')")
    @Log(title = "办学层次设置（985、211）", businessType = BusinessType.DELETE)
	@DeleteMapping("/{configLevelIds}")
    public AjaxResult remove(@PathVariable Long[] configLevelIds)
    {
        return toAjax(mallConfigLevelService.deleteMallConfigLevelByConfigLevelIds(configLevelIds));
    }

    /**
     * 办学层次列表
     * @return 结果
     */
    @GetMapping("/selectLevelList")
    public AjaxResult selectLevelList(){
        return AjaxResult.success(mallConfigLevelService.selectLevelList());
    }
}
