142 lines
5.3 KiB
Python
142 lines
5.3 KiB
Python
# import os
|
||
# import sys
|
||
|
||
# # 添加项目根目录到Python路径
|
||
# sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
|
||
|
||
from dataclasses import fields
|
||
from typing import List, Optional, Dict, Any
|
||
from datetime import datetime
|
||
from .models import ArtifactInfoModel, PDRecordModel
|
||
from .dals import ArtifactDal, PDRecordDal
|
||
|
||
|
||
class ArtifactBll:
|
||
def __init__(self):
|
||
"""初始化数据访问层,创建数据库连接"""
|
||
# 假设数据库文件在db目录下
|
||
self.dal = ArtifactDal()
|
||
pass
|
||
|
||
def get_artifact_task(self) -> List[ArtifactInfoModel]:
|
||
"""获取官片任务数据"""
|
||
return self.dal.get_top_artifact(5, "ID desc")
|
||
|
||
def update_artifact_task(self, artifact_id: str, status: int) -> bool:
|
||
"""更新管片任务状态"""
|
||
return self.dal.update_artifact(artifact_id, {"Status": status})
|
||
|
||
def finish_artifact_task(self, artifact_id: str,beton_volume) -> bool:
|
||
"""完成管片任务"""
|
||
return self.dal.update_artifact(artifact_id, {"Status": 3,"BetonVolume":beton_volume,"EndTime":datetime.now()})
|
||
|
||
def insert_artifact_task(self,model:ArtifactInfoModel) -> bool:
|
||
|
||
"""插入管片任务"""
|
||
if self.dal.exists_by_id(model.ArtifactID):
|
||
return False
|
||
return self.dal.insert_artifact({
|
||
"ArtifactID": model.ArtifactID,
|
||
"ArtifactActionID": model.ArtifactActionID,
|
||
"ArtifactIDVice1": model.ArtifactIDVice1,
|
||
"ProduceRingNumber": model.ProduceRingNumber,
|
||
"MouldCode": model.MouldCode,
|
||
"SkeletonID": model.SkeletonID,
|
||
"RingTypeCode": model.RingTypeCode,
|
||
"SizeSpecification": model.SizeSpecification,
|
||
"BuriedDepth": model.BuriedDepth,
|
||
"BlockNumber": model.BlockNumber,
|
||
"BetonVolume": model.BetonVolume,
|
||
"BetonTaskID": model.BetonTaskID,
|
||
"HoleRingMarking": model.HoleRingMarking,
|
||
"GroutingPipeMarking": model.GroutingPipeMarking,
|
||
"PolypropyleneFiberMarking": model.PolypropyleneFiberMarking,
|
||
"PStatus":1,
|
||
"Status": 2,
|
||
"Source": model.Source,
|
||
"BeginTime": model.BeginTime,
|
||
"OptTime": datetime.now(),
|
||
})
|
||
|
||
def insert_artifact_bycode(self,model: dict) -> bool:
|
||
|
||
"""根据模具编号插入管片任务"""
|
||
if self.dal.exists_by_module_code(model["MouldCode"]):
|
||
return False
|
||
return self.dal.insert_artifact({
|
||
"MouldCode": model["MouldCode"],
|
||
"SizeSpecification": model["SizeSpecification"],
|
||
"BlockNumber": model["BlockNumber"],
|
||
"BetonVolume": model["BetonVolume"],
|
||
"PStatus":1,
|
||
"Status": 1,
|
||
"Source": 2,
|
||
"OptTime": datetime.now(),
|
||
})
|
||
|
||
def get_artifacting_task(self) -> ArtifactInfoModel:
|
||
"""获取正在进行的管片任务数据"""
|
||
loc_item= self.dal.get_top_artifact(1,"ID desc","Status=2")
|
||
if loc_item:
|
||
return loc_item[0]
|
||
else:
|
||
return None
|
||
|
||
class PDRecordBll:
|
||
def __init__(self):
|
||
"""初始化数据访问层,创建数据库连接"""
|
||
# 假设数据库文件在db目录下
|
||
self.dal = PDRecordDal()
|
||
pass
|
||
|
||
def get_PD_record(self) -> List[PDRecordModel]:
|
||
"""获取PD官片任务数据"""
|
||
return self.dal.get_top_pd(5, "ID desc")
|
||
|
||
|
||
if __name__ == "__main__":
|
||
artifact_dal = ArtifactBll()
|
||
|
||
artifacts = artifact_dal.get_artifact_task()
|
||
|
||
print("\n打印artifacts数据:")
|
||
for i, artifact in enumerate(artifacts):
|
||
artifact_id = artifact.ArtifactID
|
||
# 如果是数据类对象,转换为字典输出
|
||
print(artifact.MouldCode)
|
||
if hasattr(artifact, "__dataclass_fields__"):
|
||
print(f"第{i+1}条: {artifact.__dict__}")
|
||
else:
|
||
print(f"第{i+1}条: {artifact}")
|
||
|
||
pdrecord_dal = PDRecordBll()
|
||
pdrecords = pdrecord_dal.get_PD_record()
|
||
# print(pdrecords[0].MouldCode)
|
||
print("\n打印pdrecords数据:")
|
||
for i, record in enumerate(pdrecords):
|
||
# 如果是数据类对象,转换为字典输出
|
||
# print(record.__dict__["MouldCode"])
|
||
if hasattr(record, "__dataclass_fields__"):
|
||
print(f"第{i+1}条: {record.__dict__}")
|
||
else:
|
||
print(f"第{i+1}条: {record}")
|
||
|
||
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}")
|