优化asn ip导入,减少循环次数,减少调用综合服务接口次数

This commit is contained in:
wangxin
2018-11-05 19:03:15 +08:00
parent 0607a68a38
commit b64d26e7f6
3 changed files with 20 additions and 17 deletions

View File

@@ -60,15 +60,6 @@ public class AsnIpCfgService extends CrudService<CrudDao<AsnIpCfg>, AsnIpCfg> {
}
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
public void save(List<AsnIpCfg> entitys){
Date createTime=new Date();
List<Integer> idList=ConfigServiceUtil.getId(3, entitys.size());
int index=0;
for(AsnIpCfg entity:entitys) {
entity.setCreateTime(createTime);
entity.setCreatorId(entity.getCurrentUser().getId());
entity.setRegionId(idList.get(index));
index++;
}
this.saveBatch(entitys, AsnIpCfgDao.class);
}
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
@@ -88,10 +79,12 @@ public class AsnIpCfgService extends CrudService<CrudDao<AsnIpCfg>, AsnIpCfg> {
}
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
public void saveAsnIpBatch(Map<String,List<AsnIpCfg>> cfgs) {
public void saveAsnIpBatch(Map<String,List<AsnIpCfg>> cfgs,int total) {
List<AsnIpCfg> toDelAsnIpCfgs=Lists.newArrayList();
List<AsnIpCfg> toSaveAsnIpCfgs=Lists.newArrayList();
List<SysDataDictionaryItem> isImportAll=DictUtils.getDictList("IS_ASN_IP_IMPORT_ALL");
List<Integer> idList=ConfigServiceUtil.getId(3, total);
int ind=0;
for(Entry<String,List<AsnIpCfg>> entry:cfgs.entrySet()) {
Long asnNo=Long.parseLong(entry.getKey());
ConfigGroupInfo configGroupInfo=this.getConfigGroupInfoByAsnNo(asnNo);
@@ -101,15 +94,17 @@ public class AsnIpCfgService extends CrudService<CrudDao<AsnIpCfg>, AsnIpCfg> {
info.setDescription("Create by import excel");
info.setGroupName("Import"+asnNo);
info.setGroupType(4);
this.saveAsnGroup(info);
configGroupInfo=this.getConfigGroupInfoByAsnNo(asnNo);
configGroupInfo=this.saveAsnGroup(info);
}
for(AsnIpCfg cfg:entry.getValue()) {
cfg.setAsnIpGroup(configGroupInfo.getGroupId());
cfg.setRegionId(idList.get(ind));
if(configGroupInfo.getIsIssued()==0)
cfg.setIsValid(Constants.VALID_NO);
else
else {
cfg.setIsValid(Constants.VALID_YES);
}
ind++;
}
if(isImportAll.get(0).getItemCode().equals("1")) {//全量下发,删除已有的
if(configGroupInfo.getIsIssued()==1) {//已下发
@@ -166,8 +161,9 @@ public class AsnIpCfgService extends CrudService<CrudDao<AsnIpCfg>, AsnIpCfg> {
}
}
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
public void saveAsnGroup(PolicyGroupInfo entity) throws MaatConvertException{
public ConfigGroupInfo saveAsnGroup(PolicyGroupInfo entity) throws MaatConvertException{
entity.setIsValid(1);
ConfigGroupInfo group=new ConfigGroupInfo();
//新增
Date createTime=new Date();
entity.setCreatorId(UserUtils.getUser().getId());
@@ -183,7 +179,6 @@ public class AsnIpCfgService extends CrudService<CrudDao<AsnIpCfg>, AsnIpCfg> {
}
entity.setServiceGroupId(serviceGroupId);
//新增协议分组
ConfigGroupInfo group = new ConfigGroupInfo();
group.setGroupId(serviceGroupId);
group.setGroupName(entity.getGroupName());
group.setIsIssued(0);
@@ -192,7 +187,7 @@ public class AsnIpCfgService extends CrudService<CrudDao<AsnIpCfg>, AsnIpCfg> {
specificServiceCfgDao.insertConfigGroupInfo(group);
policyGroupInfoDao.insert(entity);
}
return group;
}
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
public void saveAsnIpCfg(CfgIndexInfo entity) {
@@ -201,6 +196,8 @@ public class AsnIpCfgService extends CrudService<CrudDao<AsnIpCfg>, AsnIpCfg> {
if(groupInfo==null) {
throw new RuntimeException("ConfigGroupInfo is null!");
}
List<Integer> idList=ConfigServiceUtil.getId(3, entity.getAsnIpCfgs().size());
int index=0;
if(groupInfo.getIsIssued()==1) {//如果已经下发,则需要下到综合服务中
if(entity.getAsnIpCfgs()!=null) {
for(AsnIpCfg cfg:entity.getAsnIpCfgs()) {
@@ -214,6 +211,8 @@ public class AsnIpCfgService extends CrudService<CrudDao<AsnIpCfg>, AsnIpCfg> {
cfg.setCreatorId(entity.getCurrentUser().getId());
cfg.setAsnIpGroup(entity.getAsnIpGroup());
cfg.setIsValid(Constants.VALID_YES);
cfg.setRegionId(idList.get(index));
index++;
}
}
this.save(entity.getAsnIpCfgs());
@@ -226,6 +225,8 @@ public class AsnIpCfgService extends CrudService<CrudDao<AsnIpCfg>, AsnIpCfg> {
cfg.setCreatorId(entity.getCurrentUser().getId());
cfg.setAsnIpGroup(entity.getAsnIpGroup().intValue());
cfg.setIsValid(Constants.VALID_NO);
cfg.setRegionId(idList.get(index));
index++;
}
}
this.save(entity.getAsnIpCfgs());