package org.dromara.system.controller.info;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
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.TeacherInfoVo;
import org.dromara.system.domain.bo.TeacherInfoBo;
import org.dromara.system.service.ITeacherInfoService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 老师档案信息
 *
 * @author boman
 * @date 2023-08-16
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/teacher/info")
public class TeacherInfoController extends BaseController {

    private final ITeacherInfoService teacherInfoService;

    /**
     * 查询老师档案信息列表
     */
    @SaCheckPermission("teacher:info:list")
    @GetMapping("/list")
    public TableDataInfo<TeacherInfoVo> list(TeacherInfoBo bo, PageQuery pageQuery) {
        return teacherInfoService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出老师档案信息列表
     */
    @SaCheckPermission("teacher:info:export")
    @Log(title = "老师档案信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(TeacherInfoBo bo, HttpServletResponse response) {
        List<TeacherInfoVo> list = teacherInfoService.queryList(bo);
        ExcelUtil.exportExcel(list, "老师档案信息", TeacherInfoVo.class, response);
    }

    /**
     * 获取老师档案信息详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("teacher:info:query")
    @GetMapping("/{id}")
    public R<TeacherInfoVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(teacherInfoService.queryById(id));
    }

    /**
     * 新增老师档案信息
     */
    @SaCheckPermission("teacher:info:add")
    @Log(title = "老师档案信息", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody TeacherInfoBo bo) {
        return teacherInfoService.insertByBo(bo);
    }

    /**
     * 修改老师档案信息
     */
    @SaCheckPermission("teacher:info:edit")
    @Log(title = "老师档案信息", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PostMapping("/put")
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody TeacherInfoBo bo) {
        return toAjax(teacherInfoService.updateByBo(bo));
    }

    /**
     * 删除老师档案信息
     *
     * @param ids 主键串
     */
    @SaCheckPermission("teacher:info:remove")
    @Log(title = "老师档案信息", businessType = BusinessType.DELETE)
    @GetMapping("/delete/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(teacherInfoService.deleteWithValidByIds(List.of(ids), true));
    }
}
