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.TbMemberMajor;
import com.ruoyi.hezhi.service.ITbMemberMajorService;
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-11-29
 */
@RestController
@RequestMapping("/hezhi/memberMajor")
public class TbMemberMajorController extends BaseController
{
    @Autowired
    private ITbMemberMajorService tbMemberMajorService;

    /**
     * 查询用户题库专业列表
     */
    @PreAuthorize("@ss.hasPermi('hezhi:memberMajor:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbMemberMajor tbMemberMajor)
    {
        startPage();
        List<TbMemberMajor> list = tbMemberMajorService.selectTbMemberMajorList(tbMemberMajor);
        return getDataTable(list);
    }

    /**
     * 导出用户题库专业列表
     */
    @PreAuthorize("@ss.hasPermi('hezhi:memberMajor:export')")
    @Log(title = "用户题库专业", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbMemberMajor tbMemberMajor)
    {
        List<TbMemberMajor> list = tbMemberMajorService.selectTbMemberMajorList(tbMemberMajor);
        ExcelUtil<TbMemberMajor> util = new ExcelUtil<TbMemberMajor>(TbMemberMajor.class);
        util.exportExcel(response, list, "用户题库专业数据");
    }

    /**
     * 获取用户题库专业详细信息
     */
    @PreAuthorize("@ss.hasPermi('hezhi:memberMajor:query')")
    @GetMapping(value = "/{memberMajorId}")
    public AjaxResult getInfo(@PathVariable("memberMajorId") Long memberMajorId)
    {
        return success(tbMemberMajorService.selectTbMemberMajorByMemberMajorId(memberMajorId));
    }

    /**
     * 新增用户题库专业
     */
    @PreAuthorize("@ss.hasPermi('hezhi:memberMajor:add')")
    @Log(title = "用户题库专业", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbMemberMajor tbMemberMajor)
    {
        return toAjax(tbMemberMajorService.insertTbMemberMajor(tbMemberMajor));
    }

    /**
     * 修改用户题库专业
     */
    @PreAuthorize("@ss.hasPermi('hezhi:memberMajor:edit')")
    @Log(title = "用户题库专业", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbMemberMajor tbMemberMajor)
    {
        return toAjax(tbMemberMajorService.updateTbMemberMajor(tbMemberMajor));
    }

    /**
     * 删除用户题库专业
     */
    @PreAuthorize("@ss.hasPermi('hezhi:memberMajor:remove')")
    @Log(title = "用户题库专业", businessType = BusinessType.DELETE)
	@DeleteMapping("/{memberMajorIds}")
    public AjaxResult remove(@PathVariable Long[] memberMajorIds)
    {
        return toAjax(tbMemberMajorService.deleteTbMemberMajorByMemberMajorIds(memberMajorIds));
    }
}
