package com.yida.data.school.classCall.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yida.data.common.core.common.ResultBean;
import com.yida.data.common.core.entity.CurrentUser;
import com.yida.data.common.core.entity.classCall.EduClassCall;
import com.yida.data.common.core.entity.classschedule.EduClassSchedule;
import com.yida.data.common.core.utils.FebsUtil;
import com.yida.data.school.classCall.service.EduClassCallService;
import com.yida.data.school.dto.classCall.ClassCallAddDTO;
import com.yida.data.school.dto.classCall.ClassCallPageDTO;
import com.yida.data.school.dto.classSchedule.ClassSchedulePageDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "点名系统")
@Slf4j
@Validated
@RestController
@RequestMapping("/classCall")
@RequiredArgsConstructor
public class EduClassCallController {

    private final EduClassCallService eduClassCallService;

    @ApiOperation("保存课堂点名")
    @PostMapping("/saveClassCall")
    public ResultBean saveClassCall(@RequestBody ClassCallAddDTO dto) {
        eduClassCallService.save(dto);
        return ResultBean.buildSuccess();
    }

    @ApiOperation("分页查询历史点名")
    @PostMapping("/listClassCallPage")
    public ResultBean<IPage<EduClassCall>> listClassCallPage(@Validated @RequestBody ClassCallPageDTO dto) {
        if (dto.getSchoolId() == null) {
            CurrentUser currentUser = FebsUtil.getCurrentUser();
            dto.setSchoolId(currentUser.getDeptId());
        }
        return ResultBean.buildSuccess(eduClassCallService.listClassCallPage(dto));
    }

    @ApiOperation("点名详情")
    @GetMapping("/detail")
    public ResultBean<EduClassCall> getDetail(@RequestParam Long callId) {
        return ResultBean.buildSuccess(eduClassCallService.getDetailById(callId));
    }

}
