Files
Feeding_control_system/busisness/blls.py

91 lines
3.1 KiB
Python
Raw Normal View History

2025-10-31 18:52:31 +08:00
# import os
# import sys
# # 添加项目根目录到Python路径
# sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
2025-10-31 14:30:42 +08:00
from dataclasses import fields
from typing import List, Optional, Dict, Any
from datetime import datetime
2025-10-31 18:52:31 +08:00
from .models import ArtifactInfoModel, PDRecordModel
from .dals import ArtifactDal, PDRecordDal
2025-10-31 14:30:42 +08:00
class ArtifactBll:
def __init__(self):
"""初始化数据访问层,创建数据库连接"""
# 假设数据库文件在db目录下
self.dal = ArtifactDal()
pass
2025-10-31 18:52:31 +08:00
2025-10-31 14:30:42 +08:00
def get_artifact_task(self) -> List[ArtifactInfoModel]:
2025-10-31 18:52:31 +08:00
"""获取官片任务数据"""
return self.dal.get_top_artifact(5, "ArtifactID asc")
2025-10-31 14:30:42 +08:00
2025-11-01 17:33:26 +08:00
def get_artifacting_task(self) -> ArtifactInfoModel:
"""获取正在进行的官片任务数据"""
loc_item= self.dal.get_top_artifact(1,"","Status=2")
if loc_item:
return loc_item[0]
else:
return None
2025-10-31 14:30:42 +08:00
class PDRecordBll:
def __init__(self):
"""初始化数据访问层,创建数据库连接"""
# 假设数据库文件在db目录下
self.dal = PDRecordDal()
pass
2025-10-31 18:52:31 +08:00
2025-10-31 14:30:42 +08:00
def get_PD_record(self) -> List[PDRecordModel]:
2025-10-31 18:52:31 +08:00
"""获取PD官片任务数据"""
return self.dal.get_top_pd(5, "ID desc")
2025-10-31 14:30:42 +08:00
if __name__ == "__main__":
artifact_dal = ArtifactBll()
2025-10-31 18:52:31 +08:00
2025-10-31 14:30:42 +08:00
artifacts = artifact_dal.get_artifact_task()
2025-11-01 17:33:26 +08:00
2025-10-31 14:30:42 +08:00
print("\n打印artifacts数据:")
for i, artifact in enumerate(artifacts):
2025-11-01 17:33:26 +08:00
artifact_id = artifact.ArtifactID
2025-10-31 14:30:42 +08:00
# 如果是数据类对象,转换为字典输出
2025-10-31 18:52:31 +08:00
print(artifact.MouldCode)
if hasattr(artifact, "__dataclass_fields__"):
2025-10-31 14:30:42 +08:00
print(f"{i+1}条: {artifact.__dict__}")
else:
print(f"{i+1}条: {artifact}")
2025-10-31 18:52:31 +08:00
pdrecord_dal = PDRecordBll()
2025-10-31 14:30:42 +08:00
pdrecords = pdrecord_dal.get_PD_record()
2025-10-31 18:52:31 +08:00
# print(pdrecords[0].MouldCode)
2025-10-31 14:30:42 +08:00
print("\n打印pdrecords数据:")
for i, record in enumerate(pdrecords):
# 如果是数据类对象,转换为字典输出
2025-10-31 18:52:31 +08:00
# print(record.__dict__["MouldCode"])
if hasattr(record, "__dataclass_fields__"):
2025-10-31 14:30:42 +08:00
print(f"{i+1}条: {record.__dict__}")
else:
print(f"{i+1}条: {record}")
2025-10-31 18:52:31 +08:00
print("\ntest success")
# # 1. 提取 artifacts 中第1-3条的 MouldCode 和对应的 BetonVolume
# print("=== artifacts 提取结果 ===")
# artifact_extracts = []
# for i, artifact in enumerate(artifacts[:3], 1): # 取前3条正好3条
# mould_code = artifact['MouldCode']
# beton_volume = artifact['BetonVolume']
# artifact_extracts.append({'序号': i, 'MouldCode': mould_code, 'BetonVolume': beton_volume})
# print(f"第{i}条: MouldCode={mould_code}, BetonVolume={beton_volume}")
# # 2. 提取 pdrecords 中的所有 BetonVolume
# print("\n=== pdrecords 提取结果 ===")
# pd_beton_volumes = []
# for i, record in enumerate(pdrecords, 1):
# beton_volume = record['BetonVolume']
# pd_beton_volumes.append({'序号': i, 'BetonVolume': beton_volume})
# print(f"第{i}条: BetonVolume={beton_volume}")