Commit e90a37fe by hulei

汇款多实体适配

parent f6bf1d74
package com.brilliance.isc.support;
package com.brilliance.mda.support.mybatis.interceptor;
import cn.hutool.core.util.StrUtil;
import com.brilliance.isc.bo.Etg;
import com.brilliance.isc.bo.Ety;
import com.brilliance.isc.common.context.SettleContext;
import com.brilliance.isc.common.context.SettleSession;
import com.github.pagehelper.util.ExecutorUtil;
import com.github.pagehelper.util.MetaObjectUtil;
import org.apache.ibatis.builder.annotation.ProviderSqlSource;
......@@ -38,12 +33,17 @@ import java.util.Map;
@Signature(type = Executor.class, method = "query", args = {MappedStatement.class, Object.class, RowBounds.class, ResultHandler.class}),
@Signature(type = Executor.class, method = "query", args = {MappedStatement.class, Object.class, RowBounds.class, ResultHandler.class, CacheKey.class, BoundSql.class}),
})
public class CustomInterceptor implements Interceptor {
private static final Logger logger = LoggerFactory.getLogger(CustomInterceptor.class);
public class CustomParameterInterceptor implements Interceptor {
private static final Logger logger = LoggerFactory.getLogger(CustomParameterInterceptor.class);
private ParameterProcessor parameterProcessor;
public CustomParameterInterceptor(ParameterProcessor parameterProcessor){
this.parameterProcessor = parameterProcessor;
}
@Override
public Object intercept(Invocation invocation) throws Throwable {
if(!checkSession()){
if(!parameterProcessor.checkParameter()){
return invocation.proceed();
}
......@@ -111,48 +111,6 @@ public class CustomInterceptor implements Interceptor {
}
}
}
return processEtyEtgParameter(ms, paramMap, boundSql, pageKey);
}
// public void processAnnotation(MappedStatement ms){
// int lastDotIdx = ms.getId().lastIndexOf(".");
// String mapperName = ms.getId().substring(0,lastDotIdx);
// String methodName = ms.getId().substring(lastDotIdx+1);
// }
public static final String _ETY_PARAMETER_KEY = "_etyextkey";
public static final String _ETG_PARAMETER_KEY = "_etgextkey";
public Object processEtyEtgParameter(MappedStatement ms, Map<String, Object> paramMap, BoundSql boundSql, CacheKey pageKey) {
SettleSession session = SettleContext.getUserSession();
Ety ety = session.getEty();
Etg etg = session.getEtg();
paramMap.put(_ETY_PARAMETER_KEY, ety.getExtkey());
paramMap.put(_ETG_PARAMETER_KEY, etg.getExtkey());
//处理pageKey
pageKey.update(ety);
pageKey.update(etg);
return paramMap;
}
/**
* 检查SettleSession中是否有对应的ETY,ETG信息
* @return
*/
public boolean checkSession(){
SettleSession session = SettleContext.getUserSession();
if(session == null){
return false;
}
if(session.getEty() == null && session.getEtg() == null){
return false ;
}
if(StrUtil.isEmpty(session.getEty().getExtkey()) && StrUtil.isEmpty(session.getEtg().getExtkey())){
return false;
}
return true;
return parameterProcessor.processCustomizedParameter(ms, paramMap, boundSql, pageKey);
}
}
package com.brilliance.mda.support.mybatis.interceptor;
import org.apache.ibatis.cache.CacheKey;
import org.apache.ibatis.mapping.BoundSql;
import org.apache.ibatis.mapping.MappedStatement;
import java.util.Map;
public interface ParameterProcessor {
/**
* 已拦截到Mybatis的ParamMpa并转化为Map类型,如需要添加额外的参数,可
* @param ms
* @param paramMap
* @param boundSql
* @param pageKey
* @return
*/
Object processCustomizedParameter(MappedStatement ms, Map<String, Object> paramMap, BoundSql boundSql, CacheKey pageKey) ;
/**
* 提前检查是否需要拦截并对SQL 参数进行处理。
* @return
*/
default boolean checkParameter(){
return true;
}
}
package com.brilliance.isc.support;
import cn.hutool.core.util.StrUtil;
import com.brilliance.isc.bo.Etg;
import com.brilliance.isc.bo.Ety;
import com.brilliance.isc.common.context.SettleContext;
import com.brilliance.isc.common.context.SettleSession;
import com.brilliance.mda.support.mybatis.interceptor.CustomParameterInterceptor;
import com.brilliance.mda.support.mybatis.interceptor.ParameterProcessor;
import org.apache.ibatis.cache.CacheKey;
import org.apache.ibatis.mapping.BoundSql;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.plugin.Interceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.Map;
@Configuration
public class MyBatisConfig {
@Bean
public Interceptor customInterceptor() {
return new CustomInterceptor();
return new CustomParameterInterceptor(new ParameterProcessor() {
public static final String _ETY_PARAMETER_KEY = "_etyextkey";
public static final String _ETG_PARAMETER_KEY = "_etgextkey";
@Override
public Object processCustomizedParameter(MappedStatement ms, Map<String, Object> paramMap, BoundSql boundSql, CacheKey pageKey) {
SettleSession session = SettleContext.getUserSession();
Ety ety = session.getEty();
Etg etg = session.getEtg();
paramMap.put(_ETY_PARAMETER_KEY, ety.getExtkey());
paramMap.put(_ETG_PARAMETER_KEY, etg.getExtkey());
//处理pageKey
pageKey.update(ety);
pageKey.update(etg);
return paramMap;
}
/**
* 检查SettleSession中是否有对应的ETY,ETG信息
* @return
*/
@Override
public boolean checkParameter() {
SettleSession session = SettleContext.getUserSession();
if(session == null){
return false;
}
if(session.getEty() == null && session.getEtg() == null){
return false ;
}
if(StrUtil.isEmpty(session.getEty().getExtkey()) && StrUtil.isEmpty(session.getEtg().getExtkey())){
return false;
}
return true;
}
});
}
}
......@@ -10,5 +10,14 @@ public interface AccountCustomizedApi {
*/
boolean checkAccount(String account, Argument<String> errMsg);
/**
* 校验账号比重
* @param cur
* @param errMsg
* @return
*/
boolean checkCur(String cur,Argument<String> errMsg);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment