@@ -5,6 +5,9 @@ import java.util.Date;
import java.util.List ;
import java.util.Map ;
import org.apache.ibatis.session.ExecutorType ;
import org.apache.ibatis.session.SqlSession ;
import org.apache.ibatis.session.SqlSessionFactory ;
import org.springframework.beans.BeanUtils ;
import org.springframework.beans.factory.annotation.Autowired ;
import org.springframework.stereotype.Service ;
@@ -24,6 +27,8 @@ import com.nis.domain.configuration.AreaIpCfg;
import com.nis.domain.configuration.IpPortCfg ;
import com.nis.domain.configuration.NtcSubscribeIdCfg ;
import com.nis.domain.configuration.WebsiteDomainTopic ;
import com.nis.domain.maat.GroupReuseAddBean ;
import com.nis.domain.maat.GroupReuseCfg ;
import com.nis.domain.maat.MaatCfg ;
import com.nis.domain.maat.MaatCfg.DigestCfg ;
import com.nis.domain.maat.MaatCfg.GroupCfg ;
@@ -32,6 +37,8 @@ import com.nis.domain.maat.MaatCfg.NumBoundaryCfg;
import com.nis.domain.maat.MaatCfg.StringCfg ;
import com.nis.domain.maat.ToMaatBean ;
import com.nis.domain.maat.ToMaatResult ;
import com.nis.domain.specific.ConfigGroupInfo ;
import com.nis.domain.specific.SpecificServiceCfg ;
import com.nis.exceptions.MaatConvertException ;
import com.nis.util.ConfigServiceUtil ;
import com.nis.util.Constants ;
@@ -41,8 +48,10 @@ import com.nis.util.StringUtils;
import com.nis.web.dao.configuration.AppCfgDao ;
import com.nis.web.dao.configuration.AreaIpCfgDao ;
import com.nis.web.dao.configuration.StringCfgDao ;
import com.nis.web.dao.specific.SpecificServiceCfgDao ;
import com.nis.web.security.UserUtils ;
import com.nis.web.service.BaseService ;
import com.nis.web.service.SpringContextHolder ;
/**
* 特定协议相关配置事务类
@@ -58,6 +67,8 @@ public class AppCfgService extends BaseService {
protected AreaIpCfgDao areaIpCfgDao ;
@Autowired
protected StringCfgDao stringcfgDao ;
@Autowired
protected SpecificServiceCfgDao specificServiceCfgDao ;
public Page < AppPolicyCfg > findAppPolicyList ( Page < AppPolicyCfg > page , AppPolicyCfg entity ) {
entity . getSqlMap ( ) . put ( " dsf " , configScopeFilter ( entity . getCurrentUser ( ) , " r " ) ) ;
@@ -289,34 +300,66 @@ public class AppCfgService extends BaseService {
setAreaEffectiveIds ( entity ) ;
if ( entity . getCfgId ( ) = = null ) {
SpecificServiceCfg specificServiceCfg = specificServiceCfgDao . getBySpecServiceId ( entity . getSpecServiceId ( ) ) ;
ConfigGroupInfo configGroupInfo = specificServiceCfgDao . 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 . setGroupType ( 1 ) ;
specificServiceCfgDao . insertConfigGroupInfo ( configGroupInfo ) ;
//更新group_id
specificServiceCfg . setOpTime ( new Date ( ) ) ;
specificServiceCfgDao . update ( specificServiceCfg ) ;
}
Integer compileId = 0 ;
try {
List < Integer > idList = ConfigServiceUtil . getId ( 1 , 1 ) ;
if ( idList ! = null & & idList . size ( ) > 0 ) {
compileId = idList . get ( 0 ) ;
}
entity . setCompileId ( compileId ) ;
entity . setCreateTime ( new Date ( ) ) ;
entity . setCreatorId ( entity . getCurrentUser ( ) . getId ( ) ) ;
entity . setIsValid ( 0 ) ;
entity . setIsAudit ( 0 ) ;
appCfgDao . insertAppIpCfg ( entity ) ;
// 保存区域IP信息
if ( entity . getAreaCfg ( ) ! = null ) {
for ( AreaIpCfg cfg : entity . getAreaCfg ( ) ) {
cfg . initDefaultValue ( ) ;
BeanUtils . copyProperties ( entity , cfg ,
new String [ ] { " cfgRegionCode " , " cfgType " , " ipType " , " isAreaEffective " ,
" areaEffectiveIds " , " protocol " , " portPattern " , " srcPort " , " destPort " ,
" direction " , " destIpAddress " , " srcIpAddress " , " ipPattern " } ) ;
areaIpCfgDao . saveAreaIpCfg ( cfg ) ;
if ( configGroupInfo . getIsIssued ( ) . intValue ( ) = = 0 ) { //没有下发过
//查询AppIpCfg对应 的未下发IP的编译ID
List < AppIpCfg > beforeCfg = appCfgDao . getAppIpCfgBySpecServiceId ( entity . getSpecServiceId ( ) ) ;
if ( beforeCfg = = null | | beforeCfg . size ( ) = = 0 ) { //第一条, 获取编译id
try {
List < Integer > idList = ConfigServiceUtil . getId ( 1 , 1 ) ;
if ( idList ! = null & & idList . size ( ) > 0 ) {
compileId = idList . get ( 0 ) ;
}
} catch ( Exception e ) {
e . printStackTrace ( ) ;
logger . info ( " 获取编译ID出错 " ) ;
throw new MaatConvertException ( e . getMessage ( ) ) ;
}
} else {
compileId = beforeCfg . get ( 0 ) . getCompileId ( ) ;
}
} else if ( configGroupInfo . getIsIssued ( ) . intValue ( ) = = 1 ) { //下发过了
List < AppIpCfg > beforeCfg = appCfgDao . getAppIpCfgBySpecServiceId ( entity . getSpecServiceId ( ) ) ;
if ( beforeCfg = = null | | beforeCfg . size ( ) = = 0 ) {
throw new RuntimeException ( " Can't get compileId, there is not app ip in an issued group " ) ;
}
compileId = beforeCfg . get ( 0 ) . getCompileId ( ) ;
} else {
throw new RuntimeException ( " Unknown configGroupInfo isIssued value " ) ;
}
entity . setUserRegion1 ( String . valueOf ( ConfigServiceUtil . getId ( 3 , 1 ) . get ( 0 ) ) ) ;
entity . setCompileId ( compileId ) ;
entity . setCreateTime ( new Date ( ) ) ;
entity . setCreatorId ( entity . getCurrentUser ( ) . getId ( ) ) ;
entity . setIsValid ( 0 ) ;
entity . setIsAudit ( 0 ) ;
appCfgDao . insertAppIpCfg ( entity ) ;
// 保存区域IP信息
if ( entity . getAreaCfg ( ) ! = null ) {
for ( AreaIpCfg cfg : entity . getAreaCfg ( ) ) {
cfg . initDefaultValue ( ) ;
BeanUtils . copyProperties ( entity , cfg ,
new String [ ] { " cfgRegionCode " , " cfgType " , " ipType " , " isAreaEffective " ,
" areaEffectiveIds " , " protocol " , " portPattern " , " srcPort " , " destPort " ,
" direction " , " destIpAddress " , " srcIpAddress " , " ipPattern " } ) ;
areaIpCfgDao . saveAreaIpCfg ( cfg ) ;
}
} catch ( Exception e ) {
e . printStackTrace ( ) ;
logger . info ( " 获取编译ID出错 " ) ;
throw new MaatConvertException ( e . getMessage ( ) ) ;
}
} else {
entity . setEditorId ( entity . getCurrentUser ( ) . getId ( ) ) ;
@@ -1003,6 +1046,157 @@ public class AppCfgService extends BaseService {
logger . info ( " app协议IP配置取消配置响应信息: " + result . getMsg ( ) ) ;
}
}
/**
* ip复用批量审核
* @param data
*/
public void auditAppIpCfg ( List < AppIpCfg > data ) {
SqlSessionFactory sqlSessionFactory = SpringContextHolder . getBean ( SqlSessionFactory . class ) ;
SqlSession batchSqlSession = null ;
try {
batchSqlSession = sqlSessionFactory . openSession ( ExecutorType . BATCH , false ) ;
for ( int index = 0 ; index < data . size ( ) ; index + + ) {
AppIpCfg t = data . get ( index ) ;
( ( AppCfgDao ) batchSqlSession . getMapper ( AppCfgDao . class ) ) . auditCfg ( t ) ;
}
batchSqlSession . commit ( ) ;
} finally {
if ( batchSqlSession ! = null ) {
batchSqlSession . close ( ) ;
}
}
}
public void auditAppIpCfg ( List < AppIpCfg > entitys , Integer isAudit ) {
MaatCfg maatCfg = new MaatCfg ( ) ;
List < MaatCfg > configCompileList = new ArrayList ( ) ;
List < GroupCfg > groupRelationList = new ArrayList ( ) ;
List < IpCfg > ipRegionList = new ArrayList ( ) ;
List < StringCfg > strRegionList = new ArrayList ( ) ;
List < NumBoundaryCfg > numRegionList = new ArrayList ( ) ;
List < DigestCfg > digestRegionList = new ArrayList ( ) ;
List < IpCfg > areaIpRegionList = new ArrayList ( ) ;
this . auditAppIpCfg ( entitys ) ;
// for(AppIpCfg entity:entitys) {
// // 保存区域IP信息
// List<AreaIpCfg> areaIpCfgList = areaIpCfgDao.getByCompileId(entitys.get(0).getCompileId());
// if (!StringUtil.isEmpty(areaIpCfgList)) {
// AreaIpCfg cfg = new AreaIpCfg();
// BeanUtils.copyProperties(entity, cfg, new String[] { "cfgId" });
// cfg.setTableName(AreaIpCfg.getTablename());
// appCfgDao.auditCfg(cfg);
// if (isAudit == 1) {
// Map<String, List> map = cfgConvert(areaIpRegionList, areaIpCfgList, 1, entity, groupRelationList);
// groupRelationList = map.get("groupList");
// areaIpRegionList = map.get("dstList");
// }
// }
// }
Integer specServiceId = entitys . get ( 0 ) . getSpecServiceId ( ) ;
SpecificServiceCfg specificServiceCfg = specificServiceCfgDao . getBySpecServiceId ( specServiceId ) ;
//String businessType=specificServiceCfg.getBusinessType();
ConfigGroupInfo configGroupInfo = specificServiceCfgDao . 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 . setGroupType ( 1 ) ;
specificServiceCfgDao . insertConfigGroupInfo ( configGroupInfo ) ;
//更新group_id
specificServiceCfg . setOpTime ( new Date ( ) ) ;
specificServiceCfgDao . update ( specificServiceCfg ) ;
}
Integer groupId = configGroupInfo . getGroupId ( ) ;
// 构造提交综合服务参数格式,一条配置提交一次综合服务
if ( isAudit = = 1 ) {
if ( configGroupInfo . getIsIssued ( ) = = 0 ) { //未下发, 下发region compile,group.
ToMaatBean maatBean = new ToMaatBean ( ) ;
maatCfg . initDefaultValue ( ) ;
//group
GroupCfg groupCfg = new GroupCfg ( ) ;
groupCfg . setCompileId ( entitys . get ( 0 ) . getCompileId ( ) ) ;
groupCfg . setGroupId ( groupId ) ;
groupCfg . setIsValid ( Constants . VALID_YES ) ;
groupCfg . setAuditTime ( entitys . get ( 0 ) . 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 ) ;
// 调用服务接口下发配置数据
String json = gsonToJson ( maatBean ) ;
logger . info ( " app协议IP配置下发配置参数: " + json ) ;
// 调用服务接口下发配置
ToMaatResult result = ConfigServiceUtil . postMaatCfg ( json ) ;
logger . info ( " app协议IP配置下发响应信息: " + result . getMsg ( ) ) ;
configGroupInfo . setIsIssued ( 1 ) ;
configGroupInfo . setUpdateTime ( new Date ( ) ) ;
specificServiceCfgDao . updateConfigGroupInfobyGroupId ( configGroupInfo ) ;
} else if ( configGroupInfo . getIsIssued ( ) = = 1 ) { //已经下发,分组复用下发
GroupReuseAddBean maatBean = new GroupReuseAddBean ( ) ;
List < GroupReuseCfg > groupReuseList = new ArrayList < > ( ) ;
GroupReuseCfg groupReuseCfg = new GroupReuseCfg ( ) ;
ipRegionList . addAll ( groupReuseCfgAddRemoveConvert ( entitys , Constants . VALID_YES , groupId ) ) ;
groupReuseCfg . setIpRegionList ( ipRegionList ) ;
groupReuseCfg . setStrRegionList ( strRegionList ) ;
groupReuseCfg . setNumRegionList ( numRegionList ) ;
groupReuseList . add ( groupReuseCfg ) ;
maatBean . setGroupReuseCfgList ( groupReuseList ) ;
maatBean . setAuditTime ( entitys . get ( 0 ) . getAuditTime ( ) ) ;
maatBean . setCreatorName ( entitys . get ( 0 ) . getCurrentUser ( ) . getName ( ) ) ;
maatBean . setVersion ( Constants . MAAT_VERSION ) ;
maatBean . setOpAction ( Constants . INSERT_ACTION ) ;
//调用服务接口下发配置数据
String json = gsonToJson ( maatBean ) ;
logger . info ( " app协议IP域新增配置下发配置参数: " + json ) ;
//调用服务接口下发配置
ToMaatResult result = ConfigServiceUtil . postGroupReuseSources ( json ) ;
logger . info ( " app协议IP域新增配置响应信息: " + result . getMsg ( ) ) ;
} else {
throw new RuntimeException ( " Unknown configGroupInfo isIssued value " ) ;
}
} else if ( isAudit = = 3 ) {
//已经下发过的,调用分组复用配置删除接口
GroupReuseAddBean maatBean = new GroupReuseAddBean ( ) ;
List < GroupReuseCfg > groupReuseList = new ArrayList < > ( ) ;
GroupReuseCfg groupReuseCfg = new GroupReuseCfg ( ) ;
ipRegionList . addAll ( groupReuseCfgAddRemoveConvert ( entitys , Constants . VALID_NO , groupId ) ) ;
groupReuseCfg . setIpRegionList ( ipRegionList ) ;
groupReuseCfg . setStrRegionList ( strRegionList ) ;
groupReuseCfg . setNumRegionList ( numRegionList ) ;
groupReuseList . add ( groupReuseCfg ) ;
maatBean . setGroupReuseCfgList ( groupReuseList ) ;
maatBean . setAuditTime ( entitys . get ( 0 ) . getAuditTime ( ) ) ;
maatBean . setCreatorName ( entitys . get ( 0 ) . getCurrentUser ( ) . getName ( ) ) ;
maatBean . setVersion ( Constants . MAAT_VERSION ) ;
maatBean . setOpAction ( Constants . UPDATE_ACTION ) ;
//调用服务接口下发配置数据
String json = gsonToJson ( maatBean ) ;
logger . info ( " app协议IP域删除配置下发配置参数: " + json ) ;
//调用服务接口下发配置
ToMaatResult result = ConfigServiceUtil . put ( json , 3 ) ;
logger . info ( " app协议IP域删除配置响应信息: " + result . getMsg ( ) ) ;
}
}
public void auditAppHttpCfg ( AppHttpCfg entity , Integer isAudit ) {
ToMaatBean maatBean = new ToMaatBean ( ) ;