package com.ruoyi.web.controller.info;

import java.util.Arrays;
import java.util.List;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;

import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
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.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.info.management.domain.bo.ManagementTeacherBo;
import com.ruoyi.info.management.domain.bo.ManagementTeacherPageReqBo;
import com.ruoyi.info.management.domain.vo.ManagementTeacherVo;
import com.ruoyi.info.management.service.IManagementTeacherService;
import com.ruoyi.info.nursing.domain.bo.EnableStatusBo;

import cn.dev33.satoken.annotation.SaCheckPermission;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;

/**
 * 管理老师信息Controller
 *
 * @author baifc
 * @date 2025-09-30
 */
@Validated
@Api(value = "管理老师信息控制器", tags = {"管理老师信息管理"})
@RequiredArgsConstructor
@RestController
@RequestMapping("/info/managementTeacher")
public class ManagementTeacherController extends BaseController {

    private final IManagementTeacherService iManagementTeacherService;

    /**
     * 分页查询管理老师信息列表
     */
    @ApiOperation("查询管理老师信息列表")
    @SaCheckPermission("info:managementTeacher:list")
    @GetMapping("/page")
    public TableDataInfo<ManagementTeacherVo> page(@Validated(QueryGroup.class) ManagementTeacherPageReqBo bo, PageQuery pageQuery) {
        return iManagementTeacherService.queryPageList(bo, pageQuery);
    }

    /**
     * 获取管理老师信息详细信息
     */
    @ApiOperation("获取管理老师信息详细信息")
    @SaCheckPermission("info:managementTeacher:query")
    @GetMapping("/info/{id}")
    public R<ManagementTeacherVo> getInfo(@ApiParam("主键")
                                                  @NotNull(message = "主键不能为空")
                                                  @PathVariable("id") Long id) {
        return R.ok(iManagementTeacherService.queryById(id));
    }

    /**
     * 新增管理老师信息
     */
    @ApiOperation("新增管理老师信息")
    @SaCheckPermission("info:managementTeacher:add")
    @Log(title = "管理老师信息", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping("/add")
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ManagementTeacherBo bo) {
        return toAjax(iManagementTeacherService.insertByBo(bo) ? 1 : 0);
    }

    /**
     * 修改管理老师信息
     */
    @ApiOperation("修改管理老师信息")
    @SaCheckPermission("info:managementTeacher:edit")
    @Log(title = "管理老师信息", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PostMapping("/edit")
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ManagementTeacherBo bo) {
        return toAjax(iManagementTeacherService.updateByBo(bo) ? 1 : 0);
    }

    /**
     * 启用/禁用 管理老师
     */
    @ApiOperation("启用/禁用 管理老师")
    @SaCheckPermission("info:managementTeacher:edit")
    @Log(title = "管理老师信息", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PostMapping("/update-status")
    public R<Void> updateStatus(@Validated @RequestBody EnableStatusBo bo) {
        iManagementTeacherService.updateStatus(bo);
        return R.ok();
    }

    /**
     * 删除管理老师信息
     */
    @ApiOperation("删除管理老师信息")
    @SaCheckPermission("info:managementTeacher:remove")
    @Log(title = "管理老师信息", businessType = BusinessType.DELETE)
    @PostMapping("/del/{ids}")
    public R<Void> remove(@ApiParam("主键串")
                                       @NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] ids) {
        return toAjax(iManagementTeacherService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }

    /**
     * 导出管理老师信息列表
     */
    @ApiOperation("导出管理老师信息列表")
    @SaCheckPermission("info:managementTeacher:export")
    @Log(title = "管理老师信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(@Validated ManagementTeacherBo bo, HttpServletResponse response) {
        List<ManagementTeacherVo> list = iManagementTeacherService.queryList(bo);
        ExcelUtil.exportExcel(list, "管理老师信息", ManagementTeacherVo.class, response);
    }

}
