review code.

This commit is contained in:
lijiahang
2023-07-06 15:01:36 +08:00
parent 27bf523001
commit 87d919c742
17 changed files with 138 additions and 83 deletions

View File

@@ -113,6 +113,11 @@
<artifactId>orion-ops-spring-boot-starter-storage</artifactId> <artifactId>orion-ops-spring-boot-starter-storage</artifactId>
<version>${revision}</version> <version>${revision}</version>
</dependency> </dependency>
<dependency>
<groupId>com.orion.ops</groupId>
<artifactId>orion-ops-spring-boot-starter-security</artifactId>
<version>${revision}</version>
</dependency>
<!-- websocket --> <!-- websocket -->
<dependency> <dependency>

View File

@@ -12,4 +12,8 @@ public class Const implements com.orion.lang.constant.Const {
private Const() { private Const() {
} }
public static final Integer NOT_DELETE = 0;
public static final Integer IS_DELETED = 1;
} }

View File

@@ -1,4 +1,4 @@
package com.orion.ops.framework.log.core.utils; package com.orion.ops.framework.common.utils;
import com.orion.lang.constant.Const; import com.orion.lang.constant.Const;
@@ -16,9 +16,9 @@ import java.util.stream.Stream;
* @version 1.0.0 * @version 1.0.0
* @since 2023/6/28 23:21 * @since 2023/6/28 23:21
*/ */
public class Utils { public class ConfigUtils {
private Utils() { private ConfigUtils() {
} }
public static List<String> parseStringList(List<String> list) { public static List<String> parseStringList(List<String> list) {

View File

@@ -0,0 +1,51 @@
package com.orion.ops.framework.common.utils;
import com.orion.lang.utils.collect.Maps;
import com.orion.lang.utils.reflect.Annotations;
import com.orion.ops.framework.common.constant.Const;
import io.swagger.v3.oas.annotations.Operation;
import java.lang.reflect.Method;
import java.util.Map;
/**
* swagger 工具类
*
* @author Jiahang Li
* @version 1.0.0
* @since 2023/7/6 14:52
*/
public class SwaggerUtils {
/**
* api 描述
*/
private static final Map<String, String> SUMMARY_MAPPING = Maps.newMap();
private SwaggerUtils() {
}
/**
* 获取 api 描述
*
* @param m method
* @return summary
*/
public static String getOperationSummary(Method m) {
// 缓存中获取描述
String key = m.toString();
String cache = SUMMARY_MAPPING.get(key);
if (cache != null) {
return cache;
}
// 获取注解描述
Operation operation = Annotations.getAnnotation(m, Operation.class);
String summary = Const.EMPTY;
if (operation != null) {
summary = operation.summary();
}
SUMMARY_MAPPING.put(key, summary);
return summary;
}
}

View File

@@ -1,6 +1,6 @@
package com.orion.ops.framework.log.core.config; package com.orion.ops.framework.log.core.config;
import com.orion.ops.framework.log.core.utils.Utils; import com.orion.ops.framework.common.utils.ConfigUtils;
import lombok.Data; import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
@@ -32,7 +32,7 @@ public class LogPrinterConfig {
} }
public void setHeaders(List<String> headers) { public void setHeaders(List<String> headers) {
this.headers = Utils.parseStringList(headers, String::toLowerCase); this.headers = ConfigUtils.parseStringList(headers, String::toLowerCase);
} }
} }

View File

@@ -1,6 +1,6 @@
package com.orion.ops.framework.log.core.config; package com.orion.ops.framework.log.core.config;
import com.orion.ops.framework.log.core.utils.Utils; import com.orion.ops.framework.common.utils.ConfigUtils;
import lombok.Data; import lombok.Data;
import java.util.List; import java.util.List;
@@ -26,11 +26,11 @@ public class LogPrinterFieldConfig {
private List<String> desensitize; private List<String> desensitize;
public void setIgnore(List<String> ignore) { public void setIgnore(List<String> ignore) {
this.ignore = Utils.parseStringList(ignore); this.ignore = ConfigUtils.parseStringList(ignore);
} }
public void setDesensitize(List<String> desensitize) { public void setDesensitize(List<String> desensitize) {
this.desensitize = Utils.parseStringList(desensitize); this.desensitize = ConfigUtils.parseStringList(desensitize);
} }
} }

View File

