mirror of
https://gitee.com/orangeform/orange-admin.git
synced 2026-01-17 18:46:36 +08:00
commit:1.5多应用版本
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
package com.orange.demo.common.core.annotation;
|
||||
|
||||
import com.orange.demo.common.core.util.DataSourceResolver;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* 基于自定义解析规则的多数据源注解。主要用于标注Service的实现类。
|
||||
*
|
||||
* @author Jerry
|
||||
* @date 2020-08-08
|
||||
*/
|
||||
@Target(ElementType.TYPE)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
public @interface MyDataSourceResolver {
|
||||
|
||||
/**
|
||||
* 多数据源路由键解析接口的Class。
|
||||
* @return 多数据源路由键解析接口的Class。
|
||||
*/
|
||||
Class<? extends DataSourceResolver> resolver();
|
||||
|
||||
/**
|
||||
* DataSourceResolver.resovle方法的入参。
|
||||
* @return DataSourceResolver.resovle方法的入参。
|
||||
*/
|
||||
String arg() default "";
|
||||
}
|
||||
@@ -1,87 +0,0 @@
|
||||
package com.orange.demo.common.core.aop;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.orange.demo.common.core.constant.ApplicationConstant;
|
||||
import com.orange.demo.common.core.util.MyCommonUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Pointcut;
|
||||
import org.slf4j.MDC;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 记录接口的链路traceId、请求参数、应答数据、错误信息和调用时长。
|
||||
*
|
||||
* @author Jerry
|
||||
* @date 2020-08-08
|
||||
*/
|
||||
@Aspect
|
||||
@Component
|
||||
@Order(1)
|
||||
@Slf4j
|
||||
public class AccessLogAspect {
|
||||
|
||||
@Value("")
|
||||
private String applicationName;
|
||||
|
||||
/**
|
||||
* 所有controller方法。
|
||||
*/
|
||||
@Pointcut("execution(public * com.orange.demo..controller..*(..))")
|
||||
public void controllerPointCut() {
|
||||
// 空注释,避免sonar警告
|
||||
}
|
||||
|
||||
@Around("controllerPointCut()")
|
||||
public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
|
||||
HttpServletRequest request =
|
||||
((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest();
|
||||
// 请求流水号
|
||||
String traceId = request.getHeader(ApplicationConstant.HTTP_HEADER_TRACE_ID);
|
||||
if (StringUtils.isBlank(traceId)) {
|
||||
traceId = MyCommonUtil.generateUuid();
|
||||
}
|
||||
MDC.put(ApplicationConstant.HTTP_HEADER_TRACE_ID, traceId);
|
||||
long start = System.currentTimeMillis();
|
||||
// 获取方法参数
|
||||
List<Object> httpReqArgs = new ArrayList<>();
|
||||
Object[] args = joinPoint.getArgs();
|
||||
for (Object object : args) {
|
||||
if (!(object instanceof HttpServletRequest)
|
||||
&& !(object instanceof HttpServletResponse)
|
||||
&& !(object instanceof MultipartFile)) {
|
||||
httpReqArgs.add(object);
|
||||
}
|
||||
}
|
||||
String url = request.getRequestURI();
|
||||
String params = JSON.toJSONString(httpReqArgs);
|
||||
log.info("开始请求,app={}, url={}, reqData={}", applicationName, url, params);
|
||||
Object result = null;
|
||||
try {
|
||||
// 调用原来的方法
|
||||
result = joinPoint.proceed();
|
||||
} catch (Exception e) {
|
||||
log.error("请求报错,app={}, url={}, reqData={}, error={}", applicationName, url, params, e.getMessage());
|
||||
throw e;
|
||||
} finally {
|
||||
// 获取应答报文及接口处理耗时
|
||||
String respData = result == null ? null : JSON.toJSONString(result);
|
||||
log.info("请求完成, app={}, url={},elapse={}ms, respData={}",
|
||||
applicationName, url, (System.currentTimeMillis() - start), respData);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.orange.demo.common.core.aop;
|
||||
|
||||
import com.orange.demo.common.core.annotation.MyDataSource;
|
||||
import com.orange.demo.common.core.config.DataSourceContextHolder;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Pointcut;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 多数据源AOP切面处理类。
|
||||
*
|
||||
* @author Jerry
|
||||
* @date 2020-08-08
|
||||
*/
|
||||
@Aspect
|
||||
@Component
|
||||
@Order(1)
|
||||
@Slf4j
|
||||
public class DataSourceAspect {
|
||||
|
||||
/**
|
||||
* 所有配置MyDataSource注解的Service实现类。
|
||||
*/
|
||||
@Pointcut("execution(public * com.orange.demo..service..*(..)) " +
|
||||
"&& @target(com.orange.demo.common.core.annotation.MyDataSource)")
|
||||
public void datasourcePointCut() {
|
||||
// 空注释,避免sonar警告
|
||||
}
|
||||
|
||||
@Around("datasourcePointCut()")
|
||||
public Object around(ProceedingJoinPoint point) throws Throwable {
|
||||
Class<?> clazz = point.getTarget().getClass();
|
||||
MyDataSource ds = clazz.getAnnotation(MyDataSource.class);
|
||||
// 通过判断 DataSource 中的值来判断当前方法应用哪个数据源
|
||||
DataSourceContextHolder.setDataSourceType(ds.value());
|
||||
log.debug("set datasource is " + ds.value());
|
||||
try {
|
||||
return point.proceed();
|
||||
} finally {
|
||||
DataSourceContextHolder.clear();
|
||||
log.debug("clean datasource");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package com.orange.demo.common.core.aop;
|
||||
|
||||
import com.orange.demo.common.core.annotation.MyDataSourceResolver;
|
||||
import com.orange.demo.common.core.util.DataSourceResolver;
|
||||
import com.orange.demo.common.core.config.DataSourceContextHolder;
|
||||
import com.orange.demo.common.core.util.ApplicationContextHolder;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Pointcut;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 基于自定义解析规则的多数据源AOP切面处理类。
|
||||
*
|
||||
* @author Jerry
|
||||
* @date 2020-08-08
|
||||
*/
|
||||
@Aspect
|
||||
@Component
|
||||
@Order(1)
|
||||
@Slf4j
|
||||
public class DataSourceResolveAspect {
|
||||
|
||||
private Map<Class<? extends DataSourceResolver>, DataSourceResolver> resolverMap = new HashMap<>();
|
||||
|
||||
/**
|
||||
* 所有配置MyDataSourceResovler注解的Service实现类。
|
||||
*/
|
||||
@Pointcut("execution(public * com.orange.demo..service..*(..)) " +
|
||||
"&& @target(com.orange.demo.common.core.annotation.MyDataSourceResolver)")
|
||||
public void datasourceResolverPointCut() {
|
||||
// 空注释,避免sonar警告
|
||||
}
|
||||
|
||||
@Around("datasourceResolverPointCut()")
|
||||
public Object around(ProceedingJoinPoint point) throws Throwable {
|
||||
Class<?> clazz = point.getTarget().getClass();
|
||||
MyDataSourceResolver dsr = clazz.getAnnotation(MyDataSourceResolver.class);
|
||||
Class<? extends DataSourceResolver> resolverClass = dsr.resolver();
|
||||
DataSourceResolver resolver = resolverMap.get(resolverClass);
|
||||
if (resolver == null) {
|
||||
resolver = ApplicationContextHolder.getBean(resolverClass);
|
||||
resolverMap.put(resolverClass, resolver);
|
||||
}
|
||||
int type = resolver.resolve(dsr.arg());
|
||||
// 通过判断 DataSource 中的值来判断当前方法应用哪个数据源
|
||||
DataSourceContextHolder.setDataSourceType(type);
|
||||
log.debug("set datasource is " + type);
|
||||
try {
|
||||
return point.proceed();
|
||||
} finally {
|
||||
DataSourceContextHolder.clear();
|
||||
log.debug("clean datasource");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -20,7 +20,7 @@ import org.springframework.stereotype.Component;
|
||||
@Component
|
||||
@Order(Ordered.LOWEST_PRECEDENCE - 1)
|
||||
@Slf4j
|
||||
public class DictCacheSyncAop {
|
||||
public class DictCacheSyncAspect {
|
||||
|
||||
/**
|
||||
* BaseDictService 字典服务父类中的字典数据增删改的方法。
|
||||
@@ -55,7 +55,7 @@ public interface BaseClient<D, V, K> {
|
||||
* @param id 主键Id。
|
||||
* @return 应答结果对象。
|
||||
*/
|
||||
default ResponseResult<Void> delete(K id) {
|
||||
default ResponseResult<Integer> deleteById(K id) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ public abstract class BaseFallbackFactory<D, V, K, T extends BaseClient<D, V, K>
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseResult<Void> delete(K id) {
|
||||
public ResponseResult<Integer> deleteById(K id) {
|
||||
return ResponseResult.error(ErrorCodeEnum.RPC_DATA_ACCESS_FAILED);
|
||||
}
|
||||
|
||||
|
||||
@@ -168,6 +168,7 @@ public abstract class BaseController<M, V, K> {
|
||||
* @throws RemoteDataBuildException buildRelationForDataList会抛出此异常。
|
||||
*/
|
||||
public ResponseResult<MyPageData<V>> baseListBy(MyQueryParam queryParam, BaseModelMapper<V, M> modelMapper) {
|
||||
boolean dataFilterEnabled = GlobalThreadLocal.setDataFilter(queryParam.getUseDataFilter());
|
||||
if (CollectionUtils.isNotEmpty(queryParam.getSelectFieldList())) {
|
||||
for (String fieldName : queryParam.getSelectFieldList()) {
|
||||
String columnName = MyModelUtil.mapToColumnName(fieldName, modelClass);
|
||||
@@ -200,6 +201,7 @@ public abstract class BaseController<M, V, K> {
|
||||
service().buildRelationForDataList(resultList, MyRelationParam.dictOnly());
|
||||
}
|
||||
List<V> resultVoList = convertToVoList(resultList, modelMapper);
|
||||
GlobalThreadLocal.setDataFilter(dataFilterEnabled);
|
||||
return ResponseResult.success(new MyPageData<>(resultVoList, totalCount));
|
||||
}
|
||||
|
||||
@@ -249,8 +251,10 @@ public abstract class BaseController<M, V, K> {
|
||||
* @return 应答结果对象,包含符合查询过滤条件的记录数量。
|
||||
*/
|
||||
public ResponseResult<Integer> baseCountBy(MyQueryParam queryParam) {
|
||||
boolean dataFilterEnabled = GlobalThreadLocal.setDataFilter(queryParam.getUseDataFilter());
|
||||
String whereClause = MyWhereCriteria.makeCriteriaString(queryParam.getCriteriaList(), modelClass);
|
||||
Integer count = service().getCountByCondition(whereClause);
|
||||
GlobalThreadLocal.setDataFilter(dataFilterEnabled);
|
||||
return ResponseResult.success(count);
|
||||
}
|
||||
|
||||
@@ -261,6 +265,7 @@ public abstract class BaseController<M, V, K> {
|
||||
* @return 应该结果对象,包含聚合计算后的分组Map列表。
|
||||
*/
|
||||
public ResponseResult<List<Map<String, Object>>> baseAggregateBy(MyAggregationParam param) {
|
||||
boolean dataFilterEnabled = GlobalThreadLocal.setDataFilter(param.getUseDataFilter());
|
||||
// 完成一些共同性规则的验证。
|
||||
VerifyAggregationInfo verifyInfo = this.verifyAndParseAggregationParam(param);
|
||||
if (!verifyInfo.isSuccess) {
|
||||
@@ -312,6 +317,7 @@ public abstract class BaseController<M, V, K> {
|
||||
resultMapList.addAll(subResultMapList);
|
||||
}
|
||||
}
|
||||
GlobalThreadLocal.setDataFilter(dataFilterEnabled);
|
||||
return ResponseResult.success(resultMapList);
|
||||
}
|
||||
|
||||
@@ -323,7 +329,7 @@ public abstract class BaseController<M, V, K> {
|
||||
* @param modelMapper 从实体对象到VO对象的映射对象。
|
||||
* @return 转换后的VO域对象列表。
|
||||
*/
|
||||
private List<V> convertToVoList(List<M> modelList, BaseModelMapper<V, M> modelMapper) {
|
||||
protected List<V> convertToVoList(List<M> modelList, BaseModelMapper<V, M> modelMapper) {
|
||||
List<V> resultVoList;
|
||||
if (modelMapper != null) {
|
||||
resultVoList = modelMapper.fromModelList(modelList);
|
||||
@@ -341,7 +347,7 @@ public abstract class BaseController<M, V, K> {
|
||||
* @param modelMapper 从实体对象到VO对象的映射对象。
|
||||
* @return 转换后的VO域对象。
|
||||
*/
|
||||
private V convertToVo(M model, BaseModelMapper<V, M> modelMapper) {
|
||||
protected V convertToVo(M model, BaseModelMapper<V, M> modelMapper) {
|
||||
V resultVo;
|
||||
if (modelMapper != null) {
|
||||
resultVo = modelMapper.fromModel(model);
|
||||
|
||||
@@ -4,6 +4,7 @@ import cn.hutool.core.util.ReflectUtil;
|
||||
import com.orange.demo.common.core.constant.GlobalDeletedFlag;
|
||||
import com.orange.demo.common.core.exception.MyRuntimeException;
|
||||
import com.orange.demo.common.core.cache.DictionaryCache;
|
||||
import com.orange.demo.common.core.object.TokenData;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@@ -35,26 +36,6 @@ public abstract class BaseDictService<M, K> extends BaseService<M, K> implements
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否在服务启动的时候加载。子类可以重载该方法,并在需要的时候手工调用loadCachedData加载数据。
|
||||
*
|
||||
* @return true表示启动即可加载数据,false需要手动调用loadCachedData进行加载。
|
||||
*/
|
||||
@Override
|
||||
public boolean loadOnStartup() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载全部数据到内存,缓存的key只能为映射表的主键。
|
||||
*/
|
||||
@Override
|
||||
public void loadCachedData() {
|
||||
if (loadOnStartup()) {
|
||||
reloadCachedData(false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 重新加载数据库中所有当前表数据到系统内存。
|
||||
*
|
||||
@@ -88,6 +69,9 @@ public abstract class BaseDictService<M, K> extends BaseService<M, K> implements
|
||||
throw new MyRuntimeException(e);
|
||||
}
|
||||
}
|
||||
if (tenantIdField != null) {
|
||||
ReflectUtil.setFieldValue(data, tenantIdField, TokenData.takeFromRequest().getTenantId());
|
||||
}
|
||||
mapper().insert(data);
|
||||
return data;
|
||||
}
|
||||
@@ -102,6 +86,9 @@ public abstract class BaseDictService<M, K> extends BaseService<M, K> implements
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public boolean update(M data, M originalData) {
|
||||
if (tenantIdField != null) {
|
||||
ReflectUtil.setFieldValue(data, tenantIdField, TokenData.takeFromRequest().getTenantId());
|
||||
}
|
||||
if (deletedFlagFieldName != null) {
|
||||
try {
|
||||
setDeletedFlagMethod.invoke(data, GlobalDeletedFlag.NORMAL);
|
||||
@@ -259,6 +246,18 @@ public abstract class BaseDictService<M, K> extends BaseService<M, K> implements
|
||||
this.dictionaryCache.invalidate(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据字典对象将数据从缓存中删除。
|
||||
*
|
||||
* @param data 字典数据。
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void removeDictionaryCacheByModel(M data) {
|
||||
K key = (K) ReflectUtil.getFieldValue(data, idFieldName);
|
||||
this.dictionaryCache.invalidate(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取缓存中的数据数量。
|
||||
*
|
||||
|
||||
@@ -64,7 +64,7 @@ public abstract class BaseService<M, K> implements IBaseService<M, K> {
|
||||
*/
|
||||
protected String idFieldName;
|
||||
/**
|
||||
* 当前Service关联的主数据表中数据字段名称。
|
||||
* 当前Service关联的主数据表中主键列名称。
|
||||
*/
|
||||
protected String idColumnName;
|
||||
/**
|
||||
@@ -75,6 +75,18 @@ public abstract class BaseService<M, K> implements IBaseService<M, K> {
|
||||
* 当前Service关联的主数据表中逻辑删除字段名称。
|
||||
*/
|
||||
protected String deletedFlagColumnName;
|
||||
/**
|
||||
* 当前Service关联的主Model对象租户Id字段。
|
||||
*/
|
||||
protected Field tenantIdField;
|
||||
/**
|
||||
* 当前Service关联的主Model对象租户Id字段名称。
|
||||
*/
|
||||
protected String tenantIdFieldName;
|
||||
/**
|
||||
* 当前Service关联的主数据表中租户Id列名称。
|
||||
*/
|
||||
protected String tenantIdColumnName;
|
||||
/**
|
||||
* 当前Job服务源主表Model对象的最后更新时间字段名称。
|
||||
*/
|
||||
@@ -178,6 +190,12 @@ public abstract class BaseService<M, K> implements IBaseService<M, K> {
|
||||
setDeletedFlagMethod = ReflectUtil.getMethod(
|
||||
modelClass, "set" + StringUtils.capitalize(deletedFlagFieldName), Integer.class);
|
||||
}
|
||||
if (tenantIdFieldName == null && null != field.getAnnotation(TenantFilterColumn.class)) {
|
||||
tenantIdField = field;
|
||||
tenantIdFieldName = field.getName();
|
||||
Column c = field.getAnnotation(Column.class);
|
||||
tenantIdColumnName = c == null ? tenantIdFieldName : c.name();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -212,10 +230,12 @@ public abstract class BaseService<M, K> implements IBaseService<M, K> {
|
||||
return mapper().deleteByPrimaryKey(id) == 1;
|
||||
}
|
||||
try {
|
||||
Example e = new Example(modelClass);
|
||||
Example.Criteria c = e.createCriteria().andEqualTo(idFieldName, id);
|
||||
c.andEqualTo(deletedFlagFieldName, GlobalDeletedFlag.NORMAL);
|
||||
M data = modelClass.newInstance();
|
||||
setDeletedFlagMethod.invoke(data, GlobalDeletedFlag.DELETED);
|
||||
setIdFieldMethod.invoke(data, id);
|
||||
return mapper().updateByPrimaryKeySelective(data) == 1;
|
||||
return mapper().updateByExampleSelective(data, e) == 1;
|
||||
} catch (Exception ex) {
|
||||
log.error("Failed to call reflection method in BaseService.removeById.", ex);
|
||||
throw new MyRuntimeException(ex);
|
||||
@@ -607,6 +627,7 @@ public abstract class BaseService<M, K> implements IBaseService<M, K> {
|
||||
/**
|
||||
* 集成所有与主表实体对象相关的关联数据列表。包括本地和远程服务的一对一、字典、一对多和多对多聚合运算等。
|
||||
* 也可以根据实际需求,单独调用该函数所包含的各个数据集成函数。
|
||||
* NOTE: 该方法内执行的SQL将禁用数据权限过滤。
|
||||
*
|
||||
* @param resultList 主表实体对象列表。数据集成将直接作用于该对象列表。
|
||||
* @param relationParam 实体对象数据组装的参数构建器。
|
||||
@@ -617,47 +638,93 @@ public abstract class BaseService<M, K> implements IBaseService<M, K> {
|
||||
if (relationParam == null || CollectionUtils.isEmpty(resultList)) {
|
||||
return;
|
||||
}
|
||||
// 集成本地一对一和字段级别的数据关联。
|
||||
// NOTE: 这里必须要在集成远程一对一之前集成本地一对一。因为远程集成方法中,会为本地一对一从表数据进行远程集成。
|
||||
boolean buildOneToOne = relationParam.isBuildOneToOne() || relationParam.isBuildOneToOneWithDict();
|
||||
// 这里集成一对一关联。
|
||||
if (buildOneToOne) {
|
||||
this.buildOneToOneForDataList(resultList, relationParam.isBuildOneToOneWithDict());
|
||||
boolean dataFilterValue = GlobalThreadLocal.setDataFilter(false);
|
||||
try {
|
||||
// 集成本地一对一和字段级别的数据关联。
|
||||
// NOTE: 这里必须要在集成远程一对一之前集成本地一对一。因为远程集成方法中,会为本地一对一从表数据进行远程集成。
|
||||
boolean buildOneToOne = relationParam.isBuildOneToOne() || relationParam.isBuildOneToOneWithDict();
|
||||
// 这里集成一对一关联。
|
||||
if (buildOneToOne) {
|
||||
this.buildOneToOneForDataList(resultList, relationParam.isBuildOneToOneWithDict());
|
||||
}
|
||||
// 集成一对多关联
|
||||
if (relationParam.isBuildOneToMany()) {
|
||||
this.buildOneToManyForDataList(resultList);
|
||||
}
|
||||
// 这里集成字典关联
|
||||
if (relationParam.isBuildDict()) {
|
||||
// 构建常量字典关联关系
|
||||
this.buildConstDictForDataList(resultList);
|
||||
this.buildDictForDataList(resultList, buildOneToOne);
|
||||
}
|
||||
// 集成远程一对一和字段级别的数据关联。
|
||||
boolean buildRemoteOneToOne =
|
||||
relationParam.isBuildRemoteOneToOne() || relationParam.isBuildRemoteOneToOneWithDict();
|
||||
if (buildRemoteOneToOne) {
|
||||
this.buildRemoteOneToOneForDataList(resultList, relationParam.isBuildRemoteOneToOneWithDict());
|
||||
}
|
||||
if (relationParam.isBuildRemoteDict()) {
|
||||
this.buildRemoteDictForDataList(resultList, buildRemoteOneToOne);
|
||||
}
|
||||
// 组装本地聚合计算关联数据
|
||||
if (relationParam.isBuildAggregation()) {
|
||||
// 处理多一多场景下,根据主表的结果,进行从表聚合数据的计算。
|
||||
this.buildOneToManyAggregationForDataList(resultList, buildAggregationAdditionalWhereCriteria());
|
||||
// 处理多对多场景下,根据主表的结果,进行从表聚合数据的计算。
|
||||
this.buildManyToManyAggregationForDataList(resultList, buildAggregationAdditionalWhereCriteria());
|
||||
}
|
||||
// 组装远程聚合计算关联数据
|
||||
if (relationParam.isBuildRemoteAggregation()) {
|
||||
// 一对多场景。
|
||||
this.buildRemoteOneToManyAggregationForDataList(resultList, buildAggregationAdditionalWhereCriteria());
|
||||
// 处理多对多场景。
|
||||
this.buildRemoteManyToManyAggregationForDataList(resultList, buildAggregationAdditionalWhereCriteria());
|
||||
}
|
||||
} finally {
|
||||
GlobalThreadLocal.setDataFilter(dataFilterValue);
|
||||
}
|
||||
// 这里集成字典关联
|
||||
if (relationParam.isBuildDict()) {
|
||||
// 构建常量字典关联关系
|
||||
this.buildConstDictForDataList(resultList);
|
||||
this.buildDictForDataList(resultList, buildOneToOne);
|
||||
}
|
||||
|
||||
/**
|
||||
* 该函数主要用于对查询结果的批量导出。不同于支持分页的列表查询,批量导出没有分页机制,
|
||||
* 因此在导出数据量较大的情况下,很容易给数据库的内存、CPU和IO带来较大的压力。而通过
|
||||
* 我们的分批处理,可以极大的规避该问题的出现几率。调整batchSize的大小,也可以有效的
|
||||
* 改善运行效率。
|
||||
* 我们目前的处理机制是,先从主表取出所有符合条件的主表数据,这样可以避免分批处理时,
|
||||
* 后面几批数据,因为skip过多而带来的效率问题。因为是单表过滤,不会给数据库带来过大的压力。
|
||||
* 之后再在主表结果集数据上进行分批级联处理。
|
||||
* 集成所有与主表实体对象相关的关联数据列表。包括一对一、字典、一对多和多对多聚合运算等。
|
||||
* 也可以根据实际需求,单独调用该函数所包含的各个数据集成函数。
|
||||
* NOTE: 该方法内执行的SQL将禁用数据权限过滤。
|
||||
*
|
||||
* @param resultList 主表实体对象列表。数据集成将直接作用于该对象列表。
|
||||
* @param relationParam 实体对象数据组装的参数构建器。
|
||||
* @param batchSize 每批集成的记录数量。小于等于时将不做分批处理。
|
||||
*/
|
||||
@Override
|
||||
public void buildRelationForDataList(List<M> resultList, MyRelationParam relationParam, int batchSize) {
|
||||
if (CollectionUtils.isEmpty(resultList)) {
|
||||
return;
|
||||
}
|
||||
// 集成远程一对一和字段级别的数据关联。
|
||||
boolean buildRemoteOneToOne =
|
||||
relationParam.isBuildRemoteOneToOne() || relationParam.isBuildRemoteOneToOneWithDict();
|
||||
if (buildRemoteOneToOne) {
|
||||
this.buildRemoteOneToOneForDataList(resultList, relationParam.isBuildRemoteOneToOneWithDict());
|
||||
if (batchSize <= 0) {
|
||||
this.buildRelationForDataList(resultList, relationParam);
|
||||
return;
|
||||
}
|
||||
if (relationParam.isBuildRemoteDict()) {
|
||||
this.buildRemoteDictForDataList(resultList, buildRemoteOneToOne);
|
||||
}
|
||||
// 组装本地聚合计算关联数据
|
||||
if (relationParam.isBuildAggregation()) {
|
||||
// 处理多一多场景下,根据主表的结果,进行从表聚合数据的计算。
|
||||
this.buildOneToManyAggregationForDataList(resultList, buildAggregationAdditionalWhereCriteria());
|
||||
// 处理多对多场景下,根据主表的结果,进行从表聚合数据的计算。
|
||||
this.buildManyToManyAggregationForDataList(resultList, buildAggregationAdditionalWhereCriteria());
|
||||
}
|
||||
// 组装远程聚合计算关联数据
|
||||
if (relationParam.isBuildRemoteAggregation()) {
|
||||
// 一对多场景。
|
||||
this.buildRemoteOneToManyAggregationForDataList(resultList, buildAggregationAdditionalWhereCriteria());
|
||||
// 处理多对多场景。
|
||||
this.buildRemoteManyToManyAggregationForDataList(resultList, buildAggregationAdditionalWhereCriteria());
|
||||
int totalCount = resultList.size();
|
||||
int fromIndex = 0;
|
||||
int toIndex = Math.min(batchSize, totalCount);
|
||||
while (toIndex > fromIndex) {
|
||||
List<M> subResultList = resultList.subList(fromIndex, toIndex);
|
||||
this.buildRelationForDataList(subResultList, relationParam);
|
||||
fromIndex = toIndex;
|
||||
toIndex = Math.min(batchSize + fromIndex, totalCount);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 集成所有与主表实体对象相关的关联数据对象。包括本地和远程服务的一对一、字典、一对多和多对多聚合运算等。
|
||||
* 也可以根据实际需求,单独调用该函数所包含的各个数据集成函数。
|
||||
* NOTE: 该方法内执行的SQL将禁用数据权限过滤。
|
||||
*
|
||||
* @param dataObject 主表实体对象。数据集成将直接作用于该对象。
|
||||
* @param relationParam 实体对象数据组装的参数构建器。
|
||||
@@ -669,41 +736,50 @@ public abstract class BaseService<M, K> implements IBaseService<M, K> {
|
||||
if (dataObject == null || relationParam == null) {
|
||||
return;
|
||||
}
|
||||
// 集成本地一对一和字段级别的数据关联。
|
||||
boolean buildOneToOne = relationParam.isBuildOneToOne() || relationParam.isBuildOneToOneWithDict();
|
||||
if (buildOneToOne) {
|
||||
this.buildOneToOneForData(dataObject, relationParam.isBuildOneToOneWithDict());
|
||||
}
|
||||
if (relationParam.isBuildDict()) {
|
||||
// 构建常量字典关联关系
|
||||
this.buildConstDictForData(dataObject);
|
||||
// 构建本地数据字典关联关系。
|
||||
this.buildDictForData(dataObject, buildOneToOne);
|
||||
}
|
||||
boolean buildRemoteOneToOne =
|
||||
relationParam.isBuildRemoteOneToOne() || relationParam.isBuildRemoteOneToOneWithDict();
|
||||
if (buildRemoteOneToOne) {
|
||||
this.buildRemoteOneToOneForData(dataObject, relationParam.isBuildRemoteOneToOneWithDict());
|
||||
}
|
||||
if (relationParam.isBuildRemoteDict()) {
|
||||
this.buildRemoteDictForData(dataObject, buildRemoteOneToOne);
|
||||
}
|
||||
// 组装本地聚合计算关联数据
|
||||
if (relationParam.isBuildAggregation()) {
|
||||
// 构建一对多场景
|
||||
buildOneToManyAggregationForData(dataObject, buildAggregationAdditionalWhereCriteria());
|
||||
// 开始处理多对多场景。
|
||||
buildManyToManyAggregationForData(dataObject, buildAggregationAdditionalWhereCriteria());
|
||||
}
|
||||
// 组装远程聚合计算关联数据
|
||||
if (relationParam.isBuildRemoteAggregation()) {
|
||||
// 处理一对多场景
|
||||
this.buildRemoteOneToManyAggregationForData(dataObject, buildAggregationAdditionalWhereCriteria());
|
||||
// 处理多对多场景
|
||||
this.buildRemoteManyToManyAggregationForData(dataObject, buildAggregationAdditionalWhereCriteria());
|
||||
}
|
||||
if (relationParam.isBuildRelationManyToMany()) {
|
||||
this.buildRelationManyToMany(dataObject);
|
||||
boolean dataFilterValue = GlobalThreadLocal.setDataFilter(false);
|
||||
try {
|
||||
// 集成本地一对一和字段级别的数据关联。
|
||||
boolean buildOneToOne = relationParam.isBuildOneToOne() || relationParam.isBuildOneToOneWithDict();
|
||||
if (buildOneToOne) {
|
||||
this.buildOneToOneForData(dataObject, relationParam.isBuildOneToOneWithDict());
|
||||
}
|
||||
// 集成一对多关联
|
||||
if (relationParam.isBuildOneToMany()) {
|
||||
this.buildOneToManyForData(dataObject);
|
||||
}
|
||||
if (relationParam.isBuildDict()) {
|
||||
// 构建常量字典关联关系
|
||||
this.buildConstDictForData(dataObject);
|
||||
// 构建本地数据字典关联关系。
|
||||
this.buildDictForData(dataObject, buildOneToOne);
|
||||
}
|
||||
boolean buildRemoteOneToOne =
|
||||
relationParam.isBuildRemoteOneToOne() || relationParam.isBuildRemoteOneToOneWithDict();
|
||||
if (buildRemoteOneToOne) {
|
||||
this.buildRemoteOneToOneForData(dataObject, relationParam.isBuildRemoteOneToOneWithDict());
|
||||
}
|
||||
if (relationParam.isBuildRemoteDict()) {
|
||||
this.buildRemoteDictForData(dataObject, buildRemoteOneToOne);
|
||||
}
|
||||
// 组装本地聚合计算关联数据
|
||||
if (relationParam.isBuildAggregation()) {
|
||||
// 构建一对多场景
|
||||
buildOneToManyAggregationForData(dataObject, buildAggregationAdditionalWhereCriteria());
|
||||
// 开始处理多对多场景。
|
||||
buildManyToManyAggregationForData(dataObject, buildAggregationAdditionalWhereCriteria());
|
||||
}
|
||||
// 组装远程聚合计算关联数据
|
||||
if (relationParam.isBuildRemoteAggregation()) {
|
||||
// 处理一对多场景
|
||||
this.buildRemoteOneToManyAggregationForData(dataObject, buildAggregationAdditionalWhereCriteria());
|
||||
// 处理多对多场景
|
||||
this.buildRemoteManyToManyAggregationForData(dataObject, buildAggregationAdditionalWhereCriteria());
|
||||
}
|
||||
if (relationParam.isBuildRelationManyToMany()) {
|
||||
this.buildRelationManyToMany(dataObject);
|
||||
}
|
||||
} finally {
|
||||
GlobalThreadLocal.setDataFilter(dataFilterValue);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -794,6 +870,7 @@ public abstract class BaseService<M, K> implements IBaseService<M, K> {
|
||||
}
|
||||
boolean buildRemoteOneToOneDict = withDict && relationStruct.relationOneToOne.loadSlaveDict();
|
||||
MyQueryParam queryParam = new MyQueryParam(buildRemoteOneToOneDict);
|
||||
queryParam.setUseDataFilter(false);
|
||||
MyWhereCriteria whereCriteria = new MyWhereCriteria();
|
||||
whereCriteria.setCriteria(
|
||||
relationStruct.relationOneToOne.slaveIdField(), MyWhereCriteria.OPERATOR_IN, masterIdSet);
|
||||
@@ -826,6 +903,7 @@ public abstract class BaseService<M, K> implements IBaseService<M, K> {
|
||||
continue;
|
||||
}
|
||||
MyQueryParam queryParam = new MyQueryParam(withDict);
|
||||
queryParam.setUseDataFilter(false);
|
||||
MyWhereCriteria whereCriteria = new MyWhereCriteria();
|
||||
whereCriteria.setCriteria(
|
||||
relationStruct.relationOneToOne.slaveIdField(), MyWhereCriteria.OPERATOR_EQUAL, id);
|
||||
@@ -871,6 +949,7 @@ public abstract class BaseService<M, K> implements IBaseService<M, K> {
|
||||
continue;
|
||||
}
|
||||
MyQueryParam queryParam = new MyQueryParam(false);
|
||||
queryParam.setUseDataFilter(false);
|
||||
MyWhereCriteria whereCriteria = new MyWhereCriteria();
|
||||
whereCriteria.setCriteria(
|
||||
relationStruct.relationDict.slaveIdField(), MyWhereCriteria.OPERATOR_IN, masterIdSet);
|
||||
@@ -910,6 +989,7 @@ public abstract class BaseService<M, K> implements IBaseService<M, K> {
|
||||
continue;
|
||||
}
|
||||
MyQueryParam queryParam = new MyQueryParam(false);
|
||||
queryParam.setUseDataFilter(false);
|
||||
MyWhereCriteria whereCriteria = new MyWhereCriteria();
|
||||
whereCriteria.setCriteria(
|
||||
relationStruct.relationDict.slaveIdField(), MyWhereCriteria.OPERATOR_EQUAL, id);
|
||||
@@ -967,6 +1047,7 @@ public abstract class BaseService<M, K> implements IBaseService<M, K> {
|
||||
}
|
||||
criteriaList.add(criteria);
|
||||
aggregationParam.setWhereCriteriaList(criteriaList);
|
||||
aggregationParam.setUseDataFilter(false);
|
||||
ResponseResult<List<Map<String, Object>>> responseResult =
|
||||
relationStruct.remoteClient.aggregateBy(aggregationParam);
|
||||
if (responseResult.isSuccess()) {
|
||||
@@ -1009,6 +1090,7 @@ public abstract class BaseService<M, K> implements IBaseService<M, K> {
|
||||
relation.slaveIdField(), MyWhereCriteria.OPERATOR_EQUAL, masterIdValue);
|
||||
criteriaList.add(criteria);
|
||||
aggregationParam.setWhereCriteriaList(criteriaList);
|
||||
aggregationParam.setUseDataFilter(false);
|
||||
ResponseResult<List<Map<String, Object>>> result =
|
||||
relationStruct.remoteClient.aggregateBy(aggregationParam);
|
||||
if (result.isSuccess()) {
|
||||
@@ -1925,6 +2007,8 @@ public abstract class BaseService<M, K> implements IBaseService<M, K> {
|
||||
List<String> slaveSelectList = new LinkedList<>();
|
||||
slaveSelectList.add(relation.slaveIdField());
|
||||
queryParam.setSelectFieldList(slaveSelectList);
|
||||
// 关联集成数据需要把数据权限过滤关闭,以保证计算结果的正确性。
|
||||
queryParam.setUseDataFilter(false);
|
||||
ResponseResult<MyPageData<Map<String, Object>>> result = relationStruct.remoteClient.listMapBy(queryParam);
|
||||
if (!result.isSuccess()) {
|
||||
this.logErrorOrThrowException(result.getErrorMessage());
|
||||
@@ -1989,6 +2073,7 @@ public abstract class BaseService<M, K> implements IBaseService<M, K> {
|
||||
groupingBy(m -> m.get(relationInfo.relationMasterColumn),
|
||||
mapping(n -> n.get(relationInfo.relationSlaveColumn), toSet())));
|
||||
aggregationParam.setGroupedInFilterValues(groupedFilterMap);
|
||||
aggregationParam.setUseDataFilter(false);
|
||||
// 开始将远程返回的聚合计算结果集合,回填到主表中的聚合虚拟字段。
|
||||
ResponseResult<List<Map<String, Object>>> result =
|
||||
relationStruct.remoteClient.aggregateBy(aggregationParam);
|
||||
|
||||
@@ -11,17 +11,6 @@ import java.util.List;
|
||||
* @date 2020-08-08
|
||||
*/
|
||||
public interface IBaseDictService<M, K> extends IBaseService<M, K> {
|
||||
/**
|
||||
* 是否在服务启动的时候加载。子类可以重载该方法,并在需要的时候手工调用loadCachedData加载数据。
|
||||
*
|
||||
* @return true表示启动即可加载数据,false需要手动调用loadCachedData进行加载。
|
||||
*/
|
||||
boolean loadOnStartup();
|
||||
|
||||
/**
|
||||
* 在系统启动时,加载全部数据到内存,缓存的key只能为映射表的主键。
|
||||
*/
|
||||
void loadCachedData();
|
||||
|
||||
/**
|
||||
* 重新加载数据库中所有当前表数据到系统内存。
|
||||
@@ -76,6 +65,13 @@ public interface IBaseDictService<M, K> extends IBaseService<M, K> {
|
||||
*/
|
||||
void removeDictionaryCache(K id);
|
||||
|
||||
/**
|
||||
* 根据字典对象将数据从缓存中删除。
|
||||
*
|
||||
* @param data 字典数据。
|
||||
*/
|
||||
void removeDictionaryCacheByModel(M data);
|
||||
|
||||
/**
|
||||
* 获取缓存中的数据数量。
|
||||
*
|
||||
|
||||
@@ -207,6 +207,24 @@ public interface IBaseService<M, K> {
|
||||
*/
|
||||
void buildRelationForDataList(List<M> resultList, MyRelationParam relationParam);
|
||||
|
||||
/**
|
||||
* 该函数主要用于对查询结果的批量导出。不同于支持分页的列表查询,批量导出没有分页机制,
|
||||
* 因此在导出数据量较大的情况下,很容易给数据库的内存、CPU和IO带来较大的压力。而通过
|
||||
* 我们的分批处理,可以极大的规避该问题的出现几率。调整batchSize的大小,也可以有效的
|
||||
* 改善运行效率。
|
||||
* 我们目前的处理机制是,先从主表取出所有符合条件的主表数据,这样可以避免分批处理时,
|
||||
* 后面几批数据,因为skip过多而带来的效率问题。因为是单表过滤,不会给数据库带来过大的压力。
|
||||
* 之后再在主表结果集数据上进行分批级联处理。
|
||||
* 集成所有与主表实体对象相关的关联数据列表。包括一对一、字典、一对多和多对多聚合运算等。
|
||||
* 也可以根据实际需求,单独调用该函数所包含的各个数据集成函数。
|
||||
* NOTE: 该方法内执行的SQL将禁用数据权限过滤。
|
||||
*
|
||||
* @param resultList 主表实体对象列表。数据集成将直接作用于该对象列表。
|
||||
* @param relationParam 实体对象数据组装的参数构建器。
|
||||
* @param batchSize 每批集成的记录数量。小于等于时将不做分批处理。
|
||||
*/
|
||||
void buildRelationForDataList(List<M> resultList, MyRelationParam relationParam, int batchSize);
|
||||
|
||||
/**
|
||||
* 集成所有与主表实体对象相关的关联数据对象。包括一对一、字典、一对多和多对多聚合运算等。
|
||||
* 也可以根据实际需求,单独调用该函数所包含的各个数据集成函数。
|
||||
|
||||
@@ -60,6 +60,45 @@ public class MapTreeDictionaryCache<K, V> extends MapDictionaryCache<K, V> {
|
||||
this.parentIdGetter = parentIdGetter;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 重新加载,先清空原有数据,在执行putAll的操作。
|
||||
*
|
||||
* @param dataList 待缓存的数据列表。
|
||||
* @param force true则强制刷新,如果false,当缓存中存在数据时不刷新。
|
||||
*/
|
||||
@Override
|
||||
public void reload(List<V> dataList, boolean force) {
|
||||
if (!force && this.getCount() > 0) {
|
||||
return;
|
||||
}
|
||||
String exceptionMessage;
|
||||
try {
|
||||
if (lock.readLock().tryLock(TIMEOUT, TimeUnit.MILLISECONDS)) {
|
||||
try {
|
||||
dataMap.clear();
|
||||
allTreeMap.clear();
|
||||
dataList.forEach(data -> {
|
||||
K id = idGetter.apply(data);
|
||||
dataMap.put(id, data);
|
||||
K parentId = parentIdGetter.apply(data);
|
||||
allTreeMap.put(parentId, data);
|
||||
});
|
||||
} finally {
|
||||
lock.readLock().unlock();
|
||||
}
|
||||
} else {
|
||||
throw new TimeoutException();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
exceptionMessage = String.format(
|
||||
"LOCK Operation of [MapDictionaryCache::getInList] encountered EXCEPTION [%s] for DICT.",
|
||||
e.getClass().getSimpleName());
|
||||
log.warn(exceptionMessage);
|
||||
throw new MapCacheAccessException(exceptionMessage, e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取该父主键的子数据列表。
|
||||
*
|
||||
@@ -103,8 +142,9 @@ public class MapTreeDictionaryCache<K, V> extends MapDictionaryCache<K, V> {
|
||||
try {
|
||||
if (lock.readLock().tryLock(TIMEOUT, TimeUnit.MILLISECONDS)) {
|
||||
try {
|
||||
super.putAll(dataList);
|
||||
dataList.forEach(data -> {
|
||||
K id = idGetter.apply(data);
|
||||
dataMap.put(id, data);
|
||||
K parentId = parentIdGetter.apply(data);
|
||||
allTreeMap.remove(parentId, data);
|
||||
allTreeMap.put(parentId, data);
|
||||
@@ -136,7 +176,7 @@ public class MapTreeDictionaryCache<K, V> extends MapDictionaryCache<K, V> {
|
||||
try {
|
||||
if (lock.readLock().tryLock(TIMEOUT, TimeUnit.MILLISECONDS)) {
|
||||
try {
|
||||
super.put(id, data);
|
||||
dataMap.put(id, data);
|
||||
K parentId = parentIdGetter.apply(data);
|
||||
allTreeMap.remove(parentId, data);
|
||||
allTreeMap.put(parentId, data);
|
||||
@@ -168,7 +208,7 @@ public class MapTreeDictionaryCache<K, V> extends MapDictionaryCache<K, V> {
|
||||
try {
|
||||
if (lock.readLock().tryLock(TIMEOUT, TimeUnit.MILLISECONDS)) {
|
||||
try {
|
||||
v = super.invalidate(id);
|
||||
v = dataMap.remove(id);
|
||||
if (v != null) {
|
||||
K parentId = parentIdGetter.apply(v);
|
||||
allTreeMap.remove(parentId, v);
|
||||
@@ -233,7 +273,7 @@ public class MapTreeDictionaryCache<K, V> extends MapDictionaryCache<K, V> {
|
||||
try {
|
||||
if (lock.readLock().tryLock(TIMEOUT, TimeUnit.MILLISECONDS)) {
|
||||
try {
|
||||
super.invalidateAll();
|
||||
dataMap.clear();
|
||||
allTreeMap.clear();
|
||||
} finally {
|
||||
lock.readLock().unlock();
|
||||
|
||||
@@ -12,6 +12,10 @@ public final class ApplicationConstant {
|
||||
* 为字典表数据缓存时,缓存名称的固定后缀。
|
||||
*/
|
||||
public static final String DICT_CACHE_NAME_SUFFIX = "-DICT";
|
||||
/**
|
||||
* 为树形字典表数据缓存时,缓存名称的固定后缀。
|
||||
*/
|
||||
public static final String TREE_DICT_CACHE_NAME_SUFFIX = "-TREE-DICT";
|
||||
/**
|
||||
* 图片文件上传的父目录。
|
||||
*/
|
||||
@@ -44,6 +48,12 @@ public final class ApplicationConstant {
|
||||
* 请求头跟踪id名。
|
||||
*/
|
||||
public static final String HTTP_HEADER_TRACE_ID = "traceId";
|
||||
/**
|
||||
* 操作日志的数据源类型。仅当前服务为多数据源时使用。
|
||||
* 在common-log模块中,SysOperationLogServiceImpl的MyDataSource注解一定要使用该参数。
|
||||
* 在多数据源的业务服务中,DataSourceType的常量一定要包含该值,多数据源的配置中,也一定要有与该值匹配的数据源Bean。
|
||||
*/
|
||||
public static final int OPERATION_LOG_DATASOURCE_TYPE = 1000;
|
||||
/**
|
||||
* 重要说明:该值为项目生成后的缺省密钥,仅为使用户可以快速上手并跑通流程。
|
||||
* 在实际的应用中,一定要为不同的项目或服务,自行生成公钥和私钥,并将 PRIVATE_KEY 的引用改为服务的配置项。
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
package com.orange.demo.common.core.listener;
|
||||
|
||||
import com.orange.demo.common.core.base.service.BaseDictService;
|
||||
import org.springframework.boot.context.event.ApplicationReadyEvent;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 应用程序启动后的事件监听对象。主要负责加载Model之间的字典关联和一对一关联所对应的Service结构关系。
|
||||
*
|
||||
* @author Jerry
|
||||
* @date 2020-08-08
|
||||
*/
|
||||
@Component
|
||||
public class LoadCachedDataListener implements ApplicationListener<ApplicationReadyEvent> {
|
||||
|
||||
@SuppressWarnings("all")
|
||||
@Override
|
||||
public void onApplicationEvent(ApplicationReadyEvent applicationReadyEvent) {
|
||||
Map<String, BaseDictService> serviceMap =
|
||||
applicationReadyEvent.getApplicationContext().getBeansOfType(BaseDictService.class);
|
||||
for (Map.Entry<String, BaseDictService> e : serviceMap.entrySet()) {
|
||||
e.getValue().loadCachedData();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -27,6 +27,12 @@ public class MyAggregationParam {
|
||||
*/
|
||||
public static final String VALUE_NAME = "aggregatedValue";
|
||||
|
||||
/**
|
||||
* 聚合计算是否使用数据权限进行过滤。true表示数据过滤将产生作用,否则SQL中不会包含数据过滤。
|
||||
* 目前数据过滤包括数据权限过滤和租户数据过滤。
|
||||
*/
|
||||
private Boolean useDataFilter = true;
|
||||
|
||||
/**
|
||||
* 聚合分类,具体数值见AggregationKind。
|
||||
*/
|
||||
|
||||
@@ -23,6 +23,13 @@ public class MyQueryParam {
|
||||
* 用于数据过滤的DTO对象。
|
||||
*/
|
||||
private Map<String, Object> filterMap;
|
||||
|
||||
/**
|
||||
* 聚合计算是否使用数据权限进行过滤。true表示数据过滤将产生作用,否则SQL中不会包含数据过滤。
|
||||
* 目前数据过滤包括数据权限过滤和租户数据过滤。
|
||||
*/
|
||||
private Boolean useDataFilter = true;
|
||||
|
||||
/**
|
||||
* (In-list) 实体对象中的过滤字段(而非数据表列名),需和下面的inFilterValues字段一起使用。
|
||||
* NOTE: MyWhereCriteria中的IN类型过滤条件,完全可以替代该字段。之所以保留主要是为了保证更好的接口可读性。
|
||||
|
||||
@@ -70,7 +70,7 @@ public class LocalUpDownloader extends BaseUpDownloader {
|
||||
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file))) {
|
||||
int i = bis.read(buff);
|
||||
while (i != -1) {
|
||||
os.write(buff, 0, buff.length);
|
||||
os.write(buff, 0, i);
|
||||
os.flush();
|
||||
i = bis.read(buff);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.orange.demo.common.core.util;
|
||||
|
||||
/**
|
||||
* 基于自定义解析规则的多数据源解析接口。
|
||||
*
|
||||
* @author Jerry
|
||||
* @date 2020-08-08
|
||||
*/
|
||||
public interface DataSourceResolver {
|
||||
|
||||
/**
|
||||
* 动态解析方法。实现类可以根据当前的请求,或者上下文环境进行动态解析。
|
||||
*
|
||||
* @param arg 可选的入参。MyDataSourceResolver注解中的arg参数。
|
||||
* @return 返回用于多数据源切换的类型值。DataSourceResolveAspect 切面方法会根据该返回值和配置信息,进行多数据源切换。
|
||||
*/
|
||||
int resolve(String arg);
|
||||
}
|
||||
Reference in New Issue
Block a user