P0 安全修复: - 修复 DatabaseFieldAdder.java 硬编码密码 → 改为环境变量 - 修复 11 个文件空 catch 块 → 添加日志记录 - 修复 40 个文件 System.out → 改为 SLF4J Logger P1 性能优化: - 启用 Spring Boot Actuator 健康检查 (health/info/metrics) - 为字典数据查询添加 @Cacheable 缓存 P2 测试: - 添加 Convert 工具类单元测试 (10 个测试用例) - 添加 spring-boot-starter-test 依赖 P3 版本升级: - hutool: 5.8.35 → 5.8.36 - httpclient 5.x (跳过, 改动量大) 验证: 编译通过 / 测试通过
50 lines
1.9 KiB
Java
Executable File
50 lines
1.9 KiB
Java
Executable File
package com.openhis.tool;
|
|
|
|
import java.sql.Connection;
|
|
import java.sql.DriverManager;
|
|
import java.sql.Statement;
|
|
|
|
/**
|
|
* Database field adder tool
|
|
*/
|
|
public class DatabaseFieldAdder {
|
|
public static void main(String[] args) {
|
|
String url = System.getenv("DB_URL");
|
|
String username = System.getenv("DB_USERNAME");
|
|
String password = System.getenv("DB_PASSWORD");
|
|
|
|
if (url == null || username == null || password == null) {
|
|
System.err.println("Please set DB_URL, DB_USERNAME, DB_PASSWORD environment variables");
|
|
return;
|
|
}
|
|
|
|
try (Connection conn = DriverManager.getConnection(url, username, password);
|
|
Statement stmt = conn.createStatement()) {
|
|
|
|
// Check if field exists
|
|
String checkSql = "SELECT column_name FROM information_schema.columns " +
|
|
"WHERE table_name = 'adm_healthcare_service' AND column_name = 'practitioner_id'";
|
|
|
|
boolean fieldExists = stmt.executeQuery(checkSql).next();
|
|
|
|
if (!fieldExists) {
|
|
// Add field
|
|
String addSql = "ALTER TABLE \"public\".\"adm_healthcare_service\" " +
|
|
"ADD COLUMN \"practitioner_id\" int8";
|
|
stmt.execute(addSql);
|
|
|
|
// Add comment
|
|
String commentSql = "COMMENT ON COLUMN \"public\".\"adm_healthcare_service\".\"practitioner_id\" IS 'practitioner_id'";
|
|
stmt.execute(commentSql);
|
|
|
|
System.out.println("Successfully added practitioner_id field to adm_healthcare_service table");
|
|
} else {
|
|
System.out.println("practitioner_id field already exists");
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
System.err.println("Error executing SQL: " + e.getMessage());
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
} |