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.ArtSchoolRecruitMajorVo;
import org.dromara.art.domain.bo.ArtSchoolRecruitMajorBo;
import org.dromara.art.service.IArtSchoolRecruitMajorService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 院校招录专业
 *
 * @author ZhouWenTao
 * @date 2026-02-20
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/art/schoolRecruitMajor")
public class ArtSchoolRecruitMajorController extends BaseController {

    private final IArtSchoolRecruitMajorService artSchoolRecruitMajorService;

    /**
     * 查询院校招录专业列表
     */
    @SaCheckPermission("art:schoolRecruitMajor:list")
    @GetMapping("/list")
    public TableDataInfo<ArtSchoolRecruitMajorVo> list(ArtSchoolRecruitMajorBo bo, PageQuery pageQuery) {
        return artSchoolRecruitMajorService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出院校招录专业列表
     */
    @SaCheckPermission("art:schoolRecruitMajor:export")
    @Log(title = "院校招录专业", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(ArtSchoolRecruitMajorBo bo, HttpServletResponse response) {
        List<ArtSchoolRecruitMajorVo> list = artSchoolRecruitMajorService.queryList(bo);
        ExcelUtil.exportExcel(list, "院校招录专业", ArtSchoolRecruitMajorVo.class, response);
    }

    /**
     * 获取院校招录专业详细信息
     *
     * @param recruitMajorId 主键
     */
    @SaCheckPermission("art:schoolRecruitMajor:query")
    @GetMapping("/{recruitMajorId}")
    public R<ArtSchoolRecruitMajorVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long recruitMajorId) {
        return R.ok(artSchoolRecruitMajorService.queryById(recruitMajorId));
    }

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

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

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