package com.boman.web.core.controller;

import com.boman.domain.dto.AjaxResult;
import com.boman.domain.dto.ClockOnDto;
import com.boman.domain.dto.FormDataDto;
import com.boman.web.core.service.attendance.AttendanceService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author shiqian
 * @date 2021年06月03日 15:41
 **/
@RequestMapping("/attendance")
@RestController
public class AttendanceController {

    @Resource
    private AttendanceService service;

    /**
     * 功能描述: 打卡
     *
     * @param dto tableName
     * @return com.boman.domain.dto.AjaxResult
     */
    @PostMapping("/clockOn")
    public AjaxResult clockOn(@RequestBody ClockOnDto dto) {
        return AjaxResult.success(service.clockOn(dto));
    }

    /**
     * 功能描述: 根据tableName和userId查找迟到、早退等
     *
     * @param tableName tableName
     * @param userName  userName
     * @return com.boman.domain.dto.AjaxResult
     */
    @GetMapping("/listByUserName/{tableName}/{userName}")
    public AjaxResult listByUserName(@PathVariable("tableName") String tableName, @PathVariable("userName") String userName) {
        return service.attendanceRecord(tableName, userName);
    }


    /**
     * 功能描述: 显示是上班打卡还是下班打卡
     *
     * @param tableName tableName
     * @param userName  userName
     * @return com.boman.domain.dto.AjaxResult
     */
    @GetMapping("/showAttendanceType/{tableName}/{userName}")
    public AjaxResult showAttendanceType(@PathVariable("tableName") String tableName, @PathVariable("userName") String userName) {
        return AjaxResult.success(service.showAttendanceType(tableName, userName));
    }

    /**
     * 功能描述: 查询该人的一天打卡时间
     *
     * @param tableName tableName
     * @param userName  userName
     * @return com.boman.domain.dto.AjaxResult
     */
    @GetMapping("/attendanceTime/{tableName}/{userName}")
    public AjaxResult attendanceTime(@PathVariable("tableName") String tableName, @PathVariable("userName") String userName) {
        return AjaxResult.success(service.attendanceTime(tableName, userName));
    }


    /**
     * 功能描述: 根据tableName和userId查找当月考勤详细记录
     * @return com.boman.domain.dto.AjaxResult
     */
    @PostMapping("/detailedRecord")
    public AjaxResult detailedRecord(@RequestBody FormDataDto dto) {
        return service.detailedRecord(dto);
    }
}
