package com.xjrsoft.module.student.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.hutool.core.bean.BeanUtil;
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.base.mapper.BaseClassMapper;
import com.xjrsoft.module.student.dto.AddBaseStudentBehaviorManageDto;
import com.xjrsoft.module.student.dto.BaseStudentBehaviorManageMobilePageDto;
import com.xjrsoft.module.student.dto.BaseStudentBehaviorManagePageDto;
import com.xjrsoft.module.student.dto.UpdateBaseStudentBehaviorManageDto;
import com.xjrsoft.module.student.entity.BaseStudentBehaviorManage;
import com.xjrsoft.module.student.mapper.BaseStudentBehaviorClassRelationMapper;
import com.xjrsoft.module.student.mapper.BaseStudentBehaviorStudentRelationMapper;
import com.xjrsoft.module.student.service.IBaseStudentBehaviorManageService;
import com.xjrsoft.module.student.vo.BaseStudentBehaviorManageMobilePageVo;
import com.xjrsoft.module.student.vo.BaseStudentBehaviorManagePageVo;
import com.xjrsoft.module.student.vo.BaseStudentBehaviorManageVo;
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-17
* @Version 1.0
*/
@RestController
@RequestMapping("/student" + "/baseStudentBehaviorManage")
@Api(value = "/student"  + "/baseStudentBehaviorManage",tags = "学生操行分记录管理代码")
@AllArgsConstructor
public class BaseStudentBehaviorManageController {


    private final IBaseStudentBehaviorManageService baseStudentBehaviorManageService;
    private final BaseStudentBehaviorClassRelationMapper baseStudentBehaviorClassRelationMapper;
    private final BaseStudentBehaviorStudentRelationMapper baseStudentBehaviorStudentRelationMapper;
    private final BaseClassMapper baseClassMapper;

    @GetMapping(value = "/page")
    @ApiOperation(value="学生操行分记录管理列表(pc端)")
    @SaCheckPermission("basestudentbehaviormanage:detail")
    public RT<PageOutput<BaseStudentBehaviorManagePageVo>> page(@Valid BaseStudentBehaviorManagePageDto dto){
        Page<BaseStudentBehaviorManagePageVo> page = baseStudentBehaviorManageService.getPage(new Page<>(dto.getLimit(), dto.getSize()), dto);
        return RT.ok(ConventPage.getPageOutput(page, BaseStudentBehaviorManagePageVo.class));
    }

    @GetMapping(value = "/mobile-page")
    @ApiOperation(value="学生操行分记录管理列表(移动端)")
    @SaCheckPermission("basestudentbehaviormanage:detail")
    public RT<PageOutput<BaseStudentBehaviorManageMobilePageVo>> mibliePage(@Valid BaseStudentBehaviorManageMobilePageDto dto){
        Page<BaseStudentBehaviorManageMobilePageVo> page = baseStudentBehaviorManageService.getMobilePage(new Page<>(dto.getLimit(), dto.getSize()), dto);
        return RT.ok(ConventPage.getPageOutput(page, BaseStudentBehaviorManageMobilePageVo.class));
    }


    @GetMapping(value = "/info")
    @ApiOperation(value="根据id查询学生操行分记录管理信息(pc端)")
    @SaCheckPermission("basestudentbehaviormanage:detail")
    public RT<BaseStudentBehaviorManageVo> info(@RequestParam Long id){
        BaseStudentBehaviorManageVo baseStudentBehaviorManage = baseStudentBehaviorManageService.getInfo(id);
        if (baseStudentBehaviorManage == null) {
           return RT.error("找不到此数据！");
        }

        return RT.ok(baseStudentBehaviorManage);
    }

    @GetMapping(value = "/mobile-info")
    @ApiOperation(value="根据id查询学生操行分记录管理信息(移动端)")
    @SaCheckPermission("basestudentbehaviormanage:detail")
    public RT<BaseStudentBehaviorManageVo> mobileInfo(@RequestParam Long id){
        BaseStudentBehaviorManageVo baseStudentBehaviorManage = baseStudentBehaviorManageService.getInfo(id);
        if (baseStudentBehaviorManage == null) {
            return RT.error("找不到此数据！");
        }

        return RT.ok(baseStudentBehaviorManage);
    }


    @PostMapping
    @ApiOperation(value = "新增学生操行分记录管理")
    @SaCheckPermission("basestudentbehaviormanage:add")
    public RT<Boolean> add(@Valid @RequestBody AddBaseStudentBehaviorManageDto dto){
        BaseStudentBehaviorManage baseStudentBehaviorManage = BeanUtil.toBean(dto, BaseStudentBehaviorManage.class);
        boolean isSuccess = baseStudentBehaviorManageService.add(baseStudentBehaviorManage);
    return RT.ok(isSuccess);
    }

    @PutMapping
    @ApiOperation(value = "修改学生操行分记录管理")
    @SaCheckPermission("basestudentbehaviormanage:edit")
    public RT<Boolean> update(@Valid @RequestBody UpdateBaseStudentBehaviorManageDto dto){

        BaseStudentBehaviorManage baseStudentBehaviorManage = BeanUtil.toBean(dto, BaseStudentBehaviorManage.class);
        return RT.ok(baseStudentBehaviorManageService.update(baseStudentBehaviorManage));

    }

    @DeleteMapping
    @ApiOperation(value = "删除学生操行分记录管理")
    @SaCheckPermission("basestudentbehaviormanage:delete")
    public RT<Boolean> delete(@Valid @RequestBody List<Long> ids){
        return RT.ok(baseStudentBehaviorManageService.delete(ids));

    }

}