Przeglądaj źródła

fix 修复部分问题

yue 2 tygodni temu
rodzic
commit
bac9c26ea8

+ 35 - 35
SourceCode/IntelligentRailwayCosting/app/core/dtos/excel_parse.py

@@ -3,16 +3,16 @@ import base64
 
 
 class ExcelParseZgsDto:
-    def __init__(self, zgs_id: int, zgs_name: str):
+    def __init__(self, zgs_id: int, zgs_code: str):
         self.zgs_id = zgs_id
-        self.zgs_name = zgs_name
+        self.zgs_code = zgs_code
 
     @classmethod
     def from_dto(cls, dto: TotalBudgetInfoDto):
-        return cls(zgs_id=dto.budget_id, zgs_name=dto.budget_code)
+        return cls(zgs_id=dto.budget_id, zgs_code=dto.budget_code)
 
     def to_dict(self):
-        return {"zgs_id": self.zgs_id, "zgs_name": self.zgs_name}
+        return {"zgs_id": self.zgs_id, "zgs_code": self.zgs_code}
 
 
 class ExcelParseItemDto:
@@ -52,17 +52,17 @@ class ExcelParseFileDto:
 
 class ExcelParseDto:
     def __init__(
-        self,
-        task_id: int,
-        version: str,
-        project_id: str,
-        project_name: str,
-        project_stage: str,
-        selected_zgs_id: int,
-        zgs_list: list[ExcelParseZgsDto],
-        hierarchy: list[ExcelParseItemDto],
-        components: list[ExcelParseItemDto],
-        files: list[ExcelParseFileDto],
+            self,
+            task_id: int,
+            version: str,
+            project_id: str,
+            project_name: str,
+            project_stage: str,
+            selected_zgs_id: int,
+            zgs_list: list[ExcelParseZgsDto],
+            hierarchy: list[ExcelParseItemDto],
+            components: list[ExcelParseItemDto],
+            files: list[ExcelParseFileDto],
     ):
         self.task_id = task_id
         self.version = version
@@ -108,21 +108,21 @@ class ExcelParseResultDataDto:
     #     "ex_amount": excel中给出的数量, // number
     # }
     def __init__(
-        self,
-        zgs_id: int,  # 总概算id
-        zgs_code: str,  # 总概算编号
-        item_id: int,  # 条⽬序号
-        item_code: str,  # 条⽬编码
-        entry_name: str,  # ⼯程或费⽤项⽬名称,来⾃于定额表,
-        dinge_code: str,  # 定额编号,
-        units: str,  # 单位,
-        amount: float,  # 数量,
-        target_id: int,  # ⽤户数据库中条⽬的id,-1表示没有,
-        ex_file_id: str,  # excel⽂件id,
-        ex_cell: str,  # 数量单元格位置,例如 "C17",
-        ex_row: str,  # 该⾏内容,由逗号连接多个单元格得到,
-        ex_unit: str,  # excel中给出的单位,
-        ex_amount: float,  # excel中给出的数量,
+            self,
+            zgs_id: int,  # 总概算id
+            zgs_code: str,  # 总概算编号
+            item_id: int,  # 条⽬序号
+            item_code: str,  # 条⽬编码
+            entry_name: str,  # ⼯程或费⽤项⽬名称,来⾃于定额表,
+            dinge_code: str,  # 定额编号,
+            units: str,  # 单位,
+            amount: float,  # 数量,
+            target_id: int,  # ⽤户数据库中条⽬的id,-1表示没有,
+            ex_file_id: str,  # excel⽂件id,
+            ex_cell: str,  # 数量单元格位置,例如 "C17",
+            ex_row: str,  # 该⾏内容,由逗号连接多个单元格得到,
+            ex_unit: str,  # excel中给出的单位,
+            ex_amount: float,  # excel中给出的数量,
     ):
         self.zgs_id = zgs_id
         self.zgs_code = zgs_code
@@ -188,11 +188,11 @@ class ExcelParseResultDataDto:
 
 class ExcelParseResultDto:
     def __init__(
-        self,
-        task_id: int,
-        result: int = -1,
-        reason: str = "",
-        data: list[ExcelParseResultDataDto] = None,
+            self,
+            task_id: int,
+            result: int = -1,
+            reason: str = "",
+            data: list[ExcelParseResultDataDto] = None,
     ):
         self.task_id = task_id
         self.result = result  # -1-失败;0-运行中;1-成功

