From 5d2fb7a2868ae56c6d15dbb0bfe20fc9467c9084 Mon Sep 17 00:00:00 2001 From: shenshuo <191715030@qq.com> Date: Mon, 9 Dec 2024 11:05:02 +0800 Subject: [PATCH] =?UTF-8?q?2024=E5=B9=B412=E6=9C=8809=E6=97=A5=20=20?= =?UTF-8?q?=E7=BB=A7=E7=BB=AD=E5=AE=8C=E5=96=84=E5=AE=9A=E5=88=B6=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mg/handlers/sys_index_handler.py | 35 +++++++++++++++++++++++++++++--- models/paas_model.py | 9 ++++++++ services/index_service.py | 18 ++++++++++++---- 3 files changed, 55 insertions(+), 7 deletions(-) diff --git a/mg/handlers/sys_index_handler.py b/mg/handlers/sys_index_handler.py index 95ea7dd..163091a 100644 --- a/mg/handlers/sys_index_handler.py +++ b/mg/handlers/sys_index_handler.py @@ -11,7 +11,7 @@ from abc import ABC from libs.base_handler import BaseHandler from services.index_service import get_step_list, up_step, add_step, del_step, get_service_dict, get_service_list,\ - add_service, up_service, del_service + add_service, up_service, del_service, opt_server_list_obj, get_service_categories class IndexStepHandler(BaseHandler, ABC): @@ -35,6 +35,27 @@ def delete(self, *args, **kwargs): self.write(res) +class ServiceCategoriesHandler(BaseHandler, ABC): + def get(self, *args, **kwargs): + res = get_service_categories() + return self.write(res) + + def post(self, *args, **kwargs): + data = json.loads(self.request.body.decode("utf-8")) + res = opt_server_list_obj.handle_add(data) + self.write(res) + + def put(self, *args, **kwargs): + data = json.loads(self.request.body.decode("utf-8")) + res = opt_server_list_obj.handle_update(data) + self.write(res) + + def delete(self, *args, **kwargs): + data = json.loads(self.request.body.decode("utf-8")) + res = opt_server_list_obj.handle_delete(data) + self.write(res) + + class IndexServiceHandler(BaseHandler, ABC): def get(self, *args, **kwargs): res = get_service_list() @@ -62,6 +83,12 @@ def get(self, *args, **kwargs): return self.write(res) +class ServiceCategories(BaseHandler, ABC): + def get(self, *args, **kwargs): + res = get_service_categories() + return self.write(res) + + class IndexService(BaseHandler, ABC): def get(self, *args, **kwargs): res = get_service_dict() @@ -70,9 +97,11 @@ def get(self, *args, **kwargs): index_step_urls = [ (r"/v4/ops-step-service/", IndexStepHandler, {"handle_name": "PAAS-基础功能-首页步骤管理", "method": ["ALL"]}), + (r"/v4/ops-service-categories/", ServiceCategoriesHandler, {"handle_name": "PAAS-基础功能-首页服务列表", "method": ["ALL"]}), (r"/v4/ops-index-service/", IndexServiceHandler, {"handle_name": "PAAS-基础功能-首页服务管理", "method": ["ALL"]}), - (r"/v4/na/index-step/", IndexStep, {"handle_name": "PAAS-基础功能-首页步骤", "method": ["GET"]}), - (r"/v4/na/index-service/", IndexService, {"handle_name": "PAAS-基础功能-首页服务", "method": ["GET"]}) + (r"/v4/na/index-step/", IndexStep, {"handle_name": "PAAS-基础功能-首页步骤", "method": ["GET"]}), # 免认证 + (r"/v4/na/index-service-categories/", ServiceCategories, {"handle_name": "PAAS-基础功能-首页服务定制表", "method": ["GET"]}), + (r"/v4/na/index-service/", IndexService, {"handle_name": "PAAS-基础功能-首页服务", "method": ["GET"]}) # 免认证 ] if __name__ == "__main__": diff --git a/models/paas_model.py b/models/paas_model.py index 30a0cc0..f03bdd9 100644 --- a/models/paas_model.py +++ b/models/paas_model.py @@ -160,6 +160,15 @@ class IndexStepModel(TimeBaseModel, Base): faqs = Column(JSON, nullable=True) # FAQ 列表,存储为 JSON +class ServiceCategoriesModel(TimeBaseModel, Base): + __tablename__ = 'codo_index_service_list' + + id = Column(Integer, primary_key=True, autoincrement=True) + name = Column(String(100), nullable=False, index=True) # 分类名称 + img = Column(String(100), nullable=False) # 图标名称对应前端保存的图片 + description = Column(String(255), nullable=True) # 描述 + + class IndexServiceModel(TimeBaseModel, Base): __tablename__ = 'codo_index_service' diff --git a/services/index_service.py b/services/index_service.py index a7b8626..8048f3b 100644 --- a/services/index_service.py +++ b/services/index_service.py @@ -12,14 +12,15 @@ from sqlalchemy import or_ from websdk2.sqlalchemy_pagination import paginate from websdk2.db_context import DBContextV2 as DBContext -from websdk2.model_utils import queryset_to_list - +from websdk2.model_utils import queryset_to_list, CommonOptView from libs.feature_pydantic_utils import sqlalchemy_to_pydantic, ValidationError, PydanticDel -from models.paas_model import IndexStepModel, IndexServiceModel +from models.paas_model import IndexStepModel, ServiceCategoriesModel, IndexServiceModel PydanticFavorites = sqlalchemy_to_pydantic(IndexStepModel, exclude=['id']) # 排除自增ID PydanticFavoritesUP = sqlalchemy_to_pydantic(IndexStepModel) +opt_server_list_obj = CommonOptView(ServiceCategoriesModel) + def get_step_list() -> dict: with DBContext('r') as session: @@ -140,7 +141,7 @@ def get_service_list(**params) -> dict: # 分页查询 page = paginate(query, **params) - return dict(code=0, msg="创建成功", data=page.items, count=page.total) + return dict(code=0, msg="查询成功", data=page.items, count=page.total) def add_service(data: dict): @@ -183,3 +184,12 @@ def del_service(data: dict) -> dict: return dict(code=-3, msg=f'删除失败, {str(err)}') return dict(code=0, msg="删除成功") + + +def get_service_categories(**params) -> dict: + params.setdefault('page_size', 300) + with DBContext('r') as session: + query = session.query(ServiceCategoriesModel) + # 分页查询 + page = paginate(query, **params) + return dict(code=0, msg="查询成功", data=page.items, count=page.total)