Browse Source

更新过期套餐下发停用AI指令

locky 2 months ago
parent
commit
a2770f7f74
1 changed files with 19 additions and 0 deletions
  1. 19 0
      Controller/Cron/CronTaskController.py

+ 19 - 0
Controller/Cron/CronTaskController.py

@@ -527,7 +527,26 @@ class CronUpdateDataView(View):
         expired_uid_bucket = UID_Bucket.objects.filter(endTime__lte=now_time)
         expired_uid_bucket = expired_uid_bucket.filter(~Q(use_status=2)).values('id')
         if expired_uid_bucket.exists():
+            # 如果没有未使用套餐,或下个未使用套餐不是AI云存套餐,mqtt下发停用AI指令
+            for bucket in expired_uid_bucket:
+                uid_bucket = UID_Bucket.objects.get(id=bucket['id'])
+                uid = uid_bucket.uid
+                if not uid_bucket.has_unused:
+                    # 存在序列号则为使用序列号作为物品名
+                    thing_name = CommonService.query_serial_with_uid(uid)
+                    topic_name = 'ansjer/generic/{}'.format(thing_name)
+                    msg = {'commandType': 'AIDisable'}
+                    CommonService.req_publish_mqtt_msg(thing_name, topic_name, msg)
+                else:
+                    next_unused = Unused_Uid_Meal.objects.filter(uid=uid).order_by('addTime').first()
+                    if next_unused is None or not getattr(next_unused, 'is_ai', 0):
+                        # 存在序列号则为使用序列号作为物品名
+                        thing_name = CommonService.query_serial_with_uid(uid)
+                        topic_name = 'ansjer/generic/{}'.format(thing_name)
+                        msg = {'commandType': 'AIDisable'}
+                        CommonService.req_publish_mqtt_msg(thing_name, topic_name, msg)
             expired_uid_bucket.update(use_status=2)
+
         # 监控有未使用套餐则自动生效
         expired_uid_buckets = UID_Bucket.objects.filter(endTime__lte=now_time, has_unused=1).values("id", "uid")[0:1000]
         for expired_uid_bucket in expired_uid_buckets: