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.ScoreDataMfBo;
import org.dromara.system.domain.score.vo.ScoreDataMfVo;
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.service.IScoreDataMfService;

/**
 * 成绩满分
 *
 * @author boman
 * @date 2023-08-22
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/dataMf")
public class ScoreDataMfController extends BaseController {

    private final IScoreDataMfService scoreDataMfService;

    /**
     * 查询成绩满分列表
     */
    @SaCheckPermission("system:dataMf:list")
    @GetMapping("/list")
    public TableDataInfo<ScoreDataMfVo> list(ScoreDataMfBo bo, PageQuery pageQuery) {
        return scoreDataMfService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出成绩满分列表
     */
    @SaCheckPermission("system:dataMf:export")
    @Log(title = "成绩满分", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(ScoreDataMfBo bo, HttpServletResponse response) {
        List<ScoreDataMfVo> list = scoreDataMfService.queryList(bo);
        ExcelUtil.exportExcel(list, "成绩满分", ScoreDataMfVo.class, response);
    }

    /**
     * 获取成绩满分详细信息
     *
     * @param mfId 主键
     */
    @SaCheckPermission("system:dataMf:query")
    @GetMapping("/{mfId}")
    public R<ScoreDataMfVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long mfId) {
        return R.ok(scoreDataMfService.queryById(mfId));
    }

    /**
     * 新增成绩满分
     */
    @SaCheckPermission("system:dataMf:add")
    @Log(title = "成绩满分", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ScoreDataMfBo bo) {
        return toAjax(scoreDataMfService.insertByBo(bo));
    }

    /**
     * 修改成绩满分
     */
    @SaCheckPermission("system:dataMf:edit")
    @Log(title = "成绩满分", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PostMapping("/put")
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ScoreDataMfBo bo) {
        return toAjax(scoreDataMfService.updateByBo(bo));
    }

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