+ 14 - 14
SourceCode/IntelligentRailwayCosting/app/executor/task_runner.py

@@ -36,8 +36,8 @@ class TaskRunner:
 
         # 如果项目没有任务在运行,但并发项目数已满且该项目不在运行集合中
         if (
-                len(cls._running_projects) >= cls._max_concurrent_projects
-                and project_id not in cls._running_projects
+            len(cls._running_projects) >= cls._max_concurrent_projects
+            and project_id not in cls._running_projects
         ):
             cls._add_task_to_wait_list(
                 task,
@@ -103,7 +103,7 @@ class TaskRunner:
             for project_id in list(cls._task_wait_list.keys()):
                 # 只有当项目没有任务在运行且并发项目数未满时才执行
                 if (
-                        project_id not in cls._is_running or not cls._is_running[project_id]
+                    project_id not in cls._is_running or not cls._is_running[project_id]
                 ) and len(cls._running_projects) < cls._max_concurrent_projects:
                     cls._execute_project_tasks(project_id)
         else:
@@ -124,7 +124,7 @@ class TaskRunner:
 
     @classmethod
     def _add_task_to_wait_list(
-            cls, task: ProjectTaskDto, log_message: str = None
+        cls, task: ProjectTaskDto, log_message: str = None
     ) -> None:
         """将任务添加到等待队列并更新状态"""
         project_id = task.project_id
@@ -135,7 +135,7 @@ class TaskRunner:
 
     @classmethod
     def _update_project_running_status(
-            cls, project_id: str, is_running: bool = False
+        cls, project_id: str, is_running: bool = False
     ) -> None:
         """更新项目运行状态"""
         with cls._lock:
@@ -147,9 +147,9 @@ class TaskRunner:
 
             # 如果项目没有等待任务,从等待列表中移除
             if (
-                    not is_running
-                    and project_id in cls._task_wait_list
-                    and len(cls._task_wait_list[project_id]) == 0
+                not is_running
+                and project_id in cls._task_wait_list
+                and len(cls._task_wait_list[project_id]) == 0
             ):
                 del cls._task_wait_list[project_id]
 
@@ -161,8 +161,8 @@ class TaskRunner:
             return False
         # 如果项目不在运行集合中且并发数已满,直接返回False
         if (
-                project_id not in cls._running_projects
-                and len(cls._running_projects) >= cls._max_concurrent_projects
+            project_id not in cls._running_projects
+            and len(cls._running_projects) >= cls._max_concurrent_projects
         ):
             return False
         return True
@@ -181,8 +181,8 @@ class TaskRunner:
                 try:
                     cls._logger.debug(f"开始执行项目[{project_id}]")
                     while (
-                            project_id in cls._task_wait_list
-                            and len(cls._task_wait_list[project_id]) > 0
+                        project_id in cls._task_wait_list
+                        and len(cls._task_wait_list[project_id]) > 0
                     ):
                         current_task = cls._task_wait_list[project_id].pop(0)
                         try:
@@ -224,8 +224,8 @@ class TaskRunner:
             def execute_process_tasks():
                 try:
                     while (
-                            project_id in cls._process_task_wait_list
-                            and len(cls._process_task_wait_list[project_id]) > 0
+                        project_id in cls._process_task_wait_list
+                        and len(cls._process_task_wait_list[project_id]) > 0
                     ):
                         current_task = cls._process_task_wait_list[project_id].pop(0)
                         try:

+ 1 - 1
SourceCode/IntelligentRailwayCosting/app/routes/__init__.py

@@ -15,5 +15,5 @@ def register_api(app):
     app.register_blueprint(project_api, url_prefix=f"{url_prefix}/project")
     app.register_blueprint(project_task_api, url_prefix=f"{url_prefix}/task")
     app.register_blueprint(project_quota_api, url_prefix=f"{url_prefix}/quota")
-    app.register_blueprint(excel_test_api, url_prefix=f"{url_prefix}/excel_test")
+    app.register_blueprint(excel_test_api, url_prefix=f"{url_prefix}/v1")
     app.register_blueprint(error_api, url_prefix=f"{url_prefix}/error")

+ 13 - 12
SourceCode/IntelligentRailwayCosting/app/stores/chapter.py

@@ -129,18 +129,19 @@ class ChapterStore:
             parent_codes = []
             current_code = item_code
 
-            # 将带连字符的编码转换为纯数字格式
-            pure_code = current_code.replace("-", "")
-
-            # 每两位截取一次获得父节点编码
-            for i in range(2, len(pure_code), 2):
-                code = pure_code[:i]
-                # 如果原始编码包含连字符,则将纯数字格式转回带连字符格式
-                if "-" in current_code:
-                    parts = [code[j: j + 2] for j in range(0, len(code), 2)]
-                    parent_codes.append("-".join(parts))
-                else:
-                    parent_codes.append(code)
+            # 按'-'分割item_code
+            parts = current_code.split("-")
+            
+            # 处理第一个部分(如'0101')
+            first_part = parts[0]
+            for i in range(2, len(first_part) + 1, 2):
+                parent_codes.append(first_part[:i])
+            
+            # 逐步拼接其他部分构建完整父节点列表
+            current_parent = first_part
+            for i in range(1, len(parts)):
+                current_parent = current_parent + "-" + parts[i]
+                parent_codes.append(current_parent)
 
             if not parent_codes:
                 return []

+ 7 - 7
SourceCode/IntelligentRailwayCosting/app/stores/project.py

@@ -19,13 +19,13 @@ class ProjectStore:
         )
 
     def get_user_projects_paginated(
-            self,
-            page: int = 1,
-            page_size: int = 10,
-            keyword: Optional[str] = None,
-            start_time: Optional[datetime] = None,
-            end_time: Optional[datetime] = None,
-            can_edit: Optional[int] = 0,
+        self,
+        page: int = 1,
+        page_size: int = 10,
+        keyword: Optional[str] = None,
+        start_time: Optional[datetime] = None,
+        end_time: Optional[datetime] = None,
+        can_edit: Optional[int] = 0,
     ):
         """
         分页查询用户有权限的项目列表

+ 17 - 12
SourceCode/IntelligentRailwayCosting/app/tools/db_helper/sqlserver_helper.py

@@ -19,18 +19,21 @@ class SQLServerHelper(DBHelper):
             "password": "",
             "trusted_connection": "yes",
         }
-        # self._pool_config = {
-        #     "pool_size": 5,  # 减少初始连接数以降低资源占用
-        #     "max_overflow": 10,  # 适当减少最大溢出连接数
-        #     "pool_timeout": 60,  # 增加池等待超时时间
-        #     "pool_recycle": 1800,  # 每30分钟回收连接
-        #     "pool_pre_ping": True,  # 启用连接健康检查
-        #     "connect_args": {
-        #         "timeout": 60,  # 连接超时时间
-        #         "login_timeout": 60,  # 登录超时时间
-        #         "connection_timeout": 60,  # 连接超时设置
-        #     },
-        # }
+        self._pool_config_odbc = {
+            "pool_size": 5,  # 减少初始连接数以降低资源占用
+            "max_overflow": 10,  # 适当减少最大溢出连接数
+            "pool_timeout": 60,  # 增加池等待超时时间
+            "pool_recycle": 1800,  # 每30分钟回收连接
+            "pool_pre_ping": True,  # 启用连接健康检查
+            "connect_args": {
+                "timeout": 60,  # 连接超时时间
+                "driver_connects_timeout": 60,  # 驱动连接超时
+                "connect_timeout": 60,  # ODBC连接超时
+                "connect_retries": 3,  # 连接重试次数
+                "connect_retry_interval": 10,  # 重试间隔增加到10秒
+                "connection_timeout": 60,  # 额外的连接超时设置
+            },
+        }
         self._pool_config = {
             "pool_size": 5,  # 减少初始连接数以降低资源占用
             "max_overflow": 10,  # 适当减少最大溢出连接数
@@ -108,6 +111,8 @@ class SQLServerHelper(DBHelper):
         """获取或创建数据库引擎"""
         conn_str = self._build_pymssql_connection_string(database, config)
         engine = create_engine(conn_str, **self._pool_config)
+        # conn_str = self._build_connection_string(database, config)
+        # engine = create_engine(conn_str, **self._pool_config_odbc)
         # 预热连接池
         with engine.connect() as conn:
             conn.execute(text("SELECT 1"))

+ 1 - 1
SourceCode/IntelligentRailwayCosting/app/tools/utils/logger_helper.py

@@ -99,7 +99,7 @@ class LoggerHelper:
             return
         for filename in os.listdir(cls._log_file_path):
             if filename != cls._log_file_name and filename.startswith(
-                    cls._log_file_name
+                cls._log_file_name
             ):
                 try:
                     file_path = os.path.join(cls._log_file_path, filename)

+ 16 - 15
SourceCode/IntelligentRailwayCosting/app/views/templates/project/budget_info.html

@@ -1,30 +1,31 @@
 {% extends "base/layout.html" %} {% block title %}概算信息{% endblock %} {% block page_head_plugins %}
-<link rel="stylesheet" href="{{ url_for('static', filename='base/plugins/jstree/jstree.bundle.css') }}" />
-<link rel="stylesheet" href="{{ url_for('static', filename='project/budget.css') }}" />
+<link rel="stylesheet" href="{{ url_for('static', filename='base/plugins/jstree/jstree.bundle.css') }}"/>
+<link rel="stylesheet" href="{{ url_for('static', filename='project/budget.css') }}"/>
 {% endblock %} {% block page_content %}
 
 <div class="app-body-header h-50px" id="breadcrumb_header">
-	<h3>概算信息</h3>
-	<ol class="breadcrumb breadcrumb-dot text-muted fs-6 fw-semibold ms-5">
-		<li class="breadcrumb-item"><a href="{{ url_for('project.index') }}" class="">项目管理</a></li>
-		<li class="breadcrumb-item text-muted">概算信息</li>
-	</ol>
+    <h3>概算信息</h3>
+    <ol class="breadcrumb breadcrumb-dot text-muted fs-6 fw-semibold ms-5">
+        <li class="breadcrumb-item"><a href="{{ url_for('project.index') }}" class="">项目管理</a></li>
+        <li class="breadcrumb-item text-muted">概算信息</li>
+    </ol>
+    <h4 class="ms-5 mb-0">{{project.project_name}}</h4>
 </div>
 <div class="box w-100" id="body_box"></div>
 <section class="d-none">
-	<select class="d-none" id="budget_id_options">
-		<option value="0">全部概算单元</option>
-		{% for budget in budgets %}
-		<option value="{{ budget.budget_id }}">{{ budget.budget_code }}</option>
-		{% endfor %}
-	</select>
+    <select class="d-none" id="budget_id_options">
+        <option value="0">全部概算单元</option>
+        {% for budget in budgets %}
+        <option value="{{ budget.budget_id }}">{{ budget.budget_code }}</option>
+        {% endfor %}
+    </select>
 </section>
 
 {% endblock %} {% block page_scripts %}
 <script src="{{ url_for('static', filename='base/plugins/jstree/jstree.bundle.js') }}"></script>
 <script>
-	ChangeHeadMenu('#{{page_active}}_menu')
-	const project_id = '{{project.project_id}}'
+    ChangeHeadMenu('#{{page_active}}_menu')
+    const project_id = '{{project.project_id}}'
 </script>
 <script src="{{ url_for('static', filename='project/quota_info.js') }}"></script>
 <script src="{{ url_for('static', filename='project/budget_info.js') }}"></script>

+ 4 - 3
SourceCode/IntelligentRailwayCosting/app/views/templates/project/quota_info.html

@@ -1,8 +1,8 @@
 {% extends "base/layout.html" %}
 {% block title %}定额输入管理{% endblock %}
 {% block page_head_plugins %}
-<link rel="stylesheet" href="{{ url_for('static', filename='base/plugins/jstree/jstree.bundle.css') }}" />
-<link rel="stylesheet" href="{{ url_for('static', filename='project/budget.css') }}" />
+<link rel="stylesheet" href="{{ url_for('static', filename='base/plugins/jstree/jstree.bundle.css') }}"/>
+<link rel="stylesheet" href="{{ url_for('static', filename='project/budget.css') }}"/>
 {% endblock %}
 {% block page_content %}
 <div class="app-body-header h-50px">
@@ -10,9 +10,10 @@
     <ol class="breadcrumb breadcrumb-dot text-muted fs-6 fw-semibold ms-5">
         <li class="breadcrumb-item"><a href="{{ url_for('project.index') }}" class="">项目管理</a></li>
         <li class="breadcrumb-item"><a href="{{ url_for('project.budget_info',project_id=project.project_id) }}"
-                class="">概算信息</a></li>
+                                       class="">概算信息</a></li>
         <li class="breadcrumb-item text-muted">定额输入</li>
     </ol>
+    <h4 class="ms-5 mb-0">{{project.project_name}}</h4>
 </div>
 <div class="box w-100" id="body_box"></div>
 {% endblock %}