|
|
@@ -2,9 +2,9 @@ from datetime import datetime
|
|
|
|
|
|
from utils.mysql_helper import MySQLHelper
|
|
|
|
|
|
-from models.source_data import SourceData, SourceItemData
|
|
|
-from models.standard_data import StandardData
|
|
|
-from models.standard_update_log import StandardUpdateLog
|
|
|
+from models.project_data import ProjectModel, ProjectItemModel
|
|
|
+from models.standard_data import StandardModel
|
|
|
+from models.standard_update_log import StandardUpdateLogModel
|
|
|
|
|
|
|
|
|
class MysqlStore:
|
|
|
@@ -12,8 +12,8 @@ class MysqlStore:
|
|
|
def __init__(self):
|
|
|
self._db_helper = MySQLHelper()
|
|
|
|
|
|
- def query_source_data_all(self):
|
|
|
- query = "SELECT project_no,project_name,standard_version,status,create_time FROM source_data WHERE is_del=0"
|
|
|
+ def query_project_all(self):
|
|
|
+ query = "SELECT project_no,project_name,work_catalog,work_content,standard_version,status,create_time FROM project WHERE is_del=0"
|
|
|
with self._db_helper:
|
|
|
data = []
|
|
|
result = self._db_helper.execute_query(query)
|
|
|
@@ -21,19 +21,21 @@ class MysqlStore:
|
|
|
return data
|
|
|
for item in result:
|
|
|
data.append(
|
|
|
- SourceData(
|
|
|
+ ProjectModel(
|
|
|
+ project_id=item["id"],
|
|
|
project_no=item["project_no"],
|
|
|
project_name=item["project_name"],
|
|
|
+ work_catalog=item["work_catalog"],
|
|
|
+ work_content=item["work_content"],
|
|
|
standard_version=item["standard_version"],
|
|
|
status=item["status"],
|
|
|
create_time=item["create_time"],
|
|
|
))
|
|
|
return data
|
|
|
-
|
|
|
- def query_source_data_all_paginated(self, page: int, per_page: int, keyword: str = None, status: int = None) -> (list[SourceData], None):
|
|
|
+ def query_project_all_paginated(self, page: int, per_page: int, keyword: str = None, status: int = None) -> (list[ProjectModel], None):
|
|
|
offset = (page - 1) * per_page
|
|
|
- query_count = "SELECT COUNT(*) as count FROM source_data WHERE is_del=%s"
|
|
|
- query = "SELECT project_no,project_name,standard_version,status,create_time FROM source_data WHERE is_del=0 "
|
|
|
+ query_count = "SELECT COUNT(*) as count FROM project WHERE is_del=%s"
|
|
|
+ query = "SELECT id,project_no,project_name,work_catalog,work_content,standard_version,status,create_time FROM project WHERE is_del=0 "
|
|
|
params_count = [0]
|
|
|
params = []
|
|
|
q_1=" AND (project_no LIKE %s OR project_name LIKE %s)"
|
|
|
@@ -62,50 +64,54 @@ class MysqlStore:
|
|
|
return [], count
|
|
|
for item in result:
|
|
|
data.append(
|
|
|
- SourceData(
|
|
|
+ ProjectModel(
|
|
|
+ project_id=item["id"],
|
|
|
project_no=item["project_no"],
|
|
|
project_name=item["project_name"],
|
|
|
+ work_catalog=item["work_catalog"],
|
|
|
+ work_content=item["work_content"],
|
|
|
standard_version=item["standard_version"],
|
|
|
status=item["status"],
|
|
|
create_time=item["create_time"],
|
|
|
))
|
|
|
return data, count
|
|
|
-
|
|
|
- def query_source_data(self, project_no: str ,with_items=False) -> SourceData|None:
|
|
|
- query = "SELECT project_no,project_name,standard_version,status,create_time FROM source_data WHERE is_del=0 AND project_no = %s"
|
|
|
- params = (project_no, )
|
|
|
- query_items = "SELECT id,project_no,device_name,device_model,standard_version,standard_no FROM source_item_data WHERE project_no = %s"
|
|
|
+ def query_project(self, project_id: int, with_items=False) -> ProjectModel | None:
|
|
|
+ query = "SELECT id,project_no,project_name,work_catalog,work_content,standard_version,status,create_time FROM project WHERE is_del=0 AND id = %s"
|
|
|
+ params = (project_id,)
|
|
|
+ query_items = "SELECT id,project_id,device_name,device_model,standard_version,standard_no FROM project_item WHERE project_id = %s"
|
|
|
with self._db_helper:
|
|
|
result = self._db_helper.fetch_one(query, params)
|
|
|
if not result:
|
|
|
return None
|
|
|
- data = SourceData(result["project_no"],
|
|
|
- result["project_name"],
|
|
|
- result["standard_version"],
|
|
|
- result["status"],
|
|
|
- create_time=result["create_time"])
|
|
|
+ data = ProjectModel(result["project_no"],
|
|
|
+ result["project_name"],
|
|
|
+ result["work_catalog"],
|
|
|
+ result["work_content"],
|
|
|
+ result["standard_version"],
|
|
|
+ result["status"],
|
|
|
+ project_id=result["id"],
|
|
|
+ create_time=result["create_time"])
|
|
|
if not with_items:
|
|
|
return data
|
|
|
items_result = self._db_helper.execute_query(query_items, params)
|
|
|
if items_result:
|
|
|
for item in items_result:
|
|
|
data.add_item(
|
|
|
- SourceItemData(
|
|
|
+ ProjectItemModel(
|
|
|
item_id=item["id"],
|
|
|
- project_no=item["project_no"],
|
|
|
+ project_id=item["project_no"],
|
|
|
device_name=item["device_name"],
|
|
|
device_model=item["device_model"],
|
|
|
standard_version=item["standard_version"],
|
|
|
standard_no=item["standard_no"],
|
|
|
))
|
|
|
return data
|
|
|
-
|
|
|
- def query_source_item_data_list_by_project_paginated(self, project_no: str, page: int, per_page: int, keyword: str = None) -> (list[SourceItemData], int):
|
|
|
+ def query_project_items_by_project_paginated(self, project_id: int, page: int, per_page: int, keyword: str = None) -> (list[ProjectItemModel], int):
|
|
|
offset = (page - 1) * per_page
|
|
|
- query_count = "SELECT COUNT(*) as count FROM source_item_data WHERE project_no = %s"
|
|
|
- query = "SELECT id,project_no,device_name,device_model,device_unit,device_count,standard_version,standard_no FROM source_item_data WHERE project_no = %s"
|
|
|
- params_count = (project_no,)
|
|
|
- params = (project_no,)
|
|
|
+ query_count = "SELECT COUNT(*) as count FROM project_item WHERE project_id = %s"
|
|
|
+ query = "SELECT id,project_id,device_name,device_model,device_unit,device_count,standard_version,standard_no FROM project_item WHERE project_id = %s"
|
|
|
+ params_count = (project_id,)
|
|
|
+ params = (project_id,)
|
|
|
|
|
|
if keyword:
|
|
|
query_count += " AND (device_name LIKE %s OR device_model LIKE %s)"
|
|
|
@@ -125,9 +131,9 @@ class MysqlStore:
|
|
|
return data, count
|
|
|
for item in result:
|
|
|
data.append(
|
|
|
- SourceItemData(
|
|
|
+ ProjectItemModel(
|
|
|
item_id=item["id"],
|
|
|
- project_no=item["project_no"],
|
|
|
+ project_id=item["project_id"],
|
|
|
device_name=item["device_name"],
|
|
|
device_model=item["device_model"],
|
|
|
device_unit=item["device_unit"],
|
|
|
@@ -136,11 +142,10 @@ class MysqlStore:
|
|
|
standard_no=item["standard_no"],
|
|
|
))
|
|
|
return data, count
|
|
|
-
|
|
|
- def query_source_item_data_list_by_project(self, project_no: str, with_empty=True) -> list[SourceItemData]:
|
|
|
- query = "SELECT id,project_no,device_name,device_model,device_unit,device_count,standard_version,standard_no FROM source_item_data WHERE project_no = %s"
|
|
|
+ def query_project_items_by_project(self, project_id: int, with_empty=True) -> list[ProjectItemModel]:
|
|
|
+ query = "SELECT id,project_id,device_name,device_model,device_unit,device_count,standard_version,standard_no FROM project_item WHERE project_id = %s"
|
|
|
query += "" if with_empty else " AND standard_no !='' AND standard_no IS NOT NULL"
|
|
|
- params = (project_no,)
|
|
|
+ params = (project_id,)
|
|
|
with self._db_helper:
|
|
|
result = self._db_helper.execute_query(query, params)
|
|
|
data = []
|
|
|
@@ -148,9 +153,9 @@ class MysqlStore:
|
|
|
return data
|
|
|
for item in result:
|
|
|
data.append(
|
|
|
- SourceItemData(
|
|
|
+ ProjectItemModel(
|
|
|
item_id=item["id"],
|
|
|
- project_no=item["project_no"],
|
|
|
+ project_id=item["project_id"],
|
|
|
device_name=item["device_name"],
|
|
|
device_model=item["device_model"],
|
|
|
device_unit=item["device_unit"],
|
|
|
@@ -159,83 +164,87 @@ class MysqlStore:
|
|
|
standard_no=item["standard_no"],
|
|
|
))
|
|
|
return data
|
|
|
-
|
|
|
- def insert_source_data(self, source_data: SourceData) -> bool:
|
|
|
- query = "INSERT INTO source_data (project_no,project_name,standard_version,completion_tokens,prompt_tokens,total_tokens,create_time) VALUES (%s,%s,%s,%s,%s,%s,%s)"
|
|
|
+ def insert_project(self, project: ProjectModel) -> bool:
|
|
|
+ query = "INSERT INTO project (project_no,project_name,work_catalog,work_content,standard_version,completion_tokens,prompt_tokens,total_tokens,create_time) VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s)"
|
|
|
params = (
|
|
|
- source_data.project_no,
|
|
|
- source_data.project_name,
|
|
|
- source_data.standard_version,
|
|
|
- source_data.completion_tokens,
|
|
|
- source_data.prompt_tokens,
|
|
|
- source_data.total_tokens,
|
|
|
+ project.project_no,
|
|
|
+ project.project_name,
|
|
|
+ project.work_catalog,
|
|
|
+ project.work_content,
|
|
|
+ project.standard_version,
|
|
|
+ project.completion_tokens,
|
|
|
+ project.prompt_tokens,
|
|
|
+ project.total_tokens,
|
|
|
datetime.now(),
|
|
|
)
|
|
|
|
|
|
with self._db_helper:
|
|
|
self._db_helper.execute_non_query(query, params)
|
|
|
- self.insert_source_data_item_list(source_data)
|
|
|
+ self.insert_project_item_list(project)
|
|
|
return True
|
|
|
-
|
|
|
- def insert_source_data_item_list(self,source_data):
|
|
|
- if len(source_data.items) <= 0:
|
|
|
+ def insert_project_item_list(self, project):
|
|
|
+ if len(project.items) <= 0:
|
|
|
return
|
|
|
- query_items = "INSERT INTO source_item_data (project_no,device_name,device_model,device_unit,device_count,standard_version,standard_no,update_time) VALUES (%s,%s,%s,%s,%s,%s,%s,%s)"
|
|
|
+ query_items = "INSERT INTO project_item (project_id,device_name,device_model,device_unit,device_count,standard_version,standard_no,update_time) VALUES (%s,%s,%s,%s,%s,%s,%s,%s)"
|
|
|
params_items = []
|
|
|
- for item in source_data.items:
|
|
|
+ for item in project.items:
|
|
|
params_items.append((
|
|
|
- source_data.project_no,
|
|
|
+ project.id,
|
|
|
item.device_name,
|
|
|
item.device_model,
|
|
|
item.device_unit,
|
|
|
item.device_count,
|
|
|
- source_data.standard_version,
|
|
|
+ project.standard_version,
|
|
|
item.standard_no,
|
|
|
datetime.now(),
|
|
|
))
|
|
|
with self._db_helper:
|
|
|
self._db_helper.execute_many(query_items, params_items)
|
|
|
-
|
|
|
- def update_source_data(self, source_data: SourceData):
|
|
|
- query = "UPDATE source_data SET project_name = %s, standard_version = %s ,status = %s,update_time = %s WHERE project_no = %s"
|
|
|
+ def update_project(self, project: ProjectModel):
|
|
|
+ query = "UPDATE project SET project_name = %s, work_catalog = %s, work_content = %s, standard_version = %s ,status = %s,update_time = %s WHERE id = %s"
|
|
|
params = (
|
|
|
- source_data.project_name,
|
|
|
- source_data.standard_version,
|
|
|
- source_data.status,
|
|
|
+ project.project_name,
|
|
|
+ project.work_catalog,
|
|
|
+ project.work_content,
|
|
|
+ project.standard_version,
|
|
|
+ project.status,
|
|
|
datetime.now(),
|
|
|
- source_data.project_no,
|
|
|
+ project.id,
|
|
|
)
|
|
|
with self._db_helper:
|
|
|
self._db_helper.execute_non_query(query, params)
|
|
|
-
|
|
|
- def re_insert_source_data(self, source_data: SourceData) -> bool:
|
|
|
- if not source_data.project_no:
|
|
|
+ def update_project_status(self,project_id:int, status:int):
|
|
|
+ query = "UPDATE project SET status = %s,update_time = %s WHERE id = %s"
|
|
|
+ params = (status, datetime.now(), project_id,)
|
|
|
+ with self._db_helper:
|
|
|
+ self._db_helper.execute_non_query(query, params)
|
|
|
+ def re_insert_project(self, project: ProjectModel) -> bool:
|
|
|
+ if not project.id:
|
|
|
return False
|
|
|
- self.update_source_data(source_data)
|
|
|
- query = "DELETE FROM source_item_data WHERE project_no = %s"
|
|
|
- params = (source_data.project_no,)
|
|
|
+ self.update_project(project)
|
|
|
+ query = "DELETE FROM project_item WHERE project_id = %s"
|
|
|
+ params = (project.id,)
|
|
|
with self._db_helper:
|
|
|
self._db_helper.execute_non_query(query, params)
|
|
|
- self.insert_source_data_item_list(source_data)
|
|
|
-
|
|
|
- def delete_source_data(self, project_no: str) -> bool:
|
|
|
- query_1 = "UPDATE source_data SET is_del=1,delete_time=%s WHERE project_no = %s"
|
|
|
- # query_2 = "DELETE FROM source_item_data WHERE project_no = %s"
|
|
|
- params = (datetime.now(),project_no, )
|
|
|
+ self.insert_project_item_list(project)
|
|
|
+ def delete_project(self, project_id: int) -> bool:
|
|
|
+ query_1 = "UPDATE project SET is_del=1,delete_time=%s WHERE id = %s"
|
|
|
+ # query_2 = "DELETE FROM project_item WHERE project_no = %s"
|
|
|
+ params = (datetime.now(), project_id,)
|
|
|
with self._db_helper:
|
|
|
self._db_helper.execute_non_query(query_1, params)
|
|
|
# self._db_helper.execute_non_query(query_2, params)
|
|
|
return True
|
|
|
- def query_source_item_data_by_id(self, item_id:int) -> SourceItemData | None:
|
|
|
- query = "SELECT id,project_no,device_name,device_model,device_unit,device_count,standard_version,standard_no FROM source_item_data WHERE id = %s"
|
|
|
+ def query_project_item_by_id(self, item_id:int) -> ProjectItemModel | None:
|
|
|
+ query = "SELECT id,project_id,device_name,device_model,device_unit,device_count,standard_version,standard_no FROM project_item WHERE id = %s"
|
|
|
params = (item_id,)
|
|
|
with self._db_helper:
|
|
|
result = self._db_helper.fetch_one(query, params)
|
|
|
if not result:
|
|
|
return None
|
|
|
- data = SourceItemData(
|
|
|
+ data = ProjectItemModel(
|
|
|
item_id=result["id"],
|
|
|
- project_no=result["project_no"],
|
|
|
+ project_id=result["project_id"],
|
|
|
device_name=result["device_name"],
|
|
|
device_model=result["device_model"],
|
|
|
device_unit=result["device_unit"],
|
|
|
@@ -245,16 +254,16 @@ class MysqlStore:
|
|
|
update_time=datetime.now()
|
|
|
)
|
|
|
return data
|
|
|
- def query_source_item_data(self, project_no: str,device_name:str, device_model:str) -> SourceItemData| None:
|
|
|
- query = "SELECT id,project_no,device_name,device_model,device_unit,device_count,standard_version,standard_no FROM source_item_data WHERE project_no = %s AND device_name = %s AND device_model = %s"
|
|
|
- params = (project_no,device_name, device_model )
|
|
|
+ def query_project_item(self, project_id: int, device_name:str, device_model:str) -> ProjectItemModel | None:
|
|
|
+ query = "SELECT id,project_id,device_name,device_model,device_unit,device_count,standard_version,standard_no FROM project_item WHERE project_id = %s AND device_name = %s AND device_model = %s"
|
|
|
+ params = (project_id,device_name, device_model )
|
|
|
with self._db_helper:
|
|
|
result = self._db_helper.fetch_one(query, params)
|
|
|
if not result:
|
|
|
return None
|
|
|
- data = SourceItemData(
|
|
|
+ data = ProjectItemModel(
|
|
|
item_id=result["id"],
|
|
|
- project_no=result["project_no"],
|
|
|
+ project_id=result["project_id"],
|
|
|
device_name=result["device_name"],
|
|
|
device_model=result["device_model"],
|
|
|
device_unit=result["device_unit"],
|
|
|
@@ -263,58 +272,70 @@ class MysqlStore:
|
|
|
standard_no=result["standard_no"],
|
|
|
)
|
|
|
return data
|
|
|
- def insert_source_item_data(self, source_item_data: SourceItemData) -> bool:
|
|
|
- query = "INSERT INTO source_item_data (project_no,device_name,device_model,device_unit,device_count,standard_version,standard_no,update_time) VALUES (%s,%s,%s,%s,%s,%s,%s,%s)"
|
|
|
+ def insert_project_item(self, project_item: ProjectItemModel) -> bool:
|
|
|
+ query = "INSERT INTO project_item (project_id,device_name,device_model,device_unit,device_count,standard_version,standard_no,update_time) VALUES (%s,%s,%s,%s,%s,%s,%s,%s)"
|
|
|
params = (
|
|
|
- source_item_data.project_no,
|
|
|
- source_item_data.device_name,
|
|
|
- source_item_data.device_model,
|
|
|
- source_item_data.device_unit,
|
|
|
- source_item_data.device_count,
|
|
|
- source_item_data.standard_version,
|
|
|
- source_item_data.standard_no,
|
|
|
+ project_item.project_id,
|
|
|
+ project_item.device_name,
|
|
|
+ project_item.device_model,
|
|
|
+ project_item.device_unit,
|
|
|
+ project_item.device_count,
|
|
|
+ project_item.standard_version,
|
|
|
+ project_item.standard_no,
|
|
|
datetime.now(),
|
|
|
)
|
|
|
with self._db_helper:
|
|
|
self._db_helper.execute_non_query(query, params)
|
|
|
return True
|
|
|
- def update_source_item_data(self, source_item_data: SourceItemData) -> bool:
|
|
|
- query = "SElECT standard_no FROM source_item_data WHERE id = %s"
|
|
|
- params = (source_item_data.id,)
|
|
|
- u_query = "UPDATE source_item_data SET device_unit= %s,device_count= %s,standard_no = %s,update_time = %s WHERE id = %s"
|
|
|
- u_params = (source_item_data.device_unit, source_item_data.device_count, source_item_data.standard_no, datetime.now(), source_item_data.id)
|
|
|
+ def update_project_data(self, project_item: ProjectItemModel) -> bool:
|
|
|
+ query = "SElECT standard_no FROM project_item WHERE id = %s"
|
|
|
+ params = (project_item.id,)
|
|
|
+ u_query = "UPDATE project_item SET device_name= %s,device_model= %s,device_unit= %s,device_count= %s,standard_no = %s,update_time = %s WHERE id = %s"
|
|
|
+ u_params = (project_item.device_name, project_item.device_model,project_item.device_unit, project_item.device_count, project_item.standard_no, datetime.now(), project_item.id)
|
|
|
with self._db_helper:
|
|
|
result = self._db_helper.fetch_one(query, params)
|
|
|
if result:
|
|
|
-
|
|
|
self._db_helper.execute_non_query(u_query, u_params)
|
|
|
self.insert_or_update_standard_data(
|
|
|
- StandardData(device_name=source_item_data.device_name,
|
|
|
- device_model=source_item_data.device_model,
|
|
|
- device_unit=source_item_data.device_unit,
|
|
|
- standard_version=source_item_data.standard_version,
|
|
|
- standard_no=source_item_data.standard_no),
|
|
|
- source_item_data.project_no)
|
|
|
+ StandardModel(device_name=project_item.device_name,
|
|
|
+ device_model=project_item.device_model,
|
|
|
+ device_unit=project_item.device_unit,
|
|
|
+ standard_version=project_item.standard_version,
|
|
|
+ standard_no=project_item.standard_no),
|
|
|
+ project_item.project_id)
|
|
|
return True
|
|
|
- def delete_source_item_data_by_id(self, item_id: int):
|
|
|
- query = "DELETE FROM source_item_data WHERE id = %s"
|
|
|
+ def delete_project_item_by_id(self, item_id: int):
|
|
|
+ query = "DELETE FROM project_item WHERE id = %s"
|
|
|
params = (item_id, )
|
|
|
with self._db_helper:
|
|
|
self._db_helper.execute_non_query(query, params)
|
|
|
return True
|
|
|
- def delete_source_item_data(self,
|
|
|
- project_no: str,
|
|
|
- device_name: str,
|
|
|
- device_model: str) -> bool:
|
|
|
- query = "DELETE FROM source_item_data WHERE project_no = %s AND device_name = %s AND device_model = %s"
|
|
|
- params = (project_no, device_name, device_model)
|
|
|
- with self._db_helper:
|
|
|
- self._db_helper.execute_non_query(query, params)
|
|
|
- return True
|
|
|
|
|
|
+ def update_project_item_standard_no_batch(self,items:list[ProjectItemModel]):
|
|
|
+ data =datetime.now()
|
|
|
+ for item in items:
|
|
|
+ query = "UPDATE project_item SET standard_no = %s,update_time = %s WHERE id = %s"
|
|
|
+ params = (item.standard_no, data, item.id)
|
|
|
+ with self._db_helper:
|
|
|
+ self._db_helper.execute_non_query(query, params)
|
|
|
|
|
|
+ def query_standard_data_by_no(self, standard_no: str,version:str):
|
|
|
+ query = "SELECT device_model,device_name,device_unit,standard_version,standard_no FROM standard_data WHERE standard_no = %s AND standard_version = %s"
|
|
|
+ params = (standard_no,version,)
|
|
|
+ with self._db_helper:
|
|
|
+ result = self._db_helper.fetch_one(query, params)
|
|
|
+ if not result:
|
|
|
+ return None
|
|
|
+ data = StandardModel(
|
|
|
+ device_model=result["device_model"],
|
|
|
+ device_name=result["device_name"],
|
|
|
+ device_unit=result["device_unit"],
|
|
|
+ standard_version=result["standard_version"],
|
|
|
+ standard_no=result["standard_no"],
|
|
|
+ )
|
|
|
+ return data
|
|
|
def query_standard_data(self, device_name: str,
|
|
|
- device_model: str) -> list[StandardData]|None:
|
|
|
+ device_model: str) -> list[StandardModel] | None:
|
|
|
query = "SELECT device_model,device_name,device_unit,standard_version,standard_no FROM standard_data WHERE device_name = %s AND device_model = %s "
|
|
|
params = (device_name, device_model)
|
|
|
with self._db_helper:
|
|
|
@@ -323,7 +344,7 @@ class MysqlStore:
|
|
|
return None
|
|
|
data = []
|
|
|
for result in results:
|
|
|
- data.append(StandardData(
|
|
|
+ data.append(StandardModel(
|
|
|
device_model=result["device_model"],
|
|
|
device_name=result["device_name"],
|
|
|
device_unit=result["device_unit"],
|
|
|
@@ -332,9 +353,36 @@ class MysqlStore:
|
|
|
))
|
|
|
return data
|
|
|
|
|
|
+ def insert_standard_data(self, standard_data: StandardModel) -> bool:
|
|
|
+ query = "INSERT INTO standard_data (device_name,device_model,device_unit,standard_version,standard_no,create_time) VALUES (%s,%s,%s,%s,%s,%s)"
|
|
|
+ params = (
|
|
|
+ standard_data.device_name,
|
|
|
+ standard_data.device_model,
|
|
|
+ standard_data.device_unit,
|
|
|
+ standard_data.standard_version,
|
|
|
+ standard_data.standard_no,
|
|
|
+ datetime.now(),
|
|
|
+ )
|
|
|
+ with self._db_helper:
|
|
|
+ self._db_helper.execute_non_query(query, params)
|
|
|
+ return True
|
|
|
+
|
|
|
+ def update_standard_data(self, standard_data: StandardModel) -> bool:
|
|
|
+ query = "UPDATE standard_data SET device_name = %s, device_model = %s, device_unit= %s WHERE standard_no = %s AND standard_version = %s"
|
|
|
+ params = (
|
|
|
+ standard_data.device_name,
|
|
|
+ standard_data.device_model,
|
|
|
+ standard_data.device_unit,
|
|
|
+ standard_data.standard_no,
|
|
|
+ standard_data.standard_version,
|
|
|
+ )
|
|
|
+ with self._db_helper:
|
|
|
+ self._db_helper.execute_non_query(query, params)
|
|
|
+ return True
|
|
|
+
|
|
|
def insert_or_update_standard_data(self,
|
|
|
- standard_data: StandardData,
|
|
|
- project_no: str = None) -> bool:
|
|
|
+ standard_data: StandardModel,
|
|
|
+ project_id: int = None) -> bool:
|
|
|
query = "SELECT device_model,device_name,device_unit,standard_version,standard_no FROM standard_data WHERE device_name = %s AND device_model = %s AND standard_version = %s"
|
|
|
params = (standard_data.device_name, standard_data.device_model,standard_data.standard_version)
|
|
|
i_query = "INSERT INTO standard_data (device_name,device_model,device_unit,standard_version,standard_no,create_time) VALUES (%s,%s,%s,%s,%s,%s)"
|
|
|
@@ -359,10 +407,10 @@ class MysqlStore:
|
|
|
data = self._db_helper.fetch_one(query, params)
|
|
|
if data:
|
|
|
self._db_helper.execute_non_query(u_query, u_params)
|
|
|
- if project_no:
|
|
|
+ if project_id:
|
|
|
self.insert_standard_update_log(
|
|
|
- StandardUpdateLog(
|
|
|
- project_no=project_no,
|
|
|
+ StandardUpdateLogModel(
|
|
|
+ project_id=project_id,
|
|
|
device_name=standard_data.device_name,
|
|
|
device_model=standard_data.device_model,
|
|
|
device_unit= standard_data.device_unit,
|
|
|
@@ -373,21 +421,21 @@ class MysqlStore:
|
|
|
self._db_helper.execute_non_query(i_query, i_params)
|
|
|
return True
|
|
|
|
|
|
- def query_standard_update_log(self, project_no: str) -> list[StandardUpdateLog]|None:
|
|
|
- query = "SELECT project_no,device_name,device_model,device_unit,standard_version,new_standard_no,old_standard_no,create_time FROM standard_update_log WHERE project_no = %s"
|
|
|
- params = (project_no, )
|
|
|
+ def query_standard_update_log(self, project_id: int) -> list[StandardUpdateLogModel] | None:
|
|
|
+ query = "SELECT project_id,device_name,device_model,device_unit,standard_version,new_standard_no,old_standard_no,create_time FROM standard_update_log WHERE project_id = %s"
|
|
|
+ params = (project_id, )
|
|
|
with self._db_helper:
|
|
|
results = self._db_helper.execute_query(query, params)
|
|
|
if not results:
|
|
|
return None
|
|
|
- data = [StandardUpdateLog(**result) for result in results]
|
|
|
+ data = [StandardUpdateLogModel(**result) for result in results]
|
|
|
return data
|
|
|
|
|
|
def insert_standard_update_log(
|
|
|
- self, standard_update_log: StandardUpdateLog) -> bool:
|
|
|
- query = "INSERT INTO standard_update_log (project_no,device_name,device_model,device_unit,standard_version,new_standard_no,old_standard_no,create_time) VALUES (%s,%s,%s,%s,%s,%s,%s,%s)"
|
|
|
+ self, standard_update_log: StandardUpdateLogModel) -> bool:
|
|
|
+ query = "INSERT INTO standard_update_log (project_id,device_name,device_model,device_unit,standard_version,new_standard_no,old_standard_no,create_time) VALUES (%s,%s,%s,%s,%s,%s,%s,%s)"
|
|
|
params = (
|
|
|
- standard_update_log.project_no,
|
|
|
+ standard_update_log.project_id,
|
|
|
standard_update_log.device_name,
|
|
|
standard_update_log.device_model,
|
|
|
standard_update_log.device_unit,
|