package org.dromara.system.controller.formal;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.dromara.system.domain.vo.FormalParentsStudentVo;
import org.dromara.system.domain.vo.FormalTeacherClassListVo;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.system.domain.vo.FormalTeacherClassVo;
import org.dromara.system.domain.bo.FormalTeacherClassBo;
import org.dromara.system.service.IFormalTeacherClassService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 老师-班级（学科）(审核通过之后数据)
 *
 * @author Lion Li
 * @date 2023-08-16
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/formal/class")
public class FormalTeacherClassController extends BaseController {

    private final IFormalTeacherClassService formalTeacherClassService;

    /**
     * 查询老师-班级（学科）(审核通过之后数据)列表
     */
    @SaCheckPermission("formal:class:list")
    @GetMapping("/list")
    public TableDataInfo<FormalTeacherClassVo> list(FormalTeacherClassBo bo, PageQuery pageQuery) {
        return formalTeacherClassService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出老师-班级（学科）(审核通过之后数据)列表
     */
    @SaCheckPermission("formal:class:export")
    @Log(title = "老师-班级（学科）(审核通过之后数据)", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(FormalTeacherClassBo bo, HttpServletResponse response) {
        List<FormalTeacherClassVo> list = formalTeacherClassService.queryList(bo);
        ExcelUtil.exportExcel(list, "老师-班级（学科）(审核通过之后数据)", FormalTeacherClassVo.class, response);
    }

    /**
     * 获取老师-班级（学科）(审核通过之后数据)详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("formal:class:query")
    @GetMapping("/{id}")
    public R<FormalTeacherClassVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(formalTeacherClassService.queryById(id));
    }

    /**
     * 新增老师-班级（学科）(审核通过之后数据)
     */
    @SaCheckPermission("formal:class:add")
    @Log(title = "老师-班级（学科）(审核通过之后数据)", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody FormalTeacherClassBo bo) {
        return toAjax(formalTeacherClassService.insertByBo(bo));
    }

    /**
     * 修改老师-班级（学科）(审核通过之后数据)
     */
    @SaCheckPermission("formal:class:edit")
    @Log(title = "老师-班级（学科）(审核通过之后数据)", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PostMapping("/put")
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody FormalTeacherClassBo bo) {
        return toAjax(formalTeacherClassService.updateByBo(bo));
    }

    /**
     * 批量修改老师-班级（学科）(审核通过之后数据)
     */
    @SaCheckPermission("formal:class:editAll")
    @Log(title = "老师-班级（学科）(审核通过之后数据)", businessType = BusinessType.UPDATE)
    @PostMapping("/put/All")
    public R<Void> editAll(@RequestBody FormalTeacherClassListVo formalTeacherClassListVo) {
        return formalTeacherClassService.updateFormalTeacherClassList(formalTeacherClassListVo);
    }

    /**
     * 删除老师-班级（学科）(审核通过之后数据)
     *
     * @param ids 主键串
     */
    @SaCheckPermission("formal:class:remove")
    @Log(title = "老师-班级（学科）(审核通过之后数据)", businessType = BusinessType.DELETE)
    @GetMapping("/delete/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(formalTeacherClassService.deleteWithValidByIds(List.of(ids), true));
    }

    /***
     * 查询老师信息（用于档案信息新增）
     */
    @GetMapping("/noPage/list")
    public TableDataInfo<FormalTeacherClassVo> noPage(FormalTeacherClassBo bo) {
        return formalTeacherClassService.selectFormalTeacherClassListNoPage(bo);
    }
}
