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.StudentMindOldVo;
import org.dromara.system.domain.bo.StudentMindOldBo;
import org.dromara.system.service.IStudentMindOldService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 学生心理健康历史信息
 *
 * @author Lion Li
 * @date 2023-08-16
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/mind/old")
public class StudentMindOldController extends BaseController {

    private final IStudentMindOldService studentMindOldService;

    /**
     * 查询学生心理健康历史信息列表
     */
    @SaCheckPermission("mind:old:list")
    @GetMapping("/list")
    public TableDataInfo<StudentMindOldVo> list(StudentMindOldBo bo, PageQuery pageQuery) {
        return studentMindOldService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出学生心理健康历史信息列表
     */
    @SaCheckPermission("mind:old:export")
    @Log(title = "学生心理健康历史信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(StudentMindOldBo bo, HttpServletResponse response) {
        List<StudentMindOldVo> list = studentMindOldService.queryList(bo);
        ExcelUtil.exportExcel(list, "学生心理健康历史信息", StudentMindOldVo.class, response);
    }

    /**
     * 获取学生心理健康历史信息详细信息
     *
     * @param mindId 主键
     */
    @SaCheckPermission("mind:old:query")
    @GetMapping("/{mindId}")
    public R<StudentMindOldVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long mindId) {
        return R.ok(studentMindOldService.queryById(mindId));
    }

    /**
     * 新增学生心理健康历史信息
     */
    @SaCheckPermission("mind:old:add")
    @Log(title = "学生心理健康历史信息", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody StudentMindOldBo bo) {
        return toAjax(studentMindOldService.insertByBo(bo));
    }

    /**
     * 修改学生心理健康历史信息
     */
    @SaCheckPermission("mind:old:edit")
    @Log(title = "学生心理健康历史信息", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PostMapping("/put")
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody StudentMindOldBo bo) {
        return toAjax(studentMindOldService.updateByBo(bo));
    }

    /**
     * 删除学生心理健康历史信息
     *
     * @param mindIds 主键串
     */
    @SaCheckPermission("mind:old:remove")
    @Log(title = "学生心理健康历史信息", businessType = BusinessType.DELETE)
    @GetMapping("/delete/{mindIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] mindIds) {
        return toAjax(studentMindOldService.deleteWithValidByIds(List.of(mindIds), true));
    }
}
