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.baomidou.mybatisplus.extension.plugins.pagination.Page;
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.AddBaseStudentPunishmentInfoDto;
import com.xjrsoft.module.student.dto.BaseStudentPunishmentInfoMobilePageDto;
import com.xjrsoft.module.student.dto.BaseStudentPunishmentInfoPageDto;
import com.xjrsoft.module.student.dto.UpdateBaseStudentPunishmentInfoDto;
import com.xjrsoft.module.student.entity.BaseStudentPunishmentInfo;
import com.xjrsoft.module.student.service.IBaseStudentPunishmentInfoService;
import com.xjrsoft.module.student.vo.BaseStudentPunishmentInfoDetailVo;
import com.xjrsoft.module.student.vo.BaseStudentPunishmentInfoMobileDetailVo;
import com.xjrsoft.module.student.vo.BaseStudentPunishmentInfoMobilePageVo;
import com.xjrsoft.module.student.vo.BaseStudentPunishmentInfoPageVo;
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 dzx
* @Date: 2023-11-15
* @Version 1.0
*/
@RestController
@RequestMapping("/student" + "/basestudentpunishmentinfo")
@Api(value = "/student"  + "/basestudentpunishmentinfo",tags = "学生处分信息管理代码")
@AllArgsConstructor
public class BaseStudentPunishmentInfoController {


    private final IBaseStudentPunishmentInfoService baseStudentPunishmentInfoService;

    @GetMapping(value = "/page")
    @ApiOperation(value="学生处分信息管理列表(分页)")
    @SaCheckPermission("basestudentpunishmentinfo:detail")
    public RT<PageOutput<BaseStudentPunishmentInfoPageVo>> page(@Valid BaseStudentPunishmentInfoPageDto dto){
        IPage<BaseStudentPunishmentInfoPageVo> pageList = baseStudentPunishmentInfoService.selectJoinListPagePc(dto);
        PageOutput<BaseStudentPunishmentInfoPageVo> pageOutput = ConventPage.getPageOutput(pageList, BaseStudentPunishmentInfoPageVo.class);
        return RT.ok(pageOutput);
    }

    @GetMapping(value = "/mobile-page")
    @ApiOperation(value="学生处分信息管理列表(移动端分页)")
    @SaCheckPermission("basestudentpunishmentinfo:detail")
    public RT<PageOutput<BaseStudentPunishmentInfoMobilePageVo>> mobilePage(@Valid BaseStudentPunishmentInfoMobilePageDto dto){

        IPage<BaseStudentPunishmentInfoMobilePageVo> paglIst = baseStudentPunishmentInfoService.getMobilePage(new Page<>(dto.getLimit(), dto.getSize()), dto);
        PageOutput<BaseStudentPunishmentInfoMobilePageVo> pageOutput = ConventPage.getPageOutput(paglIst, BaseStudentPunishmentInfoMobilePageVo.class);
        return RT.ok(pageOutput);
    }

    @GetMapping(value = "/info")
    @ApiOperation(value="根据id查询学生处分信息管理信息")
    @SaCheckPermission("basestudentpunishmentinfo:detail")
    public RT<BaseStudentPunishmentInfoDetailVo> info(@RequestParam Long id){
        BaseStudentPunishmentInfoDetailVo baseStudentPunishmentInfoDetailVo = baseStudentPunishmentInfoService.getDetailById(id);
        if (baseStudentPunishmentInfoDetailVo == null) {
            return RT.error("找不到此数据！");
        }
        return RT.ok(BeanUtil.toBean(baseStudentPunishmentInfoDetailVo,BaseStudentPunishmentInfoDetailVo.class));
    }

    @GetMapping(value = "/mobile-info")
    @ApiOperation(value="根据id查询学生处分信息管理信息(移动端)")
    @SaCheckPermission("basestudentpunishmentinfo:detail")
    public RT<BaseStudentPunishmentInfoMobileDetailVo> mobileInfo(@RequestParam Long id){
        BaseStudentPunishmentInfoMobileDetailVo baseStudentPunishmentInfoMobileDetailVo = baseStudentPunishmentInfoService.getMobileInfo(id);
        if (baseStudentPunishmentInfoMobileDetailVo == null) {
            return RT.error("找不到此数据！");
        }
        return RT.ok(BeanUtil.toBean(baseStudentPunishmentInfoMobileDetailVo,BaseStudentPunishmentInfoMobileDetailVo.class));
    }


    @PostMapping
    @ApiOperation(value = "新增学生处分信息管理")
    @SaCheckPermission("basestudentpunishmentinfo:add")
    public RT<Boolean> add(@Valid @RequestBody AddBaseStudentPunishmentInfoDto dto){
        BaseStudentPunishmentInfo baseStudentPunishmentInfo = BeanUtil.toBean(dto, BaseStudentPunishmentInfo.class);
        boolean isSuccess = baseStudentPunishmentInfoService.add(baseStudentPunishmentInfo);
    return RT.ok(isSuccess);
    }

    @PutMapping
    @ApiOperation(value = "修改学生处分信息管理")
    @SaCheckPermission("basestudentpunishmentinfo:edit")
    public RT<Boolean> update(@Valid @RequestBody UpdateBaseStudentPunishmentInfoDto dto){

        BaseStudentPunishmentInfo baseStudentPunishmentInfo = BeanUtil.toBean(dto, BaseStudentPunishmentInfo.class);
        return RT.ok(baseStudentPunishmentInfoService.update(baseStudentPunishmentInfo));

    }

    @DeleteMapping
    @ApiOperation(value = "删除学生处分信息管理")
    @SaCheckPermission("basestudentpunishmentinfo:delete")
    public RT<Boolean> delete(@Valid @RequestBody List<Long> ids){
        return RT.ok(baseStudentPunishmentInfoService.delete(ids));

    }

}