更新了api-common模块
This commit is contained in:
parent
514aaf8626
commit
81e9d6f4ca
@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>sdk</artifactId>
|
<artifactId>sdk</artifactId>
|
||||||
<groupId>io.gisbi</groupId>
|
<groupId>io.gisbi</groupId>
|
||||||
<version>1.0.0</version>
|
<version>2.0.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
@ -38,8 +38,7 @@ public class SubstituleLoginConfig {
|
|||||||
pwd = CommonBeanFactory.getBean(Environment.class).getProperty("gisbi.default-pwd", "Gisbi@123456");
|
pwd = CommonBeanFactory.getBean(Environment.class).getProperty("gisbi.default-pwd", "Gisbi@123456");
|
||||||
modifyPwd(pwd);
|
modifyPwd(pwd);
|
||||||
}
|
}
|
||||||
Map<String, Object> map=objectMapper.readValue(jsonFile, Map.class);
|
return objectMapper.readValue(jsonFile, Map.class);
|
||||||
return map;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getPwd() {
|
public static String getPwd() {
|
||||||
|
@ -60,6 +60,7 @@ public class CommunityTokenFilter implements Filter {
|
|||||||
String msg = URLEncoder.encode(e.getMessage(), StandardCharsets.UTF_8).replace("+", "%20");
|
String msg = URLEncoder.encode(e.getMessage(), StandardCharsets.UTF_8).replace("+", "%20");
|
||||||
headers.add(headName, msg);
|
headers.add(headName, msg);
|
||||||
sendResponseEntity(res, new ResponseEntity<>(e.getMessage(), headers, HttpStatus.UNAUTHORIZED));
|
sendResponseEntity(res, new ResponseEntity<>(e.getMessage(), headers, HttpStatus.UNAUTHORIZED));
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,18 +15,18 @@ import java.util.List;
|
|||||||
@Configuration
|
@Configuration
|
||||||
public class CorsConfig implements WebMvcConfigurer {
|
public class CorsConfig implements WebMvcConfigurer {
|
||||||
|
|
||||||
@Value("${dataease.cors-strict:false}")
|
@Value("${gisbi.cors-strict:false}")
|
||||||
private boolean corsStrict;
|
private boolean corsStrict;
|
||||||
|
|
||||||
|
|
||||||
@Value("#{'${dataease.origin-list:http://127.0.0.1:8100}'.split(',')}")
|
@Value("#{'${gisbi.origin-list:http://127.0.0.1:8100}'.split(',')}")
|
||||||
private List<String> originList;
|
private List<String> originList;
|
||||||
|
|
||||||
private CorsRegistration operateCorsRegistration;
|
private CorsRegistration operateCorsRegistration;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void configurePathMatch(PathMatchConfigurer configurer) {
|
public void configurePathMatch(PathMatchConfigurer configurer) {
|
||||||
configurer.addPathPrefix(AuthConstant.DE_API_PREFIX, c -> c.isAnnotationPresent(RestController.class) && c.getPackageName().startsWith("io.dataease"));
|
configurer.addPathPrefix(AuthConstant.DE_API_PREFIX, c -> c.isAnnotationPresent(RestController.class) && c.getPackageName().startsWith("io.gisbi"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -88,4 +88,22 @@ public class CommonConstants {
|
|||||||
//公共
|
//公共
|
||||||
public static final String PUBLIC = "public";
|
public static final String PUBLIC = "public";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static final class RESOURCE_TABLE {
|
||||||
|
//主表
|
||||||
|
public static final String CORE = "core";
|
||||||
|
//镜像表
|
||||||
|
public static final String SNAPSHOT = "snapshot";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static final class DV_STATUS {
|
||||||
|
//未发布
|
||||||
|
public static final int UNPUBLISHED = 0;
|
||||||
|
//已发布
|
||||||
|
public static final int PUBLISHED = 1;
|
||||||
|
//已保存未发布
|
||||||
|
public static final int SAVED_UNPUBLISHED = 2;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,8 @@ public enum LogOT {
|
|||||||
UPLOADFILE(11, "OPERATE_TYPE_UPLOADFILE"),
|
UPLOADFILE(11, "OPERATE_TYPE_UPLOADFILE"),
|
||||||
BIND(12, "OPERATE_TYPE_BIND"),
|
BIND(12, "OPERATE_TYPE_BIND"),
|
||||||
UNBIND(13, "OPERATE_TYPE_UNBIND"),
|
UNBIND(13, "OPERATE_TYPE_UNBIND"),
|
||||||
LOGIN(14, "OPERATE_TYPE_LOGIN");
|
LOGIN(14, "OPERATE_TYPE_LOGIN"),
|
||||||
|
DOWNLOAD(15, "OPERATE_TYPE_DOWNLOAD");
|
||||||
private Integer value;
|
private Integer value;
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
|
@ -16,7 +16,8 @@ public enum LogST {
|
|||||||
DRIVER_FILE(11, "SOURCE_TYPE_DRIVER_FILE"),
|
DRIVER_FILE(11, "SOURCE_TYPE_DRIVER_FILE"),
|
||||||
MENU(12, "SOURCE_TYPE_MENU"),
|
MENU(12, "SOURCE_TYPE_MENU"),
|
||||||
APIKEY(13, "SOURCE_TYPE_APIKEY"),
|
APIKEY(13, "SOURCE_TYPE_APIKEY"),
|
||||||
DATA_FILLING(14, "SOURCE_TYPE_DATAFILLING");
|
DATA_FILLING(14, "SOURCE_TYPE_DATAFILLING"),
|
||||||
|
DATA(15, "SOURCE_TYPE_DATA");
|
||||||
private Integer value;
|
private Integer value;
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
|
@ -41,9 +41,9 @@ public class StaticResourceConstants {
|
|||||||
|
|
||||||
public static String getHomeData() {
|
public static String getHomeData() {
|
||||||
if (ModelUtils.isDesktop()) {
|
if (ModelUtils.isDesktop()) {
|
||||||
return ConfigUtils.getConfig("gisbi.path.data", "/opt/gisbi/data");
|
return ConfigUtils.getConfig("gisbi.path.data", "/opt/gisbi2.0/data");
|
||||||
} else {
|
} else {
|
||||||
return "/opt/gisbi/data";
|
return "/opt/gisbi2.0/data";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ import java.util.Map;
|
|||||||
@Configuration
|
@Configuration
|
||||||
public class SwaggerConfig {
|
public class SwaggerConfig {
|
||||||
|
|
||||||
@Value("1.0.0")
|
@Value("2.0.0")
|
||||||
private String version;
|
private String version;
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@ -47,46 +47,46 @@ public class SwaggerConfig {
|
|||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public GroupedOpenApi visualizationApi() {
|
public GroupedOpenApi visualizationApi() {
|
||||||
return GroupedOpenApi.builder().group("1-visualization").displayName("可视化管理").packagesToScan("io.dataease.visualization", "io.dataease.share").build();
|
return GroupedOpenApi.builder().group("1-visualization").displayName("可视化管理").packagesToScan("io.gisbi.visualization", "io.gisbi.share").build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public GroupedOpenApi chartApi() {
|
public GroupedOpenApi chartApi() {
|
||||||
return GroupedOpenApi.builder().group("2-view").displayName("图表管理").packagesToScan("io.dataease.chart").build();
|
return GroupedOpenApi.builder().group("2-view").displayName("图表管理").packagesToScan("io.gisbi.chart").build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public GroupedOpenApi datasetApi() {
|
public GroupedOpenApi datasetApi() {
|
||||||
return GroupedOpenApi.builder().group("3-dataset").displayName("数据集管理").packagesToScan("io.dataease.dataset").build();
|
return GroupedOpenApi.builder().group("3-dataset").displayName("数据集管理").packagesToScan("io.gisbi.dataset").build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public GroupedOpenApi dsApi() {
|
public GroupedOpenApi dsApi() {
|
||||||
return GroupedOpenApi.builder().group("4-datasource").displayName("数据源管理").packagesToScan("io.dataease.datasource").build();
|
return GroupedOpenApi.builder().group("4-datasource").displayName("数据源管理").packagesToScan("io.gisbi.datasource").build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public GroupedOpenApi basicSettingApi() {
|
public GroupedOpenApi basicSettingApi() {
|
||||||
String[] packageArray = {
|
String[] packageArray = {
|
||||||
"io.dataease.system",
|
"io.gisbi.system",
|
||||||
"io.dataease.map",
|
"io.gisbi.map",
|
||||||
};
|
};
|
||||||
return GroupedOpenApi.builder().group("5-xpackpermission").displayName("系统设置").packagesToScan(packageArray).build();
|
return GroupedOpenApi.builder().group("5-xpackpermission").displayName("系统设置").packagesToScan(packageArray).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public GroupedOpenApi baseXpackApi() {
|
public GroupedOpenApi baseXpackApi() {
|
||||||
return GroupedOpenApi.builder().group("6-xpackbase").displayName("基础xpack").packagesToScan("io.dataease.xpack.base").build();
|
return GroupedOpenApi.builder().group("6-xpackbase").displayName("基础xpack").packagesToScan("io.gisbi.xpack.base").build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public GroupedOpenApi systemApi() {
|
public GroupedOpenApi systemApi() {
|
||||||
return GroupedOpenApi.builder().group("7-xpackpermission").displayName("权限相关xpack").packagesToScan("io.dataease.xpack.permissions").build();
|
return GroupedOpenApi.builder().group("7-xpackpermission").displayName("权限相关xpack").packagesToScan("io.gisbi.xpack.permissions").build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public GroupedOpenApi syncApi() {
|
public GroupedOpenApi syncApi() {
|
||||||
return GroupedOpenApi.builder().group("8-xpacksync").displayName("同步管理").packagesToScan("io.dataease.xpack.sync.task").build();
|
return GroupedOpenApi.builder().group("8-xpacksync").displayName("同步管理").packagesToScan("io.gisbi.xpack.sync.task").build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
|
@ -34,7 +34,7 @@ public class GlobalExceptionHandler {
|
|||||||
public ResultMessage noUserExceptionHandler(Exception e) {
|
public ResultMessage noUserExceptionHandler(Exception e) {
|
||||||
String message = e.getMessage();
|
String message = e.getMessage();
|
||||||
LogUtil.error(message, e);
|
LogUtil.error(message, e);
|
||||||
if (StringUtils.contains(message, "Cannot invoke \"io.dataease.auth.bo.TokenUserBO.getUserId()\" because \"user\" is null")) {
|
if (StringUtils.contains(message, "Cannot invoke \"io.gisbi.auth.bo.TokenUserBO.getUserId()\" because \"user\" is null")) {
|
||||||
return new ResultMessage(ResultCode.USER_NOT_LOGGED_IN.code(), ResultCode.USER_NOT_LOGGED_IN.message());
|
return new ResultMessage(ResultCode.USER_NOT_LOGGED_IN.code(), ResultCode.USER_NOT_LOGGED_IN.message());
|
||||||
}
|
}
|
||||||
return new ResultMessage(ResultCode.PARAM_IS_BLANK.code(), message);
|
return new ResultMessage(ResultCode.PARAM_IS_BLANK.code(), message);
|
||||||
|
@ -15,7 +15,7 @@ import java.io.IOException;
|
|||||||
@Component
|
@Component
|
||||||
public class HtmlResourceFilter implements Filter, Ordered {
|
public class HtmlResourceFilter implements Filter, Ordered {
|
||||||
|
|
||||||
@Value("${dataease.http.cache:false}")
|
@Value("${gisbi.http.cache:false}")
|
||||||
private Boolean httpCache;
|
private Boolean httpCache;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -10,7 +10,7 @@ import org.springframework.stereotype.Component;
|
|||||||
@Order(1000)
|
@Order(1000)
|
||||||
public class DeI18nStarter implements ApplicationRunner {
|
public class DeI18nStarter implements ApplicationRunner {
|
||||||
|
|
||||||
@Value("${dataease.path.i18n:file:/opt/dataease2.0/data/i18n/custom}")
|
@Value("${gisbi.path.i18n:file:/opt/gisbi2.0/data/i18n/custom}")
|
||||||
private String i18nPath;
|
private String i18nPath;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,8 +1,12 @@
|
|||||||
package io.gisbi.i18n;
|
package io.gisbi.i18n;
|
||||||
|
|
||||||
|
import io.gisbi.utils.CacheUtils;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
import org.apache.commons.lang3.ObjectUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
import static io.gisbi.constant.CacheConstant.UserCacheConstant.USER_COMMUNITY_LANGUAGE;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
public enum Lang {
|
public enum Lang {
|
||||||
|
|
||||||
@ -43,4 +47,20 @@ public enum Lang {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isChinese() {
|
||||||
|
String lang = null;
|
||||||
|
Object langObj = CacheUtils.get(USER_COMMUNITY_LANGUAGE, "de");
|
||||||
|
if (ObjectUtils.isNotEmpty(langObj) && StringUtils.isNotBlank(langObj.toString())) {
|
||||||
|
lang = langObj.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (StringUtils.isBlank(lang)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (StringUtils.startsWithIgnoreCase(lang, "zh")) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -14,11 +14,11 @@ public class BusiNodeRequest implements Serializable {
|
|||||||
|
|
||||||
private String id;
|
private String id;
|
||||||
|
|
||||||
private String appId;
|
|
||||||
|
|
||||||
private Boolean leaf;
|
private Boolean leaf;
|
||||||
|
|
||||||
private Integer weight;
|
private Integer weight;
|
||||||
|
|
||||||
private String sortType;
|
private String sortType;
|
||||||
|
|
||||||
|
private String resourceTable;
|
||||||
}
|
}
|
||||||
|
@ -30,6 +30,8 @@ public class BusiNodeVO implements TreeResultModel<BusiNodeVO>, Serializable {
|
|||||||
private Integer weight;
|
private Integer weight;
|
||||||
@Schema(description = "额外标识")
|
@Schema(description = "额外标识")
|
||||||
private int extraFlag;
|
private int extraFlag;
|
||||||
|
@Schema(description = "额外标识1")
|
||||||
|
private int extraFlag1;
|
||||||
@Schema(description = "类型")
|
@Schema(description = "类型")
|
||||||
private String type;
|
private String type;
|
||||||
@Schema(description = "子节点")
|
@Schema(description = "子节点")
|
||||||
|
@ -17,7 +17,7 @@ public class ExportTaskDTO {
|
|||||||
|
|
||||||
private String fileSizeUnit;
|
private String fileSizeUnit;
|
||||||
|
|
||||||
private String exportFrom;
|
private Long exportFrom;
|
||||||
|
|
||||||
private String exportStatus;
|
private String exportStatus;
|
||||||
|
|
||||||
|
@ -22,12 +22,12 @@ public class DeTrafficAop {
|
|||||||
@Resource
|
@Resource
|
||||||
private CoreApiTrafficMapper coreApiTrafficMapper;
|
private CoreApiTrafficMapper coreApiTrafficMapper;
|
||||||
|
|
||||||
@Value("${dataease.traffic:2}")
|
@Value("${gisbi.traffic:2}")
|
||||||
private Integer defaultTraffic;
|
private Integer defaultTraffic;
|
||||||
|
|
||||||
final private static String errorMsg = "当前API【%s】设定并发阈值为【%s】,现已经达到限流阈值,请稍后再试!";
|
final private static String errorMsg = "当前API【%s】设定并发阈值为【%s】,现已经达到限流阈值,请稍后再试!";
|
||||||
|
|
||||||
@Around(value = "@annotation(io.dataease.traffic.DeTraffic)")
|
@Around(value = "@annotation(io.gisbi.traffic.DeTraffic)")
|
||||||
public Object trafficAround(ProceedingJoinPoint point) throws Throwable {
|
public Object trafficAround(ProceedingJoinPoint point) throws Throwable {
|
||||||
MethodSignature ms = (MethodSignature) point.getSignature();
|
MethodSignature ms = (MethodSignature) point.getSignature();
|
||||||
Method method = ms.getMethod();
|
Method method = ms.getMethod();
|
||||||
|
@ -12,7 +12,7 @@ import java.util.Objects;
|
|||||||
*/
|
*/
|
||||||
public class ConfigUtils {
|
public class ConfigUtils {
|
||||||
|
|
||||||
public static String configPath = "opt" + File.separator + "dataease2.0" + File.separator + "config" + File.separator + "application.yml";
|
public static String configPath = "opt" + File.separator + "gisbi2.0" + File.separator + "config" + File.separator + "application.yml";
|
||||||
|
|
||||||
public static String getConfig(String key, String defaultValue) {
|
public static String getConfig(String key, String defaultValue) {
|
||||||
try {
|
try {
|
||||||
|
@ -30,12 +30,11 @@ import org.apache.http.util.EntityUtils;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.*;
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.net.URLDecoder;
|
||||||
|
import java.net.URLEncoder;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.security.cert.X509Certificate;
|
import java.security.cert.X509Certificate;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@ -70,6 +69,7 @@ public class HttpClientUtil {
|
|||||||
throw new DEException(SYSTEM_INNER_ERROR.code(), "HttpClient查询失败: " + e.getMessage());
|
throw new DEException(SYSTEM_INNER_ERROR.code(), "HttpClient查询失败: " + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static CloseableHttpClient buildHttpClient(boolean ssl) {
|
private static CloseableHttpClient buildHttpClient(boolean ssl) {
|
||||||
try {
|
try {
|
||||||
if (ssl) {
|
if (ssl) {
|
||||||
@ -369,6 +369,71 @@ public class HttpClientUtil {
|
|||||||
return EntityUtils.toString(response.getEntity(), config.getCharset());
|
return EntityUtils.toString(response.getEntity(), config.getCharset());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Map<String, String> downloadFile(String url, HttpClientConfig config, String path) {
|
||||||
|
String encodeUIl = url;
|
||||||
|
Map<String, String> name = new HashMap<>();
|
||||||
|
if (!url.contains("%")) {
|
||||||
|
String[] http = url.split("://");
|
||||||
|
String[] server = http[1].split("/");
|
||||||
|
encodeUIl = http[0] + "://" + server[0] + "/" + URLEncoder.encode(http[1].substring(server[0].length() + 1, http[1].length()));
|
||||||
|
}
|
||||||
|
try (CloseableHttpClient httpClient = buildHttpClient(encodeUIl.replace("+", "%20"))) {
|
||||||
|
HttpGet httpGet = new HttpGet(encodeUIl.replace("+", "%20"));
|
||||||
|
// 设置请求配置
|
||||||
|
httpGet.setConfig(config.buildRequestConfig());
|
||||||
|
// 设置请求头
|
||||||
|
config.getHeader().forEach(httpGet::addHeader);
|
||||||
|
HttpResponse response = httpClient.execute(httpGet);
|
||||||
|
if (response.getStatusLine().getStatusCode() >= 400) {
|
||||||
|
String msg = EntityUtils.toString(response.getEntity(), config.getCharset());
|
||||||
|
if (StringUtils.isEmpty(msg)) {
|
||||||
|
msg = "StatusCode: " + response.getStatusLine().getStatusCode();
|
||||||
|
}
|
||||||
|
throw new Exception(msg);
|
||||||
|
}
|
||||||
|
String fileName = extractFileName(response, url);
|
||||||
|
String suffix = fileName.substring(fileName.lastIndexOf(".") + 1);
|
||||||
|
String tranName = UUID.randomUUID().toString() + "." + suffix;
|
||||||
|
name.put("fileName", fileName);
|
||||||
|
name.put("tranName", tranName);
|
||||||
|
File localFile = new File(path + tranName);
|
||||||
|
FileOutputStream outputStream = new FileOutputStream(localFile);
|
||||||
|
byte[] buffer = new byte[4096];
|
||||||
|
int bytesRead;
|
||||||
|
while ((bytesRead = response.getEntity().getContent().read(buffer)) != -1) {
|
||||||
|
outputStream.write(buffer, 0, bytesRead);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("HttpClient查询失败", e);
|
||||||
|
throw new RuntimeException("HttpClient查询失败: " + e.getMessage(), e);
|
||||||
|
}
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String extractFileName(HttpResponse response, String url) {
|
||||||
|
url = URLDecoder.decode(url);
|
||||||
|
String fileName = "";
|
||||||
|
String disposition = response.getHeaders("Content-Disposition").toString();
|
||||||
|
if (disposition != null) {
|
||||||
|
int filenameIndex = disposition.indexOf("filename=");
|
||||||
|
if (filenameIndex > 0) {
|
||||||
|
fileName = disposition.substring(filenameIndex + 9)
|
||||||
|
.replaceAll("\"", "") // 去除引号
|
||||||
|
.trim();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (fileName.isEmpty()) {
|
||||||
|
url = url.split("\\?")[0];
|
||||||
|
fileName = url.contains("/")
|
||||||
|
? url.substring(url.lastIndexOf('/') + 1)
|
||||||
|
: "download_" + System.currentTimeMillis();
|
||||||
|
}
|
||||||
|
if (fileName.trim().isEmpty()) {
|
||||||
|
fileName = "download_" + System.currentTimeMillis();
|
||||||
|
}
|
||||||
|
return fileName;
|
||||||
|
}
|
||||||
|
|
||||||
public static byte[] downloadBytes(String url) {
|
public static byte[] downloadBytes(String url) {
|
||||||
HttpClientConfig config = new HttpClientConfig();
|
HttpClientConfig config = new HttpClientConfig();
|
||||||
return HttpClientUtil.downFromRemote(url, config);
|
return HttpClientUtil.downFromRemote(url, config);
|
||||||
@ -383,7 +448,6 @@ public class HttpClientUtil {
|
|||||||
// 设置请求头
|
// 设置请求头
|
||||||
config.getHeader().forEach(httpGet::addHeader);
|
config.getHeader().forEach(httpGet::addHeader);
|
||||||
HttpResponse response = httpClient.execute(httpGet);
|
HttpResponse response = httpClient.execute(httpGet);
|
||||||
|
|
||||||
try (InputStream inputStream = response.getEntity().getContent();
|
try (InputStream inputStream = response.getEntity().getContent();
|
||||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
|
||||||
|
|
||||||
|
@ -1,12 +1,21 @@
|
|||||||
package io.gisbi.utils;
|
package io.gisbi.utils;
|
||||||
|
|
||||||
|
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
import org.apache.commons.lang3.ObjectUtils;
|
import org.apache.commons.lang3.ObjectUtils;
|
||||||
import org.apache.commons.lang3.RandomStringUtils;
|
import org.apache.commons.lang3.RandomStringUtils;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@Component
|
||||||
public class IDUtils {
|
public class IDUtils {
|
||||||
|
|
||||||
private static SnowFlake snowFlake = new SnowFlake(1, 1);
|
|
||||||
|
private static SnowFlake snowFlake;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
public void setSnowFlake(SnowFlake snowFlake) {
|
||||||
|
IDUtils.snowFlake = snowFlake;
|
||||||
|
}
|
||||||
|
|
||||||
public static String randomID(Integer num) {
|
public static String randomID(Integer num) {
|
||||||
num = ObjectUtils.isEmpty(num) ? 16 : num;
|
num = ObjectUtils.isEmpty(num) ? 16 : num;
|
||||||
|
@ -14,6 +14,7 @@ import java.util.List;
|
|||||||
public class JsonUtil {
|
public class JsonUtil {
|
||||||
|
|
||||||
private static final ObjectMapper objectMapper;
|
private static final ObjectMapper objectMapper;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
objectMapper = new ObjectMapper();
|
objectMapper = new ObjectMapper();
|
||||||
// 配置更大的 StreamReadConstraints 限制
|
// 配置更大的 StreamReadConstraints 限制
|
||||||
@ -47,6 +48,17 @@ public class JsonUtil {
|
|||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static <T> T parseObject(String json, TypeReference<T> typeReference) {
|
||||||
|
if (json == null) return null;
|
||||||
|
T t = null;
|
||||||
|
try {
|
||||||
|
t = objectMapper.readValue(json, typeReference);
|
||||||
|
} catch (JsonProcessingException e) {
|
||||||
|
LogUtil.error(e.getMessage(), e);
|
||||||
|
}
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
|
||||||
public static <T> List<T> parseList(String json, TypeReference<List<T>> classOfT) {
|
public static <T> List<T> parseList(String json, TypeReference<List<T>> classOfT) {
|
||||||
if (ObjectUtils.isEmpty(json)) return Collections.emptyList();
|
if (ObjectUtils.isEmpty(json)) return Collections.emptyList();
|
||||||
List<T> t = null;
|
List<T> t = null;
|
||||||
|
41
sdk/common/src/main/java/io/gisbi/utils/MappingUtils.java
Normal file
41
sdk/common/src/main/java/io/gisbi/utils/MappingUtils.java
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
package io.gisbi.utils;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class MappingUtils {
|
||||||
|
|
||||||
|
public static Map<String, String> mapNestedUserData(Map<String, Object> userMap, Map<String, String> mappingMap) {
|
||||||
|
|
||||||
|
Map<String, String> resultMap = new HashMap<>();
|
||||||
|
mappingMap.forEach((targetKey, sourcePath) -> {
|
||||||
|
Object value = getNestedValue(userMap, sourcePath);
|
||||||
|
if (value != null) {
|
||||||
|
resultMap.put(targetKey, value.toString());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return resultMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Object getNestedValue(Map<String, Object> sourceMap, String path) {
|
||||||
|
String[] keys = path.split("\\.");
|
||||||
|
Object current = sourceMap;
|
||||||
|
|
||||||
|
for (String key : keys) {
|
||||||
|
if (!(current instanceof Map)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
Map<String, Object> currentMap = (Map<String, Object>) current;
|
||||||
|
current = currentMap.get(key);
|
||||||
|
|
||||||
|
if (current == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return current;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,7 +1,17 @@
|
|||||||
package io.gisbi.utils;
|
package io.gisbi.utils;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@Component
|
||||||
public class SnowFlake {
|
public class SnowFlake {
|
||||||
|
|
||||||
|
|
||||||
|
@Value("${gisbi.machine-id:1}")
|
||||||
|
public void setMachineId(long machineId) {
|
||||||
|
this.machineId = machineId;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 起始的时间戳
|
* 起始的时间戳
|
||||||
*/
|
*/
|
||||||
@ -44,6 +54,10 @@ public class SnowFlake {
|
|||||||
this.machineId = machineId;
|
this.machineId = machineId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public SnowFlake() {
|
||||||
|
this.datacenterId = 1;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 产生下一个ID
|
* 产生下一个ID
|
||||||
*
|
*
|
||||||
|
@ -8,7 +8,7 @@ public class VersionUtil {
|
|||||||
public static String getRandomVersion() {
|
public static String getRandomVersion() {
|
||||||
Environment environment = CommonBeanFactory.getBean(Environment.class);
|
Environment environment = CommonBeanFactory.getBean(Environment.class);
|
||||||
assert environment != null;
|
assert environment != null;
|
||||||
return environment.getProperty("gisbi.version", "1.0.0");
|
return environment.getProperty("gisbi.version", "2.0.0");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -103,7 +103,7 @@ public class WhitelistUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void invalidUrl(String requestURI) {
|
private static void invalidUrl(String requestURI) {
|
||||||
if (requestURI.contains("./") || requestURI.contains(".%") || (requestURI.contains(";") && !requestURI.contains("?"))) {
|
if (requestURI.contains("./") || requestURI.contains(".%") || requestURI.toLowerCase().contains("%2e") || (requestURI.contains(";") && !requestURI.contains("?"))) {
|
||||||
DEException.throwException(INTERFACE_ADDRESS_INVALID.code(), String.format("%s [%s]", INTERFACE_ADDRESS_INVALID.message(), requestURI));
|
DEException.throwException(INTERFACE_ADDRESS_INVALID.code(), String.format("%s [%s]", INTERFACE_ADDRESS_INVALID.message(), requestURI));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user