From ab36c10046192d20fd5646a6400b933e9e71ed38 Mon Sep 17 00:00:00 2001
From: zhouping <zhouping@supervision.ltd>
Date: Fri, 19 Jul 2024 10:55:44 +0800
Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dbug?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 website/handlers/enterprise_entity/handler.py | 48 ++++++++++---------
 1 file changed, 25 insertions(+), 23 deletions(-)

diff --git a/website/handlers/enterprise_entity/handler.py b/website/handlers/enterprise_entity/handler.py
index f171c77..fc64e1f 100644
--- a/website/handlers/enterprise_entity/handler.py
+++ b/website/handlers/enterprise_entity/handler.py
@@ -105,7 +105,7 @@ class EntityIndexHandler(APIHandler):
                 "industry": consts.industry_map[item["industry"]],
                 "modelCount": model_count,
                 "deviceCount": device_count,
-                "logo": item["logo"],
+                "logo": str(item["logo"]),
                 "createTime": str(item["create_time"]),
             }
             for item, model_count, device_count in zip(
@@ -303,7 +303,7 @@ class EntityInfoHandler(APIHandler):
             "contact": row["contact"],
             "phone": row["phone"],
             "summary": row["summary"],
-            "logo": row["logo"],
+            "logo": str(row["logo"]),
             "createTime": str(row["create_time"]),
             "account": row["account"],  # 企业账号
         }
@@ -321,37 +321,39 @@ class ModelsHandler(APIHandler):
 
         model_ids = []
         with self.app_mysql.connect() as conn:
-            cur = conn.execute(
+            cur_modelid = conn.execute(
                 text("select base_models from enterprise_busi_model where entity_id=:eid"), {"eid": eid}
             )
-            rows = db_mysql.to_json_list(cur)
+            rows = db_mysql.to_json_list(cur_modelid)
 
             for row in rows:
                 base_models = json.loads(row["base_models"])
                 model_ids.extend([item["id"] for item in base_models])
-            cur.close()
+            cur_modelid.close()
 
             model_ids = list(set(model_ids))
 
-            cur = conn.execute(text(
-                """
-                select m.name, m.model_type, mc.name as classification_name, m.default_version 
-                from model m, model_classification mc 
-                where m.classification=mc.id and m.id in :model_ids
-                """
-            ), {"model_ids": model_ids})
-
-            rows = db_mysql.to_json_list(cur)
-            cur.close()
-
             data = []
-            for row in rows:
-                data.append({
-                    "name": row["name"],
-                    "model_type": consts.model_type_map[row["model_type"]],
-                    "classification_name": row["classification_name"],
-                    "default_version": row["default_version"]
-                })
+
+            if len(model_ids) > 0:
+                cur = conn.execute(text(
+                    """
+                    select m.name, m.model_type, mc.name as classification_name, m.default_version 
+                    from model m, model_classification mc 
+                    where m.classification=mc.id and m.id in :model_ids
+                    """
+                ), {"model_ids": model_ids})
+
+                rows = db_mysql.to_json_list(cur)
+                cur.close()
+
+                for row in rows:
+                    data.append({
+                        "name": row["name"],
+                        "model_type": consts.model_type_map[row["model_type"]],
+                        "classification_name": row["classification_name"],
+                        "default_version": row["default_version"]
+                    })
 
             self.finish({"count": len(model_ids), "data": data})