Эх сурвалжийг харах

完善创建场景,更新智能按钮紧急开关状态接口;备案前端页面

locky 3 жил өмнө
parent
commit
3c95481568

+ 231 - 2
Controller/LogManager.py

@@ -1,3 +1,5 @@
+from django.http import HttpResponse
+
 from Controller import OTAEquipment
 from django.views.decorators.csrf import csrf_exempt
 from django.views.generic import TemplateView
@@ -219,6 +221,233 @@ def upload_help_chm(request):
         return response.json(309)
 
 @csrf_exempt
-def errorPath(request,**kwargs):
+def errorPath(request, **kwargs):
+    html = """
+    <!DOCTYPE html>
+<html lang="en">
+
+<head>
+    <meta charset="UTF-8">
+    <meta http-equiv="X-UA-Compatible" content="IE=edge">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title>Document</title>
+    <link rel="stylesheet" href="index.css" </head>
+
+    <body>
+        <div class="header con">
+            <div class="photo"></div>
+            <div class="headerlist">
+                <ul>
+                    <li><a class="active">帮助中心</a></li>
+                    <li><a>售后服务</a></li>
+                </ul>
+                <div class="serch">
+                    <input type="text" placeholder="搜索">
+                </div>
+            </div>
+        </div>
+        <div class="nav">
+            <ul class="con">
+                <li>首页</li>
+                <li>产品类目</li>
+                <li>热卖商品</li>
+                <li>帮助中心</li>
+                <li>资讯</li>
+                <li>关于我们</li>
+            </ul>
+        </div>
+        <div class="banner"
+        ></div>
+        <div class="list con">
+            <div class="item">
+                <img src="http://proff01a9a1.pic12.ysjianzhan.cn/upload/3.jpg">
+                <p>无线基站套装</p>
+            </div>
+            <div class="item">
+                <img src="http://proff01a9a1.pic12.ysjianzhan.cn/upload/1-1-C1.jpg">
+                <p>C1</p>
+            </div>
+            <div class="item">
+                <img src="http://proff01a9a1.pic12.ysjianzhan.cn/upload/1-1-306.jpg">
+                <p>C306</p>
+            </div>
+        </div>
+        <div class="footer">
+            <div class="con">
+                <ul>
+                    <li>网站导航</li>
+                    <li>物流配送</li>
+                    <li>售后服务</li>
+                    <li>配送服务</li>
+                    <li>退换货政策</li>
+                    <li>联系我们</li>
+                    <li>隐私政策</li>
+                    <li>服务协议</li>
+                </ul>
+            </div>
+        </div>
+    </body>
+
+</html>
+
+<style>
+    * {
+    padding: 0;
+    margin: 0;
+}
+
+ul {
+    list-style: none;
+}
+
+.con {
+    width: 966px;
+    margin: 0 auto;
+}
+
+.header {
+    height: 110px;
+}
+
+.photo {
+    width: 165px;
+    height: 110px;
+    background: url(../图片/logo.png);
+    float: left;
+    background-position: center;
+    background-size: 100% 100%;
+}
+
+.headerlist {
+    float: right;
+}
+
+.headerlist ul {
+    height: 44px;
+    margin-top: 10px;
+    line-height: 44px;
+}
+
+.headerlist li {
+    float: left;
+}
+
+.headerlist a {
+    border-right: 1px solid #b2c7ea;
+    padding-left: 13px;
+    padding-right: 13px;
+    font-size: 13px;
+    color: indigo;
+}
+
+.headerlist .last {
+    border: 0;
+    padding-right: 0;
+}
+
+.headerlist li .active {
+    color: pink;
+}
+
+.serch {
+    float: right;
+    width: 234px;
+    height: 28px;
+    border: 1px solid indigo;
+}
+
+.serch input {
+    border: 0;
+    outline: none;
+    width: 210px;
+    float: left;
+    height: 28px;
+    padding-left: 14px;
+}
+
+.nav {
+    height: 53px;
+    line-height: 53px;
+    border-top: 1px solid #edf4fc;
+    background-color: #274964;
+    color: aliceblue;
+}
+
+.nav li {
+    float: left;
+    font-size: 16px;
+    padding-right: 76px;
+}
+
+.banner {
+    height: 380px;
+    background: url('http://proff01a9a1.pic12.ysjianzhan.cn/upload/i0ja.jpg') no-repeat center;
+    background-size: cover;
+}
+
+.list {
+    height: 213px;
+    margin-top: 11px;
+    margin-bottom: 125px;
+}
+
+.item {
+    height: 222px;
+    width: 230px;
+    border: 1px solid #cccccc;
+    float: left;
+    margin-right: 12px;
+}
+
+.item img {
+    width: 230px;
+    height: 222px;
+    display: block;
+}
+
+.item p {
+    height: 47px;
+    padding-left: 28px;
+    line-height: 47px;
+    color: #274964;
+}
+
+.footer {
+    height: 206px;
+    border-top: 1px solid cornsilk;
+    background-color: #cccccc;
+}
+
+.footer ul {
+    height: 84px;
+    padding-top: 30px;
+    padding-bottom: 30px;
+    line-height: 28px;
+    border-bottom: 1px solid gray;
+}
+
+.footer ul li {
+    width: 210px;
+    padding-left: 30px;
+    font-size: 12px;
+    float: left;
+    color: indigo;
+}
+
+.footer p {
+    height: 61px;
+    line-height: 61px;
+    padding-left: 30px;
+    font-size: 12px;
+}
+
+.footer p span {
+    color: indigo;
+}
+</style>
+    """
+
+    if os.environ.get('DJANGO_SETTINGS_MODULE') == 'Ansjer.cn_config.formal_settings':
+        return HttpResponse(html)
     response = ResponseObject()
