diff --git a/smtweb-framework/canal/file/src/main/java/cc/smtweb/system/canal/file/common/AbstractFileWork.java b/smtweb-framework/canal/file/src/main/java/cc/smtweb/system/canal/file/common/AbstractFileWork.java index 4f71826..fdc6483 100644 --- a/smtweb-framework/canal/file/src/main/java/cc/smtweb/system/canal/file/common/AbstractFileWork.java +++ b/smtweb-framework/canal/file/src/main/java/cc/smtweb/system/canal/file/common/AbstractFileWork.java @@ -201,7 +201,7 @@ public abstract class AbstractFileWork { protected Map decodeCreateSql(String sql) { Map 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; diff --git a/smtweb-framework/canal/file/src/main/java/cc/smtweb/system/canal/file/common/FileDecodeService.java b/smtweb-framework/canal/file/src/main/java/cc/smtweb/system/canal/file/common/FileDecodeService.java index 299e298..22d5eb8 100644 --- a/smtweb-framework/canal/file/src/main/java/cc/smtweb/system/canal/file/common/FileDecodeService.java +++ b/smtweb-framework/canal/file/src/main/java/cc/smtweb/system/canal/file/common/FileDecodeService.java @@ -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()); - } } diff --git a/smtweb-framework/canal/file/src/main/java/cc/smtweb/system/canal/file/impl/KbSqlFileWork.java b/smtweb-framework/canal/file/src/main/java/cc/smtweb/system/canal/file/impl/KbSqlFileWork.java index 7bbec9f..a2ced51 100644 --- a/smtweb-framework/canal/file/src/main/java/cc/smtweb/system/canal/file/impl/KbSqlFileWork.java +++ b/smtweb-framework/canal/file/src/main/java/cc/smtweb/system/canal/file/impl/KbSqlFileWork.java @@ -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(",");