package org.dromara.system.controller.formal;

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.system.domain.vo.FormalParentsStudentVo;
import org.dromara.system.domain.bo.FormalParentsStudentBo;
import org.dromara.system.service.IFormalParentsStudentService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 家长-学生(审核通过之后数据)
 *
 * @author Lion Li
 * @date 2023-08-16
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/student")
public class FormalParentsStudentController extends BaseController {

    private final IFormalParentsStudentService formalParentsStudentService;

    /**
     * 查询家长-学生(审核通过之后数据)列表
     */
    @SaCheckPermission("system:student:list")
    @GetMapping("/list")
    public TableDataInfo<FormalParentsStudentVo> list(FormalParentsStudentBo bo, PageQuery pageQuery) {
        return formalParentsStudentService.queryPageList(bo, pageQuery);
    }

    /**
     * 查询家长-学生(审核通过之后数据)列表不分页
     */
    @GetMapping("noPage/list")
    public TableDataInfo<FormalParentsStudentVo> noPage(FormalParentsStudentBo bo)
    {

        return formalParentsStudentService.selectFormalParentsStudentListNoPage(bo);
    }

    /**
     * 导出家长-学生(审核通过之后数据)列表
     */
    @SaCheckPermission("system:student:export")
    @Log(title = "家长-学生(审核通过之后数据)", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(FormalParentsStudentBo bo, HttpServletResponse response) {
        List<FormalParentsStudentVo> list = formalParentsStudentService.queryList(bo);
        ExcelUtil.exportExcel(list, "家长-学生(审核通过之后数据)", FormalParentsStudentVo.class, response);
    }

    /**
     * 获取家长-学生(审核通过之后数据)详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("system:student:query")
    @GetMapping("/{id}")
    public R<FormalParentsStudentVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(formalParentsStudentService.queryById(id));
    }

    /**
     * 新增家长-学生(审核通过之后数据)
     */
    @SaCheckPermission("system:student:add")
    @Log(title = "家长-学生(审核通过之后数据)", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody FormalParentsStudentBo bo) {
        return toAjax(formalParentsStudentService.insertByBo(bo));
    }

    /**
     * 修改家长-学生(审核通过之后数据)
     */
    @SaCheckPermission("system:student:edit")
    @Log(title = "家长-学生(审核通过之后数据)", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PostMapping("/put")
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody FormalParentsStudentBo bo) {
        return toAjax(formalParentsStudentService.updateByBo(bo));
    }

    /**
     * 删除家长-学生(审核通过之后数据)
     *
     * @param ids 主键串
     */
    @SaCheckPermission("system:student:remove")
    @Log(title = "家长-学生(审核通过之后数据)", businessType = BusinessType.DELETE)
    @GetMapping("/delete/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(formalParentsStudentService.deleteWithValidByIds(List.of(ids), true));
    }


}
