|
@@ -34,10 +34,11 @@ class ProjectStore:
|
|
|
sql += " AND (project_name LIKE %s)"
|
|
|
params_count += (f"%{keyword}%",)
|
|
|
params += (f"%{keyword}%",)
|
|
|
+ sql_count, params_count = self.filter_data(sql_count, params_count)
|
|
|
+ sql, params = self.filter_data(sql, params)
|
|
|
sql += " ORDER BY created_at DESC LIMIT %s OFFSET %s"
|
|
|
params += (per_page, offset)
|
|
|
- sql_count, params_count = self.filter_data(sql_count, params_count)
|
|
|
- sql_count, params_count = self.filter_data(sql_count, params_count)
|
|
|
+
|
|
|
with self._db_helper:
|
|
|
result_count = self._db_helper.fetch_one(sql_count, params_count)
|
|
|
count = result_count["count"] if result_count else 0
|
|
@@ -120,7 +121,7 @@ class ProjectStore:
|
|
|
return new_id
|
|
|
|
|
|
def update_sub_project(self, sub_project: SubProjectModel):
|
|
|
- current_user = self._get_current_user()
|
|
|
+ current_user = sub_project.create_by or self._get_current_user()
|
|
|
sql = "UPDATE sub_project SET sub_project_name = %s, work_catalog = %s, work_content = %s, standard_version = %s ,status = %s,updated_at = %s,update_by = %s WHERE id = %s"
|
|
|
params = (
|
|
|
sub_project.sub_project_name,
|
|
@@ -210,7 +211,7 @@ class ProjectStore:
|
|
|
return data, count
|
|
|
|
|
|
def query_sub_project(self, sub_project_id: int, with_items=False) -> SubProjectModel | None:
|
|
|
- sql = "SELECT id,project_id,sub_project_name,work_catalog,work_content,standard_version,status,file_paths,created_at FROM sub_project WHERE is_del=0 AND id = %s"
|
|
|
+ sql = "SELECT id,project_id,sub_project_name,work_catalog,work_content,standard_version,status,file_paths,create_by,created_at FROM sub_project WHERE is_del=0 AND id = %s"
|
|
|
params = (sub_project_id,)
|
|
|
sql_items = "SELECT id,project_id,sub_project_id,device_name,device_model,standard_version,standard_no,process_status,process_time,send_status,send_time FROM sub_project_item WHERE sub_project_id = %s"
|
|
|
with self._db_helper:
|
|
@@ -226,6 +227,7 @@ class ProjectStore:
|
|
|
status=result["status"],
|
|
|
file_paths=result["file_paths"],
|
|
|
sub_id=result["id"],
|
|
|
+ create_by=result["create_by"],
|
|
|
created_at=result["created_at"])
|
|
|
if not with_items:
|
|
|
return data
|
|
@@ -249,8 +251,8 @@ class ProjectStore:
|
|
|
return data
|
|
|
def query_sub_project_items_by_project_paginated(self, sub_project_id: int, page: int, per_page: int, keyword: str = None, process_status: int = None,send_status: int = None) -> (list[SubProjectItemModel], int):
|
|
|
offset = (page - 1) * per_page
|
|
|
- sql_count = "SELECT COUNT(*) as count FROM sub_project_item WHERE sub_project_id = %s"
|
|
|
- sql = "SELECT id,project_id,sub_project_id,device_name,device_model,device_unit,device_count,standard_version,standard_no,process_status,process_time,send_status,send_time FROM sub_project_item WHERE sub_project_id = %s"
|
|
|
+ sql_count = "SELECT COUNT(*) as count FROM sub_project_item WHERE is_del=0 AND sub_project_id = %s"
|
|
|
+ sql = "SELECT id,project_id,sub_project_id,device_name,device_model,device_unit,device_count,standard_version,standard_no,process_status,process_time,send_status,send_time FROM sub_project_item WHERE is_del=0 AND sub_project_id = %s"
|
|
|
params_count = (sub_project_id,)
|
|
|
params = (sub_project_id,)
|
|
|
|
|
@@ -269,7 +271,8 @@ class ProjectStore:
|
|
|
params_count += (send_status,)
|
|
|
sql += " AND send_status=%s"
|
|
|
params += (send_status,)
|
|
|
-
|
|
|
+ sql_count, params_count = self.filter_data(sql_count, params_count)
|
|
|
+ sql, params = self.filter_data(sql, params)
|
|
|
sql += " ORDER BY device_name,device_model LIMIT %s OFFSET %s"
|
|
|
params += (per_page, offset)
|
|
|
|
|
@@ -325,7 +328,7 @@ class ProjectStore:
|
|
|
def insert_sub_project_item_list(self, sub_project):
|
|
|
if len(sub_project.items) <= 0:
|
|
|
return
|
|
|
- sql = "INSERT INTO sub_project_item (project_id,sub_project_id,device_name,device_model,device_unit,device_count,standard_version,standard_no,updated_at) VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s)"
|
|
|
+ sql = "INSERT INTO sub_project_item (project_id,sub_project_id,device_name,device_model,device_unit,device_count,standard_version,standard_no,create_by,created_at) VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)"
|
|
|
params_items = []
|
|
|
for item in sub_project.items:
|
|
|
params_items.append((
|
|
@@ -337,6 +340,7 @@ class ProjectStore:
|
|
|
item.device_count,
|
|
|
sub_project.standard_version,
|
|
|
item.standard_no,
|
|
|
+ sub_project.create_by,
|
|
|
datetime.now(),
|
|
|
))
|
|
|
with self._db_helper:
|
|
@@ -387,7 +391,8 @@ class ProjectStore:
|
|
|
)
|
|
|
return data
|
|
|
def insert_sub_project_item(self, project_item: SubProjectItemModel):
|
|
|
- sql = "INSERT INTO sub_project_item (project_id,sub_project_id,device_name,device_model,device_unit,device_count,standard_version,standard_no,process_status,send_status,updated_at) VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)"
|
|
|
+ current_user = self._get_current_user()
|
|
|
+ sql = "INSERT INTO sub_project_item (project_id,sub_project_id,device_name,device_model,device_unit,device_count,standard_version,standard_no,process_status,send_status,create_by,created_at) VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)"
|
|
|
params = (
|
|
|
project_item.project_id,
|
|
|
project_item.sub_project_id,
|
|
@@ -399,18 +404,21 @@ class ProjectStore:
|
|
|
project_item.standard_no,
|
|
|
project_item.process_status,
|
|
|
project_item.send_status,
|
|
|
+ current_user,
|
|
|
datetime.now(),
|
|
|
)
|
|
|
with self._db_helper:
|
|
|
return self._db_helper.execute_non_query(sql, params)
|
|
|
def update_sub_project_item(self, project_item: SubProjectItemModel) -> bool:
|
|
|
- sql = "UPDATE sub_project_item SET device_name= %s,device_model= %s,device_unit= %s,device_count= %s,standard_no = %s,updated_at = %s WHERE id = %s"
|
|
|
+ current_user = self._get_current_user()
|
|
|
+ sql = "UPDATE sub_project_item SET device_name= %s,device_model= %s,device_unit= %s,device_count= %s,standard_no = %s,update_by,updated_at = %s WHERE id = %s"
|
|
|
params = (
|
|
|
project_item.device_name,
|
|
|
project_item.device_model,
|
|
|
project_item.device_unit,
|
|
|
project_item.device_count,
|
|
|
project_item.standard_no,
|
|
|
+ current_user,
|
|
|
datetime.now(),
|
|
|
project_item.id
|
|
|
)
|
|
@@ -418,8 +426,9 @@ class ProjectStore:
|
|
|
self._db_helper.execute_non_query(sql, params)
|
|
|
return True
|
|
|
def delete_sub_project_item_by_id(self, item_id: int):
|
|
|
- sql = "DELETE FROM sub_project_item WHERE id = %s"
|
|
|
- params = (item_id, )
|
|
|
+ current_user = self._get_current_user()
|
|
|
+ sql = "Update sub_project_item SET is_del=1,delete_by=%s,deleted_at=%s WHERE id = %s"
|
|
|
+ params = (current_user, datetime.now(),item_id )
|
|
|
with self._db_helper:
|
|
|
self._db_helper.execute_non_query(sql, params)
|
|
|
return True
|