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
|
2026-04-07 09:51:38 +08:00
|
|
|
|
from datetime import datetime,timedelta
|
2026-03-13 21:04:19 +08:00
|
|
|
|
from busisness.models import ArtifactInfoModel, PDRecordModel,FreqRecordModel
|
|
|
|
|
|
from busisness.dals import ArtifactDal, PDRecordDal,FreqRecordDal
|
2025-10-31 18:52:31 +08:00
|
|
|
|
|
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
|
|
|
|
"""获取官片任务数据"""
|
2025-11-17 00:05:40 +08:00
|
|
|
|
return self.dal.get_top_artifact(5, "ID desc")
|
2025-10-31 18:52:31 +08:00
|
|
|
|
|
2025-11-17 00:05:40 +08:00
|
|
|
|
def update_artifact_task(self, artifact_id: str, status: int) -> bool:
|
|
|
|
|
|
"""更新管片任务状态"""
|
|
|
|
|
|
return self.dal.update_artifact(artifact_id, {"Status": status})
|
|
|
|
|
|
|
2026-02-09 11:36:37 +08:00
|
|
|
|
def start_produce(self, code: str) -> bool:
|
|
|
|
|
|
"""开始管片生产"""
|
|
|
|
|
|
return self.dal.update_by_modulecode(code, {'Status': 2,'BeginTime':datetime.now()})
|
|
|
|
|
|
|
|
|
|
|
|
def finish_produce(self, code: str,weight:float) -> bool:
|
|
|
|
|
|
"""完成管片生产"""
|
|
|
|
|
|
return self.dal.update_by_modulecode(code, {'Status': 3,'EndTime':datetime.now(),'FBetonVolume':weight})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def finish_artifact_task(self, artifact_id: str,beton_volume:float) -> bool:
|
2025-11-17 00:05:40 +08:00
|
|
|
|
"""完成管片任务"""
|
|
|
|
|
|
return self.dal.update_artifact(artifact_id, {"Status": 3,"BetonVolume":beton_volume,"EndTime":datetime.now()})
|
|
|
|
|
|
|
|
|
|
|
|
def insert_artifact_task(self,model:ArtifactInfoModel) -> bool:
|
|
|
|
|
|
|
|
|
|
|
|
"""插入管片任务"""
|
2026-02-09 11:36:37 +08:00
|
|
|
|
if self.dal.get_artifactid(model.MouldCode):
|
|
|
|
|
|
return False
|
|
|
|
|
|
return self.dal.insert_artifact(model)
|
|
|
|
|
|
|
|
|
|
|
|
def save_artifact_task(self,model:ArtifactInfoModel) -> int:
|
|
|
|
|
|
|
|
|
|
|
|
"""保存管片任务(存在ModuleCode更新,不存在插入,存在ArtifactID不处理)"""
|
|
|
|
|
|
_artifactid=self.dal.get_artifactid(model.MouldCode)
|
|
|
|
|
|
if _artifactid is None:
|
|
|
|
|
|
return self.dal.insert_artifact(model)
|
|
|
|
|
|
else:
|
2026-04-07 09:51:38 +08:00
|
|
|
|
if model.ArtifactID:
|
|
|
|
|
|
if not _artifactid:
|
|
|
|
|
|
#不存在ArtifactID,更新
|
|
|
|
|
|
update_dict={
|
|
|
|
|
|
'ArtifactID':model.ArtifactID,
|
|
|
|
|
|
'ArtifactActionID':model.ArtifactActionID,
|
|
|
|
|
|
'ArtifactIDVice1':model.ArtifactIDVice1,
|
|
|
|
|
|
'ProduceRingNumber':model.ProduceRingNumber,
|
|
|
|
|
|
'SkeletonID':model.SkeletonID,
|
|
|
|
|
|
'RingTypeCode':model.RingTypeCode,
|
|
|
|
|
|
'SizeSpecification':model.SizeSpecification,
|
|
|
|
|
|
'BuriedDepth':model.BuriedDepth,
|
|
|
|
|
|
'BlockNumber':model.BlockNumber,
|
|
|
|
|
|
'HoleRingMarking':model.HoleRingMarking,
|
|
|
|
|
|
'GroutingPipeMarking':model.GroutingPipeMarking,
|
|
|
|
|
|
'PolypropyleneFiberMarking':model.PolypropyleneFiberMarking,
|
|
|
|
|
|
'BetonVolume':model.BetonVolume,
|
|
|
|
|
|
'BetonTaskID':model.BetonTaskID,
|
|
|
|
|
|
}
|
|
|
|
|
|
return self.dal.update_by_modulecode(model.MouldCode, update_dict)
|
|
|
|
|
|
else:
|
|
|
|
|
|
#已经存在了ArtifactID,不处理
|
|
|
|
|
|
return 1
|
2026-02-09 11:36:37 +08:00
|
|
|
|
|
|
|
|
|
|
return 1
|
|
|
|
|
|
|
2025-10-31 14:30:42 +08:00
|
|
|
|
|
2025-12-28 17:20:02 +08:00
|
|
|
|
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,
|
2026-01-04 11:48:12 +08:00
|
|
|
|
"Status": 1,
|
2025-12-28 17:20:02 +08:00
|
|
|
|
"Source": 2,
|
|
|
|
|
|
"OptTime": datetime.now(),
|
|
|
|
|
|
})
|
|
|
|
|
|
|
2025-11-01 17:33:26 +08:00
|
|
|
|
def get_artifacting_task(self) -> ArtifactInfoModel:
|
2025-11-17 00:05:40 +08:00
|
|
|
|
"""获取正在进行的管片任务数据"""
|
2025-11-21 14:55:52 +08:00
|
|
|
|
loc_item= self.dal.get_top_artifact(1,"ID desc","Status=2")
|
2025-11-01 17:33:26 +08:00
|
|
|
|
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
|
|
|
|
|
2026-03-13 21:04:19 +08:00
|
|
|
|
def get_last_pds(self,mould_code:str,top=1) -> List[PDRecordModel]:
|
2026-02-09 11:36:37 +08:00
|
|
|
|
"""获取当前浇筑的后三片的派据(有可能其中一项为空,但需要保证第一条有记录)"""
|
2026-03-13 21:04:19 +08:00
|
|
|
|
return self.dal.get_last_pds(top,mould_code)
|
2026-02-09 11:36:37 +08:00
|
|
|
|
|
2026-04-07 09:51:38 +08:00
|
|
|
|
def get_near_pd_scan(self,size:str) -> PDRecordModel:
|
|
|
|
|
|
"""获取最近的派单信息"""
|
|
|
|
|
|
_target_time = datetime.now() - timedelta(hours=4)
|
|
|
|
|
|
where=f"SizeSpecification='{size}' and CreateTime>='{_target_time}'"
|
|
|
|
|
|
_pdrecords=self.dal.get_top_pd(1,"ID desc",where)
|
|
|
|
|
|
if _pdrecords:
|
|
|
|
|
|
return _pdrecords[0]
|
|
|
|
|
|
else:
|
|
|
|
|
|
return None
|
|
|
|
|
|
|
2026-02-09 11:36:37 +08:00
|
|
|
|
def insert_PD_record(self,model:PDRecordModel) -> bool:
|
|
|
|
|
|
"""保存PD官片任务(存在更新,不存在插入)"""
|
|
|
|
|
|
if self.dal.exists_artifactid(model.ArtifactActionID):
|
|
|
|
|
|
return False
|
|
|
|
|
|
# return self.update_PD_record(model.ArtifactActionID,{"Status": model.Status,"OptTime": datetime.now()})
|
|
|
|
|
|
else:
|
|
|
|
|
|
return self.dal.insert_PD_record(model)
|
|
|
|
|
|
|
|
|
|
|
|
def finish_pd(self, code: str,status:int) -> bool:
|
|
|
|
|
|
"""完成管片生产"""
|
|
|
|
|
|
return self.dal.update_by_modulecode(code, {'Status': status,'EndTime':datetime.now()})
|
|
|
|
|
|
|
2026-04-07 09:51:38 +08:00
|
|
|
|
def start_pd(self, status:int,code: str,volumn:float) -> bool:
|
|
|
|
|
|
"""开始管片生产,-1不更方量"""
|
|
|
|
|
|
if volumn==-1:
|
|
|
|
|
|
return self.dal.update_by_modulecode(code, {'Status': status,'GStatus':1,'OptTime':datetime.now()})
|
|
|
|
|
|
else:
|
|
|
|
|
|
return self.dal.update_by_modulecode(code, {'Status': status,'GStatus':1,'OptTime':datetime.now(),'FBetonVolume':volumn})
|
2026-02-09 11:36:37 +08:00
|
|
|
|
|
|
|
|
|
|
def update_PD_record(self,artifact_action_id: int, update_fields: dict) -> bool:
|
|
|
|
|
|
"""更新PD官片任务状态"""
|
|
|
|
|
|
return self.dal.update_pd(artifact_action_id, update_fields)
|
|
|
|
|
|
|
2026-03-13 21:04:19 +08:00
|
|
|
|
def update_PD_record_byid(self,id: int, update_fields: dict) -> bool:
|
|
|
|
|
|
"""更新PD官片任务状态"""
|
|
|
|
|
|
return self.dal.update_pd_byid(id, update_fields)
|
|
|
|
|
|
|
2026-04-07 09:51:38 +08:00
|
|
|
|
def update_pd_notify(self,id: int, update_fields: dict) -> bool:
|
|
|
|
|
|
"""更新PD官片任务状态"""
|
|
|
|
|
|
return self.dal.update_pd_notify(id, update_fields)
|
|
|
|
|
|
|
2026-02-09 11:36:37 +08:00
|
|
|
|
def save_PD_record(self,model:PDRecordModel) -> int:
|
|
|
|
|
|
|
|
|
|
|
|
"""保存PD官片任务(存在ModuleCode更新,不存在插入,存在ArtifactID不处理)"""
|
|
|
|
|
|
_artifactid=self.dal.get_artifactid(model.MouldCode)
|
|
|
|
|
|
if _artifactid is None:
|
2026-04-07 09:51:38 +08:00
|
|
|
|
if model.TaskID:
|
|
|
|
|
|
model.ScanTime=datetime.now()
|
2026-02-09 11:36:37 +08:00
|
|
|
|
return self.dal.insert_PD_record(model)
|
|
|
|
|
|
else:
|
2026-04-07 09:51:38 +08:00
|
|
|
|
if model.ArtifactID:
|
|
|
|
|
|
if not _artifactid:
|
|
|
|
|
|
#不存在ArtifactID,更新PDRecord表
|
|
|
|
|
|
update_dict={
|
|
|
|
|
|
'ArtifactID':model.ArtifactID,
|
|
|
|
|
|
'ArtifactActionID':model.ArtifactActionID,
|
|
|
|
|
|
'TaskID':model.TaskID,
|
|
|
|
|
|
'ProjectName':model.ProjectName,
|
|
|
|
|
|
'ProduceMixID':model.ProduceMixID,
|
|
|
|
|
|
'BetonVolume':model.BetonVolume,
|
|
|
|
|
|
'BetonGrade':model.BetonGrade,
|
|
|
|
|
|
'BuriedDepth':model.BuriedDepth,
|
|
|
|
|
|
'SkeletonID':model.SkeletonID,
|
|
|
|
|
|
'RingTypeCode':model.RingTypeCode,
|
|
|
|
|
|
'SizeSpecification':model.SizeSpecification,
|
|
|
|
|
|
'BlockNumber':model.BlockNumber,
|
|
|
|
|
|
'BetonVolume':model.BetonVolume,
|
|
|
|
|
|
'GStatus':model.GStatus,
|
|
|
|
|
|
'PlannedVolume':model.PlannedVolume,
|
|
|
|
|
|
'ScanTime':datetime.now(),
|
|
|
|
|
|
}
|
|
|
|
|
|
return self.dal.update_by_modulecode(model.MouldCode, update_dict)
|
|
|
|
|
|
else:
|
|
|
|
|
|
#已经存在了ArtifactID,不处理
|
|
|
|
|
|
return 1
|
2026-02-09 11:36:37 +08:00
|
|
|
|
|
|
|
|
|
|
return 1
|
|
|
|
|
|
|
2026-03-13 21:04:19 +08:00
|
|
|
|
class FreqRecordBll:
|
|
|
|
|
|
def __init__(self):
|
|
|
|
|
|
"""初始化数据访问层,创建数据库连接"""
|
|
|
|
|
|
# 假设数据库文件在db目录下
|
|
|
|
|
|
self.dal = FreqRecordDal()
|
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
def get_freqs_sync(self) -> List[FreqRecordModel]:
|
|
|
|
|
|
"""获取所有未同步的频率记录"""
|
|
|
|
|
|
return self.dal.get_all_sync()
|
|
|
|
|
|
|
|
|
|
|
|
def insert_freq_record(self,model:FreqRecordModel) -> int:
|
|
|
|
|
|
"""插入一条频率记录"""
|
|
|
|
|
|
return self.dal.insert_record(model)
|
2025-10-31 14:30:42 +08:00
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2026-02-09 11:36:37 +08:00
|
|
|
|
# artifact_dal = ArtifactBll()
|
2025-10-31 18:52:31 +08:00
|
|
|
|
|
2026-02-09 11:36:37 +08:00
|
|
|
|
# artifacts = artifact_dal.get_artifact_task()
|
2025-11-01 17:33:26 +08:00
|
|
|
|
|
2026-02-09 11:36:37 +08:00
|
|
|
|
# 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}")
|
2025-10-31 18:52:31 +08:00
|
|
|
|
|
|
|
|
|
|
pdrecord_dal = PDRecordBll()
|
2026-02-09 11:36:37 +08:00
|
|
|
|
pdrecords = pdrecord_dal.get_last_pds("SHR2B2-11")
|
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}")
|