package com.yida.data.attendance.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.yida.data.attendance.service.EduAttendanceResultService;
import com.yida.data.common.core.common.ResultBean;
import com.yida.data.common.core.entity.attendance.EduAttendanceResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "考勤-学生-考勤记录(不鉴权)")
@RestController
@RequestMapping("/in/result")
@RequiredArgsConstructor
public class InEduAttendanceResultController {

    private final EduAttendanceResultService eduAttendanceResultService;

    @ApiOperation("检测并发送未到消息")
    @GetMapping("/pushNotArriveMsg")
    public ResultBean pushNotArriveMsg() {
        eduAttendanceResultService.pushNotArriveMsg();
        return ResultBean.buildSuccess();
    }

    @ApiOperation("处理考勤记录")
    @GetMapping("/dealAttendanceResult")
    public ResultBean dealAttendanceResult() {
        eduAttendanceResultService.dealAttendanceResult();
        return ResultBean.buildSuccess();
    }

    @ApiModelProperty("确认未到记录")
    @GetMapping("/confirmNotArrive")
    public ResultBean confirmNotArrive(@ApiParam("id") Long id) {
        eduAttendanceResultService.update(Wrappers.<EduAttendanceResult>lambdaUpdate().eq(EduAttendanceResult::getId, id)
            .set(EduAttendanceResult::getNotArriveConfirm, 1));
        return ResultBean.buildSuccess();
    }

    @ApiOperation("查询未到记录是否已经确认")
    @GetMapping("/checkResult")
    public ResultBean<Boolean> checkResult(Long id) {
        EduAttendanceResult result = eduAttendanceResultService.getById(id);
        return ResultBean.buildSuccess(result.getNotArriveConfirm() == 1);
    }
}
