Forráskód Böngészése

新增定时更新is_ai/联通账期流量

zhangdongming 2 éve
szülő
commit
f31771857d

+ 7 - 0
Controller/Cron/CronTaskController.py

@@ -102,6 +102,13 @@ class CronDelDataView(View):
                           '730201450AA', '730201450MA', '730201450NA', '72V201252AA', '72V201253AA',
                           '72V201353AA', '72V201354AA', '72V201355AA', '72V201254AA']
             UidSetModel.objects.filter(ucode__in=ucode_list, is_custom_voice=0).update(is_custom_voice=1)
+
+            # 根据设备规格码更新is_ai
+            ucode_list = ['823C01552AA', '823C01550XA', 'C18201550KA', '823C01550TA',
+                          '823C01550VA', '823C01850XA', 'C18201850KA', '823C01850TA', '823C01850VA',
+                          '730201450AA', '730201450MA', '730201450NA', '72V201252AA', '72V201253AA',
+                          '72V201353AA', '72V201354AA', '72V201355AA', '72V201254AA']
+            UidSetModel.objects.filter(ucode__in=ucode_list, is_ai=2).update(is_ai=1)
             return response.json(0)
         except Exception as e:
             return response.json(500, repr(e))

+ 55 - 0
Controller/UnicomCombo/UnicomComboTaskController.py

@@ -59,6 +59,10 @@ class UnicomComboTaskView(View):
             return self.query_flow_used_history(response)
         elif operation == 'queryFlowCache':
             return self.query_flow_cache(response)
+        elif operation == 'getDeviceUsageHistory':
+            return self.get_device_usage_history(response)
+        else:
+            return response.json(414)
 
     @classmethod
     def check_activate_combo(cls, request_dict, response):
@@ -422,3 +426,54 @@ class UnicomComboTaskView(View):
         except Exception as e:
             logger.info('出错了~次月激活套餐异常,errLine:{}, errMsg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
             return response.json(177, repr(e))
+
+    @staticmethod
+    def get_device_usage_history(response):
+        """
+        查询联通设备历史用量
+        """
+        card_qs = UnicomDeviceInfo.objects.filter(card_type=0).values('iccid')
+        if not card_qs.exists():
+            return response.json(0)
+        asy = threading.Thread(target=UnicomComboTaskView.async_update_device_usage_history, args=(card_qs,))
+        asy.start()
+        return response.json(0)
+
+    @staticmethod
+    def async_update_device_usage_history(qs):
+        """
+        异步更新设备用量历史
+        @param qs: 联通iccid集合
+        """
+        try:
+            u_service = UnicomObjeect()
+            iot_card_list = []
+            now_time = int(time.time())
+            # 获取当前时间
+            current_date = datetime.datetime.now()
+            # 计算上个月的时间
+            last_month_date = current_date - datetime.timedelta(days=current_date.day)
+            # 例格式化日期为 "202307"
+            formatted_date = last_month_date.strftime('%Y%m')
+            for item in qs:
+                params = {'iccid': item['iccid']}
+                result = u_service.query_device_usage_history(**params)
+                res_dict = u_service.get_text_dict(result)
+                if res_dict['code'] == 0 and res_dict['data']:
+                    for cycle in res_dict['data']:
+                        if cycle['flowTotalUsage'] <= 0 or cycle['cycle'] != int(formatted_date):
+                            continue
+                        iot_card_list.append(IotCardUsageHistory(
+                            iccid=item['iccid'],
+                            card_type=1,
+                            cycle=cycle['cycle'],
+                            flow_total_usage=cycle['flowTotalUsage'],
+                            created_time=now_time,
+                            updated_time=now_time
+                        ))
+            if not iot_card_list:
+                return None
+            IotCardUsageHistory.objects.bulk_create(iot_card_list)
+        except Exception as e:
+            logger.info('查询账期流量异常,errLine:{}, errMsg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
+            return None