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.AddBaseStudentAssessmentInspectionDto;
import com.xjrsoft.module.student.dto.BaseStudentAssessmentInspectionMobilePageDto;
import com.xjrsoft.module.student.dto.BaseStudentAssessmentInspectionPageDto;
import com.xjrsoft.module.student.dto.CalssQuantitativeAssessmentPageDto;
import com.xjrsoft.module.student.dto.QuantitativeAssessmentExcelDto;
import com.xjrsoft.module.student.dto.UpdateBaseStudentAssessmentInspectionDto;
import com.xjrsoft.module.student.entity.BaseStudentAssessmentInspection;
import com.xjrsoft.module.student.service.IBaseStudentAssessmentInspectionService;
import com.xjrsoft.module.student.vo.BaseStudentAssessmentInspectionMobilePageVo;
import com.xjrsoft.module.student.vo.BaseStudentAssessmentInspectionMobileVo;
import com.xjrsoft.module.student.vo.BaseStudentAssessmentInspectionPageVo;
import com.xjrsoft.module.student.vo.BaseStudentAssessmentInspectionVo;
import com.xjrsoft.module.student.vo.CalssQuantitativeAssessmentPageVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.http.ResponseEntity;
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-16
 * @Version 1.0
 */
@RestController
@RequestMapping("/student" + "/basestudentassessmentinspection")
@Api(value = "/student" + "/basestudentassessmentinspection", tags = "学生班级巡查考核代码")
@AllArgsConstructor
public class BaseStudentAssessmentInspectionController {

    private final IBaseStudentAssessmentInspectionService baseStudentAssessmentInspectionService;

    @GetMapping(value = "/page")
    @ApiOperation(value = "学生班级巡查考核列表(分页)")
    @SaCheckPermission("basestudentassessmentinspection:detail")
    public RT<PageOutput<BaseStudentAssessmentInspectionPageVo>> page(@Valid BaseStudentAssessmentInspectionPageDto dto) {
        Page<BaseStudentAssessmentInspectionPageVo> page = baseStudentAssessmentInspectionService.getPage(new Page<>(dto.getLimit(), dto.getSize()), dto);
        return RT.ok(ConventPage.getPageOutput(page, BaseStudentAssessmentInspectionPageVo.class));
    }

    @GetMapping(value = "/info")
    @ApiOperation(value = "根据id查询学生班级巡查考核信息")
    @SaCheckPermission("basestudentassessmentinspection:detail")
    public RT<BaseStudentAssessmentInspectionVo> info(@RequestParam Long id) {
        BaseStudentAssessmentInspectionVo result = baseStudentAssessmentInspectionService.getInfo(id);
        return RT.ok(result);
    }

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

    @GetMapping(value = "/mobile-info")
    @ApiOperation(value = "根据id查询学生班级巡查考核信息(移动端)")
    @SaCheckPermission("basestudentassessmentinspection:detail")
    public RT<BaseStudentAssessmentInspectionMobileVo> mobileInfo(@Valid Long id) {
        BaseStudentAssessmentInspectionMobileVo result = baseStudentAssessmentInspectionService.getMobileInfo(id);
        return RT.ok(result);
    }

    @PostMapping
    @ApiOperation(value = "新增学生班级巡查考核")
    @SaCheckPermission("basestudentassessmentinspection:add")
    public RT<Boolean> add(@Valid @RequestBody AddBaseStudentAssessmentInspectionDto dto) {
        BaseStudentAssessmentInspection baseStudentAssessmentInspection = BeanUtil.toBean(dto, BaseStudentAssessmentInspection.class);
        boolean isSuccess = baseStudentAssessmentInspectionService.save(baseStudentAssessmentInspection);
        return RT.ok(isSuccess);
    }

    @PutMapping
    @ApiOperation(value = "修改学生班级巡查考核")
    @SaCheckPermission("basestudentassessmentinspection:edit")
    public RT<Boolean> update(@Valid @RequestBody UpdateBaseStudentAssessmentInspectionDto dto) {

        BaseStudentAssessmentInspection baseStudentAssessmentInspection = BeanUtil.toBean(dto, BaseStudentAssessmentInspection.class);
        return RT.ok(baseStudentAssessmentInspectionService.updateById(baseStudentAssessmentInspection));

    }

    @DeleteMapping
    @ApiOperation(value = "删除学生班级巡查考核")
    @SaCheckPermission("basestudentassessmentinspection:delete")
    public RT<Boolean> delete(@Valid @RequestBody List<Long> ids) {
        return RT.ok(baseStudentAssessmentInspectionService.removeBatchByIds(ids));
    }

    @GetMapping(value = "/calss-quantitative-assessment-page")
    @ApiOperation(value = "班级量化考核列表(分页)")
    @SaCheckPermission("basestudentassessmentinspection:detail")
    public RT<PageOutput<CalssQuantitativeAssessmentPageVo>> calssQuantitativeAssessmentPage(@Valid CalssQuantitativeAssessmentPageDto dto) {
        IPage<CalssQuantitativeAssessmentPageVo> page = baseStudentAssessmentInspectionService.getCalssQuantitativeAssessmentPage(new Page<>(dto.getLimit(), dto.getSize()), dto);
        return RT.ok(ConventPage.getPageOutput(page, CalssQuantitativeAssessmentPageVo.class));
    }

//    @PostMapping("/export-query")
//    @ApiOperation(value = "入参导出")
//    public ResponseEntity<byte[]>  exportDataQuery(@Valid @RequestBody QuantitativeAssessmentExcelDto dto) {
    @GetMapping("/export")
    @ApiOperation(value = "导出")
    public ResponseEntity<byte[]>  exportDataQuery() {
        return baseStudentAssessmentInspectionService.getQuantitativeAssessmentExcelByte(new QuantitativeAssessmentExcelDto());
    }
}