main
HuangHai 3 months ago
parent 8191d181e8
commit aa2907fc7a

@ -1,41 +0,0 @@
package Tools;
import com.dsideal.dsBase.Util.SSHUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
public class CopyLib {
//在独立的main函数中使用下面的方式进行声明logback对象
private final static Logger log = LoggerFactory.getLogger(CopyLib.class);
public static void main(String[] args) throws Exception {
//主机
String host = "192.168.15.68";
String user = "root";
String pwd = "DsideaL4r5t6y7u!@#";
int port = 22;
//声明SSH对象
SSHUtil ssh = new SSHUtil(user, pwd, host, port);
ssh.connect();
//准备工作
ssh.exec("mkdir -p /usr/local/tomcat8/webapps/dsBase/WEB-INF/lib");
//先删除远程的jar包
ssh.exec("mkdir -p /usr/local/tomcat8/webapps/dsBase/WEB-INF/lib");
String libPath = "D:\\dsWork\\dsBaseJava\\lib";
String targetLibPath = "/usr/local/tomcat8/webapps/dsBase/WEB-INF/lib";
ssh.exec("rm -rf " + targetLibPath + "/*.*");
//上传
File file = new File(libPath);
File[] tempList = file.listFiles();
for (int i = 0; i < tempList.length; i++) {
if (tempList[i].isFile())
ssh.upload(tempList[i].getAbsolutePath(), targetLibPath + "/" + tempList[i].getName());
log.info("成功上传文件" + tempList[i].getName());
}
//断开连接
ssh.disconnect();
log.info("恭喜,所有工作成功完成!");
}
}

@ -1,272 +0,0 @@
package Tools;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;
public class DatabaseSynchronizer {
// 数据库连接配置
private static final String SQLITE_URL = "jdbc:sqlite:D:\\dsWork\\CcsEduData\\数据库与脚本\\edudb_gather_220100000000_full_fullreport.db";
private static final String PG_URL = "jdbc:postgresql://10.10.14.71:5432/szjz_db";
private static final String PG_USER = "postgres";
private static final String PG_PASSWORD = "DsideaL147258369";
public void syncDatabase() {
// 要同步的表名列表
//List<String> tables = List.of("教基1001", "教基4149", "教基3115", "教基2107","教基2106");
List<String> tables = List.of("教基3113");
try {
// 加载数据库驱动
Class.forName("org.sqlite.JDBC");
Class.forName("org.postgresql.Driver");
// 同步每个表
for (String tableName : tables) {
syncTable(tableName);
}
} catch (Exception e) {
e.printStackTrace();
}
}
private void syncTable(String tableName) throws SQLException {
// 获取表结构和数据
TableInfo tableInfo = getTableInfo(tableName);
List<List<Object>> data = getTableData(tableName);
// 在PostgreSQL中创建表并插入数据
createTableInPostgres(tableInfo);
insertDataToPostgres(tableInfo, data);
}
private TableInfo getTableInfo(String tableName) throws SQLException {
TableInfo tableInfo = new TableInfo(tableName);
try (Connection conn = DriverManager.getConnection(SQLITE_URL);
ResultSet rs = conn.getMetaData().getColumns(null, null, tableName, null)) {
while (rs.next()) {
String columnName = rs.getString("COLUMN_NAME");
String sqliteType = rs.getString("TYPE_NAME");
// 转换SQLite类型到PostgreSQL类型
String pgType = convertSqliteTypeToPg(sqliteType);
tableInfo.addColumn(columnName, pgType);
}
}
return tableInfo;
}
private void createTableInPostgres(TableInfo tableInfo) throws SQLException {
StringBuilder createTableSQL = new StringBuilder();
createTableSQL.append("CREATE TABLE IF NOT EXISTS ")
.append(tableInfo.tableName)
.append(" (");
for (int i = 0; i < tableInfo.columnNames.size(); i++) {
if (i > 0) createTableSQL.append(", ");
createTableSQL.append(tableInfo.columnNames.get(i))
.append(" ")
.append(tableInfo.columnTypes.get(i));
}
createTableSQL.append(")");
try (Connection conn = DriverManager.getConnection(PG_URL, PG_USER, PG_PASSWORD);
Statement stmt = conn.createStatement()) {
stmt.execute(createTableSQL.toString());
}
}
private void insertDataToPostgres(TableInfo tableInfo, List<List<Object>> data) throws SQLException {
if (data.isEmpty()) {
System.out.println("没有数据需要插入");
return;
}
try (Connection conn = DriverManager.getConnection(PG_URL, PG_USER, PG_PASSWORD)) {
conn.setAutoCommit(false);
StringBuilder insertSQL = new StringBuilder();
insertSQL.append("INSERT INTO ")
.append(tableInfo.tableName)
.append(" (");
for (int i = 0; i < tableInfo.columnNames.size(); i++) {
if (i > 0) insertSQL.append(", ");
insertSQL.append(tableInfo.columnNames.get(i));
}
insertSQL.append(") VALUES (");
for (int i = 0; i < tableInfo.columnNames.size(); i++) {
if (i > 0) insertSQL.append(", ");
insertSQL.append("?");
}
insertSQL.append(")");
System.out.println("插入SQL: " + insertSQL);
try (PreparedStatement pstmt = conn.prepareStatement(insertSQL.toString())) {
int batchSize = 1000;
int count = 0;
int totalInserted = 0;
for (List<Object> row : data) {
if (row.size() != tableInfo.columnNames.size()) {
System.out.println("警告: 数据行列数不匹配");
continue;
}
for (int i = 0; i < row.size(); i++) {
Object value = row.get(i);
String columnType = tableInfo.columnTypes.get(i).toUpperCase();
try {
if (value == null) {
pstmt.setNull(i + 1, Types.NULL);
}
// 处理数值类型
else if (columnType.contains("DOUBLE") || columnType.contains("NUMERIC") ||
columnType.contains("DECIMAL") || columnType.contains("REAL")) {
if (value instanceof String) {
String strValue = (String) value;
if (strValue.isEmpty()) {
pstmt.setNull(i + 1, Types.DOUBLE);
} else {
try {
pstmt.setDouble(i + 1, Double.parseDouble(strValue));
} catch (NumberFormatException e) {
pstmt.setNull(i + 1, Types.DOUBLE);
System.out.println("警告: 无法转换为数值类型: " + strValue);
}
}
} else if (value instanceof Number) {
pstmt.setDouble(i + 1, ((Number) value).doubleValue());
} else {
pstmt.setNull(i + 1, Types.DOUBLE);
System.out.println("警告: 未知的数值类型: " + value.getClass());
}
}
// 处理整数类型
else if (columnType.contains("INTEGER") || columnType.contains("INT")) {
if (value instanceof String) {
String strValue = (String) value;
if (strValue.isEmpty()) {
pstmt.setNull(i + 1, Types.INTEGER);
} else {
try {
pstmt.setInt(i + 1, Integer.parseInt(strValue));
} catch (NumberFormatException e) {
pstmt.setNull(i + 1, Types.INTEGER);
System.out.println("警告: 无法转换为整数类型: " + strValue);
}
}
} else if (value instanceof Number) {
pstmt.setInt(i + 1, ((Number) value).intValue());
} else {
pstmt.setNull(i + 1, Types.INTEGER);
System.out.println("警告: 未知的整数类型: " + value.getClass());
}
}
// 其他类型当作字符串处理
else {
pstmt.setString(i + 1, value.toString());
}
} catch (Exception e) {
System.out.println("警告: 设置值时出错: 列=" + tableInfo.columnNames.get(i) +
", 值=" + value + ", 类型=" + columnType);
pstmt.setNull(i + 1, Types.NULL);
}
}
pstmt.addBatch();
if (++count % batchSize == 0) {
pstmt.executeBatch();
conn.commit();
totalInserted += count;
count = 0;
System.out.println("已插入 " + totalInserted + " 行");
}
}
if (count > 0) {
pstmt.executeBatch();
conn.commit();
totalInserted += count;
}
System.out.println("总共插入 " + totalInserted + " 行数据");
} catch (SQLException e) {
conn.rollback();
System.out.println("插入数据时出错: " + e.getMessage());
throw e;
}
}
}
// 修改 getTableData 方法,添加调试信息
private List<List<Object>> getTableData(String tableName) throws SQLException {
List<List<Object>> data = new ArrayList<>();
try (Connection conn = DriverManager.getConnection(SQLITE_URL);
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM " + tableName)) {
ResultSetMetaData metaData = rs.getMetaData();
int columnCount = metaData.getColumnCount();
System.out.println("Table: " + tableName + ", Column count: " + columnCount);
for (int i = 1; i <= columnCount; i++) {
System.out.println("Column " + i + ": " + metaData.getColumnName(i) +
" (" + metaData.getColumnTypeName(i) + ")");
}
while (rs.next()) {
List<Object> row = new ArrayList<>();
for (int i = 1; i <= columnCount; i++) {
row.add(rs.getObject(i));
}
data.add(row);
}
System.out.println("Read " + data.size() + " rows from SQLite");
}
return data;
}
private String convertSqliteTypeToPg(String sqliteType) {
// 类型转换映射
return switch (sqliteType.toUpperCase()) {
case "INTEGER" -> "INTEGER";
case "REAL" -> "DOUBLE PRECISION";
case "TEXT" -> "TEXT";
case "BLOB" -> "BYTEA";
default -> "TEXT";
};
}
// 表信息存储类
private static class TableInfo {
String tableName;
List<String> columnNames = new ArrayList<>();
List<String> columnTypes = new ArrayList<>();
TableInfo(String tableName) {
this.tableName = tableName;
}
void addColumn(String name, String type) {
columnNames.add(name);
columnTypes.add(type);
}
}
public static void main(String[] args) {
DatabaseSynchronizer synchronizer = new DatabaseSynchronizer();
synchronizer.syncDatabase();
}
}

@ -1,148 +0,0 @@
package Tools;
import cn.hutool.core.io.file.FileReader;
import cn.hutool.core.io.file.FileWriter;
import com.dsideal.dsBase.Util.SSHUtil;
import com.jfinal.kit.HttpKit;
import com.jfinal.kit.PathKit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class DistributeToUndertow {
//在独立的main函数中使用下面的方式进行声明logback对象
private final static Logger log = LoggerFactory.getLogger(DistributeToUndertow.class);
public static Map<String, String> map = new HashMap<>();
public static void main(String[] args) throws Exception {
//修改undertow Path
//黄海添加于2021-10-29
updateUndertowPath();
//主机
String host = "192.168.15.68";
String user = "root";
String pwd = "DsideaL4r5t6y7u!@#";
int port = 22;
//声明SSH对象
SSHUtil ssh = new SSHUtil(user, pwd, host, port);
ssh.connect();
//准备工作
ssh.exec("mkdir -p /usr/local/tomcat8/webapps/dsBase/WEB-INF/lib");
ssh.exec("echo '' > /usr/local/tomcat8/logs/dsBase.log");
ssh.exec("cd /usr/local/tomcat8/webapps/dsBase/WEB-INF/classes/ && dos2unix *.sh");
ssh.exec("chmod +x /usr/local/tomcat8/webapps/dsBase/WEB-INF/classes/start.sh");
ssh.exec("chmod +x /usr/local/tomcat8/webapps/dsBase/WEB-INF/classes/debug.sh");
ssh.exec("chmod +x /usr/local/tomcat8/webapps/dsBase/WEB-INF/classes/stop.sh");
//源目录
String basePath = PathKit.getRootClassPath();
String[] dirs = new String[]{"\\com", "\\Backup", "\\Plugin", "\\Sql", "\\ExcelExportTemplate", "\\ExcelImportTemplate"};
//目标目录
String targetPath = "/usr/local/tomcat8/webapps/dsBase/WEB-INF/classes";
List<String> uploadDir = new ArrayList<>();
for (int i = 0; i < dirs.length; i++) {
uploadDir.add(basePath + dirs[i]);
}
for (int i = 0; i < dirs.length; i++) {
String deletePath = targetPath + dirs[i].replace("\\", "/");
ssh.exec("rm -rf " + deletePath);
}
//上传配置文件
File file = new File(basePath);
File[] tempList = file.listFiles();
for (int i = 0; i < tempList.length; i++) {
if (tempList[i].isFile())
ssh.upload(tempList[i].getAbsolutePath(), targetPath + "/" + tempList[i].getName());
}
//上传其它目录下的文件
for (int i = 0; i < uploadDir.size(); i++) {
//上传
map.clear();
getFileList(uploadDir.get(i));
for (Map.Entry<String, String> entry : map.entrySet()) {
String fullPath = entry.getKey();
file = new File(fullPath);
String childPath = fullPath.replace(basePath, "").replace("\\", "/").replace(file.getName(), "");
ssh.mkdir(targetPath + childPath);
ssh.upload(file.getAbsolutePath(), targetPath + childPath+"/" + file.getName());
log.info("成功上传文件:" + fullPath);
}
}
//重启undertow
ssh.exec("ps aux | grep \"tail\" |grep -v grep| cut -c 9-15 | xargs kill -9");
ssh.exec("cd /usr/local/tomcat8/webapps/dsBase/WEB-INF/classes && dos2unix *.sh");
ssh.exec("cd /usr/local/tomcat8/webapps/dsBase/WEB-INF/classes && ./stop.sh");
Thread.sleep(3000);
ssh.exec("cd /usr/local/tomcat8/webapps/dsBase/WEB-INF/classes && ./start.sh");
//检查是不是启动成功了
while (true) {
try {
log.info("正在等待undertow启动...");
HttpKit.get("http://" + host);
break;
} catch (Exception err) {
Thread.sleep(500);
}
}
//断开连接
ssh.disconnect();
log.info("恭喜,所有工作成功完成!");
}
/**
*
*
* 2018-12-14
*
* @param strPath
* @return
*/
public static void getFileList(String strPath) {
File f = new File(strPath);
if (f.isDirectory()) {
File[] fs = f.listFiles();
for (int i = 0; i < fs.length; i++) {
String fsPath = fs[i].getAbsolutePath();
getFileList(fsPath);
}
} else if (f.isFile()) {
String fsPath = f.getAbsolutePath();
map.put(fsPath, "1");
} else {
log.error("路径不正确!" + f.getAbsolutePath());
}
}
/**
* undertowPath
*/
public static void updateUndertowPath() {
String fileName = "undertow.properties";
FileReader fileReader = new FileReader(fileName);
String result = fileReader.readString();
String lines[] = result.split("\\r?\\n");
String finalStr = "";
final String oldStr = "#undertow.resourcePath";
final String newStr = "undertow.resourcePath";
for (String line : lines) {
if (line.startsWith(oldStr)) {
} else if (line.startsWith(newStr))
finalStr += "undertow.resourcePath =/usr/local/tomcat8/webapps/dsBase,classpath:static\n";
else
finalStr += line + "\n";
}
//写入
FileWriter writer = new FileWriter(fileName);
writer.write(finalStr);
}
}

@ -83,8 +83,7 @@ public class InitOrgPerson {
*
* 2018-12-21
*/
public static void generateUser(int identity_id, String person_name, String city_id, String area_id, int sort_id, String operator,String org_id)
throws Exception {
public static void generateUser(int identity_id, String person_name, String city_id, String area_id, int sort_id, String operator,String org_id) {
Record record = new Record();
String person_id = UUID.randomUUID().toString().toUpperCase();
record.set("person_id", person_id);

@ -114,8 +114,7 @@ public class clearDataBase {
*
* 2018-12-21
*/
public static void generateUser(int identity_id, String person_name, String city_id, String area_id, int sort_id, String operator,String org_id)
throws Exception {
public static void generateUser(int identity_id, String person_name, String city_id, String area_id, int sort_id, String operator,String org_id) {
Record record = new Record();
String person_id = UUID.randomUUID().toString().toUpperCase();
record.set("person_id", person_id);
@ -143,7 +142,7 @@ public class clearDataBase {
record.set("org_id", org_id);
record.set("operator", operator);
record.set("ip_address", 2130706433); //127.0.0.1
Db.save("t_sys_loginperson", record);
Db.save("t_sys_loginperson","person_id", record);
}
}

@ -44,7 +44,8 @@ public class PkUtil {
RedisKit.Del("org_pk_num");
String sql = Db.getSql("organization.getMaxPkByOrg");
Record record = Db.findFirst(sql);
int org_pk_num = record.getInt("org_pk_num");
int org_pk_num = 0;
if (record != null && record.get("org_pk_num") != null) org_pk_num = record.getInt("org_pk_num");
RedisKit.incrBy("org_pk_num", org_pk_num);
}

@ -6,10 +6,8 @@
truncate table t_import_student_by_excel;
truncate table t_import_teacher_by_excel;
truncate table t_person_duty;
truncate table t_sys_account_mount;
truncate table t_transfer_apply;
truncate table t_sys_loginperson;
truncate table t_base_app_visiable;
#end
#sql("set_install_area")

@ -3,7 +3,7 @@
-- 获取组织机构的最大主键号
#sql("getMaxPkByOrg")
select id_int as org_pk_num from t_base_organization
select max(id_int) as org_pk_num from t_base_organization
#end
-- 获取指定单位或组织机构的信息
#sql("getOrgInfoById")

Loading…
Cancel
Save