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