Browse Source

优化

4.0
yaoq 1 year ago
parent
commit
25afb4a7fa
5 changed files with 233 additions and 118 deletions
  1. +6
    -2
      smtweb-framework/canal/file/src/main/java/cc/smtweb/system/canal/file/common/AbstractFileWork.java
  2. +6
    -6
      smtweb-framework/canal/file/src/main/java/cc/smtweb/system/canal/file/impl/KbSqlFileWork.java
  3. +111
    -0
      smtweb-framework/canal/file/src/main/resources/config/application-dev.yaml
  4. +107
    -0
      smtweb-framework/canal/file/src/main/resources/config/application-prod.yaml
  5. +3
    -110
      smtweb-framework/canal/file/src/main/resources/config/application.yaml

+ 6
- 2
smtweb-framework/canal/file/src/main/java/cc/smtweb/system/canal/file/common/AbstractFileWork.java View File

@@ -123,7 +123,7 @@ public abstract class AbstractFileWork {
deleteSize++;
}
}
log.debug("[解析canal文件]:::file:" + file.getName() + " insert size:[" + insertSize + "] update size:[" + updateSize + "] delete size:[" + deleteSize + "] create size:[" + createSize + "] alter size:[" + alterSize + "]" + "drop size:[" + dropSize + "]");
log.debug("[解析canal文件]:::file:" + file.getName() + " insert size:[" + insertSize + "] update size:[" + updateSize + "] delete size:[" + deleteSize + "] create size:[" + createSize + "] alter size:[" + alterSize + "]" + " drop size:[" + dropSize + "]");
}

protected abstract String getDbType();
@@ -221,7 +221,11 @@ 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(",\\n");//data.split(",(?=(?:[^\']*\'[^\']*\')*[^\']*$)", -1);

String[] rows = data.split(",\n");//data.split(",(?=(?:[^\']*\'[^\']*\')*[^\']*$)", -1);
if (rows.length == 1) {
rows = data.split(",\r\n");
}
for (String row : rows) {
//索引不管
if (row.contains("INDEX")) continue;


+ 6
- 6
smtweb-framework/canal/file/src/main/java/cc/smtweb/system/canal/file/impl/KbSqlFileWork.java View File

@@ -52,25 +52,25 @@ public class KbSqlFileWork extends AbstractFileWork {
//添加sql
if (sql.contains("ADD")) {
sb.append("ALTER TABLE public.").append(canalVO.getTableName());
sql = sql.substring(sql.indexOf("ADD COLUMN"));
sql = sql.substring(sql.indexOf("ADD"));
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(",");
sb.append(" ADD if not exists ").append(ss[1]).append(" ").append(ss[2]).append(" ").append(convertFieldType(ss[3])).append(" NULL ").append(",");
}
sb.deleteCharAt(sb.length() - 1);
} else if (sql.contains("DROP")) {
sb.append("ALTER TABLE public.").append(canalVO.getTableName());
sql = sql.substring(sql.indexOf("DROP COLUMN"));
sql = sql.substring(sql.indexOf("DROP"));
String[] sqls = sql.split(",(?=(?:[^\']*\'[^\']*\')*[^\']*$)", -1);
for (String str : sqls) {
String[] ss = str.split(" ");
sb.append(" DROP COLUMN ").append(ss[2]).append(",");
sb.append(" DROP COLUMN IF EXISTS ").append(ss[2]).append(",");
}
sb.deleteCharAt(sb.length() - 1);

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


+ 111
- 0
smtweb-framework/canal/file/src/main/resources/config/application-dev.yaml View File

@@ -0,0 +1,111 @@
smtweb:
machine-id: 1
enable-job: true
bpm:
mode: 1
debug: true
code-java-path: 'd:/work/smtweb2/smtweb-framework/canal/file'
db:
type: kbsql
default:
rule:
prefix: _smt_
replace: smt_
file:
local-path:
url:
# 服务模块
devtools:
restart:
enabled: false # 热部署开关
additional-paths: src/main/java #重启目录
server:
port: 8081
servlet:
context-path:
logging:
level:
root: INFO
cc.smtweb: DEBUG
spring:
redis:
host: 127.0.0.1
port: 6379
password:
database: 9
datasource:
driver-class-name: com.kingbase8.Driver
# url: jdbc:kingbase8://10.176.246.198:54321/pgzx?useUnicode=true&amp;characterEncoding=utf-8
# username: 'zhengxie'
# password: '%TGB6yhn'
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
max-request-size: 10485760000000
cache:
type: caffeine
cache-names:
- core
- bpm
caffeine:
spec: maximumSize=1024,expireAfterWrite=2h

# canal配置
canal:
file:
enable: true
#path: /data/canalFile
path: E:/canalFile

# http 规则配置
http-config:
xss: #xss 规则
checkHeader: false #是否进行header校验
checkParameter: true #是否进行parameter校验
logIs: true #是否记录日志
chain: true #是否中断请求
replace: true #是否开启特殊字符替换
checkUrl: true #是否开启特殊url校验
regex:
# 匹配含有字符: alert( )
- .*[A|a][L|l][E|e][R|r][T|t](.*).*
# 匹配含有字符: window.location
- .*[W|w][I|i][N|n][D|d][O|o][W|w].[L|l][O|o][C|c][A|a][T|t][I|i][O|o][N|n].*
# 匹配含有字符:style = x:ex pression ( )
- .*[S|s][T|t][Y|y][L|l][E|e]\\s*=.*[X|x]:[E|e][X|x].*[P|p][R|r][E|e][S|s]{1,2}[I|i][O|o][N|n]\\s*\\(.*\\).*
# 匹配含有字符: document.cookie
- .*[D|d][O|o][C|c][U|u][M|m][E|e][N|n][T|t].[C|c][O|o]{2}[K|k][I|i][E|e].*
# 匹配含有字符: eval( )
- .*[E|e][V|v][A|a][L|l](.*).*
# 匹配含有字符: unescape()
- .*[U|u][N|n][E|e][S|s][C|c][A|a][P|p][E|e](.*).*
# 匹配含有字符: execscript( )
- .*[E|e][X|x][E|e][C|c][S|s][C|c][R|r][I|i][P|p][T|t](.*).*
# 匹配含有字符: msgbox( )
- .*[M|m][S|s][G|g][B|b][O|o][X|x](.*).*
# 匹配含有字符: confirm( )
- .*[C|c][O|o][N|n][F|f][I|i][R|r][M|m](.*).*
# 匹配含有字符: prompt( )
- .*[P|p][R|r][O|o][M|m][P|p][T|t](.*).*
# 匹配含有字符: <script> </script>
- .*<[S|s][C|c][R|r][I|i][P|p][T|t]>.*.*</[S|s][C|c][R|r][I|i][P|p][T|t]>.*
# 匹配含有字符: </script>
- .*</[S|s][C|c][R|r][I|i][P|p][T|t]>.*
# 匹配含有字符: <script>
- .*<[S|s][C|c][R|r][I|i][P|p][T|t]>.*
res: # 响应头规则
configs:
{
Set-Cookie: Secure; HttpOnly,
Referrer-Policy: origin-when-cross-origin,
X-Frame-Options: SAMEORIGIN,
X-XSS-Protection: 1;mode=block ,
X-Download-Options: SAMEORIGIN ,
X-Content-Type-Options: nosniff ,
Content-Security-Policy: default-src 'self'; img-src 'self' data:; script-src 'self' 'unsafe-inline' 'unsafe-eval' http://localhost:7102 https://localhost:7102; style-src 'self' 'unsafe-inline'; connect-src 'self';font-src 'self' data:; ,
Strict-Transport-Security: max-age=31536000;includeSubDomains ,
X-Permitted-Cross-Domain-Policies: master-only
}

+ 107
- 0
smtweb-framework/canal/file/src/main/resources/config/application-prod.yaml View File

@@ -0,0 +1,107 @@
smtweb:
machine-id: 1
enable-job: true
bpm:
mode: 1
debug: true
code-java-path: 'd:/work/smtweb2/smtweb-framework/canal/file'
db:
type: kbsql
default:
rule:
prefix: _smt_
replace: smt_
file:
local-path:
url:
# 服务模块
devtools:
restart:
enabled: false # 热部署开关
additional-paths: src/main/java #重启目录
server:
port: 8081
servlet:
context-path:
logging:
level:
root: INFO
cc.smtweb: DEBUG
spring:
redis:
host: 127.0.0.1
port: 6379
password:
database: 9
datasource:
driver-class-name: com.kingbase8.Driver
url: jdbc:kingbase8://10.176.246.198:54321/pgzx?useUnicode=true&amp;characterEncoding=utf-8
username: 'zhengxie'
password: '%TGB6yhn'
servlet:
multipart:
max-file-size: 104857600000
max-request-size: 10485760000000
cache:
type: caffeine
cache-names:
- core
- bpm
caffeine:
spec: maximumSize=1024,expireAfterWrite=2h

# canal配置
canal:
file:
enable: true
path: /data/canalFile

# http 规则配置
http-config:
xss: #xss 规则
checkHeader: false #是否进行header校验
checkParameter: true #是否进行parameter校验
logIs: true #是否记录日志
chain: true #是否中断请求
replace: true #是否开启特殊字符替换
checkUrl: true #是否开启特殊url校验
regex:
# 匹配含有字符: alert( )
- .*[A|a][L|l][E|e][R|r][T|t](.*).*
# 匹配含有字符: window.location
- .*[W|w][I|i][N|n][D|d][O|o][W|w].[L|l][O|o][C|c][A|a][T|t][I|i][O|o][N|n].*
# 匹配含有字符:style = x:ex pression ( )
- .*[S|s][T|t][Y|y][L|l][E|e]\\s*=.*[X|x]:[E|e][X|x].*[P|p][R|r][E|e][S|s]{1,2}[I|i][O|o][N|n]\\s*\\(.*\\).*
# 匹配含有字符: document.cookie
- .*[D|d][O|o][C|c][U|u][M|m][E|e][N|n][T|t].[C|c][O|o]{2}[K|k][I|i][E|e].*
# 匹配含有字符: eval( )
- .*[E|e][V|v][A|a][L|l](.*).*
# 匹配含有字符: unescape()
- .*[U|u][N|n][E|e][S|s][C|c][A|a][P|p][E|e](.*).*
# 匹配含有字符: execscript( )
- .*[E|e][X|x][E|e][C|c][S|s][C|c][R|r][I|i][P|p][T|t](.*).*
# 匹配含有字符: msgbox( )
- .*[M|m][S|s][G|g][B|b][O|o][X|x](.*).*
# 匹配含有字符: confirm( )
- .*[C|c][O|o][N|n][F|f][I|i][R|r][M|m](.*).*
# 匹配含有字符: prompt( )
- .*[P|p][R|r][O|o][M|m][P|p][T|t](.*).*
# 匹配含有字符: <script> </script>
- .*<[S|s][C|c][R|r][I|i][P|p][T|t]>.*.*</[S|s][C|c][R|r][I|i][P|p][T|t]>.*
# 匹配含有字符: </script>
- .*</[S|s][C|c][R|r][I|i][P|p][T|t]>.*
# 匹配含有字符: <script>
- .*<[S|s][C|c][R|r][I|i][P|p][T|t]>.*
res: # 响应头规则
configs:
{
Set-Cookie: Secure; HttpOnly,
Referrer-Policy: origin-when-cross-origin,
X-Frame-Options: SAMEORIGIN,
X-XSS-Protection: 1;mode=block ,
X-Download-Options: SAMEORIGIN ,
X-Content-Type-Options: nosniff ,
Content-Security-Policy: default-src 'self'; img-src 'self' data:; script-src 'self' 'unsafe-inline' 'unsafe-eval' http://localhost:7102 https://localhost:7102; style-src 'self' 'unsafe-inline'; connect-src 'self';font-src 'self' data:; ,
Strict-Transport-Security: max-age=31536000;includeSubDomains ,
X-Permitted-Cross-Domain-Policies: master-only
}

+ 3
- 110
smtweb-framework/canal/file/src/main/resources/config/application.yaml View File

@@ -1,111 +1,4 @@
smtweb:
machine-id: 1
enable-job: true
bpm:
mode: 1
debug: true
code-java-path: 'd:/work/smtweb2/smtweb-framework/canal/file'
db:
type: kbsql
default:
rule:
prefix: _smt_
replace: smt_
file:
local-path:
url:
# 服务模块
devtools:
restart:
enabled: false # 热部署开关
additional-paths: src/main/java #重启目录
server:
port: 8081
servlet:
context-path:
logging:
level:
root: INFO
cc.smtweb: DEBUG
spring:
redis:
host: 127.0.0.1
port: 6379
password:
database: 9
datasource:
driver-class-name: com.kingbase8.Driver
url: jdbc:kingbase8://10.176.246.198:54321/pgzx?useUnicode=true&amp;characterEncoding=utf-8
username: 'zhengxie'
password: '%TGB6yhn'
# 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
max-request-size: 10485760000000
cache:
type: caffeine
cache-names:
- core
- bpm
caffeine:
spec: maximumSize=1024,expireAfterWrite=2h

# canal配置
canal:
file:
enable: true
path: /data/canalFile
#path: E:/canalFile

# http 规则配置
http-config:
xss: #xss 规则
checkHeader: false #是否进行header校验
checkParameter: true #是否进行parameter校验
logIs: true #是否记录日志
chain: true #是否中断请求
replace: true #是否开启特殊字符替换
checkUrl: true #是否开启特殊url校验
regex:
# 匹配含有字符: alert( )
- .*[A|a][L|l][E|e][R|r][T|t](.*).*
# 匹配含有字符: window.location
- .*[W|w][I|i][N|n][D|d][O|o][W|w].[L|l][O|o][C|c][A|a][T|t][I|i][O|o][N|n].*
# 匹配含有字符:style = x:ex pression ( )
- .*[S|s][T|t][Y|y][L|l][E|e]\\s*=.*[X|x]:[E|e][X|x].*[P|p][R|r][E|e][S|s]{1,2}[I|i][O|o][N|n]\\s*\\(.*\\).*
# 匹配含有字符: document.cookie
- .*[D|d][O|o][C|c][U|u][M|m][E|e][N|n][T|t].[C|c][O|o]{2}[K|k][I|i][E|e].*
# 匹配含有字符: eval( )
- .*[E|e][V|v][A|a][L|l](.*).*
# 匹配含有字符: unescape()
- .*[U|u][N|n][E|e][S|s][C|c][A|a][P|p][E|e](.*).*
# 匹配含有字符: execscript( )
- .*[E|e][X|x][E|e][C|c][S|s][C|c][R|r][I|i][P|p][T|t](.*).*
# 匹配含有字符: msgbox( )
- .*[M|m][S|s][G|g][B|b][O|o][X|x](.*).*
# 匹配含有字符: confirm( )
- .*[C|c][O|o][N|n][F|f][I|i][R|r][M|m](.*).*
# 匹配含有字符: prompt( )
- .*[P|p][R|r][O|o][M|m][P|p][T|t](.*).*
# 匹配含有字符: <script> </script>
- .*<[S|s][C|c][R|r][I|i][P|p][T|t]>.*.*</[S|s][C|c][R|r][I|i][P|p][T|t]>.*
# 匹配含有字符: </script>
- .*</[S|s][C|c][R|r][I|i][P|p][T|t]>.*
# 匹配含有字符: <script>
- .*<[S|s][C|c][R|r][I|i][P|p][T|t]>.*
res: # 响应头规则
configs:
{
Set-Cookie: Secure; HttpOnly,
Referrer-Policy: origin-when-cross-origin,
X-Frame-Options: SAMEORIGIN,
X-XSS-Protection: 1;mode=block ,
X-Download-Options: SAMEORIGIN ,
X-Content-Type-Options: nosniff ,
Content-Security-Policy: default-src 'self'; img-src 'self' data:; script-src 'self' 'unsafe-inline' 'unsafe-eval' http://localhost:7102 https://localhost:7102; style-src 'self' 'unsafe-inline'; connect-src 'self';font-src 'self' data:; ,
Strict-Transport-Security: max-age=31536000;includeSubDomains ,
X-Permitted-Cross-Domain-Policies: master-only
}
profiles:
active: prod
include: baseparams

Loading…
Cancel
Save