0313界面对接
This commit is contained in:
@ -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
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user