liqian 3 năm trước cách đây
mục cha
commit
8f107380b6
1 tập tin đã thay đổi với 10 bổ sung10 xóa
  1. 10 10
      utils.py

+ 10 - 10
utils.py

@@ -180,23 +180,23 @@ def update_video_w_h_rate(video_ids, key_name):
     """
     # 获取数据
     if len(video_ids) == 1:
-        sql = "SELECT id, width/height w_h_rate " \
-              "FROM longvideo.wx_video " \
-              "WHERE width/height > 1 " \
-              "AND id IN ({});".format(video_ids[0])
+        sql = "SELECT id, width, height, rotate FROM longvideo.wx_video WHERE id = {};".format(video_ids[0])
     else:
-        sql = "SELECT id, width/height w_h_rate " \
-              "FROM longvideo.wx_video " \
-              "WHERE width/height > 1 " \
-              "AND id IN {};".format(tuple(video_ids))
+        sql = "SELECT id, width, height, rotate FROM longvideo.wx_video WHERE id IN {};".format(tuple(video_ids))
 
     mysql_helper = MysqlHelper()
     data = mysql_helper.get_data(sql=sql)
 
     # 更新到redis
     info_data = {}
-    for video_id, w_h_rate in data:
-        info_data[int(video_id)] = float(w_h_rate)
+    for video_id, width, height, rotate in data:
+        # rotate 字段值为 90或270时,width和height的值相反
+        if rotate in (90, 270):
+            w_h_rate = height / width
+        else:
+            w_h_rate = width / height
+        if w_h_rate > 1:
+            info_data[int(video_id)] = float(w_h_rate)
     redis_helper = RedisHelper()
     # 删除旧数据
     redis_helper.del_keys(key_name=key_name)