package org.jeecg.modules.xcx.clockin.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.util.TokenUtils;
import org.jeecg.modules.xcx.clockin.req.*;
import org.jeecg.modules.xcx.clockin.service.IClockinService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@Api(tags = "打卡接口")
@Slf4j
@RestController
@RequestMapping("/clock")
public class ClockinController {

    @Resource
    private IClockinService clockinService;

    @ApiOperation(value = "打卡")
    @PostMapping("/in")
    public Result<?> clockIn(HttpServletRequest request , ClockInReq clockInReq){
        clockInReq.setToken(TokenUtils.getTokenByRequest(request));
        return clockinService.clockIn(clockInReq);
    }

    @ApiOperation(value = "打卡详情列表")
    @GetMapping("/in/log")
    public Result<?> clockInLog(HttpServletRequest request , ClockInLogReq clockInLogReq){
        clockInLogReq.setToken(TokenUtils.getTokenByRequest(request));
        return clockinService.clockInLog(clockInLogReq);
    }

    @ApiOperation(value = "打卡统计")
    @GetMapping("/in/total")
    public Result<?> clockInTotal(HttpServletRequest request , ClockInTotalReq clockInTotalReq){
        clockInTotalReq.setToken(TokenUtils.getTokenByRequest(request));
        return clockinService.clockInTotal(clockInTotalReq);
    }

    @ApiOperation(value = "人脸识别")
    @PostMapping("/verify/face")
    public Result<?> verifyFace(HttpServletRequest request , VerifyFaceReq verifyFaceReq){
        verifyFaceReq.setToken(TokenUtils.getTokenByRequest(request));
        return clockinService.verifyFace(verifyFaceReq);
    }

    @ApiOperation("是否在打卡时间段")
    @PostMapping("/time")
    public Result<?> clockInTime(HttpServletRequest request, ClockInTimeReq clockInTimeReq){
        clockInTimeReq.setToken(TokenUtils.getTokenByRequest(request));
        return clockinService.clockInTime(clockInTimeReq);
    }

    @ApiOperation("项目列表分页")
    @GetMapping("/project/list")
    public Result<?> getProjectListPage(HttpServletRequest request, ProjectListPageReq projectListPageReq){
        projectListPageReq.setToken(TokenUtils.getTokenByRequest(request));
        return clockinService.getProjectListPage(projectListPageReq);
    }

    @ApiOperation("设置项目经纬度")
    @PostMapping("/project/location")
    public Result<?> setProjectLocation(SetProjectLocationReq setProjectLocationReq){
        return clockinService.setProjectLocation(setProjectLocationReq);
    }


    @ApiOperation("项目")
    @GetMapping("/project/id")
    public Result<?> getProjectById(@RequestParam("id") String id){
        return clockinService.getProjectById(id);
    }

}
