package com.yida.data.attendance.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yida.data.attendance.service.EduAttendanceStaffRecordService;
import com.yida.data.attendance.vo.StaffRecordVO;
import com.yida.data.common.core.common.ResultBean;
import com.yida.data.common.core.utils.FebsUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
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 ccl
 * @date 2021-09-27 18:56:19
 */
@Api(tags = "考勤-教职工-进出记录")
@Slf4j
@Validated
@RestController
@RequestMapping("/staffRecord")
@RequiredArgsConstructor
public class EduAttendanceStaffRecordController {

    private final EduAttendanceStaffRecordService eduAttendanceStaffRecordService;

    @ApiOperation("查询进出记录")
    @GetMapping("/findPageStaffRecord")
    public ResultBean<IPage<StaffRecordVO>> findPageStaffRecord(@ApiParam("部门id") @RequestParam(required = false) Long deptId,
        @ApiParam("职工姓名或手机号") @RequestParam(required = false) String nameOrPhone,
        @ApiParam("开始时间") @RequestParam(required = false) String start,
        @ApiParam("结束时间") @RequestParam(required = false) String end,
        @RequestParam(defaultValue = "10") Long pageSize,
        @RequestParam(defaultValue = "1") Long pageNum) {
        Page page = new Page();
        page.setSize(pageSize);
        page.setCurrent(pageNum);
        Long schoolId = null;
        if (FebsUtil.getCurrentUser().getDeptType() != 5) {
            schoolId = FebsUtil.getCurrentUser().getDeptId();
        }
        return ResultBean
            .buildSuccess(eduAttendanceStaffRecordService.findPageStaffRecord(page, deptId, nameOrPhone, start, end, schoolId));
    }
}
