package com.yida.data.user.controller.out;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yida.data.common.core.annotation.ControllerLog;
import com.yida.data.common.core.common.ModuleName;
import com.yida.data.common.core.common.ResultBean;
import com.yida.data.common.core.entity.system.enums.OperationLogTypeEnum;
import com.yida.data.common.core.entity.user.EduStudent;
import com.yida.data.common.core.utils.FebsUtil;
import com.yida.data.log.annotation.OperationLog;
import com.yida.data.user.dto.OutPageStudentDTO;
import com.yida.data.user.service.EduStudentService;
import com.yida.data.user.vo.OutPageStudentVO;
import com.yida.data.user.vo.StaStudentVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;

@Api(tags = "家长管理")
@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping(value = "/out/student")
public class OutEduStudentController {

    private final EduStudentService eduStudentService;

    @ApiOperation("统计学生分布数据")
    @GetMapping("/staStudentDistribu")
    public ResultBean<StaStudentVO> staStudentDistribu(Long[] schoolIds) {
        return ResultBean.buildSuccess(eduStudentService.staStudentDistribu(Arrays.asList(schoolIds)));
    }

    @ApiOperation("分页查询学生列表数据")
    @GetMapping("/listStudentPage")
    public ResultBean<IPage<OutPageStudentVO>> listStudentOutPage(OutPageStudentDTO dto, HttpServletRequest request) {
        return ResultBean.buildSuccess(eduStudentService.listStudentOutPage(dto, request));
    }

    @ApiOperation("保存学生信息 新增或编辑")
    @PostMapping("/saveStudent")
    @OperationLog(module = ModuleName.STUDENT, methods = "新增、修改学生", type = OperationLogTypeEnum.SAVE)
    public ResultBean<EduStudent> saveStudent(@RequestBody EduStudent eduStudent) {
        return ResultBean.buildSuccess(eduStudentService.saveStudent(eduStudent, null, false));
    }
}
