init
This commit is contained in:
373
chat_session.py
373
chat_session.py
@@ -3,7 +3,12 @@ import json
|
||||
import os.path
|
||||
import sqlite3
|
||||
from typing import List, Tuple
|
||||
import logging
|
||||
import os
|
||||
|
||||
import requests
|
||||
from requests.adapters import HTTPAdapter
|
||||
from urllib3.util.retry import Retry
|
||||
import pytz
|
||||
|
||||
from file import ObjectFileManager, LocalFileManager
|
||||
@@ -27,6 +32,133 @@ def convert_to_utc(time_str, time_format='%Y-%m-%d %H:%M:%S', source_timezone=No
|
||||
return utc_dt
|
||||
|
||||
|
||||
class AIAgent:
|
||||
"""AI代理类,整合了各种AI功能"""
|
||||
|
||||
def __init__(self, deepseek_api_key: str = "sk-c2f04b4d635b4df0aace0432f3c6d6f4",
|
||||
max_retries: int = 3, timeout: int = 30):
|
||||
"""初始化AI助手
|
||||
|
||||
Args:
|
||||
deepseek_api_key: DeepSeek API密钥
|
||||
max_retries: 最大重试次数
|
||||
timeout: 请求超时时间(秒)
|
||||
"""
|
||||
self.deepseek_api_key = deepseek_api_key
|
||||
self.timeout = timeout
|
||||
|
||||
# 配置日志
|
||||
self._setup_logging()
|
||||
|
||||
# 创建带重试机制的会话
|
||||
self.session = self._create_session(max_retries)
|
||||
|
||||
# 配置常量
|
||||
self.BASE_REPORT_URL = "https://a.cmdp.cn/basiceg/v1/json/tpldev"
|
||||
self.CACHE_DIR = "cache"
|
||||
|
||||
def _setup_logging(self):
|
||||
"""配置日志"""
|
||||
logging.basicConfig(
|
||||
level=logging.INFO,
|
||||
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
|
||||
)
|
||||
self.logger = logging.getLogger(__name__)
|
||||
|
||||
@staticmethod
|
||||
def _create_session(max_retries: int) -> requests.Session:
|
||||
"""创建带重试机制的会话
|
||||
|
||||
Args:
|
||||
max_retries: 最大重试次数
|
||||
|
||||
Returns:
|
||||
配置好的会话对象
|
||||
"""
|
||||
session = requests.Session()
|
||||
|
||||
# 配置重试策略
|
||||
retry_strategy = Retry(
|
||||
total=max_retries,
|
||||
status_forcelist=[429, 500, 502, 503, 504],
|
||||
backoff_factor=1
|
||||
)
|
||||
|
||||
# 为HTTP和HTTPS适配器添加重试机制
|
||||
adapter = HTTPAdapter(max_retries=retry_strategy)
|
||||
session.mount("http://", adapter)
|
||||
session.mount("https://", adapter)
|
||||
|
||||
return session
|
||||
|
||||
def _make_request(self, method: str, url: str, **kwargs):
|
||||
"""发送HTTP请求(带错误处理)
|
||||
|
||||
Args:
|
||||
method: HTTP方法
|
||||
url: 请求URL
|
||||
**kwargs: 其他请求参数
|
||||
|
||||
Returns:
|
||||
JSON响应或None
|
||||
"""
|
||||
try:
|
||||
# 设置默认超时
|
||||
if 'timeout' not in kwargs:
|
||||
kwargs['timeout'] = self.timeout
|
||||
|
||||
response = self.session.request(method, url, **kwargs)
|
||||
response.raise_for_status()
|
||||
|
||||
self.logger.info(f"请求成功: {url}")
|
||||
return response.json()
|
||||
|
||||
except requests.exceptions.RequestException as e:
|
||||
self.logger.error(f"请求失败: {url} - {str(e)}")
|
||||
return {}
|
||||
except json.JSONDecodeError as e:
|
||||
self.logger.error(f"JSON解析失败: {url} - {str(e)}")
|
||||
return {}
|
||||
|
||||
def chat_deepseek(self, message: str, role: str = "", model: str = "deepseek-chat") -> str:
|
||||
"""与DeepSeek聊天
|
||||
|
||||
Args:
|
||||
message: 用户消息
|
||||
role: 系统角色
|
||||
model: 使用的模型
|
||||
|
||||
Returns:
|
||||
AI回复内容
|
||||
"""
|
||||
url = "https://api.deepseek.com/chat/completions"
|
||||
headers = {
|
||||
"Content-Type": "application/json",
|
||||
"Authorization": f"Bearer {self.deepseek_api_key}"
|
||||
}
|
||||
|
||||
messages = []
|
||||
if role:
|
||||
messages.append({"role": "system", "content": role})
|
||||
messages.append({"role": "user", "content": message})
|
||||
|
||||
body = {
|
||||
"model": model,
|
||||
"messages": messages,
|
||||
"stream": False
|
||||
}
|
||||
|
||||
result = self._make_request("POST", url, json=body, headers=headers)
|
||||
if result and "choices" in result:
|
||||
return result.get('choices', [{}])[0]['message']['content']
|
||||
|
||||
self.logger.warning("DeepSeek API调用失败或返回空结果")
|
||||
return ""
|
||||
|
||||
|
||||
agent = AIAgent(max_retries=1, timeout=180)
|
||||
|
||||
|
||||
class ChatSessionManager:
|
||||
"""聊天会话管理器类"""
|
||||
|
||||
@@ -40,7 +172,7 @@ class ChatSessionManager:
|
||||
self.chat_history_dir = chat_history_dir
|
||||
self.files_dir = os.path.join(chat_history_dir, "files")
|
||||
self.messages_dir = os.path.join(chat_history_dir, "messages")
|
||||
self.db_path = os.path.join("", "data.sqlite")
|
||||
self.db_path = os.path.join("db", "data.sqlite")
|
||||
self.cache_path = None
|
||||
# 初始化文件管理器
|
||||
self.obj = ObjectFileManager()
|
||||
@@ -293,13 +425,6 @@ class ChatSessionManager:
|
||||
def save_all_to_sqlite(self) -> None:
|
||||
"""
|
||||
保存所有聊天数据到SQLite数据库
|
||||
|
||||
Args:
|
||||
users: 用户列表
|
||||
groups: 群组列表
|
||||
members: 成员映射
|
||||
messages: 消息列表
|
||||
files: 文件映射
|
||||
"""
|
||||
# 保存文件信息
|
||||
file_data = []
|
||||
@@ -425,50 +550,106 @@ class ChatSessionManager:
|
||||
res = cursor.fetchall()
|
||||
return res
|
||||
|
||||
def get_history(self, start_time_str: str, end_time_str: str) -> list:
|
||||
@staticmethod
|
||||
def analyze_qa_content(group_messages) -> dict:
|
||||
group_qa = {}
|
||||
for group_id in group_messages:
|
||||
print(f"群ID: {group_id}")
|
||||
print(f"消息数量: {len(group_messages[group_id])}")
|
||||
content = ""
|
||||
if len(group_messages[group_id]) <= 2:
|
||||
continue
|
||||
else:
|
||||
for msg in sorted(group_messages[group_id], key=lambda i: i[1]):
|
||||
content += json.dumps({
|
||||
"user": msg[1],
|
||||
"time": msg[2],
|
||||
"content": msg[3],
|
||||
"message_id": msg[4]
|
||||
}, ensure_ascii=False) + ",\n"
|
||||
|
||||
template = f"""
|
||||
以下是群中的消息记录
|
||||
|
||||
```json
|
||||
[
|
||||
{content}
|
||||
]
|
||||
```
|
||||
""" + """
|
||||
找到其中的问题和回答,如果没有回答就只整理问题,问题是与产品填报系统,上市公司,证券政策相关的问题
|
||||
问题可能不只由一句话构成,回答也可能不只由一句话构成
|
||||
多个问题需要分开放置
|
||||
输出格式
|
||||
|
||||
```json
|
||||
[
|
||||
{
|
||||
"question": ["message_id",...],
|
||||
"answer": ["message_id",...]
|
||||
}
|
||||
]
|
||||
```
|
||||
"""
|
||||
获取指定时间的聊天历史记录
|
||||
answer = agent.chat_deepseek(template)
|
||||
answer = answer.replace("```json", "").replace("```", "") if "```json" in answer else answer
|
||||
try:
|
||||
answer = json.loads(answer)
|
||||
except:
|
||||
print(answer)
|
||||
answer = []
|
||||
group_qa[group_id] = answer
|
||||
return group_qa
|
||||
|
||||
def save_qa_to_sqlite(self, group_qa: dict):
|
||||
"""
|
||||
将问答数据保存到 SQLite 数据库
|
||||
|
||||
Args:
|
||||
group_qa: 问答数据字典,键为群ID,值为问答列表
|
||||
"""
|
||||
data = []
|
||||
cursor = self.conn.cursor()
|
||||
for r in group_qa:
|
||||
qas = group_qa.get(r, {})
|
||||
for qa in qas:
|
||||
Q = qa["question"]
|
||||
A = qa["answer"]
|
||||
data.append((r, json.dumps(Q, ensure_ascii=False), json.dumps(A, ensure_ascii=False)))
|
||||
cursor.executemany('''
|
||||
insert into qa (groupId, question, answer)
|
||||
values (?, ?, ?)
|
||||
''', data)
|
||||
self.conn.commit()
|
||||
|
||||
def update_qa_data(self, start_time_str: str, end_time_str: str):
|
||||
"""
|
||||
更新指定时间范围内的问答内容
|
||||
|
||||
Args:
|
||||
start_time_str: 开始时间,格式为 "YYYY-MM-DD HH:MM:SS"
|
||||
end_time_str: 结束时间,格式为 "YYYY-MM-DD HH:MM:SS"
|
||||
|
||||
Returns:
|
||||
聊天历史记录列表
|
||||
"""
|
||||
start_time = convert_to_utc(start_time_str, source_timezone="Asia/Shanghai").timestamp()
|
||||
end_time = convert_to_utc(end_time_str, source_timezone="Asia/Shanghai").timestamp()
|
||||
cursor = self.conn.cursor()
|
||||
cursor.execute('''
|
||||
SELECT count(1) as count
|
||||
SELECT receiver, sender, time, content, id
|
||||
FROM message
|
||||
WHERE message.time >= ?
|
||||
AND message.time <= ?
|
||||
|
||||
AND toType = 1
|
||||
AND type in ('text', 'mixed', 'chatrecord')
|
||||
''', (str(start_time).replace(".0", "000"), str(end_time).replace(".0", "000")))
|
||||
res = cursor.fetchall()
|
||||
print(f"总消息数量: {res[0][0]}")
|
||||
cursor.execute('''
|
||||
SELECT 1 as count
|
||||
FROM message
|
||||
WHERE message.time >= ?
|
||||
AND message.time <= ?
|
||||
group by message.sender
|
||||
''', (str(start_time).replace(".0", "000"), str(end_time).replace(".0", "000")))
|
||||
res = cursor.fetchall()
|
||||
print(f"发送者数量: {len(res)}")
|
||||
cursor.execute('''
|
||||
SELECT *
|
||||
FROM message
|
||||
|
||||
WHERE message.type in ('text', 'mixed', 'chatrecord')
|
||||
AND message.time >= ?
|
||||
AND message.time <= ?
|
||||
AND message.toType == 1
|
||||
|
||||
''', (str(start_time).replace(".0", "000"), str(end_time).replace(".0", "000")))
|
||||
res = cursor.fetchall()
|
||||
return res
|
||||
data = cursor.fetchall()
|
||||
group_messages = {}
|
||||
for i in data:
|
||||
group_id = i[0]
|
||||
if group_id not in group_messages:
|
||||
group_messages[group_id] = []
|
||||
group_messages[group_id].append(i)
|
||||
group_qa = self.analyze_qa_content(group_messages)
|
||||
self.analyze_qa_content(group_qa)
|
||||
|
||||
def close(self) -> None:
|
||||
"""关闭数据库连接"""
|
||||
@@ -482,116 +663,6 @@ class ChatSessionManager:
|
||||
|
||||
if __name__ == '__main__':
|
||||
chat_session = ChatSessionManager()
|
||||
# for day in range(22, 30+1):
|
||||
# for hour in range(0, 24):
|
||||
# chat_session.process_chat_session(2025, 9, day, hour)
|
||||
# for day in range(1, 29+1):
|
||||
# for hour in range(0, 24):
|
||||
# chat_session.process_chat_session(2025, 10, day, hour)
|
||||
# start = "2025-10-15 00:00:00"
|
||||
# end = "2025-10-30 23:59:59"
|
||||
# data = chat_session.get_history(start, end)
|
||||
# group_messages = {}
|
||||
# for i in data:
|
||||
# group_id = i[-1]
|
||||
# if group_id not in group_messages:
|
||||
# group_messages[group_id] = []
|
||||
# group_messages[group_id].append((i[5], i[2], i[3]))
|
||||
# group_qa = {}
|
||||
# for group_id in group_messages:
|
||||
# print(f"群ID: {group_id}")
|
||||
# print(f"消息数量: {len(group_messages[group_id])}")
|
||||
# content = ""
|
||||
# if len(group_messages[group_id]) < 2:
|
||||
# continue
|
||||
# elif len(group_messages[group_id]) == 2:
|
||||
# print(group_messages[group_id])
|
||||
# else:
|
||||
# for msg in sorted(group_messages[group_id], key=lambda i: i[1]):
|
||||
# content += json.dumps({
|
||||
# "user": msg[0],
|
||||
# "time": msg[1],
|
||||
# "content": msg[2]
|
||||
# },ensure_ascii=False) + ",\n"
|
||||
#
|
||||
# template = f"""
|
||||
# 以下是群中的消息记录
|
||||
#
|
||||
# ```json
|
||||
# [
|
||||
# {content}
|
||||
# ]
|
||||
# ```
|
||||
# """ + """
|
||||
# 找到其中的问题和回答,如果没有回答就只整理问题,问题是与产品填报系统,上市公司,证券政策相关的问题
|
||||
# 问题可能不只由一句话构成,回答也可能不只由一句话构成
|
||||
# 多个问题需要分开放置
|
||||
# 输出格式
|
||||
#
|
||||
# ```json
|
||||
# [
|
||||
# {
|
||||
# "question": [{
|
||||
# "user": "用户1",
|
||||
# "time": "时间戳",
|
||||
# "content": "问题"
|
||||
# }],
|
||||
# "answer": [
|
||||
# {
|
||||
# "user": "用户1",
|
||||
# "time": "时间戳",
|
||||
# "content": "回答"
|
||||
# }
|
||||
# ]
|
||||
# }
|
||||
# ]
|
||||
# ```
|
||||
# """
|
||||
# answer = agent.chat_deepseek(template)
|
||||
# answer = answer.replace("```json", "").replace("```", "") if "```json" in answer else answer
|
||||
# try:
|
||||
# answer = json.loads(answer)
|
||||
# except:
|
||||
# print(answer)
|
||||
# answer = []
|
||||
# group_qa[group_id] = answer
|
||||
# print(group_qa)
|
||||
# with open(f"group_qa-{start.split(' ')[0]}-{end.split(' ')[0]}.json", "w", encoding="utf-8") as f:
|
||||
# f.write(json.dumps(group_qa, ensure_ascii=False))
|
||||
# push_message(f"群聊问答-{start.split(' ')[0]}-{end.split(' ')[0]}", "问题提取完成", "")
|
||||
with open(f"group_qa.json", "r", encoding="utf-8") as f:
|
||||
data = json.load(f)
|
||||
cursor = chat_session.conn.cursor()
|
||||
a = cursor.execute('''
|
||||
select *
|
||||
from message
|
||||
''').fetchall()
|
||||
|
||||
mapping = {}
|
||||
for i in a:
|
||||
mapping[i[2] + "-" + i[5]] = i[0]
|
||||
dar = []
|
||||
for r in data:
|
||||
qas = data.get(r)
|
||||
|
||||
for qa in qas:
|
||||
Q = []
|
||||
A = []
|
||||
q = qa["question"]
|
||||
for qq in q:
|
||||
if qq["time"] + "-" + qq["user"] not in mapping:
|
||||
print(qq)
|
||||
else:
|
||||
Q.append(mapping[qq["time"] + "-" + qq["user"]])
|
||||
a = qa["answer"]
|
||||
for aa in a:
|
||||
if aa["time"] + "-" + aa["user"] not in mapping:
|
||||
print(aa)
|
||||
else:
|
||||
A.append(mapping[aa["time"] + "-" + aa["user"]])
|
||||
dar.append((r, json.dumps(Q, ensure_ascii=False), json.dumps(A, ensure_ascii=False)))
|
||||
a = cursor.executemany('''
|
||||
insert into qa (groupId, question, answer)
|
||||
values (?, ?, ?)
|
||||
''', dar)
|
||||
chat_session.conn.commit()
|
||||
start = "2025-10-15 00:00:00"
|
||||
end = "2025-10-15 23:59:59"
|
||||
chat_session.update_qa_data(start, end)
|
||||
|
||||
BIN
db/data.sqlite
BIN
db/data.sqlite
Binary file not shown.
@@ -1,2 +1,3 @@
|
||||
Flask==2.3.3
|
||||
Werkzeug==2.3.7
|
||||
pytz
|
||||
170
static/css/daily_report.css
Normal file
170
static/css/daily_report.css
Normal file
@@ -0,0 +1,170 @@
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
||||
line-height: 1.6;
|
||||
color: #333;
|
||||
background-color: #f5f5f5;
|
||||
}
|
||||
|
||||
.container {
|
||||
max-width: 1200px;
|
||||
margin: 0 auto;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.header {
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: white;
|
||||
padding: 30px;
|
||||
border-radius: 10px;
|
||||
margin-bottom: 30px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.header h1 {
|
||||
font-size: 2.5em;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.header p {
|
||||
font-size: 1.2em;
|
||||
opacity: 0.9;
|
||||
}
|
||||
|
||||
.controls {
|
||||
background: white;
|
||||
padding: 20px;
|
||||
border-radius: 10px;
|
||||
margin-bottom: 20px;
|
||||
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.control-group {
|
||||
display: flex;
|
||||
gap: 20px;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.control-group label {
|
||||
font-weight: bold;
|
||||
color: #555;
|
||||
}
|
||||
|
||||
.control-group input {
|
||||
padding: 8px 12px;
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 5px;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.btn {
|
||||
background: #667eea;
|
||||
color: white;
|
||||
border: none;
|
||||
padding: 10px 20px;
|
||||
border-radius: 5px;
|
||||
cursor: pointer;
|
||||
font-size: 14px;
|
||||
transition: background 0.3s;
|
||||
}
|
||||
|
||||
.btn:hover {
|
||||
background: #5a6fd8;
|
||||
}
|
||||
|
||||
.btn:disabled {
|
||||
background: #ccc;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.report-container {
|
||||
background: white;
|
||||
border-radius: 10px;
|
||||
padding: 30px;
|
||||
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.report-content {
|
||||
white-space: pre-wrap;
|
||||
font-family: 'Courier New', monospace;
|
||||
line-height: 1.8;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.loading {
|
||||
text-align: center;
|
||||
padding: 40px;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.error {
|
||||
background: #ffe6e6;
|
||||
color: #d63031;
|
||||
padding: 15px;
|
||||
border-radius: 5px;
|
||||
margin: 10px 0;
|
||||
border-left: 4px solid #d63031;
|
||||
}
|
||||
|
||||
.statistics {
|
||||
background: #f8f9fa;
|
||||
padding: 20px;
|
||||
border-radius: 8px;
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
.stat-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
|
||||
gap: 15px;
|
||||
margin-top: 15px;
|
||||
}
|
||||
|
||||
.stat-item {
|
||||
background: white;
|
||||
padding: 15px;
|
||||
border-radius: 8px;
|
||||
text-align: center;
|
||||
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.stat-value {
|
||||
font-size: 1.8em;
|
||||
font-weight: bold;
|
||||
color: #667eea;
|
||||
}
|
||||
|
||||
.stat-label {
|
||||
font-size: 0.9em;
|
||||
color: #666;
|
||||
margin-top: 5px;
|
||||
}
|
||||
|
||||
.nav {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.nav-btn {
|
||||
padding: 8px 16px;
|
||||
background: #f8f9fa;
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 5px;
|
||||
text-decoration: none;
|
||||
color: #333;
|
||||
transition: all 0.3s;
|
||||
}
|
||||
|
||||
.nav-btn:hover {
|
||||
background: #667eea;
|
||||
color: white;
|
||||
border-color: #667eea;
|
||||
}
|
||||
492
static/css/index.css
Normal file
492
static/css/index.css
Normal file
@@ -0,0 +1,492 @@
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
||||
background-color: #f5f5f5;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.container {
|
||||
max-width: 1200px;
|
||||
margin: 0 auto;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.header {
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: white;
|
||||
padding: 30px;
|
||||
border-radius: 15px;
|
||||
margin-bottom: 30px;
|
||||
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.header h1 {
|
||||
font-size: 2.5em;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.header p {
|
||||
font-size: 1.1em;
|
||||
opacity: 0.9;
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
.nav-links {
|
||||
display: flex;
|
||||
gap: 15px;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.nav-btn {
|
||||
padding: 8px 16px;
|
||||
background: #f8f9fa;
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 5px;
|
||||
text-decoration: none;
|
||||
color: #333;
|
||||
transition: all 0.3s;
|
||||
}
|
||||
|
||||
.nav-btn:hover {
|
||||
background: #667eea;
|
||||
color: white;
|
||||
border-color: #667eea;
|
||||
}
|
||||
|
||||
.nav-btn.active {
|
||||
background: #667eea;
|
||||
color: white;
|
||||
border-color: #667eea;
|
||||
}
|
||||
|
||||
.nav-link {
|
||||
background: rgba(255, 255, 255, 0.2);
|
||||
color: white;
|
||||
padding: 8px 16px;
|
||||
border-radius: 20px;
|
||||
text-decoration: none;
|
||||
font-size: 0.9em;
|
||||
transition: all 0.3s ease;
|
||||
border: 1px solid rgba(255, 255, 255, 0.3);
|
||||
}
|
||||
|
||||
.nav-link:hover {
|
||||
background: rgba(255, 255, 255, 0.3);
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
|
||||
}
|
||||
|
||||
.stats-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
|
||||
gap: 20px;
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
|
||||
.stat-card {
|
||||
background: white;
|
||||
padding: 25px;
|
||||
border-radius: 12px;
|
||||
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.08);
|
||||
text-align: center;
|
||||
transition: transform 0.3s ease;
|
||||
}
|
||||
|
||||
.stat-card:hover {
|
||||
transform: translateY(-5px);
|
||||
}
|
||||
|
||||
.stat-number {
|
||||
font-size: 2.5em;
|
||||
font-weight: bold;
|
||||
color: #667eea;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
|
||||
.stat-label {
|
||||
color: #666;
|
||||
font-size: 0.9em;
|
||||
}
|
||||
|
||||
.view-switcher {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.view-btn {
|
||||
padding: 10px 20px;
|
||||
border: 2px solid #667eea;
|
||||
background: white;
|
||||
color: #667eea;
|
||||
border-radius: 25px;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s ease;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.view-btn.active {
|
||||
background: #667eea;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.view-btn:hover {
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 5px 15px rgba(102, 126, 234, 0.3);
|
||||
}
|
||||
|
||||
.chat-container {
|
||||
display: grid;
|
||||
grid-template-columns: 300px 1fr;
|
||||
gap: 20px;
|
||||
height: 70vh;
|
||||
}
|
||||
|
||||
.sidebar {
|
||||
background: white;
|
||||
border-radius: 12px;
|
||||
padding: 20px;
|
||||
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.08);
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.sidebar h3 {
|
||||
margin-bottom: 15px;
|
||||
color: #333;
|
||||
border-bottom: 2px solid #667eea;
|
||||
padding-bottom: 10px;
|
||||
}
|
||||
|
||||
.group-list {
|
||||
list-style: none;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.group-item {
|
||||
padding: 15px;
|
||||
margin-bottom: 10px;
|
||||
background: #f8f9fa;
|
||||
border-radius: 8px;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s ease;
|
||||
border-left: 4px solid transparent;
|
||||
}
|
||||
|
||||
.group-item:hover {
|
||||
background: #e9ecef;
|
||||
transform: translateX(5px);
|
||||
}
|
||||
|
||||
.group-item.active {
|
||||
background: #667eea;
|
||||
color: white;
|
||||
border-left-color: #764ba2;
|
||||
}
|
||||
|
||||
.group-name {
|
||||
font-weight: bold;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
|
||||
.group-info {
|
||||
font-size: 0.8em;
|
||||
color: #666;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.group-item.active .group-info {
|
||||
color: rgba(255, 255, 255, 0.8);
|
||||
}
|
||||
|
||||
.chat-area {
|
||||
background: white;
|
||||
border-radius: 12px;
|
||||
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.08);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.chat-header {
|
||||
padding: 20px;
|
||||
border-bottom: 1px solid #eee;
|
||||
background: #f8f9fa;
|
||||
border-radius: 12px 12px 0 0;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.current-group {
|
||||
font-size: 1.2em;
|
||||
font-weight: bold;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.group-stats {
|
||||
font-size: 0.9em;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.chat-messages {
|
||||
flex: 1;
|
||||
overflow-y: auto;
|
||||
overflow-x: hidden;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.message {
|
||||
margin-bottom: 20px;
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
}
|
||||
|
||||
.message.own {
|
||||
flex-direction: row-reverse;
|
||||
}
|
||||
|
||||
.avatar {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
border-radius: 50%;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
color: white;
|
||||
font-weight: bold;
|
||||
margin: 0 10px;
|
||||
}
|
||||
|
||||
.message-content {
|
||||
max-width: 70%;
|
||||
padding: 12px 16px;
|
||||
border-radius: 18px;
|
||||
background: #f1f3f5;
|
||||
position: relative;
|
||||
word-wrap: break-word;
|
||||
overflow-wrap: break-word;
|
||||
white-space: normal;
|
||||
}
|
||||
|
||||
.message.own .message-content {
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.message-sender {
|
||||
font-weight: bold;
|
||||
margin-bottom: 5px;
|
||||
font-size: 0.9em;
|
||||
}
|
||||
|
||||
.message-time {
|
||||
font-size: 0.8em;
|
||||
color: #999;
|
||||
margin-top: 5px;
|
||||
}
|
||||
|
||||
.message.own .message-time {
|
||||
color: rgba(255, 255, 255, 0.8);
|
||||
}
|
||||
|
||||
.controls {
|
||||
padding: 20px;
|
||||
border-top: 1px solid #eee;
|
||||
background: #f8f9fa;
|
||||
border-radius: 0 0 12px 12px;
|
||||
}
|
||||
|
||||
.load-more {
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: white;
|
||||
border: none;
|
||||
padding: 12px 24px;
|
||||
border-radius: 25px;
|
||||
cursor: pointer;
|
||||
font-size: 1em;
|
||||
transition: transform 0.3s ease;
|
||||
}
|
||||
|
||||
.load-more:hover {
|
||||
transform: scale(1.05);
|
||||
}
|
||||
|
||||
.loading {
|
||||
text-align: center;
|
||||
padding: 20px;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.error {
|
||||
background: #ffe6e6;
|
||||
color: #d63031;
|
||||
padding: 10px;
|
||||
border-radius: 8px;
|
||||
margin: 10px 0;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.chat-container {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
.sidebar {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.message-content {
|
||||
max-width: 85%;
|
||||
}
|
||||
}
|
||||
|
||||
body, .container {
|
||||
overflow-x: hidden;
|
||||
}
|
||||
|
||||
/* 聊天记录按钮样式 */
|
||||
.chatrecord-btn {
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: white;
|
||||
border: none;
|
||||
padding: 8px 16px;
|
||||
border-radius: 15px;
|
||||
cursor: pointer;
|
||||
font-size: 0.9em;
|
||||
transition: all 0.3s ease;
|
||||
text-align: left;
|
||||
max-width: 100%;
|
||||
word-wrap: break-word;
|
||||
overflow-wrap: break-word;
|
||||
white-space: normal;
|
||||
}
|
||||
|
||||
.chatrecord-btn:hover {
|
||||
transform: scale(1.05);
|
||||
box-shadow: 0 5px 15px rgba(102, 126, 234, 0.3);
|
||||
}
|
||||
|
||||
/* 模态框样式 */
|
||||
.modal {
|
||||
display: none;
|
||||
position: fixed;
|
||||
z-index: 1000;
|
||||
left: 0;
|
||||
top: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background-color: rgba(0, 0, 0, 0.5);
|
||||
animation: fadeIn 0.3s;
|
||||
}
|
||||
|
||||
.modal-content {
|
||||
background-color: white;
|
||||
margin: 5% auto;
|
||||
padding: 0;
|
||||
border-radius: 15px;
|
||||
width: 80%;
|
||||
max-width: 800px;
|
||||
max-height: 80vh;
|
||||
overflow: hidden;
|
||||
box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
|
||||
animation: slideIn 0.3s;
|
||||
}
|
||||
|
||||
.modal-header {
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: white;
|
||||
padding: 20px;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.modal-header h3 {
|
||||
margin: 0;
|
||||
font-size: 1.3em;
|
||||
}
|
||||
|
||||
.close {
|
||||
color: white;
|
||||
font-size: 28px;
|
||||
font-weight: bold;
|
||||
cursor: pointer;
|
||||
transition: opacity 0.3s;
|
||||
}
|
||||
|
||||
.close:hover {
|
||||
opacity: 0.7;
|
||||
}
|
||||
|
||||
.modal-body {
|
||||
padding: 0;
|
||||
max-height: calc(80vh - 80px);
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.chat-record-content {
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.chat-record-item {
|
||||
margin-bottom: 15px;
|
||||
padding: 15px;
|
||||
background: #f8f9fa;
|
||||
border-radius: 10px;
|
||||
border-left: 4px solid #667eea;
|
||||
}
|
||||
|
||||
.chat-record-sender {
|
||||
font-weight: bold;
|
||||
margin-bottom: 5px;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.chat-record-text {
|
||||
margin-bottom: 5px;
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
.chat-record-time {
|
||||
font-size: 0.8em;
|
||||
color: #666;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.chat-record-image {
|
||||
max-width: 200px;
|
||||
max-height: 200px;
|
||||
border-radius: 8px;
|
||||
margin: 5px 0;
|
||||
}
|
||||
|
||||
@keyframes fadeIn {
|
||||
from {
|
||||
opacity: 0;
|
||||
}
|
||||
to {
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes slideIn {
|
||||
from {
|
||||
transform: translateY(-50px);
|
||||
opacity: 0;
|
||||
}
|
||||
to {
|
||||
transform: translateY(0);
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
|
||||
.container {
|
||||
max-width: 100%;
|
||||
overflow-x: hidden;
|
||||
}
|
||||
506
static/css/qa.css
Normal file
506
static/css/qa.css
Normal file
@@ -0,0 +1,506 @@
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
||||
background-color: #f5f5f5;
|
||||
color: #333;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.container {
|
||||
max-width: 1200px;
|
||||
margin: 0 auto;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.header {
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: white;
|
||||
padding: 30px 0;
|
||||
text-align: center;
|
||||
border-radius: 10px;
|
||||
margin-bottom: 30px;
|
||||
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.header h1 {
|
||||
font-size: 2.5em;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.header p {
|
||||
font-size: 1.1em;
|
||||
opacity: 0.9;
|
||||
}
|
||||
|
||||
.controls {
|
||||
background: white;
|
||||
padding: 20px;
|
||||
border-radius: 10px;
|
||||
margin-bottom: 20px;
|
||||
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.search-box {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
.search-box input {
|
||||
flex: 1;
|
||||
padding: 10px;
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 5px;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.btn {
|
||||
padding: 10px 20px;
|
||||
border: none;
|
||||
border-radius: 5px;
|
||||
cursor: pointer;
|
||||
font-size: 14px;
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
|
||||
.btn-primary {
|
||||
background: #667eea;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.btn-primary:hover {
|
||||
background: #5a6fd8;
|
||||
transform: translateY(-2px);
|
||||
}
|
||||
|
||||
.btn-success {
|
||||
background: #28a745;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.btn-success:hover {
|
||||
background: #218838;
|
||||
}
|
||||
|
||||
.btn-danger {
|
||||
background: #dc3545;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.btn-danger:hover {
|
||||
background: #c82333;
|
||||
}
|
||||
|
||||
.qa-list {
|
||||
background: white;
|
||||
border-radius: 10px;
|
||||
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.qa-item {
|
||||
padding: 20px;
|
||||
border-bottom: 1px solid #eee;
|
||||
transition: background-color 0.3s ease;
|
||||
}
|
||||
|
||||
.qa-item:hover {
|
||||
background-color: #f8f9fa;
|
||||
}
|
||||
|
||||
.qa-item:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.qa-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
.qa-id {
|
||||
font-weight: bold;
|
||||
color: #667eea;
|
||||
font-size: 1.2em;
|
||||
}
|
||||
|
||||
.qa-group {
|
||||
background: #e9ecef;
|
||||
padding: 5px 10px;
|
||||
border-radius: 15px;
|
||||
font-size: 0.9em;
|
||||
}
|
||||
|
||||
.qa-content {
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
.nav-btn {
|
||||
padding: 8px 16px;
|
||||
background: #f8f9fa;
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 5px;
|
||||
text-decoration: none;
|
||||
color: #333;
|
||||
transition: all 0.3s;
|
||||
}
|
||||
|
||||
.nav-btn:hover {
|
||||
background: #667eea;
|
||||
color: white;
|
||||
border-color: #667eea;
|
||||
}
|
||||
|
||||
.nav-btn.active {
|
||||
background: #667eea;
|
||||
color: white;
|
||||
border-color: #667eea;
|
||||
}
|
||||
|
||||
.qa-section {
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.qa-section h4 {
|
||||
color: #495057;
|
||||
margin-bottom: 5px;
|
||||
font-size: 1em;
|
||||
}
|
||||
|
||||
.message-list {
|
||||
background: #f8f9fa;
|
||||
padding: 10px;
|
||||
border-radius: 5px;
|
||||
max-height: 150px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.message-item {
|
||||
padding: 5px;
|
||||
margin-bottom: 5px;
|
||||
background: white;
|
||||
border-radius: 3px;
|
||||
font-size: 0.9em;
|
||||
border-left: 3px solid #667eea;
|
||||
}
|
||||
|
||||
.qa-actions {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.modal {
|
||||
display: none;
|
||||
position: fixed;
|
||||
z-index: 1000;
|
||||
left: 0;
|
||||
top: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background-color: rgba(0, 0, 0, 0.5);
|
||||
}
|
||||
|
||||
.modal-content {
|
||||
background-color: white;
|
||||
margin: 5% auto;
|
||||
padding: 30px;
|
||||
border-radius: 10px;
|
||||
width: 80%;
|
||||
max-width: 800px;
|
||||
max-height: 80vh;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.modal-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.close {
|
||||
font-size: 28px;
|
||||
font-weight: bold;
|
||||
cursor: pointer;
|
||||
color: #aaa;
|
||||
}
|
||||
|
||||
.close:hover {
|
||||
color: #000;
|
||||
}
|
||||
|
||||
.form-group {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.form-group label {
|
||||
display: block;
|
||||
margin-bottom: 5px;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.form-group input,
|
||||
.form-group textarea {
|
||||
width: 100%;
|
||||
padding: 10px;
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 5px;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.message-selector {
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 5px;
|
||||
padding: 15px;
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
.search-results {
|
||||
max-height: 200px;
|
||||
overflow-y: auto;
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 5px;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.search-result-item {
|
||||
padding: 10px;
|
||||
border-bottom: 1px solid #eee;
|
||||
cursor: pointer;
|
||||
transition: background-color 0.2s;
|
||||
}
|
||||
|
||||
.search-result-item:hover {
|
||||
background-color: #f0f0f0;
|
||||
}
|
||||
|
||||
.selected-messages {
|
||||
background: #f8f9fa;
|
||||
padding: 10px;
|
||||
border-radius: 5px;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.selected-message {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 5px;
|
||||
margin-bottom: 5px;
|
||||
background: white;
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
.loading {
|
||||
text-align: center;
|
||||
padding: 20px;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.empty-state {
|
||||
text-align: center;
|
||||
padding: 40px;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.empty-state i {
|
||||
font-size: 48px;
|
||||
margin-bottom: 10px;
|
||||
opacity: 0.5;
|
||||
}
|
||||
|
||||
/* 聊天记录预览样式 */
|
||||
.chat-preview {
|
||||
background: white;
|
||||
border-radius: 10px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.chat-header {
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: white;
|
||||
padding: 20px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.chat-header h3 {
|
||||
margin: 0 0 10px 0;
|
||||
font-size: 1.5em;
|
||||
}
|
||||
|
||||
.chat-info {
|
||||
opacity: 0.9;
|
||||
font-size: 0.9em;
|
||||
}
|
||||
|
||||
.chat-container {
|
||||
padding: 20px;
|
||||
max-height: 400px;
|
||||
overflow-y: auto;
|
||||
background: #f8f9fa;
|
||||
}
|
||||
|
||||
.chat-message {
|
||||
display: flex;
|
||||
margin-bottom: 15px;
|
||||
animation: fadeIn 0.3s ease;
|
||||
}
|
||||
|
||||
.chat-message.question {
|
||||
flex-direction: row;
|
||||
}
|
||||
|
||||
.chat-message.answer {
|
||||
flex-direction: row-reverse;
|
||||
}
|
||||
|
||||
.chat-message.other {
|
||||
flex-direction: row;
|
||||
opacity: 0.7;
|
||||
}
|
||||
|
||||
.message-avatar {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
border-radius: 50%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 18px;
|
||||
margin: 0 10px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.chat-message.question .message-avatar {
|
||||
background: #e3f2fd;
|
||||
color: #1976d2;
|
||||
}
|
||||
|
||||
.chat-message.answer .message-avatar {
|
||||
background: #f3e5f5;
|
||||
color: #7b1fa2;
|
||||
}
|
||||
|
||||
.chat-message.other .message-avatar {
|
||||
background: #f5f5f5;
|
||||
color: #757575;
|
||||
}
|
||||
|
||||
.message-content {
|
||||
flex: 1;
|
||||
max-width: 70%;
|
||||
}
|
||||
|
||||
.message-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
margin-bottom: 5px;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.sender {
|
||||
font-weight: bold;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.time {
|
||||
font-size: 0.8em;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.message-type-badge {
|
||||
padding: 2px 8px;
|
||||
border-radius: 12px;
|
||||
font-size: 0.7em;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.message-type-badge.question {
|
||||
background: #e3f2fd;
|
||||
color: #1976d2;
|
||||
}
|
||||
|
||||
.message-type-badge.answer {
|
||||
background: #f3e5f5;
|
||||
color: #7b1fa2;
|
||||
}
|
||||
|
||||
.message-type-badge.other {
|
||||
background: #f5f5f5;
|
||||
color: #757575;
|
||||
}
|
||||
|
||||
.message-text {
|
||||
background: white;
|
||||
padding: 12px 15px;
|
||||
border-radius: 18px;
|
||||
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
|
||||
line-height: 1.4;
|
||||
word-wrap: break-word;
|
||||
}
|
||||
|
||||
.chat-message.question .message-text {
|
||||
background: #e3f2fd;
|
||||
border-bottom-left-radius: 5px;
|
||||
}
|
||||
|
||||
.chat-message.answer .message-text {
|
||||
background: #f3e5f5;
|
||||
border-bottom-right-radius: 5px;
|
||||
}
|
||||
|
||||
.chat-message.other .message-text {
|
||||
background: #f5f5f5;
|
||||
border-radius: 18px;
|
||||
}
|
||||
|
||||
.message-meta {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
margin-top: 5px;
|
||||
font-size: 0.7em;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.chat-summary {
|
||||
background: white;
|
||||
padding: 15px 20px;
|
||||
border-top: 1px solid #eee;
|
||||
display: flex;
|
||||
justify-content: space-around;
|
||||
}
|
||||
|
||||
.summary-item {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.summary-label {
|
||||
display: block;
|
||||
font-size: 0.8em;
|
||||
color: #666;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
|
||||
.summary-value {
|
||||
display: block;
|
||||
font-size: 1.2em;
|
||||
font-weight: bold;
|
||||
color: #667eea;
|
||||
}
|
||||
|
||||
@keyframes fadeIn {
|
||||
from {
|
||||
opacity: 0;
|
||||
transform: translateY(10px);
|
||||
}
|
||||
to {
|
||||
opacity: 1;
|
||||
transform: translateY(0);
|
||||
}
|
||||
}
|
||||
212
static/css/weekly_report.css
Normal file
212
static/css/weekly_report.css
Normal file
@@ -0,0 +1,212 @@
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
||||
line-height: 1.6;
|
||||
color: #333;
|
||||
background-color: #f5f5f5;
|
||||
}
|
||||
|
||||
.container {
|
||||
max-width: 1200px;
|
||||
margin: 0 auto;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.header {
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: white;
|
||||
padding: 30px;
|
||||
border-radius: 10px;
|
||||
margin-bottom: 30px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.header h1 {
|
||||
font-size: 2.5em;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.header p {
|
||||
font-size: 1.2em;
|
||||
opacity: 0.9;
|
||||
}
|
||||
|
||||
.controls {
|
||||
background: white;
|
||||
padding: 20px;
|
||||
border-radius: 10px;
|
||||
margin-bottom: 20px;
|
||||
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
|
||||
}
|
||||
|
||||
.control-group {
|
||||
display: flex;
|
||||
gap: 20px;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.control-group label {
|
||||
font-weight: bold;
|
||||
color: #555;
|
||||
}
|
||||
|
||||
.control-group input {
|
||||
padding: 8px 12px;
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 5px;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.btn {
|
||||
background: #667eea;
|
||||
color: white;
|
||||
border: none;
|
||||
padding: 10px 20px;
|
||||
border-radius: 5px;
|
||||
cursor: pointer;
|
||||
font-size: 14px;
|
||||
transition: background 0.3s;
|
||||
}
|
||||
|
||||
.btn:hover {
|
||||
background: #5a6fd8;
|
||||
}
|
||||
|
||||
.btn:disabled {
|
||||
background: #ccc;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.report-container {
|
||||
background: white;
|
||||
border-radius: 10px;
|
||||
padding: 30px;
|
||||
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.report-content {
|
||||
white-space: pre-wrap;
|
||||
font-family: 'Courier New', monospace;
|
||||
line-height: 1.8;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.loading {
|
||||
text-align: center;
|
||||
padding: 40px;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.error {
|
||||
background: #ffe6e6;
|
||||
color: #d63031;
|
||||
padding: 15px;
|
||||
border-radius: 5px;
|
||||
margin: 10px 0;
|
||||
border-left: 4px solid #d63031;
|
||||
}
|
||||
|
||||
.statistics {
|
||||
background: #f8f9fa;
|
||||
padding: 20px;
|
||||
border-radius: 8px;
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
.stat-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
|
||||
gap: 15px;
|
||||
margin-top: 15px;
|
||||
}
|
||||
|
||||
.stat-item {
|
||||
background: white;
|
||||
padding: 15px;
|
||||
border-radius: 8px;
|
||||
text-align: center;
|
||||
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
|
||||
}
|
||||
|
||||
.stat-value {
|
||||
font-size: 1.8em;
|
||||
font-weight: bold;
|
||||
color: #667eea;
|
||||
}
|
||||
|
||||
.stat-label {
|
||||
font-size: 0.9em;
|
||||
color: #666;
|
||||
margin-top: 5px;
|
||||
}
|
||||
|
||||
.category-chart {
|
||||
margin: 20px 0;
|
||||
}
|
||||
|
||||
.category-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
margin: 10px 0;
|
||||
padding: 10px;
|
||||
background: #f8f9fa;
|
||||
border-radius: 5px;
|
||||
}
|
||||
|
||||
.category-bar {
|
||||
height: 20px;
|
||||
background: linear-gradient(90deg, #667eea, #764ba2);
|
||||
border-radius: 10px;
|
||||
margin: 0 10px;
|
||||
min-width: 50px;
|
||||
}
|
||||
|
||||
.nav {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.nav-btn {
|
||||
padding: 8px 16px;
|
||||
background: #f8f9fa;
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 5px;
|
||||
text-decoration: none;
|
||||
color: #333;
|
||||
transition: all 0.3s;
|
||||
}
|
||||
|
||||
.nav-btn:hover {
|
||||
background: #667eea;
|
||||
color: white;
|
||||
border-color: #667eea;
|
||||
}
|
||||
|
||||
.nav-btn.active {
|
||||
background: #667eea;
|
||||
color: white;
|
||||
border-color: #667eea;
|
||||
}
|
||||
|
||||
.export-btn {
|
||||
background: #28a745;
|
||||
color: white;
|
||||
border: none;
|
||||
padding: 8px 16px;
|
||||
border-radius: 5px;
|
||||
cursor: pointer;
|
||||
font-size: 14px;
|
||||
margin-left: auto;
|
||||
}
|
||||
|
||||
.export-btn:hover {
|
||||
background: #218838;
|
||||
}
|
||||
86
static/js/daily_report.js
Normal file
86
static/js/daily_report.js
Normal file
@@ -0,0 +1,86 @@
|
||||
// 设置默认日期为今天
|
||||
document.getElementById('date').value = new Date().toISOString().split('T')[0];
|
||||
|
||||
function showLoading() {
|
||||
document.getElementById('loading').style.display = 'block';
|
||||
document.getElementById('report-container').style.display = 'none';
|
||||
document.getElementById('error').style.display = 'none';
|
||||
}
|
||||
|
||||
function hideLoading() {
|
||||
document.getElementById('loading').style.display = 'none';
|
||||
}
|
||||
|
||||
function showError(message) {
|
||||
document.getElementById('error').style.display = 'block';
|
||||
document.getElementById('error').textContent = message;
|
||||
}
|
||||
|
||||
function generateTodayReport() {
|
||||
document.getElementById('date').value = new Date().toISOString().split('T')[0];
|
||||
generateReport();
|
||||
}
|
||||
|
||||
function generateReport() {
|
||||
const date = document.getElementById('date').value;
|
||||
if (!date) {
|
||||
showError('请选择日期');
|
||||
return;
|
||||
}
|
||||
|
||||
showLoading();
|
||||
|
||||
fetch(`/api/reports/daily?date=${date}`)
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
hideLoading();
|
||||
|
||||
if (data.success) {
|
||||
document.getElementById('report-content').textContent = data.report;
|
||||
document.getElementById('report-container').style.display = 'block';
|
||||
|
||||
// 显示统计数据
|
||||
if (data.statistics) {
|
||||
displayStatistics(data.statistics);
|
||||
document.getElementById('statistics').style.display = 'block';
|
||||
}
|
||||
} else {
|
||||
showError('生成日报失败:' + data.error);
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
hideLoading();
|
||||
showError('网络错误:' + error.message);
|
||||
});
|
||||
}
|
||||
|
||||
function displayStatistics(stats) {
|
||||
const statGrid = document.getElementById('stat-grid');
|
||||
statGrid.innerHTML = '';
|
||||
|
||||
const statistics = [
|
||||
{label: '今日消息量', value: stats.today_message_count, unit: '条'},
|
||||
{label: '昨日消息量', value: stats.yesterday_message_count, unit: '条'},
|
||||
{label: '消息变化率', value: stats.message_change_rate.toFixed(1), unit: '%'},
|
||||
{label: '今日活跃用户', value: stats.today_active_users, unit: '人'},
|
||||
{label: '昨日活跃用户', value: stats.yesterday_active_users, unit: '人'},
|
||||
{label: '用户变化率', value: stats.user_change_rate.toFixed(1), unit: '%'},
|
||||
{label: '群组数量', value: stats.group_count, unit: '个'},
|
||||
{label: '成员总数', value: stats.member_count, unit: '人'}
|
||||
];
|
||||
|
||||
statistics.forEach(stat => {
|
||||
const statItem = document.createElement('div');
|
||||
statItem.className = 'stat-item';
|
||||
statItem.innerHTML = `
|
||||
<div class="stat-value">${stat.value}${stat.unit}</div>
|
||||
<div class="stat-label">${stat.label}</div>
|
||||
`;
|
||||
statGrid.appendChild(statItem);
|
||||
});
|
||||
}
|
||||
|
||||
// 页面加载时自动生成今日日报
|
||||
window.addEventListener('load', function () {
|
||||
generateTodayReport();
|
||||
});
|
||||
309
static/js/index.js
Normal file
309
static/js/index.js
Normal file
@@ -0,0 +1,309 @@
|
||||
let currentOffset = 0;
|
||||
const limit = 50;
|
||||
let currentView = 'groups';
|
||||
let currentGroupId = null;
|
||||
// 页面加载时初始化
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
loadStatistics();
|
||||
loadGroupMessages();
|
||||
loadMessages();
|
||||
});
|
||||
|
||||
// 加载统计信息
|
||||
async function loadStatistics() {
|
||||
try {
|
||||
const response = await fetch('/api/statistics');
|
||||
const data = await response.json();
|
||||
if (data) {
|
||||
const stats = data;
|
||||
document.getElementById('userCount').textContent = stats.user_count;
|
||||
document.getElementById('groupCount').textContent = stats.group_count;
|
||||
document.getElementById('messageCount').textContent = stats.message_count;
|
||||
document.getElementById('fileCount').textContent = stats.file_count;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('加载统计信息失败:', error);
|
||||
}
|
||||
}
|
||||
|
||||
// 加载按群组分组的消息统计
|
||||
async function loadGroupMessages() {
|
||||
try {
|
||||
const response = await fetch('/api/groups');
|
||||
const data = await response.json();
|
||||
const groupList = document.getElementById('groupList');
|
||||
|
||||
if (data.success) {
|
||||
const groups = data.groups || [];
|
||||
groupList.innerHTML = '';
|
||||
|
||||
if (groups.length === 0) {
|
||||
groupList.innerHTML = '<li>暂无群组</li>';
|
||||
return;
|
||||
} else {
|
||||
currentGroupId = groups[0].id;
|
||||
}
|
||||
|
||||
groups.forEach(group => {
|
||||
const li = document.createElement('li');
|
||||
li.className = 'group-item';
|
||||
li.setAttribute('data-group-id', group.id);
|
||||
li.onclick = () => selectGroup(group.id);
|
||||
|
||||
const groupName = document.createElement('div');
|
||||
groupName.className = 'group-name';
|
||||
groupName.textContent = group.name || group.id;
|
||||
|
||||
const groupInfo = document.createElement('div');
|
||||
groupInfo.className = 'group-info';
|
||||
groupInfo.innerHTML = `
|
||||
<span>创建者: ${group.owner || '未知'}</span>
|
||||
`;
|
||||
|
||||
li.appendChild(groupName);
|
||||
li.appendChild(groupInfo);
|
||||
groupList.appendChild(li);
|
||||
});
|
||||
|
||||
// 默认选择第一个群组
|
||||
if (currentView === 'groups' && groups.length > 0) {
|
||||
selectGroup(groups[0].id);
|
||||
}
|
||||
} else {
|
||||
groupList.innerHTML = '<li>加载失败</li>';
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('加载群组消息失败:', error);
|
||||
}
|
||||
}
|
||||
|
||||
// 选择群组
|
||||
function selectGroup(groupId) {
|
||||
currentGroupId = groupId;
|
||||
currentOffset = 0;
|
||||
|
||||
// 更新选中状态
|
||||
document.querySelectorAll('.group-item').forEach(item => {
|
||||
item.classList.remove('active');
|
||||
});
|
||||
|
||||
// 找到对应的群组项并添加选中状态
|
||||
document.querySelectorAll('.group-item').forEach(item => {
|
||||
// 使用data-group-id属性来准确匹配群组
|
||||
if (item.getAttribute('data-group-id') === groupId) {
|
||||
item.classList.add('active');
|
||||
|
||||
// 更新群组信息
|
||||
document.getElementById('currentGroup').textContent = item.querySelector('.group-name').textContent;
|
||||
document.getElementById('messageCountDisplay').textContent = '消息数量: 加载中...';
|
||||
document.getElementById('latestTime').textContent = '最新消息: 加载中...';
|
||||
}
|
||||
});
|
||||
|
||||
// 加载该群组的消息
|
||||
loadMessages();
|
||||
|
||||
// 加载统计信息
|
||||
loadStatistics();
|
||||
}
|
||||
|
||||
|
||||
// 加载更多消息
|
||||
async function loadMoreMessages() {
|
||||
await loadMessages();
|
||||
currentOffset += limit;
|
||||
}
|
||||
|
||||
// 关闭聊天记录模态框
|
||||
function closeChatRecordModal() {
|
||||
document.getElementById('chatRecordModal').style.display = 'none';
|
||||
}
|
||||
|
||||
// 显示聊天记录模态框
|
||||
function showChatRecordModal(chatrecordData) {
|
||||
const modal = document.getElementById('chatRecordModal');
|
||||
const title = document.getElementById('modalTitle');
|
||||
const content = document.getElementById('chatRecordContent');
|
||||
|
||||
// 设置模态框标题
|
||||
if (chatrecordData.chatrecord && chatrecordData.chatrecord.title) {
|
||||
title.textContent = chatrecordData.chatrecord.title;
|
||||
} else {
|
||||
title.textContent = '聊天记录';
|
||||
}
|
||||
|
||||
// 渲染聊天记录内容
|
||||
renderChatRecordContent(chatrecordData, content);
|
||||
|
||||
modal.style.display = 'block';
|
||||
}
|
||||
|
||||
// 渲染聊天记录内容
|
||||
function renderChatRecordContent(chatrecordData, contentElement) {
|
||||
try {
|
||||
if (!chatrecordData.chatrecord || !chatrecordData.chatrecord.item) {
|
||||
contentElement.innerHTML = '<div class="error">聊天记录数据格式错误</div>';
|
||||
return;
|
||||
}
|
||||
|
||||
const chatItems = chatrecordData.chatrecord.item;
|
||||
|
||||
if (!Array.isArray(chatItems) || chatItems.length === 0) {
|
||||
contentElement.innerHTML = '<div class="error">暂无聊天记录内容</div>';
|
||||
return;
|
||||
}
|
||||
|
||||
let html = '';
|
||||
chatItems.forEach(item => {
|
||||
// 处理不同类型的聊天记录项
|
||||
let contentHtml = '';
|
||||
|
||||
if (item.type === 'ChatRecordText') {
|
||||
// 文本消息
|
||||
try {
|
||||
const contentData = JSON.parse(item.content);
|
||||
contentHtml = contentData.content || item.content || '';
|
||||
} catch (e) {
|
||||
contentHtml = item.content || '';
|
||||
}
|
||||
} else if (item.type === 'ChatRecordImage') {
|
||||
// 图片消息
|
||||
contentHtml = '<div class="chat-record-image">[图片消息]</div>';
|
||||
} else {
|
||||
// 其他类型消息
|
||||
contentHtml = `[${item.type}] ${item.content || ''}`;
|
||||
}
|
||||
|
||||
html += `
|
||||
<div class="chat-record-item">
|
||||
<div class="chat-record-sender">${item.from_chatroom ? '群聊' : '私聊'}</div>
|
||||
<div class="chat-record-text">${contentHtml}</div>
|
||||
<div class="chat-record-time">${new Date(item.msgtime * 1000).toLocaleString()}</div>
|
||||
</div>
|
||||
`;
|
||||
});
|
||||
|
||||
contentElement.innerHTML = html;
|
||||
} catch (error) {
|
||||
console.error('渲染聊天记录失败:', error);
|
||||
contentElement.innerHTML = '<div class="error">渲染聊天记录失败: ' + error.message + '</div>';
|
||||
}
|
||||
}
|
||||
|
||||
// 加载消息
|
||||
async function loadMessages() {
|
||||
try {
|
||||
const chatMessages = document.getElementById('chatMessages');
|
||||
if (!currentGroupId) {
|
||||
chatMessages.innerHTML = '<div class="loading">暂无消息</div>';
|
||||
return;
|
||||
}
|
||||
let url = `/api/group_messages?limit=${limit}&offset=${currentOffset}&group_id=${currentGroupId}`;
|
||||
|
||||
|
||||
const response = await fetch(url);
|
||||
const data = await response.json();
|
||||
|
||||
if (data.success) {
|
||||
const messages = data.messages || [];
|
||||
|
||||
if (currentOffset === 0) {
|
||||
chatMessages.innerHTML = '';
|
||||
}
|
||||
|
||||
if (messages.length === 0) {
|
||||
if (currentOffset === 0) {
|
||||
chatMessages.innerHTML = '<div class="loading">暂无消息</div>';
|
||||
document.getElementById('messageCountDisplay').textContent = `消息数量: 0`;
|
||||
document.getElementById('latestTime').textContent = `最新消息: 暂无`;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
messages.forEach(message => {
|
||||
const messageDiv = createMessageElement(message);
|
||||
if (currentOffset === 0) {
|
||||
chatMessages.appendChild(messageDiv);
|
||||
} else {
|
||||
// 加载更多消息时,插入到现有消息的前面
|
||||
chatMessages.insertBefore(messageDiv, chatMessages.firstChild);
|
||||
}
|
||||
});
|
||||
currentOffset += limit;
|
||||
|
||||
|
||||
document.getElementById('messageCountDisplay').textContent = `消息数量: ${data.total || 0}`;
|
||||
document.getElementById('latestTime').textContent = `最新消息: ${data.lastest_time || '暂无'}`;
|
||||
|
||||
|
||||
} else {
|
||||
chatMessages.innerHTML = '<div class="error">加载消息失败</div>';
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('加载消息失败:', error);
|
||||
document.getElementById('chatMessages').innerHTML = '<div class="error">加载消息失败: ' + error.message + '</div>';
|
||||
}
|
||||
}
|
||||
|
||||
// 创建消息元素
|
||||
function createMessageElement(message) {
|
||||
const messageDiv = document.createElement('div');
|
||||
messageDiv.className = 'message';
|
||||
|
||||
// 判断是否为自己的消息
|
||||
if (message.is_own) {
|
||||
messageDiv.classList.add('own');
|
||||
}
|
||||
|
||||
const avatar = document.createElement('div');
|
||||
avatar.className = 'avatar';
|
||||
avatar.textContent = message.sender_name ? message.sender_name.charAt(0).toUpperCase() : 'U';
|
||||
|
||||
const contentDiv = document.createElement('div');
|
||||
contentDiv.className = 'message-content';
|
||||
|
||||
const senderDiv = document.createElement('div');
|
||||
senderDiv.className = 'message-sender';
|
||||
senderDiv.textContent = message.sender_name || '未知用户';
|
||||
|
||||
const textDiv = document.createElement('div');
|
||||
textDiv.className = 'message-text';
|
||||
|
||||
// 处理消息内容
|
||||
if (message.content) {
|
||||
if (message.type === 'chatrecord' && message.chatrecord_data) {
|
||||
const chatrecordBtn = document.createElement('button');
|
||||
chatrecordBtn.className = 'chatrecord-btn';
|
||||
chatrecordBtn.textContent = message.display_content || '[聊天记录]';
|
||||
chatrecordBtn.onclick = () => showChatRecordModal(message.chatrecord_data);
|
||||
textDiv.appendChild(chatrecordBtn);
|
||||
} else {
|
||||
textDiv.textContent = message.display_content;
|
||||
}
|
||||
} else {
|
||||
textDiv.textContent = '[空消息]';
|
||||
}
|
||||
|
||||
const timeDiv = document.createElement('div');
|
||||
timeDiv.className = 'message-time';
|
||||
timeDiv.textContent = message.formatted_time;
|
||||
|
||||
contentDiv.appendChild(senderDiv);
|
||||
contentDiv.appendChild(textDiv);
|
||||
contentDiv.appendChild(timeDiv);
|
||||
|
||||
messageDiv.appendChild(avatar);
|
||||
messageDiv.appendChild(contentDiv);
|
||||
|
||||
return messageDiv;
|
||||
}
|
||||
|
||||
|
||||
// 点击模态框外部关闭
|
||||
window.onclick = function (event) {
|
||||
const modal = document.getElementById('chatRecordModal');
|
||||
if (event.target === modal) {
|
||||
modal.style.display = 'none';
|
||||
}
|
||||
}
|
||||
567
static/js/qa.js
Normal file
567
static/js/qa.js
Normal file
@@ -0,0 +1,567 @@
|
||||
let currentQA = null;
|
||||
let selectedQuestions = [];
|
||||
let selectedAnswers = [];
|
||||
|
||||
// 页面加载时获取QA列表
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
loadQAList();
|
||||
});
|
||||
|
||||
// 加载QA列表
|
||||
async function loadQAList() {
|
||||
try {
|
||||
const response = await fetch('/api/qa');
|
||||
const result = await response.json();
|
||||
if (result.success) {
|
||||
// 根据后端API返回的数据结构,data字段包含qa_list
|
||||
const qaList = result.qa_list || [];
|
||||
displayQAList(qaList);
|
||||
} else {
|
||||
alert('加载QA列表失败: ' + result.error);
|
||||
}
|
||||
} catch (error) {
|
||||
alert('加载QA列表时出错: ' + error.message);
|
||||
}
|
||||
}
|
||||
|
||||
// 显示QA列表
|
||||
async function displayQAList(qaList) {
|
||||
const qaListContainer = document.getElementById('qaList');
|
||||
|
||||
if (qaList.length === 0) {
|
||||
qaListContainer.innerHTML = `
|
||||
<div class="empty-state">
|
||||
<div>📝</div>
|
||||
<h3>暂无QA记录</h3>
|
||||
<p>点击"创建新QA"按钮开始创建第一个问答记录</p>
|
||||
</div>
|
||||
`;
|
||||
return;
|
||||
}
|
||||
|
||||
// 获取所有消息的详细内容
|
||||
let allMessageIds = [];
|
||||
qaList.forEach(qa => {
|
||||
// 解析JSON格式的question和answer字段
|
||||
let questionIds = [];
|
||||
let answerIds = [];
|
||||
|
||||
try {
|
||||
questionIds = typeof qa.question === 'string' ? JSON.parse(qa.question) : qa.question || [];
|
||||
answerIds = typeof qa.answer === 'string' ? JSON.parse(qa.answer) : qa.answer || [];
|
||||
} catch (e) {
|
||||
console.error('解析QA数据时出错:', e);
|
||||
questionIds = [];
|
||||
answerIds = [];
|
||||
}
|
||||
|
||||
allMessageIds = [...allMessageIds, ...questionIds, ...answerIds];
|
||||
});
|
||||
|
||||
let messageMap = {};
|
||||
if (allMessageIds.length > 0) {
|
||||
try {
|
||||
const response = await fetch('/api/messages_by_ids', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({message_ids: allMessageIds})
|
||||
});
|
||||
const result = await response.json();
|
||||
if (result.success) {
|
||||
result.messages.forEach(msg => {
|
||||
messageMap[msg.id] = msg;
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取消息详情时出错:', error);
|
||||
}
|
||||
}
|
||||
|
||||
qaListContainer.innerHTML = qaList.map(qa => {
|
||||
// 解析JSON格式的question和answer字段
|
||||
let questionIds = [];
|
||||
let answerIds = [];
|
||||
|
||||
try {
|
||||
questionIds = typeof qa.question === 'string' ? JSON.parse(qa.question) : qa.question || [];
|
||||
answerIds = typeof qa.answer === 'string' ? JSON.parse(qa.answer) : qa.answer || [];
|
||||
} catch (e) {
|
||||
console.error('解析QA数据时出错:', e);
|
||||
questionIds = [];
|
||||
answerIds = [];
|
||||
}
|
||||
|
||||
// 获取第一个问题的内容作为显示
|
||||
let questionContent = '暂无问题内容';
|
||||
if (questionIds.length > 0) {
|
||||
const firstQuestionId = questionIds[0];
|
||||
const message = messageMap[firstQuestionId];
|
||||
if (message && message.content) {
|
||||
questionContent = message.content;
|
||||
} else {
|
||||
questionContent = `问题消息ID: ${firstQuestionId}`;
|
||||
}
|
||||
}
|
||||
|
||||
// 截取问题内容,超过30个字用省略号
|
||||
if (questionContent.length > 30) {
|
||||
questionContent = questionContent.substring(0, 30) + '...';
|
||||
}
|
||||
|
||||
return `
|
||||
<div class="qa-item">
|
||||
<div class="qa-header">
|
||||
<div class="qa-id">QA #${qa.id}</div>
|
||||
<div class="qa-group">${qa.groupId || '无群组'}</div>
|
||||
</div>
|
||||
|
||||
<div class="qa-content">
|
||||
<div class="qa-question">
|
||||
<strong>问题:</strong> ${questionContent}
|
||||
</div>
|
||||
<div class="qa-stats">
|
||||
<span class="stat">问题: ${questionIds.length}条</span>
|
||||
<span class="stat">答案: ${answerIds.length}条</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="qa-actions">
|
||||
<button class="btn btn-primary" onclick="previewQA(${qa.id})">预览</button>
|
||||
<button class="btn" onclick="editQA(${qa.id})">编辑</button>
|
||||
<button class="btn btn-danger" onclick="deleteQA(${qa.id})">删除</button>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
}).join('');
|
||||
}
|
||||
|
||||
// 搜索消息
|
||||
async function searchMessages() {
|
||||
const keyword = document.getElementById('searchInput').value.trim();
|
||||
if (!keyword) {
|
||||
alert('请输入搜索关键词');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch(`/api/search_messages?keyword=${encodeURIComponent(keyword)}`);
|
||||
const result = await response.json();
|
||||
|
||||
if (result.success) {
|
||||
displaySearchResults(result.messages);
|
||||
} else {
|
||||
alert('搜索失败: ' + result.error);
|
||||
}
|
||||
} catch (error) {
|
||||
alert('搜索时出错: ' + error.message);
|
||||
}
|
||||
}
|
||||
|
||||
// 显示搜索结果
|
||||
function displaySearchResults(messages) {
|
||||
const qaListContainer = document.getElementById('qaList');
|
||||
|
||||
if (messages.length === 0) {
|
||||
qaListContainer.innerHTML = `
|
||||
<div class="empty-state">
|
||||
<div>🔍</div>
|
||||
<h3>未找到相关消息</h3>
|
||||
<p>请尝试其他搜索关键词</p>
|
||||
</div>
|
||||
`;
|
||||
return;
|
||||
}
|
||||
|
||||
qaListContainer.innerHTML = messages.map(msg => `
|
||||
<div class="qa-item">
|
||||
<div class="qa-header">
|
||||
<div class="qa-id">消息ID: ${msg.id}</div>
|
||||
<div class="qa-group">${msg.formatted_time || '未知时间'}</div>
|
||||
</div>
|
||||
|
||||
<div class="qa-content">
|
||||
<div class="message-item">
|
||||
<strong>类型:</strong> ${msg.type} |
|
||||
<strong>发送者:</strong> ${msg.sender || '未知'} |
|
||||
<strong>接收者:</strong> ${msg.receiver || '未知'}
|
||||
</div>
|
||||
<div class="message-item" style="margin-top: 10px;">
|
||||
<strong>内容:</strong> ${msg.content || '无内容'}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="qa-actions">
|
||||
<button class="btn btn-primary" onclick="addToQuestion('${msg.id}')">设为问题</button>
|
||||
<button class="btn btn-success" onclick="addToAnswer('${msg.id}')">设为答案</button>
|
||||
</div>
|
||||
</div>
|
||||
`).join('');
|
||||
}
|
||||
|
||||
// 打开创建模态框
|
||||
function openCreateModal() {
|
||||
currentQA = null;
|
||||
selectedQuestions = [];
|
||||
selectedAnswers = [];
|
||||
|
||||
document.getElementById('modalTitle').textContent = '创建QA记录';
|
||||
document.getElementById('groupId').value = '';
|
||||
updateSelectedMessages();
|
||||
|
||||
document.getElementById('qaModal').style.display = 'block';
|
||||
}
|
||||
|
||||
// 编辑QA
|
||||
async function editQA(qaId) {
|
||||
try {
|
||||
const response = await fetch(`/api/qa/${qaId}`);
|
||||
const result = await response.json();
|
||||
|
||||
if (result.success) {
|
||||
currentQA = result.qa;
|
||||
selectedQuestions = [...currentQA.question_list];
|
||||
selectedAnswers = [...currentQA.answer_list];
|
||||
|
||||
document.getElementById('modalTitle').textContent = '编辑QA记录';
|
||||
document.getElementById('groupId').value = currentQA.groupId || '';
|
||||
updateSelectedMessages();
|
||||
|
||||
document.getElementById('qaModal').style.display = 'block';
|
||||
} else {
|
||||
alert('加载QA详情失败: ' + result.error);
|
||||
}
|
||||
} catch (error) {
|
||||
alert('加载QA详情时出错: ' + error.message);
|
||||
}
|
||||
}
|
||||
|
||||
// 搜索问题消息
|
||||
async function searchQuestionMessages() {
|
||||
const keyword = document.getElementById('questionSearch').value.trim();
|
||||
if (!keyword) {
|
||||
document.getElementById('questionResults').innerHTML = '';
|
||||
return;
|
||||
}
|
||||
const groupId = document.getElementById('groupId').value.trim();
|
||||
try {
|
||||
const url = `/api/search_messages?keyword=${encodeURIComponent(keyword)}&limit=20${groupId ? `&group_id=${groupId}` : ''}`;
|
||||
const response = await fetch(url);
|
||||
const result = await response.json();
|
||||
if (result.success) {
|
||||
displayQuestionResults(result.messages);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('搜索问题消息时出错:', error);
|
||||
}
|
||||
}
|
||||
|
||||
// 显示问题搜索结果
|
||||
function displayQuestionResults(messages) {
|
||||
const resultsContainer = document.getElementById('questionResults');
|
||||
console.log(messages);
|
||||
resultsContainer.innerHTML = messages.map(msg => `
|
||||
<div class="search-result-item" onclick="selectQuestion('${msg.id}', '${msg.content.replace(/'/g, "\\'").substring(0, 100)}')">
|
||||
<div><strong>ID:</strong> ${msg.id}</div>
|
||||
<div><strong>内容:</strong> ${msg.content ? msg.content.substring(0, 100) + (msg.content.length > 100 ? '...' : '') : '无内容'}</div>
|
||||
<div><strong>时间:</strong> ${msg.formatted_time || '未知'}</div>
|
||||
</div>
|
||||
`).join('');
|
||||
}
|
||||
|
||||
// 搜索答案消息
|
||||
async function searchAnswerMessages() {
|
||||
const keyword = document.getElementById('answerSearch').value.trim();
|
||||
if (!keyword) {
|
||||
document.getElementById('answerResults').innerHTML = '';
|
||||
return;
|
||||
}
|
||||
const groupId = document.getElementById('groupId').value.trim();
|
||||
|
||||
try {
|
||||
const url = `/api/search_messages?keyword=${encodeURIComponent(keyword)}&limit=20${groupId ? `&group_id=${groupId}` : ''}`;
|
||||
const response = await fetch(url);
|
||||
const result = await response.json();
|
||||
|
||||
if (result.success) {
|
||||
displayAnswerResults(result.messages);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('搜索答案消息时出错:', error);
|
||||
}
|
||||
}
|
||||
|
||||
// 显示答案搜索结果
|
||||
function displayAnswerResults(messages) {
|
||||
const resultsContainer = document.getElementById('answerResults');
|
||||
|
||||
resultsContainer.innerHTML = messages.map(msg => `
|
||||
<div class="search-result-item" onclick="selectAnswer('${msg.id}', '${msg.content.replace(/'/g, "\\'").substring(0, 100)}')">
|
||||
<div><strong>ID:</strong> ${msg.id}</div>
|
||||
<div><strong>内容:</strong> ${msg.content ? msg.content.substring(0, 100) + (msg.content.length > 100 ? '...' : '') : '无内容'}</div>
|
||||
<div><strong>时间:</strong> ${msg.formatted_time || '未知'}</div>
|
||||
</div>
|
||||
`).join('');
|
||||
}
|
||||
|
||||
// 选择问题消息
|
||||
function selectQuestion(messageId, content) {
|
||||
if (!selectedQuestions.includes(messageId)) {
|
||||
selectedQuestions.push(messageId);
|
||||
updateSelectedMessages();
|
||||
}
|
||||
}
|
||||
|
||||
// 选择答案消息
|
||||
function selectAnswer(messageId, content) {
|
||||
if (!selectedAnswers.includes(messageId)) {
|
||||
selectedAnswers.push(messageId);
|
||||
updateSelectedMessages();
|
||||
}
|
||||
}
|
||||
|
||||
// 从搜索结果添加为问题
|
||||
function addToQuestion(messageId) {
|
||||
if (!selectedQuestions.includes(messageId)) {
|
||||
selectedQuestions.push(messageId);
|
||||
alert('已添加到问题列表');
|
||||
}
|
||||
}
|
||||
|
||||
// 从搜索结果添加为答案
|
||||
function addToAnswer(messageId) {
|
||||
if (!selectedAnswers.includes(messageId)) {
|
||||
selectedAnswers.push(messageId);
|
||||
alert('已添加到答案列表');
|
||||
}
|
||||
}
|
||||
|
||||
// 更新已选择的消息显示
|
||||
function updateSelectedMessages() {
|
||||
document.getElementById('selectedQuestions').innerHTML = selectedQuestions.map(id => `
|
||||
<div class="selected-message">
|
||||
<span>消息ID: ${id}</span>
|
||||
<button class="btn btn-danger" onclick="removeQuestion('${id}')" style="padding: 2px 8px; font-size: 12px;">移除</button>
|
||||
</div>
|
||||
`).join('');
|
||||
|
||||
document.getElementById('selectedAnswers').innerHTML = selectedAnswers.map(id => `
|
||||
<div class="selected-message">
|
||||
<span>消息ID: ${id}</span>
|
||||
<button class="btn btn-danger" onclick="removeAnswer('${id}')" style="padding: 2px 8px; font-size: 12px;">移除</button>
|
||||
</div>
|
||||
`).join('');
|
||||
}
|
||||
|
||||
// 移除问题消息
|
||||
function removeQuestion(messageId) {
|
||||
selectedQuestions = selectedQuestions.filter(id => id !== messageId);
|
||||
updateSelectedMessages();
|
||||
}
|
||||
|
||||
// 移除答案消息
|
||||
function removeAnswer(messageId) {
|
||||
selectedAnswers = selectedAnswers.filter(id => id !== messageId);
|
||||
updateSelectedMessages();
|
||||
}
|
||||
|
||||
// 保存QA记录
|
||||
async function saveQA() {
|
||||
const groupId = document.getElementById('groupId').value.trim();
|
||||
|
||||
if (selectedQuestions.length === 0) {
|
||||
alert('请至少选择一个问题消息');
|
||||
return;
|
||||
}
|
||||
|
||||
if (selectedAnswers.length === 0) {
|
||||
alert('请至少选择一个答案消息');
|
||||
return;
|
||||
}
|
||||
|
||||
const qaData = {
|
||||
groupId: groupId,
|
||||
question: selectedQuestions,
|
||||
answer: selectedAnswers
|
||||
};
|
||||
|
||||
try {
|
||||
const url = currentQA ? `/api/qa/${currentQA.id}` : '/api/qa';
|
||||
const method = currentQA ? 'PUT' : 'POST';
|
||||
|
||||
const response = await fetch(url, {
|
||||
method: method,
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify(qaData)
|
||||
});
|
||||
|
||||
const result = await response.json();
|
||||
|
||||
if (result.success) {
|
||||
alert(currentQA ? 'QA记录更新成功' : 'QA记录创建成功');
|
||||
closeModal();
|
||||
loadQAList();
|
||||
} else {
|
||||
alert('保存失败: ' + result.error);
|
||||
}
|
||||
} catch (error) {
|
||||
alert('保存时出错: ' + error.message);
|
||||
}
|
||||
}
|
||||
|
||||
// 预览QA
|
||||
async function previewQA(qaId) {
|
||||
try {
|
||||
const response = await fetch(`/api/qa/${qaId}`);
|
||||
const result = await response.json();
|
||||
if (result.success) {
|
||||
displayPreview(result.qa);
|
||||
} else {
|
||||
alert('加载QA详情失败: ' + result.error);
|
||||
}
|
||||
} catch (error) {
|
||||
alert('加载QA详情时出错: ' + error.message);
|
||||
}
|
||||
}
|
||||
|
||||
// 显示预览
|
||||
async function displayPreview(qa) {
|
||||
const previewContent = document.getElementById('previewContent');
|
||||
// 获取所有消息的详细内容
|
||||
let allMessages = [];
|
||||
const allMessageIds = [...qa.question_list, ...qa.answer_list];
|
||||
|
||||
if (allMessageIds.length > 0) {
|
||||
try {
|
||||
const response = await fetch('/api/messages_by_ids', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({message_ids: allMessageIds})
|
||||
});
|
||||
const result = await response.json();
|
||||
if (result.success) {
|
||||
allMessages = result.messages;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取消息详情时出错:', error);
|
||||
}
|
||||
}
|
||||
|
||||
// 创建消息映射
|
||||
const messageMap = {};
|
||||
allMessages.forEach(msg => {
|
||||
messageMap[msg.id] = msg;
|
||||
});
|
||||
|
||||
// 按时间排序所有消息
|
||||
const sortedMessages = allMessages.sort((a, b) => {
|
||||
return new Date(a.time) - new Date(b.time);
|
||||
});
|
||||
|
||||
previewContent.innerHTML = `
|
||||
<div class="chat-preview">
|
||||
<div class="chat-header">
|
||||
<h3>QA #${qa.id} - 聊天记录预览</h3>
|
||||
<div class="chat-info">群组: ${qa.groupId || '无群组'} | 消息数量: ${sortedMessages.length}</div>
|
||||
</div>
|
||||
|
||||
<div class="chat-container">
|
||||
${sortedMessages.map(msg => {
|
||||
|
||||
const isQuestion = qa.question_list.includes(msg.id);
|
||||
const isAnswer = qa.answer_list.includes(msg.id);
|
||||
const messageType = isQuestion ? 'question' : (isAnswer ? 'answer' : 'other');
|
||||
|
||||
return `
|
||||
<div class="chat-message ${messageType}">
|
||||
<div class="message-avatar">
|
||||
${messageType === 'question' ? '❓' : (messageType === 'answer' ? '💬' : '📝')}
|
||||
</div>
|
||||
<div class="message-content">
|
||||
<div class="message-header">
|
||||
<span class="sender">${msg.sender || '未知用户'}</span>
|
||||
<span class="time">${msg.formatted_time || '未知时间'}</span>
|
||||
<span class="message-type-badge ${messageType}">${messageType === 'question' ? '问题' : (messageType === 'answer' ? '答案' : '其他')}</span>
|
||||
</div>
|
||||
<div class="message-text">${msg.content || '无内容'}</div>
|
||||
<div class="message-meta">
|
||||
<span class="message-id">消息ID: ${msg.id}</span>
|
||||
<span class="message-type">类型: ${msg.type || '未知'}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
}).join('')}
|
||||
</div>
|
||||
|
||||
<div class="chat-summary">
|
||||
<div class="summary-item">
|
||||
<span class="summary-label">问题数量:</span>
|
||||
<span class="summary-value">${qa.question_list.length}</span>
|
||||
</div>
|
||||
<div class="summary-item">
|
||||
<span class="summary-label">答案数量:</span>
|
||||
<span class="summary-value">${qa.answer_list.length}</span>
|
||||
</div>
|
||||
<div class="summary-item">
|
||||
<span class="summary-label">总消息数:</span>
|
||||
<span class="summary-value">${sortedMessages.length}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
document.getElementById('previewModal').style.display = 'block';
|
||||
}
|
||||
|
||||
// 删除QA
|
||||
async function deleteQA(qaId) {
|
||||
if (!confirm('确定要删除这个QA记录吗?此操作不可恢复。')) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch(`/api/qa/${qaId}`, {
|
||||
method: 'DELETE'
|
||||
});
|
||||
|
||||
const result = await response.json();
|
||||
|
||||
if (result.success) {
|
||||
alert('QA记录删除成功');
|
||||
loadQAList();
|
||||
} else {
|
||||
alert('删除失败: ' + result.error);
|
||||
}
|
||||
} catch (error) {
|
||||
alert('删除时出错: ' + error.message);
|
||||
}
|
||||
}
|
||||
|
||||
// 关闭模态框
|
||||
function closeModal() {
|
||||
document.getElementById('qaModal').style.display = 'none';
|
||||
}
|
||||
|
||||
// 关闭预览模态框
|
||||
function closePreviewModal() {
|
||||
document.getElementById('previewModal').style.display = 'none';
|
||||
}
|
||||
|
||||
// 点击模态框外部关闭
|
||||
window.onclick = function (event) {
|
||||
const modal = document.getElementById('qaModal');
|
||||
const previewModal = document.getElementById('previewModal');
|
||||
|
||||
if (event.target === modal) {
|
||||
modal.style.display = 'none';
|
||||
}
|
||||
if (event.target === previewModal) {
|
||||
previewModal.style.display = 'none';
|
||||
}
|
||||
}
|
||||
146
static/js/weekly_report.js
Normal file
146
static/js/weekly_report.js
Normal file
@@ -0,0 +1,146 @@
|
||||
// 设置默认周次为当前周
|
||||
function getCurrentWeek() {
|
||||
const now = new Date();
|
||||
const startOfYear = new Date(now.getFullYear(), 0, 1);
|
||||
const days = Math.floor((now - startOfYear) / (24 * 60 * 60 * 1000));
|
||||
const weekNumber = Math.ceil((days + 1) / 7);
|
||||
return `${now.getFullYear()}-W${weekNumber.toString().padStart(2, '0')}`;
|
||||
}
|
||||
|
||||
// 页面加载时设置默认周次
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
document.getElementById('week').value = getCurrentWeek();
|
||||
});
|
||||
|
||||
function showLoading() {
|
||||
document.getElementById('loading').style.display = 'block';
|
||||
document.getElementById('report-container').style.display = 'none';
|
||||
document.getElementById('error').style.display = 'none';
|
||||
}
|
||||
|
||||
function hideLoading() {
|
||||
document.getElementById('loading').style.display = 'none';
|
||||
}
|
||||
|
||||
function showError(message) {
|
||||
document.getElementById('error').style.display = 'block';
|
||||
document.getElementById('error').textContent = message;
|
||||
}
|
||||
|
||||
function generateCurrentWeekReport() {
|
||||
document.getElementById('week').value = getCurrentWeek();
|
||||
generateReport();
|
||||
}
|
||||
|
||||
function generateReport() {
|
||||
const week = document.getElementById('week').value;
|
||||
if (!week) {
|
||||
showError('请选择周次');
|
||||
return;
|
||||
}
|
||||
|
||||
// 转换格式:YYYY-WWW 到 YYYY-WW
|
||||
const weekFormatted = week.replace('W', '-W');
|
||||
|
||||
showLoading();
|
||||
|
||||
fetch(`/api/reports/weekly?week=${weekFormatted}`)
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
hideLoading();
|
||||
|
||||
if (data.success) {
|
||||
document.getElementById('report-content').textContent = data.report;
|
||||
document.getElementById('report-container').style.display = 'block';
|
||||
|
||||
// 显示统计数据
|
||||
if (data.statistics) {
|
||||
displayStatistics(data.statistics);
|
||||
document.getElementById('statistics').style.display = 'block';
|
||||
|
||||
// 显示分类图表
|
||||
if (data.statistics.category_breakdown) {
|
||||
displayCategoryChart(data.statistics.category_breakdown);
|
||||
document.getElementById('category-chart').style.display = 'block';
|
||||
}
|
||||
}
|
||||
} else {
|
||||
showError('生成周报失败:' + data.error);
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
hideLoading();
|
||||
showError('网络错误:' + error.message);
|
||||
});
|
||||
}
|
||||
|
||||
function displayStatistics(stats) {
|
||||
const statGrid = document.getElementById('stat-grid');
|
||||
statGrid.innerHTML = '';
|
||||
|
||||
const statistics = [
|
||||
{ label: '本周消息量', value: stats.week_message_count, unit: '条' },
|
||||
{ label: '上周消息量', value: stats.last_week_message_count, unit: '条' },
|
||||
{ label: '消息变化率', value: stats.message_change_rate.toFixed(1), unit: '%' },
|
||||
{ label: '本周活跃用户', value: stats.week_active_users, unit: '人' },
|
||||
{ label: '群组数量', value: stats.group_count, unit: '个' },
|
||||
{ label: '成员总数', value: stats.member_count, unit: '人' },
|
||||
{ label: '问答记录数', value: stats.qa_count, unit: '条' }
|
||||
];
|
||||
|
||||
statistics.forEach(stat => {
|
||||
const statItem = document.createElement('div');
|
||||
statItem.className = 'stat-item';
|
||||
statItem.innerHTML = `
|
||||
<div class="stat-value">${stat.value}${stat.unit}</div>
|
||||
<div class="stat-label">${stat.label}</div>
|
||||
`;
|
||||
statGrid.appendChild(statItem);
|
||||
});
|
||||
}
|
||||
|
||||
function displayCategoryChart(categories) {
|
||||
const categoryItems = document.getElementById('category-items');
|
||||
categoryItems.innerHTML = '';
|
||||
|
||||
Object.entries(categories).forEach(([category, percentage]) => {
|
||||
const categoryItem = document.createElement('div');
|
||||
categoryItem.className = 'category-item';
|
||||
categoryItem.innerHTML = `
|
||||
<span style="min-width: 120px;">${category}</span>
|
||||
<div class="category-bar" style="width: ${percentage * 2}px;"></div>
|
||||
<span style="min-width: 40px; text-align: right;">${percentage}%</span>
|
||||
`;
|
||||
categoryItems.appendChild(categoryItem);
|
||||
});
|
||||
}
|
||||
|
||||
function exportReport() {
|
||||
const reportContent = document.getElementById('report-content').textContent;
|
||||
if (!reportContent) {
|
||||
showError('请先生成周报');
|
||||
return;
|
||||
}
|
||||
|
||||
const blob = new Blob([reportContent], { type: 'text/markdown' });
|
||||
const url = URL.createObjectURL(blob);
|
||||
const a = document.createElement('a');
|
||||
a.href = url;
|
||||
a.download = `运营周报_${document.getElementById('week').value}.md`;
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
document.body.removeChild(a);
|
||||
URL.revokeObjectURL(url);
|
||||
}
|
||||
|
||||
// 页面加载时自动生成本周周报
|
||||
window.addEventListener('load', function() {
|
||||
generateCurrentWeekReport();
|
||||
});
|
||||
|
||||
// 支持回车键生成报告
|
||||
document.getElementById('week').addEventListener('keypress', function(e) {
|
||||
if (e.key === 'Enter') {
|
||||
generateReport();
|
||||
}
|
||||
});
|
||||
50
templates/daily_report.html
Normal file
50
templates/daily_report.html
Normal file
@@ -0,0 +1,50 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>运营日报 - 致远速联</title>
|
||||
<link rel="stylesheet" href="/static/css/daily_report.css">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div class="container">
|
||||
<div class="nav">
|
||||
<a href="/" class="nav-btn">聊天记录</a>
|
||||
<a href="/qa" class="nav-btn">问答管理</a>
|
||||
<a href="/daily_report" class="nav-btn active">日报生成</a>
|
||||
<a href="/weekly_report" class="nav-btn">周报生成</a>
|
||||
</div>
|
||||
|
||||
<div class="header">
|
||||
<h1>运营日报生成器</h1>
|
||||
<p>致远速联高端社群运营数据分析</p>
|
||||
</div>
|
||||
|
||||
<div class="controls">
|
||||
<div class="control-group">
|
||||
<label for="date">选择日期:</label>
|
||||
<input type="date" id="date" value="">
|
||||
<button class="btn" onclick="generateReport()">生成日报</button>
|
||||
<button class="btn" onclick="generateTodayReport()">今日日报</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="report-container" class="report-container" style="display: none;">
|
||||
<div id="report-content" class="report-content"></div>
|
||||
<div id="statistics" class="statistics" style="display: none;">
|
||||
<h3>详细统计数据</h3>
|
||||
<div class="stat-grid" id="stat-grid"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="loading" class="loading" style="display: none;">
|
||||
<p>正在生成日报,请稍候...</p>
|
||||
</div>
|
||||
|
||||
<div id="error" class="error" style="display: none;"></div>
|
||||
</div>
|
||||
|
||||
<script src="/static/js/daily_report.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -4,478 +4,20 @@
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>企业微信聊天记录查看器</title>
|
||||
<style>
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
||||
background-color: #f5f5f5;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.container {
|
||||
max-width: 1200px;
|
||||
margin: 0 auto;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.header {
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: white;
|
||||
padding: 30px;
|
||||
border-radius: 15px;
|
||||
margin-bottom: 30px;
|
||||
box-shadow: 0 10px 30px rgba(0,0,0,0.1);
|
||||
}
|
||||
|
||||
.header h1 {
|
||||
font-size: 2.5em;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.header p {
|
||||
font-size: 1.1em;
|
||||
opacity: 0.9;
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
.nav-links {
|
||||
display: flex;
|
||||
gap: 15px;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.nav-link {
|
||||
background: rgba(255, 255, 255, 0.2);
|
||||
color: white;
|
||||
padding: 8px 16px;
|
||||
border-radius: 20px;
|
||||
text-decoration: none;
|
||||
font-size: 0.9em;
|
||||
transition: all 0.3s ease;
|
||||
border: 1px solid rgba(255, 255, 255, 0.3);
|
||||
}
|
||||
|
||||
.nav-link:hover {
|
||||
background: rgba(255, 255, 255, 0.3);
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 5px 15px rgba(0,0,0,0.2);
|
||||
}
|
||||
|
||||
.stats-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
|
||||
gap: 20px;
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
|
||||
.stat-card {
|
||||
background: white;
|
||||
padding: 25px;
|
||||
border-radius: 12px;
|
||||
box-shadow: 0 5px 15px rgba(0,0,0,0.08);
|
||||
text-align: center;
|
||||
transition: transform 0.3s ease;
|
||||
}
|
||||
|
||||
.stat-card:hover {
|
||||
transform: translateY(-5px);
|
||||
}
|
||||
|
||||
.stat-number {
|
||||
font-size: 2.5em;
|
||||
font-weight: bold;
|
||||
color: #667eea;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
|
||||
.stat-label {
|
||||
color: #666;
|
||||
font-size: 0.9em;
|
||||
}
|
||||
|
||||
.view-switcher {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.view-btn {
|
||||
padding: 10px 20px;
|
||||
border: 2px solid #667eea;
|
||||
background: white;
|
||||
color: #667eea;
|
||||
border-radius: 25px;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s ease;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.view-btn.active {
|
||||
background: #667eea;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.view-btn:hover {
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 5px 15px rgba(102, 126, 234, 0.3);
|
||||
}
|
||||
|
||||
.chat-container {
|
||||
display: grid;
|
||||
grid-template-columns: 300px 1fr;
|
||||
gap: 20px;
|
||||
height: 70vh;
|
||||
}
|
||||
|
||||
.sidebar {
|
||||
background: white;
|
||||
border-radius: 12px;
|
||||
padding: 20px;
|
||||
box-shadow: 0 5px 15px rgba(0,0,0,0.08);
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.sidebar h3 {
|
||||
margin-bottom: 15px;
|
||||
color: #333;
|
||||
border-bottom: 2px solid #667eea;
|
||||
padding-bottom: 10px;
|
||||
}
|
||||
|
||||
.group-list {
|
||||
list-style: none;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.group-item {
|
||||
padding: 15px;
|
||||
margin-bottom: 10px;
|
||||
background: #f8f9fa;
|
||||
border-radius: 8px;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s ease;
|
||||
border-left: 4px solid transparent;
|
||||
}
|
||||
|
||||
.group-item:hover {
|
||||
background: #e9ecef;
|
||||
transform: translateX(5px);
|
||||
}
|
||||
|
||||
.group-item.active {
|
||||
background: #667eea;
|
||||
color: white;
|
||||
border-left-color: #764ba2;
|
||||
}
|
||||
|
||||
.group-name {
|
||||
font-weight: bold;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
|
||||
.group-info {
|
||||
font-size: 0.8em;
|
||||
color: #666;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.group-item.active .group-info {
|
||||
color: rgba(255,255,255,0.8);
|
||||
}
|
||||
|
||||
.chat-area {
|
||||
background: white;
|
||||
border-radius: 12px;
|
||||
box-shadow: 0 5px 15px rgba(0,0,0,0.08);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.chat-header {
|
||||
padding: 20px;
|
||||
border-bottom: 1px solid #eee;
|
||||
background: #f8f9fa;
|
||||
border-radius: 12px 12px 0 0;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.current-group {
|
||||
font-size: 1.2em;
|
||||
font-weight: bold;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.group-stats {
|
||||
font-size: 0.9em;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.chat-messages {
|
||||
flex: 1;
|
||||
overflow-y: auto;
|
||||
overflow-x: hidden;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.message {
|
||||
margin-bottom: 20px;
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
}
|
||||
|
||||
.message.own {
|
||||
flex-direction: row-reverse;
|
||||
}
|
||||
|
||||
.avatar {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
border-radius: 50%;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
color: white;
|
||||
font-weight: bold;
|
||||
margin: 0 10px;
|
||||
}
|
||||
|
||||
.message-content {
|
||||
max-width: 70%;
|
||||
padding: 12px 16px;
|
||||
border-radius: 18px;
|
||||
background: #f1f3f5;
|
||||
position: relative;
|
||||
word-wrap: break-word;
|
||||
overflow-wrap: break-word;
|
||||
white-space: normal;
|
||||
}
|
||||
|
||||
.message.own .message-content {
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.message-sender {
|
||||
font-weight: bold;
|
||||
margin-bottom: 5px;
|
||||
font-size: 0.9em;
|
||||
}
|
||||
|
||||
.message-time {
|
||||
font-size: 0.8em;
|
||||
color: #999;
|
||||
margin-top: 5px;
|
||||
}
|
||||
|
||||
.message.own .message-time {
|
||||
color: rgba(255,255,255,0.8);
|
||||
}
|
||||
|
||||
.controls {
|
||||
padding: 20px;
|
||||
border-top: 1px solid #eee;
|
||||
background: #f8f9fa;
|
||||
border-radius: 0 0 12px 12px;
|
||||
}
|
||||
|
||||
.load-more {
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: white;
|
||||
border: none;
|
||||
padding: 12px 24px;
|
||||
border-radius: 25px;
|
||||
cursor: pointer;
|
||||
font-size: 1em;
|
||||
transition: transform 0.3s ease;
|
||||
}
|
||||
|
||||
.load-more:hover {
|
||||
transform: scale(1.05);
|
||||
}
|
||||
|
||||
.loading {
|
||||
text-align: center;
|
||||
padding: 20px;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.error {
|
||||
background: #ffe6e6;
|
||||
color: #d63031;
|
||||
padding: 10px;
|
||||
border-radius: 8px;
|
||||
margin: 10px 0;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.chat-container {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
.sidebar {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.message-content {
|
||||
max-width: 85%;
|
||||
}
|
||||
}
|
||||
|
||||
body, .container {
|
||||
overflow-x: hidden;
|
||||
}
|
||||
|
||||
/* 聊天记录按钮样式 */
|
||||
.chatrecord-btn {
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: white;
|
||||
border: none;
|
||||
padding: 8px 16px;
|
||||
border-radius: 15px;
|
||||
cursor: pointer;
|
||||
font-size: 0.9em;
|
||||
transition: all 0.3s ease;
|
||||
text-align: left;
|
||||
max-width: 100%;
|
||||
word-wrap: break-word;
|
||||
overflow-wrap: break-word;
|
||||
white-space: normal;
|
||||
}
|
||||
|
||||
.chatrecord-btn:hover {
|
||||
transform: scale(1.05);
|
||||
box-shadow: 0 5px 15px rgba(102, 126, 234, 0.3);
|
||||
}
|
||||
|
||||
/* 模态框样式 */
|
||||
.modal {
|
||||
display: none;
|
||||
position: fixed;
|
||||
z-index: 1000;
|
||||
left: 0;
|
||||
top: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background-color: rgba(0,0,0,0.5);
|
||||
animation: fadeIn 0.3s;
|
||||
}
|
||||
|
||||
.modal-content {
|
||||
background-color: white;
|
||||
margin: 5% auto;
|
||||
padding: 0;
|
||||
border-radius: 15px;
|
||||
width: 80%;
|
||||
max-width: 800px;
|
||||
max-height: 80vh;
|
||||
overflow: hidden;
|
||||
box-shadow: 0 20px 40px rgba(0,0,0,0.2);
|
||||
animation: slideIn 0.3s;
|
||||
}
|
||||
|
||||
.modal-header {
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: white;
|
||||
padding: 20px;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.modal-header h3 {
|
||||
margin: 0;
|
||||
font-size: 1.3em;
|
||||
}
|
||||
|
||||
.close {
|
||||
color: white;
|
||||
font-size: 28px;
|
||||
font-weight: bold;
|
||||
cursor: pointer;
|
||||
transition: opacity 0.3s;
|
||||
}
|
||||
|
||||
.close:hover {
|
||||
opacity: 0.7;
|
||||
}
|
||||
|
||||
.modal-body {
|
||||
padding: 0;
|
||||
max-height: calc(80vh - 80px);
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.chat-record-content {
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.chat-record-item {
|
||||
margin-bottom: 15px;
|
||||
padding: 15px;
|
||||
background: #f8f9fa;
|
||||
border-radius: 10px;
|
||||
border-left: 4px solid #667eea;
|
||||
}
|
||||
|
||||
.chat-record-sender {
|
||||
font-weight: bold;
|
||||
margin-bottom: 5px;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.chat-record-text {
|
||||
margin-bottom: 5px;
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
.chat-record-time {
|
||||
font-size: 0.8em;
|
||||
color: #666;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.chat-record-image {
|
||||
max-width: 200px;
|
||||
max-height: 200px;
|
||||
border-radius: 8px;
|
||||
margin: 5px 0;
|
||||
}
|
||||
|
||||
@keyframes fadeIn {
|
||||
from { opacity: 0; }
|
||||
to { opacity: 1; }
|
||||
}
|
||||
|
||||
@keyframes slideIn {
|
||||
from { transform: translateY(-50px); opacity: 0; }
|
||||
to { transform: translateY(0); opacity: 1; }
|
||||
}
|
||||
|
||||
.container {
|
||||
max-width: 100%;
|
||||
overflow-x: hidden;
|
||||
}
|
||||
</style>
|
||||
<link rel="stylesheet" href="/static/css/index.css">
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="container">
|
||||
<div class="nav-links">
|
||||
<a href="/" class="nav-btn active">聊天记录</a>
|
||||
<a href="/qa" class="nav-btn">问答管理</a>
|
||||
<a href="/daily_report" class="nav-btn">日报生成</a>
|
||||
<a href="/weekly_report" class="nav-btn">周报生成</a>
|
||||
</div>
|
||||
<div class="header">
|
||||
<h1>企业微信聊天记录查看器</h1>
|
||||
<p>基于企业微信会话数据库的实时聊天记录展示</p>
|
||||
<div class="nav-links">
|
||||
<a href="/" class="nav-link">聊天记录</a>
|
||||
<a href="/qa" class="nav-link">问答列表</a>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="stats-grid" id="statsGrid">
|
||||
@@ -498,13 +40,12 @@
|
||||
</div>
|
||||
|
||||
<div class="view-switcher">
|
||||
<button class="view-btn active" onclick="switchView('groups')" id="viewGroups">按群组查看</button>
|
||||
<button class="view-btn active" id="viewGroups">群组列表</button>
|
||||
</div>
|
||||
|
||||
<div class="chat-container">
|
||||
<div class="sidebar">
|
||||
<div id="groupsView">
|
||||
<h3>群组列表</h3>
|
||||
<ul class="group-list" id="groupList">
|
||||
<li>加载中...</li>
|
||||
</ul>
|
||||
@@ -529,10 +70,10 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 聊天记录模态框 -->
|
||||
<div id="chatRecordModal" class="modal">
|
||||
<!-- 聊天记录模态框 -->
|
||||
<div id="chatRecordModal" class="modal">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h3 id="modalTitle">聊天记录</h3>
|
||||
@@ -544,344 +85,8 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
let currentOffset = 0;
|
||||
const limit = 50;
|
||||
let currentView = 'groups';
|
||||
let currentGroupId = null;
|
||||
let groupMessages = [];
|
||||
|
||||
// 页面加载时初始化
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
loadStatistics();
|
||||
loadGroupMessages();
|
||||
loadMessages();
|
||||
});
|
||||
|
||||
// 加载统计信息
|
||||
async function loadStatistics() {
|
||||
try {
|
||||
const response = await fetch('/api/statistics');
|
||||
const data = await response.json();
|
||||
|
||||
if (data.success) {
|
||||
const stats = data.statistics;
|
||||
document.getElementById('userCount').textContent = stats.user_count;
|
||||
document.getElementById('groupCount').textContent = stats.group_count;
|
||||
document.getElementById('messageCount').textContent = stats.message_count;
|
||||
document.getElementById('fileCount').textContent = stats.file_count;
|
||||
document.getElementById('latestTime').textContent = `最新消息时间: ${stats.latest_message_time}`;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('加载统计信息失败:', error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 加载按群组分组的消息统计
|
||||
async function loadGroupMessages() {
|
||||
try {
|
||||
const response = await fetch('/api/group_messages');
|
||||
const data = await response.json();
|
||||
|
||||
const groupList = document.getElementById('groupList');
|
||||
|
||||
if (data.success) {
|
||||
groupMessages = data.groups;
|
||||
groupList.innerHTML = '';
|
||||
|
||||
if (groupMessages.length === 0) {
|
||||
groupList.innerHTML = '<li>暂无群组消息</li>';
|
||||
return;
|
||||
}
|
||||
|
||||
groupMessages.forEach(group => {
|
||||
const li = document.createElement('li');
|
||||
li.className = 'group-item';
|
||||
li.onclick = () => selectGroup(group.group_id);
|
||||
|
||||
const groupName = document.createElement('div');
|
||||
groupName.className = 'group-name';
|
||||
groupName.textContent = group.group_name || group.group_id;
|
||||
|
||||
const groupInfo = document.createElement('div');
|
||||
groupInfo.className = 'group-info';
|
||||
groupInfo.innerHTML = `
|
||||
<span>${group.message_count || 0} 条消息</span>
|
||||
<span>${group.member_count || 0} 人</span>
|
||||
`;
|
||||
|
||||
li.appendChild(groupName);
|
||||
li.appendChild(groupInfo);
|
||||
groupList.appendChild(li);
|
||||
});
|
||||
|
||||
// 默认选择第一个群组
|
||||
if (currentView === 'groups' && groupMessages.length > 0) {
|
||||
selectGroup(groupMessages[0].group_id);
|
||||
}
|
||||
} else {
|
||||
groupList.innerHTML = '<li>加载失败</li>';
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('加载群组消息失败:', error);
|
||||
}
|
||||
}
|
||||
|
||||
// 选择群组
|
||||
function selectGroup(groupId) {
|
||||
currentGroupId = groupId;
|
||||
currentOffset = 0;
|
||||
|
||||
// 更新选中状态
|
||||
const groupItems = document.querySelectorAll('.group-item');
|
||||
groupItems.forEach(item => {
|
||||
item.classList.remove('active');
|
||||
if (item.onclick && item.onclick.toString().includes(groupId)) {
|
||||
item.classList.add('active');
|
||||
}
|
||||
});
|
||||
|
||||
// 更新群组信息
|
||||
const selectedGroup = groupMessages.find(g => g.group_id === groupId);
|
||||
if (selectedGroup) {
|
||||
document.getElementById('currentGroup').textContent = selectedGroup.group_name || selectedGroup.group_id;
|
||||
document.getElementById('messageCountDisplay').textContent = `消息数量: ${selectedGroup.message_count || 0}`;
|
||||
document.getElementById('latestTime').textContent = `最新消息: ${selectedGroup.latest_message_time_formatted || '暂无消息'}`;
|
||||
}
|
||||
|
||||
// 加载该群组的消息
|
||||
loadMessages();
|
||||
}
|
||||
|
||||
// 切换视图(只保留群组视图)
|
||||
function switchView(view) {
|
||||
currentView = view;
|
||||
currentOffset = 0;
|
||||
currentGroupId = null;
|
||||
|
||||
// 更新按钮状态
|
||||
document.getElementById('viewGroups').classList.toggle('active', view === 'groups');
|
||||
|
||||
// 更新聊天区域标题
|
||||
if (view === 'groups') {
|
||||
document.getElementById('currentGroup').textContent = '请选择群组';
|
||||
document.getElementById('messageCountDisplay').textContent = '消息数量: 0';
|
||||
document.getElementById('latestTime').textContent = '最新消息: 暂无';
|
||||
|
||||
// 重置群组选中状态
|
||||
const groupItems = document.querySelectorAll('.group-item');
|
||||
groupItems.forEach(item => item.classList.remove('active'));
|
||||
}
|
||||
|
||||
// 重新加载消息
|
||||
loadMessages();
|
||||
}
|
||||
|
||||
// 加载消息
|
||||
async function loadMessages() {
|
||||
try {
|
||||
let url = `/api/messages?limit=${limit}&offset=${currentOffset}`;
|
||||
|
||||
// 如果是按群组查看,添加群组筛选参数
|
||||
if (currentView === 'groups' && currentGroupId) {
|
||||
url += `&group_id=${currentGroupId}`;
|
||||
}
|
||||
|
||||
const response = await fetch(url);
|
||||
const data = await response.json();
|
||||
|
||||
const chatMessages = document.getElementById('chatMessages');
|
||||
|
||||
if (data.success) {
|
||||
if (currentOffset === 0) {
|
||||
chatMessages.innerHTML = '';
|
||||
}
|
||||
|
||||
if (data.messages.length === 0) {
|
||||
if (currentOffset === 0) {
|
||||
chatMessages.innerHTML = '<div class="loading">暂无消息记录</div>';
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
data.messages.forEach(message => {
|
||||
const messageDiv = createMessageElement(message);
|
||||
chatMessages.appendChild(messageDiv);
|
||||
});
|
||||
|
||||
// 滚动到底部(如果是第一次加载)
|
||||
if (currentOffset === 0) {
|
||||
chatMessages.scrollTop = chatMessages.scrollHeight;
|
||||
}
|
||||
|
||||
currentOffset += data.messages.length;
|
||||
|
||||
} else {
|
||||
chatMessages.innerHTML = '<div class="error">加载消息失败: ' + data.error + '</div>';
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('加载消息失败:', error);
|
||||
document.getElementById('chatMessages').innerHTML = '<div class="error">加载消息失败: ' + error.message + '</div>';
|
||||
}
|
||||
}
|
||||
|
||||
// 创建消息元素
|
||||
function createMessageElement(message) {
|
||||
const messageDiv = document.createElement('div');
|
||||
messageDiv.className = 'message';
|
||||
|
||||
// 这里可以根据需要判断是否是自己的消息
|
||||
// 暂时都显示为接收的消息
|
||||
|
||||
const avatar = document.createElement('div');
|
||||
avatar.className = 'avatar';
|
||||
avatar.textContent = (message.sender_name || message.sender || '?').charAt(0).toUpperCase();
|
||||
|
||||
const contentDiv = document.createElement('div');
|
||||
contentDiv.className = 'message-content';
|
||||
|
||||
const senderDiv = document.createElement('div');
|
||||
senderDiv.className = 'message-sender';
|
||||
senderDiv.textContent = message.sender_name || message.sender || '未知用户';
|
||||
|
||||
const textDiv = document.createElement('div');
|
||||
|
||||
// 处理chatrecord类型的消息
|
||||
if (message.type === 'chatrecord' && message.chatrecord_data) {
|
||||
const chatrecordBtn = document.createElement('button');
|
||||
chatrecordBtn.className = 'chatrecord-btn';
|
||||
chatrecordBtn.textContent = message.display_content || '[聊天记录]';
|
||||
chatrecordBtn.onclick = () => showChatRecordModal(message.chatrecord_data);
|
||||
textDiv.appendChild(chatrecordBtn);
|
||||
} else {
|
||||
textDiv.textContent = message.display_content || message.content || '[空消息]';
|
||||
}
|
||||
|
||||
const timeDiv = document.createElement('div');
|
||||
timeDiv.className = 'message-time';
|
||||
timeDiv.textContent = message.formatted_time || '未知时间';
|
||||
|
||||
contentDiv.appendChild(senderDiv);
|
||||
contentDiv.appendChild(textDiv);
|
||||
contentDiv.appendChild(timeDiv);
|
||||
|
||||
messageDiv.appendChild(avatar);
|
||||
messageDiv.appendChild(contentDiv);
|
||||
|
||||
return messageDiv;
|
||||
}
|
||||
|
||||
// 加载更多消息
|
||||
function loadMoreMessages() {
|
||||
loadMessages();
|
||||
}
|
||||
|
||||
// 显示聊天记录模态框
|
||||
function showChatRecordModal(chatrecordData) {
|
||||
const modal = document.getElementById('chatRecordModal');
|
||||
const modalTitle = document.getElementById('modalTitle');
|
||||
const contentDiv = document.getElementById('chatRecordContent');
|
||||
|
||||
// 设置模态框标题
|
||||
if (chatrecordData.chatrecord && chatrecordData.chatrecord.title) {
|
||||
modalTitle.textContent = chatrecordData.chatrecord.title;
|
||||
} else {
|
||||
modalTitle.textContent = '聊天记录';
|
||||
}
|
||||
|
||||
// 清空内容
|
||||
contentDiv.innerHTML = '';
|
||||
|
||||
// 渲染聊天记录内容
|
||||
if (chatrecordData.chatrecord && chatrecordData.chatrecord.item) {
|
||||
chatrecordData.chatrecord.item.forEach((item, index) => {
|
||||
const itemDiv = document.createElement('div');
|
||||
itemDiv.className = 'chat-record-item';
|
||||
|
||||
try {
|
||||
// 解析消息内容
|
||||
const contentData = JSON.parse(item.content);
|
||||
|
||||
// 创建发送者信息
|
||||
const senderDiv = document.createElement('div');
|
||||
senderDiv.className = 'chat-record-sender';
|
||||
senderDiv.textContent = item.from_chatroom ? '群聊' : '私聊';
|
||||
|
||||
// 创建消息内容
|
||||
const textDiv = document.createElement('div');
|
||||
textDiv.className = 'chat-record-text';
|
||||
|
||||
if (item.type === 'ChatRecordText') {
|
||||
textDiv.textContent = contentData.content || '[文本消息]';
|
||||
} else if (item.type === 'ChatRecordImage') {
|
||||
const imgText = document.createElement('div');
|
||||
imgText.textContent = '[图片]';
|
||||
textDiv.appendChild(imgText);
|
||||
|
||||
if (contentData.sdkfileid) {
|
||||
const img = document.createElement('img');
|
||||
img.className = 'chat-record-image';
|
||||
img.src = `/api/file/${contentData.sdkfileid}`;
|
||||
img.alt = '聊天记录图片';
|
||||
img.onerror = function() {
|
||||
this.style.display = 'none';
|
||||
};
|
||||
textDiv.appendChild(img);
|
||||
}
|
||||
} else {
|
||||
textDiv.textContent = `[${item.type}]`;
|
||||
}
|
||||
|
||||
// 创建时间信息
|
||||
const timeDiv = document.createElement('div');
|
||||
timeDiv.className = 'chat-record-time';
|
||||
if (item.msgtime) {
|
||||
const date = new Date(item.msgtime * 1000);
|
||||
timeDiv.textContent = date.toLocaleString('zh-CN');
|
||||
} else {
|
||||
timeDiv.textContent = '未知时间';
|
||||
}
|
||||
|
||||
itemDiv.appendChild(senderDiv);
|
||||
itemDiv.appendChild(textDiv);
|
||||
itemDiv.appendChild(timeDiv);
|
||||
contentDiv.appendChild(itemDiv);
|
||||
} catch (error) {
|
||||
console.error('解析聊天记录项失败:', error);
|
||||
const errorDiv = document.createElement('div');
|
||||
errorDiv.className = 'chat-record-item';
|
||||
errorDiv.textContent = '[无法解析的消息]';
|
||||
contentDiv.appendChild(errorDiv);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
contentDiv.innerHTML = '<div class="chat-record-item">暂无聊天记录内容</div>';
|
||||
}
|
||||
|
||||
// 显示模态框
|
||||
modal.style.display = 'block';
|
||||
}
|
||||
|
||||
// 关闭聊天记录模态框
|
||||
function closeChatRecordModal() {
|
||||
const modal = document.getElementById('chatRecordModal');
|
||||
modal.style.display = 'none';
|
||||
}
|
||||
|
||||
// 点击模态框外部关闭
|
||||
window.onclick = function(event) {
|
||||
const modal = document.getElementById('chatRecordModal');
|
||||
if (event.target === modal) {
|
||||
closeChatRecordModal();
|
||||
}
|
||||
}
|
||||
|
||||
// 自动刷新统计信息(每30秒)
|
||||
setInterval(loadStatistics, 30000);
|
||||
</script>
|
||||
<script src="/static/js/index.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
1038
templates/qa.html
1038
templates/qa.html
File diff suppressed because it is too large
Load Diff
@@ -1,39 +0,0 @@
|
||||
以下是群中的消息记录
|
||||
|
||||
```json
|
||||
[
|
||||
{"user": "wmAHzSCAAAheHVxal-lGkJVN7H2rLCyg", "time": "1761102279795", "content": "各位老师,这条规定来源哪个文件,有了解的吗,大家一般是严格按这个标准写原因吗"} ,
|
||||
{"user": "wmAHzSCAAAeOuRy3QGoK7g7ACTquBLqQ", "time": "1761102335857", "content": "公告格式里有季报的格式要求"} ,
|
||||
{"user": "wmAHzSCAAAHDp8njcrAkkOPLbaS2B0tw", "time": "1761102409786", "content": "不是写了“主要”两个字[憨笑]"} ,
|
||||
{"user": "wmAHzSCAAAheHVxal-lGkJVN7H2rLCyg", "time": "1761102612486", "content": "好嘞懂了,谢谢各位[抱拳]"} ,
|
||||
{"user": "wmAHzSCAAAheHVxal-lGkJVN7H2rLCyg", "time": "1761119889355", "content": "各位老师,三季报中这块选否的话是不是不用填下边的表了"} ,
|
||||
{"user": "wmAHzSCAAAMUW-BIILUWQpZtE5Pc5xoQ", "time": "1761130830609", "content": "请教一下,在公告编制系统填写股东会通知,股东会召集人没有董事会选项怎么整?"} ,
|
||||
{"user": "wmAHzSCAAArhe26Lm6YQb7Dai0zkZdjQ", "time": "1761131499914", "content": "我之前看是有的"} ,
|
||||
{"user": "wmAHzSCAAAMUW-BIILUWQpZtE5Pc5xoQ", "time": "1761131937412", "content": "今天没了[捂脸]"} ,
|
||||
{"user": "wmAHzSCAAAo1A0E7Lox5KQpNm--NfDjA", "time": "1761132189834", "content": "「300322 张利容:[图片]」\n- - - - - - - - - - - - - - -\n@300174 兰靖 证代 创建公告的这里,需要选择这个。"} ,
|
||||
]
|
||||
```
|
||||
|
||||
找到其中的问题和回答,如果没有回答就只整理问题,问题是与产品填报系统,上市公司,证券政策相关的问题
|
||||
问题可能不只由一句话构成,回答也可能不只由一句话构成
|
||||
多个问题需要分开放置
|
||||
输出格式
|
||||
|
||||
```json
|
||||
[
|
||||
{
|
||||
"question": [{
|
||||
"user": "用户1",
|
||||
"time": "时间戳",
|
||||
"content": "问题"
|
||||
}],
|
||||
"answer": [
|
||||
{
|
||||
"user": "用户1",
|
||||
"time": "时间戳",
|
||||
"content": "回答"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
```
|
||||
54
templates/weekly_report.html
Normal file
54
templates/weekly_report.html
Normal file
@@ -0,0 +1,54 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>运营周报 - 致远速联</title>
|
||||
<link rel="stylesheet" href="/static/css/weekly_report.css">
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="nav">
|
||||
<a href="/" class="nav-btn">聊天记录</a>
|
||||
<a href="/qa" class="nav-btn">问答管理</a>
|
||||
<a href="/daily_report" class="nav-btn">日报生成</a>
|
||||
<a href="/weekly_report" class="nav-btn active">周报生成</a>
|
||||
</div>
|
||||
|
||||
<div class="header">
|
||||
<h1>运营周报生成器</h1>
|
||||
<p>致远速联高端社群运营周度数据分析</p>
|
||||
</div>
|
||||
|
||||
<div class="controls">
|
||||
<div class="control-group">
|
||||
<label for="week">选择周次:</label>
|
||||
<input type="week" id="week" value="">
|
||||
<button class="btn" onclick="generateReport()">生成周报</button>
|
||||
<button class="btn" onclick="generateCurrentWeekReport()">本周周报</button>
|
||||
<button class="export-btn" onclick="exportReport()">导出报告</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="report-container" class="report-container" style="display: none;">
|
||||
<div id="report-content" class="report-content"></div>
|
||||
<div id="statistics" class="statistics" style="display: none;">
|
||||
<h3>详细统计数据</h3>
|
||||
<div class="stat-grid" id="stat-grid"></div>
|
||||
<div id="category-chart" class="category-chart" style="display: none;">
|
||||
<h4>问题分类分布</h4>
|
||||
<div id="category-items"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="loading" class="loading" style="display: none;">
|
||||
<p>正在生成周报,请稍候...</p>
|
||||
</div>
|
||||
|
||||
<div id="error" class="error" style="display: none;"></div>
|
||||
</div>
|
||||
|
||||
<script src="/static/js/weekly_report.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
329
tools.py
Normal file
329
tools.py
Normal file
@@ -0,0 +1,329 @@
|
||||
import time
|
||||
import datetime
|
||||
from typing import Union, Optional
|
||||
|
||||
|
||||
class TimeUtils:
|
||||
"""
|
||||
时间工具类
|
||||
支持时间戳、时间字符串等多种格式的时间处理,以及相互转换和时间计算
|
||||
"""
|
||||
|
||||
# 常用时间格式
|
||||
FORMAT_DATETIME = "%Y-%m-%d %H:%M:%S"
|
||||
FORMAT_DATE = "%Y-%m-%d"
|
||||
FORMAT_TIME = "%H:%M:%S"
|
||||
FORMAT_DATETIME_COMPACT = "%Y%m%d%H%M%S"
|
||||
FORMAT_DATE_COMPACT = "%Y%m%d"
|
||||
|
||||
def __init__(self, time_input: Optional[Union[str, int, float, datetime.datetime]] = None):
|
||||
"""
|
||||
初始化时间工具
|
||||
|
||||
Args:
|
||||
time_input: 时间输入,可以是:
|
||||
- 时间戳(整数或浮点数)
|
||||
- 时间字符串(支持多种格式)
|
||||
- datetime对象
|
||||
- None(使用当前时间)
|
||||
"""
|
||||
if time_input is None:
|
||||
self.datetime_obj = datetime.datetime.now()
|
||||
elif isinstance(time_input, (int, float)):
|
||||
self.datetime_obj = datetime.datetime.fromtimestamp(time_input)
|
||||
elif isinstance(time_input, str):
|
||||
self.datetime_obj = self._parse_string(time_input)
|
||||
elif isinstance(time_input, datetime.datetime):
|
||||
self.datetime_obj = time_input
|
||||
else:
|
||||
raise ValueError(f"不支持的时间输入类型: {type(time_input)}")
|
||||
|
||||
def _parse_string(self, time_str: str) -> datetime.datetime:
|
||||
"""
|
||||
解析时间字符串,支持多种格式
|
||||
|
||||
Args:
|
||||
time_str: 时间字符串
|
||||
|
||||
Returns:
|
||||
datetime对象
|
||||
"""
|
||||
# 尝试多种格式进行解析
|
||||
formats = [
|
||||
self.FORMAT_DATETIME, # 2023-01-01 12:00:00
|
||||
self.FORMAT_DATE, # 2023-01-01
|
||||
self.FORMAT_DATETIME_COMPACT, # 20230101120000
|
||||
self.FORMAT_DATE_COMPACT, # 20230101
|
||||
"%Y/%m/%d %H:%M:%S", # 2023/01/01 12:00:00
|
||||
"%Y/%m/%d", # 2023/01/01
|
||||
"%Y年%m月%d日 %H时%M分%S秒", # 2023年01月01日 12时00分00秒
|
||||
"%Y年%m月%d日", # 2023年01月01日
|
||||
]
|
||||
|
||||
for fmt in formats:
|
||||
try:
|
||||
return datetime.datetime.strptime(time_str, fmt)
|
||||
except ValueError:
|
||||
continue
|
||||
|
||||
# 如果所有格式都失败,尝试自动解析
|
||||
try:
|
||||
return datetime.datetime.fromisoformat(time_str.replace('Z', '+00:00'))
|
||||
except ValueError:
|
||||
raise ValueError(f"无法解析时间字符串: {time_str}")
|
||||
|
||||
def to_timestamp(self) -> float:
|
||||
"""
|
||||
转换为时间戳
|
||||
|
||||
Returns:
|
||||
时间戳(浮点数)
|
||||
"""
|
||||
return self.datetime_obj.timestamp()
|
||||
|
||||
def to_string(self, fmt: str = FORMAT_DATETIME) -> str:
|
||||
"""
|
||||
转换为字符串格式
|
||||
|
||||
Args:
|
||||
fmt: 时间格式字符串
|
||||
|
||||
Returns:
|
||||
格式化后的时间字符串
|
||||
"""
|
||||
return self.datetime_obj.strftime(fmt)
|
||||
|
||||
def to_datetime(self) -> datetime.datetime:
|
||||
"""
|
||||
转换为datetime对象
|
||||
|
||||
Returns:
|
||||
datetime对象
|
||||
"""
|
||||
return self.datetime_obj
|
||||
|
||||
def add_days(self, days: int) -> 'TimeUtils':
|
||||
"""
|
||||
添加天数
|
||||
|
||||
Args:
|
||||
days: 天数(可以为负数)
|
||||
|
||||
Returns:
|
||||
新的TimeUtils对象
|
||||
"""
|
||||
new_datetime = self.datetime_obj + datetime.timedelta(days=days)
|
||||
return TimeUtils(new_datetime)
|
||||
|
||||
def add_hours(self, hours: int) -> 'TimeUtils':
|
||||
"""
|
||||
添加小时数
|
||||
|
||||
Args:
|
||||
hours: 小时数(可以为负数)
|
||||
|
||||
Returns:
|
||||
新的TimeUtils对象
|
||||
"""
|
||||
new_datetime = self.datetime_obj + datetime.timedelta(hours=hours)
|
||||
return TimeUtils(new_datetime)
|
||||
|
||||
def add_minutes(self, minutes: int) -> 'TimeUtils':
|
||||
"""
|
||||
添加分钟数
|
||||
|
||||
Args:
|
||||
minutes: 分钟数(可以为负数)
|
||||
|
||||
Returns:
|
||||
新的TimeUtils对象
|
||||
"""
|
||||
new_datetime = self.datetime_obj + datetime.timedelta(minutes=minutes)
|
||||
return TimeUtils(new_datetime)
|
||||
|
||||
def add_seconds(self, seconds: int) -> 'TimeUtils':
|
||||
"""
|
||||
添加秒数
|
||||
|
||||
Args:
|
||||
seconds: 秒数(可以为负数)
|
||||
|
||||
Returns:
|
||||
新的TimeUtils对象
|
||||
"""
|
||||
new_datetime = self.datetime_obj + datetime.timedelta(seconds=seconds)
|
||||
return TimeUtils(new_datetime)
|
||||
|
||||
def days_ago(self, days: int) -> 'TimeUtils':
|
||||
"""
|
||||
计算n天前的日期时间
|
||||
|
||||
Args:
|
||||
days: 天数
|
||||
|
||||
Returns:
|
||||
新的TimeUtils对象
|
||||
"""
|
||||
return self.add_days(-days)
|
||||
|
||||
def days_after(self, days: int) -> 'TimeUtils':
|
||||
"""
|
||||
计算n天后的日期时间
|
||||
|
||||
Args:
|
||||
days: 天数
|
||||
|
||||
Returns:
|
||||
新的TimeUtils对象
|
||||
"""
|
||||
return self.add_days(days)
|
||||
|
||||
def start_of_day(self) -> 'TimeUtils':
|
||||
"""
|
||||
获取当天的开始时间(00:00:00)
|
||||
|
||||
Returns:
|
||||
新的TimeUtils对象
|
||||
"""
|
||||
new_datetime = self.datetime_obj.replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
return TimeUtils(new_datetime)
|
||||
|
||||
def end_of_day(self) -> 'TimeUtils':
|
||||
"""
|
||||
获取当天的结束时间(23:59:59)
|
||||
|
||||
Returns:
|
||||
新的TimeUtils对象
|
||||
"""
|
||||
new_datetime = self.datetime_obj.replace(hour=23, minute=59, second=59, microsecond=999999)
|
||||
return TimeUtils(new_datetime)
|
||||
|
||||
def diff_seconds(self, other: 'TimeUtils') -> float:
|
||||
"""
|
||||
计算两个时间的秒数差
|
||||
|
||||
Args:
|
||||
other: 另一个TimeUtils对象
|
||||
|
||||
Returns:
|
||||
秒数差(self - other)
|
||||
"""
|
||||
return (self.datetime_obj - other.datetime_obj).total_seconds()
|
||||
|
||||
def diff_days(self, other: 'TimeUtils') -> float:
|
||||
"""
|
||||
计算两个时间的天数差
|
||||
|
||||
Args:
|
||||
other: 另一个TimeUtils对象
|
||||
|
||||
Returns:
|
||||
天数差(self - other)
|
||||
"""
|
||||
return (self.datetime_obj - other.datetime_obj).days
|
||||
|
||||
def is_after(self, other: 'TimeUtils') -> bool:
|
||||
"""
|
||||
判断是否在另一个时间之后
|
||||
|
||||
Args:
|
||||
other: 另一个TimeUtils对象
|
||||
|
||||
Returns:
|
||||
bool值
|
||||
"""
|
||||
return self.datetime_obj > other.datetime_obj
|
||||
|
||||
def is_before(self, other: 'TimeUtils') -> bool:
|
||||
"""
|
||||
判断是否在另一个时间之前
|
||||
|
||||
Args:
|
||||
other: 另一个TimeUtils对象
|
||||
|
||||
Returns:
|
||||
bool值
|
||||
"""
|
||||
return self.datetime_obj < other.datetime_obj
|
||||
|
||||
def is_same_day(self, other: 'TimeUtils') -> bool:
|
||||
"""
|
||||
判断是否在同一天
|
||||
|
||||
Args:
|
||||
other: 另一个TimeUtils对象
|
||||
|
||||
Returns:
|
||||
bool值
|
||||
"""
|
||||
return (self.datetime_obj.year == other.datetime_obj.year and
|
||||
self.datetime_obj.month == other.datetime_obj.month and
|
||||
self.datetime_obj.day == other.datetime_obj.day)
|
||||
|
||||
def format_custom(self, fmt: str) -> str:
|
||||
"""
|
||||
自定义格式化输出
|
||||
|
||||
Args:
|
||||
fmt: 格式化字符串
|
||||
|
||||
Returns:
|
||||
格式化后的字符串
|
||||
"""
|
||||
return self.datetime_obj.strftime(fmt)
|
||||
|
||||
def __str__(self) -> str:
|
||||
"""字符串表示"""
|
||||
return self.to_string()
|
||||
|
||||
def __repr__(self) -> str:
|
||||
"""repr表示"""
|
||||
return f"TimeUtils('{self.to_string()}')"
|
||||
|
||||
|
||||
# 工具函数
|
||||
def now() -> TimeUtils:
|
||||
"""获取当前时间的TimeUtils对象"""
|
||||
return TimeUtils()
|
||||
|
||||
|
||||
def from_timestamp(timestamp: Union[int, float]) -> TimeUtils:
|
||||
"""从时间戳创建TimeUtils对象"""
|
||||
return TimeUtils(timestamp)
|
||||
|
||||
|
||||
def from_string(time_str: str) -> TimeUtils:
|
||||
"""从时间字符串创建TimeUtils对象"""
|
||||
return TimeUtils(time_str)
|
||||
|
||||
|
||||
def from_datetime(dt: datetime.datetime) -> TimeUtils:
|
||||
"""从datetime对象创建TimeUtils对象"""
|
||||
return TimeUtils(dt)
|
||||
|
||||
|
||||
def get_timestamp() -> float:
|
||||
"""获取当前时间戳"""
|
||||
return time.time()
|
||||
|
||||
|
||||
def format_timestamp(timestamp: Union[int, float], fmt: str = TimeUtils.FORMAT_DATETIME) -> str:
|
||||
"""格式化时间戳"""
|
||||
return TimeUtils(timestamp).to_string(fmt)
|
||||
|
||||
|
||||
def parse_string(time_str: str) -> datetime.datetime:
|
||||
"""解析时间字符串为datetime对象"""
|
||||
return TimeUtils(time_str).to_datetime()
|
||||
|
||||
|
||||
def days_ago(days: int, base_time: Optional[Union[str, int, float, datetime.datetime]] = None) -> TimeUtils:
|
||||
"""计算n天前的日期时间"""
|
||||
base = TimeUtils(base_time) if base_time else now()
|
||||
return base.days_ago(days)
|
||||
|
||||
|
||||
def days_after(days: int, base_time: Optional[Union[str, int, float, datetime.datetime]] = None) -> TimeUtils:
|
||||
"""计算n天后的日期时间"""
|
||||
base = TimeUtils(base_time) if base_time else now()
|
||||
return base.days_after(days)
|
||||
Reference in New Issue
Block a user