添加默认文件客户端.
This commit is contained in:
@@ -4,11 +4,9 @@ import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.generator.AutoGenerator;
|
||||
import com.baomidou.mybatisplus.generator.config.*;
|
||||
import com.baomidou.mybatisplus.generator.config.builder.CustomFile;
|
||||
import com.baomidou.mybatisplus.generator.config.converts.MySqlTypeConvert;
|
||||
import com.baomidou.mybatisplus.generator.config.querys.MySqlQuery;
|
||||
import com.baomidou.mybatisplus.generator.config.rules.DateType;
|
||||
import com.baomidou.mybatisplus.generator.config.rules.DbColumnType;
|
||||
import com.baomidou.mybatisplus.generator.config.rules.IColumnType;
|
||||
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
|
||||
import com.orion.lang.constant.Const;
|
||||
import com.orion.lang.utils.ext.yml.YmlExt;
|
||||
@@ -19,6 +17,7 @@ import org.apache.ibatis.annotations.Mapper;
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.File;
|
||||
import java.sql.Types;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -164,16 +163,13 @@ public class CodeGenerator {
|
||||
private static DataSourceConfig getDataSourceConfig(String url, String username, String password) {
|
||||
DataSourceConfig dsConfig = new DataSourceConfig.Builder(url, username, password)
|
||||
// 转换器
|
||||
.typeConvert(new MySqlTypeConvert() {
|
||||
@Override
|
||||
public IColumnType processTypeConvert(GlobalConfig globalConfig, String fieldType) {
|
||||
if (fieldType.toLowerCase().contains("bit")) {
|
||||
.typeConvertHandler((globalConfig, typeRegistry, metaInfo) -> {
|
||||
switch (metaInfo.getJdbcType().TYPE_CODE) {
|
||||
case Types.BIT:
|
||||
case Types.TINYINT:
|
||||
return DbColumnType.INTEGER;
|
||||
}
|
||||
if (fieldType.toLowerCase().contains("tinyint")) {
|
||||
return DbColumnType.INTEGER;
|
||||
}
|
||||
return super.processTypeConvert(globalConfig, fieldType);
|
||||
default:
|
||||
return typeRegistry.getColumnType(metaInfo);
|
||||
}
|
||||
})
|
||||
// 查询器
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.orion.ops.framework.storage.config;
|
||||
|
||||
import com.orion.ops.framework.common.constant.AutoConfigureOrderConst;
|
||||
import com.orion.ops.framework.storage.core.client.FileClient;
|
||||
import com.orion.ops.framework.storage.core.client.PrimaryFileClient;
|
||||
import com.orion.ops.framework.storage.core.client.local.LocalFileClient;
|
||||
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureOrder;
|
||||
@@ -30,10 +31,18 @@ public class OrionStorageAutoConfiguration {
|
||||
private StorageConfig config;
|
||||
|
||||
/**
|
||||
* 本地文件客户端
|
||||
* 默认文件客户端
|
||||
*/
|
||||
@Bean
|
||||
@Primary
|
||||
public FileClient primaryFileClient() {
|
||||
return new PrimaryFileClient();
|
||||
}
|
||||
|
||||
/**
|
||||
* 本地文件客户端
|
||||
*/
|
||||
@Bean
|
||||
@ConditionalOnProperty(value = "orion.storage.local.enabled", havingValue = "true")
|
||||
public FileClient localFileClient() {
|
||||
return new LocalFileClient(config.getLocal());
|
||||
|
||||
@@ -20,6 +20,10 @@ public abstract class AbstractFileClient<Config extends FileClientConfig> implem
|
||||
|
||||
public AbstractFileClient(Config config) {
|
||||
this.config = config;
|
||||
// 设置默认文件客户端
|
||||
if (config.isPrimary()) {
|
||||
PrimaryFileClient.delegate = this;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -12,6 +12,11 @@ import lombok.Data;
|
||||
@Data
|
||||
public class FileClientConfig {
|
||||
|
||||
/**
|
||||
* 是否为默认客户端
|
||||
*/
|
||||
protected boolean primary;
|
||||
|
||||
/**
|
||||
* 是否启用
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
package com.orion.ops.framework.storage.core.client;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
/**
|
||||
* 默认文件客户端
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2023/7/14 11:01
|
||||
*/
|
||||
public class PrimaryFileClient implements FileClient {
|
||||
|
||||
protected static FileClient delegate;
|
||||
|
||||
@Override
|
||||
public String upload(String path, byte[] content) throws Exception {
|
||||
return delegate.upload(path, content);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String upload(String path, byte[] content, boolean overrideIfExist) throws Exception {
|
||||
return delegate.upload(path, content, overrideIfExist);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String upload(String path, InputStream in) throws Exception {
|
||||
return delegate.upload(path, in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String upload(String path, InputStream in, boolean autoClose) throws Exception {
|
||||
return delegate.upload(path, in, autoClose);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String upload(String path, InputStream in, boolean autoClose, boolean overrideIfExist) throws Exception {
|
||||
return delegate.upload(path, in, autoClose, overrideIfExist);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isExists(String path) {
|
||||
return delegate.isExists(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean delete(String path) throws Exception {
|
||||
return delegate.delete(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getContent(String path) throws Exception {
|
||||
return delegate.getContent(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream getContentInputStream(String path) throws Exception {
|
||||
return delegate.getContentInputStream(path);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -12,6 +12,12 @@
|
||||
}
|
||||
],
|
||||
"properties": [
|
||||
{
|
||||
"name": "orion.storage.local.primary",
|
||||
"type": "java.lang.Boolean",
|
||||
"description": "是否为默认客户端.",
|
||||
"defaultValue": false
|
||||
},
|
||||
{
|
||||
"name": "orion.storage.local.enabled",
|
||||
"type": "java.lang.Boolean",
|
||||
|
||||
@@ -20,7 +20,7 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
@RequestMapping("/server/bootstrap")
|
||||
public class BootstrapController {
|
||||
|
||||
@Operation(summary = "检测心跳")
|
||||
@Operation(summary = "健康检测")
|
||||
@GetMapping("/health")
|
||||
public String health() {
|
||||
return "server ok";
|
||||
|
||||
@@ -165,6 +165,7 @@ orion:
|
||||
storage:
|
||||
# 本地文件存储
|
||||
local:
|
||||
primary: true
|
||||
enabled: true
|
||||
name-append-trace-id: true
|
||||
storage-path: ${user.home}
|
||||
|
||||
Reference in New Issue
Block a user