Browse Source

update 优化代码,修复部分问题

yue 2 months ago
parent
commit
0db03cd3d5

+ 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: 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
@@ -112,22 +112,22 @@ 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,  # 定额编号,
-            dinge_adjust: 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,  # 定额编号,
+        dinge_adjust: 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
@@ -194,11 +194,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-成功

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

@@ -176,14 +176,14 @@ class TaskProcessor:
             return None, msg
 
     def _build_api_body(
-            self,
-            task: ProjectTaskDto,
-            project: ProjectDto,
-            budgets: list[TotalBudgetInfoDto],
-            chapter: 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]
@@ -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}")

+ 4 - 8
SourceCode/IntelligentRailwayCosting/app/executor/task_sender.py

@@ -14,15 +14,13 @@ class TaskSender:
     def send_task(self, task: ProjectTaskDto):
         try:
             self._logger.info(f"开始推送任务:{task.task_name}")
-            self._task_store.update_send_status(
-                task.id, SendStatusEnum.PROCESSING.value
-            )
+            self._task_store.update_send_status(task.id, SendStatusEnum.SUCCESS.value)
 
             error_count = 0
             data_list = self._quota_store.get_quotas_by_task_id(task.id, True)
             for data in data_list:
                 msg = self._quota_store.update_send_status(
-                    data.id, SendStatusEnum.PROCESSING.value
+                    data.id, SendStatusEnum.SUCCESS.value
                 )
                 if msg:
                     error_count += 1
@@ -44,12 +42,10 @@ class TaskSender:
     def send_quota(self, quota: ProjectQuotaDto):
         try:
             self._logger.debug(f"开始推送定额输入[{quota.id}]")
-            self._quota_store.update_send_status(
-                quota.id, SendStatusEnum.PROCESSING.value
-            )
+            self._quota_store.update_send_status(quota.id, SendStatusEnum.SUCCESS.value)
             quota_input = QuotaInputDto.from_quota_dto(quota)
             self._save_quota(quota_input, quota.project_id)
-            self._quota_store.update_send_status(quota.id, SendStatusEnum.SUCCESS.value)
+            # self._quota_store.update_send_status(quota.id, SendStatusEnum.SUCCESS.value)
             self._logger.debug(f"推送定额输入[{quota.id}]完成")
             return None
         except Exception as e:

+ 38 - 31
SourceCode/IntelligentRailwayCosting/app/services/project_quota.py

@@ -1,6 +1,6 @@
 from typing import Optional
 
-import tools.utils as utils, threading
+import tools.utils as utils
 from core.dtos import ProjectQuotaDto
 from core.models import ProjectQuotaModel
 from stores import ProjectQuotaStore, ChapterStore
@@ -17,14 +17,14 @@ class ProjectQuotaService:
         self._logger = utils.get_logger()
 
     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,
