123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- # -*- coding: utf-8 -*-
- from fastapi import APIRouter, HTTPException, Query
- from loguru import logger
- from app.controllers.targets import readjust_all_target
- from app.models.domain.targets import TargetReadjustResponse
- from app.utils.date import get_time_str
- router = APIRouter()
- @router.get('/adjust', response_model=TargetReadjustResponse, tags=['targets'])
- async def readjust_target(
- projectId: str = Query(..., max_length=50, regex='^Pj'),
- roomId: str = Query(..., max_length=50, regex='^Sp'),
- time: str = Query(None, min_length=14, max_length=14),
- ):
- try:
- if not time:
- time = get_time_str()
- need_run_room_control = await readjust_all_target(projectId, roomId, time)
- except Exception as e:
- logger.error(e)
- raise HTTPException(
- status_code=500,
- detail='Oops, something wrong has happened'
- )
- response = {
- 'projectId': projectId,
- 'roomId': roomId,
- 'flag': 1 if need_run_room_control else 0,
- 'time': time,
- }
- return response
- @router.get('/adjust/test', response_model=TargetReadjustResponse, tags=['targets'])
- async def test_readjust_target(
- project_id: str = Query(..., max_length=50, regex='^Pj'),
- space_id: str = Query(..., max_length=50, regex='^Sp')
- ):
- feedback = {
- 'a little cold': 1,
- 'so cold': 0,
- 'a little hot': 0,
- 'so hot': 0,
- 'switch on': 0,
- }
- try:
- need_run_room_control = await readjust_all_target(project_id, space_id, feedback=feedback)
- except Exception as e:
- logger.error(e)
- raise HTTPException(
- status_code=500,
- detail='Oops, something wrong has happened'
- )
- response = {
- 'projectId': project_id,
- 'roomId': space_id,
- 'flag': 1 if need_run_room_control else 0,
- 'time': get_time_str()
- }
- return response
|