Browse Source

优化运营成本统计

peng 1 năm trước cách đây
mục cha
commit
b10770eba6
1 tập tin đã thay đổi với 5 bổ sung4 xóa
  1. 5 4
      Controller/Cron/CronTaskController.py

+ 5 - 4
Controller/Cron/CronTaskController.py

@@ -1137,10 +1137,11 @@ class CronCollectDataView(View):
     def collect_operating_costs(response):
         try:
             today = datetime.datetime.today()
-            start_time = datetime.datetime(today.year, today.month, 1)
             end_time = datetime.datetime(today.year, today.month, today.day)
-            start_time_stamp = CommonService.str_to_timestamp(start_time.strftime('%Y-%m-%d %H:%M:%S'))
-            end_time_stamp = CommonService.str_to_timestamp(end_time.strftime('%Y-%m-%d %H:%M:%S'))
+            yesterday = end_time - datetime.timedelta(days=1)
+            start_time = datetime.datetime(yesterday.year, yesterday.month, 1)
+            start_time_stamp = int(start_time.timestamp())
+            end_time_stamp = int(end_time.timestamp())
             thread = threading.Thread(target=CronCollectDataView.thread_collect_operating_costs,
                                       args=(start_time_stamp, end_time_stamp, start_time, end_time))
             thread.start()  # 启动线程
@@ -1253,8 +1254,8 @@ class CronCollectDataView(View):
         try:
             today = datetime.datetime.today()
             end_time = datetime.datetime(today.year, today.month, today.day)
-            first_date = datetime.datetime(today.year, today.month, 1)
             start_time = end_time - datetime.timedelta(days=1)
+            first_date = datetime.datetime(start_time.year, start_time.month, 1)
             start_time_stamp = int(start_time.timestamp())
             end_time_stamp = int(end_time.timestamp())
             first_date_stamp = int(first_date.timestamp())