-        send_status: Optional[int] = None,
+            self,
+            budget_id: int,
+            project_id: str,
+            item_code: str,
+            page: int = 1,
+            page_size: int = 10,
+            keyword: Optional[str] = None,
+            send_status: Optional[int] = None,
     ):
         """获取项目定额列表
 
@@ -61,15 +61,15 @@ class ProjectQuotaService:
             raise
 
     def get_quotas_by_task_paginated(
-        self,
-        task_id: int,
-        budget_id,
-        project_id,
-        item_code,
-        page: int = 1,
-        page_size: int = 10,
-        keyword: Optional[str] = None,
-        send_status: Optional[int] = None,
+            self,
+            task_id: int,
+            budget_id,
+            project_id,
+            item_code,
+            page: int = 1,
+            page_size: int = 10,
+            keyword: Optional[str] = None,
+            send_status: Optional[int] = None,
     ):
         try:
             data = self.store.get_quotas_by_task_paginated(
@@ -321,7 +321,7 @@ class ProjectQuotaService:
             id_list = ids.split(",")
             err = ""
             for _id in id_list:
-                msg = self.start_send(int(_id), is_cover)
+                msg = self.start_send(int(_id), is_cover, False)
                 if msg:
                     err += f"{msg}[{_id}],"
             if err:
@@ -348,29 +348,36 @@ class ProjectQuotaService:
             self._logger.error(f"批量启动定额条目发送失败: {str(e)}")
             raise
 
-    def start_send(self, _id: int, is_cover: bool = False) -> Optional[str]:
+    def start_send(
+            self, _id: int, is_cover: bool = False, is_log: bool = True
+    ) -> Optional[str]:
         """启动发送"""
         quota = self.get_quota_dto(_id)
         if quota:
-            self.update_send_status(_id, 1)
+            self.update_send_status(_id, SendStatusEnum.SUCCESS.value)
             if not is_cover:
                 quota.quota_id = 0
-            thread = threading.Thread(target=self._send_quota, args=(quota,))
-            thread.start()
-            LogRecordHelper.log_success(
-                OperationType.SEND,
-                OperationModule.QUOTA,
-                f"推送定额条目",
-                f"ID:{_id},是否覆盖:{is_cover}",
-            )
-            return None
+            # thread = threading.Thread(target=self._send_quota, args=(quota,))
+            # thread.start()
+            if is_log:
+                LogRecordHelper.log_success(
+                    OperationType.SEND,
+                    OperationModule.QUOTA,
+                    f"推送定额条目",
+                    f"ID:{_id},是否覆盖:{is_cover}",
+                )
+            if self._send_quota(quota):
+                return None
+            else:
+                return f"{_id}发送失败;"
         else:
             return "定额条目没有查询到"
 
     def _send_quota(self, quota: ProjectQuotaDto):
         try:
             executor.send_quota(quota)
+            return True
         except Exception as e:
             self._logger.error(f"发送定额条目失败: {str(e)}")
             self.update_send_status(quota.id, 3, str(e))
-            raise
+            return False

+ 4 - 4
SourceCode/IntelligentRailwayCosting/app/stores/quota_input.py

@@ -106,8 +106,8 @@ class QuotaInputStore:
                 # sequence_number=dto.sequence_number,
                 project_name=dto.project_name,
                 unit=dto.unit,
-                project_quantity=dto.project_quantity,
-                # project_quantity_input=dto.project_quantity_input,
+                # project_quantity=dto.project_quantity,
+                project_quantity_input=str(dto.project_quantity),
                 quota_adjustment=dto.quota_adjustment,
                 # compilation_unit_price=dto.compilation_unit_price,
                 # compilation_total_price=dto.compilation_total_price,
@@ -174,8 +174,8 @@ class QuotaInputStore:
             # model.sequence_number = dto.sequence_number
             model.project_name = dto.project_name
             model.unit = dto.unit
-            model.project_quantity = dto.project_quantity
-            # model.project_quantity_input = dto.project_quantity_input
+            # model.project_quantity = dto.project_quantity
+            model.project_quantity_input = str(dto.project_quantity)
             model.quota_adjustment = dto.quota_adjustment
             # model.unit_price = dto.unit_price
             # model.compilation_unit_price = dto.compilation_unit_price

+ 1 - 1
SourceCode/IntelligentRailwayCosting/app/stores/railway_costing_mysql/project_quota.py

@@ -115,7 +115,7 @@ class ProjectQuotaStore:
 
             # 分页
             query = (
-                query.order_by(ProjectQuotaModel.id.desc())
+                query.order_by(ProjectQuotaModel.id.asc())
                 .offset((page - 1) * page_size)
                 .limit(page_size)
             )

+ 7 - 2
SourceCode/IntelligentRailwayCosting/app/views/static/base/js/utils.js

@@ -156,7 +156,11 @@ function IwbTable(table, opts, isReload) {
                 if (opt.checkBox) {
                     const disabled_checkbox = opt.checkBoxDisable && opt.checkBoxDisable(row) ? 'disabled' : ''
                     if (opt.selected_ids.size && opt.selected_ids.has(row[opt.idFiled] + "")) {
-                        body_str += `<td>${checkBoxDiv.format(row[opt.idFiled], `${opt.tableCheckboxName}`, `checked ${disabled_checkbox}`)}</td>`
+                        if (disabled_checkbox === '') {
+                            body_str += `<td>${checkBoxDiv.format(row[opt.idFiled], `${opt.tableCheckboxName}`, `checked`)}</td>`
+                        } else {
+                            body_str += `<td>${checkBoxDiv.format(row[opt.idFiled], `${opt.tableCheckboxName}`, `${disabled_checkbox}`)}</td>`
+                        }
                     } else {
                         check_all = false
                         body_str += `<td>${checkBoxDiv.format(row[opt.idFiled], `${opt.tableCheckboxName}`, `${disabled_checkbox}`)}</td>`
@@ -468,11 +472,12 @@ function Confirm(title, callback) {
     });
 }
 
-function ConfirmUrl(title, url, table) {
+function ConfirmUrl(title, url, table, success) {
     Confirm(title, function () {
         IwbAjax({
             url: url,
             table: table || '#table',
+            success: success
         })
     })
 }

+ 24 - 3
SourceCode/IntelligentRailwayCosting/app/views/static/project/budget_info.js

@@ -416,17 +416,38 @@ function Delete(id) {
 }
 
 function StarTask(id) {
-    ConfirmUrl('确定开始运行任务吗?', `/api/task/start_task/${id}`, `#table_0`)
+    clear()
+    ConfirmUrl('确定开始运行任务吗?', `/api/task/start_task/${id}`, `#table_0`, function () {
+        auto_refresh_table(id)
+    })
 }
 
 function ReStarTask(id) {
-    ConfirmUrl('确定重新开始运行任务吗?', `/api/task/start_task/${id}`, `#table_0`)
+    clear()
+    ConfirmUrl('确定重新开始运行任务吗?', `/api/task/start_task/${id}`, `#table_0`, function () {
+        auto_refresh_table(id)
+    })
 }
 
 function CancelTask(id) {
-    ConfirmUrl('确定取消运行任务吗?', `/api/task/cancel_task/${id}`, `#table_0`)
+    ConfirmUrl('确定取消运行任务吗?', `/api/task/cancel_task/${id}`, `#table_0`, function () {
+        clear()
+    })
 }
 
+function auto_refresh_table(id) {
+    clearTimeout(task_timer)
+    task_query_count++
+    task_timer = setTimeout(() => {
+        const $table = $(`#table_0`), rows = $table.data('rows')
+        const row = rows.find(row => row.id === id)
+        IwbTable($table)
+        console.log("===>", task_query_count, row)
+        if (task_query_count <= 20 && (!row || row.process_status !== 200 && row.process_status !== 4)) {
+            auto_refresh_table(id)
+        }
+    }, 10 * 1000)
+}
 
 // function StartProcessTask(id){
 // 	ConfirmUrl('确定开始处理吗?',`/api/task/start_process/${id}`,`#table_0`)

+ 17 - 6
SourceCode/IntelligentRailwayCosting/app/views/static/project/quota_info.js

@@ -152,8 +152,8 @@ const nav_template = `<ul id="nav_tab" class="nav nav-tabs nav-line-tabs nav-lin
 											<input type="text" class="form-control form-control-sm w-200px" placeholder="请输入关键字" name="keyword" />
 										</div>
 										<div class="btn-group ms-5">
-											<button type="button" class="btn btn-primary btn-sm" onclick="IwbTableSearch(this)">查询</button>
-											<button type="button" class="btn btn-danger btn-sm" onclick="IwbTableResetSearch(this)">重置</button>
+											<button type="button" class="btn btn-primary btn-sm" onclick="IwbTableSearch(this);clear()">查询</button>
+											<button type="button" class="btn btn-danger btn-sm" onclick="IwbTableResetSearch(this);clear()">重置</button>
 										</div>
 									</form>
 								</div>
@@ -166,14 +166,23 @@ let table_add_quota_btn_template = `<button type="button" class="quota_add_btn b
 //`<button type="button" class="quota_add_btn btn btn-primary btn-sm" onclick="Add_Quota('{0}')">添加定额</button>`
 
 const $modalQuota = $('#modal_quota'), $modalChapter = $('#modal_chapter')
-let $rightBox, $rightBoxHeader, $rightBoxBody, $taskBox, $quotaBox, budget_id, item_code
+let $rightBox, $rightBoxHeader, $rightBoxBody, $taskBox, $quotaBox, budget_id, item_code, task_timer,
+    task_query_count = 0
 
 console.log(`加载项目:${project_id}`)
 InitBody()
+
+function clear() {
+    task_query_count = 0
+    clearTimeout(task_timer)
+}
+
 $(function () {
     BuildChapterInfo()
     $(window).on('resize', AdjustBoxHeight)
-    RenderChapterSelect()
+    if (task_id) {
+        RenderChapterSelect()
+    }
 })
 
 function InitBody() {
@@ -280,6 +289,7 @@ function BuildChapterInfo() {
 function RenderRightBox(data) {
     console.log('RenderRightBox', arguments)
     $rightBoxBody.data('data', data)
+    clear()
     $rightBox.find('input[name="budget_id"]').val(data.budget_id);
     $rightBox.find('input[name="project_id"]').val(project_id);
     $rightBox.find('input[name="item_id"]').val(data.item_id);
@@ -291,6 +301,7 @@ function RenderRightBox(data) {
 }
 
 function RenderRightBox_Custom(data) {
+
     $('.table_radio_box .form-check').hide()
     $quotaBox.data("table-url", `/api/quota/list/task/${task_id}`)
     QuotaNavTab(data)
@@ -634,14 +645,14 @@ function Send_Quota_Batch(budget_id) {
             ids.push(row.id)
         }
         const ids_str = ids.join(','), insert_ids_str = insert_ids.join(','), update_ids_str = update_ids.join(',')
-        let str = `<div class="">确定批量推送这些数据吗?部分数据只能新增,无法覆盖,请谨慎操作!</div>`
+        let str = `<div class="mb-3 fw-bold">确定批量推送这些数据吗?</div>`
         if (insert_ids_str) {
             str += `<div class="text-primary d-flex align-items-center"><strong style="white-space: nowrap">新增ID:</strong>${insert_ids_str}</div>`
         }
         if (update_ids_str) {
             str += `<div class="text-danger d-flex align-items-center"><strong style="white-space: nowrap">覆盖(修改)ID:</strong>${update_ids_str}</div>`
         }
-        SendQuota(str, ids_str, budget_id, true, true)
+        SendQuota(str, ids_str, budget_id, !!update_ids_str, true)
     } else {
         MsgWarning('没有选择数据,请选择要推送的数据!')
     }