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.MallFacultyInfo;
import com.ruoyi.mall.service.IMallFacultyInfoService;
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/mallFacultyInfo")
public class MallFacultyInfoController extends BaseController
{
    @Autowired
    private IMallFacultyInfoService mallFacultyInfoService;

    /**
     * 查询学院介绍列表
     */
    @PreAuthorize("@ss.hasPermi('mall:mallFacultyInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(MallFacultyInfo mallFacultyInfo)
    {
        startPage();
        List<MallFacultyInfo> list = mallFacultyInfoService.selectMallFacultyInfoList(mallFacultyInfo);
        return getDataTable(list);
    }

    /**
     * 导出学院介绍列表
     */
    @PreAuthorize("@ss.hasPermi('mall:mallFacultyInfo:export')")
    @Log(title = "学院介绍", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MallFacultyInfo mallFacultyInfo)
    {
        List<MallFacultyInfo> list = mallFacultyInfoService.selectMallFacultyInfoList(mallFacultyInfo);
        ExcelUtil<MallFacultyInfo> util = new ExcelUtil<MallFacultyInfo>(MallFacultyInfo.class);
        util.exportExcel(response, list, "学院介绍数据");
    }

    /**
     * 获取学院介绍详细信息
     */
    @PreAuthorize("@ss.hasPermi('mall:mallFacultyInfo:query')")
    @GetMapping(value = "/{facultyId}")
    public AjaxResult getInfo(@PathVariable("facultyId") Long facultyId)
    {
        return AjaxResult.success(mallFacultyInfoService.selectMallFacultyInfoByFacultyId(facultyId));
    }

    /**
     * 新增学院介绍
     */
    @PreAuthorize("@ss.hasPermi('mall:mallFacultyInfo:add')")
    @Log(title = "学院介绍", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MallFacultyInfo mallFacultyInfo)
    {
        return toAjax(mallFacultyInfoService.insertMallFacultyInfo(mallFacultyInfo));
    }

    /**
     * 修改学院介绍
     */
    @PreAuthorize("@ss.hasPermi('mall:mallFacultyInfo:edit')")
    @Log(title = "学院介绍", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MallFacultyInfo mallFacultyInfo)
    {
        return toAjax(mallFacultyInfoService.updateMallFacultyInfo(mallFacultyInfo));
    }

    /**
     * 删除学院介绍
     */
    @PreAuthorize("@ss.hasPermi('mall:mallFacultyInfo:remove')")
    @Log(title = "学院介绍", businessType = BusinessType.DELETE)
	@DeleteMapping("/{facultyIds}")
    public AjaxResult remove(@PathVariable Long[] facultyIds)
    {
        return toAjax(mallFacultyInfoService.deleteMallFacultyInfoByFacultyIds(facultyIds));
    }
}
