2 Cometimentos

Autor SHA1 Mensagem Data
  yaoq b43475b09c Merge remote-tracking branch 'origin/4.0' into 4.0 há 2 anos
  yaoq 12dc05d38b canal集成 há 2 anos
3 ficheiros alterados com 50 adições e 7 eliminações
  1. +17
    -1
      smtweb-framework/canal/file/src/main/java/cc/smtweb/system/canal/file/common/AbstractFileWork.java
  2. +27
    -1
      smtweb-framework/canal/file/src/main/java/cc/smtweb/system/canal/file/impl/KbSqlFileWork.java
  3. +6
    -5
      smtweb-framework/canal/file/src/main/resources/config/application.yaml

+ 17
- 1
smtweb-framework/canal/file/src/main/java/cc/smtweb/system/canal/file/common/AbstractFileWork.java Ver ficheiro

@@ -18,6 +18,7 @@ import java.util.*;
@Component
public abstract class AbstractFileWork {
private final static String suffix = ".cf";
protected final static String idField = "idField";

protected FileDecodeConfig fileConfig;

@@ -136,7 +137,7 @@ public abstract class AbstractFileWork {
sql.append("?").append(",");
String value = data.get(field);
if (StringUtils.isEmpty(value)) {
value = null;
args.add(null);
} else {
args.add(value);
}
@@ -170,4 +171,19 @@ public abstract class AbstractFileWork {
protected void doDeleteSql(CanalVO canalVO) {
getDbEngine().update("delete from " + canalVO.getTableName() + " where " + canalVO.getIdField() + " = ? ", canalVO.getId());
}

protected Map<String, String> decodeCreateSql(String sql) {
Map<String, String> map = new HashMap<>();
String data = sql.substring(sql.indexOf("(") + 1, sql.lastIndexOf(")")).trim().replaceAll("`", "");
String[] rows = data.split(",");
for (String row : rows) {
if (row.contains("PRIMARY KEY")) {
map.put(idField, row.substring(row.indexOf("(") + 1, row.lastIndexOf(")")));
continue;
}
String[] fields = row.trim().split(" ");
map.put(fields[0], fields[1]);
}
return map;
}
}

+ 27
- 1
smtweb-framework/canal/file/src/main/java/cc/smtweb/system/canal/file/impl/KbSqlFileWork.java Ver ficheiro

@@ -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;
}
}

+ 6
- 5
smtweb-framework/canal/file/src/main/resources/config/application.yaml Ver ficheiro

@@ -6,7 +6,7 @@ smtweb:
debug: true
code-java-path: 'd:/work/smtweb2/smtweb-framework/canal/file'
db:
type: mysql
type: kbsql
default:
rule:
prefix: _smt_
@@ -33,11 +33,12 @@ spring:
port: 6379
password:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
driver-class-name: com.kingbase8.Driver
# url: jdbc:mysql://139.9.38.43:6032/smt?useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&useSSL=false
url: jdbc:mysql://127.0.0.1:3306/tzrs?useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&useSSL=false
username: root
password: root
# url: jdbc:mysql://127.0.0.1:3306/tzrs?useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&useSSL=false
url: jdbc:kingbase8://172.28.123.205:54321/HLJTY?useUnicode=true&amp;characterEncoding=utf-8
username: system
password: system
servlet:
multipart:
max-file-size: 104857600000


Carregando…
Cancelar
Guardar