package com.ruoyi.web.controller.dz;

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

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.dz.service.IDzTeacherClassService;
import com.ruoyi.enums.UserTypeEnum;
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.dz.domain.DzTeacher;
import com.ruoyi.dz.service.IDzTeacherService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 老师Controller
 *
 * @author ruoyi
 * @date 2025-09-12
 */
@RestController
@RequestMapping("/dz/teacher")
public class DzTeacherController extends BaseController
{
    @Autowired
    private IDzTeacherService dzTeacherService;
    @Autowired
    private IDzTeacherClassService teacherClassService;

    /**
     * 查询老师列表
     */
    @PreAuthorize("@ss.hasPermi('dz:teacher:list')")
    @GetMapping("/list")
    public TableDataInfo list(DzTeacher dzTeacher)
    {
        if(!UserTypeEnum.isSys(SecurityUtils.getLoginUser().getUser().getUserType())){
            dzTeacher.setDeptId(SecurityUtils.getLoginUser().getUser().getDeptId());
        }
        startPage();
        List<DzTeacher> list = dzTeacherService.selectDzTeacherList(dzTeacher);
        return getDataTable(list);
    }

    /**
     * 导出老师列表
     */
    @PreAuthorize("@ss.hasPermi('dz:teacher:export')")
    @Log(title = "老师", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DzTeacher dzTeacher)
    {
        List<DzTeacher> list = dzTeacherService.selectDzTeacherList(dzTeacher);
        ExcelUtil<DzTeacher> util = new ExcelUtil<DzTeacher>(DzTeacher.class);
        util.exportExcel(response, list, "老师数据");
    }

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

    /**
     * 新增老师
     */
    @PreAuthorize("@ss.hasPermi('dz:teacher:add')")
    @Log(title = "老师", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DzTeacher dzTeacher)
    {
        return toAjax(dzTeacherService.insertDzTeacher(dzTeacher));
    }

    /**
     * 修改老师
     */
    @PreAuthorize("@ss.hasPermi('dz:teacher:edit')")
    @Log(title = "老师", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DzTeacher dzTeacher)
    {
        return toAjax(dzTeacherService.updateDzTeacher(dzTeacher));
    }

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