|
@@ -14,6 +14,7 @@ from app.utils.common_util import bytes2file_response
|
|
|
from app.core.logger import log
|
|
from app.core.logger import log
|
|
|
from app.core.base_schema import BatchSetAvailable
|
|
from app.core.base_schema import BatchSetAvailable
|
|
|
|
|
|
|
|
|
|
+
|
|
|
from .service import BizVarDictService
|
|
from .service import BizVarDictService
|
|
|
from .schema import BizVarDictCreateSchema, BizVarDictUpdateSchema, BizVarDictQueryParam
|
|
from .schema import BizVarDictCreateSchema, BizVarDictUpdateSchema, BizVarDictQueryParam
|
|
|
from ..crane.service import BizCraneService
|
|
from ..crane.service import BizCraneService
|
|
@@ -140,22 +141,27 @@ async def get_vardict_list_alarms_controller(
|
|
|
) -> JSONResponse:
|
|
) -> JSONResponse:
|
|
|
if search.crane_no: #带crane_no说明是单台车报警直接查数据库即可
|
|
if search.crane_no: #带crane_no说明是单台车报警直接查数据库即可
|
|
|
result_dict = await BizVarDictService.vardict_alarms_list(auth=auth, crane_no=search.crane_no)
|
|
result_dict = await BizVarDictService.vardict_alarms_list(auth=auth, crane_no=search.crane_no)
|
|
|
- async with httpx.AsyncClient() as client:
|
|
|
|
|
- response = await client.get(
|
|
|
|
|
- url=settings.COLLECT_DATA_FULL,
|
|
|
|
|
- params={},
|
|
|
|
|
- timeout=2
|
|
|
|
|
- )
|
|
|
|
|
- if response.status_code == 200:
|
|
|
|
|
|
|
+ try:
|
|
|
|
|
+ async with httpx.AsyncClient() as client:
|
|
|
|
|
+ response = await client.get(
|
|
|
|
|
+ url=settings.COLLECT_DATA_FULL,
|
|
|
|
|
+ params={},
|
|
|
|
|
+ timeout=2
|
|
|
|
|
+ )
|
|
|
|
|
+ # 捕获HTTP状态码非200的情况
|
|
|
|
|
+ response.raise_for_status()
|
|
|
|
|
+ # 捕获JSON解析异常
|
|
|
json_data = response.json()
|
|
json_data = response.json()
|
|
|
if json_data['code'] == 200 and json_data.get('data'):
|
|
if json_data['code'] == 200 and json_data.get('data'):
|
|
|
for item in result_dict:
|
|
for item in result_dict:
|
|
|
item['value'] = False
|
|
item['value'] = False
|
|
|
crane_no = item['crane_no']
|
|
crane_no = item['crane_no']
|
|
|
- alarm = json_data['data'].get(crane_no, {}).get('data', {}).get('alarm', {}).get(
|
|
|
|
|
|
|
+ alarm = json_data.get('data').get(crane_no, {}).get('data', {}).get('alarm', {}).get(
|
|
|
item['var_code'])
|
|
item['var_code'])
|
|
|
if alarm:
|
|
if alarm:
|
|
|
item['value'] = alarm.get('value')
|
|
item['value'] = alarm.get('value')
|
|
|
|
|
+ except Exception as e:
|
|
|
|
|
+ log.error(f"调用数据初始化接口获取报警列表时发生未知异常:{str(e)}", exc_info=True)
|
|
|
else: #全部报警点位查缓存
|
|
else: #全部报警点位查缓存
|
|
|
result_dict = await BizVarDictService.get_vardict_alarms_service(auth=auth, redis=redis)
|
|
result_dict = await BizVarDictService.get_vardict_alarms_service(auth=auth, redis=redis)
|
|
|
cranes = await BizCraneService.list_crane_service(auth=auth)
|
|
cranes = await BizCraneService.list_crane_service(auth=auth)
|
|
@@ -166,30 +172,33 @@ async def get_vardict_list_alarms_controller(
|
|
|
crane_no = crane_dict.get('crane_no')
|
|
crane_no = crane_dict.get('crane_no')
|
|
|
if crane_no and isinstance(crane_no, str):
|
|
if crane_no and isinstance(crane_no, str):
|
|
|
valid_crane_nos.add(crane_no)
|
|
valid_crane_nos.add(crane_no)
|
|
|
-
|
|
|
|
|
- json_data = None
|
|
|
|
|
- async with httpx.AsyncClient() as client:
|
|
|
|
|
- response = await client.get(
|
|
|
|
|
- url=settings.COLLECT_DATA_FULL,
|
|
|
|
|
- params={},
|
|
|
|
|
- timeout=2
|
|
|
|
|
- )
|
|
|
|
|
- if response.status_code == 200:
|
|
|
|
|
|
|
+ try:
|
|
|
|
|
+ async with httpx.AsyncClient() as client:
|
|
|
|
|
+ response = await client.get(
|
|
|
|
|
+ url=settings.COLLECT_DATA_FULL,
|
|
|
|
|
+ params={},
|
|
|
|
|
+ timeout=2
|
|
|
|
|
+ )
|
|
|
|
|
+ # 捕获HTTP状态码非200的情况
|
|
|
|
|
+ response.raise_for_status()
|
|
|
|
|
+ # 捕获JSON解析异常
|
|
|
json_data = response.json()
|
|
json_data = response.json()
|
|
|
|
|
|
|
|
- filtered_result = []
|
|
|
|
|
- for item in result_dict:
|
|
|
|
|
- item_crane_no = item.get('crane_no')
|
|
|
|
|
- if item_crane_no not in valid_crane_nos:
|
|
|
|
|
- continue
|
|
|
|
|
- item['value'] = False # 默认值
|
|
|
|
|
- if json_data and json_data['code'] == 200 and json_data.get('data'):
|
|
|
|
|
- alarm = json_data['data'].get(item_crane_no, {}).get('data', {}).get('alarm', {}).get(
|
|
|
|
|
- item.get('var_code'))
|
|
|
|
|
- if alarm:
|
|
|
|
|
- item['value'] = alarm.get('value')
|
|
|
|
|
- filtered_result.append(item)
|
|
|
|
|
- result_dict = filtered_result
|
|
|
|
|
|
|
+ filtered_result = []
|
|
|
|
|
+ for item in result_dict:
|
|
|
|
|
+ item_crane_no = item.get('crane_no')
|
|
|
|
|
+ if item_crane_no not in valid_crane_nos:
|
|
|
|
|
+ continue
|
|
|
|
|
+ item['value'] = False # 默认值
|
|
|
|
|
+ if json_data and json_data['code'] == 200 and json_data.get('data'):
|
|
|
|
|
+ alarm = json_data.get('data').get(item_crane_no, {}).get('data', {}).get('alarm', {}).get(
|
|
|
|
|
+ item.get('var_code'))
|
|
|
|
|
+ if alarm:
|
|
|
|
|
+ item['value'] = alarm.get('value')
|
|
|
|
|
+ filtered_result.append(item)
|
|
|
|
|
+ result_dict = filtered_result
|
|
|
|
|
+ except Exception as e:
|
|
|
|
|
+ log.error(f"调用数据初始化接口获取报警列表时发生未知异常:{str(e)}", exc_info=True)
|
|
|
log.info("查询变量信息列表成功")
|
|
log.info("查询变量信息列表成功")
|
|
|
return SuccessResponse(data=result_dict, msg="查询变量信息列表成功")
|
|
return SuccessResponse(data=result_dict, msg="查询变量信息列表成功")
|
|
|
@BizVarDictRouter.get("/list_analog", summary="查询变量信息列表", description="查询变量信息列表")
|
|
@BizVarDictRouter.get("/list_analog", summary="查询变量信息列表", description="查询变量信息列表")
|
|
@@ -216,24 +225,82 @@ async def get_vardict_mec_group_controller(
|
|
|
log.info(f"获取变量信息分组数据成功:{result_dict}")
|
|
log.info(f"获取变量信息分组数据成功:{result_dict}")
|
|
|
return SuccessResponse(data=result_dict, msg="获取变量分组数据成功")
|
|
return SuccessResponse(data=result_dict, msg="获取变量分组数据成功")
|
|
|
#请求采集接口获取状态信息
|
|
#请求采集接口获取状态信息
|
|
|
- async with httpx.AsyncClient() as client:
|
|
|
|
|
- response = await client.get(
|
|
|
|
|
- url=settings.COLLECT_DATA_FULL,
|
|
|
|
|
- params={},
|
|
|
|
|
- timeout=2
|
|
|
|
|
- )
|
|
|
|
|
- if response.status_code == 200:
|
|
|
|
|
|
|
+ try:
|
|
|
|
|
+ async with httpx.AsyncClient() as client:
|
|
|
|
|
+ response = await client.get(
|
|
|
|
|
+ url=settings.COLLECT_DATA_FULL,
|
|
|
|
|
+ params={},
|
|
|
|
|
+ timeout=2
|
|
|
|
|
+ )
|
|
|
|
|
+ # 捕获HTTP状态码非200的情况
|
|
|
|
|
+ response.raise_for_status()
|
|
|
|
|
+ # 捕获JSON解析异常
|
|
|
json_data = response.json()
|
|
json_data = response.json()
|
|
|
- if json_data['code'] == 200 and json_data['data']:
|
|
|
|
|
|
|
+ if json_data['code'] == 200 and json_data.get('data'):
|
|
|
json_analog = json_data.get('data').get(crane_no).get('data').get('analog')
|
|
json_analog = json_data.get('data').get(crane_no).get('data').get('analog')
|
|
|
json_digital = json_data.get('data').get(crane_no).get('data').get('digital')
|
|
json_digital = json_data.get('data').get(crane_no).get('data').get('digital')
|
|
|
for var_dict in result_dict:
|
|
for var_dict in result_dict:
|
|
|
- for key,inner_dict in var_dict.items():
|
|
|
|
|
|
|
+ for key, inner_dict in var_dict.items():
|
|
|
if key != 'mec_type' and key != 'alarm_varList' and key != 'mecVarList_simple':
|
|
if key != 'mec_type' and key != 'alarm_varList' and key != 'mecVarList_simple':
|
|
|
for item in inner_dict:
|
|
for item in inner_dict:
|
|
|
if key == 'digital_varList':
|
|
if key == 'digital_varList':
|
|
|
- item['value'] = json_digital.get(item.get('var_code')).get('value')
|
|
|
|
|
|
|
+ if json_digital:
|
|
|
|
|
+ item['value'] = json_digital.get(item.get('var_code')).get('value')
|
|
|
else:
|
|
else:
|
|
|
- item['value'] = json_analog.get(item.get('var_code')).get('value')
|
|
|
|
|
|
|
+ if json_analog:
|
|
|
|
|
+ item['value'] = json_analog.get(item.get('var_code')).get('value')
|
|
|
|
|
+ except Exception as e:
|
|
|
|
|
+ log.error(f"调用采集接口获取分组变量状态时发生未知异常:{str(e)}", exc_info=True)
|
|
|
log.info(f"获取变量信息分组数据成功:{result_dict}")
|
|
log.info(f"获取变量信息分组数据成功:{result_dict}")
|
|
|
- return SuccessResponse(data=result_dict, msg="获取变量分组数据成功")
|
|
|
|
|
|
|
+ return SuccessResponse(data=result_dict, msg="获取变量分组数据成功")
|
|
|
|
|
+
|
|
|
|
|
+@BizVarDictRouter.get("/historyData", summary="查询历史数据列表", description="查询历史数据列表")
|
|
|
|
|
+async def get_vardict_historyData_controller(
|
|
|
|
|
+ page: PaginationQueryParam = Depends(),
|
|
|
|
|
+ search: BizVarDictQueryParam = Depends(),
|
|
|
|
|
+ auth: AuthSchema = Depends(AuthPermission(["module_business:vardict:query"]))
|
|
|
|
|
+) -> JSONResponse:
|
|
|
|
|
+ search.data_type = ('!=', 1)
|
|
|
|
|
+ result_dict = await BizVarDictService.get_tdengine_data(
|
|
|
|
|
+ search=search,
|
|
|
|
|
+ stable_name='st_analog',
|
|
|
|
|
+ page_no=page.page_no if page.page_no is not None else 1,
|
|
|
|
|
+ page_size=page.page_size if page.page_size is not None else 10,
|
|
|
|
|
+ auth=auth
|
|
|
|
|
+ )
|
|
|
|
|
+ log.info("查询历史数据列表成功")
|
|
|
|
|
+ return SuccessResponse(data=result_dict, msg="查询历史数据列表成功")
|
|
|
|
|
+
|
|
|
|
|
+@BizVarDictRouter.get("/operationRecord", summary="查询操作记录列表", description="查询操作记录列表")
|
|
|
|
|
+async def get_vardict_operationRecord_controller(
|
|
|
|
|
+ page: PaginationQueryParam = Depends(),
|
|
|
|
|
+ search: BizVarDictQueryParam = Depends(),
|
|
|
|
|
+ auth: AuthSchema = Depends(AuthPermission(["module_business:vardict:query"]))
|
|
|
|
|
+) -> JSONResponse:
|
|
|
|
|
+
|
|
|
|
|
+ result_dict = await BizVarDictService.get_tdengine_data(
|
|
|
|
|
+ search=search,
|
|
|
|
|
+ stable_name='st_digital',
|
|
|
|
|
+ page_no=page.page_no if page.page_no is not None else 1,
|
|
|
|
|
+ page_size=page.page_size if page.page_size is not None else 10,
|
|
|
|
|
+ auth=auth
|
|
|
|
|
+ )
|
|
|
|
|
+ log.info("查询操作记录列表成功")
|
|
|
|
|
+ return SuccessResponse(data=result_dict, msg="查询操作记录列表成功")
|
|
|
|
|
+
|
|
|
|
|
+@BizVarDictRouter.get("/historyAlarm", summary="查询报警记录列表", description="查询报警记录列表")
|
|
|
|
|
+async def get_vardict_historyAlarm_controller(
|
|
|
|
|
+ page: PaginationQueryParam = Depends(),
|
|
|
|
|
+ search: BizVarDictQueryParam = Depends(),
|
|
|
|
|
+ auth: AuthSchema = Depends(AuthPermission(["module_business:vardict:query"]))
|
|
|
|
|
+) -> JSONResponse:
|
|
|
|
|
+
|
|
|
|
|
+ result_dict = await BizVarDictService.get_tdengine_data(
|
|
|
|
|
+ search=search,
|
|
|
|
|
+ stable_name='st_alarm',
|
|
|
|
|
+ page_no=page.page_no if page.page_no is not None else 1,
|
|
|
|
|
+ page_size=page.page_size if page.page_size is not None else 10,
|
|
|
|
|
+ auth=auth
|
|
|
|
|
+ )
|
|
|
|
|
+ log.info("查询报警记录列表成功")
|
|
|
|
|
+ return SuccessResponse(data=result_dict, msg="查询报警记录列表成功")
|