package org.dromara.system.controller.score;

import java.util.List;

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

/**
 * 成绩_成绩详情id
 *
 * @author boman
 * @date 2023-08-17
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/dataDetail")
public class ScoreDataDetailController extends BaseController {

    private final IScoreDataDetailService scoreDataDetailService;

    /**
     * 查询成绩_成绩详情id列表
     */
    @SaCheckPermission("system:dataDetail:list")
    @GetMapping("/list")
    public TableDataInfo<ScoreDataDetailVo> list(ScoreDataDetailBo bo, PageQuery pageQuery) {
        return scoreDataDetailService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出成绩_成绩详情id列表
     */
    @SaCheckPermission("system:dataDetail:export")
    @Log(title = "成绩_成绩详情id", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(ScoreDataDetailBo bo, HttpServletResponse response) {
        List<ScoreDataDetailVo> list = scoreDataDetailService.queryList(bo);
        ExcelUtil.exportExcel(list, "成绩_成绩详情id", ScoreDataDetailVo.class, response);
    }

    /**
     * 获取成绩_成绩详情id详细信息
     *
     * @param scoreDetailId 主键
     */
    @SaCheckPermission("system:dataDetail:query")
    @GetMapping("/{scoreDetailId}")
    public R<ScoreDataDetailVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long scoreDetailId) {
        return R.ok(scoreDataDetailService.queryById(scoreDetailId));
    }

    /**
     * 新增成绩_成绩详情id
     */
    @SaCheckPermission("system:dataDetail:add")
    @Log(title = "成绩_成绩详情id", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ScoreDataDetailBo bo) {
        return toAjax(scoreDataDetailService.insertByBo(bo));
    }

    /**
     * 修改成绩_成绩详情id
     */
    @SaCheckPermission("system:dataDetail:edit")
    @Log(title = "成绩_成绩详情id", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PostMapping("/put")
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ScoreDataDetailBo bo) {
        return toAjax(scoreDataDetailService.updateByBo(bo));
    }

    /**
     * 删除成绩_成绩详情id
     *
     * @param scoreDetailIds 主键串
     */
    @SaCheckPermission("system:dataDetail:remove")
    @Log(title = "成绩_成绩详情id", businessType = BusinessType.DELETE)
    @GetMapping("/delete/{scoreDetailIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] scoreDetailIds) {
        return toAjax(scoreDataDetailService.deleteWithValidByIds(List.of(scoreDetailIds), true));
    }
}
