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.MallSchoolLevel;
import com.ruoyi.mall.service.IMallSchoolLevelService;
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;

/**
 * 学校办学层次Controller
 *
 * @author Lsm
 * @date 2023-10-18
 */
@RestController
@RequestMapping("/mall/mallSchoolLevel")
public class MallSchoolLevelController extends BaseController
{
    @Autowired
    private IMallSchoolLevelService mallSchoolLevelService;

    /**
     * 查询学校办学层次列表
     */
    @PreAuthorize("@ss.hasPermi('mall:mallSchoolLevel:list')")
    @GetMapping("/list")
    public TableDataInfo list(MallSchoolLevel mallSchoolLevel)
    {
        startPage();
        List<MallSchoolLevel> list = mallSchoolLevelService.selectMallSchoolLevelList(mallSchoolLevel);
        return getDataTable(list);
    }

    /**
     * 导出学校办学层次列表
     */
    @PreAuthorize("@ss.hasPermi('mall:mallSchoolLevel:export')")
    @Log(title = "学校办学层次", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MallSchoolLevel mallSchoolLevel)
    {
        List<MallSchoolLevel> list = mallSchoolLevelService.selectMallSchoolLevelList(mallSchoolLevel);
        ExcelUtil<MallSchoolLevel> util = new ExcelUtil<MallSchoolLevel>(MallSchoolLevel.class);
        util.exportExcel(response, list, "学校办学层次数据");
    }

    /**
     * 获取学校办学层次详细信息
     */
    @PreAuthorize("@ss.hasPermi('mall:mallSchoolLevel:query')")
    @GetMapping(value = "/{schoolLevelId}")
    public AjaxResult getInfo(@PathVariable("schoolLevelId") Long schoolLevelId)
    {
        return AjaxResult.success(mallSchoolLevelService.selectMallSchoolLevelBySchoolLevelId(schoolLevelId));
    }

    /**
     * 新增学校办学层次
     */
    @PreAuthorize("@ss.hasPermi('mall:mallSchoolLevel:add')")
    @Log(title = "学校办学层次", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MallSchoolLevel mallSchoolLevel)
    {
        return toAjax(mallSchoolLevelService.insertMallSchoolLevel(mallSchoolLevel));
    }

    /**
     * 修改学校办学层次
     */
    @PreAuthorize("@ss.hasPermi('mall:mallSchoolLevel:edit')")
    @Log(title = "学校办学层次", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MallSchoolLevel mallSchoolLevel)
    {
        return toAjax(mallSchoolLevelService.updateMallSchoolLevel(mallSchoolLevel));
    }

    /**
     * 删除学校办学层次
     */
    @PreAuthorize("@ss.hasPermi('mall:mallSchoolLevel:remove')")
    @Log(title = "学校办学层次", businessType = BusinessType.DELETE)
	@DeleteMapping("/{schoolLevelIds}")
    public AjaxResult remove(@PathVariable Long[] schoolLevelIds)
    {
        return toAjax(mallSchoolLevelService.deleteMallSchoolLevelBySchoolLevelIds(schoolLevelIds));
    }
}
