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.ArtSchoolRecruitMajorHistoryVo;
import org.dromara.art.domain.bo.ArtSchoolRecruitMajorHistoryBo;
import org.dromara.art.service.IArtSchoolRecruitMajorHistoryService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 院校招录专业历年录取数据
 *
 * @author ZhouWenTao
 * @date 2026-02-20
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/art/schoolRecruitMajorHistory")
public class ArtSchoolRecruitMajorHistoryController extends BaseController {

    private final IArtSchoolRecruitMajorHistoryService artSchoolRecruitMajorHistoryService;

    /**
     * 查询院校招录专业历年录取数据列表
     */
    @SaCheckPermission("art:schoolRecruitMajorHistory:list")
    @GetMapping("/list")
    public TableDataInfo<ArtSchoolRecruitMajorHistoryVo> list(ArtSchoolRecruitMajorHistoryBo bo, PageQuery pageQuery) {
        return artSchoolRecruitMajorHistoryService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出院校招录专业历年录取数据列表
     */
    @SaCheckPermission("art:schoolRecruitMajorHistory:export")
    @Log(title = "院校招录专业历年录取数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(ArtSchoolRecruitMajorHistoryBo bo, HttpServletResponse response) {
        List<ArtSchoolRecruitMajorHistoryVo> list = artSchoolRecruitMajorHistoryService.queryList(bo);
        ExcelUtil.exportExcel(list, "院校招录专业历年录取数据", ArtSchoolRecruitMajorHistoryVo.class, response);
    }

    /**
     * 获取院校招录专业历年录取数据详细信息
     *
     * @param historyId 主键
     */
    @SaCheckPermission("art:schoolRecruitMajorHistory:query")
    @GetMapping("/{historyId}")
    public R<ArtSchoolRecruitMajorHistoryVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long historyId) {
        return R.ok(artSchoolRecruitMajorHistoryService.queryById(historyId));
    }

    /**
     * 新增院校招录专业历年录取数据
     */
    @SaCheckPermission("art:schoolRecruitMajorHistory:add")
    @Log(title = "院校招录专业历年录取数据", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ArtSchoolRecruitMajorHistoryBo bo) {
        return toAjax(artSchoolRecruitMajorHistoryService.insertByBo(bo));
    }

    /**
     * 修改院校招录专业历年录取数据
     */
    @SaCheckPermission("art:schoolRecruitMajorHistory:edit")
    @Log(title = "院校招录专业历年录取数据", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ArtSchoolRecruitMajorHistoryBo bo) {
        return toAjax(artSchoolRecruitMajorHistoryService.updateByBo(bo));
    }

    /**
     * 删除院校招录专业历年录取数据
     *
     * @param historyIds 主键串
     */
    @SaCheckPermission("art:schoolRecruitMajorHistory:remove")
    @Log(title = "院校招录专业历年录取数据", businessType = BusinessType.DELETE)
    @DeleteMapping("/{historyIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] historyIds) {
        return toAjax(artSchoolRecruitMajorHistoryService.deleteWithValidByIds(List.of(historyIds), true));
    }
}
