@@ -39,7 +39,7 @@ import redis.clients.jedis.exceptions.JedisConnectionException;
@Service ( )
public class ConfigJedisServiceimpl implements ConfigRedisService {
private static Logger logger = LoggerFactory . getLogger ( ConfigJedisServiceimpl . class ) ;
// Constants.COMMONGROUPDBARR
// 用于在实时统计配置后面添加时间,方便读取入库时间
private static final SimpleDateFormat sdf = new SimpleDateFormat ( " yyyyMMddHHmmss " ) ;
@@ -435,11 +435,10 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
}
}
return groupAndRegionMap ;
}
@Override
public boolean saveMaatConfig ( Map < Integer , List < MaatConfig > > configMap ) {
public boolean saveMaatConfig ( Map < Integer , List < MaatConfig > > configMap , List < Long > commonGroupIdList ) {
if ( configMap ! = null & & configMap . size ( ) > 0 ) {
int count = 0 ;
Jedis resource = JedisUtils . getResource ( 0 ) ;
@@ -470,7 +469,7 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
MaatXmlConfig maatXmlConfig = ReadMaatXmlUtil . getMaatConfigByService ( service ) ;
setConfig ( maatConfig , maatXmlConfig , maatVersion , service , transaction ,
redisDBIndex ) ;
redisDBIndex , commonGroupIdList );
}
transaction . incrBy ( " MAAT_VERSION " , 1l ) ;
@@ -527,31 +526,25 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
* @param redisDBIndex
*/
public void setConfig ( MaatConfig maatConfig , MaatXmlConfig maatXmlConfig , Double maatVersion , int service ,
Transaction transaction , Integer redisDBIndex ) {
Transaction transaction , Integer redisDBIndex , List < Long > commonGroupIdList ) {
Map < String , String > compileMap = maatConfig . getCompileMap ( ) ;
String compileId = compileMap . get ( " compile_id " ) ;
if ( compileMap ! = null & & compileMap . size ( ) > 0 ) {
setCommonConfig ( maatXmlConfig , compileMap , 10 , maatVersion , service , transaction , redisDBIndex , null ,
false ) ; // 10代表是编译配置
setCommonConfig ( maatXmlConfig , compileMap , 10 , maatVersion , service , transaction , redisDBIndex , null ) ; // 10代表是编译配置
} else {
throw new ServiceRuntimeException (
" 无法从参数中获取 " + redisDBIndex + " 号redis库,业务类型为: " + service + " 的编译配置信息,请检查配置参数是否正确 " ,
RestBusinessCode . NotFoundCompileInfo . getValue ( ) ) ;
}
boolean isReuse = false ;
/**
* 保存域配置信息
*/
int count = addRegion ( maatConfig , maatXmlConfig , maatVersion , service , transaction , redisDBIndex , false ) ;
if ( count = = 0 & & ServiceAndRDBIndexReal . serviceIsReuse ( service ) ) {
isReuse = true ; // 如果没有域配置那么就是分组复用的配置,只有分组复用的配置才可以没有域配置
}
addRegion ( maatConfig , maatXmlConfig , maatVersion , service , transaction , redisDBIndex , commonGroupIdList ) ;
List < Map < String , String > > groupMapList = maatConfig . getGroupMapList ( ) ;
if ( groupMapList ! = null & & groupMapList . size ( ) > 0 ) {
for ( Map < String , String > map : groupMapList ) {
setCommonConfig ( maatXmlConfig , map , 11 , maatVersion , service , transaction , redisDBIndex , compileId ,
isReuse ) ; // 11代表是分组配置
setCommonConfig ( maatXmlConfig , map , 11 , maatVersion , service , transaction , redisDBIndex , compileId ) ; // 11代表是分组配置
}
} else {
throw new ServiceRuntimeException (
@@ -574,7 +567,7 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
* @param isReuse 是否是分组复用
*/
private void setCommonConfig ( MaatXmlConfig maatXmlConfig , Map < String , String > map , int type , Double maatVersion ,
int service , Transaction transaction , Integer redisDBIndex , String compileId , boolean isReuse ) {
int service , Transaction transaction , Integer redisDBIndex , String compileId ) {
if ( maatXmlConfig ! = null & & map ! = null & & map . size ( ) > 0 ) {
List < MaatXmlExpr > expressionList = maatXmlConfig . getExpressionList ( ) ;
String maatKey = null ;
@@ -675,41 +668,6 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
transaction . set ( maatKey . toUpperCase ( ) , valBF . toString ( ) ) ;
logger . info ( " 向{}号redis数据库添加了一条配置,key是{},value是{} " , redisDBIndex , maatKey . toUpperCase ( ) ,
valBF . toString ( ) ) ;
if ( isReuse & & type = = 11 ) {
int tmpStorageReuseRegionDB = Configurations . getIntProperty ( " tmpStorageReuseRegionDB " , 15 ) ;
int idRelaRedisDBIndex = Configurations . getIntProperty ( " idRelaRedisDBIndex " , 15 ) ;
String groupIdStr = " GROUPREGION: " + groupId ;
String groupCompileVal = JedisUtils . get ( groupIdStr , idRelaRedisDBIndex ) ;
if ( groupCompileVal ! = null & & ! groupCompileVal . trim ( ) . equals ( " " ) ) {
Set < String > regionKeySet = new HashSet < String > ( ) ; // 获取当前组下所有的域,并将该域往当前组所在的redisdb复制一份
String [ ] split = org . apache . commons . lang . StringUtils . split ( groupCompileVal , " ; " ) ;
if ( split ! = null & & split . length > 0 ) {
for ( String compileStr : split ) {
if ( compileStr ! = null & & ! compileStr . trim ( ) . equals ( " " ) ) {
regionKeySet . add ( compileStr . split ( " - " ) [ 0 ] . trim ( ) ) ;
}
}
}
transaction . select ( redisDBIndex ) ;
for ( String regionKey : regionKeySet ) {
if ( ! JedisUtils . exists ( regionKey , redisDBIndex ) ) { // 先判断是否存在,如果存在就不复制了,不存在就复制
String regionVal = JedisUtils . get ( regionKey , tmpStorageReuseRegionDB ) ;
if ( regionVal ! = null & & ! regionVal . trim ( ) . equals ( " " ) ) {
transaction . set ( regionKey . toUpperCase ( ) , regionVal ) ;
logger . info ( " 向{}号redis数据库复制了一条域配置,key是{},value是{} " , redisDBIndex ,
regionKey . toUpperCase ( ) , regionVal . toString ( ) ) ;
}
}
}
}
} else if ( isReuse & & ( type = = 12 | | type = = 13 | | type = = 14 | | type = = 15 | | type = = 18 ) ) { // 将数据往临时库复制一份,无论临时库里有没有都可以直接写,有则覆盖,不影响
int tmpStorageReuseRegionDB = Configurations . getIntProperty ( " tmpStorageReuseRegionDB " , 15 ) ;
transaction . select ( tmpStorageReuseRegionDB ) ;
transaction . set ( maatKey . toUpperCase ( ) , valBF . toString ( ) ) ;
logger . info ( " 向临时存放region的{}号redis数据库添加了一条配置,key是{},value是{} " , tmpStorageReuseRegionDB ,
maatKey . toUpperCase ( ) , valBF . toString ( ) ) ;
}
break ;
}
@@ -896,7 +854,7 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
}
/**
* 根据配置id从关联关系db中获取各个配置实际所在的db
* 根据配置id从关联关系db中获取各个配置实际所在的db,key是redisdb,value是配置id
*
* @param idList
* @param service
@@ -1011,11 +969,12 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
list . add ( i ) ;
}
serviceConfigMap . put ( 129 , list ) ;
delMaatConfig ( serviceConfigMap , false ) ;
delMaatConfig ( serviceConfigMap , false , null );
}
@Override
public boolean delMaatConfig ( Map < Integer , List < Long > > serviceConfigMap , boolean isStart ) {
public boolean delMaatConfig ( Map < Integer , List < Long > > serviceConfigMap , boolean isStart ,
Map < Long , List < Long > > compileGroupMap ) {
if ( serviceConfigMap ! = null & & serviceConfigMap . size ( ) > 0 ) {
Jedis resource = JedisUtils . getResource ( 0 ) ;
Transaction transaction = resource . multi ( ) ;
@@ -1035,8 +994,14 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
for ( Long id : list ) {
// 按序号选择Redis数据库
transaction . select ( redisDb ) ;
removeConfig ( id , maatXmlConfig , maatVersion , service , transaction , redisDb ,
idRelaRedisDBIndex , isStart ) ;
if ( ! isStart & & compileGroupMap . size ( ) > 0 ) {
removeConfig ( id , maatXmlConfig , maatVersion , service , transaction , redisDb ,
idRelaRedisDBIndex , isStart , compileGroupMap . get ( id ) ) ;
} else {
removeConfig ( id , maatXmlConfig , maatVersion , service , transaction , redisDb ,
idRelaRedisDBIndex , isStart , null ) ;
}
}
} else {
throw new ServiceRuntimeException ( " 删除配置时,未发现对应的配置id信息,请检查配置参数是否正确 " ,
@@ -1056,7 +1021,7 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
throw new ServiceRuntimeException ( " 删除maat类配置时,未发现对应的配置信息,请检查配置参数是否正确 " ,
RestBusinessCode . ConfigSourceIsNull . getValue ( ) ) ;
}
if ( removeMaatRelation ( serviceConfigMap , transaction , isStart )
if ( removeMaatRelation ( serviceConfigMap , transaction , isStart , compileGroupMap )
& & removeStatisticsReal ( serviceConfigMap , transaction , isStart ) ) {
transaction . exec ( ) ;
return true ;
@@ -1090,8 +1055,6 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
return false ;
}
/**
* 获取关联关系中每个关系中的-前部分
*
@@ -1115,10 +1078,12 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
* @param service 业务类型
* @param redisTemplate
* @param maatRelation id对应关系对象
* @param isStart 是否将配置置为生效
* @param isStart 是否将配置置为生效
* @param keepGroupId 将配置置为失效时需要保留的组
*/
private void removeConfig ( Long id , MaatXmlConfig maatXmlConfig , Double maatVersion , int service ,
Transaction transaction , int redisDBIndex , int idRelaRedisDBIndex , boolean isStart ) {
Transaction transaction , int redisDBIndex , int idRelaRedisDBIndex , boolean isStart ,
List < Long > keepGroupId ) {
if ( maatXmlConfig ! = null ) {
Map < String , String > keyMap = new HashMap < > ( ) ;
// 删除(重命名)编译配置
@@ -1127,16 +1092,18 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
// 拼接编译与分组关系的Redis Key
String compileStr = " COMPILEGROUP: " + id ;
// 获取当前编译配置与分组配置的关联关系
String compileStrVal = JedisUtils . get ( compileStr , idRelaRedisDBIndex ) ; // 根据编译id获取该编译下的分组关系
String compileStrVal = JedisUtils . get ( compileStr , idRelaRedisDBIndex ) ; // 根据编译id获取该编译下的分组关系,示例:
// GROUPCOMPILE:25166-2,5;GROUPCOMPILE:25167-2,5;GROUPCOMPILE:25168-2,5
if ( compileStrVal ! = null & & ! compileStrVal . trim ( ) . equals ( " " ) ) {
String [ ] compileGroupStrArr = org . apache . commons . lang . StringUtils . split ( compileStrVal , " ; " ) ;
for ( String compileGroup : compileGroupStrArr ) {
// compileGroup=GROUPCOMPILE:25166-2, 5
if ( compileGroup ! = null & & ! compileGroup . trim ( ) . equals ( " " ) ) {
String groupCompileStrs = getRegionInfo ( compileGroup ) ; // 获取编译对应的分组信息,去除后面的redisdb信息
String groupCompileStrs = getRegionInfo ( compileGroup ) ; // 获取编译对应的分组信息,去除后面的redisdb信息,GROUPCOMPILE:25166
if ( groupCompileStrs ! = null & & ! groupCompileStrs . trim ( ) . equals ( " " ) ) { // 遍历编译和分组的信息
String [ ] split = org . apache . commons . lang . StringUtils . split ( groupCompileStrs , " ; " ) ;
for ( String groupId : split ) { // GROUPCOMPILE:groupid-redisdb
for ( String groupId : split ) { // GROUPCOMPILE:groupid
if ( groupId ! = null & & ! groupId . trim ( ) . equals ( " " ) ) {
String groupCompileAndDBStrs = null ;
if ( ! keyMap . containsKey ( groupId ) ) {
@@ -1146,50 +1113,56 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
groupCompileAndDBStrs = keyMap . get ( groupId ) ;
}
String [ ] compileGroupArr = org . ap ach e. commons . lang . StringUtils
. split ( groupCompileAndDBStrs , " ; " ) ; // 获取组对应的编译id
String groupIdReal = groupId . repl ace( " GROUPCOMPILE: " , " " ) ;
String [ ] compileGroupArr = org . apache . commons . lang . StringUtils
. split ( groupCompileAndDBStrs , " ; " ) ; // 获取组对应的编译id,示例:
// ;COMPILEGROUP:24070-2, 5
for ( String groupAndCompileStr : compileGroupArr ) {
if ( groupAndCompileStr ! = null & & ! groupAndCompileStr . trim ( ) . equals ( " " ) ) {
String compileId = getRegionInfo ( groupAndCompileStr ) ;
String compileId = getRegionInfo ( groupAndCompileStr ) ; // COMPILEGROUP:24070
if ( compileId ! = null & & ! compileId . trim ( ) . equals ( " " ) ) {
// 被分组复用的业务,不能将域置为失效
if ( ! ServiceAndRDBIndexReal . serviceIsReuse ( service ) ) { // 如果当前业务不允许被分组复用(普通的maat类配置),则可以 将域置为失效,否则不 将域置为失效
// 如果只有一个编译id且与上面的编译id相同则说明未被分组复用,可以将其下的所有 域置失效,否则不处理域配置,只把编译,分组关系 置为无 效
if ( compileId . equals ( compileStr ) ) { //
String groupRegionKey = groupId . replace ( " GROUPCOMPILE " ,
" GROUPREGION " ) ; // groupr egion里面value是region的信息,key是group的信息,所以可以直接将GROUPCOMPILE替换为GROUPREGION
String regionStrs = null ;
if ( ! keyMap . containsKey ( groupRegionKey ) ) {
regionStrs = JedisUtils . get ( groupRegionKey ,
idRelaRedisDBIndex ) ;
keyMap . put ( groupRegionKey , regionStrs ) ;
} else {
regionStrs = keyMap . get ( groupRegionKey ) ;
}
if ( regionStrs ! = null & & ! regionStrs . trim ( ) . equals ( " " ) ) {
String [ ] regionStrArr = regionStrs . split ( " ; " ) ;
for ( String st r : regionStrArr ) {
i f ( s tr ! = null & & ! str . trim ( ) . equals ( " " ) ) {
if ( keepGroupId ! = null & & keepGroupId . size ( ) > 0
& & keepGroupId . contains ( Long . parseLong ( groupIdReal ) ) ) { // 包含保留的group,则不 将域置为失效,否则将域置为失效,否
if ( ! ServiceAndRDBIndexReal . serviceIsReuse ( service ) ) { // 如果当前业务不允许被分组复用(普通的maat类配置),则可以将 域置为 失效,否则不将域 置为失 效
// 如果只有一个编译id且与上面的编译id相同则说明未被分组复用,可以将其下的所有域置失效,否则不处理域配置,只把编译,分组关系置为无效
if ( compileId . equals ( compileStr ) ) { //
String groupR egionKey = groupId . replace ( " GROUPCOMPILE " ,
" GROUPREGION " ) ; // groupregion里面value是region的信息,key是group的信息,所以可以直接将GROUPCOMPILE替换为GROUPREGION
String regionStrs = null ;
if ( ! keyMap . containsKey ( groupRegionKey ) ) {
regionStrs = JedisUtils . get ( groupRegionKey ,
idRelaRedisDBIndex ) ;
keyMap . put ( groupRegionKey , regionStrs ) ;
} else {
regionStrs = keyMap . get ( groupRegionKey ) ;
}
if ( regionStrs ! = null & & ! regionStrs . trim ( ) . equals ( " " ) ) {
String [ ] regionStrAr r = regionStrs . split ( " ; " ) ;
for ( S tring str : regionStrArr ) {
if ( str ! = null & & ! str . trim ( ) . equals ( " " ) ) {
String regionStr = getRegionInfo ( str ) ;
if ( regionStr ! = null
& & ! regionStr . trim ( ) . equals ( " " ) ) {
String [ ] regionKeyArr = regionStr . split ( " ; " ) ;
if ( regionKeyArr ! = null
& & regionKeyArr . length > 0 ) {
// 根据分组与域关联关系找到对应域配置然后删除(重命名)
removeRegionConfig ( maatXmlConfig ,
regionKeyArr , maatVersion , service ,
transaction , redisDBIndex , isStart ) ;
String regionStr = getRegionInfo ( str ) ;
if ( regionStr ! = null
& & ! regionStr . trim ( ) . equals ( " " ) ) {
String [ ] regionKeyArr = regionStr
. split ( " ; " ) ;
if ( regionKeyArr ! = null
& & regionKeyArr . length > 0 ) {
// 根据分组与域关联关系找到对应域配置然后删除(重命名)
removeRegionConfig ( maatXmlConfig ,
regionKeyArr , maatVersion ,
service , transaction ,
redisDBIndex , isStart ) ;
}
} else {
throw new ServiceRuntimeException ( " 从 "
+ idRelaRedisDBIndex
+ " 号redis库中无法获取MAAT配置分组与域的关联关系, key为 "
+ groupRegionKey ,
RestBusinessCode . KeyNotExistsInRedis
. getValue ( ) ) ;
}
} else {
throw new ServiceRuntimeException ( " 从 "
+ idRelaRedisDBIndex
+ " 号redis库中无法获取MAAT配置分组与域的关联关系, key为 "
+ groupRegionKey ,
RestBusinessCode . KeyNotExistsInRedis
. getValue ( ) ) ;
}
}
}
@@ -1348,7 +1321,9 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
}
/**
* 编译配置用于实时统计 取消分类性质,标签等信息
* 取消实时统计库中的 编译配置
*
* @return
*/
private boolean removeStatisticsReal ( Map < Integer , List < Long > > map , Transaction transaction , Boolean isStart ) {
if ( map ! = null & & map . size ( ) > 0 ) {
@@ -1411,11 +1386,16 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
}
/**
* 删除配置成功后,需要 更新编译,组,域等配置id的对应关系
* 失效或生效配置后, 更新编译,组,域等配置id的对应关系
*
* @param idMap
* @param map redisdb与编译id的对应
* @param transaction
* @param isStart 是否将配置置为生效
* @param compileGroupMap 将配置置为失效时,需要保留哪些组(一般针对分组复用的配置,保留当前组,下次可以重复利用改组及其下的域)
* @return
*/
private boolean removeMaatRelation ( Map < Integer , List < Long > > map , Transaction transaction , Boolean isStart ) {
private boolean removeMaatRelation ( Map < Integer , List < Long > > map , Transaction transaction , Boolean isStart ,
Map < Long , List < Long > > compileGroupMap ) {
if ( map ! = null & & map . size ( ) > 0 ) {
int idRelaRedisDBIndex = Configurations . getIntProperty ( " idRelaRedisDBIndex " , 15 ) ;
transaction . select ( idRelaRedisDBIndex ) ;
@@ -1423,6 +1403,9 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
List < Long > idList = map . get ( service ) ;
if ( idList ! = null & & idList . size ( ) > 0 ) {
for ( Long compileId : idList ) {
List < Long > keepGroupIdList = compileGroupMap . get ( compileId ) ;
String compileStr = " COMPILEGROUP: " + compileId ;
String compileStrVal = JedisUtils . get ( compileStr , idRelaRedisDBIndex ) ; // 根据编译id获取该编译下的分组关系
if ( compileStrVal ! = null & & ! compileStrVal . trim ( ) . equals ( " " ) ) {
@@ -1468,10 +1451,7 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
try {
// 为了提高效率,不判断了,如果报错直接捕捉异常处理
// 删除分组与域的关联关系
if ( isStart = = null ) { // 删除
transaction . del ( groupRegion ) ;
} else if ( isStart ) { // 将失效置为生效
if ( isStart ) { // 将失效置为生效
groupRegionVal = groupRegionVal
. replace ( " OBSOLETE_RULE " , " EFFECTIVE_RULE " ) ;
String [ ] split = org . apache . commons . lang . StringUtils
@@ -1495,29 +1475,35 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
groupRegionVal ) ;
}
} else { // 将生效变为失效
groupRegionVal = groupRegionVal
. replace ( " EFFECTIVE_RULE " , " OBSOLETE_RULE " ) ;
String [ ] split = org . apache . commons . lang . StringUtils
. split ( groupRegionVal , " ; " ) ;
if ( split . length > 1 ) {
Set < String > set = new HashSet < > ( ) ;
long groupId = Long . parseLong (
groupRegion . replace ( " GROUPREGION: " , " " ) ) ;
for ( String regionKeyStr : split ) {
if ( regionKeyStr ! = null & & ! regionKeyStr
. trim ( ) . equals ( " " ) ) {
set . add ( regionKeyStr ) ;
i f ( ! keepGroupIdList . contains ( groupId ) ) {
groupRegionVal = groupRegionVal . replace (
" EFFECTIVE_RULE " , " OBSOLETE_RULE " ) ;
String [ ] split = org . apache . commons . lang . StringUtils
. split ( groupRegionVal , " ; " ) ;
if ( split . length > 1 ) {
Set < String > set = new HashSet < > ( ) ;
for ( String regionKeyStr : split ) {
if ( regionKeyStr ! = null
& & ! regionKeyStr . trim ( )
. equals ( " " ) ) {
set . add ( regionKeyStr ) ;
}
}
}
StringBuffer sb = new StringBuffer ( ) ;
for ( String regionKeyStr : set ) {
sb . append ( " ; " ) ;
sb . append ( regionKeyStr ) ;
}
transaction . set ( groupRegion , sb . toString ( ) ) ; // 避免有多个重复的region-key
StringBuffer sb = new StringBuffer ( ) ;
for ( String regionKeyStr : set ) {
sb . append ( " ; " ) ;
sb . append ( regionKeyStr ) ;
}
transaction . set ( groupRegion , sb . toString ( ) ) ; // 避免有多个重复的region-key
} else {
transaction . set ( groupRegion . toUpperCase ( ) ,
groupRegionVal ) ;
} else {
transaction . set ( groupRegion . toUpperCase ( ) ,
groupRegionVal ) ;
}
}
}
@@ -1840,7 +1826,7 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
* 如果没有被使用则先存储在临时库里面,后面下发编译时使用到了该分组再把该分组下的所有域复制到编译下面
*/
@Override
public boolean sav eGroupReuseConfig ( List < MaatConfig > configList ) {
public boolean updat eGroupRegion ( List < MaatConfig > configList ) {
Jedis resource = JedisUtils . getResource ( 0 ) ;
Transaction transaction = resource . multi ( ) ;
try {
@@ -1945,83 +1931,136 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
}
/**
* 保存域配置信息,供分组复用单独添加域和普通maat配置添加域
* 保存域配置信息,如果当前域所属的组是公共组则需要向所有的redisdb中下发域配置,否则只向指定的组下发
*
* @param maatConfig 配置信息
* @param maatXmlConfig 配置的表达式
* @param maatVersion 版本号
* @param service 业务类型
* @param transaction redis连接
* @param redisDBIndex redis编号
* @param isReuseSaveRegion 是否是分组复用单独添加域配置
* @param maatConfig 配置信息
* @param maatXmlConfig 配置的表达式
* @param maatVersion 版本号
* @param service 业务类型
* @param transaction redis连接
* @param redisDBIndex redis编号
* @param isCommonGroup 是否是公共组,如果是公共组则需要向所有的db下发
*/
private Integer addRegion ( MaatConfig maatConfig , MaatXmlConfig maatXmlConfig , Double maatVersion , int service ,
Transaction transaction , Integer redisDBIndex , boolean isReuseSaveRegion ) {
Boolean serviceIsReuse = ServiceAndRDBIndexReal . serviceIsReuse ( service ) ;
Transaction transaction , Integer redisDBIndex , List < Long > commonGroupIdList ) {
// Boolean serviceIsReuse = ServiceAndRDBIndexReal.serviceIsReuse(service);
int count = 0 ; // 计算下所有的域是不是都没有值,如果没有值则给出提示
List < Map < String , String > > ipRegionMapList = maatConfig . getIpRegionMapList ( ) ;
if ( ipRegionMapList ! = null & & ipRegionMapList . size ( ) > 0 ) {
count + = ipRegionMapList . size ( ) ;
for ( Map < String , String > map : ipRegionMapList ) {
setCommonConfig ( maatXmlConfig , map , 12 , maatVersi on, service , transaction , redisDBIndex , null ,
serviceIsReuse ) ; // 12代表是ip类域配置
Long groupId = Long . parseL ong ( map . get ( " group_id " ) ) ;
boolean isCommonGroup = commonGroupIdList . contains ( groupId ) ;
if ( isCommonGroup ) {
for ( String db : Constants . COMMONGROUPDBARR ) {
setCommonConfig ( maatXmlConfig , map , 12 , maatVersion , service , transaction , Integer . parseInt ( db ) ,
null ) ; // 12代表是ip类域配置
}
} else {
setCommonConfig ( maatXmlConfig , map , 12 , maatVersion , service , transaction , redisDBIndex , null ) ; // 12代表是ip类域配置
}
}
}
List < Map < String , String > > numRegionMapList = maatConfig . getNumRegionMapList ( ) ;
if ( numRegionMapList ! = null & & numRegionMapList . size ( ) > 0 ) {
count + = numRegionMapList . size ( ) ;
for ( Map < String , String > map : numRegionMapList ) {
setCommonConfig ( maatXmlConfig , map , 13 , maatVersi on, service , transaction , redisDBIndex , null ,
serviceIsReuse ) ; // 13代表是数值类配置
Long groupId = Long . parseL ong ( map . get ( " group_id " ) ) ;
boolean isCommonGroup = commonGroupIdList . contains ( groupId ) ;
if ( isCommonGroup ) {
for ( String db : Constants . COMMONGROUPDBARR ) {
setCommonConfig ( maatXmlConfig , map , 13 , maatVersion , service , transaction , Integer . parseInt ( db ) ,
null ) ; // 13代表是数值类配置
}
} else {
setCommonConfig ( maatXmlConfig , map , 13 , maatVersion , service , transaction , redisDBIndex , null ) ; // 13代表是数值类配置
}
}
}
List < Map < String , String > > strRegionMapList = maatConfig . getStrRegionMapList ( ) ;
if ( strRegionMapList ! = null & & strRegionMapList . size ( ) > 0 ) {
count + = strRegionMapList . size ( ) ;
for ( Map < String , String > map : strRegionMapList ) {
setCommonConfig ( maatXmlConfig , map , 14 , maatVersi on, service , transaction , redisDBIndex , null ,
serviceIsReuse ) ; // 14代表是字符串类域配置
Long groupId = Long . parseL ong ( map . get ( " group_id " ) ) ;
boolean isCommonGroup = commonGroupIdList . contains ( groupId ) ;
if ( isCommonGroup ) {
for ( String db : Constants . COMMONGROUPDBARR ) {
setCommonConfig ( maatXmlConfig , map , 14 , maatVersion , service , transaction , Integer . parseInt ( db ) ,
null ) ; // 14代表是字符串类域配置
}
} else {
setCommonConfig ( maatXmlConfig , map , 14 , maatVersion , service , transaction , redisDBIndex , null ) ; // 14代表是字符串类域配置
}
}
}
List < Map < String , String > > strStrRegionMapList = maatConfig . getStrStrRegionMapList ( ) ;
if ( strStrRegionMapList ! = null & & strStrRegionMapList . size ( ) > 0 ) {
count + = strStrRegionMapList . size ( ) ;
for ( Map < String , String > map : strStrRegionMapList ) {
setCommonConfig ( maatXmlConfig , map , 15 , maatVersi on, service , transaction , redisDBIndex , null ,
serviceIsReuse ) ; // 15代表是增强字符串类域配置
Long groupId = Long . parseL ong ( map . get ( " group_id " ) ) ;
boolean isCommonGroup = commonGroupIdList . contains ( groupId ) ;
if ( isCommonGroup ) {
for ( String db : Constants . COMMONGROUPDBARR ) {
setCommonConfig ( maatXmlConfig , map , 15 , maatVersion , service , transaction , Integer . parseInt ( db ) ,
null ) ; // 15代表是增强字符串类域配置
}
} else {
setCommonConfig ( maatXmlConfig , map , 15 , maatVersion , service , transaction , redisDBIndex , null ) ; // 15代表是增强字符串类域配置
}
}
}
List < Map < String , String > > fileDigestRegionMapList = maatConfig . getFileDigestRegionMapList ( ) ;
if ( fileDigestRegionMapList ! = null & & fileDigestRegionMapList . size ( ) > 0 ) {
count + = fileDigestRegionMapList . size ( ) ;
for ( Map < String , String > map : fileDigestRegionMapList ) {
setCommonConfig ( maatXmlConfig , map , 16 , maatVersi on, service , transaction , redisDBIndex , null ,
serviceIsReuse ) ; // 16代表是文件摘要类域配置
Long groupId = Long . parseL ong ( map . get ( " group_id " ) ) ;
boolean isCommonGroup = commonGroupIdList . contains ( groupId ) ;
if ( isCommonGroup ) {
for ( String db : Constants . COMMONGROUPDBARR ) {
setCommonConfig ( maatXmlConfig , map , 16 , maatVersion , service , transaction , Integer . parseInt ( db ) ,
null ) ; // 16代表是文件摘要类域配置
}
} else {
setCommonConfig ( maatXmlConfig , map , 16 , maatVersion , service , transaction , redisDBIndex , null ) ; // 16代表是文件摘要类域配置
}
}
}
List < Map < String , String > > fileLikeRegionMapList = maatConfig . getFileLikeRegionMapList ( ) ;
if ( fileLikeRegionMapList ! = null & & fileLikeRegionMapList . size ( ) > 0 ) {
count + = fileLikeRegionMapList . size ( ) ;
for ( Map < String , String > map : fileLikeRegionMapList ) {
setCommonConfig ( maatXmlConfig , map , 17 , maatVersi on, service , transaction , redisDBIndex , null ,
serviceIsReuse ) ; // 17代表是文本相似性域配置
Long groupId = Long . parseL ong ( map . get ( " group_id " ) ) ;
boolean isCommonGroup = commonGroupIdList . contains ( groupId ) ;
if ( isCommonGroup ) {
for ( String db : Constants . COMMONGROUPDBARR ) {
setCommonConfig ( maatXmlConfig , map , 17 , maatVersion , service , transaction , Integer . parseInt ( db ) ,
null ) ; // 17代表是文本相似性域配置
}
} else {
setCommonConfig ( maatXmlConfig , map , 17 , maatVersion , service , transaction , redisDBIndex , null ) ; // 17代表是文本相似性域配置
}
}
}
List < Map < String , String > > ipclientList = maatConfig . getIpClientRangeMapList ( ) ;
if ( ipclientList ! = null & & ipclientList . size ( ) > 0 ) {
count + = ipclientList . size ( ) ;
for ( Map < String , String > map : ipclientList ) {
setCommonConfig ( maatXmlConfig , map , 18 , maatVersi on, service , transaction , redisDBIndex , null ,
serviceIsReuse ) ; // 18代表是区域ip域配置
Long groupId = Long . parseL ong ( map . get ( " group_id " ) ) ;
boolean isCommonGroup = commonGroupIdList . contains ( groupId ) ;
if ( isCommonGroup ) {
for ( String db : Constants . COMMONGROUPDBARR ) {
setCommonConfig ( maatXmlConfig , map , 18 , maatVersion , service , transaction , Integer . parseInt ( db ) ,
null ) ; // 18代表是区域ip域配置
}
} else {
setCommonConfig ( maatXmlConfig , map , 18 , maatVersion , service , transaction , redisDBIndex , null ) ; // 18代表是区域ip域配置
}
}
}
if ( count = = 0 & & isReuseSaveRegion ) {
throw new ServiceRuntimeException ( " 添加分组复用域配置时,所有的域配置都为空,请检查配置参数是否正确 " ,
RestBusinessCode . ConfigSourceIsNull . getValue ( ) ) ;
}
// if (count == 0 && isReuseSaveRegion) {
// throw new ServiceRuntimeException("添加分组复用域配置时,所有的域配置都为空,请检查配置参数是否正确",
// RestBusinessCode.ConfigSourceIsNull.getValue());
// }
return count ;
}