Ver Fonte

Update 数据推送功能更新

yue há 4 meses atrás
pai
commit
8dd37ffc46

+ 1 - 0
SourceCode/IntelligentRailwayCosting/app/core/dtos/project_quota.py

@@ -35,6 +35,7 @@ class ProjectQuotaDto(BaseModel):
     created_by: Optional[str] = None
     updated_at: Optional[datetime] = None
     updated_by: Optional[str] = None
+    sequence_number: Optional[int] = None
 
     @classmethod
     def from_model(cls, model: ProjectQuotaModel) -> "ProjectQuotaDto":

+ 1 - 1
SourceCode/IntelligentRailwayCosting/app/core/dtos/quota_input.py

@@ -106,7 +106,7 @@ class QuotaInputDto(BaseModel):
             budget_id=quota_dto.budget_id,
             item_id=quota_dto.item_id,
             quota_code=quota_dto.quota_code,
-            sequence_number=1000,
+            sequence_number=quota_dto.sequence_number,
             project_name=quota_dto.entry_name,
             unit=quota_dto.units,
             project_quantity=quota_dto.amount,

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

@@ -45,7 +45,7 @@ class TaskSender:
             self._quota_store.update_send_status(quota.id, SendStatusEnum.SUCCESS.value)
             quota_input = QuotaInputDto.from_quota_dto(quota)
             quota_input.project_name = f"{quota_input.project_name}{configs.app.ai_flag if quota.is_change else ''}"
-            self._save_quota(quota_input, quota.project_id)
+            self._save_quota(quota_input, quota.project_id, quota.id)
             # self._quota_store.update_send_status(quota.id, SendStatusEnum.SUCCESS.value)
             self._logger.debug(f"推送定额输入[{quota.id}]完成")
             return None
@@ -57,7 +57,7 @@ class TaskSender:
             )
             return msg
 
-    def _save_quota(self, quota: QuotaInputDto, project_id: str):
+    def _save_quota(self, quota: QuotaInputDto, project_id: str, project_quota_id: int):
         try:
             # data = self._quota_input_store.get_quota(project_id, quota.budget_id,quota.item_id,quota.quota_code)
             if quota.quota_id and quota.quota_id > 0:
@@ -66,7 +66,8 @@ class TaskSender:
                 )
                 self._quota_input_store.update_quota(project_id, quota)
             else:
-                self._quota_input_store.create_quota(project_id, quota)
+                dto = self._quota_input_store.create_quota(project_id, quota)
+                self._quota_store.update_quota_id(project_quota_id, dto.quota_id)
                 self._logger.debug(
                     f"新增定额输入[{quota.quota_id}]:{quota.project_name} {quota.quota_code} {quota.quota_id}"
                 )

+ 13 - 1
SourceCode/IntelligentRailwayCosting/app/routes/project_quota.py

@@ -138,7 +138,19 @@ def start_send():
             return ResponseBase.error(msg)
         return ResponseBase.success()
     except Exception as e:
-        return ResponseBase.error(f"启动定额条目失败:{str(e)}")
+        return ResponseBase.error(f"推送定额条目失败:{str(e)}")
+
+
+@project_quota_api.route("/start_send_all/<int:task_id>", methods=["POST"])
+@Permission.authorize
+def start_send_all(task_id: int):
+    try:
+        msg = quota_service.start_send_by_task_id(task_id)
+        if msg:
+            return ResponseBase.error(msg)
+        return ResponseBase.success()
+    except Exception as e:
+        return ResponseBase.error(f"推送定额条目失败:{str(e)}")
 
 
 @project_quota_api.route("/save_change_chapter/<project_id>", methods=["POST"])

+ 52 - 8
SourceCode/IntelligentRailwayCosting/app/services/project_quota.py

@@ -3,7 +3,7 @@ from typing import Optional
 import tools.utils as utils
 from core.dtos import ProjectQuotaDto
 from core.models import ProjectQuotaModel
