Browse Source

is_all_day字段从场景执行时间表移到智能场景表

peng 3 years ago
parent
commit
7dfdd15307
1 changed files with 25 additions and 22 deletions
  1. 25 22
      Controller/SensorGateway/SmartSceneController.py

+ 25 - 22
Controller/SensorGateway/SmartSceneController.py

@@ -233,31 +233,34 @@ class SmartSceneView(View):
 
             with transaction.atomic():
                 if not is_all_day or is_all_day == 1:  # 不设置时间或全天
+                    if is_all_day == 1:
+                        smart_scene_dict['is_all_day'] = is_all_day
                     smart_scene_qs = SmartScene.objects.create(**smart_scene_dict)
                 elif is_all_day == 2:
-                    if is_all_day == '0':
-                        effective_time_qs = EffectiveTime.objects.filter(is_all_day=True).values('id')
-                        if effective_time_qs.exists():
-                            effective_time_id = effective_time_qs[0]['id']
-                        else:
-                            effective_time_id = EffectiveTime.objects.create(is_all_day=True).id
-                        smart_scene_dict['effective_time_id'] = effective_time_id
-                        smart_scene_qs = SmartScene.objects.create(**smart_scene_dict)
+                    # if is_all_day == '0':
+                    #     effective_time_qs = EffectiveTime.objects.filter(is_all_day=True).values('id')
+                    #     if effective_time_qs.exists():
+                    #         effective_time_id = effective_time_qs[0]['id']
+                    #     else:
+                    #         effective_time_id = EffectiveTime.objects.create(is_all_day=True).id
+                    #     smart_scene_dict['effective_time_id'] = effective_time_id
+                    #     smart_scene_qs = SmartScene.objects.create(**smart_scene_dict)
+                    # else:
+                    start_time = int(request_dict.get('startTime', None))
+                    end_time = int(request_dict.get('endTime', None))
+                    repeat = int(request_dict.get('repeat', None))
+                    if not all([start_time, end_time, repeat]):
+                        return response.json(444, {'error param': 'startTime and endTime and repeat'})
+                    effective_time_qs = EffectiveTime.objects.filter(start_time=start_time, end_time=end_time,
+                                                                     repeat=repeat).values('id')
+                    if effective_time_qs.exists():
+                        effective_time_id = effective_time_qs[0]['id']
                     else:
-                        start_time = int(request_dict.get('startTime', None))
-                        end_time = int(request_dict.get('endTime', None))
-                        repeat = int(request_dict.get('repeat', None))
-                        if not all([start_time, end_time, repeat]):
-                            return response.json(444, {'error param': 'startTime and endTime and repeat'})
-                        effective_time_qs = EffectiveTime.objects.filter(start_time=start_time, end_time=end_time,
-                                                                         repeat=repeat).values('id')
-                        if effective_time_qs.exists():
-                            effective_time_id = effective_time_qs[0]['id']
-                        else:
-                            effective_time_id = EffectiveTime.objects.create(start_time=start_time, end_time=end_time,
-                                                                             repeat=repeat).id
-                        smart_scene_dict['effective_time_id'] = effective_time_id
-                        smart_scene_qs = SmartScene.objects.create(**smart_scene_dict)
+                        effective_time_id = EffectiveTime.objects.create(start_time=start_time, end_time=end_time,
+                                                                         repeat=repeat).id
+                    smart_scene_dict['effective_time_id'] = effective_time_id
+                    smart_scene_dict['is_all_day'] = is_all_day
+                    smart_scene_qs = SmartScene.objects.create(**smart_scene_dict)
                 else:
                     return response.json(444, {'error param': 'invalid isAllDay'})