package com.ruoyi.hezhi.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.hezhi.domain.TbMajorClass;
import com.ruoyi.hezhi.service.ITbMajorClassService;
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 ruoyi
 * @date 2024-10-16
 */
@RestController
@RequestMapping("/hezhi/majorClass")
public class TbMajorClassController extends BaseController
{
    @Autowired
    private ITbMajorClassService tbMajorClassService;

    /**
     * 查询专业分类列表
     */
    @PreAuthorize("@ss.hasPermi('hezhi:majorClass:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbMajorClass tbMajorClass)
    {
        startPage();
        List<TbMajorClass> list = tbMajorClassService.selectTbMajorClassList(tbMajorClass);
        return getDataTable(list);
    }

    /**
     * 导出专业分类列表
     */
    @PreAuthorize("@ss.hasPermi('hezhi:majorClass:export')")
    @Log(title = "专业分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbMajorClass tbMajorClass)
    {
        List<TbMajorClass> list = tbMajorClassService.selectTbMajorClassList(tbMajorClass);
        ExcelUtil<TbMajorClass> util = new ExcelUtil<TbMajorClass>(TbMajorClass.class);
        util.exportExcel(response, list, "专业分类数据");
    }

    /**
     * 获取专业分类详细信息
     */
    @PreAuthorize("@ss.hasPermi('hezhi:majorClass:query')")
    @GetMapping(value = "/{majorId}")
    public AjaxResult getInfo(@PathVariable("majorId") Long majorId)
    {
        return success(tbMajorClassService.selectTbMajorClassByMajorId(majorId));
    }

    /**
     * 新增专业分类
     */
    @PreAuthorize("@ss.hasPermi('hezhi:majorClass:add')")
    @Log(title = "专业分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbMajorClass tbMajorClass)
    {
        return toAjax(tbMajorClassService.insertTbMajorClass(tbMajorClass));
    }

    /**
     * 修改专业分类
     */
    @PreAuthorize("@ss.hasPermi('hezhi:majorClass:edit')")
    @Log(title = "专业分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbMajorClass tbMajorClass)
    {
        return toAjax(tbMajorClassService.updateTbMajorClass(tbMajorClass));
    }

    /**
     * 删除专业分类
     */
    @PreAuthorize("@ss.hasPermi('hezhi:majorClass:remove')")
    @Log(title = "专业分类", businessType = BusinessType.DELETE)
    @DeleteMapping("/{majorIds}")
    public AjaxResult remove(@PathVariable Long[] majorIds)
    {
        return toAjax(tbMajorClassService.deleteTbMajorClassByMajorIds(majorIds));
    }

    /**
     * 查询专业分类列表-下拉框树列表
     */
    @GetMapping("/getAllMajorClassList")
    public AjaxResult getAllMajorClassList()
    {
        return AjaxResult.success(tbMajorClassService.getAllMajorClassList());
    }
}
