0313界面对接
This commit is contained in:
@ -6,8 +6,8 @@
|
||||
from dataclasses import fields
|
||||
from typing import List, Optional, Dict, Any
|
||||
from datetime import datetime
|
||||
from busisness.models import ArtifactInfoModel, PDRecordModel
|
||||
from busisness.dals import ArtifactDal, PDRecordDal
|
||||
from busisness.models import ArtifactInfoModel, PDRecordModel,FreqRecordModel
|
||||
from busisness.dals import ArtifactDal, PDRecordDal,FreqRecordDal
|
||||
|
||||
|
||||
class ArtifactBll:
|
||||
@ -109,9 +109,9 @@ class PDRecordBll:
|
||||
"""获取PD官片任务数据"""
|
||||
return self.dal.get_top_pd(5, "ID desc")
|
||||
|
||||
def get_last_pds(self,mould_code:str) -> List[PDRecordModel]:
|
||||
def get_last_pds(self,mould_code:str,top=1) -> List[PDRecordModel]:
|
||||
"""获取当前浇筑的后三片的派据(有可能其中一项为空,但需要保证第一条有记录)"""
|
||||
return self.dal.get_last_pds(1,mould_code)
|
||||
return self.dal.get_last_pds(top,mould_code)
|
||||
|
||||
def insert_PD_record(self,model:PDRecordModel) -> bool:
|
||||
"""保存PD官片任务(存在更新,不存在插入)"""
|
||||
@ -127,12 +127,16 @@ class PDRecordBll:
|
||||
|
||||
def start_pd(self, code: str,volumn:float) -> bool:
|
||||
"""开始管片生产"""
|
||||
return self.dal.update_by_modulecode(code, {'Status': 2,'OptTime':datetime.now(),'FBetonVolume':volumn})
|
||||
return self.dal.update_by_modulecode(code, {'Status': 2,'GStatus':1,'OptTime':datetime.now(),'FBetonVolume':volumn})
|
||||
|
||||
def update_PD_record(self,artifact_action_id: int, update_fields: dict) -> bool:
|
||||
"""更新PD官片任务状态"""
|
||||
return self.dal.update_pd(artifact_action_id, update_fields)
|
||||
|
||||
def update_PD_record_byid(self,id: int, update_fields: dict) -> bool:
|
||||
"""更新PD官片任务状态"""
|
||||
return self.dal.update_pd_byid(id, update_fields)
|
||||
|
||||
def save_PD_record(self,model:PDRecordModel) -> int:
|
||||
|
||||
"""保存PD官片任务(存在ModuleCode更新,不存在插入,存在ArtifactID不处理)"""
|
||||
@ -155,13 +159,27 @@ class PDRecordBll:
|
||||
'SizeSpecification':model.SizeSpecification,
|
||||
'BlockNumber':model.BlockNumber,
|
||||
'BetonVolume':model.BetonVolume,
|
||||
'GStatus':model.GStatus,
|
||||
'PlannedVolume':model.PlannedVolume
|
||||
}
|
||||
return self.dal.update_by_modulecode(model.MouldCode, update_dict)
|
||||
|
||||
return 1
|
||||
|
||||
|
||||
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)
|
||||
|
||||
if __name__ == "__main__":
|
||||
# artifact_dal = ArtifactBll()
|
||||
|
||||
@ -4,7 +4,7 @@ sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
from dataclasses import fields
|
||||
from typing import List, Optional, Dict, Any
|
||||
from datetime import datetime, timedelta
|
||||
from busisness.models import ArtifactInfoModel,PDRecordModel
|
||||
from busisness.models import ArtifactInfoModel,PDRecordModel,FreqRecordModel
|
||||
from common.sqlite_handler import SQLiteHandler
|
||||
|
||||
|
||||
@ -20,6 +20,7 @@ class BaseDal:
|
||||
"""初始化数据访问层,创建数据库连接"""
|
||||
# 假设数据库文件在db目录下
|
||||
self.db_dao = SQLiteHandler.get_instance("db/three.db", max_readers=50, busy_timeout=4000)
|
||||
self.db_dao_record = SQLiteHandler.get_instance("db/three-record.db", max_readers=50, busy_timeout=4000)
|
||||
|
||||
class ArtifactDal(BaseDal):
|
||||
def __init__(self):
|
||||
@ -202,6 +203,7 @@ class PDRecordDal(BaseDal):
|
||||
pdrecord = PDRecordModel()
|
||||
pdrecord.ID=row["ID"]
|
||||
pdrecord.ArtifactID=row["ArtifactID"]
|
||||
pdrecord.ArtifactActionID=row["ArtifactActionID"]
|
||||
pdrecord.TaskID=row["TaskID"]
|
||||
pdrecord.ProjectName=row["ProjectName"]
|
||||
pdrecord.ProduceMixID=row["ProduceMixID"]
|
||||
@ -231,12 +233,12 @@ class PDRecordDal(BaseDal):
|
||||
# 确保top为正整数
|
||||
if not isinstance(top, int) or top <= 0:
|
||||
raise ValueError("top参数必须是正整数")
|
||||
_target_time = datetime.now() - timedelta(hours=4)
|
||||
# 查询指定数量的记录,按ID降序排列
|
||||
# _target_time = datetime.now() - timedelta(hours=4)
|
||||
_target_time ='2026-02-06 00:00:00'
|
||||
# 查询当前浇筑模具编号的前一条记录
|
||||
sql = f"""SELECT * FROM PDRecord WHERE CreateTime>? and ID>(
|
||||
select ID FROM PDRecord WHERE MouldCode=? and CreateTime>?
|
||||
)
|
||||
order by ID asc LIMIT ?"""
|
||||
select ID FROM PDRecord WHERE MouldCode=? and CreateTime>?
|
||||
) order by ID asc LIMIT ?"""
|
||||
results = self.db_dao.execute_read(sql, (_target_time,mould_code,_target_time,top))
|
||||
|
||||
pdrecords = []
|
||||
@ -316,17 +318,67 @@ order by ID asc LIMIT ?"""
|
||||
print(f"更新PD管片任务失败: {e}")
|
||||
return False
|
||||
|
||||
def update_by_modulecode(self, module_code: str, update_data: dict) -> int:
|
||||
def update_pd_byid(self, id: int, update_data: dict) -> bool:
|
||||
"""更新PD官片任务记录"""
|
||||
try:
|
||||
# 构建WHERE条件
|
||||
where_condition = f"ID={id}"
|
||||
# 使用update方法更新数据
|
||||
affected_rows = self.db_dao.update("PDRecord", update_data, where_condition)
|
||||
return affected_rows > 0
|
||||
except Exception as e:
|
||||
print(f"更新PD管片任务失败: {e}")
|
||||
return False
|
||||
|
||||
def update_by_modulecode(self, module_code: str, update_data: dict) -> bool:
|
||||
"""更新构件派单记录"""
|
||||
try:
|
||||
# 构建WHERE条件
|
||||
_target_time = datetime.now() - timedelta(hours=4)
|
||||
_target_time ='2026-02-06 00:00:00'
|
||||
where_condition = f"MouldCode='{module_code}' and CreateTime>='{_target_time}'"
|
||||
# 使用update方法更新数据
|
||||
affected_rows = self.db_dao.update("PDRecord", update_data, where_condition)
|
||||
return affected_rows
|
||||
return affected_rows > 0
|
||||
except Exception as e:
|
||||
print(f"更新PD官片任务失败: {e}")
|
||||
return False
|
||||
|
||||
class FreqRecordDal(BaseDal):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
def get_all_sync(self) -> List[FreqRecordModel]:
|
||||
"""获取未同步的记录"""
|
||||
try:
|
||||
# 查询所有记录
|
||||
sql = "SELECT * FROM FreqRecord WHERE IsSync=0"
|
||||
results = self.db_dao.execute_read(sql)
|
||||
|
||||
# 将查询结果转换为FreqRecord对象列表
|
||||
artifacts = []
|
||||
for row in results:
|
||||
# 过滤字典,只保留模型中定义的字段
|
||||
# filtered_data = filter_dict_for_model(dict(row), ArtifactInfoModel)
|
||||
artifact = FreqRecordModel(**row)
|
||||
artifacts.append(artifact)
|
||||
|
||||
return artifacts
|
||||
except Exception as e:
|
||||
print(f"获取所有频率记录失败: {e}")
|
||||
return []
|
||||
|
||||
|
||||
def insert_record(self, model: FreqRecordModel) -> int:
|
||||
"""插入一条频率记录"""
|
||||
try:
|
||||
# 使用insert方法插入数据
|
||||
model.OptTime=datetime.now()
|
||||
model.__dict__.pop("ID", None)
|
||||
row_id = self.db_dao_record.insert("FreqRecord", model.__dict__)
|
||||
return row_id
|
||||
except Exception as e:
|
||||
print(f"插入频率记录失败: {e}")
|
||||
return 0
|
||||
|
||||
|
||||
|
||||
@ -276,9 +276,9 @@ class PDRecordModel:
|
||||
BlockNumber: str=""
|
||||
# 派单模式(1自动派单 2手动派单0未知 )
|
||||
Mode: int=0
|
||||
# 派单状态(1计划中2已下发0未知),默认1
|
||||
# 派单状态((1计划中2已下发0未知 3已超时 4未扫码)),默认1
|
||||
Status: int=1
|
||||
#搅拌生产状态()
|
||||
#搅拌生产状态(搅拌生产状态(1未进行生产,2正在生产3生产完毕,4生产中断5已插入搅拌系统6已取消)
|
||||
GStatus: int=0
|
||||
#数据来源(1 api 2离线)
|
||||
Source: int=1
|
||||
@ -289,6 +289,25 @@ class PDRecordModel:
|
||||
#派单时间(下发)
|
||||
OptTime: str=""
|
||||
|
||||
|
||||
@dataclass
|
||||
class FreqRecordModel:
|
||||
"""频率记录"""
|
||||
ID: int=0
|
||||
#模具编号
|
||||
ArtifactID: str=""
|
||||
#模具ID
|
||||
ArtifactActionID: int=0
|
||||
#模具编号
|
||||
MouldCode: str=""
|
||||
#骨架编号
|
||||
Freq: float=0.0
|
||||
#是否已同步 0否 1是
|
||||
IsSync: int=0
|
||||
#记录时间
|
||||
OptTime: str=""
|
||||
|
||||
|
||||
@dataclass
|
||||
class LEDInfo:
|
||||
"""LED信息模型"""
|
||||
|
||||
Reference in New Issue
Block a user