|
@@ -1,10 +1,8 @@
|
|
|
from datetime import datetime
|
|
|
|
|
|
-from flask import session
|
|
|
from utils.mysql_helper import MySQLHelper
|
|
|
-
|
|
|
from models.project_data import ProjectModel, SubProjectModel, SubProjectItemModel
|
|
|
-
|
|
|
+from user_session.user_session import UserSession
|
|
|
|
|
|
class ProjectStore:
|
|
|
|
|
@@ -12,15 +10,16 @@ class ProjectStore:
|
|
|
self._db_helper = MySQLHelper()
|
|
|
|
|
|
@staticmethod
|
|
|
- def _get_current_user():
|
|
|
- return session.get('username', 'system')
|
|
|
+ def _get_current_user_name():
|
|
|
+ current_user = UserSession.get_current_user()
|
|
|
+ return current_user.username
|
|
|
|
|
|
def filter_data(self, sql:str, params:tuple):
|
|
|
- current_user = self._get_current_user()
|
|
|
- if current_user == 'system' or current_user == 'admin':
|
|
|
+ current_user_name = self._get_current_user_name()
|
|
|
+ if current_user_name == 'system' or current_user_name == 'admin':
|
|
|
return sql, params
|
|
|
sql += " AND create_by=%s"
|
|
|
- params += (current_user,)
|
|
|
+ params += (current_user_name,)
|
|
|
return sql, params
|
|
|
|
|
|
def query_project_all_paginated(self, page: int, per_page: int, keyword: str = None):
|
|
@@ -81,29 +80,29 @@ class ProjectStore:
|
|
|
)
|
|
|
|
|
|
def insert_project(self, project_data: ProjectModel):
|
|
|
- current_user = self._get_current_user()
|
|
|
+ current_user_name = self._get_current_user_name()
|
|
|
sql = "INSERT INTO project (project_name,description,create_by,created_at,update_by,updated_at) VALUES (%s,%s,%s,%s,%s,%s)"
|
|
|
- params = (project_data.project_name,project_data.description, current_user, datetime.now(), current_user, datetime.now())
|
|
|
+ params = (project_data.project_name,project_data.description, current_user_name, datetime.now(), current_user_name, datetime.now())
|
|
|
|
|
|
with self._db_helper:
|
|
|
self._db_helper.execute_non_query(sql, params)
|
|
|
|
|
|
def update_project(self, project_data: ProjectModel):
|
|
|
- current_user = self._get_current_user()
|
|
|
+ current_user_name = self._get_current_user_name()
|
|
|
sql = "UPDATE project SET project_name=%s,description=%s,update_by=%s,updated_at=%s WHERE id=%s"
|
|
|
- params = (project_data.project_name, project_data.description, current_user, datetime.now(), project_data.id)
|
|
|
+ params = (project_data.project_name, project_data.description, current_user_name, datetime.now(), project_data.id)
|
|
|
with self._db_helper:
|
|
|
self._db_helper.execute_non_query(sql, params)
|
|
|
|
|
|
def delete_project(self, project_id: int):
|
|
|
- current_user = self._get_current_user()
|
|
|
+ current_user_name = self._get_current_user_name()
|
|
|
sql = "UPDATE project SET is_del=1,project.delete_by=%s,deleted_at=%s WHERE id=%s"
|
|
|
- params = (current_user, datetime.now(), project_id)
|
|
|
+ params = (current_user_name, datetime.now(), project_id)
|
|
|
with self._db_helper:
|
|
|
self._db_helper.execute_non_query(sql, params)
|
|
|
|
|
|
def insert_sub_project(self, sub_project: SubProjectModel) -> int:
|
|
|
- current_user = self._get_current_user()
|
|
|
+ current_user_name = self._get_current_user_name()
|
|
|
sql = "INSERT INTO sub_project (project_id,sub_project_name,work_catalog,work_content,standard_version,file_paths,created_at,create_by) VALUES (%s,%s,%s,%s,%s,%s,%s,%s)"
|
|
|
params = (
|
|
|
sub_project.project_id,
|
|
@@ -113,7 +112,7 @@ class ProjectStore:
|
|
|
sub_project.standard_version,
|
|
|
sub_project.file_paths,
|
|
|
datetime.now(),
|
|
|
- current_user,
|
|
|
+ current_user_name,
|
|
|
)
|
|
|
with self._db_helper:
|
|
|
new_id = self._db_helper.execute_non_query(sql, params)
|
|
@@ -121,7 +120,7 @@ class ProjectStore:
|
|
|
return new_id
|
|
|
|
|
|
def update_sub_project(self, sub_project: SubProjectModel):
|
|
|
- current_user = sub_project.create_by or self._get_current_user()
|
|
|
+ current_user_name = sub_project.create_by or self._get_current_user_name()
|
|
|
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,
|
|
@@ -130,16 +129,16 @@ class ProjectStore:
|
|
|
sub_project.standard_version,
|
|
|
sub_project.status,
|
|
|
datetime.now(),
|
|
|
- current_user,
|
|
|
+ current_user_name,
|
|
|
sub_project.id,
|
|
|
)
|
|
|
with self._db_helper:
|
|
|
self._db_helper.execute_non_query(sql, params)
|
|
|
|
|
|
def delete_sub_project(self, sub_project_id: int) -> bool:
|
|
|
- current_user = self._get_current_user()
|
|
|
+ current_user_name = self._get_current_user_name()
|
|
|
sql = "UPDATE sub_project SET is_del=1,delete_by=%s,deleted_at=%s WHERE id = %s"
|
|
|
- params = (current_user, datetime.now(), sub_project_id,)
|
|
|
+ params = (current_user_name, datetime.now(), sub_project_id,)
|
|
|
with self._db_helper:
|
|
|
self._db_helper.execute_non_query(sql, params)
|
|
|
return True
|
|
@@ -391,7 +390,7 @@ class ProjectStore:
|
|
|
)
|
|
|
return data
|
|
|
def insert_sub_project_item(self, project_item: SubProjectItemModel):
|
|
|
- current_user = self._get_current_user()
|
|
|
+ current_user_name = self._get_current_user_name()
|
|
|
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,
|
|
@@ -404,13 +403,13 @@ class ProjectStore:
|
|
|
project_item.standard_no,
|
|
|
project_item.process_status,
|
|
|
project_item.send_status,
|
|
|
- current_user,
|
|
|
+ current_user_name,
|
|
|
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:
|
|
|
- current_user = self._get_current_user()
|
|
|
+ current_user_name = self._get_current_user_name()
|
|
|
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,
|
|
@@ -418,7 +417,7 @@ class ProjectStore:
|
|
|
project_item.device_unit,
|
|
|
project_item.device_count,
|
|
|
project_item.standard_no,
|
|
|
- current_user,
|
|
|
+ current_user_name,
|
|
|
datetime.now(),
|
|
|
project_item.id
|
|
|
)
|
|
@@ -426,9 +425,9 @@ class ProjectStore:
|
|
|
self._db_helper.execute_non_query(sql, params)
|
|
|
return True
|
|
|
def delete_sub_project_item_by_id(self, item_id: int):
|
|
|
- current_user = self._get_current_user()
|
|
|
+ current_user_name = self._get_current_user_name()
|
|
|
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 )
|
|
|
+ params = (current_user_name, datetime.now(),item_id )
|
|
|
with self._db_helper:
|
|
|
self._db_helper.execute_non_query(sql, params)
|
|
|
return True
|