package com.ruoyi.web.controller.dz;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
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.DzTeacherClass;
import com.ruoyi.dz.service.IDzTeacherClassService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 教师班级关系Controller
 *
 * @author ruoyi
 * @date 2025-09-12
 */
@RestController
@RequestMapping("/dz/teacherclass")
public class DzTeacherClassController extends BaseController
{
    @Autowired
    private IDzTeacherClassService dzTeacherClassService;

    /**
     * 查询教师班级关系列表
     */
    @PreAuthorize("@ss.hasPermi('dz:teacherclass:list')")
    @GetMapping("/list")
    public TableDataInfo list(DzTeacherClass dzTeacherClass)
    {
        startPage();
        List<DzTeacherClass> list = dzTeacherClassService.selectDzTeacherClassList(dzTeacherClass);
        return getDataTable(list);
    }

    @GetMapping("/listAllTeacherClass")
    public AjaxResult listAllTeacherClass(DzTeacherClass dzTeacherClass)
    {
        List<DzTeacherClass> list = dzTeacherClassService.selectDzTeacherClassList(dzTeacherClass);
        return AjaxResult.success(list);
    }

    /**
     * 导出教师班级关系列表
     */
    @PreAuthorize("@ss.hasPermi('dz:teacherclass:export')")
    @Log(title = "教师班级关系", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DzTeacherClass dzTeacherClass)
    {
        List<DzTeacherClass> list = dzTeacherClassService.selectDzTeacherClassList(dzTeacherClass);
        ExcelUtil<DzTeacherClass> util = new ExcelUtil<DzTeacherClass>(DzTeacherClass.class);
        util.exportExcel(response, list, "教师班级关系数据");
    }

    /**
     * 获取教师班级关系详细信息
     */
    @PreAuthorize("@ss.hasPermi('dz:teacherclass:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(dzTeacherClassService.selectDzTeacherClassById(id));
    }

    /**
     * 新增教师班级关系
     */
    @PreAuthorize("@ss.hasPermi('dz:teacherclass:add')")
    @Log(title = "关联教师班级关系", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DzTeacherClass dzTeacherClass)
    {
        return toAjax(dzTeacherClassService.insertDzTeacherClass(dzTeacherClass));
    }

    @Log(title = "批量关联教师班级关系", businessType = BusinessType.INSERT)
    @PostMapping("/batchBindTeacherClass")
    public AjaxResult batchBindTeacherClass(@RequestBody DzTeacherClass dzTeacherClass)
    {
        dzTeacherClassService.batchBindTeacherClass(dzTeacherClass);
        return AjaxResult.success();
    }

    /**
     * 修改教师班级关系
     */
    @PreAuthorize("@ss.hasPermi('dz:teacherclass:edit')")
    @Log(title = "教师班级关系", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DzTeacherClass dzTeacherClass)
    {
        return toAjax(dzTeacherClassService.updateDzTeacherClass(dzTeacherClass));
    }

    /**
     * 删除教师班级关系
     */
    @PreAuthorize("@ss.hasPermi('dz:teacherclass:remove')")
    @Log(title = "教师班级关系", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(dzTeacherClassService.deleteDzTeacherClassByIds(ids));
    }
}
