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)