@@ -52,6 +52,7 @@ import com.nis.domain.specific.ConfigGroupInfo;
import com.nis.domain.specific.SpecificServiceCfg ;
import com.nis.util.ConfigServiceUtil ;
import com.nis.util.Constants ;
import com.nis.util.DateUtil ;
import com.nis.util.DateUtils ;
import com.nis.util.DictUtils ;
import com.nis.util.FileUtils ;
@@ -120,13 +121,6 @@ public class ConfigSynchronizationService extends BaseService{
handleSingleMaatData ( cfgType , userRegionList , page , entity , request , response , false ) ;
}
}
/*if("cfg_index_info".equals(tableName)){
Page<CfgIndexInfo> page=new Page<CfgIndexInfo>(request,response,Constants.MAAT_JSON_SEND_SIZE,"a");
handleNtcMaatData(cfgList,userRegionList,page,entity,request,response,false);
}else if("ddos_ip_cfg".equals(tableName)){
Page<DdosIpCfg> page=new Page<DdosIpCfg>(request,response,Constants.MAAT_JSON_SEND_SIZE,"a");
handleDdosMaatData(cfgList,userRegionList,page,entity,request,response,false);
}*/
} else if ( " 2 " . equals ( serviceType ) ) { //回调类配置
entity . setTableName ( tableName ) ;
entity . setServiceId ( Integer . valueOf ( serviceId ) ) ;
@@ -172,6 +166,16 @@ public class ConfigSynchronizationService extends BaseService{
} else {
hasData = false ;
}
} else if ( " file_digest_cfg " . equals ( tableName ) ) {
list = configSynchronizationDao . getFileDigestListByService ( entity ) ;
if ( ! StringUtil . isEmpty ( list ) ) {
hasData = auditFileDigestData ( cfgList , userRegionList , page , entity , list , hasData , isUpdateCfg ) ;
if ( hasData ) {
page . setPageNo ( page . getNext ( ) ) ;
}
} else {
hasData = false ;
}
} else if ( " app_policy_cfg " . equals ( tableName ) ) {
list = configSynchronizationDao . getAppPolicyList ( entity ) ;
if ( ! StringUtil . isEmpty ( list ) ) {
@@ -350,23 +354,6 @@ public class ConfigSynchronizationService extends BaseService{
userRegion = userRegion . substring ( 0 , userRegion . length ( ) - 1 ) ;
}
}
if ( ipList . size ( ) > 0 ) {
// List<Integer> ipGroupId = ConfigServiceUtil.getId(2,1);//多条IP只获取一个groupId
for ( int index = 0 ; index < ipList . size ( ) ; index + + ) {
IpPortCfg ip = ipList . get ( index ) ;
if ( ip . getCompileId ( ) . equals ( cfg . getCompileId ( ) ) ) {
// BeanUtils.copyProperties(cfg, ip);
ip . setRegionId ( regionIds . get ( 0 ) ) ;
regionIds . remove ( 0 ) ;
ip . setGroupId ( groupIds . get ( 0 ) ) ;
groupIds . remove ( 0 ) ;
ip . setIsValid ( entity . getIsValid ( ) ) ;
ip . setAuditTime ( StringUtil . isEmpty ( entity . getAuditTime ( ) ) ? cfg . getAuditTime ( ) : entity . getAuditTime ( ) ) ;
list1 . add ( ip ) ;
}
}
}
for ( AsnIpCfg ip : asnIpList ) { //asn不需要再次获取regionId,groupId
if ( ip . getAsnIpGroup ( ) . toString ( ) . equals ( cfg . getUserRegion4 ( ) ) ) { //根据组号对应
ip . setIsValid ( entity . getIsValid ( ) ) ;
@@ -374,118 +361,20 @@ public class ConfigSynchronizationService extends BaseService{
list1 . add ( ip ) ;
}
}
for ( int index = 0 ; index < strList . size ( ) ; index + + ) {
BaseStringCfg str = strList . get ( index ) ;
if ( str . getCompileId ( ) . equals ( cfg . getCompileId ( ) ) ) {
// BeanUtils.copyProperties(cfg, str);
str . setRegionId ( regionIds . get ( 0 ) ) ;
regionIds . remove ( 0 ) ;
str . setGroupId ( groupIds . get ( 0 ) ) ;
groupIds . remove ( 0 ) ;
str . setIsValid ( entity . getIsValid ( ) ) ;
str . setAuditTime ( StringUtil . isEmpty ( entity . getAuditTime ( ) ) ? cfg . getAuditTime ( ) : entity . getAuditTime ( ) ) ;
list2 . add ( str ) ;
if ( entity . getServiceId ( ) . equals ( 513 ) | | entity . getServiceId ( ) . equals ( 515 ) ) {
if ( userRegion . equals ( " " ) ) {
userRegion + = Constants . USERREGION_DOMAIN_STR + " = " + str . getCfgKeywords ( ) ;
} else {
userRegion + = Constants . USER_REGION_SPLIT + Constants . USERREGION_DOMAIN_STR + " = " + str . getCfgKeywords ( ) ;
}
}
}
}
for ( int index = 0 ; index < complexStrList . size ( ) ; index + + ) {
ComplexkeywordCfg str = complexStrList . get ( index ) ;
if ( str . getCompileId ( ) . equals ( cfg . getCompileId ( ) ) ) {
// BeanUtils.copyProperties(cfg, str);
str . setRegionId ( regionIds . get ( 0 ) ) ;
regionIds . remove ( 0 ) ;
str . setGroupId ( groupIds . get ( 0 ) ) ;
groupIds . remove ( 0 ) ;
str . setIsValid ( entity . getIsValid ( ) ) ;
str . setAuditTime ( StringUtil . isEmpty ( entity . getAuditTime ( ) ) ? cfg . getAuditTime ( ) : entity . getAuditTime ( ) ) ;
list3 . add ( str ) ;
if ( entity . getServiceId ( ) . equals ( 129 ) & & str . getDistrict ( ) ! = null ) { //http监测
String dictValue = DictUtils . getDictCode ( Constants . HTTP_HEADER_DICT_MODULE , str . getDistrict ( ) ) ;
if ( StringUtil . isEmpty ( dictValue ) | | dictValue . equals ( " 默认 " ) ) {
if ( userRegion . equals ( " " ) ) {
userRegion + = Constants . HTTP_HEADER_USER_REGION_KEY + " = " + str . getDistrict ( ) ;
} else {
userRegion + = Constants . USER_REGION_SPLIT + Constants . HTTP_HEADER_USER_REGION_KEY + " = " + str . getDistrict ( ) ;
}
}
}
}
}
for ( int index = 0 ; index < numList . size ( ) ; index + + ) {
com . nis . domain . configuration . NumBoundaryCfg num = numList . get ( index ) ;
if ( num . getCompileId ( ) . equals ( cfg . getCompileId ( ) ) ) {
// BeanUtils.copyProperties(cfg, num);
num . setRegionId ( regionIds . get ( 0 ) ) ;
regionIds . remove ( 0 ) ;
num . setGroupId ( groupIds . get ( 0 ) ) ;
groupIds . remove ( 0 ) ;
num . setIsValid ( entity . getIsValid ( ) ) ;
num . setAuditTime ( StringUtil . isEmpty ( entity . getAuditTime ( ) ) ? cfg . getAuditTime ( ) : entity . getAuditTime ( ) ) ;
list4 . add ( num ) ;
}
}
for ( int index = 0 ; index < fileList . size ( ) ; index + + ) {
FileDigestCfg file = fileList . get ( index ) ;
if ( file . getCompileId ( ) . equals ( cfg . getCompileId ( ) ) ) {
// BeanUtils.copyProperties(cfg, file);
file . setRegionId ( regionIds . get ( 0 ) ) ;
regionIds . remove ( 0 ) ;
file . setGroupId ( groupIds . get ( 0 ) ) ;
groupIds . remove ( 0 ) ;
file . setIsValid ( entity . getIsValid ( ) ) ;
file . setAuditTime ( StringUtil . isEmpty ( entity . getAuditTime ( ) ) ? cfg . getAuditTime ( ) : entity . getAuditTime ( ) ) ;
list5 . add ( file ) ;
}
}
if ( list1 . size ( ) > 0 ) {
ipList . removeAll ( list1 ) ;
if ( entity . g etServic eId( ) . equals ( 37 ) | | entity . getServic eId ( ) . equals ( 149 ) ) { //asn业务
G roupCfg groupCfg = new GroupCfg ( ) ;
groupCfg . setCompileId ( cfg . getCompileI d ( ) ) ;
groupCfg . setGroupId ( Integer . parseInt ( cfg . getUserRegion4 ( ) ) ) ;
groupCfg . setIsValid ( entity . getIsValid ( ) ) ;
groupCfg . setAuditTime ( StringUtil . isEmpty ( entity . getAuditTime ( ) ) ? cfg . getAuditTime ( ) : entity . getAuditTime ( ) ) ;
groupRelationList . add ( groupCfg ) ;
ipRegionList . addAll ( groupReuseCfgAddRemoveConvert ( list1 , Constants . VALID_YES , null ) ) ;
} else {
Map < String , List > map = cfgToMaatConvert ( ipRegionList , list1 , 1 , groupRelationList ) ;
groupRelationList = map . get ( " groupList " ) ;
ipRegionList = map . get ( " dstList " ) ;
if ( map . get ( " numRegionList " ) ! = null ) {
numRegionList . addAll ( map . get ( " numRegionList " ) ) ;
}
}
}
if ( list2 . size ( ) > 0 ) {
strList . removeAll ( list2 ) ;
Map < String , List > map = cfgToMaatConvert ( strRegionList , list2 , 2 , groupRelationList ) ;
groupRelationList = map . get ( " groupList " ) ;
strRegionList = map . get ( " dstList " ) ;
}
if ( list3 . size ( ) > 0 ) {
complexStrList . removeAll ( list3 ) ;
Map < String , List > map = cfgToMaatConvert ( strRegionList , list3 , 3 , groupRelationList ) ;
groupRelationList = map . get ( " groupList " ) ;
strRegionList = map . get ( " dstList " ) ;
}
if ( list4 . size ( ) > 0 ) {
numList . removeAll ( list4 ) ;
Map < String , List > map = cfgToMaatConvert ( numRegionList , list4 , 4 , groupRelationList ) ;
groupRelationList = map . get ( " groupList " ) ;
numRegionList = map . get ( " dstList " ) ;
}
if ( list5 . size ( ) > 0 ) {
fileList . removeAll ( list5 ) ;
Map < String , List > map = cfgToMaatConvert ( digestRegionList , list5 , 5 , groupRelationList ) ;
groupRelationList = map . get ( " groupList " ) ;
digestRegionList = map . get ( " dstList " ) ;
GroupCfg groupCfg = new GroupCfg ( ) ;
groupCfg . s etCompil eId( cfg . getCompil eId ( ) ) ;
g roupCfg. setGroupId ( Integer . parseInt ( cfg . getUserRegion4 ( ) ) ) ;
groupCfg . setIsValid ( entity . getIsVali d ( ) ) ;
groupCfg . setAuditTime ( StringUtil . isEmpty ( entity . getAuditTime ( ) ) ? cfg . getAuditTime ( ) : entity . getAuditTime ( ) ) ;
groupRelationList . add ( groupCfg ) ;
ipRegionList . addAll ( groupReuseCfgAddRemoveConvert ( list1 , Constants . VALID_YES , null ) ) ;
}
//配置域转换
configCovert ( ipList , strList , complexStrList ,
numList , fileList , regionIds , groupIds , entity , cfg . getCompileId ( ) ,
StringUtil . isEmpty ( entity . getAuditTime ( ) ) ? cfg . getAuditTime ( ) : entity . getAuditTime ( ) ,
groupRelationList , ipRegionList , strRegionList , numRegionList , digestRegionList , areaIpRegionList , userRegion ) ;
BeanUtils . copyProperties ( cfg , maatCfg ) ;
maatCfg . setAction ( cfg . getAction ( ) ) ;
@@ -525,13 +414,180 @@ public class ConfigSynchronizationService extends BaseService{
}
} else {
//调用服务接口配置全量更新
// FileUtils. writeToFile("d:\\configSync\\"+ entity. getServiceId()+"_"+page.getPageNo()+"_"+ System. currentTimeMillis()+".txt", json, false) ;
JSONObject result = ConfigServiceUtil. configSync( json , 1 , entity. getServiceId( ) , null , ( hasData ? null : " FINISHED " ) ) ;
FileUtils. writeToFile( " /home/configSync/ " + DateUtils . getDate ( " yyyy-MM-dd " ) + " / " + entity. getServiceId( ) + " _ " + page . getPageNo ( ) + " _ " + System. currentTimeMillis( ) + " .json " , json , false ) ;
// JSONObject result = ConfigServiceUtil. configSync(json,1, entity. getServiceId(),null,(hasData?null:"FINISHED")) ;
}
}
return hasData ;
}
/**
* 文件摘要配置批量下发
* @param cfgList
* @param userRegionList
* @param page
* @param entity
* @param list
* @param hasData
* @param isUpdateCfg 业务配置全部生效时需同步更新库表配置状态
* @return
* @throws NoSuchFieldException
* @throws SecurityException
* @throws IllegalArgumentException
* @throws IllegalAccessException
*/
public boolean auditFileDigestData ( List < Map < String , Object > > cfgList ,
List < Map < String , Object > > userRegionList ,
Page page ,
BaseCfg entity ,
List < FileDigestCfg > list ,
boolean hasData ,
boolean isUpdateCfg ) throws NoSuchFieldException , SecurityException , IllegalArgumentException , IllegalAccessException {
ToMaatBean maatBean ;
MaatCfg maatCfg ;
List < MaatCfg > configCompileList ;
List < GroupCfg > groupRelationList ;
List < IpCfg > ipRegionList ;
List < StringCfg > strRegionList ;
List < NumBoundaryCfg > numRegionList ;
List < DigestCfg > digestRegionList ;
List < IpCfg > areaIpRegionList ;
List < IpPortCfg > ipList = new ArrayList ( ) ;
List < BaseStringCfg > strList = new ArrayList ( ) ;
List < ComplexkeywordCfg > complexStrList = new ArrayList ( ) ;
List < com . nis . domain . configuration . NumBoundaryCfg > numList = new ArrayList ( ) ;
List < FileDigestCfg > fileList = new ArrayList ( ) ;
maatBean = new ToMaatBean ( ) ;
configCompileList = new ArrayList ( ) ;
List < Integer > compileIds = new ArrayList ( ) ;
for ( FileDigestCfg cfg : list ) {
compileIds . add ( cfg . getCompileId ( ) ) ;
fileList . add ( cfg ) ;
}
if ( isUpdateCfg ) {
if ( ! StringUtil . isEmpty ( compileIds ) & & ! StringUtil . isEmpty ( entity . getTableName ( ) ) ) {
commonPolicyDao . auditCfgBatch ( entity . getTableName ( ) , entity , compileIds , null ) ;
}
}
if ( cfgList ! = null ) {
for ( Map < String , Object > m : cfgList ) {
String tableName = m . get ( " tableName " ) . toString ( ) ;
if ( " 1 " . equals ( m . get ( " cfgType " ) ) ) {
ipList . addAll ( configSynchronizationDao . getIpPortList ( tableName , compileIds ) ) ;
} else if ( " 2 " . equals ( m . get ( " cfgType " ) ) ) {
strList . addAll ( configSynchronizationDao . getStrList ( tableName , compileIds ) ) ;
} else if ( " 3 " . equals ( m . get ( " cfgType " ) ) ) {
complexStrList . addAll ( configSynchronizationDao . getComplexStrList ( tableName , compileIds ) ) ;
} else if ( " 4 " . equals ( m . get ( " cfgType " ) ) ) {
} else if ( " 5 " . equals ( m . get ( " cfgType " ) ) ) {
fileList . addAll ( configSynchronizationDao . getFileDigestList ( tableName , compileIds ) ) ;
}
if ( isUpdateCfg ) {
commonPolicyDao . auditCfgBatch ( tableName , entity , compileIds , null ) ;
}
}
}
//批量获取regionId,groupId(相同编译下的IP类配置多条ip只获取一个组号) , 分组复用的域配置不需要重新获取regionId,groupId
List < Integer > regionIds = ConfigServiceUtil . getId ( 3 , ipList . size ( ) + strList . size ( ) + complexStrList . size ( ) + numList . size ( ) + fileList . size ( ) ) ;
List < Integer > groupIds = ConfigServiceUtil . getId ( 2 , ipList . size ( ) + strList . size ( ) + complexStrList . size ( ) + numList . size ( ) + fileList . size ( ) ) ;
for ( FileDigestCfg cfg : list ) {
maatCfg = new MaatCfg ( ) ;
maatCfg . initDefaultValue ( ) ;
groupRelationList = new ArrayList ( ) ;
ipRegionList = new ArrayList ( ) ;
strRegionList = new ArrayList ( ) ;
numRegionList = new ArrayList ( ) ;
digestRegionList = new ArrayList ( ) ;
areaIpRegionList = new ArrayList ( ) ;
List list1 = new ArrayList ( ) ;
List < BaseStringCfg > list2 = new ArrayList ( ) ;
List < ComplexkeywordCfg > list3 = new ArrayList ( ) ;
List < com . nis . domain . configuration . NumBoundaryCfg > list4 = new ArrayList ( ) ;
List < FileDigestCfg > list5 = new ArrayList ( ) ;
String userRegion = " " ;
//处理自定义域
if ( userRegionList ! = null ) {
for ( Map < String , Object > n : userRegionList ) {
Object userRegionPosition = n . get ( " userRegionPosition " ) ;
if ( userRegionPosition ! = null & & ( userRegionPosition . toString ( ) . equals ( " 1 " ) | | userRegionPosition . toString ( ) . equals ( " 0 " ) ) ) {
//通过反射机制获取自定义域字段值
String regionColumn = n . get ( " regionColumn " ) . toString ( ) ;
Class aClass = null ;
if ( userRegionPosition . toString ( ) . equals ( ( " 0 " ) ) ) {
aClass = BaseCfg . class ;
} else {
aClass = FileDigestCfg . class ;
}
Object value = " " ;
Field field = aClass . getDeclaredField ( regionColumn ) ;
field . setAccessible ( true ) ;
value = field . get ( cfg ) ;
if ( ! StringUtil . isEmpty ( value ) ) {
if ( StringUtil . isEmpty ( n . get ( " regionKey " ) ) ) {
userRegion = value . toString ( ) ;
} else {
userRegion + = n . get ( " regionKey " ) + " = " + value + Constants . USER_REGION_SPLIT ;
}
}
}
// System.out.println("userRegionList:"+n.get("regionKey")+","+n.get("regionColumn")+","+n.get("handleType"));
}
if ( userRegion . endsWith ( Constants . USER_REGION_SPLIT ) ) {
userRegion = userRegion . substring ( 0 , userRegion . length ( ) - 1 ) ;
}
}
//配置域转换
configCovert ( ipList , strList , complexStrList ,
numList , fileList , regionIds , groupIds , entity , cfg . getCompileId ( ) ,
StringUtil . isEmpty ( entity . getAuditTime ( ) ) ? cfg . getAuditTime ( ) : entity . getAuditTime ( ) ,
groupRelationList , ipRegionList , strRegionList , numRegionList , digestRegionList , areaIpRegionList , userRegion ) ;
BeanUtils . copyProperties ( cfg , maatCfg ) ;
maatCfg . setAction ( cfg . getAction ( ) ) ;
maatCfg . setAuditTime ( StringUtil . isEmpty ( entity . getAuditTime ( ) ) ? cfg . getAuditTime ( ) : entity . getAuditTime ( ) ) ;
maatCfg . setIpRegionList ( ipRegionList ) ;
maatCfg . setStrRegionList ( strRegionList ) ;
maatCfg . setNumRegionList ( numRegionList ) ;
maatCfg . setDigestRegionList ( digestRegionList ) ;
maatCfg . setGroupRelationList ( groupRelationList ) ;
maatCfg . setGroupNum ( groupRelationList . size ( ) ) ;
maatCfg . setAreaIpRegionList ( areaIpRegionList ) ;
maatCfg . setIsValid ( entity . getIsValid ( ) ) ;
maatCfg . setAuditTime ( new Date ( ) ) ;
if ( ! StringUtil . isEmpty ( userRegion ) ) {
maatCfg . setUserRegion ( userRegion ) ;
}
configCompileList . add ( maatCfg ) ;
}
page . setList ( list ) ;
if ( page . isLastPage ( ) ) {
hasData = false ;
}
if ( ! StringUtil . isEmpty ( configCompileList . size ( ) ) ) {
maatBean . setConfigCompileList ( configCompileList ) ;
maatBean . setAuditTime ( new Date ( ) ) ;
maatBean . setCreatorName ( UserUtils . getUser ( ) . getName ( ) ) ;
maatBean . setVersion ( Constants . MAAT_VERSION ) ;
maatBean . setOpAction ( Constants . INSERT_ACTION ) ;
String json = gsonToJson ( maatBean ) ;
//调用服务接口下发配置数据
if ( isUpdateCfg ) {
logger . info ( " 配置批量下发: " + json ) ;
//调用服务接口同步回调类配置
ToMaatResult result = ConfigServiceUtil . postMaatCfg ( json ) ;
if ( result ! = null ) {
logger . info ( " 配置批量下发响应信息: " + result . getMsg ( ) ) ;
}
} else {
//调用服务接口配置全量更新
FileUtils . writeToFile ( " /home/configSync/ " + DateUtils . getDate ( " yyyy-MM-dd " ) + " / " + entity . getServiceId ( ) + " _ " + page . getPageNo ( ) + " _ " + System . currentTimeMillis ( ) + " .json " , json , false ) ;
// JSONObject result = ConfigServiceUtil.configSync(json,1,entity.getServiceId(),null,(hasData?null:"FINISHED"));
}
}
return hasData ;
}
/**
* APP策略配置批量下发
* @param cfgList
@@ -661,110 +717,11 @@ public class ConfigSynchronizationService extends BaseService{
cfg . setCfgKeywords ( cfgKeywords . toString ( ) ) ;
BeanUtils . copyProperties ( cfg , strCfg ) ;
strList . add ( strCfg ) ;
if ( ip List. size ( ) > 0 ) {
// List<Integer> ipGroupId = ConfigServiceUtil.getId(2,1);//多条IP只获取一个groupId
for ( int index = 0 ; index < ipList . size ( ) ; index + + ) {
IpPortCfg ip = ipList . get ( index ) ;
if ( ip . getCompileId ( ) . equals ( cfg . getCompileId ( ) ) ) {
// BeanUtils.copyProperties(cfg, ip);
ip . setRegionId ( regionIds . get ( 0 ) ) ;
regionIds . remove ( 0 ) ;
ip . setGroupId ( groupIds . get ( 0 ) ) ;
groupIds . remove ( 0 ) ;
ip . setIsValid ( entity . getIsValid ( ) ) ;
ip . setAuditTime ( StringUtil . isEmpty ( entity . getAuditTime ( ) ) ? cfg . getAuditTime ( ) : entity . getAuditTime ( ) ) ;
list1 . add ( ip ) ;
}
}
}
for ( int index = 0 ; index < strList . size ( ) ; index + + ) {
BaseStringCfg str = strList . get ( index ) ;
if ( str . getCompileId ( ) . equals ( cfg . getCompileId ( ) ) ) {
// BeanUtils.copyProperties(cfg, str);
str . setRegionId ( regionIds . get ( 0 ) ) ;
regionIds . remove ( 0 ) ;
str . setGroupId ( groupIds . get ( 0 ) ) ;
groupIds . remove ( 0 ) ;
str . setIsValid ( entity . getIsValid ( ) ) ;
str . setAuditTime ( StringUtil . isEmpty ( entity . getAuditTime ( ) ) ? cfg . getAuditTime ( ) : entity . getAuditTime ( ) ) ;
list2 . add ( str ) ;
}
}
for ( int index = 0 ; index < complexStrList . size ( ) ; index + + ) {
ComplexkeywordCfg str = complexStrList . get ( index ) ;
if ( str . getCompileId ( ) . equals ( cfg . getCompileId ( ) ) ) {
// BeanUtils.copyProperties(cfg, str);
str . setRegionId ( regionIds . get ( 0 ) ) ;
regionIds . remove ( 0 ) ;
str . setGroupId ( groupIds . get ( 0 ) ) ;
groupIds . remove ( 0 ) ;
str . setIsValid ( entity . getIsValid ( ) ) ;
str . setAuditTime ( StringUtil . isEmpty ( entity . getAuditTime ( ) ) ? cfg . getAuditTime ( ) : entity . getAuditTime ( ) ) ;
list3 . add ( str ) ;
}
}
for ( int index = 0 ; index < numList . size ( ) ; index + + ) {
com . nis . domain . configuration . NumBoundaryCfg num = numList . get ( index ) ;
if ( num . getCompileId ( ) . equals ( cfg . getCompileId ( ) ) ) {
// BeanUtils.copyProperties(cfg, num);
num . setRegionId ( regionIds . get ( 0 ) ) ;
regionIds . remove ( 0 ) ;
num . setGroupId ( groupIds . get ( 0 ) ) ;
groupIds . remove ( 0 ) ;
num . setIsValid ( entity . getIsValid ( ) ) ;
num . setAuditTime ( StringUtil . isEmpty ( entity . getAuditTime ( ) ) ? cfg . getAuditTime ( ) : entity . getAuditTime ( ) ) ;
list4 . add ( num ) ;
}
}
for ( int index = 0 ; index < fileList . size ( ) ; index + + ) {
FileDigestCfg file = fileList . get ( index ) ;
if ( file . getCompileId ( ) . equals ( cfg . getCompileId ( ) ) ) {
// BeanUtils.copyProperties(cfg, file);
file . setRegionId ( regionIds . get ( 0 ) ) ;
regionIds . remove ( 0 ) ;
file . setGroupId ( groupIds . get ( 0 ) ) ;
groupIds . remove ( 0 ) ;
file . setIsValid ( entity . getIsValid ( ) ) ;
file . setAuditTime ( StringUtil . isEmpty ( entity . getAuditTime ( ) ) ? cfg . getAuditTime ( ) : entity . getAuditTime ( ) ) ;
list5 . add ( file ) ;
}
}
if ( list1 . size ( ) > 0 ) {
ipList . removeAll ( list1 ) ;
Map < String , List > map = cfgToMaatConvert ( ipRegionList , list1 , 1 , groupRelationList ) ;
groupRelationList = map . get ( " groupList " ) ;
ipRegionList = map . get ( " dstList " ) ;
if ( map . get ( " numRegionList " ) ! = null ) {
numRegionList . addAll ( map . get ( " numRegionList " ) ) ;
}
}
if ( list2 . size ( ) > 0 ) {
strList . removeAll ( list2 ) ;
Map < String , List > map = cfgToMaatConvert ( strRegionList , list2 , 2 , groupRelationList ) ;
groupRelationList = map . get ( " groupList " ) ;
strRegionList = map . get ( " dstList " ) ;
}
if ( list3 . size ( ) > 0 ) {
complexStrList . removeAll ( list3 ) ;
Map < String , List > map = cfgToMaatConvert ( strRegionList , list3 , 3 , groupRelationList ) ;
groupRelationList = map . get ( " groupList " ) ;
strRegionList = map . get ( " dstList " ) ;
}
if ( list4 . size ( ) > 0 ) {
numList . removeAll ( list4 ) ;
Map < String , List > map = cfgToMaatConvert ( numRegionList , list4 , 4 , groupRelationList ) ;
groupRelationList = map . get ( " groupList " ) ;
numRegionList = map . get ( " dstList " ) ;
}
if ( list5 . size ( ) > 0 ) {
fileList . removeAll ( list5 ) ;
Map < String , List > map = cfgToMaatConvert ( digestRegionList , list5 , 5 , groupRelationList ) ;
groupRelationList = map . get ( " groupList " ) ;
digestRegionList = map . get ( " dstList " ) ;
}
//配置域转换
configCovert ( ipList , strList , complexStrList ,
numList , file List, regionIds , groupIds , entity , cfg . getCompileId ( ) ,
StringUtil . isEmpty ( entity . getAuditTime ( ) ) ? cfg . getAuditTime ( ) : entity . getAuditTime ( ) ,
groupRelationList , ipRegionList , strRegionList , numRegionList , digestRegionList , areaIpRegionList , userRegion ) ;
BeanUtils . copyProperties ( cfg , maatCfg ) ;
maatCfg . setAction ( cfg . getAction ( ) ) ;
@@ -804,8 +761,8 @@ public class ConfigSynchronizationService extends BaseService{
}
} else {
//调用服务接口配置全量更新
// FileUtils. writeToFile("d:\\configSync\\"+ entity. getServiceId()+"_"+page.getPageNo()+"_"+ System. currentTimeMillis()+".txt", json, false) ;
JSONObject result = ConfigServiceUtil. configSync( json , 1 , entity. getServiceId( ) , null , ( hasData ? null : " FINISHED " ) ) ;
FileUtils. writeToFile( " /home/configSync/ " + DateUtils . getDate ( " yyyy-MM-dd " ) + " / " + entity. getServiceId( ) + " _ " + page . getPageNo ( ) + " _ " + System. currentTimeMillis( ) + " .json " , json , false ) ;
// JSONObject result = ConfigServiceUtil. configSync(json,1, entity. getServiceId(),null,(hasData?null:"FINISHED")) ;
}
}
return hasData ;
@@ -921,108 +878,11 @@ public class ConfigSynchronizationService extends BaseService{
userRegion = userRegion . substring ( 0 , userRegion . length ( ) - 1 ) ;
}
}
if ( ipList . size ( ) > 0 ) {
// List<Integer> ipGroupId = ConfigServiceUtil.getId(2,1);//多条IP只获取一个groupId
for ( int index = 0 ; index < ipList . size ( ) ; index + + ) {
IpPortCfg ip = ipList . get (index ) ;
if ( ip. getCompileId ( ) . equals ( cfg . getCompileId ( ) ) ) {
// BeanUtils.copyProperties(cfg, ip);
ip . setRegionId ( regionIds . get ( 0 ) ) ;
regionIds . remove ( 0 ) ;
ip . setGroupId ( groupIds . get ( 0 ) ) ;
groupIds . remove ( 0 ) ;
ip . setIsValid ( entity . getIsValid ( ) ) ;
ip . setAuditTime ( StringUtil . isEmpty ( entity . getAuditTime ( ) ) ? cfg . getAuditTime ( ) : entity . getAuditTime ( ) ) ;
list1 . add ( ip ) ;
}
}
}
for ( int index = 0 ; index < strList . size ( ) ; index + + ) {
BaseStringCfg str = strList . get ( index ) ;
if ( str . getCompileId ( ) . equals ( cfg . getCompileId ( ) ) ) {
// BeanUtils.copyProperties(cfg, str);
str . setRegionId ( regionIds . get ( 0 ) ) ;
regionIds . remove ( 0 ) ;
str . setGroupId ( groupIds . get ( 0 ) ) ;
groupIds . remove ( 0 ) ;
str . setIsValid ( entity . getIsValid ( ) ) ;
str . setAuditTime ( StringUtil . isEmpty ( entity . getAuditTime ( ) ) ? cfg . getAuditTime ( ) : entity . getAuditTime ( ) ) ;
list2 . add ( str ) ;
}
}
for ( int index = 0 ; index < complexStrList . size ( ) ; index + + ) {
ComplexkeywordCfg str = complexStrList . get ( index ) ;
if ( str . getCompileId ( ) . equals ( cfg . getCompileId ( ) ) ) {
// BeanUtils.copyProperties(cfg, str);
str . setRegionId ( regionIds . get ( 0 ) ) ;
regionIds . remove ( 0 ) ;
str . setGroupId ( groupIds . get ( 0 ) ) ;
groupIds . remove ( 0 ) ;
str . setIsValid ( entity . getIsValid ( ) ) ;
str . setAuditTime ( StringUtil . isEmpty ( entity . getAuditTime ( ) ) ? cfg . getAuditTime ( ) : entity . getAuditTime ( ) ) ;
list3 . add ( str ) ;
}
}
for ( int index = 0 ; index < numList . size ( ) ; index + + ) {
com . nis . domain . configuration . NumBoundaryCfg num = numList . get ( index ) ;
if ( num . getCompileId ( ) . equals ( cfg . getCompileId ( ) ) ) {
// BeanUtils.copyProperties(cfg, num);
num . setRegionId ( regionIds . get ( 0 ) ) ;
regionIds . remove ( 0 ) ;
num . setGroupId ( groupIds . get ( 0 ) ) ;
groupIds . remove ( 0 ) ;
num . setIsValid ( entity . getIsValid ( ) ) ;
num . setAuditTime ( StringUtil . isEmpty ( entity . getAuditTime ( ) ) ? cfg . getAuditTime ( ) : entity . getAuditTime ( ) ) ;
list4 . add ( num ) ;
}
}
for ( int index = 0 ; index < fileList . size ( ) ; index + + ) {
FileDigestCfg file = fileList . get ( index ) ;
if ( file . getCompileId ( ) . equals ( cfg . getCompileId ( ) ) ) {
// BeanUtils.copyProperties(cfg, file);
file . setRegionId ( regionIds . get ( 0 ) ) ;
regionIds . remove ( 0 ) ;
file . setGroupId ( groupIds . get ( 0 ) ) ;
groupIds . remove ( 0 ) ;
file . setIsValid ( entity . getIsValid ( ) ) ;
file . setAuditTime ( StringUtil . isEmpty ( entity . getAuditTime ( ) ) ? cfg . getAuditTime ( ) : entity . getAuditTime ( ) ) ;
list5 . add ( file ) ;
}
}
if ( list1 . size ( ) > 0 ) {
ipList . removeAll ( list1 ) ;
Map < String , List > map = cfgToMaatConvert ( ipRegionList , list1 , 1 , groupRelationList ) ;
groupRelationList = map . get ( " groupList " ) ;
ipRegionList = map . get ( " dstList " ) ;
if ( map . get ( " numRegionList " ) ! = null ) {
numRegionList . addAll ( map . get ( " numRegionList " ) ) ;
}
}
if ( list2 . size ( ) > 0 ) {
strList . removeAll ( list2 ) ;
Map < String , List > map = cfgToMaatConvert ( strRegionList , list2 , 2 , groupRelationList ) ;
groupRelationList = map . get ( " groupList " ) ;
strRegionList = map . get ( " dstList " ) ;
}
if ( list3 . size ( ) > 0 ) {
complexStrList . removeAll ( list3 ) ;
Map < String , List > map = cfgToMaatConvert ( strRegionList , list3 , 3 , groupRelationList ) ;
groupRelationList = map . get ( " groupList " ) ;
strRegionList = map . get ( " dstList " ) ;
}
if ( list4 . size ( ) > 0 ) {
numList . removeAll ( list4 ) ;
Map < String , List > map = cfgToMaatConvert ( numRegionList , list4 , 4 , groupRelationList ) ;
groupRelationList = map . get ( " groupList " ) ;
numRegionList = map . get ( " dstList " ) ;
}
if ( list5 . size ( ) > 0 ) {
fileList . removeAll ( list5 ) ;
Map < String , List > map = cfgToMaatConvert ( digestRegionList , list5 , 5 , groupRelationList ) ;
groupRelationList = map . get ( " groupList " ) ;
digestRegionList = map . get ( " dstList " ) ;
}
//配置域转换
configCovert ( ipList , strList , complexStrList ,
numList , fileList , regionIds , groupIds , entity , cfg . getCompileId ( ) ,
StringUtil . isEmpty ( entity . getAuditTime ( ) ) ? cfg . getAuditTime ( ) : entity . getAuditTime ( ) ,
groupRelationList , ipRegionList , strRegionList , numRegionList , digestRegionList , areaIpRegionList , userRegion ) ;
BeanUtils . copyProperties ( cfg , maatCfg ) ;
maatCfg . setAction ( cfg . getAction ( ) ) ;
maatCfg . setAuditTime ( StringUtil . isEmpty ( entity . getAuditTime ( ) ) ? cfg . getAuditTime ( ) : entity . getAuditTime ( ) ) ;
@@ -1061,8 +921,8 @@ public class ConfigSynchronizationService extends BaseService{
}
} else {
//调用服务接口配置全量更新
// FileUtils. writeToFile("d:\\configSync\\"+ entity. getServiceId()+"_"+page.getPageNo()+"_"+ System. currentTimeMillis()+".txt", json, false) ;
JSONObject result = ConfigServiceUtil. configSync( json , 1 , entity. getServiceId( ) , null , ( hasData ? null : " FINISHED " ) ) ;
FileUtils. writeToFile( " /home/configSync/ " + DateUtils . getDate ( " yyyy-MM-dd " ) + " / " + entity. getServiceId( ) + " _ " + page . getPageNo ( ) + " _ " + System. currentTimeMillis( ) + " .json " , json , false ) ;
// JSONObject result = ConfigServiceUtil. configSync(json,1, entity. getServiceId(),null,(hasData?null:"FINISHED")) ;
}
}
return hasData ;
@@ -1270,8 +1130,8 @@ public class ConfigSynchronizationService extends BaseService{
}
} else {
//调用服务接口配置全量更新
// FileUtils. writeToFile("d:\\configSync\\"+ entity. getServiceId()+"_"+page.getPageNo()+"_"+ System. currentTimeMillis()+".txt", json, false) ;
JSONObject result = ConfigServiceUtil. configSync( json , 1 , entity. getServiceId( ) , null , ( hasData ? null : " FINISHED " ) ) ;
FileUtils. writeToFile( " /home/configSync/ " + DateUtils . getDate ( " yyyy-MM-dd " ) + " / " + entity. getServiceId( ) + " _ " + page . getPageNo ( ) + " _ " + System. currentTimeMillis( ) + " .json " , json , false ) ;
// JSONObject result = ConfigServiceUtil. configSync(json,1, entity. getServiceId(),null,(hasData?null:"FINISHED")) ;
}
}
@@ -1327,8 +1187,6 @@ public class ConfigSynchronizationService extends BaseService{
BeanUtils . copyProperties ( list . get ( i ) , complexStrCfg ) ;
}
BeanUtils . copyProperties ( list . get ( i ) , cfg ) ;
// cfg.setRegionId(regionIds.get(i));
// cfg.setGroupId(groupIds.get(i));
cfg . setIsValid ( entity . getIsValid ( ) ) ;
cfg . setAuditTime ( StringUtil . isEmpty ( entity . getAuditTime ( ) ) ? cfg . getAuditTime ( ) : entity . getAuditTime ( ) ) ;
maatCfg = new MaatCfg ( ) ;
@@ -1455,8 +1313,8 @@ public class ConfigSynchronizationService extends BaseService{
}
} else {
//调用服务接口配置全量更新
// FileUtils. writeToFile("d:\\configSync\\"+ entity. getServiceId()+"_"+page.getPageNo()+"_"+ System. currentTimeMillis()+".txt", json, false) ;
JSONObject result = ConfigServiceUtil. configSync( json , 1 , entity. getServiceId( ) , null , ( hasData ? null : " FINISHED " ) ) ;
FileUtils. writeToFile( " /home/configSync/ " + DateUtils . getDate ( " yyyy-MM-dd " ) + " / " + entity. getServiceId( ) + " _ " + page . getPageNo ( ) + " _ " + System. currentTimeMillis( ) + " .json " , json , false ) ;
// JSONObject result = ConfigServiceUtil. configSync(json,1, entity. getServiceId(),null,(hasData?null:"FINISHED")) ;
}
}
@@ -1573,8 +1431,8 @@ public class ConfigSynchronizationService extends BaseService{
}
} else {
//调用服务接口配置全量更新
// FileUtils. writeToFile("d:\\configSync\\"+ entity. getServiceId()+"_"+page.getPageNo()+"_"+ System. currentTimeMillis()+".txt", json, false) ;
JSONObject result = ConfigServiceUtil. configSync( json , 1 , entity. getServiceId( ) , null , ( hasData ? null : " FINISHED " ) ) ;
FileUtils. writeToFile( " /home/configSync/ " + DateUtils . getDate ( " yyyy-MM-dd " ) + " / " + entity. getServiceId( ) + " _ " + page . getPageNo ( ) + " _ " + System. currentTimeMillis( ) + " .json " , json , false ) ;
// JSONObject result = ConfigServiceUtil. configSync(json,1, entity. getServiceId(),null,(hasData?null:"FINISHED")) ;
}
}
@@ -1698,14 +1556,159 @@ public class ConfigSynchronizationService extends BaseService{
logger . info ( " 配置批量下发响应信息: " + result . getMsg ( ) ) ;
}
} else {
// logger.info("回调类配置同步:"+json) ;
// FileUtils.writeToFile("d:\\configSync\\"+entity.getServiceId()+"_"+page.getPageNo()+"_"+System.currentTimeMillis()+".txt", json, false);
FileUtils . writeToFile ( " /home/configSync/ " + DateUtils . getDate ( " yyyy-MM-dd " ) + " / " + entity . getServiceId ( ) + " _ " + page . getPageNo ( ) + " _ " + System . currentTimeMillis ( ) + " .json " , json , false ) ;
//调用服务接口同步回调类配置
JSONObject result = ConfigServiceUtil. configSync( json , 2 , entity. getServiceId( ) , entity. getTableName( ) , ( hasData ? null : " FINISHED " ) ) ;
// logger.info("回调类配置同步:"+result.getMsg());
// JSONObject result = ConfigServiceUtil. configSync(json,2, entity. getServiceId(), entity. getTableName(),(hasData?null:"FINISHED")) ;
}
}
return hasData ;
}
/**
* 配置域转换
* @param ipList
* @param strList
* @param complexStrList
* @param numList
* @param fileList
* @param regionIds
* @param groupIds
* @param entity
* @param compileId
* @param auditTime
* @param groupRelationList
* @param ipRegionList
* @param strRegionList
* @param numRegionList
* @param digestRegionList
* @param areaIpRegionList
* @param userRegion
*/
public void configCovert ( List < IpPortCfg > ipList , List < BaseStringCfg > strList , List < ComplexkeywordCfg > complexStrList ,
List < com . nis . domain . configuration . NumBoundaryCfg > numList ,
List < FileDigestCfg > fileList , List < Integer > regionIds , List < Integer > groupIds , BaseCfg entity ,
Integer compileId , Date auditTime , List < GroupCfg > groupRelationList ,
List < IpCfg > ipRegionList ,
List < StringCfg > strRegionList ,
List < NumBoundaryCfg > numRegionList ,
List < DigestCfg > digestRegionList ,
List < IpCfg > areaIpRegionList , String userRegion ) {
List list1 = new ArrayList ( ) ;
List < BaseStringCfg > list2 = new ArrayList ( ) ;
List < ComplexkeywordCfg > list3 = new ArrayList ( ) ;
List < com . nis . domain . configuration . NumBoundaryCfg > list4 = new ArrayList ( ) ;
List < FileDigestCfg > list5 = new ArrayList ( ) ;
if ( ipList . size ( ) > 0 ) {
for ( int index = 0 ; index < ipList . size ( ) ; index + + ) {
IpPortCfg ip = ipList . get ( index ) ;
if ( ip . getCompileId ( ) . equals ( compileId ) ) {
ip . setRegionId ( regionIds . get ( 0 ) ) ;
regionIds . remove ( 0 ) ;
ip . setGroupId ( groupIds . get ( 0 ) ) ;
groupIds . remove ( 0 ) ;
ip . setIsValid ( entity . getIsValid ( ) ) ;
ip . setAuditTime ( auditTime ) ;
list1 . add ( ip ) ;
}
}
}
for ( int index = 0 ; index < strList . size ( ) ; index + + ) {
BaseStringCfg str = strList . get ( index ) ;
if ( str . getCompileId ( ) . equals ( compileId ) ) {
str . setRegionId ( regionIds . get ( 0 ) ) ;
regionIds . remove ( 0 ) ;
str . setGroupId ( groupIds . get ( 0 ) ) ;
groupIds . remove ( 0 ) ;
str . setIsValid ( entity . getIsValid ( ) ) ;
str . setAuditTime ( auditTime ) ;
list2 . add ( str ) ;
if ( entity . getServiceId ( ) . equals ( 513 ) | | entity . getServiceId ( ) . equals ( 515 ) ) {
if ( userRegion . equals ( " " ) ) {
userRegion + = Constants . USERREGION_DOMAIN_STR + " = " + str . getCfgKeywords ( ) ;
} else {
userRegion + = Constants . USER_REGION_SPLIT + Constants . USERREGION_DOMAIN_STR + " = " + str . getCfgKeywords ( ) ;
}
}
}
}
for ( int index = 0 ; index < complexStrList . size ( ) ; index + + ) {
ComplexkeywordCfg str = complexStrList . get ( index ) ;
if ( str . getCompileId ( ) . equals ( compileId ) ) {
str . setRegionId ( regionIds . get ( 0 ) ) ;
regionIds . remove ( 0 ) ;
str . setGroupId ( groupIds . get ( 0 ) ) ;
groupIds . remove ( 0 ) ;
str . setIsValid ( entity . getIsValid ( ) ) ;
str . setAuditTime ( auditTime ) ;
list3 . add ( str ) ;
if ( entity . getServiceId ( ) . equals ( 129 ) & & str . getDistrict ( ) ! = null ) { //http监测
String dictValue = DictUtils . getDictCode ( Constants . HTTP_HEADER_DICT_MODULE , str . getDistrict ( ) ) ;
if ( StringUtil . isEmpty ( dictValue ) | | dictValue . equals ( " 默认 " ) ) {
if ( userRegion . equals ( " " ) ) {
userRegion + = Constants . HTTP_HEADER_USER_REGION_KEY + " = " + str . getDistrict ( ) ;
} else {
userRegion + = Constants . USER_REGION_SPLIT + Constants . HTTP_HEADER_USER_REGION_KEY + " = " + str . getDistrict ( ) ;
}
}
}
}
}
for ( int index = 0 ; index < numList . size ( ) ; index + + ) {
com . nis . domain . configuration . NumBoundaryCfg num = numList . get ( index ) ;
if ( num . getCompileId ( ) . equals ( compileId ) ) {
num . setRegionId ( regionIds . get ( 0 ) ) ;
regionIds . remove ( 0 ) ;
num . setGroupId ( groupIds . get ( 0 ) ) ;
groupIds . remove ( 0 ) ;
num . setIsValid ( entity . getIsValid ( ) ) ;
num . setAuditTime ( auditTime ) ;
list4 . add ( num ) ;
}
}
for ( int index = 0 ; index < fileList . size ( ) ; index + + ) {
FileDigestCfg file = fileList . get ( index ) ;
if ( file . getCompileId ( ) . equals ( compileId ) ) {
file . setRegionId ( regionIds . get ( 0 ) ) ;
regionIds . remove ( 0 ) ;
file . setGroupId ( groupIds . get ( 0 ) ) ;
groupIds . remove ( 0 ) ;
file . setIsValid ( entity . getIsValid ( ) ) ;
file . setAuditTime ( auditTime ) ;
list5 . add ( file ) ;
}
}
if ( list1 . size ( ) > 0 ) {
ipList . removeAll ( list1 ) ;
Map < String , List > map = cfgToMaatConvert ( ipRegionList , list1 , 1 , groupRelationList ) ;
groupRelationList = map . get ( " groupList " ) ;
ipRegionList = map . get ( " dstList " ) ;
if ( map . get ( " numRegionList " ) ! = null ) {
numRegionList . addAll ( map . get ( " numRegionList " ) ) ;
}
}
if ( list2 . size ( ) > 0 ) {
strList . removeAll ( list2 ) ;
Map < String , List > map = cfgToMaatConvert ( strRegionList , list2 , 2 , groupRelationList ) ;
groupRelationList = map . get ( " groupList " ) ;
strRegionList = map . get ( " dstList " ) ;
}
if ( list3 . size ( ) > 0 ) {
complexStrList . removeAll ( list3 ) ;
Map < String , List > map = cfgToMaatConvert ( strRegionList , list3 , 3 , groupRelationList ) ;
groupRelationList = map . get ( " groupList " ) ;
strRegionList = map . get ( " dstList " ) ;
}
if ( list4 . size ( ) > 0 ) {
numList . removeAll ( list4 ) ;
Map < String , List > map = cfgToMaatConvert ( numRegionList , list4 , 4 , groupRelationList ) ;
groupRelationList = map . get ( " groupList " ) ;
numRegionList = map . get ( " dstList " ) ;
}
if ( list5 . size ( ) > 0 ) {
fileList . removeAll ( list5 ) ;
Map < String , List > map = cfgToMaatConvert ( digestRegionList , list5 , 5 , groupRelationList ) ;
groupRelationList = map . get ( " groupList " ) ;
digestRegionList = map . get ( " dstList " ) ;
}
}
}