Merge remote-tracking branch 'origin/dev' into dev
This commit is contained in:
@@ -13,6 +13,4 @@ public interface FilterOrderConst {
|
||||
|
||||
int CORS_FILTER = Integer.MIN_VALUE + 2000;
|
||||
|
||||
int MYBATIS_CACHE_CLEAR_FILTER = Integer.MIN_VALUE + 100000;
|
||||
|
||||
}
|
||||
|
||||
@@ -4,17 +4,13 @@ import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
|
||||
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
|
||||
import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
|
||||
import com.orion.ops.framework.common.constant.AutoConfigureOrderConst;
|
||||
import com.orion.ops.framework.common.constant.FilterOrderConst;
|
||||
import com.orion.ops.framework.common.web.filter.FilterCreator;
|
||||
import com.orion.ops.framework.common.security.SecurityHolder;
|
||||
import com.orion.ops.framework.mybatis.core.cache.CacheClearFilter;
|
||||
import com.orion.ops.framework.mybatis.core.handler.FieldFillHandler;
|
||||
import com.orion.ops.framework.mybatis.core.utils.DomainFillUtils;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureOrder;
|
||||
import org.springframework.boot.web.servlet.FilterRegistrationBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
||||
/**
|
||||
@@ -51,12 +47,4 @@ public class OrionMybatisAutoConfiguration {
|
||||
return interceptor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mybatis 缓存清理过滤器
|
||||
*/
|
||||
@Bean
|
||||
public FilterRegistrationBean<CacheClearFilter> rowCacheClearFilterBean() {
|
||||
return FilterCreator.create(new CacheClearFilter(), FilterOrderConst.MYBATIS_CACHE_CLEAR_FILTER);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
package com.orion.ops.framework.mybatis.core.cache;
|
||||
|
||||
import org.springframework.web.filter.OncePerRequestFilter;
|
||||
|
||||
import javax.servlet.FilterChain;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* mybatis 缓存清理过滤器
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2023/6/25 15:14
|
||||
*/
|
||||
public class CacheClearFilter extends OncePerRequestFilter {
|
||||
|
||||
@Override
|
||||
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
|
||||
try {
|
||||
// 执行请求
|
||||
filterChain.doFilter(request, response);
|
||||
} finally {
|
||||
// 清理缓存
|
||||
CacheHolder.remove();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
package com.orion.ops.framework.mybatis.core.cache;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.orion.lang.define.collect.MultiHashMap;
|
||||
import com.orion.lang.define.wrapper.Ref;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 缓存行持有者
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2023/6/25 14:21
|
||||
*/
|
||||
public class CacheHolder {
|
||||
|
||||
private CacheHolder() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 缓存
|
||||
* <p>
|
||||
* key: mapper
|
||||
* value: id > row
|
||||
*/
|
||||
private static final ThreadLocal<MultiHashMap<BaseMapper<?>, Serializable, Ref<?>>> HOLDER = ThreadLocal.withInitial(MultiHashMap::new);
|
||||
|
||||
/**
|
||||
* 获取缓存
|
||||
*
|
||||
* @param mapper mapper
|
||||
* @param id id
|
||||
* @param <T> domain
|
||||
* @return cacheWrapper
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> Ref<T> get(BaseMapper<?> mapper, Serializable id) {
|
||||
return (Ref<T>) HOLDER.get().get(mapper, id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置缓存
|
||||
*
|
||||
* @param mapper mapper
|
||||
* @param id id
|
||||
* @param row row
|
||||
* @param <T> domainClass
|
||||
*/
|
||||
public static <T> void set(BaseMapper<T> mapper, Serializable id, T row) {
|
||||
HOLDER.get().put(mapper, id, new Ref<>(row));
|
||||
}
|
||||
|
||||
/**
|
||||
* 清空缓存
|
||||
*/
|
||||
public static void remove() {
|
||||
HOLDER.remove();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,11 +3,9 @@ package com.orion.ops.framework.mybatis.core.mapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.extension.toolkit.Db;
|
||||
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;
|
||||
|
||||
/**
|
||||
@@ -56,25 +54,6 @@ public interface IMapper<T> extends BaseMapper<T> {
|
||||
return DataQuery.of(this, wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 CacheQuery 对象
|
||||
*
|
||||
* @return CacheQuery
|
||||
*/
|
||||
default CacheQuery<T> cache() {
|
||||
return CacheQuery.of(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 CacheQuery 对象
|
||||
*
|
||||
* @param id id
|
||||
* @return CacheQuery
|
||||
*/
|
||||
default CacheQuery<T> cache(Serializable id) {
|
||||
return CacheQuery.of(this, id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量插入
|
||||
*
|
||||
|
||||
@@ -1,95 +0,0 @@
|
||||
package com.orion.ops.framework.mybatis.core.query;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.orion.lang.define.wrapper.Ref;
|
||||
import com.orion.lang.utils.Valid;
|
||||
import com.orion.ops.framework.mybatis.core.cache.CacheHolder;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* 缓存查询器
|
||||
* <p>
|
||||
* 查询会存入缓存
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2023/6/25 13:05
|
||||
*/
|
||||
public class CacheQuery<T> {
|
||||
|
||||
private final BaseMapper<T> dao;
|
||||
|
||||
private Serializable id;
|
||||
|
||||
private boolean force;
|
||||
|
||||
private CacheQuery(BaseMapper<T> dao, Serializable id) {
|
||||
this.dao = dao;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public static <T> CacheQuery<T> of(BaseMapper<T> dao) {
|
||||
Valid.notNull(dao, "dao is null");
|
||||
return new CacheQuery<>(dao, null);
|
||||
}
|
||||
|
||||
public static <T> CacheQuery<T> of(BaseMapper<T> dao, Serializable id) {
|
||||
Valid.notNull(dao, "dao is null");
|
||||
Valid.notNull(id, "id is null");
|
||||
return new CacheQuery<>(dao, id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置 id
|
||||
*
|
||||
* @param id id
|
||||
* @return this
|
||||
*/
|
||||
public CacheQuery<T> id(Serializable id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 强制查询
|
||||
*
|
||||
* @param id id
|
||||
* @return this
|
||||
*/
|
||||
public CacheQuery<T> force(Serializable id) {
|
||||
this.force = true;
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
public <R> Optional<R> optional(Function<T, R> mapper) {
|
||||
Valid.notNull(mapper, "convert function is null");
|
||||
return Optional.ofNullable(this.get())
|
||||
.map(mapper);
|
||||
}
|
||||
|
||||
public Optional<T> optional() {
|
||||
return Optional.ofNullable(this.get());
|
||||
}
|
||||
|
||||
public T get() {
|
||||
// 不查询缓存
|
||||
if (!force) {
|
||||
// 从缓存中获取
|
||||
Ref<T> ref = CacheHolder.get(dao, id);
|
||||
// 命中直接返回
|
||||
if (ref != null) {
|
||||
return ref.get();
|
||||
}
|
||||
}
|
||||
// 查询
|
||||
T row = dao.selectById(id);
|
||||
// 设置缓存
|
||||
CacheHolder.set(dao, id, row);
|
||||
return row;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -7,20 +7,18 @@ SELECT @MODULE_KEY_ID:= id FROM dict_key WHERE key_name = 'operatorLogModule' AN
|
||||
SELECT @MODULE_KEY_MAX_SORT:= IFNULL(MAX(sort), 0) FROM dict_value where key_id = @MODULE_KEY_ID AND deleted = 0;
|
||||
-- 类型 key id
|
||||
SELECT @TYPE_KEY_ID:= id FROM dict_key WHERE key_name = 'operatorLogType' AND deleted = 0;
|
||||
-- 类型 key 排序
|
||||
SELECT @TYPE_KEY_MAX_SORT:= IFNULL(MAX(sort), 0) FROM dict_value WHERE key_id = @TYPE_KEY_ID AND deleted = 0;
|
||||
-- 插入类型
|
||||
INSERT INTO dict_value
|
||||
(`key_id`, `key_name`, `value`, `label`, `extra`, `sort`, `create_time`, `update_time`, `creator`, `updater`, `deleted`)
|
||||
VALUES
|
||||
(@MODULE_KEY_ID, 'operatorLogModule', '${package.ModuleName}:${typeHyphen}', '$!{table.comment}', '{}', @MODULE_KEY_MAX_SORT + 10, now(), now(), '1', '1', 0),
|
||||
(@TYPE_KEY_ID, 'operatorLogType', '${typeHyphen}:create', '创建$!{table.comment}', '{}', @TYPE_KEY_MAX_SORT + 10, now(), now(), '1', '1', 0),
|
||||
(@TYPE_KEY_ID, 'operatorLogType', '${typeHyphen}:update', '更新$!{table.comment}', '{}', @TYPE_KEY_MAX_SORT + 20, now(), now(), '1', '1', 0),
|
||||
(@TYPE_KEY_ID, 'operatorLogType', '${typeHyphen}:create', '创建$!{table.comment}', '{}', 10, now(), now(), '1', '1', 0),
|
||||
(@TYPE_KEY_ID, 'operatorLogType', '${typeHyphen}:update', '更新$!{table.comment}', '{}', 20, now(), now(), '1', '1', 0),
|
||||
#if($meta.enableExport)
|
||||
(@TYPE_KEY_ID, 'operatorLogType', '${typeHyphen}:delete', '删除$!{table.comment}', '{}', @TYPE_KEY_MAX_SORT + 30, now(), now(), '1', '1', 0),
|
||||
(@TYPE_KEY_ID, 'operatorLogType', '${typeHyphen}:export', '导出$!{table.comment}', '{}', @TYPE_KEY_MAX_SORT + 40, now(), now(), '1', '1', 0);
|
||||
(@TYPE_KEY_ID, 'operatorLogType', '${typeHyphen}:delete', '删除$!{table.comment}', '{}', 30, now(), now(), '1', '1', 0),
|
||||
(@TYPE_KEY_ID, 'operatorLogType', '${typeHyphen}:export', '导出$!{table.comment}', '{}', 40, now(), now(), '1', '1', 0);
|
||||
#else
|
||||
(@TYPE_KEY_ID, 'operatorLogType', '${typeHyphen}:delete', '删除$!{table.comment}', '{}', @TYPE_KEY_MAX_SORT + 30, now(), now(), '1', '1', 0);
|
||||
(@TYPE_KEY_ID, 'operatorLogType', '${typeHyphen}:delete', '删除$!{table.comment}', '{}', 30, now(), now(), '1', '1', 0);
|
||||
#end
|
||||
#end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user