package org.dromara.system.controller.school;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.system.domain.school.bo.SysSchoolNameBo;
import org.dromara.system.domain.school.vo.SysSchoolNameVo;
import org.dromara.system.service.school.ISysSchoolNameService;
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;

/**
 * 学校名称
 *
 * @author boman
 * @date 2023-08-21
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/schoolName")
public class SysSchoolNameController extends BaseController {

    private final ISysSchoolNameService sysSchoolNameService;

    /**
     * 查询学校名称列表
     */
    @SaCheckPermission("system:schoolName:list")
    @GetMapping("/list")
    public TableDataInfo<SysSchoolNameVo> list(SysSchoolNameBo bo, PageQuery pageQuery) {
        return sysSchoolNameService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出学校名称列表
     */
    @SaCheckPermission("system:schoolName:export")
    @Log(title = "学校名称", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(SysSchoolNameBo bo, HttpServletResponse response) {
        List<SysSchoolNameVo> list = sysSchoolNameService.queryList(bo);
        ExcelUtil.exportExcel(list, "学校名称", SysSchoolNameVo.class, response);
    }

    /**
     * 获取学校名称详细信息
     *
     * @param schoolNameId 主键
     */
    @SaCheckPermission("system:schoolName:query")
    @GetMapping("/{schoolNameId}")
    public R<SysSchoolNameVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long schoolNameId) {
        return R.ok(sysSchoolNameService.queryById(schoolNameId));
    }

    /**
     * 新增学校名称
     */
    @SaCheckPermission("system:schoolName:add")
    @Log(title = "学校名称", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody SysSchoolNameBo bo) {
        return toAjax(sysSchoolNameService.insertByBo(bo));
    }

    /**
     * 修改学校名称
     */
    @SaCheckPermission("system:schoolName:edit")
    @Log(title = "学校名称", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PostMapping("/put")
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody SysSchoolNameBo bo) {
        return toAjax(sysSchoolNameService.updateByBo(bo));
    }

    /**
     * 删除学校名称
     *
     * @param schoolNameIds 主键串
     */
    @SaCheckPermission("system:schoolName:remove")
    @Log(title = "学校名称", businessType = BusinessType.DELETE)
    @GetMapping("/delete/{schoolNameIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] schoolNameIds) {
        return toAjax(sysSchoolNameService.deleteWithValidByIds(List.of(schoolNameIds), true));
    }
}
