修改数据源集成代码2025-06
This commit is contained in:
parent
c0c5f21609
commit
559c08a557
@ -18,9 +18,11 @@
|
|||||||
<maven.compiler.source>21</maven.compiler.source>
|
<maven.compiler.source>21</maven.compiler.source>
|
||||||
<maven.compiler.target>21</maven.compiler.target>
|
<maven.compiler.target>21</maven.compiler.target>
|
||||||
<java.version>21</java.version>
|
<java.version>21</java.version>
|
||||||
<mybatis-plus.version>3.5.3</mybatis-plus.version>
|
<mybatis-spring.version>3.0.3</mybatis-spring.version>
|
||||||
|
<mybatis-plus.version>3.5.6</mybatis-plus.version>
|
||||||
<jjwt.version>0.11.5</jjwt.version>
|
<jjwt.version>0.11.5</jjwt.version>
|
||||||
<springdoc.version>2.0.2</springdoc.version>
|
<springdoc.version>2.0.2</springdoc.version>
|
||||||
|
<calcite-core.version>1.35.18</calcite-core.version>
|
||||||
</properties>
|
</properties>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
@ -57,6 +59,11 @@
|
|||||||
<systemPath>${project.basedir}/libs/sdk-bundle-2.0.jar</systemPath>
|
<systemPath>${project.basedir}/libs/sdk-bundle-2.0.jar</systemPath>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mybatis</groupId>
|
||||||
|
<artifactId>mybatis-spring</artifactId>
|
||||||
|
<version>${mybatis-spring.version}</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.baomidou</groupId>
|
<groupId>com.baomidou</groupId>
|
||||||
<artifactId>mybatis-plus-boot-starter</artifactId>
|
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||||
@ -118,18 +125,9 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.projectlombok</groupId>
|
<groupId>org.projectlombok</groupId>
|
||||||
<artifactId>lombok</artifactId>
|
<artifactId>lombok</artifactId>
|
||||||
|
<version>1.18.34</version> <!-- 推荐使用最新稳定版本 -->
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>com.baomidou</groupId>
|
|
||||||
<artifactId>mybatis-plus-core</artifactId>
|
|
||||||
<version>3.5.3.1</version> <!-- 请使用你项目中统一的版本 -->
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.projectlombok</groupId>
|
|
||||||
<artifactId>lombok</artifactId>
|
|
||||||
<version>1.18.34</version> <!-- 推荐使用最新稳定版本 --> <scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
@ -13,8 +13,8 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
|
|||||||
* @author StdProject
|
* @author StdProject
|
||||||
* @since 2023-12-07
|
* @since 2023-12-07
|
||||||
*/
|
*/
|
||||||
@SpringBootApplication(scanBasePackages = {"com.stdproject", "io.gisbi.extensions.datasource.utils", "io.gisbi.i18n"})
|
@SpringBootApplication(scanBasePackages = {"com.stdproject","io.gisbi.rsa", "io.gisbi.utils", "io.gisbi.extensions"})
|
||||||
@MapperScan("com.stdproject.mapper")
|
@MapperScan("com.stdproject.mapper,io.gisbi.rsa.dao.mapper")
|
||||||
@EnableCaching
|
@EnableCaching
|
||||||
@EnableAsync
|
@EnableAsync
|
||||||
@EnableTransactionManagement
|
@EnableTransactionManagement
|
||||||
|
@ -17,7 +17,7 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
|
import com.stdproject.utils.EncryptUtils;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -33,6 +33,7 @@ public class DynamicDataServiceImpl implements IDynamicDataService {
|
|||||||
public boolean addTableData(Long datasourceId, String tableData) throws Exception {
|
public boolean addTableData(Long datasourceId, String tableData) throws Exception {
|
||||||
// 根据数据源 id 查询数据源信息,调用通用数据源执行器
|
// 根据数据源 id 查询数据源信息,调用通用数据源执行器
|
||||||
CoreDatasource coreDatasource = coreDatasourceMapper.selectById(datasourceId);
|
CoreDatasource coreDatasource = coreDatasourceMapper.selectById(datasourceId);
|
||||||
|
coreDatasource.setConfiguration(String.valueOf(EncryptUtils.aesDecrypt(coreDatasource.getConfiguration())));
|
||||||
if (coreDatasource == null) {
|
if (coreDatasource == null) {
|
||||||
BusinessException.throwException("数据源不存在");
|
BusinessException.throwException("数据源不存在");
|
||||||
}
|
}
|
||||||
|
@ -745,11 +745,16 @@ public class CalciteProvider extends Provider {
|
|||||||
private Connection getCalciteConnection() {
|
private Connection getCalciteConnection() {
|
||||||
registerDriver();
|
registerDriver();
|
||||||
Properties info = new Properties();
|
Properties info = new Properties();
|
||||||
info.setProperty(CalciteConnectionProperty.LEX.camelName(), "JAVA");
|
// info.setProperty(CalciteConnectionProperty.LEX.camelName(), "JAVA");
|
||||||
info.setProperty(CalciteConnectionProperty.FUN.camelName(), "all");
|
// info.setProperty(CalciteConnectionProperty.FUN.camelName(), "all");
|
||||||
info.setProperty(CalciteConnectionProperty.CASE_SENSITIVE.camelName(), "false");
|
// info.setProperty(CalciteConnectionProperty.CASE_SENSITIVE.camelName(), "false");
|
||||||
info.setProperty(CalciteConnectionProperty.PARSER_FACTORY.camelName(), "org.apache.calcite.sql.parser.impl.SqlParserImpl#FACTORY");
|
// info.setProperty(CalciteConnectionProperty.PARSER_FACTORY.camelName(), "org.apache.calcite.sql.parser.impl.SqlParserImpl#FACTORY");
|
||||||
info.setProperty(CalciteConnectionProperty.DEFAULT_NULL_COLLATION.camelName(), NullCollation.LAST.name());
|
// info.setProperty(CalciteConnectionProperty.DEFAULT_NULL_COLLATION.camelName(), NullCollation.LAST.name());
|
||||||
|
info.setProperty("lex", "JAVA");
|
||||||
|
info.setProperty("fun", "all");
|
||||||
|
info.setProperty("caseSensitive", "false");
|
||||||
|
info.setProperty("parserFactory", "org.apache.calcite.sql.parser.impl.SqlParserImpl#FACTORY");
|
||||||
|
info.setProperty("defaultNullCollation", NullCollation.LAST.name());
|
||||||
info.setProperty("remarks", "true");
|
info.setProperty("remarks", "true");
|
||||||
Connection connection = null;
|
Connection connection = null;
|
||||||
try {
|
try {
|
||||||
|
210
backend/src/main/java/com/stdproject/utils/CodingUtil.java
Normal file
210
backend/src/main/java/com/stdproject/utils/CodingUtil.java
Normal file
@ -0,0 +1,210 @@
|
|||||||
|
package com.stdproject.utils;
|
||||||
|
|
||||||
|
import org.apache.commons.codec.binary.Base64;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
import javax.crypto.*;
|
||||||
|
import javax.crypto.spec.IvParameterSpec;
|
||||||
|
import javax.crypto.spec.SecretKeySpec;
|
||||||
|
import java.security.MessageDigest;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 加密解密工具
|
||||||
|
*
|
||||||
|
* @Author bi-coder
|
||||||
|
*/
|
||||||
|
public class CodingUtil {
|
||||||
|
|
||||||
|
private static final String UTF_8 = "UTF-8";
|
||||||
|
|
||||||
|
private static final char[] HEX_DIGITS = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
|
||||||
|
|
||||||
|
|
||||||
|
public static String[] chars = new String[] { "a", "b", "c", "d", "e", "f",
|
||||||
|
"g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s",
|
||||||
|
"t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5",
|
||||||
|
"6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H", "I",
|
||||||
|
"J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V",
|
||||||
|
"W", "X", "Y", "Z" };
|
||||||
|
/**
|
||||||
|
* MD5加密
|
||||||
|
*
|
||||||
|
* @param src 要加密的串
|
||||||
|
* @return 加密后的字符串
|
||||||
|
*/
|
||||||
|
public static String md5(String src) {
|
||||||
|
return md5(src, UTF_8);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MD5加密
|
||||||
|
*
|
||||||
|
* @param src 要加密的串
|
||||||
|
* @param charset 加密字符集
|
||||||
|
* @return 加密后的字符串
|
||||||
|
*/
|
||||||
|
public static String md5(String src, String charset) {
|
||||||
|
try {
|
||||||
|
byte[] strTemp = StringUtils.isEmpty(charset) ? src.getBytes() : src.getBytes(charset);
|
||||||
|
MessageDigest mdTemp = MessageDigest.getInstance("MD5");
|
||||||
|
mdTemp.update(strTemp);
|
||||||
|
|
||||||
|
byte[] md = mdTemp.digest();
|
||||||
|
int j = md.length;
|
||||||
|
char[] str = new char[j * 2];
|
||||||
|
int k = 0;
|
||||||
|
|
||||||
|
for (byte byte0 : md) {
|
||||||
|
str[k++] = HEX_DIGITS[byte0 >>> 4 & 0xf];
|
||||||
|
str[k++] = HEX_DIGITS[byte0 & 0xf];
|
||||||
|
}
|
||||||
|
|
||||||
|
return new String(str);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException("MD5 encrypt error:", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* BASE64解密
|
||||||
|
*
|
||||||
|
* @param src 待解密的字符串
|
||||||
|
* @return 解密后的字符串
|
||||||
|
*/
|
||||||
|
public static String base64Decoding(String src) {
|
||||||
|
byte[] b;
|
||||||
|
String result = null;
|
||||||
|
if (src != null) {
|
||||||
|
try {
|
||||||
|
b = Base64.decodeBase64(src);
|
||||||
|
result = new String(b, UTF_8);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException("BASE64 decoding error:", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* BASE64加密
|
||||||
|
*
|
||||||
|
* @param src 待加密的字符串
|
||||||
|
* @return 加密后的字符串
|
||||||
|
*/
|
||||||
|
public static String base64Encoding(String src) {
|
||||||
|
String result = null;
|
||||||
|
if (src != null) {
|
||||||
|
try {
|
||||||
|
result = Base64.encodeBase64String(src.getBytes(UTF_8));
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException("BASE64 encoding error:", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* AES加密
|
||||||
|
*
|
||||||
|
* @param src 待加密字符串
|
||||||
|
* @param secretKey 密钥
|
||||||
|
* @param iv 向量
|
||||||
|
* @return 加密后字符串
|
||||||
|
*/
|
||||||
|
public static String aesEncrypt(String src, String secretKey, String iv) {
|
||||||
|
if (StringUtils.isBlank(secretKey)) {
|
||||||
|
throw new RuntimeException("secretKey is empty");
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
byte[] raw = secretKey.getBytes(UTF_8);
|
||||||
|
SecretKeySpec secretKeySpec = new SecretKeySpec(raw, "AES");
|
||||||
|
// "算法/模式/补码方式" ECB
|
||||||
|
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
|
||||||
|
IvParameterSpec iv1 = new IvParameterSpec(iv.getBytes());
|
||||||
|
cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec, iv1);
|
||||||
|
byte[] encrypted = cipher.doFinal(src.getBytes(UTF_8));
|
||||||
|
return Base64.encodeBase64String(encrypted);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException("AES encrypt error:", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* AES 解密
|
||||||
|
*
|
||||||
|
* @param src 待解密字符串
|
||||||
|
* @param secretKey 密钥
|
||||||
|
* @param iv 向量
|
||||||
|
* @return 解密后字符串
|
||||||
|
*/
|
||||||
|
public static String aesDecrypt(String src, String secretKey, String iv) {
|
||||||
|
if (StringUtils.isBlank(secretKey)) {
|
||||||
|
throw new RuntimeException("secretKey is empty");
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
byte[] raw = secretKey.getBytes(UTF_8);
|
||||||
|
SecretKeySpec secretKeySpec = new SecretKeySpec(raw, "AES");
|
||||||
|
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
|
||||||
|
IvParameterSpec iv1 = new IvParameterSpec(iv.getBytes());
|
||||||
|
cipher.init(Cipher.DECRYPT_MODE, secretKeySpec, iv1);
|
||||||
|
byte[] encrypted1 = Base64.decodeBase64(src);
|
||||||
|
byte[] original = cipher.doFinal(encrypted1);
|
||||||
|
return new String(original, UTF_8);
|
||||||
|
} catch (BadPaddingException | IllegalBlockSizeException e) {
|
||||||
|
// 解密的原字符串为非加密字符串,则直接返回原字符串
|
||||||
|
return src;
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException("decrypt error,please check parameters", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static String secretKey() {
|
||||||
|
try {
|
||||||
|
KeyGenerator keyGen = KeyGenerator.getInstance("AES");
|
||||||
|
keyGen.init(128);
|
||||||
|
SecretKey secretKey = keyGen.generateKey();
|
||||||
|
return Base64.encodeBase64String(secretKey.getEncoded());
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException("generate secretKey error", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isNumeric(String str){
|
||||||
|
for (int i = str.length();--i>=0;){
|
||||||
|
if (!Character.isDigit(str.charAt(i))){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public static String shortUuid() {
|
||||||
|
StringBuffer shortBuffer = new StringBuffer();
|
||||||
|
String uuid = UUID.randomUUID().toString().replace("-", "");
|
||||||
|
for (int i = 0; i < 8; i++) {
|
||||||
|
String str = uuid.substring(i * 4, i * 4 + 4);
|
||||||
|
int x = Integer.parseInt(str, 16);
|
||||||
|
shortBuffer.append(chars[x % 0x3E]);
|
||||||
|
}
|
||||||
|
return shortBuffer.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Integer string2Integer(String str) {
|
||||||
|
StringBuffer sb = new StringBuffer();
|
||||||
|
if (StringUtils.isBlank(str)) return null;
|
||||||
|
for (int i = 0; i < str.length(); i++) {
|
||||||
|
char c = str.charAt(i);
|
||||||
|
if (Character.isDigit(c)) {
|
||||||
|
sb.append(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sb.length() > 0 ? Integer.parseInt(sb.toString()) : null;
|
||||||
|
}
|
||||||
|
}
|
44
backend/src/main/java/com/stdproject/utils/EncryptUtils.java
Normal file
44
backend/src/main/java/com/stdproject/utils/EncryptUtils.java
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
package com.stdproject.utils;
|
||||||
|
|
||||||
|
import io.gisbi.utils.BeanUtils;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
public class EncryptUtils extends CodingUtil {
|
||||||
|
|
||||||
|
private static final String secretKey = "www.fit2cloud.co";
|
||||||
|
private static final String iv = "1234567890123456";
|
||||||
|
|
||||||
|
|
||||||
|
public static Object aesEncrypt(Object o) {
|
||||||
|
if (o == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return aesEncrypt(o.toString(), secretKey, iv);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Object aesDecrypt(Object o) {
|
||||||
|
if (o == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return aesDecrypt(o.toString(), secretKey, iv);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> Object aesDecrypt(List<T> o, String attrName) {
|
||||||
|
if (o == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return o.stream()
|
||||||
|
.filter(element -> BeanUtils.getFieldValueByName(attrName, element) != null)
|
||||||
|
.peek(element -> BeanUtils.setFieldValueByName(element, attrName, aesDecrypt(BeanUtils.getFieldValueByName(attrName, element).toString(), secretKey, iv), String.class))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Object md5Encrypt(Object o) {
|
||||||
|
if (o == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return md5(o.toString());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user