package com.xjrsoft.module.student.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.xjrsoft.common.model.result.RT;
import com.xjrsoft.common.page.ConventPage;
import com.xjrsoft.common.page.PageOutput;
import com.xjrsoft.module.student.dto.AddSchoolRollFurtherEducationDto;
import com.xjrsoft.module.student.dto.SchoolRollFurtherEducationPageDto;
import com.xjrsoft.module.student.dto.UpdateSchoolRollFurtherEducationDto;
import com.xjrsoft.module.student.entity.SchoolRollFurtherEducation;
import com.xjrsoft.module.student.service.ISchoolRollFurtherEducationService;
import com.xjrsoft.module.student.vo.SchoolRollFurtherEducationPageVo;
import com.xjrsoft.module.student.vo.SchoolRollFurtherEducationVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
* @title: 升学管理
* @Author szs
* @Date: 2023-12-01
* @Version 1.0
*/
@RestController
@RequestMapping("/student" + "/schoolRollFurtherEducation")
@Api(value = "/student"  + "/schoolRollFurtherEducation",tags = "升学管理代码")
@AllArgsConstructor
public class SchoolRollFurtherEducationController {


    private final ISchoolRollFurtherEducationService schoolRollFurtherEducationService;

    @GetMapping(value = "/page")
    @ApiOperation(value="升学管理列表(分页)")
    @SaCheckPermission("schoolrollfurthereducation:detail")
    public RT<PageOutput<SchoolRollFurtherEducationPageVo>> page(@Valid SchoolRollFurtherEducationPageDto dto){
        IPage<SchoolRollFurtherEducationPageVo> page = schoolRollFurtherEducationService.getPageListPc(dto);
        PageOutput<SchoolRollFurtherEducationPageVo> pageOutput = ConventPage.getPageOutput(page, SchoolRollFurtherEducationPageVo.class);
        return RT.ok(pageOutput);
    }

    @GetMapping(value = "/info")
    @ApiOperation(value="根据id查询升学管理信息")
    @SaCheckPermission("schoolrollfurthereducation:detail")
    public RT<SchoolRollFurtherEducationVo> info(@RequestParam Long id){
        SchoolRollFurtherEducationVo schoolRollFurtherEducationVo = schoolRollFurtherEducationService.getDetailById(id);
        if (schoolRollFurtherEducationVo == null) {
           return RT.error("找不到此数据！");
        }
        return RT.ok(schoolRollFurtherEducationVo);
    }


    @PostMapping
    @ApiOperation(value = "新增升学管理")
    @SaCheckPermission("schoolrollfurthereducation:add")
    public RT<Boolean> add(@Valid @RequestBody AddSchoolRollFurtherEducationDto dto){
        SchoolRollFurtherEducation schoolRollFurtherEducation = BeanUtil.toBean(dto, SchoolRollFurtherEducation.class);
        boolean isSuccess = schoolRollFurtherEducationService.save(schoolRollFurtherEducation);
    return RT.ok(isSuccess);
    }

    @PutMapping
    @ApiOperation(value = "修改升学管理")
    @SaCheckPermission("schoolrollfurthereducation:edit")
    public RT<Boolean> update(@Valid @RequestBody UpdateSchoolRollFurtherEducationDto dto){

        SchoolRollFurtherEducation schoolRollFurtherEducation = BeanUtil.toBean(dto, SchoolRollFurtherEducation.class);
        return RT.ok(schoolRollFurtherEducationService.updateById(schoolRollFurtherEducation));

    }

    @DeleteMapping
    @ApiOperation(value = "删除升学管理")
    @SaCheckPermission("schoolrollfurthereducation:delete")
    public RT<Boolean> delete(@Valid @RequestBody List<Long> ids){
        return RT.ok(schoolRollFurtherEducationService.removeBatchByIds(ids));

    }

}