变频器集成以及增加点动控制(0209)
This commit is contained in:
@ -1,7 +1,10 @@
|
||||
import os
|
||||
import sys
|
||||
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
|
||||
from .models import ArtifactInfoModel,PDRecordModel
|
||||
from datetime import datetime, timedelta
|
||||
from busisness.models import ArtifactInfoModel,PDRecordModel
|
||||
from common.sqlite_handler import SQLiteHandler
|
||||
|
||||
|
||||
@ -33,8 +36,8 @@ class ArtifactDal(BaseDal):
|
||||
artifacts = []
|
||||
for row in results:
|
||||
# 过滤字典,只保留模型中定义的字段
|
||||
filtered_data = filter_dict_for_model(dict(row), ArtifactInfoModel)
|
||||
artifact = ArtifactInfoModel(**filtered_data)
|
||||
# filtered_data = filter_dict_for_model(dict(row), ArtifactInfoModel)
|
||||
artifact = ArtifactInfoModel(**row)
|
||||
artifacts.append(artifact)
|
||||
|
||||
return artifacts
|
||||
@ -57,26 +60,9 @@ class ArtifactDal(BaseDal):
|
||||
artifacts = []
|
||||
for row in results:
|
||||
# 保证row的变量和模板变量一致
|
||||
artifact = ArtifactInfoModel()
|
||||
artifact.ArtifactID=row["ArtifactID"]
|
||||
artifact.ArtifactActionID=row["ArtifactActionID"]
|
||||
artifact.ArtifactIDVice1=row["ArtifactIDVice1"]
|
||||
artifact.ProduceRingNumber=row["ProduceRingNumber"]
|
||||
artifact.MouldCode=row["MouldCode"]
|
||||
artifact.SkeletonID=row["SkeletonID"]
|
||||
artifact.RingTypeCode=row["RingTypeCode"]
|
||||
artifact.SizeSpecification=row["SizeSpecification"]
|
||||
artifact.BuriedDepth=row["BuriedDepth"]
|
||||
artifact.BlockNumber=row["BlockNumber"]
|
||||
artifact.BetonVolume=row["BetonVolume"]
|
||||
artifact.BetonTaskID=row["BetonTaskID"]
|
||||
artifact.HoleRingMarking=row["HoleRingMarking"]
|
||||
artifact.GroutingPipeMarking=row["GroutingPipeMarking"]
|
||||
artifact.PolypropyleneFiberMarking=row["PolypropyleneFiberMarking"]
|
||||
artifact.Status=row["Status"]
|
||||
artifact.BeginTime=row["BeginTime"]
|
||||
artifact = ArtifactInfoModel(**row)
|
||||
artifacts.append(artifact)
|
||||
|
||||
|
||||
return artifacts
|
||||
except Exception as e:
|
||||
print(f"获取top构件任务失败: {e}")
|
||||
@ -103,7 +89,6 @@ class ArtifactDal(BaseDal):
|
||||
try:
|
||||
sql = "SELECT count(1) FROM ArtifactTask WHERE MouldCode = ? and OptTime>?"
|
||||
results = self.db_dao.execute_read(sql, (module_code,datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)))
|
||||
|
||||
rows = list(results)
|
||||
if rows[0][0] == 1:
|
||||
return True
|
||||
@ -112,6 +97,20 @@ class ArtifactDal(BaseDal):
|
||||
except Exception as e:
|
||||
print(f"根据ID获取构件任务失败: {e}")
|
||||
return False
|
||||
|
||||
def get_artifactid(self, module_code: str) -> Optional[str]:
|
||||
"""根据模具编号查找ID,根据ID确认是否扫码"""
|
||||
try:
|
||||
sql = "SELECT ArtifactID FROM ArtifactTask WHERE MouldCode = ? and OptTime>?"
|
||||
_target_time = datetime.now() - timedelta(hours=4)
|
||||
results = self.db_dao.fetch_one(sql, (module_code,_target_time))
|
||||
if results is None:
|
||||
return None
|
||||
else:
|
||||
return results['ArtifactID']
|
||||
except Exception as e:
|
||||
print(f"根据ID获取构件任务失败: {e}")
|
||||
return None
|
||||
|
||||
def get_by_id(self, artifact_id: int) -> Optional[ArtifactInfoModel]:
|
||||
"""根据构件ID获取构件任务"""
|
||||
@ -129,27 +128,43 @@ class ArtifactDal(BaseDal):
|
||||
return None
|
||||
|
||||
|
||||
def insert_artifact(self, artifact_data: dict) -> Optional[int]:
|
||||
def insert_artifact(self, model: ArtifactInfoModel) -> int:
|
||||
"""插入一条构件任务记录"""
|
||||
try:
|
||||
# 使用insert方法插入数据
|
||||
row_id = self.db_dao.insert("ArtifactTask", artifact_data)
|
||||
model.OptTime=datetime.now()
|
||||
model.__dict__.pop("ProductionProcessCode", None)
|
||||
model.__dict__.pop("ID", None)
|
||||
row_id = self.db_dao.insert("ArtifactTask", model.__dict__)
|
||||
return row_id
|
||||
except Exception as e:
|
||||
print(f"插入构件任务失败: {e}")
|
||||
return None
|
||||
return 0
|
||||
|
||||
def update_artifact(self, artifact_id: int, update_data: dict) -> bool:
|
||||
def update_artifact(self, artifact_id: int, update_data: dict) -> int:
|
||||
"""更新构件任务记录"""
|
||||
try:
|
||||
# 构建WHERE条件
|
||||
where_condition = f"ArtifactID='{artifact_id}'"
|
||||
# 使用update方法更新数据
|
||||
affected_rows = self.db_dao.update("ArtifactTask", update_data, where_condition)
|
||||
return affected_rows > 0
|
||||
return affected_rows
|
||||
except Exception as e:
|
||||
print(f"更新构件任务失败: {e}")
|
||||
return False
|
||||
return 0
|
||||
|
||||
def update_by_modulecode(self, module_code: str, update_data: dict) -> int:
|
||||
"""更新构件任务记录"""
|
||||
try:
|
||||
# 构建WHERE条件
|
||||
_target_time = datetime.now() - timedelta(hours=4)
|
||||
where_condition = f"MouldCode='{module_code}' and OptTime>='{_target_time}'"
|
||||
# 使用update方法更新数据
|
||||
affected_rows = self.db_dao.update("ArtifactTask", update_data, where_condition)
|
||||
return affected_rows
|
||||
except Exception as e:
|
||||
print(f"更新构件任务失败: {e}")
|
||||
return 0
|
||||
|
||||
def validate_artifact(self, artifact_info: ArtifactInfoModel) -> bool:
|
||||
"""验证构件信息是否符合业务规则"""
|
||||
@ -186,11 +201,11 @@ class PDRecordDal(BaseDal):
|
||||
#
|
||||
pdrecord = PDRecordModel()
|
||||
pdrecord.ID=row["ID"]
|
||||
pdrecord.PDCode=row["PDCode"]
|
||||
pdrecord.ArtifactID=row["ArtifactID"]
|
||||
pdrecord.TaskID=row["TaskID"]
|
||||
pdrecord.ProjectName=row["ProjectName"]
|
||||
pdrecord.ProduceMixID=row["ProduceMixID"]
|
||||
pdrecord.VinNo=row["VinNo"]
|
||||
pdrecord.FBetonVolume=row["FBetonVolume"]
|
||||
pdrecord.BetonVolume=row["BetonVolume"]
|
||||
pdrecord.MouldCode=row["MouldCode"]
|
||||
pdrecord.SkeletonID=row["SkeletonID"]
|
||||
@ -210,14 +225,115 @@ class PDRecordDal(BaseDal):
|
||||
print(f"获取top PD官片任务失败: {e}")
|
||||
return []
|
||||
|
||||
|
||||
|
||||
def get_last_pds(self, top: int,mould_code:str) -> List[PDRecordModel]:
|
||||
"""获取派单的记录进行派单"""
|
||||
try:
|
||||
# 确保top为正整数
|
||||
if not isinstance(top, int) or top <= 0:
|
||||
raise ValueError("top参数必须是正整数")
|
||||
_target_time = datetime.now() - timedelta(hours=4)
|
||||
# 查询指定数量的记录,按ID降序排列
|
||||
sql = f"""SELECT * FROM PDRecord WHERE CreateTime>? and ID>(
|
||||
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 = []
|
||||
for row in results:
|
||||
pdrecord = PDRecordModel(**row)
|
||||
pdrecords.append(pdrecord)
|
||||
return pdrecords
|
||||
except Exception as e:
|
||||
print(f"获取top PD官片任务失败: {e}")
|
||||
return []
|
||||
|
||||
def get_artifactid(self, module_code: str) -> Optional[str]:
|
||||
"""根据模具编号查找ID,根据ID确认是否扫码"""
|
||||
try:
|
||||
sql = "SELECT ArtifactID FROM PDRecord WHERE MouldCode = ? and CreateTime>?"
|
||||
_target_time = datetime.now() - timedelta(hours=4)
|
||||
results = self.db_dao.fetch_one(sql, (module_code,_target_time))
|
||||
if results is None:
|
||||
return None
|
||||
else:
|
||||
return results['ArtifactID']
|
||||
except Exception as e:
|
||||
print(f"根据ID获取构件任务失败: {e}")
|
||||
return None
|
||||
|
||||
def exists_by_module_code(self, module_code: str) -> bool:
|
||||
"""根据模具编号获取PD官片任务"""
|
||||
try:
|
||||
sql = "SELECT count(1) FROM PDRecord WHERE MouldCode = ? and OptTime>?"
|
||||
results = self.db_dao.execute_read(sql, (module_code,datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)))
|
||||
|
||||
rows = list(results)
|
||||
if rows[0][0] == 1:
|
||||
return True
|
||||
|
||||
return False
|
||||
except Exception as e:
|
||||
print(f"PDRecord(exists_by_module_code)失败: {e}")
|
||||
return False
|
||||
|
||||
def exists_artifactid(self, artifact_action_id: str) -> bool:
|
||||
"""根据构件动作编号获取PD官片任务"""
|
||||
try:
|
||||
sql = "SELECT count(1) FROM PDRecord WHERE ArtifactActionID = ?"
|
||||
results = self.db_dao.execute_read(sql, (artifact_action_id,))
|
||||
|
||||
rows = list(results)
|
||||
if rows[0][0] == 1:
|
||||
return True
|
||||
|
||||
return False
|
||||
except Exception as e:
|
||||
print(f"PDRecord(exists_by_module_code)失败: {e}")
|
||||
return False
|
||||
|
||||
def insert_PD_record(self, model: PDRecordModel) -> int:
|
||||
"""插入一条PD官片任务记录"""
|
||||
try:
|
||||
# 使用insert方法插入数据
|
||||
model.CreateTime=datetime.now()
|
||||
model.__dict__.pop("ID", None)
|
||||
row_id = self.db_dao.insert("PDRecord", model.__dict__)
|
||||
return row_id
|
||||
except Exception as e:
|
||||
print(f"插入PD官片任务失败: {e}")
|
||||
return 0
|
||||
|
||||
def update_pd(self, artifact_action_id: int, update_data: dict) -> bool:
|
||||
"""更新PD官片任务记录"""
|
||||
try:
|
||||
# 构建WHERE条件
|
||||
where_condition = f"ArtifactActionID='{artifact_action_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) -> int:
|
||||
"""更新构件派单记录"""
|
||||
try:
|
||||
# 构建WHERE条件
|
||||
_target_time = datetime.now() - timedelta(hours=4)
|
||||
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
|
||||
except Exception as e:
|
||||
print(f"更新PD官片任务失败: {e}")
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
artifact_dal = ArtifactDal()
|
||||
|
||||
artifacts = artifact_dal.get_artifact_task()
|
||||
artifacts = artifact_dal.get_top_artifact(5, "ID desc")
|
||||
|
||||
# 显示获取到的数据
|
||||
print(f"获取到 {len(artifacts)} 条构件任务数据:")
|
||||
|
||||
Reference in New Issue
Block a user