Browse Source

update 优化代码

yue 2 months ago
parent
commit
f35afbbf9c

+ 1 - 1
SourceCode/IntelligentRailwayCosting/app/core/configs/app_config.py

@@ -55,4 +55,4 @@ class AppConfig:
         self._task_api_url = config.get("task_api_url", "")
         self._task_max_projects_count = int(config.get("task_max_projects", 10))
         self._task_interval = int(config.get("task_interval", 300))
-        self._ai_flag = config.get("ai_flag", "_AI")
+        self._ai_flag = config.get("ai_flag", "[AI]")

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

@@ -52,18 +52,18 @@ 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],
-        selected_chapter: list[ExcelParseItemDto],
-        # 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],
+            selected_chapter: ExcelParseItemDto,
+            # hierarchy: list[ExcelParseItemDto],
+            # components: list[ExcelParseItemDto],
+            files: list[ExcelParseFileDto],
     ):
         self.task_id = task_id
         self.version = version
@@ -87,7 +87,7 @@ class ExcelParseDto:
             "selected_zgs_id": self.selected_zgs_id,
             "files": [file.to_dict() for file in self.files],
             "zgs_list": [zgs.to_dict() for zgs in self.zgs_list],
-            "selected_chapter": [item.to_dict() for item in self.selected_chapter],
+            "selected_chapter": self.selected_chapter.to_dict(),
             # "hierarchy": [item.to_dict() for item in self.hierarchy],
             # "components": [item.to_dict() for item in self.components],
         }
@@ -112,21 +112,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
@@ -192,11 +192,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-成功

+ 13 - 13
SourceCode/IntelligentRailwayCosting/app/executor/task_processor.py

@@ -176,20 +176,20 @@ class TaskProcessor:
             return None, msg
 
     def _build_api_body(
-        self,
-        task: ProjectTaskDto,
-        project: ProjectDto,
-        budgets: list[TotalBudgetInfoDto],
-        chapter: list[ChapterDto],
-        # parents: list[ChapterDto],
-        # children: list[ChapterDto],
-        files: list[ExcelParseFileDto],
+            self,
+            task: ProjectTaskDto,
+            project: ProjectDto,
+            budgets: list[TotalBudgetInfoDto],
+            chapter: ChapterDto,
+            # parents: list[ChapterDto],
+            # children: list[ChapterDto],
+            files: list[ExcelParseFileDto],
     ):
         try:
             budgets_data = [ExcelParseZgsDto.from_dto(budget) for budget in budgets]
-            chapter_data = [ExcelParseItemDto.from_dto(chapter) for chapter in chapter]
             # parents_data = [ExcelParseItemDto.from_dto(parent) for parent in parents]
             # children_data = [ExcelParseItemDto.from_dto(child) for child in children]
+            chapter_data = ExcelParseItemDto.from_dto(chapter)
             data = ExcelParseDto(
                 task_id=task.id or 0,
                 version=configs.app.version or "2020",
@@ -233,10 +233,10 @@ class TaskProcessor:
             raise Exception(msg)
 
     def _insert_data(
-        self,
-        task: ProjectTaskDto,
-        project: ProjectDto,
-        data: list[ExcelParseResultDataDto],
+            self,
+            task: ProjectTaskDto,
+            project: ProjectDto,
+            data: list[ExcelParseResultDataDto],
     ):
         try:
             self._logger.debug(f"开始插入数据:{task.task_name}")

+ 18 - 7
SourceCode/IntelligentRailwayCosting/app/routes/excel_test.py

@@ -2,12 +2,14 @@ from flask import Blueprint, request, jsonify
 import random
 import string
 
-from core.dtos import ExcelParseResultDto, ExcelParseResultDataDto
+from core.dtos import ExcelParseResultDto, ExcelParseResultDataDto, ChapterDto
+from stores import ChapterStore
 
 excel_test_api = Blueprint("test_api", __name__)
 
 test_data_dic = {}
 task_count_dic = {}
+chapter_store = ChapterStore()
 
 
 @excel_test_api.route("/task_submit", methods=["POST"])
@@ -65,12 +67,21 @@ def build_test_data(task_data):
     if file_excel:
         file = random.choice(file_excel)
         ex_file_id = file.get("file_id")
-
-    items = task_data.get("components", [])
-    item = random.choice(items)
-    item_id = item.get("item_id", 2)
-    item_code = item.get("item_code", "01")
-    entry_name = item.get("item_name", "001")
+    project_id = task_data.get("project_id", None)
+    selected_chapter = task_data.get("selected_chapter", None)
+    item_id = 0
+    item_code = ""
+    entry_name = ""
+    if project_id and selected_chapter:
+        selected_item_code = selected_chapter.get("item_code", "")
+        items = chapter_store.get_all_children_chapter_items(
+            project_id, selected_item_code
+        )
+        item_data = random.choice(items)
+        item = ChapterDto.from_model(item_data)
+        item_id = item.item_id
+        item_code = item.item_code
+        entry_name = item.project_name
     dinge_code = f"TY-{''.join(random.choices(string.digits, k=3))}"
     # 随机选择单位和数量
     units_list = ["个", "米", "千米", "平方米", "立方米", "吨", "件"]