YueYunyun 1 сар өмнө
parent
commit
5a08817dab

+ 7 - 0
SourceCode/IntelligentRailwayCosting/app/config.yml

@@ -41,6 +41,13 @@ db:
     password: Iwb2017
     database: Iwb_RecoData2020
     trusted_connection: false
+  Iwb_RailwayCosting:
+    driver: '{ODBC Driver 17 for SQL Server}'
+    server: shvber.com,50535
+    username: sa
+    password: Iwb2017
+    database: iwb_railway_costing_v1
+    trusted_connection: false
   # MySQL 配置
   mysql_main:
     db: iwb_railway_costing_v1

+ 1 - 1
SourceCode/IntelligentRailwayCosting/app/services/project_quota.py

@@ -3,7 +3,7 @@ from typing import Optional
 import tools.utils as utils,threading
 from core.dtos import ProjectQuotaDto
 from core.models import ProjectQuotaModel
-from stores.project_quota import ProjectQuotaStore
+from stores import ProjectQuotaStore
 import executor
 
 class ProjectQuotaService:

+ 1 - 1
SourceCode/IntelligentRailwayCosting/app/services/project_task.py

@@ -5,7 +5,7 @@ from core.log.log_record import LogRecordHelper
 from core.enum import OperationModule,OperationType
 from core.dtos import ProjectTaskDto
 from core.models import ProjectTaskModel
-from stores.project_task import ProjectTaskStore
+from stores import ProjectTaskStore
 import executor
 
 class ProjectTaskService:

+ 1 - 3
SourceCode/IntelligentRailwayCosting/app/stores/__init__.py

@@ -1,6 +1,4 @@
-from .log import LogStore
-from .project_quota import ProjectQuotaStore
-from .project_task import ProjectTaskStore
+from stores.railway_costing_mysql import LogStore,ProjectQuotaStore,ProjectTaskStore
 
 from .user import UserStore
 from .project import ProjectStore

+ 3 - 0
SourceCode/IntelligentRailwayCosting/app/stores/railway_costing_mysql/__init__.py

@@ -0,0 +1,3 @@
+from .project_task import  ProjectTaskStore
+from .project_quota import ProjectQuotaStore
+from .log import LogStore

+ 0 - 0
SourceCode/IntelligentRailwayCosting/app/stores/log.py → SourceCode/IntelligentRailwayCosting/app/stores/railway_costing_mysql/log.py


+ 0 - 0
SourceCode/IntelligentRailwayCosting/app/stores/project_quota.py → SourceCode/IntelligentRailwayCosting/app/stores/railway_costing_mysql/project_quota.py


+ 292 - 0
SourceCode/IntelligentRailwayCosting/app/stores/railway_costing_mysql/project_task.py