-from stores import ProjectQuotaStore, ChapterStore
+from stores import ProjectQuotaStore, ChapterStore, QuotaInputStore
 from core.log.log_record import LogRecordHelper
 from core.enum import OperationModule, OperationType, SendStatusEnum
 
@@ -13,6 +13,7 @@ import executor
 class ProjectQuotaService:
     def __init__(self):
         self.store = ProjectQuotaStore()
+        self.quota_input_store = QuotaInputStore()
         self.chapter_store = ChapterStore()
         self._logger = utils.get_logger()
 
@@ -35,7 +36,7 @@ class ProjectQuotaService:
             page: 页码
             page_size: 每页数量
             keyword: 关键字
-            send_status: 送状态
+            send_status: 送状态
 
         Returns:
             dict: 包含总数和定额列表的字典
@@ -185,6 +186,9 @@ class ProjectQuotaService:
                 quota_dto.ex_unit = quota.ex_unit
                 quota_dto.ex_amount = quota.ex_amount
                 quota_dto.note = quota.note
+                quota_dto.send_status = quota.send_status
+                quota_dto.send_time = quota.send_time
+                quota_dto.send_error = ""
 
             # self.update_process_status(quota_dto.id,4)
             LogRecordHelper.log_success(
@@ -348,7 +352,7 @@ class ProjectQuotaService:
             return msg
 
     def update_send_status(self, quota_id: int, status: int, err: str = None) -> bool:
-        """更新送状态
+        """更新送状态
 
         Args:
             quota_id: 定额ID
@@ -361,7 +365,7 @@ class ProjectQuotaService:
         try:
             return self.store.update_send_status(quota_id, status, err)
         except Exception as e:
-            self._logger.error(f"更新项目定额送状态失败: {str(e)}")
+            self._logger.error(f"更新项目定额送状态失败: {str(e)}")
             raise
 
     # def start_process(self, quota_id: int) -> Optional[str]:
@@ -413,13 +417,47 @@ class ProjectQuotaService:
                 f"批量推送定额条目失败: {str(e)}",
                 ids,
             )
-            self._logger.error(f"批量启动定额条目发送失败: {str(e)}")
+            self._logger.error(f"批量启动定额条目推送失败: {str(e)}")
+            raise
+
+    def start_send_by_task_id(self, task_id):
+        try:
+            quota_list = self.store.get_quotas_by_task_id(task_id)
+            err = ""
+            for quota in quota_list:
+                msg = self.start_send(
+                    quota.id, True if quota.quota_id else False, False
+                )
+                if msg:
+                    err += f"{msg}[{quota.id}],"
+            if err:
+                LogRecordHelper.log_fail(
+                    OperationType.SEND,
+                    OperationModule.QUOTA,
+                    f"推送全部定额条目失败",
+                    f"任务ID:{task_id}",
+                )
+            LogRecordHelper.log_success(
+                OperationType.SEND,
+                OperationModule.QUOTA,
+                f"推送全部定额条目",
+                f"任务ID:{task_id}",
+            )
+            return err
+        except Exception as e:
+            LogRecordHelper.log_fail(
+                OperationType.SEND,
+                OperationModule.QUOTA,
+                f"推送全部定额条目失败: {str(e)}",
+                f"任务ID:{task_id}",
+            )
+            self._logger.error(f"推送全部定额条目失败: {str(e)}")
             raise
 
     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, SendStatusEnum.SUCCESS.value)
@@ -434,10 +472,16 @@ class ProjectQuotaService:
                     f"推送定额条目",
                     f"ID:{_id},是否覆盖:{is_cover}",
                 )
+
+            if not is_cover:
+                num = self.quota_input_store.query_quota_sequence_number(
+                    quota.project_id, quota.budget_id, quota.item_id
+                )
+                quota.sequence_number = num
             if self._send_quota(quota):
                 return None
             else:
-                return f"{_id}发送失败;"
+                return f"{_id}送失败;"
         else:
             return "定额条目没有查询到"
 
@@ -446,6 +490,6 @@ class ProjectQuotaService:
             executor.send_quota(quota)
             return True
         except Exception as e:
-            self._logger.error(f"送定额条目失败: {str(e)}")
+            self._logger.error(f"送定额条目失败: {str(e)}")
             self.update_send_status(quota.id, 3, str(e))
             return False

+ 27 - 9
SourceCode/IntelligentRailwayCosting/app/stores/quota_input.py

@@ -20,13 +20,13 @@ class QuotaInputStore:
         return self._current_user
 
     def get_quotas_paginated(
-        self,
-        project_id: str,
-        budget_id: int,
-        item_id: int,
-        page: int = 1,
-        page_size: int = 10,
-        keyword: Optional[str] = None,
+            self,
+            project_id: str,
+            budget_id: int,
+            item_id: int,
+            page: int = 1,
+            page_size: int = 10,
+            keyword: Optional[str] = None,
     ):
         """分页查询定额输入列表
 
@@ -147,8 +147,26 @@ class QuotaInputStore:
 
             return QuotaInputDto.from_model(model)
 
+    def query_quota_sequence_number(
+            self, project_id: str, budget_id: int, item_id: int
+    ):
+        self._database = project_id
+        with db_helper.sqlserver_session(self._database) as db_session:
+            num = (
+                db_session.query(QuotaInputModel.sequence_number)
+                .filter(
+                    and_(
+                        QuotaInputModel.budget_id == budget_id,
+                        QuotaInputModel.item_id == item_id,
+                    )
+                )
+                .order_by(QuotaInputModel.sequence_number.desc())
+                .first()
+            )
+            return num[0] + 1 if num and num[0] else 1
+
     def update_quota(
-        self, project_id: str, dto: QuotaInputDto
+            self, project_id: str, dto: QuotaInputDto
     ) -> Optional[QuotaInputDto]:
         """更新定额输入
 
@@ -172,7 +190,7 @@ class QuotaInputStore:
             model.budget_id = dto.budget_id
             model.item_id = dto.item_id
             model.quota_code = dto.quota_code
-            model.sequence_number = dto.sequence_number
+            model.sequence_number = model.sequence_number
             model.project_name = dto.project_name
             model.unit = dto.unit
             model.project_quantity = dto.project_quantity

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

@@ -268,6 +268,15 @@ class ProjectQuotaStore:
             quota = db_session.merge(quota)
             return ProjectQuotaDto.from_model(quota)
 
+    def update_quota_id(self, id: int, quota_id: int):
+        quota = self.get_quota(id)
+        if not quota:
+            raise Exception(f"定额条目[{id}]不存在")
+        with db_helper.mysql_session(self._database) as db_session:
+            quota.quota_id = quota_id
+            quota = db_session.merge(quota)
+            return ProjectQuotaDto.from_model(quota)
+
     def update_quota_change(self, quota_id: int):
         quota = self.get_quota(quota_id)
         if not quota:
@@ -286,6 +295,11 @@ class ProjectQuotaStore:
         with db_helper.mysql_session(self._database) as db_session:
             quota.item_id = item_id
             quota.item_code = item_code
+            quota.send_status = (
+                SendStatusEnum.CHANGE.value
+                if quota.send_status == SendStatusEnum.SUCCESS.value
+                else quota.send_status
+            )
             quota.updated_by = self.current_user.username
             quota.updated_at = datetime.now()
             quota = db_session.merge(quota)

+ 22 - 12
SourceCode/IntelligentRailwayCosting/app/views/static/project/quota_info.js

@@ -161,7 +161,9 @@ const nav_template = `<ul id="nav_tab" class="nav nav-tabs nav-line-tabs nav-lin
 								<table class="table table-striped table-bordered table-hover  table-rounded" id="table_{0}">
 								</table>
 							</div>`
