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.ArtSchoolEnrollPlanVo;
import org.dromara.art.domain.bo.ArtSchoolEnrollPlanBo;
import org.dromara.art.service.IArtSchoolEnrollPlanService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 学校招生计划
 *
 * @author ZhouWenTao
 * @date 2026-02-17
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/art/schoolEnrollPlan")
public class ArtSchoolEnrollPlanController extends BaseController {

    private final IArtSchoolEnrollPlanService artSchoolEnrollPlanService;

    /**
     * 查询学校招生计划列表
     */
    @SaCheckPermission("art:schoolEnrollPlan:list")
    @GetMapping("/list")
    public TableDataInfo<ArtSchoolEnrollPlanVo> list(ArtSchoolEnrollPlanBo bo, PageQuery pageQuery) {
        return artSchoolEnrollPlanService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出学校招生计划列表
     */
    @SaCheckPermission("art:schoolEnrollPlan:export")
    @Log(title = "学校招生计划", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(ArtSchoolEnrollPlanBo bo, HttpServletResponse response) {
        List<ArtSchoolEnrollPlanVo> list = artSchoolEnrollPlanService.queryList(bo);
        ExcelUtil.exportExcel(list, "学校招生计划", ArtSchoolEnrollPlanVo.class, response);
    }

    /**
     * 获取学校招生计划详细信息
     *
     * @param planId 主键
     */
    @SaCheckPermission("art:schoolEnrollPlan:query")
    @GetMapping("/{planId}")
    public R<ArtSchoolEnrollPlanVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long planId) {
        return R.ok(artSchoolEnrollPlanService.queryById(planId));
    }

    /**
     * 新增学校招生计划
     */
    @SaCheckPermission("art:schoolEnrollPlan:add")
    @Log(title = "学校招生计划", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ArtSchoolEnrollPlanBo bo) {
        return toAjax(artSchoolEnrollPlanService.insertByBo(bo));
    }

    /**
     * 修改学校招生计划
     */
    @SaCheckPermission("art:schoolEnrollPlan:edit")
    @Log(title = "学校招生计划", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ArtSchoolEnrollPlanBo bo) {
        return toAjax(artSchoolEnrollPlanService.updateByBo(bo));
    }

    /**
     * 删除学校招生计划
     *
     * @param planIds 主键串
     */
    @SaCheckPermission("art:schoolEnrollPlan:remove")
    @Log(title = "学校招生计划", businessType = BusinessType.DELETE)
    @DeleteMapping("/{planIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] planIds) {
        return toAjax(artSchoolEnrollPlanService.deleteWithValidByIds(List.of(planIds), true));
    }
}
