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.StudentLiveOldVo;
import org.dromara.system.domain.bo.StudentLiveOldBo;
import org.dromara.system.service.IStudentLiveOldService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

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

    private final IStudentLiveOldService studentLiveOldService;

    /**
     * 查询学生生活历史信息列表
     */
    @SaCheckPermission("live:old:list")
    @GetMapping("/list")
    public TableDataInfo<StudentLiveOldVo> list(StudentLiveOldBo bo, PageQuery pageQuery) {
        return studentLiveOldService.queryPageList(bo, pageQuery);
    }

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

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

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

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

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