package org.dromara.art.controller;

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.art.domain.vo.ArtHistoryScoreControlLineVo;
import org.dromara.art.domain.bo.ArtHistoryScoreControlLineBo;
import org.dromara.art.service.IArtHistoryScoreControlLineService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 历年省控线
 *
 * @author ZhouWenTao
 * @date 2026-02-20
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/art/historyScoreControlLine")
public class ArtHistoryScoreControlLineController extends BaseController {

    private final IArtHistoryScoreControlLineService artHistoryScoreControlLineService;

    /**
     * 查询历年省控线列表
     */
    @SaCheckPermission("art:historyScoreControlLine:list")
    @GetMapping("/list")
    public TableDataInfo<ArtHistoryScoreControlLineVo> list(ArtHistoryScoreControlLineBo bo, PageQuery pageQuery) {
        return artHistoryScoreControlLineService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出历年省控线列表
     */
    @SaCheckPermission("art:historyScoreControlLine:export")
    @Log(title = "历年省控线", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(ArtHistoryScoreControlLineBo bo, HttpServletResponse response) {
        List<ArtHistoryScoreControlLineVo> list = artHistoryScoreControlLineService.queryList(bo);
        ExcelUtil.exportExcel(list, "历年省控线", ArtHistoryScoreControlLineVo.class, response);
    }

    /**
     * 获取历年省控线详细信息
     *
     * @param controlId 主键
     */
    @SaCheckPermission("art:historyScoreControlLine:query")
    @GetMapping("/{controlId}")
    public R<ArtHistoryScoreControlLineVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long controlId) {
        return R.ok(artHistoryScoreControlLineService.queryById(controlId));
    }

    /**
     * 新增历年省控线
     */
    @SaCheckPermission("art:historyScoreControlLine:add")
    @Log(title = "历年省控线", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ArtHistoryScoreControlLineBo bo) {
        return toAjax(artHistoryScoreControlLineService.insertByBo(bo));
    }

    /**
     * 修改历年省控线
     */
    @SaCheckPermission("art:historyScoreControlLine:edit")
    @Log(title = "历年省控线", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ArtHistoryScoreControlLineBo bo) {
        return toAjax(artHistoryScoreControlLineService.updateByBo(bo));
    }

    /**
     * 删除历年省控线
     *
     * @param controlIds 主键串
     */
    @SaCheckPermission("art:historyScoreControlLine:remove")
    @Log(title = "历年省控线", businessType = BusinessType.DELETE)
    @DeleteMapping("/{controlIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] controlIds) {
        return toAjax(artHistoryScoreControlLineService.deleteWithValidByIds(List.of(controlIds), true));
    }
}
