Unverified Commit 946a9582 authored by ZackYoung's avatar ZackYoung Committed by GitHub

[Fix] fix_pg & sms_alert & SystemConfiguration (#2047)

* fix_pg & sms_alert & SystemConfiguration * fix_pg & sms_alert & SystemConfiguration * fix_pg & sms_alert & SystemConfiguration * fix_pg & sms_alert & SystemConfiguration * fix_pg & sms_alert & SystemConfiguration
parent 3ba2338d
...@@ -20,6 +20,9 @@ ...@@ -20,6 +20,9 @@
package org.dinky.configure; package org.dinky.configure;
import org.dinky.context.TenantContextHolder; import org.dinky.context.TenantContextHolder;
import org.dinky.data.annotation.ConditionalOnListProperty;
import org.dinky.interceptor.PostgreSQLPrepareInterceptor;
import org.dinky.interceptor.PostgreSQLQueryInterceptor;
import org.dinky.mybatis.handler.DateMetaObjectHandler; import org.dinky.mybatis.handler.DateMetaObjectHandler;
import org.dinky.mybatis.properties.MybatisPlusFillProperties; import org.dinky.mybatis.properties.MybatisPlusFillProperties;
...@@ -77,6 +80,25 @@ public class MybatisPlusConfig { ...@@ -77,6 +80,25 @@ public class MybatisPlusConfig {
"dinky_git_project", "dinky_git_project",
"dinky_task_version"); "dinky_task_version");
@Bean
// @ConditionalOnProperty(name = "spring.profiles.active", havingValue = "pgsql , jmx")
@ConditionalOnListProperty(name = "spring.profiles.active", havingValue = "pgsql")
public PostgreSQLQueryInterceptor postgreSQLQueryInterceptor() {
return new PostgreSQLQueryInterceptor();
}
/**
* Add the plugin to the MyBatis plugin interceptor chain.
*
* @return {@linkplain PostgreSQLPrepareInterceptor}
*/
@Bean
// @ConditionalOnProperty(name = "spring.profiles.active", havingValue = "pgsql , jmx")
@ConditionalOnListProperty(name = "spring.profiles.active", havingValue = "pgsql")
public PostgreSQLPrepareInterceptor postgreSQLPrepareInterceptor() {
return new PostgreSQLPrepareInterceptor();
}
@Bean @Bean
public MybatisPlusInterceptor mybatisPlusInterceptor() { public MybatisPlusInterceptor mybatisPlusInterceptor() {
log.info("mybatis plus interceptor execute"); log.info("mybatis plus interceptor execute");
......
/*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.dinky.data.annotation;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.util.Arrays;
import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.context.annotation.Conditional;
import org.springframework.core.type.AnnotatedTypeMetadata;
@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Conditional(CustomListCondition.class)
public @interface ConditionalOnListProperty {
String name();
String havingValue();
}
class CustomListCondition implements Condition {
@Override
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
String propertyName =
(String)
metadata.getAnnotationAttributes(ConditionalOnListProperty.class.getName())
.get("name");
String requiredValue =
(String)
metadata.getAnnotationAttributes(ConditionalOnListProperty.class.getName())
.get("havingValue");
String[] propertyValues =
context.getEnvironment().getProperty(propertyName, String[].class);
return Arrays.asList(propertyValues).contains(requiredValue);
}
}
/*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.dinky.interceptor;
import org.apache.ibatis.executor.statement.StatementHandler;
import org.apache.ibatis.mapping.BoundSql;
import org.apache.ibatis.plugin.Interceptor;
import org.apache.ibatis.plugin.Intercepts;
import org.apache.ibatis.plugin.Invocation;
import org.apache.ibatis.plugin.Plugin;
import org.apache.ibatis.plugin.Signature;
import java.lang.reflect.Field;
import java.sql.Connection;
import java.util.Properties;
@Intercepts({
@Signature(
type = StatementHandler.class,
method = "prepare",
args = {Connection.class, Integer.class})
})
public class PostgreSQLPrepareInterceptor implements Interceptor {
@Override
public Object intercept(final Invocation invocation) throws Throwable {
StatementHandler statementHandler = (StatementHandler) invocation.getTarget();
BoundSql boundSql = statementHandler.getBoundSql();
Field field = boundSql.getClass().getDeclaredField("sql");
field.setAccessible(true);
field.set(boundSql, boundSql.getSql().replace("`", "\"").toLowerCase());
return invocation.proceed();
}
@Override
public Object plugin(final Object target) {
return Plugin.wrap(target, this);
}
@Override
public void setProperties(final Properties properties) {}
}
/*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.dinky.interceptor;
import org.apache.ibatis.cache.CacheKey;
import org.apache.ibatis.executor.Executor;
import org.apache.ibatis.mapping.BoundSql;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.plugin.Interceptor;
import org.apache.ibatis.plugin.Intercepts;
import org.apache.ibatis.plugin.Invocation;
import org.apache.ibatis.plugin.Plugin;
import org.apache.ibatis.plugin.Signature;
import org.apache.ibatis.session.ResultHandler;
import org.apache.ibatis.session.RowBounds;
import java.util.Properties;
@Intercepts({
@Signature(
type = Executor.class,
method = "query",
args = {MappedStatement.class, Object.class, RowBounds.class, ResultHandler.class}),
@Signature(
type = Executor.class,
method = "query",
args = {
MappedStatement.class,
Object.class,
RowBounds.class,
ResultHandler.class,
CacheKey.class,
BoundSql.class
})
})
public class PostgreSQLQueryInterceptor implements Interceptor {
@Override
public Object intercept(final Invocation invocation) throws Throwable {
Object[] args = invocation.getArgs();
MappedStatement ms = (MappedStatement) args[0];
Object parameter = args[1];
RowBounds rowBounds = (RowBounds) args[2];
ResultHandler<?> resultHandler = (ResultHandler<?>) args[3];
Executor executor = (Executor) invocation.getTarget();
CacheKey cacheKey;
BoundSql boundSql;
if (args.length == 4) {
boundSql = ms.getBoundSql(parameter);
cacheKey = executor.createCacheKey(ms, parameter, rowBounds, boundSql);
} else {
cacheKey = (CacheKey) args[4];
boundSql = (BoundSql) args[5];
}
return executor.query(ms, parameter, rowBounds, resultHandler, cacheKey, boundSql);
}
@Override
public Object plugin(final Object target) {
return Plugin.wrap(target, this);
}
@Override
public void setProperties(final Properties properties) {}
}
...@@ -30,6 +30,8 @@ import java.util.LinkedHashMap; ...@@ -30,6 +30,8 @@ import java.util.LinkedHashMap;
import org.dromara.sms4j.api.SmsBlend; import org.dromara.sms4j.api.SmsBlend;
import org.dromara.sms4j.api.universal.SupplierConfig; import org.dromara.sms4j.api.universal.SupplierConfig;
import org.dromara.sms4j.provider.base.BaseProviderFactory;
import org.dromara.sms4j.provider.enumerate.SupplierType;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
...@@ -40,6 +42,8 @@ public class SmsSender { ...@@ -40,6 +42,8 @@ public class SmsSender {
private static final Logger logger = LoggerFactory.getLogger(SmsSender.class); private static final Logger logger = LoggerFactory.getLogger(SmsSender.class);
private static SupplierConfig configLoader = null; private static SupplierConfig configLoader = null;
private static BaseProviderFactory providerFactory = null;
private static SmsBlend smsSendFactory = null; private static SmsBlend smsSendFactory = null;
/** manufacturers of sms */ /** manufacturers of sms */
...@@ -51,11 +55,14 @@ public class SmsSender { ...@@ -51,11 +55,14 @@ public class SmsSender {
this.manufacturers = manufacturersId; this.manufacturers = manufacturersId;
requireNonNull(manufacturers, "manufacturers is null"); requireNonNull(manufacturers, "manufacturers is null");
configLoader = SmsConfigLoader.getConfigLoader(config, manufacturers); configLoader = SmsConfigLoader.getConfigLoader(config, manufacturers);
smsSendFactory = SmsConfigLoader.getSmsFactory(manufacturersId); providerFactory = getSmsTpye(manufacturersId).getProviderFactory();
logger.info("you choose {} manufacturers", ManuFacturers.getManuFacturers(manufacturersId)); logger.info("you choose {} manufacturers", ManuFacturers.getManuFacturers(manufacturersId));
} }
public AlertResult send(String title, String content) { public synchronized AlertResult send(String title, String content) {
providerFactory.refresh(configLoader);
smsSendFactory = providerFactory.createSms(configLoader);
AlertResult alertResult = new AlertResult(); AlertResult alertResult = new AlertResult();
logger.info("send sms, title: {}, content: {}", title, content); logger.info("send sms, title: {}, content: {}", title, content);
// todo: 1. support multi sms manufacturers send // todo: 1. support multi sms manufacturers send
...@@ -64,4 +71,32 @@ public class SmsSender { ...@@ -64,4 +71,32 @@ public class SmsSender {
// todo: 2. validate sms send result // todo: 2. validate sms send result
return alertResult; return alertResult;
} }
public static SupplierType getSmsTpye(Integer manufacturersType) {
switch (manufacturersType) {
case 1:
return SupplierType.ALIBABA;
case 2:
return SupplierType.HUAWEI;
case 3:
return SupplierType.YUNPIAN;
case 4:
return SupplierType.TENCENT;
case 5:
return SupplierType.UNI_SMS;
case 6:
return SupplierType.JD_CLOUD;
case 7:
return SupplierType.CLOOPEN;
case 8:
return SupplierType.EMAY;
case 9:
return SupplierType.CTYUN;
default:
throw new IllegalArgumentException(
"Unsupported manufacturers type: "
+ ManuFacturers.getManuFacturers(manufacturersType));
}
}
} }
...@@ -68,7 +68,7 @@ public class SystemConfiguration { ...@@ -68,7 +68,7 @@ public class SystemConfiguration {
private Configuration<String> sqlSeparator = private Configuration<String> sqlSeparator =
key("flink.settings.sqlSeparator") key("flink.settings.sqlSeparator")
.stringType() .stringType()
.defaultValue(";\n") .defaultValue(";\\n")
.note("FlinkSQL语句分割符"); .note("FlinkSQL语句分割符");
private Configuration<Integer> jobIdWait = private Configuration<Integer> jobIdWait =
key("flink.settings.jobIdWait") key("flink.settings.jobIdWait")
......
...@@ -111,7 +111,7 @@ export const BuildSteps: React.FC<BuildStepsProps> = (props) => { ...@@ -111,7 +111,7 @@ export const BuildSteps: React.FC<BuildStepsProps> = (props) => {
description: item.startTime, description: item.startTime,
disabled: true, disabled: true,
onClick: () => { onClick: () => {
if (finish) { if (finish&& item.step<=currentStep) {
if (item.step === showDataStep) { if (item.step === showDataStep) {
setShowList(true) setShowList(true)
setLog(showData) setLog(showData)
...@@ -149,7 +149,7 @@ export const BuildSteps: React.FC<BuildStepsProps> = (props) => { ...@@ -149,7 +149,7 @@ export const BuildSteps: React.FC<BuildStepsProps> = (props) => {
stepArray[currentStep - 1].status = renderStatus(status) stepArray[currentStep - 1].status = renderStatus(status)
} }
if ((status === 2 && currentStep === stepNum) || status === 0) { if ((status === 2 && currentStep === stepNum) || status === 0) {
stepArray.forEach(d => d.disabled = false) stepArray.filter(x=>x.status!="wait").forEach(d => d.disabled = false)
finish = true; finish = true;
eventSource.close(); eventSource.close();
return; return;
......
...@@ -1472,7 +1472,7 @@ CREATE TABLE "public"."dinky_user" ( ...@@ -1472,7 +1472,7 @@ CREATE TABLE "public"."dinky_user" (
"password" varchar(50) COLLATE "pg_catalog"."default", "password" varchar(50) COLLATE "pg_catalog"."default",
"nickname" varchar(50) COLLATE "pg_catalog"."default", "nickname" varchar(50) COLLATE "pg_catalog"."default",
"worknum" varchar(50) COLLATE "pg_catalog"."default", "worknum" varchar(50) COLLATE "pg_catalog"."default",
"user_type" int2 COLLATE "pg_catalog"."default", "user_type" int2 NOT NULL,
"avatar" bytea, "avatar" bytea,
"mobile" varchar(20) COLLATE "pg_catalog"."default", "mobile" varchar(20) COLLATE "pg_catalog"."default",
"enabled" int2 NOT NULL, "enabled" int2 NOT NULL,
...@@ -1487,6 +1487,7 @@ COMMENT ON COLUMN "public"."dinky_user"."password" IS 'password'; ...@@ -1487,6 +1487,7 @@ COMMENT ON COLUMN "public"."dinky_user"."password" IS 'password';
COMMENT ON COLUMN "public"."dinky_user"."nickname" IS 'nickname'; COMMENT ON COLUMN "public"."dinky_user"."nickname" IS 'nickname';
COMMENT ON COLUMN "public"."dinky_user"."worknum" IS 'worknum'; COMMENT ON COLUMN "public"."dinky_user"."worknum" IS 'worknum';
COMMENT ON COLUMN "public"."dinky_user"."avatar" IS 'avatar'; COMMENT ON COLUMN "public"."dinky_user"."avatar" IS 'avatar';
COMMENT ON COLUMN "public"."dinky_user"."user_type" IS 'user_type';
COMMENT ON COLUMN "public"."dinky_user"."mobile" IS 'mobile phone'; COMMENT ON COLUMN "public"."dinky_user"."mobile" IS 'mobile phone';
COMMENT ON COLUMN "public"."dinky_user"."enabled" IS 'is enable'; COMMENT ON COLUMN "public"."dinky_user"."enabled" IS 'is enable';
COMMENT ON COLUMN "public"."dinky_user"."is_delete" IS 'is delete'; COMMENT ON COLUMN "public"."dinky_user"."is_delete" IS 'is delete';
......
...@@ -108,4 +108,4 @@ CREATE TABLE `dinky_git_project` ( ...@@ -108,4 +108,4 @@ CREATE TABLE `dinky_git_project` (
ALTER TABLE dinky_role_select_permissions RENAME TO dinky_row_permissions; ALTER TABLE dinky_role_select_permissions RENAME TO dinky_row_permissions;
ALTER TABLE dinky_user ALTER TABLE dinky_user
add user_type int default 0 not null comment 'login type(0:LOCAL,1:LDAP)' after user_type; add COLUMN `user_type` int default 0 not null comment 'login type(0:LOCAL,1:LDAP)' after user_type;
\ No newline at end of file \ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment