package com.ruoyi.mall.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
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.MallSubjectClass;
import com.ruoyi.mall.service.IMallSubjectClassService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 学科Controller
 * 
 * @author ruoyi
 * @date 2023-10-27
 */
@RestController
@RequestMapping("/mall/mallSubjectClass")
public class MallSubjectClassController extends BaseController
{
    @Autowired
    private IMallSubjectClassService mallSubjectClassService;

    /**
     * 查询学科列表
     */
    @PreAuthorize("@ss.hasPermi('mall:mallSubjectClass:list')")
    @GetMapping("/list")
    public TableDataInfo list(MallSubjectClass mallSubjectClass)
    {
        startPage();
        List<MallSubjectClass> list = mallSubjectClassService.selectMallSubjectClassList(mallSubjectClass);
        return getDataTable(list);
    }

    /**
     * 导出学科列表
     */
    @PreAuthorize("@ss.hasPermi('mall:mallSubjectClass:export')")
    @Log(title = "学科", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MallSubjectClass mallSubjectClass)
    {
        List<MallSubjectClass> list = mallSubjectClassService.selectMallSubjectClassList(mallSubjectClass);
        ExcelUtil<MallSubjectClass> util = new ExcelUtil<MallSubjectClass>(MallSubjectClass.class);
        util.exportExcel(response, list, "学科数据");
    }

    /**
     * 获取学科详细信息
     */
    @PreAuthorize("@ss.hasPermi('mall:mallSubjectClass:query')")
    @GetMapping(value = "/{subjectId}")
    public AjaxResult getInfo(@PathVariable("subjectId") Long subjectId)
    {
        return AjaxResult.success(mallSubjectClassService.selectMallSubjectClassBySubjectId(subjectId));
    }

    /**
     * 新增学科
     */
    @PreAuthorize("@ss.hasPermi('mall:mallSubjectClass:add')")
    @Log(title = "学科", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MallSubjectClass mallSubjectClass)
    {
        return toAjax(mallSubjectClassService.insertMallSubjectClass(mallSubjectClass));
    }

    /**
     * 修改学科
     */
    @PreAuthorize("@ss.hasPermi('mall:mallSubjectClass:edit')")
    @Log(title = "学科", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MallSubjectClass mallSubjectClass)
    {
        return toAjax(mallSubjectClassService.updateMallSubjectClass(mallSubjectClass));
    }

    /**
     * 删除学科
     */
    @PreAuthorize("@ss.hasPermi('mall:mallSubjectClass:remove')")
    @Log(title = "学科", businessType = BusinessType.DELETE)
	@DeleteMapping("/{subjectIds}")
    public AjaxResult remove(@PathVariable Long[] subjectIds)
    {
        return toAjax(mallSubjectClassService.deleteMallSubjectClassBySubjectIds(subjectIds));
    }
}
