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

Merge branch 'dev' of ssh://192.168.136.45:10022/SERVER/AnsjerServer into dev

chenjunkai 5 éve
szülő
commit
48a30bef30
2 módosított fájl, 44 hozzáadás és 16 törlés
  1. 33 8
      Controller/EquipmentOTA.py
  2. 11 8
      Controller/UserBrandController.py

+ 33 - 8
Controller/EquipmentOTA.py

@@ -152,14 +152,14 @@ class EquipmentVersionView(View):
     def get(self, request, *args, **kwargs):
         request.encoding = 'utf-8'
         operation = kwargs.get('operation')
-        return self.validation(request.GET, operation)
+        return self.validation(request.GET, operation,request)
 
     def post(self, request, *args, **kwargs):
         request.encoding = 'utf-8'
         operation = kwargs.get('operation')
-        return self.validation(request.POST, operation)
+        return self.validation(request.POST, operation,request)
 
-    def validation(self, request_dict, operation):
+    def validation(self, request_dict, operation, request):
         response = ResponseObject()
         if operation is None:
             return response.json(444, 'error path')
@@ -180,26 +180,51 @@ class EquipmentVersionView(View):
         if operation == 'query':
             return self.do_query(request_dict, response)
         if operation == 'update':
-            return self.do_update(request_dict, response)
+            return self.do_update(request_dict, response,request)
         if operation == 'filter':
             return self.do_filter(request_dict, response)
         else:
             return response.json(444, 'error path')
 
-    def do_update(self, request_dict, response):
+    def do_update(self, request_dict, response,request):
         code = request_dict.get('code', None)
         status = request_dict.get('status', None)
         lang = request_dict.get('lang', None)
+
+        file_s = request.FILES.get('file', None)
+        paths = 'static/versions/image'
+        if not os.path.exists(paths):
+            os.makedirs(paths)  # makedirs 创建文件时如果路径不存在会创建这个路径
+            # print ('该文件不存在')
+        else:
+            print ('该文件存在')
+        ev = Equipment_Version.objects.filter(code=code, lang=lang)
+        if file_s is None:
+             rv_path = 'static/versions/image/' + code + '.png'
+             img = SERVER_DOMAIN + 'sysfile/' + rv_path
+        else:
+            rv_path = 'static/versions/image/' + code + '.png'
+            try:
+                as_path = os.path.join(BASE_DIR, rv_path)
+                if os.path.exists(as_path):
+                    os.remove(as_path)
+                with open(as_path, 'wb+') as destination:
+                    for chunk in file_s.chunks():
+                        destination.write(chunk)
+            except Exception as e:
+                pass
+            else:
+                img= SERVER_DOMAIN + 'sysfile/' + rv_path
         if code is not None:
-            ev = Equipment_Version.objects.filter(code=code, lang=lang)
+
             if ev.exists():
                 try:
                     update_time = timezone.localtime(timezone.now())
-                    ev.update(status=status, update_time=update_time)
+                    ev.update(status=status,img=img, update_time=update_time)
                 except Exception as e:
                     return response.json(404, repr(e))
                 else:
-                    return response.json(0, {'update_time': str(update_time)})
+                    return response.json(0, {'update_time': str(update_time),'img':img})
             else:
                 return response.json(173)
         else:

+ 11 - 8
Controller/UserBrandController.py

@@ -660,18 +660,23 @@ class UserBrandInfo(View):
 
     # Query each user record statistics
     def query_all_info(self, request_dict, userID, user_brand, user_brand_all, response):
+
         page = int(request_dict.get('page', None))
         line = int(request_dict.get('line', None))
         username = request_dict.get('username', None)
         param_flag = CommonService.get_param_flag(data=[page, line])
 
         # 增加用户扩展信息
-        redisObj = RedisObject()
-        logKey = USER_BRAND_ALL
-        data_list = redisObj.lrange(logKey, 0, -1)
-        redisObj.del_data(key=logKey)
-        # 添加user_brand_all表信息
-        my.user_brand_all_item_put(user_brand_all, data_list)
+
+        try:
+            redisObj = RedisObject()
+            logKey = USER_BRAND_ALL
+            data_list = redisObj.lrange(logKey, 0, -1)
+            redisObj.del_data(key=logKey)
+            # 添加user_brand_all表信息
+            my.user_brand_all_item_put(user_brand_all, data_list)
+        except Exception:
+            print ('有误')
         print ('添加了数据')
         if param_flag is True:
             check_perm = ModelService.check_perm(userID=userID, permID=30)
@@ -705,9 +710,7 @@ class UserBrandInfo(View):
                 send_jsons.append(table_value[counts]['deviceSupplier'])
                 counts = counts + 1
             send_jsons = Counter(send_jsons)
-
             return response.json(0, {'datas': send_jsons, 'counts': counts})
-
         else:
             return response.json(404)