@@ -0,0 +1,292 @@
+from sqlalchemy import and_
+from datetime import datetime
+from typing import Optional
+
+import tools.db_helper as db_helper
+from core.dtos import ProjectTaskDto
+from core.models import ProjectTaskModel
+from core.user_session import UserSession
+
+
+class ProjectTaskStore:
+    def __init__(self):
+        self._current_user = None
+        self._database=None
+
+    @property
+    def current_user(self):
+        if self._current_user is None:
+            self._current_user = UserSession.get_current_user()
+        return self._current_user
+
+    def get_tasks_paginated(
+        self,
+        project_id: str,
+        item_code: str,
+        page: int = 1,
+        page_size: int = 10,
+        keyword: Optional[str] = None,
+        collect_status: Optional[int] = None,
+        process_status: Optional[int] = None,
+        send_status: Optional[int] = None,
+    ) :
+        """分页查询任务列表
+
+        Args:
+            page: 页码,从1开始
+            page_size: 每页数量
+            project_id: 项目编号
+            item_code: 条目编号
+            keyword: 关键字
+            collect_status: 采集状态
+            process_status: 处理状态
+            send_status: 发送状态
+
+        Returns:
+
+        """
+        with db_helper.mysql_query_session(self._database) as db_session:
+            query = db_session.query(ProjectTaskModel)
+
+            # 构建查询条件
+            conditions = [
+                ProjectTaskModel.is_del == 0,
+                ProjectTaskModel.project_id == project_id,
+                # ProjectTaskModel.budget_id == budget_id,
+                ProjectTaskModel.item_code.like(f"{item_code}%")
+            ]
+            if keyword:
+                conditions.append(ProjectTaskModel.task_name.like(f'%{keyword}%'))
+            if collect_status is not None:
+                conditions.append(ProjectTaskModel.collect_status == collect_status)
+            if process_status is not None:
+                conditions.append(ProjectTaskModel.process_status == process_status)
+            if send_status is not None:
+                conditions.append(ProjectTaskModel.send_status == send_status)
+
+            query = query.filter(and_(*conditions))
+
+            # 计算总数
+            total_count = query.count()
+
+            # 分页
+            query = query.offset((page - 1) * page_size).limit(page_size)
+
+            tasks = query.all()
+
+            return {
+                'total': total_count,
+                'data': tasks
+            }
+
+    def get_tasks_paginated_bk(
+        self,
+        budget_id: int,
+        project_id: str,
+        item_code: str,
+        page: int = 1,
+        page_size: int = 10,
+        keyword: Optional[str] = None,
+        collect_status: Optional[int] = None,
+        process_status: Optional[int] = None,
+        send_status: Optional[int] = None,
+    ) :
+        """分页查询任务列表
+
+        Args:
+            page: 页码,从1开始
+            page_size: 每页数量
+            project_id: 项目编号
+            budget_id: 概算序号
+            item_code: 条目编号
+            keyword: 关键字
+            collect_status: 采集状态
+            process_status: 处理状态
+            send_status: 发送状态
+
+        Returns:
+
+        """
+        with db_helper.mysql_query_session(self._database) as db_session:
+            query = db_session.query(ProjectTaskModel)
+
+            # 构建查询条件
+            conditions = [
+                ProjectTaskModel.is_del == 0,
+                ProjectTaskModel.project_id == project_id,
+                ProjectTaskModel.budget_id == budget_id,
+                ProjectTaskModel.item_code.like(f"{item_code}%")
+            ]
+            if keyword:
+                conditions.append(ProjectTaskModel.task_name.like(f'%{keyword}%'))
+            if collect_status is not None:
+                conditions.append(ProjectTaskModel.collect_status == collect_status)
+            if process_status is not None:
+                conditions.append(ProjectTaskModel.process_status == process_status)
+            if send_status is not None:
+                conditions.append(ProjectTaskModel.send_status == send_status)
+
+            query = query.filter(and_(*conditions))
+
+            # 计算总数
+            total_count = query.count()
+
+            # 分页
+            query = query.offset((page - 1) * page_size).limit(page_size)
+
+            tasks = query.all()
+
+            return {
+                'total': total_count,
+                'data': tasks
+            }
+
+    def get_task(self, task_id: int) -> Optional[ProjectTaskModel]:
+        with db_helper.mysql_query_session(self._database) as db_session:
+            task = db_session.query(ProjectTaskModel).filter(
+                and_(
+                    ProjectTaskModel.id == task_id,
+                    ProjectTaskModel.is_del == 0
+                )).first()
+            return task
+
+
+    def get_task_dto(self, task_id: int) -> Optional[ProjectTaskDto]:
+        """根据ID查询任务
+
+        Args:
+            task_id: 任务ID
+
+        Returns:
+            Optional[ProjectTaskDto]
+        """
+        task_dto = self.get_task(task_id)
+        return ProjectTaskDto.from_model(task_dto) if task_dto else None
+
+    def create_task(self, task_dto: ProjectTaskDto) -> ProjectTaskDto:
+        """创建任务
+
+        Args:
+            task_dto: 任务DTO
+
+        Returns:
+            ProjectTaskDto
+        """
+        task = ProjectTaskModel(
+            task_name=task_dto.task_name,
+            task_desc=task_dto.task_desc,
+            project_id=task_dto.project_id,
+            budget_id=task_dto.budget_id,
+            item_id=task_dto.item_id,
+            item_code=task_dto.item_code,
+            file_path=task_dto.file_path,
+            created_by=self.current_user.username,
+            created_at=datetime.now(),
+        )
+
+        with db_helper.mysql_session(self._database) as db_session:
+            db_session.add(task)
+            db_session.flush()
+            return ProjectTaskDto.from_model(task)
+
+    def update_task(self, task_dto: ProjectTaskDto) -> Optional[ProjectTaskDto]:
+        """更新任务
+
+        Args:
+            task_dto: 任务DTO
+
+        Returns:
+            Optional[ProjectTaskDto]
+        """
+        task = self.get_task(task_dto.id)
+
+        if not task:
+            return None
+        with db_helper.mysql_session(self._database) as db_session:
+            task.task_name = task_dto.task_name
+            task.task_desc = task_dto.task_desc
+            # task.project_id = task_dto.project_id
+            # task.budget_id = task_dto.budget_id
+            # task.item_id = task_dto.item_id
+            # task.item_code = task_dto.item_code
+            # task.file_path = task_dto.file_path
+            task.updated_by=self.current_user.username
+            task.updated_at=datetime.now()
+            task = db_session.merge(task)
+            return ProjectTaskDto.from_model(task)
+
+
+    def update_task_files(self, task_id: int,files: str):
+        task = self.get_task(task_id)
+        if not task:
+            return None
+        with db_helper.mysql_session(self._database) as db_session:
+            task.file_path = files
+            if task.collect_status != 0:
+                task.collect_status = 4
+            if task.process_status != 0:
+                task.process_status = 4
+            if task.send_status != 0:
+                task.send_status = 4
+            task.updated_by=self.current_user.username
+            task.updated_at=datetime.now()
+            task = db_session.merge(task)
+            return ProjectTaskDto.from_model(task)
+
+    def delete_task(self, task_id: int) -> bool:
+        """删除任务
+
+        Args:
+            task_id: 任务ID
+        Returns:
+            bool
+        """
+        task = self.get_task(task_id)
+
+        if not task:
+            return False
+
+
+        with db_helper.mysql_session(self._database) as db_session:
+            task.is_del = 1
+            task.deleted_by = self.current_user.username
+            task.deleted_at = datetime.now()
+            task = db_session.merge(task)
+            return True
+
+    def update_collect_status(self,task_id:int, status:int, err:str = None):
+        task = self.get_task(task_id)
+        if not task:
+            return False
+        with db_helper.mysql_session(self._database) as db_session:
+            task.collect_status = status
+            if err:
+                task.collect_error = err
+            task.collect_time = datetime.now()
+            task = db_session.merge(task)
+            return True
+
+    def update_process_status(self,task_id:int, status:int, err:str = None):
+        task = self.get_task(task_id)
+        if not task:
+            return False
+        with db_helper.mysql_session(self._database) as db_session:
+            task.process_status = status
+            if err:
+                task.process_error = err
+            task.process_time = datetime.now()
+            task = db_session.merge(task)
+            return True
+
+    def update_send_status(self,task_id:int, status:int, err:str = None):
+        task = self.get_task(task_id)
+        if not task:
+            return False
+        with db_helper.mysql_session(self._database) as db_session:
+            task.send_status = status
+            if err:
+                task.send_error = err
+            task.send_time = datetime.now()
+            task = db_session.merge(task)
+            return True
+

+ 3 - 0
SourceCode/IntelligentRailwayCosting/app/stores/railway_costing_sqlserver/__init__.py

@@ -0,0 +1,3 @@
+from .project_task import  ProjectTaskStore
+from .project_quota import ProjectQuotaStore
+from .log import LogStore

+ 121 - 0
SourceCode/IntelligentRailwayCosting/app/stores/railway_costing_sqlserver/log.py

@@ -0,0 +1,121 @@
+from typing import List, Optional, Dict, Any
+from datetime import datetime
+from sqlalchemy import and_,  desc
+import tools.db_helper as db_helper
+
+from core.models import LogModel
+
+class LogStore:
+    def __init__(self):
+        # self._database= None
+        self._database= 'Iwb_RailwayCosting'
+
+    def query_logs_paginated(
+        self,
+        page: int = 1,
+        page_size: int = 10,
+        username: Optional[str] = None,
+        operation_type: Optional[str] = None,
+        operation_module: Optional[str] = None,
+        operation_result: Optional[int] = None,
+        start_time: Optional[datetime] = None,
+        end_time: Optional[datetime] = None
+    ) -> Dict[str, Any]:
+        """
+        分页查询日志记录
+        :param page: 页码
+        :param page_size: 每页记录数
+        :param username: 用户名(支持模糊查询)
+        :param operation_type: 操作类型
+        :param operation_module: 操作模块
+        :param operation_result: 操作结果
+        :param start_time: 开始时间
+        :param end_time: 结束时间
+        :return: 包含总记录数和日志列表的字典
+        """
+        # with db_helper.mysql_query_session(self._database) as db_session:
+        with db_helper.sqlserver_query_session(self._database) as db_session:
+            pass
+            query = db_session.query(LogModel)
+
+            # 构建查询条件
+            conditions = []
+            if username:
+                conditions.append(LogModel.username.like(f'%{username}%'))
+            if operation_type:
+                conditions.append(LogModel.operation_type == operation_type)
+            if operation_module:
+                conditions.append(LogModel.operation_module == operation_module)
+            if operation_result is not None:
+                conditions.append(LogModel.operation_result == operation_result)
+            if start_time:
+                conditions.append(LogModel.created_at >= start_time)
+            if end_time:
+                conditions.append(LogModel.created_at < end_time)
+
+            if conditions:
+                query = query.filter(and_(*conditions))
+
+            # 计算总记录数
+            total = query.count()
+
+            # 分页并按创建时间倒序排序
+            logs = query.order_by(desc(LogModel.created_at))\
+                .offset((page - 1) * page_size)\
+                .limit(page_size)\
+                .all()
+
+            return {
+                'total': total,
+                'data': logs
+            }
+    
+    def insert_log(
+        self,
+        username: str,
+        operation_type: str,
+        operation_desc: Optional[str] = None,
+        operation_result: Optional[int] = None,
+        operation_module: Optional[str] = None,
+        operation_data: Optional[str] = None,
+        data_changes: Optional[str] = None,
+        operation_ip: Optional[str] = None
+    ) -> LogModel:
+        """
+        插入单条日志记录
+        :param username: 用户名
+        :param operation_type: 操作类型
+        :param operation_desc: 操作描述
+        :param operation_result: 操作结果
+        :param operation_module: 操作模块
+        :param operation_data: 操作数据
+        :param data_changes: 数据变更记录
+        :param operation_ip: 操作IP
+        :return: 创建的日志记录
+        """
+        log = LogModel(
+            username=username,
+            operation_type=operation_type,
+            operation_desc=operation_desc,
+            operation_result=operation_result,
+            operation_module=operation_module,
+            operation_data=operation_data,
+            data_changes=data_changes,
+            operation_ip=operation_ip
+        )
+        # with db_helper.mysql_session(self._database) as db_session:
+        with db_helper.sqlserver_session(self._database) as db_session:
+            db_session.add(log)
+            return log
+    
+    def batch_insert_logs(self, logs: List[Dict[str, Any]]) -> List[LogModel]:
+        """
+        批量插入日志记录
+        :param logs: 日志记录列表
+        :return: 创建的日志记录列表
+        """
+        log_models = [LogModel(**log) for log in logs]
+        # with db_helper.mysql_session(self._database) as db_session:
+        with db_helper.sqlserver_session(self._database) as db_session:
+            db_session.add_all(log_models)
+            return log_models

+ 289 - 0
SourceCode/IntelligentRailwayCosting/app/stores/railway_costing_sqlserver/project_quota.py

@@ -0,0 +1,289 @@
+from sqlalchemy import and_, or_
+from datetime import datetime
+from typing import Optional
+
+import tools.db_helper as db_helper
+from core.dtos import ProjectQuotaDto
+from core.models import ProjectQuotaModel
+from core.user_session import UserSession
+
+class ProjectQuotaStore:
+    def __init__(self):
+        # self._database= None
+        self._database = 'Iwb_RailwayCosting'
+        self._current_user = None
+
+    @property
+    def current_user(self):
+        if self._current_user is None:
+            self._current_user = UserSession.get_current_user()
+        return self._current_user
+
+    def get_quotas_paginated(
+        self,
+        budget_id: int,
+        project_id: str,
+        item_code: str,
+        page: int = 1,
+        page_size: int = 10,
+        keyword: Optional[str] = None,
+        process_status: Optional[int] = None,
+        send_status: Optional[int] = None,
+    ):
+        """分页查询定额列表
+
+        Args:
+            page: 页码,从1开始
+            page_size: 每页数量
+            project_id: 项目编号
+            budget_id: 概算序号
+            item_code: 条目序号
+            keyword: 关键字
+            process_status: 处理状态
+            send_status: 发送状态
+
+        Returns:
+            Tuple[total_count, quotas]
+        """
+        # with db_helper.mysql_query_session(self._database) as db_session:
+        with db_helper.sqlserver_query_session(self._database) as db_session:
+            query = db_session.query(ProjectQuotaModel)
+
+            # 构建查询条件
+            conditions = [
+                ProjectQuotaModel.is_del == 0,
+                ProjectQuotaModel.project_id == project_id,
+                ProjectQuotaModel.budget_id == budget_id,
+                ProjectQuotaModel.item_code.like(f"{item_code}%")
+            ]
+
+            if process_status is not None:
+                conditions.append(ProjectQuotaModel.process_status == process_status)
+            if send_status is not None:
+                conditions.append(ProjectQuotaModel.send_status == send_status)
+            if keyword:
+                conditions.append(or_(
+                    ProjectQuotaModel.quota_code.like(f"%{keyword}%"),
+                    ProjectQuotaModel.project_name.like(f"%{keyword}%"),
+                ))
+            query = query.filter(and_(*conditions))
+
+            # 计算总数
+            total_count = query.count()
+
+            # 分页
+            query = query.offset((page - 1) * page_size).limit(page_size)
+
+            quotas = query.all()
+
+            return {
+                'total': total_count,
+                'data': quotas
+            }
+
+
+    def get_quotas_by_task_id(self,task_id:int, with_quota_code:bool=False):
+        # with db_helper.sqlserver_query_session(self._database) as db_session:
+        with db_helper.mysql_query_session(self._database) as db_session:
+            query = db_session.query(ProjectQuotaModel).filter(
+                and_(
+                    ProjectQuotaModel.task_id == task_id,
+                    ProjectQuotaModel.is_del == 0
+                )
+            )
+            if with_quota_code:
+                query = query.filter(and_(ProjectQuotaModel.quota_code!=None,ProjectQuotaModel.quota_code!='') )
+            quotas = query.all()
+            return quotas
+
+
+
+    def get_quota(self, quota_id: int) -> Optional[ProjectQuotaModel]:
+        """根据ID查询定额
+
+        Args:
+            quota_id: 定额ID
+
+        Returns:
+            Optional[ProjectQuotaDto]
+        """
+        # with db_helper.mysql_query_session(self._database) as db_session:
+        with db_helper.sqlserver_query_session(self._database) as db_session:
+            quota = db_session.query(ProjectQuotaModel).filter(
+                and_(
+                    ProjectQuotaModel.id == quota_id,
+                    ProjectQuotaModel.is_del == 0
+                )
+            ).first()
+            return quota
+    def get_quota_dto(self, quota_id: int) -> Optional[ProjectQuotaDto]:
+        """根据ID查询定额
+
+        Args:
+            quota_id: 定额ID
+
+        Returns:
+            Optional[ProjectQuotaDto]
+        """
+        quota = self.get_quota(quota_id)
+
+        return ProjectQuotaDto.from_model(quota) if quota else None
+
+    def create_quota(self, quota_dto: ProjectQuotaDto) -> ProjectQuotaDto:
+        """创建定额
+
+        Args:
+            quota_dto: 定额DTO
+
+        Returns:
+            ProjectQuotaDto
+        """
+        # with db_helper.mysql_session(self._database) as db_session:
+        with db_helper.sqlserver_session(self._database) as db_session:
+            quota = ProjectQuotaModel(
+                project_id=quota_dto.project_id,
+                budget_id=quota_dto.budget_id,
+                item_id=quota_dto.item_id,
+                item_code=quota_dto.item_code,
+                quota_code=quota_dto.quota_code,
+                project_name=quota_dto.project_name,
+                unit=quota_dto.unit,
+                project_quantity=quota_dto.project_quantity,
+                project_quantity_input=quota_dto.project_quantity_input,
+                quota_adjustment=quota_dto.quota_adjustment,
+                unit_price=quota_dto.unit_price,
+                total_price=quota_dto.total_price,
+                unit_weight=quota_dto.unit_weight,
+                total_weight=quota_dto.total_weight,
+                labor_cost=quota_dto.labor_cost,
+                process_status=quota_dto.process_status,
+                process_time=quota_dto.process_time,
+                process_error=quota_dto.process_error,
+                send_status=quota_dto.send_status,
+                send_time=quota_dto.send_time,
+                send_error=quota_dto.send_error,
+                created_by=quota_dto.created_by or self.current_user.username,
+                created_at=datetime.now(),
+            )
+
+            db_session.add(quota)
+            db_session.flush()
+            return ProjectQuotaDto.from_model(quota)
+
+    def update_quota(self, quota_dto: ProjectQuotaDto) -> Optional[ProjectQuotaDto]:
+        """更新定额
+
+        Args:
+            quota_dto: 定额DTO
+
+        Returns:
+            Optional[ProjectQuotaDto]
+        """
+        quota = self.get_quota(quota_dto.id)
+
+        if not quota:
+            return None
+        # with db_helper.mysql_session(self._database) as db_session:
+        with db_helper.sqlserver_session(self._database) as db_session:
+            quota.quota_code = quota_dto.quota_code
+            quota.project_name = quota_dto.project_name
+            quota.unit = quota_dto.unit
+            quota.project_quantity = quota_dto.project_quantity
+            quota.project_quantity_input = quota_dto.project_quantity_input
+            quota.quota_adjustment = quota_dto.quota_adjustment
+            quota.unit_price = quota_dto.unit_price
+            quota.total_price = quota_dto.total_price
+            quota.unit_weight = quota_dto.unit_weight
+            quota.total_weight = quota_dto.total_weight
+            quota.labor_cost = quota_dto.labor_cost
+            quota.updated_by = self.current_user.username
+            quota.updated_at = datetime.now()
+
+            quota = db_session.merge(quota)
+            return ProjectQuotaDto.from_model(quota)
+
+    def delete_quota(self, quota_id: int) -> bool:
+        """删除定额
+
+        Args:
+            quota_id: 定额ID
+
+        Returns:
+            bool
+        """
+
+        quota = self.get_quota(quota_id)
+        if not quota:
+            return False
+
+        # with db_helper.mysql_session(self._database) as db_session:
+        with db_helper.sqlserver_session(self._database) as db_session:
+            quota.is_del = 1
+            quota.deleted_by = self.current_user.username
+            quota.deleted_at = datetime.now()
+            quota = db_session.merge(quota)
+            return True
+
+    def update_process_status(self,quota_id:int, status:int, err:str = None):
+        """
+        更新项目定额的流程状态
+        Args:
+            quota_id: 定额ID
+            status: 流程状态
+            err:
+        Returns:
+            bool
+        """
+        quota = self.get_quota(quota_id)
+        if not quota:
+            return False
+        # with db_helper.mysql_session(self._database) as db_session:
+        with db_helper.sqlserver_session(self._database) as db_session:
+            quota.process_status = status
+            quota.process_error = err
+            quota.process_time = datetime.now()
+            quota = db_session.merge(quota)
+            return True
+
+    def update_send_status(self,quota_id:int, status:int, err:str = None) -> bool:
+        """
+        更新发送状态
+        Args:
+            quota_id: int
+            status: int
+            err: str
+        Returns:
+            bool
+        """
+        quota = self.get_quota(quota_id)
+        if not quota:
+            return False
+        # with db_helper.mysql_session(self._database) as db_session:
+        with db_helper.sqlserver_session(self._database) as db_session:
+            quota.send_status = status
+            quota.send_error = err
+            quota.send_time = datetime.now()
+            quota = db_session.merge(quota)
+            return True
+
+    def update_quota_code(self, quota_dto: ProjectQuotaDto):
+        """更新定额编号
+        Args:
+            quota_dto: 定额DTO
+        Returns:
+            bool
+        """
+        quota = self.get_quota(quota_dto.id)
+        if not quota:
+            return False
+        # with db_helper.mysql_session(self._database) as db_session:
+        with db_helper.sqlserver_session(self._database) as db_session:
+            quota.quota_code = quota_dto.quota_code
+            quota.unit = quota_dto.unit
+            quota.unit_price = quota_dto.unit_price
+            quota.total_price = quota_dto.total_price
+
+            quota.updated_by = self.current_user.username
+            quota.updated_at = datetime.now()
+            db_session.merge(quota)
+            return True