-    return response.json(414)
+    return response.json(414)

+ 4 - 2
Controller/SensorGateway/SmartSceneController.py

@@ -215,7 +215,9 @@ class SmartSceneView(View):
                 'created_time': now_time,
                 'updated_time': now_time,
             }
-            msg = {}
+            msg = {
+                'scene_status': 1
+            }
             # 处理设置时间
             if is_all_day is not None:
                 is_all_day = int(is_all_day)
@@ -249,7 +251,7 @@ class SmartSceneView(View):
                 if not sub_device_qs.exists():
                     return response.json(173)
                 serial_number = sub_device_qs[0]['device__serial_number']
-                msg['scene_status'] = 1
+
                 msg['sensor_type'] = int(conditions_dict['sensor']['device_type'])
                 msg['sensor_src'] = int(sub_device_qs[0]['src_addr'], 16)
                 msg['sensor_status'] = int(conditions_dict['sensor']['eventValues'][0]['event_type'])

+ 25 - 31
Controller/SensorGateway/SubDeviceController.py

@@ -443,38 +443,32 @@ class GatewaySubDeviceView(View):
             return response.json(444, {'error param': 'gatewaySubId or emergency_status'})
 
         try:
-            with transaction.atomic():
-                # 更新智能按钮开关状态
-                sub_device_qs = GatewaySubDevice.objects.filter(id=sub_device_id)
-                if not sub_device_qs.exists():
-                    response.json(173)
-                sub_device_qs.update(status=emergency_status)
-
-                # 更新智能按钮场景状态
-                if emergency_status == '0':
-                    smart_scene_status = 0
-                else:
-                    smart_scene_status = 1
-                smart_scene_qs = SmartScene.objects.filter(sub_device_id=sub_device_id)
-                if not smart_scene_qs:
-                    return response.json(173)
-                smart_scene_qs.update(is_enable=smart_scene_status)
-
-            # 通过mqtt发送设备数据
-            sub_device_qs = sub_device_qs.values('device__serial_number')
+            emergency_status = int(emergency_status)
+            sub_device_qs = GatewaySubDevice.objects.filter(id=sub_device_id)
             if not sub_device_qs.exists():
-                return response.json(173)
-            serial_number = sub_device_qs[0]['device__serial_number']
-            thing_name = serial_number
-            topic_name = 'loocam/gateway_sensor/smart_scene/{}'.format(serial_number)
-            for item in smart_scene_qs:
-                msg = {
-                    'scene_id': item.id,
-                    'scene_status': item.is_enable
-                }
-
-                success = CommonService.req_publish_mqtt_msg(thing_name, topic_name, msg)
-                time.sleep(0.3)
+                response.json(173)
+            with transaction.atomic():
+                # 更新智能按钮紧急开关状态
+                sub_device_qs.update(is_tampered=emergency_status)
+
+                # 如果打开紧急开关,关闭已开启的场景
+                if emergency_status == 1:
+                    smart_scene_qs = SmartScene.objects.filter(sub_device_id=sub_device_id, is_enable=True)
+                    if not smart_scene_qs.exists():
+                        return response.json(0)
+
+                    # 通过mqtt发送设备数据
+                    sub_device_qs = sub_device_qs.values('device__serial_number')
+                    serial_number = sub_device_qs[0]['device__serial_number']
+                    topic_name = 'loocam/gateway_sensor/smart_scene/{}'.format(serial_number)
+                    for smart_scene in smart_scene_qs:
+                        msg = {
+                            'scene_id': smart_scene.id,
+                            'scene_status': 0
+                        }
+                        CommonService.req_publish_mqtt_msg(serial_number, topic_name, msg)
+                        time.sleep(0.3)
+                    smart_scene_qs.update(is_enable=False)
 
             return response.json(0)
         except Exception as e: