策略组group id region id 不固定版本

This commit is contained in:
wangxin
2019-07-25 20:53:11 +08:00
parent d2d52b0b13
commit e37128e2c8

View File

@@ -575,6 +575,25 @@ public class ConfigConvertUtil {
dstIp.setDstPortMask("65535");
}
}
private static <T> Map<Integer,Integer> getGroupIdList(List<T> srcList){
Set<Integer> groupIdSet=new HashSet<>();
Map<Integer,Integer> groupIdMap=new HashMap<>();
for(T src:srcList){
BaseCfg cfg=(BaseCfg)src;
if(!groupIdSet.contains(cfg.getGroupId())){
groupIdSet.add(cfg.getGroupId());
}
}
if(groupIdSet.size()>0){
List<Integer> groupIds= ConfigServiceUtil.getId(2,groupIdSet.size());
for(Integer id:groupIdSet){
groupIdMap.put(id,groupIds.get(0));
}
groupIds.remove(0);
}
return groupIdMap;
}
/**
*Obj 组maat配置转换
* @param <T>
@@ -591,6 +610,7 @@ public class ConfigConvertUtil {
List groupRelationList, Map<String,Object> maatTableMap, Set<Integer> groupIdSet) {
long start=System.currentTimeMillis(),end=0l;
Map<String, List> map = new HashMap();
Map<Integer,Integer> groupIdMap=getGroupIdList(srcList);
if (cfgType == 1) {
List numRegionList = new ArrayList();
int pos=0;
@@ -607,15 +627,17 @@ public class ConfigConvertUtil {
if (!groupIdSet.contains(baseIpCfg.getGroupId())) {
GroupCfg group = new GroupCfg();
//groupId = ConfigServiceUtil.getId(2, 1).get(0);
group.setGroupId(baseIpCfg.getGroupId());
// group.setGroupId(baseIpCfg.getGroupId());
Integer groupId =groupIdMap.get(baseIpCfg.getGroupId());
group.setGroupId(groupId);
group.setCompileId(baseCfg.getCompileId());
group.setAuditTime(baseCfg.getAuditTime());
group.setIsValid(baseCfg.getIsValid());
groupRelationList.add(group);
groupIdSet.add(baseIpCfg.getGroupId());
}
cfg.setGroupId(baseIpCfg.getGroupId());
// cfg.setGroupId(baseIpCfg.getGroupId());
cfg.setGroupId(groupIdMap.get(baseIpCfg.getGroupId()));
cfg.setAuditTime(baseCfg.getAuditTime());
cfg.setIsValid(baseCfg.getIsValid());
if(maatTableMap.containsKey("ipMaatTable")){
@@ -623,11 +645,11 @@ public class ConfigConvertUtil {
cfg.setCfgType(ipMaatTable.get(baseIpCfg.getGroupId().toString()));
}
List<IpCfg> cfgs = ipConvert(cfg, baseIpCfg);
if (cfgs.size() > 1) {
if (cfgs.size() > 0) {
List<Integer> ids =regionIdList.subList(pos,pos+cfgs.size());
//支持range????
for (int j = 1; j < cfgs.size(); j++) {
cfgs.get(j).setRegionId(ids.get(j-1));
for (int j = 0; j < cfgs.size(); j++) {
cfgs.get(j).setRegionId(ids.get(j));
}
pos+=cfgs.size();
}
@@ -665,13 +687,15 @@ public class ConfigConvertUtil {
regionIdList.clear();
} else if (cfgType == 2 || cfgType == 3) {
// List<Integer> groupIdList = ConfigServiceUtil.getId(2, srcList.size());
//List<Integer> regionIdList = ConfigServiceUtil.getId(3, srcList.size());
List<Integer> regionIdList = ConfigServiceUtil.getId(3, srcList.size());
for (int i = 0; i < srcList.size(); i++) {
BaseStringCfg baserStringCfg=new BaseStringCfg();
BeanUtils.copyProperties(srcList.get(i),baserStringCfg);
if(!groupIdSet.contains(baserStringCfg.getGroupId())){
GroupCfg group = new GroupCfg();
group.setGroupId(baserStringCfg.getGroupId());
// group.setGroupId(baserStringCfg.getGroupId());
Integer groupId =groupIdMap.get(baserStringCfg.getGroupId());
group.setGroupId(groupId);
group.setCompileId(baseCfg.getCompileId());
group.setAuditTime(baseCfg.getAuditTime());
group.setIsValid(baseCfg.getIsValid());
@@ -680,8 +704,10 @@ public class ConfigConvertUtil {
}
StringCfg cfg = new StringCfg();
BeanUtils.copyProperties(srcList.get(i), cfg);
cfg.setGroupId(baserStringCfg.getGroupId());
cfg.setRegionId(baserStringCfg.getRegionId());
// cfg.setGroupId(baserStringCfg.getGroupId());
// cfg.setRegionId(baserStringCfg.getRegionId());
cfg.setGroupId(groupIdMap.get(baserStringCfg.getGroupId()));
cfg.setRegionId(regionIdList.get(i));
cfg.setAuditTime(baseCfg.getAuditTime());
cfg.setIsValid(baseCfg.getIsValid());
// 处理配置关键字转译
@@ -696,44 +722,52 @@ public class ConfigConvertUtil {
}
} else if (cfgType == 4) {
// List<Integer> groupIdList = ConfigServiceUtil.getId(2, srcList.size());
// List<Integer> regionIdList = ConfigServiceUtil.getId(3, srcList.size());
List<Integer> regionIdList = ConfigServiceUtil.getId(3, srcList.size());
for (int i = 0; i < srcList.size(); i++) {
// 一条业务配置创建一个分组
NumBoundaryCfg cfg = new NumBoundaryCfg();
BeanUtils.copyProperties(srcList.get(i), cfg);
if(!groupIdSet.contains(cfg.getGroupId())){
GroupCfg group = new GroupCfg();
group.setGroupId(cfg.getGroupId());
// group.setGroupId(cfg.getGroupId());
Integer groupId =groupIdMap.get(cfg.getGroupId());
group.setGroupId(groupId);
group.setCompileId(baseCfg.getCompileId());
group.setAuditTime(baseCfg.getAuditTime());
group.setIsValid(baseCfg.getIsValid());
groupRelationList.add(group);
groupIdSet.add(cfg.getGroupId());
}
cfg.setGroupId(cfg.getGroupId());
cfg.setRegionId(cfg.getRegionId());
// cfg.setGroupId(cfg.getGroupId());
// cfg.setRegionId(cfg.getRegionId());
cfg.setGroupId(groupIdMap.get(cfg.getGroupId()));
cfg.setRegionId(regionIdList.get(i));
cfg.setAuditTime(baseCfg.getAuditTime());
cfg.setIsValid(baseCfg.getIsValid());
dstList.add(cfg);
}
} else if (cfgType == 5) {
//List<Integer> groupIdList = ConfigServiceUtil.getId(2, srcList.size());
//List<Integer> regionIdList = ConfigServiceUtil.getId(3, srcList.size());
List<Integer> regionIdList = ConfigServiceUtil.getId(3, srcList.size());
for (int i = 0; i < srcList.size(); i++) {
// 一条业务配置创建一个分组
com.nis.domain.maat.MaatCfg.DigestCfg cfg = new com.nis.domain.maat.MaatCfg.DigestCfg();
BeanUtils.copyProperties(srcList.get(i), cfg);
if(!groupIdSet.contains(cfg.getGroupId())){
GroupCfg group = new GroupCfg();
group.setGroupId(cfg.getGroupId());
// group.setGroupId(cfg.getGroupId());
Integer groupId =groupIdMap.get(cfg.getGroupId());
group.setGroupId(groupId);
group.setCompileId(baseCfg.getCompileId());
group.setAuditTime(baseCfg.getAuditTime());
group.setIsValid(baseCfg.getIsValid());
groupRelationList.add(group);
groupIdSet.add(cfg.getGroupId());
}
cfg.setGroupId(cfg.getGroupId());
cfg.setRegionId(cfg.getRegionId());
// cfg.setGroupId(cfg.getGroupId());
// cfg.setRegionId(cfg.getRegionId());
cfg.setGroupId(groupIdMap.get(cfg.getGroupId()));
cfg.setRegionId(regionIdList.get(i));
cfg.setAuditTime(baseCfg.getAuditTime());
cfg.setIsValid(baseCfg.getIsValid());
dstList.add(cfg);
@@ -986,7 +1020,7 @@ public class ConfigConvertUtil {
}
}
//拆分IP数量大于1获取ID
if(total>1){
if(total>0){
regionIdsList=ConfigServiceUtil.getId(3,total);
}