package com.yida.data.device.studentCard.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.system.enums.DeptTypeEnum;
import com.yida.data.common.core.utils.FebsUtil;
import com.yida.data.device.dto.studentCard.AlarmPageDTO;
import com.yida.data.device.studentCard.service.EduStudentCardAlarmService;
import com.yida.data.device.vo.studentCard.AlarmPageVO;
import com.yida.data.device.vo.studentCard.StudentAlarmVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import java.util.Objects;
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.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 电子学生证-告警信息 Controller
 *
 * @author zhanghaijun
 * @date 2021-08-04 15:08:05
 */
@Api(tags = "学生证-告警信息")
@Slf4j
@Validated
@RestController
@RequestMapping("/studentCard/alarm")
@RequiredArgsConstructor
public class EduStudentCardAlarmController {

    private final EduStudentCardAlarmService eduStudentCardAlarmService;

    @ApiOperation("分页查询告警信息")
    @GetMapping("/listAlarmPage")
    public ResultBean<IPage<AlarmPageVO>> listAlarmPage(AlarmPageDTO dto) {
        CurrentUser currentUser = FebsUtil.getCurrentUser();
        if (dto.getSchoolId() == null &&
            !DeptTypeEnum.COMPANY_TYPE.getValue().equals(Objects.requireNonNull(currentUser).getDeptType())) {
            dto.setSchoolId(currentUser.getDeptId());
        }
        return ResultBean.buildSuccess(eduStudentCardAlarmService.listAlarmPage(dto));
    }

    @ApiModelProperty("家长查询告警信息")
    @GetMapping("/listStudentAlarmPage")
    public ResultBean<IPage<StudentAlarmVO>> listStudentAlarmPage(Long studentId,
        @RequestParam(defaultValue = "1", required = false) Integer pageNum,
        @RequestParam(defaultValue = "10", required = false) Integer pageSize) {
        return ResultBean.buildSuccess(eduStudentCardAlarmService.listStudentAlarmPage(studentId, pageNum, pageSize));
    }
}