@@ -3,6 +3,7 @@ package com.nis.web.service.configuration;
import java.lang.reflect.Field ;
import java.util.ArrayList ;
import java.util.Date ;
import java.util.HashMap ;
import java.util.List ;
import java.util.Map ;
@@ -24,6 +25,7 @@ import com.nis.domain.FunctionServiceDict;
import com.nis.domain.Page ;
import com.nis.domain.basics.AsnIpCfg ;
import com.nis.domain.configuration.AppFeatureIndex ;
import com.nis.domain.configuration.AppIpCfg ;
import com.nis.domain.configuration.AppPolicyCfg ;
import com.nis.domain.configuration.AvFileSampleCfg ;
import com.nis.domain.configuration.BaseCfg ;
@@ -46,6 +48,8 @@ import com.nis.domain.maat.MaatCfg.GroupCfg;
import com.nis.domain.maat.MaatCfg.IpCfg ;
import com.nis.domain.maat.MaatCfg.NumBoundaryCfg ;
import com.nis.domain.maat.MaatCfg.StringCfg ;
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.DateUtils ;
@@ -54,6 +58,8 @@ import com.nis.util.ServiceConfigTemplateUtil;
import com.nis.util.StringUtil ;
import com.nis.web.dao.configuration.CommonPolicyDao ;
import com.nis.web.dao.configuration.ConfigSynchronizationDao ;
import com.nis.web.dao.specific.ConfigGroupInfoDao ;
import com.nis.web.dao.specific.SpecificServiceCfgDao ;
import com.nis.web.security.UserUtils ;
import com.nis.web.service.BaseService ;
@@ -68,6 +74,10 @@ public class ConfigSynchronizationService extends BaseService{
protected ConfigSynchronizationDao configSynchronizationDao ;
@Autowired
protected CommonPolicyDao commonPolicyDao ;
@Autowired
protected SpecificServiceCfgDao specificServiceCfgDao ;
@Autowired
protected ConfigGroupInfoDao configGroupInfoDao ;
/**
* 配置全量更新下发
* @param request
@@ -1107,15 +1117,25 @@ public class ConfigSynchronizationService extends BaseService{
entity . setPage ( page ) ;
List list = Lists . newArrayList ( ) ;
if ( cfgType = = 1 ) {
list = configSynchronizationDao . getIpPortListByService ( entity ) ;
if ( entity . getServiceId ( ) . equals ( 1028 ) ) {
list = configSynchronizationDao . getAppIpFeatureList ( entity ) ;
} else {
list = configSynchronizationDao . getIpPortListByService ( entity ) ;
}
} else if ( cfgType = = 2 ) {
list = configSynchronizationDao . getStrListByService ( entity ) ;
} else if ( cfgType = = 3 ) {
list = configSynchronizationDao . getComplexStrListByService ( entity ) ;
}
if ( ! StringUtil . isEmpty ( list ) ) {
hasData = auditSingleMaatData ( cfgType , userRegionList ,
page , entity , list , has Data, isUpdateCfg ) ;
if ( entity . getServiceId ( ) . equals ( 1028 ) ) {
hasData = auditAppIp Data( userRegionList ,
page , entity , list , hasData , isUpdateCfg ) ;
} else {
hasData = auditSingleMaatData ( cfgType , userRegionList ,
page , entity , list , hasData , isUpdateCfg ) ;
}
if ( hasData ) {
page . setPageNo ( page . getNext ( ) ) ;
}
@@ -1155,9 +1175,6 @@ public class ConfigSynchronizationService extends BaseService{
List < NumBoundaryCfg > numRegionList ;
List < DigestCfg > digestRegionList ;
List < IpCfg > areaIpRegionList ;
List < IpPortCfg > ipList = new ArrayList ( ) ;
maatBean = new ToMaatBean ( ) ;
configCompileList = new ArrayList ( ) ;
//批量获取regionId,groupId
@@ -1211,7 +1228,6 @@ public class ConfigSynchronizationService extends BaseService{
}
list1 . add ( cfg ) ;
if ( list1 . size ( ) > 0 ) {
ipList . removeAll ( list1 ) ;
Map < String , List > map = cfgToMaatConvert ( ipRegionList , list1 , 1 , groupRelationList ) ;
groupRelationList = map . get ( " groupList " ) ;
ipRegionList = map . get ( " dstList " ) ;
@@ -1294,8 +1310,6 @@ public class ConfigSynchronizationService extends BaseService{
List < DigestCfg > digestRegionList ;
List < IpCfg > areaIpRegionList ;
List cfgList = new ArrayList ( ) ;
maatBean = new ToMaatBean ( ) ;
configCompileList = new ArrayList ( ) ;
//批量获取regionId,groupId
@@ -1314,8 +1328,8 @@ 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. 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 ( ) ;
@@ -1346,7 +1360,6 @@ public class ConfigSynchronizationService extends BaseService{
} else if ( cfgType = = 3 ) {
aClass = ComplexkeywordCfg . class ;
}
}
Object value = " " ;
Field field = aClass . getDeclaredField ( regionColumn ) ;
@@ -1393,7 +1406,6 @@ public class ConfigSynchronizationService extends BaseService{
}
if ( list1 . size ( ) > 0 ) {
cfgList . removeAll ( list1 ) ;
if ( cfgType = = 1 ) {
Map < String , List > map = cfgToMaatConvert ( ipRegionList , list1 , 1 , groupRelationList ) ;
groupRelationList = map . get ( " groupList " ) ;
@@ -1451,26 +1463,121 @@ public class ConfigSynchronizationService extends BaseService{
return hasData ;
}
/**
* 处理app业务maat类 配置
* 处理app ip特征( 分组复用) 配置
* @param serviceId
* @param request
* @param response
*/
public void handleAppMaatData ( List < Map < String , Object > > cfgList , List < Map < String , Object > > userRegionList ,
Page < BaseCfg > page , Object entity , HttpServletRequest request , HttpServletResponse response ) {
/*if(entity instanceof AppPolicyCfg){
AppPolicyCfg newEntity = entity;
entity.setPage(page);
}
public boolean auditAppIpData ( List < Map < String , Object > > userRegionList ,
Page < T > page ,
BaseCfg entity ,
List < T > list ,
boolean hasData ,
boolean isUpdateCfg ) throws NoSuchFieldException , SecurityException , IllegalArgumentException , IllegalAccessException {
boolean hasData = true;
while(hasData){
List<CfgIndexInfo> list = configSynchronizationDao.getCfgIndexList(entity);
page.setList(list);
if(page.isLastPage()){
hasData = false;
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 ;
maatBean = new ToMaatBean ( ) ;
configCompileList = new ArrayList ( ) ;
//同一编译IP的分组
Map < Integer , List < AppIpCfg > > dataMap = new HashMap < > ( ) ;
for ( int i = 0 ; i < list . size ( ) ; i + + ) {
AppIpCfg cfg = new AppIpCfg ( ) ;
BeanUtils . copyProperties ( list . get ( i ) , cfg ) ;
cfg . setIsValid ( entity . getIsValid ( ) ) ;
cfg . setAuditTime ( StringUtil . isEmpty ( entity . getAuditTime ( ) ) ? cfg . getAuditTime ( ) : entity . getAuditTime ( ) ) ;
if ( dataMap . containsKey ( cfg . getCompileId ( ) ) ) {
dataMap . get ( cfg . getCompileId ( ) ) . add ( cfg ) ;
} else {
List < AppIpCfg > ipList = new ArrayList < > ( ) ;
ipList . add ( cfg ) ;
dataMap . put ( cfg . getCompileId ( ) , ipList ) ;
}
}*/
}
for ( List < AppIpCfg > entitys : dataMap . values ( ) ) {
maatCfg = new MaatCfg ( ) ;
maatCfg . initDefaultValue ( ) ;
groupRelationList = new ArrayList ( ) ;
ipRegionList = new ArrayList ( ) ;
strRegionList = new ArrayList ( ) ;
numRegionList = new ArrayList ( ) ;
digestRegionList = new ArrayList ( ) ;
areaIpRegionList = new ArrayList ( ) ;
SpecificServiceCfg specificServiceCfg = specificServiceCfgDao . getBySpecServiceId ( entitys . get ( 0 ) . getSpecServiceId ( ) ) ;
ConfigGroupInfo configGroupInfo = configGroupInfoDao . getConfigGroupInfoByGroupId ( specificServiceCfg . getGroupId ( ) ) ;
/*if(configGroupInfo==null) {
Integer groupId = ConfigServiceUtil.getId(2, 1).get(0);
specificServiceCfg.setGroupId(groupId);
configGroupInfo = new ConfigGroupInfo();
configGroupInfo.setGroupId(specificServiceCfg.getGroupId());
configGroupInfo.setGroupName(specificServiceCfg.getSpecServiceName());
configGroupInfo.setIsIssued(0);
configGroupInfo.setCompileId(entitys.get(0).getCompileId());
configGroupInfo.setGroupType(1);
configGroupInfoDao.insertConfigGroupInfo(configGroupInfo);
//更新group_id
specificServiceCfg.setOpTime(new Date());
specificServiceCfgDao.update(specificServiceCfg);
}*/
Integer groupId = configGroupInfo . getGroupId ( ) ;
GroupCfg groupCfg = new GroupCfg ( ) ;
groupCfg . setCompileId ( entitys . get ( 0 ) . getCompileId ( ) ) ;
groupCfg . setGroupId ( groupId ) ;
groupCfg . setIsValid ( Constants . VALID_YES ) ;
groupCfg . setAuditTime ( StringUtil . isEmpty ( entity . getAuditTime ( ) ) ? entitys . get ( 0 ) . getAuditTime ( ) : entity . getAuditTime ( ) ) ;
groupRelationList . add ( groupCfg ) ;
BeanUtils . copyProperties ( entitys . get ( 0 ) , maatCfg ) ;
ipRegionList . addAll ( groupReuseCfgAddRemoveConvert ( entitys , Constants . VALID_YES , groupId ) ) ;
maatCfg . setAction ( entitys . get ( 0 ) . getAction ( ) ) ;
maatCfg . setAuditTime ( entitys . get ( 0 ) . 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 ( entitys . get ( 0 ) . getIsValid ( ) ) ;
// 设置APP自定义域
String userRegion = " APP_ID= " + entitys . get ( 0 ) . getAppCode ( ) /*+Constants.USER_REGION_SPLIT+"ASEV_ID="+businessType*/ ;
maatCfg . setUserRegion ( userRegion ) ;
configCompileList . add ( maatCfg ) ;
maatBean . setConfigCompileList ( configCompileList ) ;
maatBean . setAuditTime ( entitys . get ( 0 ) . getAuditTime ( ) ) ;
maatBean . setCreatorName ( entitys . get ( 0 ) . getCurrentUser ( ) . getName ( ) ) ;
maatBean . setVersion ( Constants . MAAT_VERSION ) ;
maatBean . setOpAction ( Constants . INSERT_ACTION ) ;
}
page . setList ( list ) ;
if ( page . isLastPage ( ) ) {
hasData = false ;
}
if ( ! StringUtil . isEmpty ( configCompileList . size ( ) ) ) {
String json = gsonToJson ( maatBean ) ;
//调用服务接口下发配置数据
if ( isUpdateCfg ) {
logger . info ( " 配置批量下发: " + json ) ;
//调用服务接口同步回调类配置
ToMaatResult result = ConfigServiceUtil . postMaatCfg ( json ) ;
if ( result ! = null ) {
logger . info ( " 配置批量下发响应信息: " + result . getMsg ( ) ) ;
}
} else {
//调用服务接口配置全量更新
// JSONObject result = ConfigServiceUtil.configSync(json,1,entity.getServiceId(),null,(hasData?null:"FINISHED"));
}
}
return hasData ;
}
/**