+ 20 - 10
SourceCode/IntelligentRailwayCosting/app/stores/project_task.py → SourceCode/IntelligentRailwayCosting/app/stores/railway_costing_sqlserver/project_task.py

@@ -10,8 +10,9 @@ from core.user_session import UserSession
 
 class ProjectTaskStore:
     def __init__(self):
+        # self._database= None
+        self._database = 'Iwb_RailwayCosting'
         self._current_user = None
-        self._database=None
 
     @property
     def current_user(self):
@@ -47,7 +48,8 @@ class ProjectTaskStore:
         Returns:
 
         """
-        with db_helper.mysql_query_session(self._database) as db_session:
+        # with db_helper.mysql_query_session(self._database) as db_session:
+        with db_helper.sqlserver_query_session(self._database) as db_session:
             query = db_session.query(ProjectTaskModel)
 
             # 构建查询条件
@@ -82,7 +84,8 @@ class ProjectTaskStore:
             }
 
     def get_task(self, task_id: int) -> Optional[ProjectTaskModel]:
-        with db_helper.mysql_query_session(self._database) as db_session:
+        # with db_helper.mysql_query_session(self._database) as db_session:
+        with db_helper.sqlserver_query_session(self._database) as db_session:
             task = db_session.query(ProjectTaskModel).filter(
                 and_(
                     ProjectTaskModel.id == task_id,
@@ -124,7 +127,8 @@ class ProjectTaskStore:
             created_at=datetime.now(),
         )
 
-        with db_helper.mysql_session(self._database) as db_session:
+        # with db_helper.mysql_session(self._database) as db_session:
+        with db_helper.sqlserver_query_session(self._database) as db_session:
             db_session.add(task)
             db_session.flush()
             return ProjectTaskDto.from_model(task)
@@ -142,7 +146,8 @@ class ProjectTaskStore:
 
         if not task:
             return None
-        with db_helper.mysql_session(self._database) as db_session:
+        # with db_helper.mysql_session(self._database) as db_session:
+        with db_helper.sqlserver_session(self._database) as db_session:
             task.task_name = task_dto.task_name
             task.task_desc = task_dto.task_desc
             # task.project_id = task_dto.project_id
@@ -160,7 +165,8 @@ class ProjectTaskStore:
         task = self.get_task(task_id)
         if not task:
             return None
-        with db_helper.mysql_session(self._database) as db_session:
+        # with db_helper.mysql_session(self._database) as db_session:
+        with db_helper.sqlserver_session(self._database) as db_session:
             task.file_path = files
             if task.collect_status != 0:
                 task.collect_status = 4
@@ -187,7 +193,8 @@ class ProjectTaskStore:
             return False
 
 
-        with db_helper.mysql_session(self._database) as db_session:
+        # with db_helper.mysql_session(self._database) as db_session:
+        with db_helper.sqlserver_session(self._database) as db_session:
             task.is_del = 1
             task.deleted_by = self.current_user.username
             task.deleted_at = datetime.now()
@@ -198,7 +205,8 @@ class ProjectTaskStore:
         task = self.get_task(task_id)
         if not task:
             return False
-        with db_helper.mysql_session(self._database) as db_session:
+        # with db_helper.mysql_session(self._database) as db_session:
+        with db_helper.sqlserver_session(self._database) as db_session:
             task.collect_status = status
             if err:
                 task.collect_error = err
@@ -210,7 +218,8 @@ class ProjectTaskStore:
         task = self.get_task(task_id)
         if not task:
             return False
-        with db_helper.mysql_session(self._database) as db_session:
+        # with db_helper.mysql_session(self._database) as db_session:
+        with db_helper.sqlserver_session(self._database) as db_session:
             task.process_status = status
             if err:
                 task.process_error = err
@@ -222,7 +231,8 @@ class ProjectTaskStore:
         task = self.get_task(task_id)
         if not task:
             return False
-        with db_helper.mysql_session(self._database) as db_session:
+        # with db_helper.mysql_session(self._database) as db_session:
+        with db_helper.sqlserver_session(self._database) as db_session:
             task.send_status = status
             if err:
                 task.send_error = err