from fastapi import APIRouter, Depends, Form, Request, Body, UploadFile, File
from module_admin.service.login_service import LoginService
from module_admin.annotation.log_annotation import Log
from module_admin.service.compreface_service import ComprefaceService
from config.enums import BusinessType
from utils.response_util import ResponseUtil
from utils.log_util import logger
import datetime



comprefaceController = APIRouter(prefix='/system/compreface'
                                 , dependencies=[Depends(LoginService.get_current_user)]
                                 )

# 人脸检测
@comprefaceController.post('/face_detection')
async def face_detection(request: Request, file: UploadFile = File(None)) -> dict:
    """
    人脸检测
    
    """
    if file:  # 说明是表单上传
        image = await file.read()
        
    else:  # 尝试按字节流读取
        image = await request.body()
       
    result = await ComprefaceService.face_detection_service(image)
    print(result)
    return ResponseUtil.success(data=result)

# 人脸识别
@comprefaceController.post('/face_recognition')
# @Log(title='人脸识别', business_type=BusinessType.OTHER)
async def face_recognition(request: Request, file: UploadFile = File(None)) -> dict:
    """
    人脸识别
    
    """
    if file:  # 说明是表单上传
        image = await file.read()
        
    else:  # 尝试按字节流读取
        image = await request.body()
       
    result = await ComprefaceService.face_recognition_service(image)
    print(result)
    return ResponseUtil.success(data=result)
    
    
# def my_job():
#     print("任务执行时间:", datetime.datetime.now())
    
# from config.get_scheduler import scheduler
# from apscheduler.triggers.cron import CronTrigger
# trigger = CronTrigger(minute='*', second=0)
# scheduler.add_job(my_job, trigger=trigger)