diff --git a/dsBase/src/main/java/Tools/CopyLib.java b/dsBase/src/main/java/Tools/CopyLib.java deleted file mode 100644 index 03e19ee8..00000000 --- a/dsBase/src/main/java/Tools/CopyLib.java +++ /dev/null @@ -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("恭喜,所有工作成功完成!"); - } -} diff --git a/dsBase/src/main/java/Tools/DatabaseSynchronizer.java b/dsBase/src/main/java/Tools/DatabaseSynchronizer.java deleted file mode 100644 index 2f34b5b8..00000000 --- a/dsBase/src/main/java/Tools/DatabaseSynchronizer.java +++ /dev/null @@ -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 tables = List.of("教基1001", "教基4149", "教基3115", "教基2107","教基2106"); - List 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> 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> 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 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> getTableData(String tableName) throws SQLException { - List> 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 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 columnNames = new ArrayList<>(); - List 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(); - } -} \ No newline at end of file diff --git a/dsBase/src/main/java/Tools/DistributeToUndertow.java b/dsBase/src/main/java/Tools/DistributeToUndertow.java deleted file mode 100644 index f4b2875d..00000000 --- a/dsBase/src/main/java/Tools/DistributeToUndertow.java +++ /dev/null @@ -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 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 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 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); - } -} diff --git a/dsBase/src/main/java/Tools/Init/InitOrgPerson.java b/dsBase/src/main/java/Tools/Init/InitOrgPerson.java index 88992bdd..14ce294b 100644 --- a/dsBase/src/main/java/Tools/Init/InitOrgPerson.java +++ b/dsBase/src/main/java/Tools/Init/InitOrgPerson.java @@ -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); diff --git a/dsBase/src/main/java/Tools/Init/clearDataBase.java b/dsBase/src/main/java/Tools/Init/clearDataBase.java index 3758eed2..9c793551 100644 --- a/dsBase/src/main/java/Tools/Init/clearDataBase.java +++ b/dsBase/src/main/java/Tools/Init/clearDataBase.java @@ -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); } } diff --git a/dsBase/src/main/java/com/dsideal/dsBase/Util/PkUtil.java b/dsBase/src/main/java/com/dsideal/dsBase/Util/PkUtil.java index 49e8995c..5f5d298f 100644 --- a/dsBase/src/main/java/com/dsideal/dsBase/Util/PkUtil.java +++ b/dsBase/src/main/java/com/dsideal/dsBase/Util/PkUtil.java @@ -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); } diff --git a/dsBase/src/main/resources/Sql/ClearDataBase.sql b/dsBase/src/main/resources/Sql/ClearDataBase.sql index 20d01622..2264c182 100644 --- a/dsBase/src/main/resources/Sql/ClearDataBase.sql +++ b/dsBase/src/main/resources/Sql/ClearDataBase.sql @@ -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") diff --git a/dsBase/src/main/resources/Sql/organization.sql b/dsBase/src/main/resources/Sql/organization.sql index 7015f993..93464d15 100644 --- a/dsBase/src/main/resources/Sql/organization.sql +++ b/dsBase/src/main/resources/Sql/organization.sql @@ -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")