|
|
@@ -3,12 +3,16 @@ package cc.smtweb.system.canal.file.impl; |
|
|
|
import cc.smtweb.framework.core.common.CanalVO; |
|
|
|
import cc.smtweb.framework.core.common.SwEnum; |
|
|
|
import cc.smtweb.system.canal.file.common.AbstractFileWork; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
/** |
|
|
|
* @Author yaoq |
|
|
|
* @Date 2022年09月20日 10:29 |
|
|
|
* @Description |
|
|
|
*/ |
|
|
|
@Slf4j |
|
|
|
public class KbSqlFileWork extends AbstractFileWork { |
|
|
|
|
|
|
|
@Override |
|
|
@@ -18,11 +22,33 @@ public class KbSqlFileWork extends AbstractFileWork { |
|
|
|
|
|
|
|
@Override |
|
|
|
protected void doCreateSql(CanalVO canalVO) { |
|
|
|
|
|
|
|
Map<String, String> sqlMap = decodeCreateSql(canalVO.getSql()); |
|
|
|
StringBuilder sql = new StringBuilder(); |
|
|
|
sql.append("create table public.").append(canalVO.getTableName()).append(" ( "); |
|
|
|
sqlMap.forEach((k, v) -> { |
|
|
|
if (idField.equals(k)) return; |
|
|
|
sql.append(k).append(" ").append(convertFieldType(v)); |
|
|
|
if (k.equals(sqlMap.get(idField))) { |
|
|
|
sql.append(" ").append("NOT NULL DEFAULT -1"); |
|
|
|
} else { |
|
|
|
sql.append(" ").append("NULL"); |
|
|
|
} |
|
|
|
sql.append(","); |
|
|
|
}); |
|
|
|
sql.append(" CONSTRAINT pk_").append(canalVO.getTableName()).append(" PRIMARY KEY (").append(sqlMap.get(idField)).append(") ENABLE VALIDATE ) "); |
|
|
|
log.debug("sql:::" + sql); |
|
|
|
getDbEngine().update(sql.toString()); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
protected void doAlterSql(CanalVO canalVO) { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private String convertFieldType(String type) { |
|
|
|
if (type.contains("bigint")) return "bigint"; |
|
|
|
if (type.contains("tinyint")) return "tinyint"; |
|
|
|
return type; |
|
|
|
} |
|
|
|
} |