Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
customer-recall
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ai-tools
customer-recall
Commits
bd05440d
Commit
bd05440d
authored
Aug 08, 2025
by
yiling.shen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修复数据库连接和表结构问题;添加表结构检查和自动修复功能
parent
51baad37
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
53 additions
and
27 deletions
+53
-27
auth_system.py
+14
-10
callback_record_mysql.py
+39
-17
No files found.
auth_system.py
View file @
bd05440d
...
@@ -194,17 +194,21 @@ temp_callback_records = {}
...
@@ -194,17 +194,21 @@ temp_callback_records = {}
if
CALLBACK_AVAILABLE
:
if
CALLBACK_AVAILABLE
:
try
:
try
:
# 直接使用环境变量构建数据库配置
# 直接使用环境变量构建数据库配置
db_config
=
{
db_host
=
os
.
getenv
(
'DB_HOST'
,
'mysql'
)
'host'
:
os
.
getenv
(
'DB_HOST'
,
'mysql'
),
db_port
=
int
(
os
.
getenv
(
'DB_PORT'
,
'3306'
))
'port'
:
int
(
os
.
getenv
(
'DB_PORT'
,
'3306'
)),
db_user
=
os
.
getenv
(
'DB_USER'
,
'callback_user'
)
'user'
:
os
.
getenv
(
'DB_USER'
,
'callback_user'
),
db_password
=
os
.
getenv
(
'DB_PASSWORD'
,
''
)
'password'
:
os
.
getenv
(
'DB_PASSWORD'
,
''
),
db_name
=
os
.
getenv
(
'DB_NAME'
,
'callback_system'
)
'database'
:
os
.
getenv
(
'DB_NAME'
,
'callback_system'
),
'charset'
:
'utf8mb4'
}
print
(
f
"尝试连接数据库: {db_config['host']}:{db_config['port']}"
)
print
(
f
"尝试连接数据库: {db_host}:{db_port}"
)
db_manager
=
MySQLCallbackRecordManager
(
db_config
)
db_manager
=
MySQLCallbackRecordManager
(
host
=
db_host
,
port
=
db_port
,
user
=
db_user
,
password
=
db_password
,
database
=
db_name
,
charset
=
'utf8mb4'
)
print
(
"✅ 回访记录数据库管理器初始化成功"
)
print
(
"✅ 回访记录数据库管理器初始化成功"
)
except
Exception
as
e
:
except
Exception
as
e
:
print
(
f
"⚠️ 回访记录数据库管理器初始化失败: {e}"
)
print
(
f
"⚠️ 回访记录数据库管理器初始化失败: {e}"
)
...
...
callback_record_mysql.py
View file @
bd05440d
...
@@ -124,24 +124,46 @@ class MySQLCallbackRecordManager:
...
@@ -124,24 +124,46 @@ class MySQLCallbackRecordManager:
# 连接到指定数据库并创建表
# 连接到指定数据库并创建表
with
self
.
get_connection
()
as
conn
:
with
self
.
get_connection
()
as
conn
:
with
conn
.
cursor
()
as
cursor
:
with
conn
.
cursor
()
as
cursor
:
# 创建回访记录表
# 检查表是否存在
create_table_sql
=
"""
cursor
.
execute
(
"SHOW TABLES LIKE 'callback_records'"
)
CREATE TABLE IF NOT EXISTS callback_records (
table_exists
=
cursor
.
fetchone
()
record_id INT AUTO_INCREMENT PRIMARY KEY COMMENT '记录ID',
case_number VARCHAR(50) NOT NULL COMMENT '病历号',
if
table_exists
:
callback_methods JSON NOT NULL COMMENT '回访方式(JSON格式)',
# 检查表结构
callback_record TEXT NOT NULL COMMENT '回访记录内容',
cursor
.
execute
(
"DESCRIBE callback_records"
)
operator VARCHAR(100) NOT NULL COMMENT '操作员',
columns
=
[
row
[
0
]
for
row
in
cursor
.
fetchall
()]
create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
update_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
# 检查必需的字段
INDEX idx_case_number (case_number),
required_columns
=
[
'record_id'
,
'case_number'
,
'callback_methods'
,
'callback_record'
,
'operator'
,
'create_time'
]
INDEX idx_create_time (create_time),
missing_columns
=
[
col
for
col
in
required_columns
if
col
not
in
columns
]
INDEX idx_operator (operator)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='回访记录表'
if
missing_columns
:
"""
print
(
f
"表结构不完整,缺少字段: {missing_columns}"
)
print
(
"删除旧表并重新创建..."
)
cursor
.
execute
(
"DROP TABLE callback_records"
)
table_exists
=
False
cursor
.
execute
(
create_table_sql
)
if
not
table_exists
:
print
(
"回访记录表创建成功或已存在"
)
# 创建回访记录表
create_table_sql
=
"""
CREATE TABLE callback_records (
record_id INT AUTO_INCREMENT PRIMARY KEY COMMENT '记录ID',
case_number VARCHAR(50) NOT NULL COMMENT '病历号',
callback_methods JSON NOT NULL COMMENT '回访方式(JSON格式)',
callback_record TEXT NOT NULL COMMENT '回访记录内容',
operator VARCHAR(100) NOT NULL COMMENT '操作员',
create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
update_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
INDEX idx_case_number (case_number),
INDEX idx_create_time (create_time),
INDEX idx_operator (operator)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='回访记录表'
"""
cursor
.
execute
(
create_table_sql
)
print
(
"回访记录表创建成功"
)
else
:
print
(
"回访记录表已存在且结构正确"
)
except
Exception
as
e
:
except
Exception
as
e
:
print
(
f
"数据库初始化失败: {e}"
)
print
(
f
"数据库初始化失败: {e}"
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment