package com.yida.data.attendance.controller.h5;

import com.yida.data.attendance.service.EduAttendanceStasticService;
import com.yida.data.attendance.vo.CountVO;
import com.yida.data.attendance.vo.TeacherStasticVO;
import com.yida.data.common.core.common.ModuleName;
import com.yida.data.common.core.common.ResultBean;
import com.yida.data.common.core.entity.user.EduStudent;
import com.yida.data.log.annotation.OperationLog;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

import java.time.LocalDate;
import java.util.List;

import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "考勤-前台-家长考勤统计")
@RequiredArgsConstructor
@RestController
@RequestMapping("/h5/statistics")
public class H5EduAttendanceStatisticsController {

    private final EduAttendanceStasticService eduAttendanceStasticService;

    @ApiOperation("统计学生出勤次数")
    @GetMapping("/countStudentAttendance")
    @OperationLog(module = ModuleName.ATTENDANCE, methods = "统计学生出勤次数")
    public ResultBean<CountVO> countStudentAttendance(Long studentId, String startDate, String endDate) {
        return ResultBean.buildSuccess(
                eduAttendanceStasticService.countStudentAttendance(studentId, LocalDate.parse(startDate), LocalDate.parse(endDate)));
    }

    @ApiOperation("统计某班出勤数据")
    @GetMapping("/statisticsClass")
    @OperationLog(module = ModuleName.ATTENDANCE, methods = "统计某班出勤数据")
    public ResultBean<TeacherStasticVO> statisticsClass(Long classId,
                                                        @ApiParam("日期,yyyy-MM-dd (和月必传一个)") @RequestParam(required = false) String date,
                                                        @ApiParam("月,yyyy-MM(和日期必传一个)") @RequestParam(required = false) String month,
                                                        @RequestParam(required = false) @ApiParam("时段id,按月统计不传") Long timeId) {
        return ResultBean.buildSuccess(eduAttendanceStasticService.statisticsClass(classId, date, month, timeId));
    }

    @ApiOperation("统计班级宿舍考勤")
    @GetMapping("/statisticsClassDormAtt")
    @OperationLog(module = ModuleName.ATTENDANCE, methods = "统计班级宿舍考勤")
    public ResultBean<List<EduStudent>> statisticsClassDormAtt(@ApiParam("学校ID") @RequestParam(required = true) Long schoolId,
                                                               @ApiParam("班级ID") @RequestParam(required = true) Long classId,
                                                               @ApiParam("日期") @RequestParam(required = true) String date,
                                                               @ApiParam("考勤时段，1=午间考勤，2=晚间考勤") @RequestParam(required = false) Integer time) {
        return ResultBean.buildSuccess(eduAttendanceStasticService.getStudentDormInfo(schoolId, classId, date, time));
    }


}