@@ -9,13 +9,10 @@ import com.orion.lang.utils.Desensitizes;
import com.orion.lang.utils.Objects1; import com.orion.lang.utils.Objects1;
import com.orion.lang.utils.collect.Lists; import com.orion.lang.utils.collect.Lists;
import com.orion.lang.utils.collect.Maps; import com.orion.lang.utils.collect.Maps;
import com.orion.lang.utils.reflect.Annotations;
import com.orion.lang.utils.reflect.Classes; import com.orion.lang.utils.reflect.Classes;
import com.orion.ops.framework.common.annotation.IgnoreLog; import com.orion.ops.framework.common.annotation.IgnoreLog;
import com.orion.ops.framework.common.constant.Const;
import com.orion.ops.framework.common.meta.TraceIdHolder; import com.orion.ops.framework.common.meta.TraceIdHolder;
import com.orion.ops.framework.log.core.config.LogPrinterConfig; import com.orion.ops.framework.log.core.config.LogPrinterConfig;
import io.swagger.v3.oas.annotations.Operation;
import org.aopalliance.intercept.MethodInvocation; import org.aopalliance.intercept.MethodInvocation;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Qualifier;
@@ -53,11 +50,6 @@ public abstract class AbstractLogPrinterInterceptor implements LogPrinterInterce
*/ */
private final LogPrinterConfig config; private final LogPrinterConfig config;
/**
* api 描述
*/
private final Map<String, String> summaryMapping;
/** /**
* 忽略的参数 * 忽略的参数
*/ */
@@ -70,7 +62,6 @@ public abstract class AbstractLogPrinterInterceptor implements LogPrinterInterce
public AbstractLogPrinterInterceptor(LogPrinterConfig config) { public AbstractLogPrinterInterceptor(LogPrinterConfig config) {
this.config = config; this.config = config;
this.summaryMapping = Maps.newMap();
this.ignoreParameter = Maps.newMap(); this.ignoreParameter = Maps.newMap();
} }
@@ -146,29 +137,6 @@ public abstract class AbstractLogPrinterInterceptor implements LogPrinterInterce
*/ */
protected abstract void errorPrinter(Date startTime, String traceId, Throwable throwable); protected abstract void errorPrinter(Date startTime, String traceId, Throwable throwable);
/**
* 获取 api 描述
*
* @param m method
* @return summary
*/
protected String getApiSummary(Method m) {
// 缓存中获取描述
String key = m.toString();
String cache = summaryMapping.get(key);
if (cache != null) {
return cache;
}
// 获取注解描述
Operation operation = Annotations.getAnnotation(m, Operation.class);
String summary = Const.EMPTY;
if (operation != null) {
summary = operation.summary();
}
summaryMapping.put(key, summary);
return summary;
}
/** /**
* 请求参数 json * 请求参数 json
* *

View File

@@ -3,6 +3,7 @@ package com.orion.ops.framework.log.core.interceptor;
import com.orion.lang.utils.Exceptions; import com.orion.lang.utils.Exceptions;
import com.orion.lang.utils.Strings; import com.orion.lang.utils.Strings;
import com.orion.lang.utils.time.Dates; import com.orion.lang.utils.time.Dates;
import com.orion.ops.framework.common.utils.SwaggerUtils;
import com.orion.ops.framework.log.core.config.LogPrinterConfig; import com.orion.ops.framework.log.core.config.LogPrinterConfig;
import com.orion.web.servlet.web.Servlets; import com.orion.web.servlet.web.Servlets;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@@ -47,7 +48,7 @@ public class PrettyLogPrinterInterceptor extends AbstractLogPrinterInterceptor {
// 开始时间 // 开始时间
requestLog.append("\tstart: ").append(Dates.format(startTime, Dates.YMD_HMSS)).append('\n'); requestLog.append("\tstart: ").append(Dates.format(startTime, Dates.YMD_HMSS)).append('\n');
// api 描述 // api 描述
String summary = this.getApiSummary(invocation.getMethod()); String summary = SwaggerUtils.getOperationSummary(invocation.getMethod());
if (!Strings.isEmpty(summary)) { if (!Strings.isEmpty(summary)) {
requestLog.append("\tsummary: ").append(summary).append('\n'); requestLog.append("\tsummary: ").append(summary).append('\n');
} }

View File

@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON;
import com.orion.lang.utils.Exceptions; import com.orion.lang.utils.Exceptions;
import com.orion.lang.utils.Strings; import com.orion.lang.utils.Strings;
import com.orion.lang.utils.time.Dates; import com.orion.lang.utils.time.Dates;
import com.orion.ops.framework.common.utils.SwaggerUtils;
import com.orion.ops.framework.log.core.config.LogPrinterConfig; import com.orion.ops.framework.log.core.config.LogPrinterConfig;
import com.orion.ops.framework.log.core.enums.LogFieldConst; import com.orion.ops.framework.log.core.enums.LogFieldConst;
import com.orion.web.servlet.web.Servlets; import com.orion.web.servlet.web.Servlets;
@@ -51,7 +52,7 @@ public class RowLogPrinterInterceptor extends AbstractLogPrinterInterceptor impl
// 开始时间 // 开始时间
fields.put(START, Dates.format(startTime, Dates.YMD_HMSS)); fields.put(START, Dates.format(startTime, Dates.YMD_HMSS));
// api 描述 // api 描述
String summary = this.getApiSummary(invocation.getMethod()); String summary = SwaggerUtils.getOperationSummary(invocation.getMethod());
if (!Strings.isEmpty(summary)) { if (!Strings.isEmpty(summary)) {
fields.put(SUMMARY, summary); fields.put(SUMMARY, summary);
} }

View File

@@ -44,10 +44,10 @@ public class BaseDO implements Serializable {
private String updater; private String updater;
/** /**
* 是否删除 1未删除 2已删除 * 是否删除 0未删除 1已删除
* *
* @see com.orion.lang.constant.Const#NOT_DELETED * @see com.orion.ops.framework.common.constant.Const#NOT_DELETE
* @see com.orion.lang.constant.Const#IS_DELETED * @see com.orion.ops.framework.common.constant.Const#IS_DELETED
*/ */
@TableLogic @TableLogic
private Boolean deleted; private Boolean deleted;

View File

@@ -6,6 +6,8 @@ import com.orion.lang.utils.Valid;
import com.orion.ops.framework.mybatis.cache.RowCacheHolder; import com.orion.ops.framework.mybatis.cache.RowCacheHolder;
import java.io.Serializable; import java.io.Serializable;
import java.util.Optional;
import java.util.function.Function;
/** /**
* 缓存查询器 * 缓存查询器
@@ -63,30 +65,26 @@ public class CacheQuery<T> {
return this; return this;
} }
@SuppressWarnings("unchecked") public <R> Optional<R> get(Function<T, R> mapper) {
public <R> R get(Class<R> c) { Valid.notNull(mapper, "convert function is null");
T row = this.get(); return this.get().map(mapper);
// FIXME mapstruct
return (R) row;
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public T get() { public Optional<T> get() {
Class<? extends BaseMapper<T>> mapperClass = (Class<? extends BaseMapper<T>>) dao.getClass(); Class<? extends BaseMapper<T>> mapperClass = (Class<? extends BaseMapper<T>>) dao.getClass();
// 不查询缓存 // 不查询缓存
if (!force) { if (!force) {
// 从缓存中获取 // 从缓存中获取
Store<T> store = RowCacheHolder.get(mapperClass, id); Store<T> store = RowCacheHolder.get(mapperClass, id);
// 设置过缓存 return Optional.ofNullable(store)
if (store != null) { .map(Store::get);
return store.get();
}
} }
// 查询 // 查询
T row = dao.selectById(id); T row = dao.selectById(id);
// 设置缓存 // 设置缓存
RowCacheHolder.set(mapperClass, id, row); RowCacheHolder.set(mapperClass, id, row);
return row; return Optional.ofNullable(row);
} }
} }

View File

@@ -7,7 +7,6 @@ import com.orion.lang.define.wrapper.PageRequest;
import com.orion.lang.define.wrapper.Pager; import com.orion.lang.define.wrapper.Pager;
import com.orion.lang.utils.Valid; import com.orion.lang.utils.Valid;
import com.orion.lang.utils.collect.Lists; import com.orion.lang.utils.collect.Lists;
import com.orion.lang.utils.convert.Converts;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
@@ -53,19 +52,19 @@ public class DataQuery<T> {
return Optional.ofNullable(dao.selectOne(wrapper)); return Optional.ofNullable(dao.selectOne(wrapper));
} }
// FIXME mapstruct public <R> Optional<R> get(Function<T, R> mapper) {
public <R> Optional<R> get(Class<R> c) { Valid.notNull(mapper, "convert function is null");
return Optional.ofNullable(dao.selectOne(wrapper)) return Optional.ofNullable(dao.selectOne(wrapper))
.map(s -> Converts.to(s, c)); .map(mapper);
} }
public Stream<T> list() { public Stream<T> list() {
return dao.selectList(wrapper).stream(); return dao.selectList(wrapper).stream();
} }
// FIXME mapstruct public <R> List<R> list(Function<T, R> mapper) {
public <R> List<R> list(Class<R> c) { Valid.notNull(mapper, "convert function is null");
return Converts.toList(dao.selectList(wrapper), c); return Lists.map(dao.selectList(wrapper), mapper);
} }
public Long count() { public Long count() {
@@ -80,13 +79,8 @@ public class DataQuery<T> {
return this.dataGrid(Function.identity()); return this.dataGrid(Function.identity());
} }
// FIXME mapstruct public <R> DataGrid<R> dataGrid(Function<T, R> mapper) {
public <R> DataGrid<R> dataGrid(Class<R> c) { Valid.notNull(mapper, "convert function is null");
return this.dataGrid(t -> Converts.to(t, c));
}
public <R> DataGrid<R> dataGrid(Function<T, R> convert) {
Valid.notNull(convert, "convert is null");
Valid.notNull(page, "page is null"); Valid.notNull(page, "page is null");
Valid.notNull(wrapper, "wrapper is null"); Valid.notNull(wrapper, "wrapper is null");
Long count = dao.selectCount(wrapper); Long count = dao.selectCount(wrapper);
@@ -96,7 +90,7 @@ public class DataQuery<T> {
if (next) { if (next) {
wrapper.last(pager.getSql()); wrapper.last(pager.getSql());
List<R> rows = dao.selectList(wrapper).stream() List<R> rows = dao.selectList(wrapper).stream()
.map(convert) .map(mapper)
.collect(Collectors.toList()); .collect(Collectors.toList());
pager.setRows(rows); pager.setRows(rows);
} else { } else {

View File

@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>com.orion.ops</groupId>
<artifactId>orion-ops-framework</artifactId>
<version>${revision}</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>orion-ops-spring-boot-starter-security</artifactId>
<name>${project.artifactId}</name>
<packaging>jar</packaging>
<description>项目 security 配置包</description>
<url>https://github.com/lijiahangmax/orion-ops-pro</url>
<dependencies>
<dependency>
<groupId>com.orion.ops</groupId>
<artifactId>orion-ops-common</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-websocket</artifactId>
</dependency>
</dependencies>
</project>

View File

@@ -1,11 +1,10 @@
package com.orion.ops.framework.storage.core.client.local; package com.orion.ops.framework.storage.core.client.local;
import com.orion.lang.utils.io.FileWriters;
import com.orion.lang.utils.io.Files1; import com.orion.lang.utils.io.Files1;
import com.orion.lang.utils.io.Streams;
import com.orion.ops.framework.storage.core.client.AbstractFileClient; import com.orion.ops.framework.storage.core.client.AbstractFileClient;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream;
/** /**
* 本地文件客户端 * 本地文件客户端
@@ -31,13 +30,7 @@ public class LocalFileClient extends AbstractFileClient<LocalFileClientConfig> {
// 获取实际文件路径 // 获取实际文件路径
String absolutePath = this.getAbsolutePath(returnPath); String absolutePath = this.getAbsolutePath(returnPath);
// 上传文件 // 上传文件
try (OutputStream out = Files1.openOutputStreamFast(absolutePath)) { FileWriters.writeFast(absolutePath, in, autoClose);
Streams.transfer(in, out);
} finally {
if (autoClose) {
Streams.close(in);
}
}
return returnPath; return returnPath;
} }

View File

@@ -28,6 +28,7 @@
<module>orion-ops-spring-boot-starter-desensitize</module> <module>orion-ops-spring-boot-starter-desensitize</module>
<module>orion-ops-spring-boot-starter-log</module> <module>orion-ops-spring-boot-starter-log</module>
<module>orion-ops-spring-boot-starter-storage</module> <module>orion-ops-spring-boot-starter-storage</module>
<module>orion-ops-spring-boot-starter-security</module>
</modules> </modules>
</project> </project>

View File

@@ -67,7 +67,10 @@
<dependency> <dependency>
<groupId>com.orion.ops</groupId> <groupId>com.orion.ops</groupId>
<artifactId>orion-ops-spring-boot-starter-storage</artifactId> <artifactId>orion-ops-spring-boot-starter-storage</artifactId>
<version>${revision}</version> </dependency>
<dependency>
<groupId>com.orion.ops</groupId>
<artifactId>orion-ops-spring-boot-starter-security</artifactId>
</dependency> </dependency>
<!-- orion-ops biz-modules --> <!-- orion-ops biz-modules -->

View File

@@ -75,8 +75,8 @@ mybatis-plus:
global-config: global-config:
db-config: db-config:
logic-delete-field: deleted logic-delete-field: deleted
logic-not-delete-value: 1 logic-not-delete-value: 0
logic-delete-value: 2 logic-delete-value: 1
springdoc: springdoc:
api-docs: api-docs: