# # Copyright 2024 The InfiniFlow Authors. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # from datetime import datetime import peewee from werkzeug.security import generate_password_hash, check_password_hash from api.db import UserTenantRole from api.db.db_models import DB, UserTenant from api.db.db_models import User, Tenant, MesumAntique from api.db.services.common_service import CommonService from api.utils import get_uuid, get_format_time, current_timestamp, datetime_format from api.db import StatusEnum class MesumAntiqueService(CommonService): model = MesumAntique @classmethod @DB.connection_context() def get_by_mesum_id(cls, mesum_id): objs = cls.query(mesum_id=mesum_id) return objs @classmethod @DB.connection_context() def get_all_categories(cls): # 查询所有唯一的category categories = [category.category for category in cls.model.select(cls.model.category).distinct().execute() if category.category] return categories @classmethod @DB.connection_context() def get_all_labels(cls): # 查询所有去重后的label labels = [label.label for label in cls.model.select(cls.model.label).distinct().execute() if label.label] return labels @classmethod @DB.connection_context() def get_labels_ext(cls, mesum_id): # 根据mesum_id过滤,并排除空的category query = cls.model.select().where( (cls.model.mesum_id == mesum_id) & (cls.model.category != "") ).order_by(cls.model.category) # 按category分组并存储结果 grouped_data = {} for obj in query.dicts().execute(): category = obj['category'] if category not in grouped_data: grouped_data[category] = [] grouped_data[category].append({ 'id': obj['id'], 'label': obj['label'] }) return grouped_data @classmethod @DB.connection_context() def get_antique_by_id(cls, mesum_id,antique_id): query = cls.model.select().where( (cls.model.mesum_id == mesum_id) & (cls.model.id == antique_id) ) data = [] for obj in query.dicts().execute(): data.append(obj) if len(data) > 0: data = data[0] return data