-let table_add_quota_btn_template = `<button type="button" class="quota_add_btn btn btn-primary btn-sm" onclick="Send_Quota_Batch('{0}')">批量推送</button>`;
+let table_add_quota_btn_template = ''
+table_add_quota_btn_template += `<button type="button" class="quota_add_btn btn btn-info btn-sm" onclick="Send_Quota_All('{0}')">全部推送</button>`;
+table_add_quota_btn_template += `<button type="button" class="ms-5 quota_add_btn btn btn-primary btn-sm" onclick="Send_Quota_Batch('{0}')">批量推送</button>`;
 table_add_quota_btn_template += `<button type="button" class="ms-5 btn btn-warning btn-sm" onclick="Edit_Quota_Code_Batch('{0}')">批量修改定额编号</button>`
 // table_add_quota_btn_template += `<button type="button" class="ms-5 btn btn-warning btn-sm" onclick="Edit_QuotaChapter(null,'{0}')">批量修改章节</button>`
 //`<button type="button" class="quota_add_btn btn btn-primary btn-sm" onclick="Add_Quota('{0}')">添加定额</button>`
@@ -378,12 +380,12 @@ function LoadQuotaTable(table) {
         editUrl: '/api/quota/edit',
         checkBox: true,
         isDragColumn: true,
-        checkBoxDisable: (row) => {
-            return row.send_status === 200
-        },
-        canEdit: (row) => {
-            return row.send_status !== 200
-        },
+        // checkBoxDisable: (row) => {
+        //     return row.send_status === 200
+        // },
+        // canEdit: (row) => {
+        //     return row.send_status !== 200
+        // },
         trClass: (row) => {
             return row.note || !row.quota_code ? 'tr-waring' : ''
         },
@@ -529,16 +531,20 @@ function LoadQuotaTable(table) {
                     if (row.send_status === 0) {
                         str += `<button type="button" class="btn btn-icon btn-sm ${row.quota_id ? 'btn-primary' : 'btn-light-primary'}" data-bs-toggle="tooltip" data-bs-placement="top" title="开始推送" onclick="StartSendQuota(${row.id}, ${row.budget_id}, ${row.quota_id})"><i class="ki-duotone ki-send fs-3"><span class="path1"></span><span class="path2"></span></i></button>`
                     } else if (row.send_status === 200) {
-                        str = `<span class="text-gray-500">暂无操作</span>`
-                        // str += `<button type="button" class="btn btn-icon btn-sm  ${row.quota_id ? 'btn-warning' : 'btn-light-warning'}" data-bs-toggle="tooltip" data-bs-placement="top" title="重新推送" onclick="ReStartSendQuota(${row.id}, ${row.budget_id}, ${row.quota_id})"><i class="ki-duotone ki-send fs-3"><span class="path1"></span><span class="path2"></span></i></button>`
+                        // str = `<span class="text-gray-500">暂无操作</span>`
+                        str += `<button type="button" class="btn btn-icon btn-sm  ${row.quota_id ? 'btn-warning' : 'btn-light-warning'}" data-bs-toggle="tooltip" data-bs-placement="top" title="重新推送" onclick="ReStartSendQuota(${row.id}, ${row.budget_id}, ${row.quota_id})"><i class="ki-duotone ki-send fs-3"><span class="path1"></span><span class="path2"></span></i></button>`
+
                     } else if (row.send_status === 2) {
                         str += `<button type="button" class="btn btn-icon btn-sm  ${row.quota_id ? 'btn-danger' : 'btn-light-danger'}" data-bs-toggle="tooltip" data-bs-placement="top" title="重新推送" onclick="ReStartSendQuota(${row.id}, ${row.budget_id}, ${row.quota_id})"><i class="ki-duotone ki-send fs-3"><span class="path1"></span><span class="path2"></span></i></button>`
                     } else if (row.send_status === 3) {
                         str += `<button type="button" class="btn btn-icon btn-sm  ${row.quota_id ? 'btn-info' : 'btn-light-info'}" data-bs-toggle="tooltip" data-bs-placement="top" title="重新推送" onclick="ReStartSendQuota(${row.id}, ${row.budget_id}, ${row.quota_id})"><i class="ki-duotone ki-send fs-3"><span class="path1"></span><span class="path2"></span></i></button>`
                     }
-                    if (row.send_status !== 200) {
-                        str += `<button type="button" class="btn btn-icon btn-sm btn-light-primary" data-bs-toggle="tooltip" data-bs-placement="top" title="编辑" onclick="Edit_Quota(${row.id}, ${row.budget_id})"><i class="ki-duotone ki-message-edit fs-1"><span class="path1"></span><span class="path2"></span></i></button>`
-                        str += `<button type="button" class="btn btn-icon btn-sm btn-light-primary" data-bs-toggle="tooltip" data-bs-placement="top" title="修改条目" onclick="Edit_QuotaChapter(${row.id}, ${row.budget_id})"><i class="ki-duotone ki-burger-menu-1 fs-1"><span class="path1"></span><span class="path2"></span><span class="path3"></span><span class="path4"></span></i></button>`
+                    str += `<button type="button" class="btn btn-icon btn-sm btn-light-primary" data-bs-toggle="tooltip" data-bs-placement="top" title="编辑" onclick="Edit_Quota(${row.id}, ${row.budget_id})"><i class="ki-duotone ki-message-edit fs-1"><span class="path1"></span><span class="path2"></span></i></button>`
+                    str += `<button type="button" class="btn btn-icon btn-sm btn-light-primary" data-bs-toggle="tooltip" data-bs-placement="top" title="修改条目" onclick="Edit_QuotaChapter(${row.id}, ${row.budget_id})"><i class="ki-duotone ki-burger-menu-1 fs-1"><span class="path1"></span><span class="path2"></span><span class="path3"></span><span class="path4"></span></i></button>`
+
+                    if (row.send_status !== 200 && row.send_status !== 3) {
+                        // str += `<button type="button" class="btn btn-icon btn-sm btn-light-primary" data-bs-toggle="tooltip" data-bs-placement="top" title="编辑" onclick="Edit_Quota(${row.id}, ${row.budget_id})"><i class="ki-duotone ki-message-edit fs-1"><span class="path1"></span><span class="path2"></span></i></button>`
+                        // str += `<button type="button" class="btn btn-icon btn-sm btn-light-primary" data-bs-toggle="tooltip" data-bs-placement="top" title="修改条目" onclick="Edit_QuotaChapter(${row.id}, ${row.budget_id})"><i class="ki-duotone ki-burger-menu-1 fs-1"><span class="path1"></span><span class="path2"></span><span class="path3"></span><span class="path4"></span></i></button>`
                         str += `<button type="button" class="btn btn-icon btn-sm btn-light-danger"  data-bs-toggle="tooltip" data-bs-placement="top" title="删除" onclick="Delete_Quota(${row.id}, ${row.budget_id})"><i class="ki-duotone ki-trash-square fs-1"><span class="path1"></span><span class="path2"></span><span class="path3"></span><span class="path4"></span></i></button>`
                     }
                     return str
@@ -657,6 +663,10 @@ function ReStartSendQuota(ids, budget_id, is_cover) {
     SendQuota('确定重新开始推送数据吗?', ids, budget_id, is_cover)
 }
 
+function Send_Quota_All(budget_id) {
+    ConfirmUrl('确定推送全部数据吗?', `/api/quota/start_send_all/${task_id}`, `#table_${budget_id}`)
+}
+
 function Send_Quota_Batch(budget_id) {
     const $table = `#table_${budget_id}`,
         selectedRows = IwbTableGetSelectedRows($table)