From 1c04b32028187d6afcf32c5ed5165843ead9c21c Mon Sep 17 00:00:00 2001
From: zhouping <zhouping@supervision.ltd>
Date: Wed, 26 Jun 2024 15:14:19 +0800
Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=B8=9A=E5=8A=A1=E6=A8=A1?=
 =?UTF-8?q?=E5=9E=8B=E6=97=A0=E6=B3=95=E6=9B=B4=E6=96=B0=E7=9A=84bug?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 website/db/enterprise_busi_model/enterprise_busi_model.py | 7 +++++--
 website/db/enterprise_device/enterprise_device.py         | 2 ++
 website/handlers/alg_model/handler.py                     | 8 +++++++-
 website/handlers/enterprise_busi_model/handler.py         | 2 +-
 website/handlers/enterprise_entity/handler.py             | 3 ++-
 5 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/website/db/enterprise_busi_model/enterprise_busi_model.py b/website/db/enterprise_busi_model/enterprise_busi_model.py
index 5231895..a32bda1 100644
--- a/website/db/enterprise_busi_model/enterprise_busi_model.py
+++ b/website/db/enterprise_busi_model/enterprise_busi_model.py
@@ -127,9 +127,12 @@ class EnterpriseBusiModelRepository(object):
         data['base_models'] = json.dumps(base_model)
         with get_session() as session:
             try:
-                session.query(EnterpriseBusiModel).filter(EnterpriseBusiModel.id == data['id']).update(data)
+                # 过滤不必要的字段
+                valid_columns = {col.name for col in EnterpriseBusiModel.__table__.columns}
+                filtered_data = {key: value for key, value in data.items() if key in valid_columns}
+                session.query(EnterpriseBusiModel).filter(EnterpriseBusiModel.id == data['id']).update(filtered_data)
             except Exception as e:
-                logging.error("Failed to edit device")
+                logging.error("Failed to edit device, error: {}".format(e))
             session.commit()
 
         return
diff --git a/website/db/enterprise_device/enterprise_device.py b/website/db/enterprise_device/enterprise_device.py
index b128322..12823d2 100644
--- a/website/db/enterprise_device/enterprise_device.py
+++ b/website/db/enterprise_device/enterprise_device.py
@@ -113,6 +113,8 @@ class EnterpriseDeviceRepository(object):
         device_id = device["id"]
         with get_session() as session:
             try:
+                # valid_columns = {col.name for col in EnterpriseDevice.__table__.columns}
+                # filtered_data = {key: value for key, value in device.items() if key in valid_columns}
                 session.query(EnterpriseDevice).filter(
                     EnterpriseDevice.id == device_id
                 ).update(device)
diff --git a/website/handlers/alg_model/handler.py b/website/handlers/alg_model/handler.py
index 553d3a7..272bea0 100644
--- a/website/handlers/alg_model/handler.py
+++ b/website/handlers/alg_model/handler.py
@@ -268,7 +268,7 @@ class InfoHandler(APIHandler):
                 text(
                     """
                     select 
-                        m.name, m.model_type, m.comment, m.update_time, 
+                        m.name, m.model_type, m.default_version, m.comment, m.update_time, 
                         mc.id as classification_id, mc.name as classification_name 
                     from model m, model_classification mc 
                     where m.id=:id and m.classification=mc.id
@@ -284,6 +284,7 @@ class InfoHandler(APIHandler):
         data = {
             "name": result["name"],
             "model_type": result["model_type"],
+            "default_version": result["default_version"],
             "classification_id": result["classification_id"],
             "classification_name": result["classification_name"],
             "comment": result["comment"],
@@ -621,6 +622,11 @@ class VersionSetDefaultHandler(APIHandler):
                 text("update model_version set is_default=1 where id=:id"),
                 {"id": version_id},
             )
+            conn.execute(
+                text("update model m set m.default_version=(select version from model_version v where v.id=:vid) "
+                     "where m.id=:mid"),
+                {"vid": version_id, "mid": model_id}
+            )
             conn.commit()
 
         self.finish()
diff --git a/website/handlers/enterprise_busi_model/handler.py b/website/handlers/enterprise_busi_model/handler.py
index d39b0d0..cca761a 100644
--- a/website/handlers/enterprise_busi_model/handler.py
+++ b/website/handlers/enterprise_busi_model/handler.py
@@ -190,7 +190,7 @@ class EditHandler(APIHandler):
     """
     @authenticated
     def post(self):
-        busimodel_id = self.get_argument("id")
+        busimodel_id = self.get_int_argument("id")
     
         if not busimodel_id:
             raise errors.HTTPAPIError(errors.ERROR_BAD_REQUEST, "参数错误")
diff --git a/website/handlers/enterprise_entity/handler.py b/website/handlers/enterprise_entity/handler.py
index 9a41d40..3f626d1 100644
--- a/website/handlers/enterprise_entity/handler.py
+++ b/website/handlers/enterprise_entity/handler.py
@@ -293,7 +293,8 @@ class EntityInfoHandler(APIHandler):
             "province": row["province"],
             "city": row["city"],
             "addr": row["addr"],
-            "industry": row["industry"],
+            "industry": consts.industry_map[row["industry"]],
+            "expire_at": "",
             "contact": row["contact"],
             "phone": row["phone"],
             "summary": row["summary"],