asn 相关修改提交

(1)asn_ip_cfg增加四列
(2)新增asn_group_info表
(3)asn ip菜单移动到policy object下,新增审核审计菜单
(4)asn ip导入修改,适应新的需求放弃了使用AsnCache,直接从数据库查
(5)asn ip加入审核流程
(6)Packet IP选择asn时,改为选中一个组织,审核下发的配置为as号字符串域
(7)asn ip 新增业务新增function_service_dict字典,serviceId为400
This commit is contained in:
wangxin
2019-01-04 18:28:57 +06:00
parent 429b1841f1
commit 85507b5a55
44 changed files with 2596 additions and 767 deletions

View File

@@ -1,16 +1,16 @@
package com.nis.web.service.basics;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.Set;
import org.apache.commons.lang3.StringUtils;
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;
@@ -18,27 +18,29 @@ import org.springframework.transaction.annotation.Transactional;
import com.beust.jcommander.internal.Lists;
import com.nis.domain.Page;
import com.nis.domain.basics.AsnGroupInfo;
import com.nis.domain.basics.AsnIpCfg;
import com.nis.domain.basics.PolicyGroupInfo;
import com.nis.domain.basics.Varibles;
import com.nis.domain.configuration.BaseIpCfg;
import com.nis.domain.configuration.CfgIndexInfo;
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;
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.maat.ToMaatBean;
import com.nis.domain.maat.ToMaatResult;
import com.nis.domain.specific.ConfigGroupInfo;
import com.nis.exceptions.MaatConvertException;
import com.nis.util.AsnCacheUtils;
import com.nis.util.ConfigServiceUtil;
import com.nis.util.Constants;
import com.nis.web.dao.CrudDao;
import com.nis.web.dao.basics.AsnGroupInfoDao;
import com.nis.web.dao.basics.AsnIpCfgDao;
import com.nis.web.dao.basics.PolicyGroupInfoDao;
import com.nis.web.dao.configuration.IpCfgDao;
import com.nis.web.dao.specific.ConfigGroupInfoDao;
import com.nis.web.security.UserUtils;
import com.nis.web.service.CrudService;
import com.nis.web.service.SpringContextHolder;
@Service
public class AsnIpCfgService extends CrudService<CrudDao<AsnIpCfg>, AsnIpCfg> {
@Autowired
@@ -48,7 +50,7 @@ public class AsnIpCfgService extends CrudService<CrudDao<AsnIpCfg>, AsnIpCfg> {
@Autowired
private ConfigGroupInfoDao configGroupInfoDao;
@Autowired
private PolicyGroupInfoDao policyGroupInfoDao;
private AsnGroupInfoDao asnGroupInfoDao;
/**
* @param page
* @param entity
@@ -66,41 +68,32 @@ public class AsnIpCfgService extends CrudService<CrudDao<AsnIpCfg>, AsnIpCfg> {
List<AsnIpCfg> list=asnIpCfgDao.findByPage(ids);
return list;
}
public boolean hasValidAsnIp(Long asnId) {
return asnIpCfgDao.hasValidAsnIp(asnId)>0;
}
public AsnIpCfg get(Long id ) {
return asnIpCfgDao.get(id);
}
// public void save(List<AsnIpCfg> entitys){
// this.saveBatch(entitys, AsnIpCfgDao.class);
// }
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
public void save(List<AsnIpCfg> entitys) {
logger.warn("Start to save IP,size:"+entitys.size());
long start=System.currentTimeMillis();
int len=0;
List<AsnIpCfg> tempList=Lists.newArrayList();
// Varibles maxPacket=asnIpCfgDao.getVaribles("max_allowed_packet");
for(AsnIpCfg asnIpCfg:entitys) {
int tempLen=asnIpCfg.toString().getBytes(Charset.forName("UTF-8")).length;
if((len+tempLen)<Constants.MAX_ALLOWED_PACKET) {
tempList.add(asnIpCfg);
len+=tempLen;
}else {
// logger.warn("save ip size:"+tempList.size());
asnIpCfgDao.insertBatch(tempList);
tempList.clear();
tempList.add(asnIpCfg);
len=tempLen;
}
}
if(tempList.size()>0) {
// logger.warn("save ip size:"+tempList.size());
asnIpCfgDao.insertBatch(tempList);
tempList.clear();
}
// entitys.clear();
SqlSessionFactory sqlSessionFactory=SpringContextHolder.getBean(SqlSessionFactory.class);
SqlSession batchSqlSession = null;
try{
batchSqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, false);
for(AsnIpCfg asnIpCfg:entitys) {
((AsnIpCfgDao) batchSqlSession.getMapper(AsnIpCfgDao.class)).insert(asnIpCfg);
}
batchSqlSession.commit();
}finally {
if(batchSqlSession != null){
batchSqlSession.close();
}
}
long end=System.currentTimeMillis();
logger.warn("Save IP finish,cost:"+(end-start));
}
@@ -109,122 +102,133 @@ public class AsnIpCfgService extends CrudService<CrudDao<AsnIpCfg>, AsnIpCfg> {
Date editTime=new Date();
entity.setEditTime(editTime);
entity.setEditorId(entity.getCurrentUser().getId());
if(entity.getAsnIpGroup()==null) {
throw new RuntimeException("asn group name not found!");
}
ConfigGroupInfo groupInfo=configGroupInfoDao.getConfigGroupInfoByGroupId(entity.getAsnIpGroup());
if(groupInfo.getIsIssued()==0) {//未下发,可修改
asnIpCfgDao.update(entity);
}else {
throw new RuntimeException("asn group is issued, cannot update asn ip!");
}
String org=entity.getOrganization().trim();
String country=entity.getCountry().trim();
String detail=entity.getDetail().trim();
entity.setOrganization(org);
entity.setCountry(country);
entity.setDetail(detail);
asnIpCfgDao.update(entity);
}
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
public void processGroup(Map<Long,Integer> asnNoMap){
public void processGroup(Map<Long,AsnGroupInfo> asnNoMap){
logger.warn("Start to save group");
long start=System.currentTimeMillis();
List<PolicyGroupInfo> policyGroupInfos=Lists.newArrayList();
List<ConfigGroupInfo> configGroupInfoS=Lists.newArrayList();
Date createTime=new Date();
int len=0,len1=0;
// Varibles maxPacket=asnIpCfgDao.getVaribles("max_allowed_packet");
for(Entry<Long, Integer> e:asnNoMap.entrySet()) {
PolicyGroupInfo info=new PolicyGroupInfo();
info.setAsnNo(e.getKey());
info.setDescription("Create by import excel");
info.setGroupName("Import"+e.getKey());
info.setGroupType(4);
info.setServiceGroupId(asnNoMap.get(e.getKey()));
info.setIsValid(1);
info.setCreatorId(UserUtils.getUser().getId());
info.setCreateTime(createTime);
int tempLen=info.toString().getBytes(Charset.forName("UTF-8")).length;
if((len+tempLen)<Constants.MAX_ALLOWED_PACKET) {
policyGroupInfos.add(info);
len+=tempLen;
}else {
policyGroupInfoDao.insertBatch(policyGroupInfos);
policyGroupInfos.clear();
policyGroupInfos.add(info);
len=tempLen;
}
ConfigGroupInfo group=new ConfigGroupInfo();
group.setGroupId(info.getServiceGroupId());
group.setGroupName(info.getGroupName());
group.setIsIssued(0);
group.setGroupType(info.getGroupType());
group.setAsnId(info.getAsnNo());
int tempLen1=group.toString().getBytes(Charset.forName("UTF-8")).length;
if((len1+tempLen1)<Constants.MAX_ALLOWED_PACKET) {
configGroupInfoS.add(group);
len1+=tempLen1;
}else {
configGroupInfoDao.insertBatch(configGroupInfoS);
configGroupInfoS.clear();
configGroupInfoS.add(group);
len1=tempLen1;
}
}
if(policyGroupInfos.size()>0) {
policyGroupInfoDao.insertBatch(policyGroupInfos);
policyGroupInfos.clear();
}
if(configGroupInfoS.size()>0) {
configGroupInfoDao.insertBatch(configGroupInfoS);
configGroupInfoS.clear();
}
int index=0;
SqlSessionFactory sqlSessionFactory=SpringContextHolder.getBean(SqlSessionFactory.class);
SqlSession batchSqlSession = null;
Set<String> groupSet=new HashSet<>();
try{
batchSqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, false);
if(!asnNoMap.isEmpty()) {
List<Integer> compileIds=ConfigServiceUtil.getId(1, asnNoMap.size());
List<Integer> groupIds=ConfigServiceUtil.getId(2, asnNoMap.size());
for(Entry<Long, AsnGroupInfo> e:asnNoMap.entrySet()) {
AsnGroupInfo info=e.getValue();
info.setAsnId(e.getKey());
info.setIsValid(0);
info.setCreatorId(UserUtils.getUser().getId());
info.setCreateTime(createTime);
info.setGroupId(groupIds.get(index));
info.setCompileId(compileIds.get(index));
if(!groupSet.contains(info.getOrganization())) {
groupSet.add(info.getOrganization());
}
((AsnGroupInfoDao) batchSqlSession.getMapper(AsnGroupInfoDao.class)).insert(info);
if(index%Constants.IMPORT_LIMIT==0) {
batchSqlSession.commit();
}
index++;
}
batchSqlSession.commit();
}
}finally {
if(batchSqlSession != null){
batchSqlSession.close();
}
}
batchSaveConfigGroupInfo(groupSet);
//刷新缓存
AsnCacheUtils.init(true);
//AsnCacheUtils.init(true);
long end=System.currentTimeMillis();
logger.warn("Save group finish,cost:"+(end-start));
}
public void deleteIps(Map<Long,Integer> asnNoMap){
List<AsnIpCfg> toDelAndSendAsnIpCfgs=Lists.newArrayList();
List<Long> asnIds=Lists.newArrayList(asnNoMap.size());
for(Entry<Long, Integer> e:asnNoMap.entrySet()) {
ConfigGroupInfo configGroupInfo=AsnCacheUtils.get(e.getKey());
if(configGroupInfo==null) {
configGroupInfo=this.getConfigGroupInfoByAsnNo(e.getKey());
}
if(configGroupInfo.getIsIssued()==1) {//已下发
List<AsnIpCfg> _toDelAsnIpCfgs=this.getByAsnNo(configGroupInfo.getAsnId());
toDelAndSendAsnIpCfgs.addAll(_toDelAsnIpCfgs);
}else {
asnIds.add(e.getKey());
}
}
if(asnIds.size()>0) {
this.deleteByAsnNo(asnIds);
}
if(toDelAndSendAsnIpCfgs.size()>0) {
int pointsDataLimit = Constants.MAAT_JSON_SEND_SIZE;//限制条数
Integer size = toDelAndSendAsnIpCfgs.size();
//判断是否有必要分批
if(pointsDataLimit<size){
int part = size/pointsDataLimit;//分批数
for (int i = 0; i < part; i++) {
//pointsDataLimit条
List<AsnIpCfg> listPage = toDelAndSendAsnIpCfgs.subList(0, pointsDataLimit);
delAndSend(listPage);
//剔除
toDelAndSendAsnIpCfgs.subList(0, pointsDataLimit).clear();
public void batchSaveConfigGroupInfo(Set<String> groupSet) {
SqlSessionFactory sqlSessionFactory=SpringContextHolder.getBean(SqlSessionFactory.class);
SqlSession batchSqlSession = null;
try{
batchSqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, false);
if(groupSet.size()>0) {
int index=0;
List<Integer> groupIds=ConfigServiceUtil.getId(2, groupSet.size());
for(String org:groupSet) {
ConfigGroupInfo configGroupInfo=new ConfigGroupInfo();
configGroupInfo.setGroupName(org);
configGroupInfo.setIsIssued(0);
configGroupInfo.setGroupType(4);
configGroupInfo.setInsertTime(new Date());
configGroupInfo.setGroupId(groupIds.get(index));
((ConfigGroupInfoDao) batchSqlSession.getMapper(ConfigGroupInfoDao.class)).insertConfigGroupInfo(configGroupInfo);
if(index%Constants.IMPORT_LIMIT==0) {
batchSqlSession.commit();
}
index++;
}
//最后剩下的
if(!toDelAndSendAsnIpCfgs.isEmpty()){
delAndSend(toDelAndSendAsnIpCfgs);
}
}else {
delAndSend(toDelAndSendAsnIpCfgs);
batchSqlSession.commit();
}
}
}finally {
if(batchSqlSession != null){
batchSqlSession.close();
}
}
}
/**
* 根据Id 批量删除
* @param entities
*/
public void deleteByIdsBatch(List<AsnIpCfg> entities) {
// public void deleteIps(Map<Long,AsnGroupInfo> asnNoMap){
// List<AsnIpCfg> toDelAndSendAsnIpCfgs=Lists.newArrayList();
// List<Long> asnIds=Lists.newArrayList(asnNoMap.size());
// for(Entry<Long, AsnGroupInfo> e:asnNoMap.entrySet()) {
// AsnGroupInfo asnGroupInfo=e.getValue();
// if(asnGroupInfo==null) {
// asnGroupInfo=this.getAsnGroupInfoByAsnNo(e.getKey());
// }
// if(asnGroupInfo.getIsValid()==1) {//已下发
// List<AsnIpCfg> _toDelAsnIpCfgs=this.getByAsnNo(asnGroupInfo.getAsnId());
// toDelAndSendAsnIpCfgs.addAll(_toDelAsnIpCfgs);
// }else {
// asnIds.add(e.getKey());
// }
// }
// if(asnIds.size()>0) {
// this.deleteByAsnNo(asnIds);
// }
// if(toDelAndSendAsnIpCfgs.size()>0) {
// int pointsDataLimit = Constants.MAAT_JSON_SEND_SIZE;//限制条数
// Integer size = toDelAndSendAsnIpCfgs.size();
// //判断是否有必要分批
// if(pointsDataLimit<size){
// int part = size/pointsDataLimit;//分批数
// for (int i = 0; i < part; i++) {
// //pointsDataLimit条
// List<AsnIpCfg> listPage = toDelAndSendAsnIpCfgs.subList(0, pointsDataLimit);
// delAndSend(listPage);
// //剔除
// toDelAndSendAsnIpCfgs.subList(0, pointsDataLimit).clear();
// }
// //最后剩下的
// if(!toDelAndSendAsnIpCfgs.isEmpty()){
// delAndSend(toDelAndSendAsnIpCfgs);
//
// }
// }else {
// delAndSend(toDelAndSendAsnIpCfgs);
// }
// }
// }
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
public void delAndSend(List<AsnIpCfg> entities) {
StringBuilder sb=new StringBuilder();
for(AsnIpCfg ip:entities) {
sb.append(ip.getCfgId());
@@ -232,134 +236,87 @@ public class AsnIpCfgService extends CrudService<CrudDao<AsnIpCfg>, AsnIpCfg> {
}
sb.deleteCharAt(sb.toString().lastIndexOf(","));
asnIpCfgDao.delete(sb.toString());
}
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
public void delAndSend(List<AsnIpCfg> entities) {
deleteByIdsBatch(entities);
asnIPRegionSendToMaat(entities,Constants.VALID_NO);
}
/**
* 分割IP region分次下发
* 由于在Controller中分割此方法不需要调用直接使用asnIPRegionSendToMaat方法即可
* @param asnIpCfgs
* @param valid
*/
@Deprecated
public void splitAndSend(List<AsnIpCfg> asnIpCfgs,Integer valid){
if(asnIpCfgs!=null&&asnIpCfgs.size()>0) {
// List<AsnIpCfg> asnIpCfgs=Lists.newArrayList(list.size());
// asnIpCfgs.addAll(list);
int pointsDataLimit = Constants.MAAT_JSON_SEND_SIZE;//限制条数
Integer size = asnIpCfgs.size();
//判断是否有必要分批
if(pointsDataLimit<size){
int part = size/pointsDataLimit;//分批数
for (int i = 0; i < part; i++) {
//pointsDataLimit条
List<AsnIpCfg> listPage = asnIpCfgs.subList(0, pointsDataLimit);
asnIPRegionSendToMaat(listPage,valid);
//剔除
asnIpCfgs.subList(0, pointsDataLimit).clear();
}
//最后剩下的
if(!asnIpCfgs.isEmpty()){
asnIPRegionSendToMaat(asnIpCfgs,valid);
}
}else {
asnIPRegionSendToMaat(asnIpCfgs,valid);
}
}
}
/**
* 批量保存asn PolicyGroupInfo
* @param entities
* @return
* @throws MaatConvertException
*/
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
public Map<Long,ConfigGroupInfo> saveAsnGroupBatch(List<PolicyGroupInfo> entities) throws MaatConvertException{
Map<Long,ConfigGroupInfo> configGroupInfoMap=new HashMap<>(entities.size());
List<Integer> groupIds= ConfigServiceUtil.getId(2,entities.size());
if(groupIds.size()!=entities.size()) {
throw new MaatConvertException("Get asn group id failed");
}
int ind=0;
for(PolicyGroupInfo entity:entities) {
entity.setIsValid(1);
ConfigGroupInfo group=new ConfigGroupInfo();
//新增
Date createTime=new Date();
entity.setCreatorId(UserUtils.getUser().getId());
entity.setCreateTime(createTime);
//asn类型从综合服务获取groupId
if(4!=entity.getGroupType().intValue()) {
throw new RuntimeException("ConfigGroupInfo is not asn type 4!");
}
entity.setServiceGroupId(groupIds.get(ind).intValue());
//新增协议分组
group.setGroupId(groupIds.get(ind).intValue());
group.setGroupName(entity.getGroupName());
group.setIsIssued(0);
group.setGroupType(entity.getGroupType());
group.setAsnId(entity.getAsnNo());
configGroupInfoDao.insertConfigGroupInfo(group);
if(group.getGroupType().intValue()==4) {
AsnCacheUtils.put(entity.getAsnNo(), group);
}
policyGroupInfoDao.insert(entity);
configGroupInfoMap.put(group.getAsnId(), group);
ind++;
}
return configGroupInfoMap;
}
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
public void saveAsnIpCfg(CfgIndexInfo entity) {
Date createTime=new Date();
ConfigGroupInfo groupInfo=configGroupInfoDao.getConfigGroupInfoByGroupId(entity.getAsnIpGroup().intValue());
if(groupInfo==null) {
throw new RuntimeException("ConfigGroupInfo is null!");
//组织去除首尾空格
entity.setOrganization(entity.getOrganization().trim());
entity.setCountry(entity.getCountry().trim());
entity.setDetail(entity.getDetail().trim());
ConfigGroupInfo configGroupInfo=configGroupInfoDao.getAsnGroupByName(entity.getOrganization());
AsnGroupInfo asnGroupInfo=asnGroupInfoDao.getGroupIdByNameAndASNId(entity.getOrganization(), entity.getCountry(), Long.parseLong(entity.getUserRegion1()));
Integer orgGroup=0;
Integer compileId=0;
Integer asnIdGroup=0;
if(configGroupInfo==null) {
configGroupInfo=new ConfigGroupInfo();
configGroupInfo.setGroupName(entity.getOrganization());
configGroupInfo.setGroupType(4);
configGroupInfo.setInsertTime(new Date());
configGroupInfo.setIsIssued(0);
if(asnGroupInfo==null) {
List<Integer> groupIdList=ConfigServiceUtil.getId(2, 2);
orgGroup=groupIdList.get(0);
asnIdGroup=groupIdList.get(1);
}else {
List<Integer> groupIdList=ConfigServiceUtil.getId(2, 1);
orgGroup=groupIdList.get(0);
configGroupInfo.setGroupId(orgGroup);
asnIdGroup=asnGroupInfo.getGroupId();
}
configGroupInfo.setGroupId(orgGroup);
configGroupInfoDao.insertConfigGroupInfo(configGroupInfo);
}else {
orgGroup=configGroupInfo.getGroupId();
if(asnGroupInfo==null) {
List<Integer> groupIdList=ConfigServiceUtil.getId(2, 1);
asnIdGroup=groupIdList.get(0);
}else {
asnIdGroup=asnGroupInfo.getGroupId();
}
}
if(asnGroupInfo==null) {
asnGroupInfo=new AsnGroupInfo();
asnGroupInfo.setOrganization(entity.getOrganization());
asnGroupInfo.setCountry(entity.getCountry());
asnGroupInfo.setDetail(entity.getDetail());
asnGroupInfo.setIsValid(0);
asnGroupInfo.setCreateTime(new Date());
asnGroupInfo.setCreatorId(entity.getCurrentUser().getId());
asnGroupInfo.setAsnId(Long.parseLong(entity.getUserRegion1()));
asnGroupInfo.setGroupId(asnIdGroup);
List<Integer> compileIds=ConfigServiceUtil.getId(1, 1);
asnGroupInfo.setCompileId(compileIds.get(0));
asnGroupInfoDao.insert(asnGroupInfo);
}
entity.setAsnIpGroup(asnIdGroup);
entity.setCompileId(asnGroupInfo.getCompileId());
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()) {
if(StringUtils.isNotBlank(entity.getCfgDesc())) {
BeanUtils.copyProperties(entity, cfg, new String[]{"cfgId"});
}else {
BeanUtils.copyProperties(entity, cfg, new String[]{"cfgId","cfgDesc"});
}
cfg.setCreateTime(createTime);
cfg.setCreatorId(entity.getCurrentUser().getId());
cfg.setAsnIpGroup(entity.getAsnIpGroup());
cfg.setIsValid(Constants.VALID_YES);
cfg.setRegionId(idList.get(index));
index++;
}
if(entity.getAsnIpCfgs()!=null) {
for(AsnIpCfg cfg:entity.getAsnIpCfgs()) {
BeanUtils.copyProperties(entity, cfg, new String[]{"cfgId"});
cfg.setRequestId(0);
cfg.setClassify("0");
cfg.setAttribute("0");
cfg.setLable("0");
cfg.setCreateTime(createTime);
cfg.setCreatorId(entity.getCurrentUser().getId());
cfg.setAsnIpGroup(entity.getAsnIpGroup().intValue());
cfg.setIsValid(Constants.VALID_NO);
cfg.setIsAudit(Constants.AUDIT_NOT_YET);
cfg.setRegionId(idList.get(index));
index++;
}
this.save(entity.getAsnIpCfgs());
asnIPRegionSendToMaat(entity.getAsnIpCfgs(),Constants.VALID_YES);
// splitAndSend(entity.getAsnIpCfgs(),Constants.VALID_YES);
}else {
if(entity.getAsnIpCfgs()!=null) {
for(AsnIpCfg cfg:entity.getAsnIpCfgs()) {
BeanUtils.copyProperties(entity, cfg, new String[]{"cfgId"});
cfg.setCreateTime(createTime);
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());
}
this.save(entity.getAsnIpCfgs());
}
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
public void delete(Integer isValid,String ids) {
public void delete(String ids) {
/*for(String id:ids.split(",")) {
Long.parseLong(id);
}*/
@@ -368,13 +325,13 @@ public class AsnIpCfgService extends CrudService<CrudDao<AsnIpCfg>, AsnIpCfg> {
for(AsnIpCfg asnIpCfg:asnIpCfgList) {
if(asnIpCfg.getIsValid()==Constants.VALID_YES) {//代表下发过了
asnIpCfg.setIsValid(isValid);
asnIpCfg.setIsValid(Constants.VALID_DEL);
issuedList.add(asnIpCfg);
Integer groupId=asnIpCfg.getAsnIpGroup();
List result=asnIpCfgDao.findOtherIps(groupId, asnIpCfg.getCfgId().intValue());
if(result==null||result.size()==0) {
throw new RuntimeException("Cant not delete ip from asn group, there is only one ip left in the group!");
}
// groupId=asnIpCfg.getAsnIpGroup();
//List result=asnIpCfgDao.findOtherIps(groupId, asnIpCfg.getCfgId().intValue());
//if(result==null||result.size()==0) {
// throw new RuntimeException("Cant not delete ip from asn group, there is only one ip left in the group!");
//}
}
}
asnIpCfgDao.delete(ids);
@@ -385,10 +342,7 @@ public class AsnIpCfgService extends CrudService<CrudDao<AsnIpCfg>, AsnIpCfg> {
}
}
// public List<ConfigGroupInfo> findPolicyGroupInfosByType(Integer groupId) {
// // TODO Auto-generated method stub
// return asnIpCfgDao.findPolicyGroupInfosByType(groupId);
// }
/**
* 选中组中是否含有只剩一个未删除IP的组
* @param serviceGroupIds
@@ -410,9 +364,10 @@ public class AsnIpCfgService extends CrudService<CrudDao<AsnIpCfg>, AsnIpCfg> {
}
return false;
}
public ConfigGroupInfo getConfigGroupInfoByAsnNo(Long asnNo) {
ConfigGroupInfo configGroupInfo=configGroupInfoDao.getInfoByAsnNo(asnNo);
AsnCacheUtils.put(asnNo, configGroupInfo);
public AsnGroupInfo getAsnGroupInfoByAsnNo(Long asnNo) {
AsnGroupInfo configGroupInfo=new AsnGroupInfo();
configGroupInfo.setAsnId(asnNo);
configGroupInfo=asnGroupInfoDao.getInfoByAsnNo(configGroupInfo);
return configGroupInfo;
}
public List<AsnIpCfg> getByAsnNo(Long asnNo) {
@@ -421,12 +376,12 @@ public class AsnIpCfgService extends CrudService<CrudDao<AsnIpCfg>, AsnIpCfg> {
}
return asnIpCfgDao.getByAsnNo(asnNo.longValue());
}
// public void deleteByAsnGroup(Long asnNo) {
// if(asnNo==null) {
// throw new RuntimeException("asnNo is null!");
// }
// asnIpCfgDao.deleteByAsnGroup(asnNo.longValue());
// }
public List<AsnIpCfg> getByIds(String ids) {
if(ids==null) {
throw new RuntimeException("ids is null!");
}
return asnIpCfgDao.getByIds(ids);
}
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
public void deleteByAsnNo(List<Long> asnNoList) {
int pointsDataLimit = 1000;//限制条数
@@ -442,7 +397,7 @@ public class AsnIpCfgService extends CrudService<CrudDao<AsnIpCfg>, AsnIpCfg> {
}
int result=0;
do {
result=asnIpCfgDao.deleteByAsnGroup(asnNoStr.toString().substring(0,asnNoStr.toString().length()-1));
result=asnIpCfgDao.deleteByAsnId(asnNoStr.toString().substring(0,asnNoStr.toString().length()-1));
}while(result>0);
//剔除
asnNoList.subList(0, pointsDataLimit).clear();
@@ -455,7 +410,7 @@ public class AsnIpCfgService extends CrudService<CrudDao<AsnIpCfg>, AsnIpCfg> {
}
int result=0;
do {
result=asnIpCfgDao.deleteByAsnGroup(asnNoStr.toString().substring(0,asnNoStr.toString().length()-1));
result=asnIpCfgDao.deleteByAsnId(asnNoStr.toString().substring(0,asnNoStr.toString().length()-1));
}while(result>0);
asnNoList.clear();
}
@@ -467,7 +422,7 @@ public class AsnIpCfgService extends CrudService<CrudDao<AsnIpCfg>, AsnIpCfg> {
}
int result=0;
do {
result=asnIpCfgDao.deleteByAsnGroup(asnNoStr.toString().substring(0,asnNoStr.toString().length()-1));
result=asnIpCfgDao.deleteByAsnId(asnNoStr.toString().substring(0,asnNoStr.toString().length()-1));
}while(result>0);
asnNoList.clear();
}
@@ -475,4 +430,129 @@ public class AsnIpCfgService extends CrudService<CrudDao<AsnIpCfg>, AsnIpCfg> {
public void ajaxDeleteAsnIp(String ids) {
asnIpCfgDao.ajaxDeleteAsnIp(ids);
}
/**
*
* auditIpBatch(非IP类配置用审核区域IP)
* (这里描述这个方法适用条件 可选)
* @param data
*void
* @exception
* @since 1.0.0
*/
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
public void auditIpBatch(Map<Long,List<AsnIpCfg>> data,Integer isValid) {
SqlSessionFactory sqlSessionFactory=SpringContextHolder.getBean(SqlSessionFactory.class);
final SqlSession batchSqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, false);
try{
data.entrySet().stream().forEach( enrty->{
Long asn=enrty.getKey();//ans group 的group id
List<AsnIpCfg> asnIpCfgs=enrty.getValue();
for(int index = 0; index < asnIpCfgs.size();index++){
AsnIpCfg t = asnIpCfgs.get(index);
BaseIpCfg ipCfg=new BaseIpCfg();
BeanUtils.copyProperties(t, ipCfg);
ipCfg.setTableName(AsnIpCfg.getTablename());
((IpCfgDao) batchSqlSession.getMapper(IpCfgDao.class)).audit(ipCfg);
}
batchSqlSession.commit();
AsnGroupInfo asnGroupInfo=new AsnGroupInfo();
asnGroupInfo.setAsnId(asn);
asnGroupInfo=asnGroupInfoDao.getInfoByAsnNo(asnGroupInfo);
Integer groupId=asnGroupInfo.getGroupId();
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();
if(isValid==Constants.VALID_YES) {//审核通过
if(asnGroupInfo.getIsValid()==0) {//ans组未下发过下发编译配置
asnGroupInfo.setIsValid(1);
asnGroupInfo.setEditorId(UserUtils.getUser().getId());
asnGroupInfo.setEditTime(new Date());
asnGroupInfoDao.updateValid(asnGroupInfo);
maatCfg.initDefaultValue();
ToMaatBean maatBean = new ToMaatBean();
//group
GroupCfg groupCfg=new GroupCfg();
groupCfg.setCompileId(asnGroupInfo.getCompileId());
groupCfg.setGroupId(groupId);
groupCfg.setIsValid(Constants.VALID_YES);
groupCfg.setAuditTime(asnIpCfgs.get(0).getAuditTime());
groupRelationList.add(groupCfg);
BeanUtils.copyProperties(asnIpCfgs.get(0), maatCfg);
ipRegionList.addAll(groupReuseCfgAddRemoveConvert(asnIpCfgs,Constants.VALID_YES,groupId));
maatCfg.setCompileId(asnGroupInfo.getCompileId());
maatCfg.setAction(asnIpCfgs.get(0).getAction());
maatCfg.setAuditTime(asnIpCfgs.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(isValid);
// 设置ASN自定义域
String userRegion = "ASN_ID=" + asnIpCfgs.get(0).getUserRegion1();
maatCfg.setUserRegion(userRegion);
configCompileList.add(maatCfg);
maatBean.setConfigCompileList(configCompileList);
maatBean.setAuditTime(asnIpCfgs.get(0).getAuditTime());
maatBean.setCreatorName(asnIpCfgs.get(0).getCurrentUser().getName());
maatBean.setVersion(Constants.MAAT_VERSION);
maatBean.setOpAction(Constants.INSERT_ACTION);
// 调用服务接口下发配置数据
String json = gsonToJson(maatBean);
logger.info("ASN IP配置下发配置参数" + json);
// 调用服务接口下发配置
ToMaatResult result = ConfigServiceUtil.postMaatCfg(json);
logger.info("ASN IP配置下发响应信息" + result.getMsg());
}else if(asnGroupInfo.getIsValid()==1){//已经下发过,走分组复用
asnIPRegionSendToMaat(asnIpCfgs,isValid);
}else {
throw new RuntimeException("asnGroupInfo isValid value is "+asnGroupInfo.getIsValid());
}
}else if(isValid==Constants.VALID_NO) {//取消审核通过
//已经下发过的,调用分组复用配置删除接口
// GroupReuseAddBean maatBean = new GroupReuseAddBean();
// List<GroupReuseCfg> groupReuseList=new ArrayList<>();
// GroupReuseCfg groupReuseCfg=new GroupReuseCfg();
// ipRegionList.addAll(groupReuseCfgAddRemoveConvert(asnIpCfgs,Constants.VALID_NO,groupId));
// groupReuseCfg.setIpRegionList(ipRegionList);
// groupReuseCfg.setStrRegionList(strRegionList);
// groupReuseCfg.setNumRegionList(numRegionList);
// groupReuseList.add(groupReuseCfg);
// maatBean.setGroupReuseCfgList(groupReuseList);
// maatBean.setAuditTime(asnIpCfgs.get(0).getAuditTime());
// maatBean.setCreatorName(asnIpCfgs.get(0).getCurrentUser().getName());
// maatBean.setVersion(Constants.MAAT_VERSION);
// maatBean.setOpAction(Constants.UPDATE_ACTION);
// //调用服务接口下发配置数据
// String json=gsonToJson(maatBean);
// logger.info("ASN IP域删除配置下发配置参数"+json);
// //调用服务接口下发配置
// ToMaatResult result = ConfigServiceUtil.put(json,3);
// logger.info("ASN IP域删除配置响应信息"+result.getMsg());
asnIPRegionSendToMaat(asnIpCfgs,isValid);
//如果一个asn组下没有IP了修改有效状态
//if(hasValidAsnIp(asn)) {
// asnGroupInfo.setIsValid(0);
// asnGroupInfo.setEditorId(UserUtils.getUser().getId());
// asnGroupInfo.setEditTime(new Date());
// asnGroupInfoDao.updateValid(asnGroupInfo);
//}
}else {
throw new RuntimeException("isValid value is "+isValid);
}
});
}finally {
if(batchSqlSession != null){
batchSqlSession.close();
}
}
}
}