package org.dromara.system.controller.info;

import java.util.List;
import java.util.Map;

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

/**
 * 学生档案历史信息
 *
 * @author Lion Li
 * @date 2023-08-16
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/student/old")
public class StudentInfoOldController extends BaseController {

    private final IStudentInfoOldService studentInfoOldService;

    /**
     * 查询学生档案历史信息列表
     */
    @SaCheckPermission("student:old:list")
    @GetMapping("/list")
    public TableDataInfo<StudentInfoOldVo> list(StudentInfoOldBo bo, PageQuery pageQuery) {
        return studentInfoOldService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出学生档案历史信息列表
     */
    @SaCheckPermission("student:old:export")
    @Log(title = "学生档案历史信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(StudentInfoOldBo bo, HttpServletResponse response) {
        List<StudentInfoOldVo> list = studentInfoOldService.queryList(bo);
        ExcelUtil.exportExcel(list, "学生档案历史信息", StudentInfoOldVo.class, response);
    }

    /**
     * 获取学生档案历史信息详细信息
     *
     * @param oldId 主键
     */
    @SaCheckPermission("student:old:query")
    @GetMapping("/{oldId}")
    public R<StudentInfoOldVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long oldId) {
        return R.ok(studentInfoOldService.queryById(oldId));
    }

    /**
     * 新增学生档案历史信息
     */
    @SaCheckPermission("student:old:add")
    @Log(title = "学生档案历史信息", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody StudentInfoOldBo bo) {
        return toAjax(studentInfoOldService.insertByBo(bo));
    }

    /**
     * 修改学生档案历史信息
     */
    @SaCheckPermission("student:old:edit")
    @Log(title = "学生档案历史信息", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PostMapping("/put")
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody StudentInfoOldBo bo) {
        return toAjax(studentInfoOldService.updateByBo(bo));
    }

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

    /**
     * 查询学生档案历史信息列表
     */
    @GetMapping("/echarts")
    public R<Map<String, Object>> echarts(StudentLiveOldBo bo)
    {
        return studentInfoOldService.selectStudentInfoOldListEcharts(bo);
    }
}
