小程序在9月27日发布了正式版

This commit is contained in:
qcloud
2025-10-01 08:29:09 +08:00
parent 8d90798647
commit c44e6715a0
15 changed files with 6679 additions and 25074 deletions

View File

@@ -991,6 +991,7 @@ class CanvasTemplate(DataBaseModel):
# ------------added by cyx for mesum overview
class MesumOverview(DataBaseModel):
id = BigIntegerField(primary_key=True,null=False) # 非自增主键
name = CharField(
max_length=128,
null=False,
@@ -1043,6 +1044,14 @@ class MesumOverview(DataBaseModel):
free = IntegerField(default=0, index=False)
hotspot_rank = IntegerField(default=50, index=False)
functions = CharField(
max_length=300,
null=False,
help_text="此场所软件开放的功能",
index=False)
sort_order = IntegerField(default=0, null=False) #
def __str__(self):
return self.name
@@ -1063,7 +1072,9 @@ class MesumAntique(DataBaseModel):
ttsUrl_child = CharField(max_length=256, null=True)
photo_url = CharField(max_length=256, null=True)
orgin_text = TextField(null=True)
tags = CharField(max_length=200, null=True)
sort_order = IntegerField(default=0) # 添加sort_order字段
class Meta:
db_table = 'mesum_antique'

View File

@@ -25,7 +25,7 @@ from api.db.services.common_service import CommonService
from api.db.services.brief_service import MesumOverviewService
from api.utils import get_uuid, get_format_time, current_timestamp, datetime_format
from api.db import StatusEnum
import logging
import logging,json
class MesumAntiqueService(CommonService):
model = MesumAntique
@@ -33,8 +33,25 @@ class MesumAntiqueService(CommonService):
@classmethod
@DB.connection_context()
def get_by_mesum_id(cls, mesum_id):
objs = cls.query(mesum_id=mesum_id)
return objs
# objs = cls.query(mesum_id=mesum_id)
# return objs
"""
根据mesum_id查询记录并按category和sort_order排序
"""
try:
objs = (cls.model
.select()
.where(cls.model.mesum_id == mesum_id)
.order_by(
cls.model.category, # 一级排序按category
cls.model.sort_order.asc() # 二级排序sort_order升序
)
.execute())
return list(objs)
except Exception as e:
print(f"根据mesum_id查询失败: {e}")
return []
@classmethod
@DB.connection_context()
@@ -44,6 +61,15 @@ class MesumAntiqueService(CommonService):
try:
mesum_brief = MesumOverviewService.query(id=mesum_id)
if mesum_brief:
"""
20250922 数据库中category 改为如下形式
[{"name":"第一展厅(新石器-唐、战国、秦汉)","audio":"xxxx","photo":"xxx"},
{"name":"第二展厅 (辽金)","audio":"xxx","photo":""},
{"name":"第三展厅(元)","audio":"xxx","photo":""},
{"name":"第四展厅(明清-至今)","audio":"xxx","photo":""}]
"""
"""
categories_text= mesum_brief[0].category
# 统一替换中文分号为英文分号,并去除末尾分号
if categories_text:
@@ -51,6 +77,9 @@ class MesumAntiqueService(CommonService):
# 分割并清理空格/空值
mesum_antique_categories = [dynasty.strip() for dynasty in categories_text.split(";") if dynasty.strip()]
"""
mesum_category_json = json.loads(mesum_brief[0].category.strip())
mesum_antique_categories = [item["name"] for item in mesum_category_json]
finally:
pass
categories = [category.category
@@ -82,13 +111,61 @@ class MesumAntiqueService(CommonService):
@classmethod
@DB.connection_context()
def get_labels_ext(cls, mesum_id):
def get_labels_ext(cls, mesum_id,tags = None):
# 根据mesum_id过滤并排除空的category
query = cls.model.select().where(
"""query = cls.model.select().where(
(cls.model.mesum_id == mesum_id) &
(cls.model.category != "")
).order_by(cls.model.category)
).order_by(
cls.model.category, # 一级排序按category
cls.model.sort_order.asc() # 二级排序sort_order升序
)
"""
# 基础查询条件
conditions = [
(cls.model.mesum_id == mesum_id),
(cls.model.category != ""),
(cls.model.category.is_null(False)) # 确保category不为NULL
]
# 添加tags条件
if tags is not None:
# 如果tags是字符串按逗号分割处理
if isinstance(tags, str):
tags_list = [tag.strip() for tag in tags.split(',') if tag.strip()]
elif isinstance(tags, list):
tags_list = tags
else:
tags_list = []
if tags_list:
# 构建tags匹配条件tags包含任意一个指定的标签
tag_conditions = []
for tag in tags_list:
# 匹配tags字段包含该标签考虑逗号分隔的情况
tag_conditions.append(
(cls.model.tags.contains(tag)) |
(cls.model.tags.startswith(f"{tag},")) |
(cls.model.tags.endswith(f",{tag}")) |
(cls.model.tags == tag)
)
# 将所有tag条件用OR连接
tags_condition = reduce(lambda a, b: a | b, tag_conditions)
conditions.append(tags_condition)
else:
# 如果tags为空但传入了参数确保tags不为空
conditions.append(
(cls.model.tags != "") &
(cls.model.tags.is_null(False))
)
else:
# 如果未传入tags参数包含所有tags记录包括空值
pass
# 执行查询,添加二级排序
query = cls.model.select().where(*conditions).order_by(
cls.model.category, # 一级排序按category
cls.model.sort_order.asc() # 二级排序按sort_order升序
)
# 按category分组并存储结果
grouped_data = {}
for obj in query.dicts().execute():

View File

@@ -14,7 +14,7 @@
# limitations under the License.
#
from datetime import datetime
import logging
import peewee
from api.db.db_models import DB
@@ -38,7 +38,7 @@ class CommonService:
else:
query_records = cls.model.select()
if reverse is not None:
if not order_by or not hasattr(cls, order_by):
if not order_by or not hasattr(cls.model, order_by): # 20250923 这里之前使用cls 而没有model是错误的
order_by = "create_time"
if reverse is True:
query_records = query_records.order_by(