review code.

This commit is contained in:
lijiahang
2023-07-21 14:00:01 +08:00
parent 70e5abadc5
commit 26868254e3
19 changed files with 245 additions and 32 deletions

View File

@@ -12,11 +12,6 @@ public class Const implements com.orion.lang.constant.Const {
private Const() {
}
/**
* 同 ${orion.version} 迭代时候需要手动更改
*/
public static String VERSION = "1.0.0";
public static final Integer NOT_DELETE = 0;
public static final Integer IS_DELETED = 1;

View File

@@ -9,12 +9,15 @@ package com.orion.ops.framework.common.constant;
*/
public interface OrionOpsProConst {
/**
* 同 ${orion.version} 迭代时候需要手动更改
*/
String VERSION = "1.0.0";
String GITHUB = "https://github.com/lijiahangmax/orion-ops-pro";
String GITEE = "https://gitee.com/lijiahangmax/orion-ops-pro";
String ISSUES = "https://gitee.com/lijiahangmax/orion-ops-pro/issues";
String VERSION = "1.0.0";
}

View File

@@ -4,6 +4,8 @@ import com.orion.ops.framework.common.crypto.ValueCrypto;
/**
* 加密工具类
* <p>
* PrimaryValueCrypto 代理类工具
*
* @author Jiahang Li
* @version 1.0.0
@@ -13,6 +15,9 @@ public class CryptoUtils {
private static ValueCrypto delegate;
private CryptoUtils() {
}
/**
* 加密
*

View File

@@ -0,0 +1,136 @@
package com.orion.ops.framework.common.utils;
import com.orion.ops.framework.common.file.FileClient;
import java.io.InputStream;
/**
* 文件客户端工具
* <p>
* PrimaryFileClient 代理类工具
*
* @author Jiahang Li
* @version 1.0.0
* @since 2023/7/21 12:05
*/
public class FileClientUtils {
private static FileClient delegate;
private FileClientUtils() {
}
/**
* 上传文件
*
* @param path 文件路径
* @param content 文件内容
* @return 路径
* @throws Exception Exception
*/
public static String upload(String path, byte[] content) throws Exception {
return delegate.upload(path, content);
}
/**
* 上传文件
*
* @param path 文件路径
* @param content 文件内容
* @param overrideIfExist 文件存在是否覆盖
* @return 路径
* @throws Exception Exception
*/
public static String upload(String path, byte[] content, boolean overrideIfExist) throws Exception {
return delegate.upload(path, content, overrideIfExist);
}
/**
* 上传文件
*
* @param path 文件路径
* @param in in
* @return 路径
* @throws Exception Exception
*/
public static String upload(String path, InputStream in) throws Exception {
return delegate.upload(path, in);
}
/**
* 上传文件
*
* @param path 文件路径
* @param in in
* @param autoClose autoClose
* @return 路径
* @throws Exception Exception
*/
public static String upload(String path, InputStream in, boolean autoClose) throws Exception {
return delegate.upload(path, in, autoClose);
}
/**
* 上传文件
*
* @param path 文件路径
* @param in in
* @param autoClose autoClose
* @param overrideIfExist 文件存在是否覆盖
* @return 路径
* @throws Exception Exception
*/
public static String upload(String path, InputStream in, boolean autoClose, boolean overrideIfExist) throws Exception {
return delegate.upload(path, in, autoClose, overrideIfExist);
}
// TODO getOutputStream
/**
* 检测文件是否存在
*
* @param path path
* @return 是否存在
*/
public static boolean isExists(String path) {
return delegate.isExists(path);
}
/**
* 删除文件
*
* @param path 路径
* @return 是否删除
* @throws Exception Exception
*/
public static boolean delete(String path) throws Exception {
return delegate.delete(path);
}
/**
* 获取文件内容
*
* @param path path
* @return bytes
* @throws Exception Exception
*/
public static byte[] getContent(String path) throws Exception {
return delegate.getContent(path);
}
/**
* 获取文件输入流
*
* @param path path
* @return stream
* @throws Exception Exception
*/
public static InputStream getContentInputStream(String path) throws Exception {
return delegate.getContentInputStream(path);
}
public static void setDelegate(FileClient delegate) {
FileClientUtils.delegate = delegate;
}
}

View File

@@ -7,7 +7,7 @@ import com.orion.ops.framework.desensitize.core.serializer.DesensitizeJsonSerial
import java.lang.annotation.*;
/**
* 脱敏配置元注解
* FastJson / Jackson 脱敏配置元注解
* <p>
* 标注在字段上则标记该字段执行 http 序列化时脱敏
*

View File

@@ -3,7 +3,7 @@ package com.orion.ops.framework.desensitize.core.annotation;
import java.lang.annotation.*;
/**
* 脱敏配置元注解
* FastJson 脱敏配置元注解
* <p>
* 标注在类上则标记该类执行序列化时会执行脱敏
*

View File

@@ -25,7 +25,7 @@ import com.baomidou.mybatisplus.generator.config.po.TableInfo;
import com.baomidou.mybatisplus.generator.engine.AbstractTemplateEngine;
import com.orion.lang.utils.Strings;
import com.orion.lang.utils.reflect.Fields;
import com.orion.ops.framework.common.constant.Const;
import com.orion.ops.framework.common.constant.OrionOpsProConst;
import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.Velocity;
@@ -161,7 +161,7 @@ public class VelocityTemplateEngine extends AbstractTemplateEngine {
// http 注释标识
objectMap.put("httpComment", "###");
// 版本
objectMap.put("since", Const.VERSION);
objectMap.put("since", OrionOpsProConst.VERSION);
// 替换业务注释
tableInfo.setComment(tables.get(tableInfo.getName()).getComment());
// 实体名称

View File

@@ -7,6 +7,7 @@ import com.orion.ops.framework.mybatis.core.query.CacheQuery;
import com.orion.ops.framework.mybatis.core.query.Conditions;
import com.orion.ops.framework.mybatis.core.query.DataQuery;
import java.io.Serializable;
import java.util.Collection;
/**
@@ -55,6 +56,16 @@ public interface IMapper<T> extends BaseMapper<T> {
return CacheQuery.of(this);
}
/**
* 获取 CacheQuery 对象
*
* @param id id
* @return CacheQuery
*/
default CacheQuery<T> cache(Serializable id) {
return CacheQuery.of(this, id);
}
/**
* 批量插入
*

View File

@@ -65,26 +65,31 @@ public class CacheQuery<T> {
return this;
}
public <R> Optional<R> get(Function<T, R> mapper) {
public <R> Optional<R> optional(Function<T, R> mapper) {
Valid.notNull(mapper, "convert function is null");
return this.get().map(mapper);
return Optional.ofNullable(this.get())
.map(mapper);
}
public Optional<T> get() {
public Optional<T> optional() {
return Optional.ofNullable(this.get());
}
public T get() {
// 不查询缓存
if (!force) {
// 从缓存中获取
Store<T> store = CacheHolder.get(dao, id);
// 命中直接返回
if (store != null) {
return Optional.of(store).map(Store::get);
return store.get();
}
}
// 查询
T row = dao.selectById(id);
// 设置缓存
CacheHolder.set(dao, id, row);
return Optional.ofNullable(row);
return row;
}
}

View File

@@ -2,12 +2,14 @@ package com.orion.ops.framework.security.config;
import com.orion.ops.framework.common.constant.AutoConfigureOrderConst;
import com.orion.ops.framework.common.crypto.ValueCrypto;
import com.orion.ops.framework.security.core.crypto.PrimaryValueCrypto;
import com.orion.ops.framework.security.core.crypto.aes.AesCryptoProcessor;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigureOrder;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Primary;
import javax.annotation.Resource;
@@ -26,12 +28,21 @@ public class OrionCryptoAutoConfiguration {
@Resource
private CryptoConfig config;
/**
* @return 默认加密器
*/
@Bean(name = "valueCrypto")
@Primary
public ValueCrypto primaryValueCrypto() {
return new PrimaryValueCrypto();
}
/**
* @return aes 加密器
*/
@Bean(initMethod = "init")
@ConditionalOnProperty(value = "orion.crypto.aes.enabled", havingValue = "true")
public ValueCrypto aes() {
public ValueCrypto aesValueCrypto() {
return new AesCryptoProcessor(config.getAes());
}

View File

@@ -18,6 +18,7 @@ public abstract class CryptoProcessor<Config extends CryptoConfig> implements Va
this.config = config;
// 设置为默认加密器
if (config.isPrimary()) {
PrimaryValueCrypto.delegate = this;
CryptoUtils.setDelegate(this);
}
}

View File

@@ -0,0 +1,30 @@
package com.orion.ops.framework.security.core.crypto;
import com.orion.ops.framework.common.crypto.ValueCrypto;
/**
* 默认加密器
*
* @author Jiahang Li
* @version 1.0.0
* @since 2023/7/21 12:11
*/
public class PrimaryValueCrypto implements ValueCrypto {
protected static ValueCrypto delegate;
@Override
public void init() {
}
@Override
public byte[] encrypt(byte[] plain) {
return delegate.encrypt(plain);
}
@Override
public byte[] decrypt(byte[] text) {
return delegate.decrypt(text);
}
}

View File

@@ -1,7 +1,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.common.file.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;
@@ -31,16 +31,16 @@ public class OrionStorageAutoConfiguration {
private StorageConfig config;
/**
* 默认文件客户端
* @return 默认文件客户端
*/
@Bean
@Bean(name = "primaryFileClient")
@Primary
public FileClient primaryFileClient() {
return new PrimaryFileClient();
}
/**
* 本地文件客户端
* @return 本地文件客户端
*/
@Bean
@ConditionalOnProperty(value = "orion.storage.local.enabled", havingValue = "true")

View File

@@ -4,6 +4,8 @@ import com.orion.lang.utils.io.Files1;
import com.orion.lang.utils.io.Streams;
import com.orion.lang.utils.time.Dates;
import com.orion.ops.framework.common.constant.Const;
import com.orion.ops.framework.common.file.FileClient;
import com.orion.ops.framework.common.utils.FileClientUtils;
import java.io.InputStream;
import java.util.Date;
@@ -24,6 +26,7 @@ public abstract class AbstractFileClient<Config extends FileClientConfig> implem
// 设置默认文件客户端
if (config.isPrimary()) {
PrimaryFileClient.delegate = this;
FileClientUtils.setDelegate(this);
}
}

View File

@@ -1,5 +1,7 @@
package com.orion.ops.framework.storage.core.client;
import com.orion.ops.framework.common.file.FileClient;
import java.io.InputStream;
/**