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.ArtSchoolCollegeVo;
import org.dromara.art.domain.bo.ArtSchoolCollegeBo;
import org.dromara.art.service.IArtSchoolCollegeService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 学校学院
 *
 * @author ZhouWenTao
 * @date 2026-02-17
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/art/schoolCollege")
public class ArtSchoolCollegeController extends BaseController {

    private final IArtSchoolCollegeService artSchoolCollegeService;

    /**
     * 查询学校学院列表
     */
    @SaCheckPermission("art:schoolCollege:list")
    @GetMapping("/list")
    public TableDataInfo<ArtSchoolCollegeVo> list(ArtSchoolCollegeBo bo, PageQuery pageQuery) {
        return artSchoolCollegeService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出学校学院列表
     */
    @SaCheckPermission("art:schoolCollege:export")
    @Log(title = "学校学院", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(ArtSchoolCollegeBo bo, HttpServletResponse response) {
        List<ArtSchoolCollegeVo> list = artSchoolCollegeService.queryList(bo);
        ExcelUtil.exportExcel(list, "学校学院", ArtSchoolCollegeVo.class, response);
    }

    /**
     * 获取学校学院详细信息
     *
     * @param collegeId 主键
     */
    @SaCheckPermission("art:schoolCollege:query")
    @GetMapping("/{collegeId}")
    public R<ArtSchoolCollegeVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long collegeId) {
        return R.ok(artSchoolCollegeService.queryById(collegeId));
    }

    /**
     * 新增学校学院
     */
    @SaCheckPermission("art:schoolCollege:add")
    @Log(title = "学校学院", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ArtSchoolCollegeBo bo) {
        return toAjax(artSchoolCollegeService.insertByBo(bo));
    }

    /**
     * 修改学校学院
     */
    @SaCheckPermission("art:schoolCollege:edit")
    @Log(title = "学校学院", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ArtSchoolCollegeBo bo) {
        return toAjax(artSchoolCollegeService.updateByBo(bo));
    }

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