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.MallIntroduceClass;
import com.ruoyi.mall.service.IMallIntroduceClassService;
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/mallIntroduceClass")
public class MallIntroduceClassController extends BaseController
{
    @Autowired
    private IMallIntroduceClassService mallIntroduceClassService;

    /**
     * 查询学校介绍类别列表
     */
    @PreAuthorize("@ss.hasPermi('mall:mallIntroduceClass:list')")
    @GetMapping("/list")
    public TableDataInfo list(MallIntroduceClass mallIntroduceClass)
    {
        startPage();
        List<MallIntroduceClass> list = mallIntroduceClassService.selectMallIntroduceClassList(mallIntroduceClass);
        return getDataTable(list);
    }

    /**
     * 导出学校介绍类别列表
     */
    @PreAuthorize("@ss.hasPermi('mall:mallIntroduceClass:export')")
    @Log(title = "学校介绍类别", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MallIntroduceClass mallIntroduceClass)
    {
        List<MallIntroduceClass> list = mallIntroduceClassService.selectMallIntroduceClassList(mallIntroduceClass);
        ExcelUtil<MallIntroduceClass> util = new ExcelUtil<MallIntroduceClass>(MallIntroduceClass.class);
        util.exportExcel(response, list, "学校介绍类别数据");
    }

    /**
     * 获取学校介绍类别详细信息
     */
    @PreAuthorize("@ss.hasPermi('mall:mallIntroduceClass:query')")
    @GetMapping(value = "/{introduceClassId}")
    public AjaxResult getInfo(@PathVariable("introduceClassId") Long introduceClassId)
    {
        return AjaxResult.success(mallIntroduceClassService.selectMallIntroduceClassByIntroduceClassId(introduceClassId));
    }

    /**
     * 新增学校介绍类别
     */
    @PreAuthorize("@ss.hasPermi('mall:mallIntroduceClass:add')")
    @Log(title = "学校介绍类别", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MallIntroduceClass mallIntroduceClass)
    {
        return toAjax(mallIntroduceClassService.insertMallIntroduceClass(mallIntroduceClass));
    }

    /**
     * 修改学校介绍类别
     */
    @PreAuthorize("@ss.hasPermi('mall:mallIntroduceClass:edit')")
    @Log(title = "学校介绍类别", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MallIntroduceClass mallIntroduceClass)
    {
        return toAjax(mallIntroduceClassService.updateMallIntroduceClass(mallIntroduceClass));
    }

    /**
     * 删除学校介绍类别
     */
    @PreAuthorize("@ss.hasPermi('mall:mallIntroduceClass:remove')")
    @Log(title = "学校介绍类别", businessType = BusinessType.DELETE)
	@DeleteMapping("/{introduceClassIds}")
    public AjaxResult remove(@PathVariable Long[] introduceClassIds)
    {
        return toAjax(mallIntroduceClassService.deleteMallIntroduceClassByIntroduceClassIds(introduceClassIds));
    }

    /**
     * 查询分类列表
     * @return
     */
    @GetMapping("/selectClassList")
    public AjaxResult selectClassList()
    {
        MallIntroduceClass mallIntroduceClass = new MallIntroduceClass();
        List<MallIntroduceClass> list = mallIntroduceClassService.selectMallIntroduceClassList(mallIntroduceClass);
        return AjaxResult.success(list);
    }
}
