package com.yida.data.attendance.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yida.data.attendance.dto.InOutPageDTO;
import com.yida.data.attendance.dto.ListRecordDTO;
import com.yida.data.attendance.service.EduAttendanceRecordService;
import com.yida.data.attendance.vo.InOutDormPageVO;
import com.yida.data.attendance.vo.RecordDetailVO;
import com.yida.data.common.core.common.ModuleName;
import com.yida.data.common.core.common.ResultBean;
import com.yida.data.common.core.entity.CurrentUser;
import com.yida.data.common.core.utils.FebsUtil;
import com.yida.data.log.annotation.OperationLog;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
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;

@Api(tags = "考勤-学生-进出记录")
@RestController
@RequestMapping("/record")
public class EduAttendanceRecordController {

    @Resource
    private EduAttendanceRecordService eduAttendanceRecordService;

    @ApiOperation("分页查询进出记录")
    @GetMapping("/listInOutPage")
    @OperationLog(module = ModuleName.ATTENDANCE, methods = "分页查询进出记录")
    public ResultBean<IPage<InOutDormPageVO>> listInOutPage(InOutPageDTO dto) {
        if (dto.getSchoolId() == null) {
            CurrentUser currentUser = FebsUtil.getCurrentUser();
            if (currentUser.getDeptType() == 0) {
                dto.setSchoolId(currentUser.getDeptId());
            }
        }
        return ResultBean.buildSuccess(eduAttendanceRecordService.listInOutPage(dto));
    }

    @ApiOperation("导出进出记录")
    @PostMapping("/exportInOut")
    public void exportInOut(@RequestBody InOutPageDTO dto, HttpServletResponse response) {
        eduAttendanceRecordService.exportInOut(dto, response);
    }

    @ApiOperation("查询进出记录详情")
    @GetMapping("/getRecordById")
    public ResultBean<RecordDetailVO> getRecordById(Long id) {
        return ResultBean.buildSuccess(eduAttendanceRecordService.getRecordDetail(id));
    }

    @ApiOperation("查询进出记录")
    @GetMapping("/listRecord")
    public ResultBean<List<RecordDetailVO>> listRecord(ListRecordDTO dto) {
        return ResultBean.buildSuccess(eduAttendanceRecordService.listRecord(dto));
    }
}
