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.TbTeacher;
import com.ruoyi.hezhi.service.ITbTeacherService;
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-09-14
 */
@RestController
@RequestMapping("/hezhi/teacher")
public class TbTeacherController extends BaseController
{
    @Autowired
    private ITbTeacherService tbTeacherService;

    /**
     * 查询教师列表
     */
    @PreAuthorize("@ss.hasPermi('hezhi:teacher:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbTeacher tbTeacher)
    {
        startPage();
        List<TbTeacher> list = tbTeacherService.selectTbTeacherList(tbTeacher);
        return getDataTable(list);
    }

    /**
     * 导出教师列表
     */
    @PreAuthorize("@ss.hasPermi('hezhi:teacher:export')")
    @Log(title = "教师", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbTeacher tbTeacher)
    {
        List<TbTeacher> list = tbTeacherService.selectTbTeacherList(tbTeacher);
        ExcelUtil<TbTeacher> util = new ExcelUtil<TbTeacher>(TbTeacher.class);
        util.exportExcel(response, list, "教师数据");
    }

    /**
     * 获取教师详细信息
     */
    @PreAuthorize("@ss.hasPermi('hezhi:teacher:query')")
    @GetMapping(value = "/{teacherId}")
    public AjaxResult getInfo(@PathVariable("teacherId") Long teacherId)
    {
        return success(tbTeacherService.selectTbTeacherByTeacherId(teacherId));
    }

    /**
     * 新增教师
     */
    @PreAuthorize("@ss.hasPermi('hezhi:teacher:add')")
    @Log(title = "教师", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbTeacher tbTeacher)
    {
        return toAjax(tbTeacherService.insertTbTeacher(tbTeacher));
    }

    /**
     * 修改教师
     */
    @PreAuthorize("@ss.hasPermi('hezhi:teacher:edit')")
    @Log(title = "教师", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbTeacher tbTeacher)
    {
        return toAjax(tbTeacherService.updateTbTeacher(tbTeacher));
    }

    /**
     * 删除教师
     */
    @PreAuthorize("@ss.hasPermi('hezhi:teacher:remove')")
    @Log(title = "教师", businessType = BusinessType.DELETE)
	@DeleteMapping("/{teacherIds}")
    public AjaxResult remove(@PathVariable Long[] teacherIds)
    {
        return toAjax(tbTeacherService.deleteTbTeacherByTeacherIds(teacherIds));
    }

    /**
     * 所有教师列表
     * @return
     */
    @GetMapping("/getAllTeacherList")
    public AjaxResult getAllTeacherList() {
        TbTeacher tbTeacher = new TbTeacher();
        tbTeacher.setDelFlag(0);
        return AjaxResult.success(tbTeacherService.selectTbTeacherList(tbTeacher));
    }
}
