yaoq vor 2 Jahren
Ursprung
Commit
6574e4b142
3 geänderte Dateien mit 12 neuen und 15 gelöschten Zeilen
  1. +8
    -2
      smtweb-framework/canal/file/src/main/java/cc/smtweb/system/canal/file/common/AbstractFileWork.java
  2. +0
    -9
      smtweb-framework/canal/file/src/main/java/cc/smtweb/system/canal/file/common/FileDecodeService.java
  3. +4
    -4
      smtweb-framework/canal/file/src/main/java/cc/smtweb/system/canal/file/impl/KbSqlFileWork.java

+ 8
- 2
smtweb-framework/canal/file/src/main/java/cc/smtweb/system/canal/file/common/AbstractFileWork.java Datei anzeigen

@@ -201,7 +201,7 @@ public abstract class AbstractFileWork {
protected Map<String, String> decodeCreateSql(String sql) {
Map<String, String> map = new HashMap<>();
String data = sql.substring(sql.indexOf("(") + 1, sql.lastIndexOf(")")).trim().replaceAll("`", "").replace("\t", "");
String[] rows = data.split(",(?=(?:[^\']*\'[^\']*\')*[^\']*$)", -1);
String[] rows = data.split(",\\n");//data.split(",(?=(?:[^\']*\'[^\']*\')*[^\']*$)", -1);
for (String row : rows) {
//索引不管
if (row.contains("INDEX")) continue;
@@ -209,7 +209,13 @@ public abstract class AbstractFileWork {
map.put(idField, row.substring(row.indexOf("(") + 1, row.lastIndexOf(")")));
continue;
}
String[] fields = row.trim().split(" ");
String str = row.trim();
str = str.substring(0, str.indexOf(" ", str.indexOf(" ") + 1));
if (str.contains("(")) {
str = str.substring(0, str.indexOf("("));
}
String[] fields = str.split(" ");
if (fields.length < 2) continue;
map.put(fields[0], fields[1]);
}
return map;


+ 0
- 9
smtweb-framework/canal/file/src/main/java/cc/smtweb/system/canal/file/common/FileDecodeService.java Datei anzeigen

@@ -29,13 +29,4 @@ public class FileDecodeService extends BaseSysService {
log.error("解析canal文件失败:", e);
}
}

public static void main( String args[] ) {
String sentence = "^pgzx.*\\..*";
Pattern pattern = Pattern.compile(sentence);
Matcher matcher = pattern.matcher("pgzx.tb_sys_job");
Matcher matcher1 = pattern.matcher("pgzx_zx.tb_sys_job");
System.out.println(matcher.find());
System.out.println(matcher1.find());
}
}

+ 4
- 4
smtweb-framework/canal/file/src/main/java/cc/smtweb/system/canal/file/impl/KbSqlFileWork.java Datei anzeigen

@@ -53,7 +53,7 @@ public class KbSqlFileWork extends AbstractFileWork {
if (sql.contains("ADD")) {
sb.append("ALTER TABLE public.").append(canalVO.getTableName());
sql = sql.substring(sql.indexOf("ADD COLUMN"));
String[] sqls = sql.split(",");
String[] sqls = sql.split(",(?=(?:[^\']*\'[^\']*\')*[^\']*$)", -1);
for (String str : sqls) {
String[] ss = str.split(" ");
sb.append(" ADD COLUMN ").append(ss[2]).append(" ").append(convertFieldType(ss[3])).append(" NULL ").append(",");
@@ -62,7 +62,7 @@ public class KbSqlFileWork extends AbstractFileWork {
} else if (sql.contains("DROP")) {
sb.append("ALTER TABLE public.").append(canalVO.getTableName());
sql = sql.substring(sql.indexOf("DROP COLUMN"));
String[] sqls = sql.split(",");
String[] sqls = sql.split(",(?=(?:[^\']*\'[^\']*\')*[^\']*$)", -1);
for (String str : sqls) {
String[] ss = str.split(" ");
sb.append(" DROP COLUMN ").append(ss[2]).append(",");
@@ -71,7 +71,7 @@ public class KbSqlFileWork extends AbstractFileWork {

} else if (sql.contains("CHANGE")) {
sql = sql.substring(sql.indexOf("CHANGE COLUMN"));
String[] sqls = sql.split(",");
String[] sqls = sql.split(",(?=(?:[^\']*\'[^\']*\')*[^\']*$)", -1);
for (String str : sqls) {
String[] ss = str.split(" ");
sb.append("ALTER TABLE public.").append(canalVO.getTableName()).append(" RENAME COLUMN ").append(ss[2]).append(" TO ").append(ss[3]).append(";");
@@ -80,7 +80,7 @@ public class KbSqlFileWork extends AbstractFileWork {
} else if (sql.contains("MODIFY")) {
sb.append("ALTER TABLE public.").append(canalVO.getTableName());
sql = sql.substring(sql.indexOf("MODIFY COLUMN"));
String[] sqls = sql.split(",");
String[] sqls = sql.split(",(?=(?:[^\']*\'[^\']*\')*[^\']*$)", -1);
for (String str : sqls) {
String[] ss = str.split(" ");
sb.append(" ALTER COLUMN ").append(ss[2]).append(" TYPE ").append(convertFieldType(ss[3])).append(",");


Laden…
Abbrechen
Speichern