package com.ruoyi.sim.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.sim.service.impl.MajorService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
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.sim.domain.Major;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 专业Controller
 *
 * @author tom
 * @date 2024-12-10
 */
@RestController
@RequestMapping("/sim/major")
@Api("专业Controller")
public class MajorController extends BaseController {
    @Autowired
    private MajorService majorService;

    /**
     * 查询专业列表
     */
    // @PreAuthorize("@ss.hasPermi('sim:major:list')")
    @GetMapping("/list")
    @ApiOperation("查询专业列表")
    public TableDataInfo list(Major major) {
        startPage();
        List<Major> list = majorService.selectMajorList(major);
        return getDataTable(list);
    }

    /**
     * 导出专业列表
     */
    // @PreAuthorize("@ss.hasPermi('sim:major:export')")
    @Log(title = "专业", businessType = BusinessType.EXPORT)
    // @PostMapping("/export")
    public void export(HttpServletResponse response, Major major) {
        List<Major> list = majorService.selectMajorList(major);
        ExcelUtil<Major> util = new ExcelUtil<Major>(Major.class);
        util.exportExcel(response, list, "专业数据");
    }

    /**
     * 获取专业详细信息
     */
    // @PreAuthorize("@ss.hasPermi('sim:major:query')")
    @GetMapping(value = "/{majorId}")
    @ApiOperation("获取专业详细信息")
    public AjaxResult getInfo(@PathVariable("majorId") Long majorId) {
        return success(majorService.selectMajorByMajorId(majorId));
    }

    /**
     * 新增专业
     */
    // @PreAuthorize("@ss.hasPermi('sim:major:add')")
    @Log(title = "专业", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增专业")
    public AjaxResult add(@RequestBody Major major) {
        return toAjax(majorService.insertMajor(major));
    }

    /**
     * 修改专业
     */
    // @PreAuthorize("@ss.hasPermi('sim:major:edit')")
    @Log(title = "专业", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改专业")
    public AjaxResult edit(@RequestBody Major major) {
        return toAjax(majorService.updateMajor(major));
    }

    /**
     * 删除专业
     */
    // @PreAuthorize("@ss.hasPermi('sim:major:remove')")
    @Log(title = "专业", businessType = BusinessType.DELETE)
    @DeleteMapping("/{majorIds}")
    @ApiOperation("删除专业")
    public AjaxResult remove(@PathVariable Long[] majorIds) {
        return toAjax(majorService.deleteMajorByMajorIds(majorIds));
    }

    // -------------------------------- tom add  --------------------------------
}
