20250904-初步功能已完成

This commit is contained in:
2025-09-12 21:36:47 +08:00
parent f450226d2d
commit aa2f291f49
9 changed files with 284 additions and 64 deletions

View File

@@ -179,17 +179,31 @@ class JsonUtils:
return updated
# @classmethod
# def query_all_json_items(cls, filename="log/last_message.json") -> list:
# """
# 查询 JSON 文件(数组)中的所有项
# :param filename: JSON 文件路径
# :return: list可能为空
# """
# file_path = Path(filename)
# print(file_path)
# data = cls._read_json_list(file_path)
# return data if isinstance(data, list) else []
@classmethod
def query_all_json_items(cls, filename="log/last_message.json") -> list:
"""
查询 JSON 文件(数组)中的所有项
查询 JSON 文件(数组)中的所有项,并剔除 sender 为空的记录
:param filename: JSON 文件路径
:return: list可能为空
"""
file_path = Path(filename)
print(file_path)
data = cls._read_json_list(file_path)
return data if isinstance(data, list) else []
if not isinstance(data, list):
return []
# 过滤 sender 为空字符串的项
return [item for item in data if isinstance(item, dict) and item.get("sender", "").strip()]
@classmethod
def delete_json_items(cls,