2018-08-30 21:21:00 +08:00
|
|
|
|
package com.nis.web.service.basics;
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
import java.util.Date;
|
2019-01-04 18:28:57 +06:00
|
|
|
|
import java.util.HashSet;
|
2018-08-30 21:21:00 +08:00
|
|
|
|
import java.util.List;
|
2018-10-26 18:57:20 +08:00
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
import java.util.Map.Entry;
|
2019-01-04 18:28:57 +06:00
|
|
|
|
import java.util.Set;
|
2018-08-30 21:21:00 +08:00
|
|
|
|
|
2019-01-04 18:28:57 +06:00
|
|
|
|
import org.apache.ibatis.session.ExecutorType;
|
|
|
|
|
|
import org.apache.ibatis.session.SqlSession;
|
|
|
|
|
|
import org.apache.ibatis.session.SqlSessionFactory;
|
2018-08-30 21:21:00 +08:00
|
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
2018-10-26 18:57:20 +08:00
|
|
|
|
import com.beust.jcommander.internal.Lists;
|
2019-01-06 11:24:49 +08:00
|
|
|
|
import com.google.common.collect.Maps;
|
2018-08-30 21:21:00 +08:00
|
|
|
|
import com.nis.domain.Page;
|
2019-01-04 18:28:57 +06:00
|
|
|
|
import com.nis.domain.basics.AsnGroupInfo;
|
2018-08-30 21:21:00 +08:00
|
|
|
|
import com.nis.domain.basics.AsnIpCfg;
|
2019-01-04 18:28:57 +06:00
|
|
|
|
import com.nis.domain.configuration.BaseIpCfg;
|
2018-08-30 21:21:00 +08:00
|
|
|
|
import com.nis.domain.configuration.CfgIndexInfo;
|
2019-01-04 18:28:57 +06:00
|
|
|
|
import com.nis.domain.maat.MaatCfg;
|
|
|
|
|
|
import com.nis.domain.maat.MaatCfg.DigestCfg;
|
|
|
|
|
|
import com.nis.domain.maat.MaatCfg.GroupCfg;
|
2018-08-30 21:21:00 +08:00
|
|
|
|
import com.nis.domain.maat.MaatCfg.IpCfg;
|
|
|
|
|
|
import com.nis.domain.maat.MaatCfg.NumBoundaryCfg;
|
|
|
|
|
|
import com.nis.domain.maat.MaatCfg.StringCfg;
|
2019-01-04 18:28:57 +06:00
|
|
|
|
import com.nis.domain.maat.ToMaatBean;
|
2018-08-30 21:21:00 +08:00
|
|
|
|
import com.nis.domain.maat.ToMaatResult;
|
|
|
|
|
|
import com.nis.domain.specific.ConfigGroupInfo;
|
|
|
|
|
|
import com.nis.util.ConfigServiceUtil;
|
|
|
|
|
|
import com.nis.util.Constants;
|
|
|
|
|
|
import com.nis.web.dao.CrudDao;
|
2019-01-04 18:28:57 +06:00
|
|
|
|
import com.nis.web.dao.basics.AsnGroupInfoDao;
|
2018-08-30 21:21:00 +08:00
|
|
|
|
import com.nis.web.dao.basics.AsnIpCfgDao;
|
2019-01-04 18:28:57 +06:00
|
|
|
|
import com.nis.web.dao.configuration.IpCfgDao;
|
2018-11-11 19:36:53 +08:00
|
|
|
|
import com.nis.web.dao.specific.ConfigGroupInfoDao;
|
2018-10-26 18:57:20 +08:00
|
|
|
|
import com.nis.web.security.UserUtils;
|
2018-08-30 21:21:00 +08:00
|
|
|
|
import com.nis.web.service.CrudService;
|
2019-01-04 18:28:57 +06:00
|
|
|
|
import com.nis.web.service.SpringContextHolder;
|
2018-08-30 21:21:00 +08:00
|
|
|
|
@Service
|
|
|
|
|
|
public class AsnIpCfgService extends CrudService<CrudDao<AsnIpCfg>, AsnIpCfg> {
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
private AsnIpCfgDao asnIpCfgDao;
|
2018-11-11 19:36:53 +08:00
|
|
|
|
// @Autowired
|
|
|
|
|
|
// private SpecificServiceCfgDao specificServiceCfgDao;
|
2018-08-30 21:21:00 +08:00
|
|
|
|
@Autowired
|
2018-11-11 19:36:53 +08:00
|
|
|
|
private ConfigGroupInfoDao configGroupInfoDao;
|
2018-10-26 18:57:20 +08:00
|
|
|
|
@Autowired
|
2019-01-04 18:28:57 +06:00
|
|
|
|
private AsnGroupInfoDao asnGroupInfoDao;
|
2018-08-30 21:21:00 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* @param page
|
|
|
|
|
|
* @param entity
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
|
|
|
|
|
public Page<AsnIpCfg> findPage(Page<AsnIpCfg> page, AsnIpCfg entity) {
|
|
|
|
|
|
entity.getSqlMap().put("dsf", configScopeFilter(entity.getCurrentUser(),"r"));
|
|
|
|
|
|
entity.setPage(page);
|
|
|
|
|
|
List<AsnIpCfg> list=asnIpCfgDao.findPage(entity);
|
|
|
|
|
|
page.setList(list);
|
|
|
|
|
|
return page;
|
|
|
|
|
|
}
|
2018-12-26 14:47:23 +08:00
|
|
|
|
|
|
|
|
|
|
public List<AsnIpCfg> findByPage(String ids) {
|
|
|
|
|
|
List<AsnIpCfg> list=asnIpCfgDao.findByPage(ids);
|
|
|
|
|
|
return list;
|
|
|
|
|
|
}
|
2019-01-04 18:28:57 +06:00
|
|
|
|
public boolean hasValidAsnIp(Long asnId) {
|
|
|
|
|
|
return asnIpCfgDao.hasValidAsnIp(asnId)>0;
|
|
|
|
|
|
}
|
2018-12-26 14:47:23 +08:00
|
|
|
|
|
|
|
|
|
|
|
2018-08-30 21:21:00 +08:00
|
|
|
|
public AsnIpCfg get(Long id ) {
|
|
|
|
|
|
return asnIpCfgDao.get(id);
|
|
|
|
|
|
}
|
2018-11-11 19:36:53 +08:00
|
|
|
|
|
2018-08-30 21:21:00 +08:00
|
|
|
|
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
|
2018-11-11 19:36:53 +08:00
|
|
|
|
public void save(List<AsnIpCfg> entitys) {
|
2018-11-18 18:28:53 +08:00
|
|
|
|
logger.warn("Start to save IP,size:"+entitys.size());
|
2018-11-11 19:36:53 +08:00
|
|
|
|
long start=System.currentTimeMillis();
|
2019-01-04 18:28:57 +06:00
|
|
|
|
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();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-11-11 19:36:53 +08:00
|
|
|
|
long end=System.currentTimeMillis();
|
|
|
|
|
|
logger.warn("Save IP finish,cost:"+(end-start));
|
2018-08-30 21:21:00 +08:00
|
|
|
|
}
|
|
|
|
|
|
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
|
|
|
|
|
|
public void update(AsnIpCfg entity){
|
|
|
|
|
|
Date editTime=new Date();
|
|
|
|
|
|
entity.setEditTime(editTime);
|
|
|
|
|
|
entity.setEditorId(entity.getCurrentUser().getId());
|
2019-01-06 11:24:49 +08:00
|
|
|
|
String userRegion1=entity.getUserRegion1();
|
|
|
|
|
|
AsnGroupInfo groupInfo=new AsnGroupInfo();
|
|
|
|
|
|
groupInfo.setAsnId(Long.parseLong(userRegion1));
|
|
|
|
|
|
groupInfo=asnGroupInfoDao.getInfoByAsnNo(groupInfo);
|
|
|
|
|
|
String org=groupInfo.getOrganization().trim();
|
|
|
|
|
|
String country=groupInfo.getCountry().trim();
|
|
|
|
|
|
String detail=groupInfo.getDetail().trim();
|
2019-01-04 18:28:57 +06:00
|
|
|
|
entity.setOrganization(org);
|
|
|
|
|
|
entity.setCountry(country);
|
|
|
|
|
|
entity.setDetail(detail);
|
2019-01-06 11:49:48 +08:00
|
|
|
|
entity.setCompileId(groupInfo.getCompileId());
|
2019-01-04 18:28:57 +06:00
|
|
|
|
asnIpCfgDao.update(entity);
|
2018-10-26 18:57:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
|
2019-01-04 18:28:57 +06:00
|
|
|
|
public void processGroup(Map<Long,AsnGroupInfo> asnNoMap){
|
2018-11-11 19:36:53 +08:00
|
|
|
|
logger.warn("Start to save group");
|
|
|
|
|
|
long start=System.currentTimeMillis();
|
|
|
|
|
|
Date createTime=new Date();
|
2019-01-04 18:28:57 +06:00
|
|
|
|
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);
|
2018-11-11 19:36:53 +08:00
|
|
|
|
//刷新缓存
|
2019-01-04 18:28:57 +06:00
|
|
|
|
//AsnCacheUtils.init(true);
|
2018-11-11 19:36:53 +08:00
|
|
|
|
long end=System.currentTimeMillis();
|
|
|
|
|
|
logger.warn("Save group finish,cost:"+(end-start));
|
|
|
|
|
|
}
|
2019-01-04 18:28:57 +06:00
|
|
|
|
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++;
|
2018-10-26 18:57:20 +08:00
|
|
|
|
}
|
2019-01-04 18:28:57 +06:00
|
|
|
|
batchSqlSession.commit();
|
2018-10-26 18:57:20 +08:00
|
|
|
|
}
|
2019-01-04 18:28:57 +06:00
|
|
|
|
|
|
|
|
|
|
}finally {
|
|
|
|
|
|
if(batchSqlSession != null){
|
|
|
|
|
|
batchSqlSession.close();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-11-11 19:36:53 +08:00
|
|
|
|
}
|
2019-01-04 18:28:57 +06:00
|
|
|
|
// 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) {
|
2018-11-11 19:36:53 +08:00
|
|
|
|
StringBuilder sb=new StringBuilder();
|
2019-01-06 11:24:49 +08:00
|
|
|
|
Map<Long,Integer> asnDelCounts=Maps.newHashMap();
|
2018-11-11 19:36:53 +08:00
|
|
|
|
for(AsnIpCfg ip:entities) {
|
|
|
|
|
|
sb.append(ip.getCfgId());
|
|
|
|
|
|
sb.append(",");
|
2019-01-06 11:24:49 +08:00
|
|
|
|
if(asnDelCounts.containsKey(Long.parseLong(ip.getUserRegion1()))) {
|
|
|
|
|
|
int count=asnDelCounts.get(Long.parseLong(ip.getUserRegion1()))+1;
|
|
|
|
|
|
asnDelCounts.put(Long.parseLong(ip.getUserRegion1()), count);
|
|
|
|
|
|
}else {
|
|
|
|
|
|
asnDelCounts.put(Long.parseLong(ip.getUserRegion1()), 1);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
//跟新asn组的审核通过IP数量
|
|
|
|
|
|
for(Entry<Long,Integer> asnDelCount: asnDelCounts.entrySet()) {
|
|
|
|
|
|
AsnGroupInfo info=new AsnGroupInfo();
|
|
|
|
|
|
info.setAsnId(asnDelCount.getKey());
|
|
|
|
|
|
info.setIssuedIPs(0l-asnDelCount.getValue());
|
|
|
|
|
|
asnGroupInfoDao.modifyIssuedIp(info);
|
2018-10-26 18:57:20 +08:00
|
|
|
|
}
|
2018-11-11 19:36:53 +08:00
|
|
|
|
sb.deleteCharAt(sb.toString().lastIndexOf(","));
|
|
|
|
|
|
asnIpCfgDao.delete(sb.toString());
|
|
|
|
|
|
asnIPRegionSendToMaat(entities,Constants.VALID_NO);
|
|
|
|
|
|
}
|
2018-11-21 11:19:40 +08:00
|
|
|
|
|
2018-10-26 18:57:20 +08:00
|
|
|
|
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
|
2019-01-04 18:28:57 +06:00
|
|
|
|
public void saveAsnIpCfg(CfgIndexInfo entity) {
|
|
|
|
|
|
Date createTime=new Date();
|
2019-01-06 11:24:49 +08:00
|
|
|
|
//asn号
|
|
|
|
|
|
String userRegion1=entity.getUserRegion1();
|
|
|
|
|
|
AsnGroupInfo asnGroupInfo=new AsnGroupInfo();
|
|
|
|
|
|
asnGroupInfo.setAsnId(Long.parseLong(userRegion1));
|
|
|
|
|
|
asnGroupInfo=asnGroupInfoDao.getInfoByAsnNo(asnGroupInfo);
|
2019-01-04 18:28:57 +06:00
|
|
|
|
//组织去除首尾空格
|
2019-01-06 11:24:49 +08:00
|
|
|
|
entity.setOrganization(asnGroupInfo.getOrganization().trim());
|
|
|
|
|
|
entity.setCountry(asnGroupInfo.getCountry().trim());
|
|
|
|
|
|
entity.setDetail(asnGroupInfo.getDetail().trim());
|
2019-01-04 18:28:57 +06:00
|
|
|
|
ConfigGroupInfo configGroupInfo=configGroupInfoDao.getAsnGroupByName(entity.getOrganization());
|
|
|
|
|
|
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);
|
2019-01-06 11:24:49 +08:00
|
|
|
|
List<Integer> groupIdList=ConfigServiceUtil.getId(2, 2);
|
|
|
|
|
|
orgGroup=groupIdList.get(0);
|
2019-01-04 18:28:57 +06:00
|
|
|
|
configGroupInfo.setGroupId(orgGroup);
|
|
|
|
|
|
configGroupInfoDao.insertConfigGroupInfo(configGroupInfo);
|
2018-09-27 14:27:47 +08:00
|
|
|
|
}
|
2019-01-06 11:24:49 +08:00
|
|
|
|
asnIdGroup=asnGroupInfo.getGroupId();
|
2019-01-04 18:28:57 +06:00
|
|
|
|
entity.setAsnIpGroup(asnIdGroup);
|
|
|
|
|
|
entity.setCompileId(asnGroupInfo.getCompileId());
|
2018-11-05 19:03:15 +08:00
|
|
|
|
List<Integer> idList=ConfigServiceUtil.getId(3, entity.getAsnIpCfgs().size());
|
|
|
|
|
|
int index=0;
|
2019-01-04 18:28:57 +06:00
|
|
|
|
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++;
|
2018-08-30 21:21:00 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2019-01-04 18:28:57 +06:00
|
|
|
|
this.save(entity.getAsnIpCfgs());
|
2018-08-30 21:21:00 +08:00
|
|
|
|
}
|
|
|
|
|
|
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
|
2019-01-04 18:28:57 +06:00
|
|
|
|
public void delete(String ids) {
|
2018-12-13 18:07:15 +08:00
|
|
|
|
/*for(String id:ids.split(",")) {
|
2018-08-30 21:21:00 +08:00
|
|
|
|
Long.parseLong(id);
|
2018-12-13 18:07:15 +08:00
|
|
|
|
}*/
|
2018-08-30 21:21:00 +08:00
|
|
|
|
List<AsnIpCfg> issuedList=new ArrayList<>();
|
|
|
|
|
|
List<AsnIpCfg> asnIpCfgList= asnIpCfgDao.getByIds(ids);
|
|
|
|
|
|
|
|
|
|
|
|
for(AsnIpCfg asnIpCfg:asnIpCfgList) {
|
|
|
|
|
|
if(asnIpCfg.getIsValid()==Constants.VALID_YES) {//代表下发过了
|
2019-01-04 18:28:57 +06:00
|
|
|
|
asnIpCfg.setIsValid(Constants.VALID_DEL);
|
2018-08-30 21:21:00 +08:00
|
|
|
|
issuedList.add(asnIpCfg);
|
2019-01-04 18:28:57 +06:00
|
|
|
|
// 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!");
|
|
|
|
|
|
//}
|
2018-08-30 21:21:00 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-11-11 19:36:53 +08:00
|
|
|
|
asnIpCfgDao.delete(ids);
|
|
|
|
|
|
//已经下发过的,调用分组复用配置删除接口
|
2018-11-14 11:32:02 +08:00
|
|
|
|
// splitAndSend(issuedList,Constants.VALID_NO);
|
2018-12-13 18:07:15 +08:00
|
|
|
|
if(issuedList.size() > 0){
|
|
|
|
|
|
asnIPRegionSendToMaat(issuedList,Constants.VALID_NO);
|
|
|
|
|
|
}
|
2018-11-11 19:36:53 +08:00
|
|
|
|
|
2018-08-30 21:21:00 +08:00
|
|
|
|
}
|
2019-01-04 18:28:57 +06:00
|
|
|
|
|
2018-09-03 13:02:24 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 选中组中是否含有只剩一个未删除IP的组
|
|
|
|
|
|
* @param serviceGroupIds
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
2018-09-28 11:49:53 +08:00
|
|
|
|
public boolean hasLastIp(String serviceGroupIds,String ids) {
|
2018-09-03 13:02:24 +08:00
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
|
for(String groupId:serviceGroupIds.split(",")) {
|
|
|
|
|
|
Long.parseLong(groupId);
|
|
|
|
|
|
}
|
2018-09-28 11:49:53 +08:00
|
|
|
|
List<Integer> countList=asnIpCfgDao.countValidIPs(serviceGroupIds,ids);
|
|
|
|
|
|
if(countList.size()==0) {
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
2018-09-03 13:02:24 +08:00
|
|
|
|
for(Integer count:countList) {
|
2018-09-28 11:49:53 +08:00
|
|
|
|
if(count==0) {
|
2018-09-03 13:02:24 +08:00
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2019-01-04 18:28:57 +06:00
|
|
|
|
public AsnGroupInfo getAsnGroupInfoByAsnNo(Long asnNo) {
|
|
|
|
|
|
AsnGroupInfo configGroupInfo=new AsnGroupInfo();
|
|
|
|
|
|
configGroupInfo.setAsnId(asnNo);
|
|
|
|
|
|
configGroupInfo=asnGroupInfoDao.getInfoByAsnNo(configGroupInfo);
|
2018-11-11 19:36:53 +08:00
|
|
|
|
return configGroupInfo;
|
2018-10-26 18:57:20 +08:00
|
|
|
|
}
|
2018-11-11 19:36:53 +08:00
|
|
|
|
public List<AsnIpCfg> getByAsnNo(Long asnNo) {
|
|
|
|
|
|
if(asnNo==null) {
|
2018-10-26 18:57:20 +08:00
|
|
|
|
throw new RuntimeException("groupId or asnNo is null!");
|
|
|
|
|
|
}
|
2018-11-11 19:36:53 +08:00
|
|
|
|
return asnIpCfgDao.getByAsnNo(asnNo.longValue());
|
2018-10-26 18:57:20 +08:00
|
|
|
|
}
|
2019-01-04 18:28:57 +06:00
|
|
|
|
public List<AsnIpCfg> getByIds(String ids) {
|
|
|
|
|
|
if(ids==null) {
|
|
|
|
|
|
throw new RuntimeException("ids is null!");
|
|
|
|
|
|
}
|
|
|
|
|
|
return asnIpCfgDao.getByIds(ids);
|
|
|
|
|
|
}
|
2018-11-11 19:36:53 +08:00
|
|
|
|
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
|
|
|
|
|
|
public void deleteByAsnNo(List<Long> asnNoList) {
|
2019-01-06 11:24:49 +08:00
|
|
|
|
// for(Long asnNo:asnNoList) {
|
|
|
|
|
|
// int result=0;
|
|
|
|
|
|
// do {
|
|
|
|
|
|
// result=asnIpCfgDao.deleteByAsnId(String.valueOf(asnNo));
|
|
|
|
|
|
// }while(result>0);
|
|
|
|
|
|
// }
|
2018-11-11 19:36:53 +08:00
|
|
|
|
int pointsDataLimit = 1000;//限制条数
|
|
|
|
|
|
Integer size = asnNoList.size();
|
|
|
|
|
|
if(pointsDataLimit<size){
|
|
|
|
|
|
int part = size/pointsDataLimit;//分批数
|
|
|
|
|
|
for (int i = 0; i < part; i++) {
|
|
|
|
|
|
List<Long> listPage = asnNoList.subList(0, pointsDataLimit);
|
|
|
|
|
|
StringBuilder asnNoStr=new StringBuilder();
|
|
|
|
|
|
for(Long asnNo:asnNoList) {
|
|
|
|
|
|
asnNoStr.append(asnNo);
|
|
|
|
|
|
asnNoStr.append(",");
|
|
|
|
|
|
}
|
|
|
|
|
|
int result=0;
|
|
|
|
|
|
do {
|
2019-01-04 18:28:57 +06:00
|
|
|
|
result=asnIpCfgDao.deleteByAsnId(asnNoStr.toString().substring(0,asnNoStr.toString().length()-1));
|
2018-11-11 19:36:53 +08:00
|
|
|
|
}while(result>0);
|
|
|
|
|
|
//剔除
|
|
|
|
|
|
asnNoList.subList(0, pointsDataLimit).clear();
|
|
|
|
|
|
}
|
|
|
|
|
|
if(!asnNoList.isEmpty()){
|
|
|
|
|
|
StringBuilder asnNoStr=new StringBuilder();
|
|
|
|
|
|
for(Long asnNo:asnNoList) {
|
|
|
|
|
|
asnNoStr.append(asnNo);
|
|
|
|
|
|
asnNoStr.append(",");
|
|
|
|
|
|
}
|
|
|
|
|
|
int result=0;
|
|
|
|
|
|
do {
|
2019-01-04 18:28:57 +06:00
|
|
|
|
result=asnIpCfgDao.deleteByAsnId(asnNoStr.toString().substring(0,asnNoStr.toString().length()-1));
|
2018-11-11 19:36:53 +08:00
|
|
|
|
}while(result>0);
|
|
|
|
|
|
asnNoList.clear();
|
|
|
|
|
|
}
|
|
|
|
|
|
}else {
|
|
|
|
|
|
StringBuilder asnNoStr=new StringBuilder();
|
|
|
|
|
|
for(Long asnNo:asnNoList) {
|
|
|
|
|
|
asnNoStr.append(asnNo);
|
|
|
|
|
|
asnNoStr.append(",");
|
|
|
|
|
|
}
|
|
|
|
|
|
int result=0;
|
|
|
|
|
|
do {
|
2019-01-04 18:28:57 +06:00
|
|
|
|
result=asnIpCfgDao.deleteByAsnId(asnNoStr.toString().substring(0,asnNoStr.toString().length()-1));
|
2018-11-11 19:36:53 +08:00
|
|
|
|
}while(result>0);
|
|
|
|
|
|
asnNoList.clear();
|
2018-10-26 18:57:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2019-01-06 11:24:49 +08:00
|
|
|
|
/*public void ajaxDeleteAsnIp(String ids) {
|
2018-12-13 20:31:59 +08:00
|
|
|
|
asnIpCfgDao.ajaxDeleteAsnIp(ids);
|
2019-01-06 11:24:49 +08:00
|
|
|
|
}*/
|
2019-01-04 18:28:57 +06:00
|
|
|
|
/**
|
|
|
|
|
|
*
|
|
|
|
|
|
* 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{
|
2019-01-04 21:38:13 +08:00
|
|
|
|
for(Entry<Long,List<AsnIpCfg>> enrty:data.entrySet()) {
|
|
|
|
|
|
//data.entrySet().stream().forEach( enrty->{
|
2019-01-04 18:28:57 +06:00
|
|
|
|
Long asn=enrty.getKey();//ans group 的group id
|
|
|
|
|
|
List<AsnIpCfg> asnIpCfgs=enrty.getValue();
|
2019-01-06 11:24:49 +08:00
|
|
|
|
int issuedNum=asnIpCfgs.size();
|
2019-01-04 18:28:57 +06:00
|
|
|
|
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());
|
2019-01-06 11:24:49 +08:00
|
|
|
|
asnGroupInfo.setIssuedIPs(issuedNum+0L);
|
2019-01-04 18:28:57 +06:00
|
|
|
|
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){//已经下发过,走分组复用
|
2019-01-06 11:24:49 +08:00
|
|
|
|
asnGroupInfo.setIssuedIPs(issuedNum+0l);
|
|
|
|
|
|
asnGroupInfoDao.update(asnGroupInfo);
|
2019-01-04 18:28:57 +06:00
|
|
|
|
asnIPRegionSendToMaat(asnIpCfgs,isValid);
|
|
|
|
|
|
}else {
|
|
|
|
|
|
throw new RuntimeException("asnGroupInfo isValid value is "+asnGroupInfo.getIsValid());
|
|
|
|
|
|
}
|
|
|
|
|
|
}else if(isValid==Constants.VALID_NO) {//取消审核通过
|
2019-01-06 11:24:49 +08:00
|
|
|
|
asnGroupInfo.setIssuedIPs(0L-issuedNum);
|
|
|
|
|
|
asnGroupInfoDao.update(asnGroupInfo);
|
2019-01-04 18:28:57 +06:00
|
|
|
|
//已经下发过的,调用分组复用配置删除接口
|
|
|
|
|
|
// 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);
|
|
|
|
|
|
//}
|
2019-01-06 11:24:49 +08:00
|
|
|
|
|
2019-01-04 18:28:57 +06:00
|
|
|
|
}else {
|
|
|
|
|
|
throw new RuntimeException("isValid value is "+isValid);
|
|
|
|
|
|
}
|
2019-01-04 21:38:13 +08:00
|
|
|
|
//});
|
|
|
|
|
|
}
|
2019-01-04 18:28:57 +06:00
|
|
|
|
}finally {
|
|
|
|
|
|
if(batchSqlSession != null){
|
|
|
|
|
|
batchSqlSession.close();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2019-01-06 11:24:49 +08:00
|
|
|
|
|
|
|
|
|
|
public AsnIpCfg getOne(AsnIpCfg cfg) {
|
|
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
|
return asnIpCfgDao.getOne(cfg);
|
|
|
|
|
|
}
|
2018-08-30 21:21:00 +08:00
|
|
|
|
}
|