2018-08-30 21:21:00 +08:00
|
|
|
|
package com.nis.web.service.basics;
|
|
|
|
|
|
|
2018-11-11 19:36:53 +08:00
|
|
|
|
import java.nio.charset.Charset;
|
2018-08-30 21:21:00 +08:00
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
import java.util.Date;
|
2018-11-11 19:36:53 +08:00
|
|
|
|
import java.util.HashMap;
|
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;
|
2018-11-11 19:36:53 +08:00
|
|
|
|
import java.util.concurrent.ArrayBlockingQueue;
|
|
|
|
|
|
import java.util.concurrent.BlockingQueue;
|
2018-08-30 21:21:00 +08:00
|
|
|
|
|
2018-10-25 16:44:04 +08:00
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
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;
|
2018-08-30 21:21:00 +08:00
|
|
|
|
import com.nis.domain.Page;
|
|
|
|
|
|
import com.nis.domain.basics.AsnIpCfg;
|
2018-10-26 18:57:20 +08:00
|
|
|
|
import com.nis.domain.basics.PolicyGroupInfo;
|
2018-11-11 19:36:53 +08:00
|
|
|
|
import com.nis.domain.basics.Varibles;
|
2018-08-30 21:21:00 +08:00
|
|
|
|
import com.nis.domain.configuration.CfgIndexInfo;
|
|
|
|
|
|
import com.nis.domain.maat.GroupReuseAddBean;
|
|
|
|
|
|
import com.nis.domain.maat.GroupReuseCfg;
|
|
|
|
|
|
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.ToMaatResult;
|
|
|
|
|
|
import com.nis.domain.specific.ConfigGroupInfo;
|
2018-10-26 18:57:20 +08:00
|
|
|
|
import com.nis.exceptions.MaatConvertException;
|
2018-11-11 19:36:53 +08:00
|
|
|
|
import com.nis.util.AsnCacheUtils;
|
2018-08-30 21:21:00 +08:00
|
|
|
|
import com.nis.util.ConfigServiceUtil;
|
|
|
|
|
|
import com.nis.util.Constants;
|
|
|
|
|
|
import com.nis.web.dao.CrudDao;
|
|
|
|
|
|
import com.nis.web.dao.basics.AsnIpCfgDao;
|
2018-10-26 18:57:20 +08:00
|
|
|
|
import com.nis.web.dao.basics.PolicyGroupInfoDao;
|
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;
|
|
|
|
|
|
@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
|
|
|
|
|
|
private PolicyGroupInfoDao policyGroupInfoDao;
|
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;
|
|
|
|
|
|
}
|
|
|
|
|
|
public AsnIpCfg get(Long id ) {
|
|
|
|
|
|
return asnIpCfgDao.get(id);
|
|
|
|
|
|
}
|
2018-11-11 19:36:53 +08:00
|
|
|
|
|
|
|
|
|
|
// public void save(List<AsnIpCfg> entitys){
|
|
|
|
|
|
// this.saveBatch(entitys, AsnIpCfgDao.class);
|
|
|
|
|
|
// }
|
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();
|
|
|
|
|
|
int len=0;
|
|
|
|
|
|
List<AsnIpCfg> tempList=Lists.newArrayList();
|
2018-11-18 18:28:53 +08:00
|
|
|
|
// Varibles maxPacket=asnIpCfgDao.getVaribles("max_allowed_packet");
|
2018-11-11 19:36:53 +08:00
|
|
|
|
for(AsnIpCfg asnIpCfg:entitys) {
|
|
|
|
|
|
int tempLen=asnIpCfg.toString().getBytes(Charset.forName("UTF-8")).length;
|
2018-11-18 18:28:53 +08:00
|
|
|
|
if((len+tempLen)<Constants.MAX_ALLOWED_PACKET) {
|
2018-11-11 19:36:53 +08:00
|
|
|
|
tempList.add(asnIpCfg);
|
|
|
|
|
|
len+=tempLen;
|
|
|
|
|
|
}else {
|
2018-11-18 18:28:53 +08:00
|
|
|
|
// logger.warn("save ip size:"+tempList.size());
|
2018-11-11 19:36:53 +08:00
|
|
|
|
asnIpCfgDao.insertBatch(tempList);
|
|
|
|
|
|
tempList.clear();
|
|
|
|
|
|
tempList.add(asnIpCfg);
|
|
|
|
|
|
len=tempLen;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if(tempList.size()>0) {
|
2018-11-18 18:28:53 +08:00
|
|
|
|
// logger.warn("save ip size:"+tempList.size());
|
2018-11-11 19:36:53 +08:00
|
|
|
|
asnIpCfgDao.insertBatch(tempList);
|
|
|
|
|
|
tempList.clear();
|
|
|
|
|
|
}
|
|
|
|
|
|
// entitys.clear();
|
|
|
|
|
|
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());
|
|
|
|
|
|
if(entity.getAsnIpGroup()==null) {
|
|
|
|
|
|
throw new RuntimeException("asn group name not found!");
|
|
|
|
|
|
}
|
2018-11-11 19:36:53 +08:00
|
|
|
|
ConfigGroupInfo groupInfo=configGroupInfoDao.getConfigGroupInfoByGroupId(entity.getAsnIpGroup());
|
2018-08-30 21:21:00 +08:00
|
|
|
|
if(groupInfo.getIsIssued()==0) {//未下发,可修改
|
|
|
|
|
|
asnIpCfgDao.update(entity);
|
|
|
|
|
|
}else {
|
|
|
|
|
|
throw new RuntimeException("asn group is issued, cannot update asn ip!");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-10-26 18:57:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
|
2018-11-11 19:36:53 +08:00
|
|
|
|
public void processGroup(Map<Long,Integer> 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;
|
2018-11-18 18:28:53 +08:00
|
|
|
|
// Varibles maxPacket=asnIpCfgDao.getVaribles("max_allowed_packet");
|
2018-11-11 19:36:53 +08:00
|
|
|
|
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;
|
2018-11-18 18:28:53 +08:00
|
|
|
|
if((len+tempLen)<Constants.MAX_ALLOWED_PACKET) {
|
2018-11-11 19:36:53 +08:00
|
|
|
|
policyGroupInfos.add(info);
|
|
|
|
|
|
len+=tempLen;
|
|
|
|
|
|
}else {
|
|
|
|
|
|
policyGroupInfoDao.insertBatch(policyGroupInfos);
|
|
|
|
|
|
policyGroupInfos.clear();
|
|
|
|
|
|
policyGroupInfos.add(info);
|
|
|
|
|
|
len=tempLen;
|
2018-10-26 18:57:20 +08:00
|
|
|
|
}
|
2018-11-11 19:36:53 +08:00
|
|
|
|
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;
|
2018-11-18 18:28:53 +08:00
|
|
|
|
if((len1+tempLen1)<Constants.MAX_ALLOWED_PACKET) {
|
2018-11-11 19:36:53 +08:00
|
|
|
|
configGroupInfoS.add(group);
|
|
|
|
|
|
len1+=tempLen1;
|
|
|
|
|
|
}else {
|
|
|
|
|
|
configGroupInfoDao.insertBatch(configGroupInfoS);
|
|
|
|
|
|
configGroupInfoS.clear();
|
|
|
|
|
|
configGroupInfoS.add(group);
|
|
|
|
|
|
len1=tempLen1;
|
2018-10-26 18:57:20 +08:00
|
|
|
|
}
|
2018-11-11 19:36:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
if(policyGroupInfos.size()>0) {
|
|
|
|
|
|
policyGroupInfoDao.insertBatch(policyGroupInfos);
|
|
|
|
|
|
policyGroupInfos.clear();
|
|
|
|
|
|
}
|
|
|
|
|
|
if(configGroupInfoS.size()>0) {
|
|
|
|
|
|
configGroupInfoDao.insertBatch(configGroupInfoS);
|
|
|
|
|
|
configGroupInfoS.clear();
|
|
|
|
|
|
}
|
|
|
|
|
|
//刷新缓存
|
2018-11-23 14:19:05 +08:00
|
|
|
|
AsnCacheUtils.init(true);
|
2018-11-11 19:36:53 +08:00
|
|
|
|
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();
|
|
|
|
|
|
}
|
|
|
|
|
|
//最后剩下的
|
|
|
|
|
|
if(!toDelAndSendAsnIpCfgs.isEmpty()){
|
|
|
|
|
|
delAndSend(toDelAndSendAsnIpCfgs);
|
|
|
|
|
|
|
2018-10-26 18:57:20 +08:00
|
|
|
|
}
|
2018-11-11 19:36:53 +08:00
|
|
|
|
}else {
|
|
|
|
|
|
delAndSend(toDelAndSendAsnIpCfgs);
|
2018-10-26 18:57:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-11-11 19:36:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 根据Id 批量删除
|
|
|
|
|
|
* @param entities
|
|
|
|
|
|
*/
|
|
|
|
|
|
public void deleteByIdsBatch(List<AsnIpCfg> entities) {
|
|
|
|
|
|
StringBuilder sb=new StringBuilder();
|
|
|
|
|
|
for(AsnIpCfg ip:entities) {
|
|
|
|
|
|
sb.append(ip.getCfgId());
|
|
|
|
|
|
sb.append(",");
|
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());
|
|
|
|
|
|
}
|
|
|
|
|
|
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
|
|
|
|
|
|
public void delAndSend(List<AsnIpCfg> entities) {
|
|
|
|
|
|
deleteByIdsBatch(entities);
|
|
|
|
|
|
asnIPRegionSendToMaat(entities,Constants.VALID_NO);
|
|
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 分割IP region分次下发
|
2018-11-14 11:32:02 +08:00
|
|
|
|
* 由于在Controller中分割,此方法不需要调用,直接使用asnIPRegionSendToMaat方法即可
|
2018-11-11 19:36:53 +08:00
|
|
|
|
* @param asnIpCfgs
|
|
|
|
|
|
* @param valid
|
|
|
|
|
|
*/
|
2018-11-14 11:32:02 +08:00
|
|
|
|
@Deprecated
|
2018-11-11 19:36:53 +08:00
|
|
|
|
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);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-10-26 18:57:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-11-21 11:19:40 +08:00
|
|
|
|
|
2018-11-11 19:36:53 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 批量保存asn PolicyGroupInfo
|
|
|
|
|
|
* @param entities
|
|
|
|
|
|
* @return
|
|
|
|
|
|
* @throws MaatConvertException
|
|
|
|
|
|
*/
|
2018-10-26 18:57:20 +08:00
|
|
|
|
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
|
2018-11-11 19:36:53 +08:00
|
|
|
|
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!");
|
2018-10-26 18:57:20 +08:00
|
|
|
|
}
|
2018-11-11 19:36:53 +08:00
|
|
|
|
entity.setServiceGroupId(groupIds.get(ind).intValue());
|
2018-10-26 18:57:20 +08:00
|
|
|
|
//新增协议分组
|
2018-11-11 19:36:53 +08:00
|
|
|
|
group.setGroupId(groupIds.get(ind).intValue());
|
2018-10-26 18:57:20 +08:00
|
|
|
|
group.setGroupName(entity.getGroupName());
|
|
|
|
|
|
group.setIsIssued(0);
|
|
|
|
|
|
group.setGroupType(entity.getGroupType());
|
|
|
|
|
|
group.setAsnId(entity.getAsnNo());
|
2018-11-11 19:36:53 +08:00
|
|
|
|
configGroupInfoDao.insertConfigGroupInfo(group);
|
|
|
|
|
|
if(group.getGroupType().intValue()==4) {
|
|
|
|
|
|
AsnCacheUtils.put(entity.getAsnNo(), group);
|
|
|
|
|
|
}
|
2018-10-26 18:57:20 +08:00
|
|
|
|
policyGroupInfoDao.insert(entity);
|
2018-11-11 19:36:53 +08:00
|
|
|
|
configGroupInfoMap.put(group.getAsnId(), group);
|
|
|
|
|
|
ind++;
|
2018-10-26 18:57:20 +08:00
|
|
|
|
}
|
2018-11-11 19:36:53 +08:00
|
|
|
|
return configGroupInfoMap;
|
2018-08-30 21:21:00 +08:00
|
|
|
|
}
|
|
|
|
|
|
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
|
|
|
|
|
|
public void saveAsnIpCfg(CfgIndexInfo entity) {
|
2018-10-26 18:57:20 +08:00
|
|
|
|
Date createTime=new Date();
|
2018-11-11 19:36:53 +08:00
|
|
|
|
ConfigGroupInfo groupInfo=configGroupInfoDao.getConfigGroupInfoByGroupId(entity.getAsnIpGroup().intValue());
|
2018-09-27 14:27:47 +08:00
|
|
|
|
if(groupInfo==null) {
|
|
|
|
|
|
throw new RuntimeException("ConfigGroupInfo is null!");
|
|
|
|
|
|
}
|
2018-11-05 19:03:15 +08:00
|
|
|
|
List<Integer> idList=ConfigServiceUtil.getId(3, entity.getAsnIpCfgs().size());
|
|
|
|
|
|
int index=0;
|
2018-08-30 21:21:00 +08:00
|
|
|
|
if(groupInfo.getIsIssued()==1) {//如果已经下发,则需要下到综合服务中
|
|
|
|
|
|
if(entity.getAsnIpCfgs()!=null) {
|
|
|
|
|
|
for(AsnIpCfg cfg:entity.getAsnIpCfgs()) {
|
2018-10-25 16:44:04 +08:00
|
|
|
|
if(StringUtils.isNotBlank(entity.getCfgDesc())) {
|
|
|
|
|
|
BeanUtils.copyProperties(entity, cfg, new String[]{"cfgId"});
|
|
|
|
|
|
}else {
|
|
|
|
|
|
BeanUtils.copyProperties(entity, cfg, new String[]{"cfgId","cfgDesc"});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-10-26 18:57:20 +08:00
|
|
|
|
cfg.setCreateTime(createTime);
|
2018-08-30 21:21:00 +08:00
|
|
|
|
cfg.setCreatorId(entity.getCurrentUser().getId());
|
|
|
|
|
|
cfg.setAsnIpGroup(entity.getAsnIpGroup());
|
|
|
|
|
|
cfg.setIsValid(Constants.VALID_YES);
|
2018-11-05 19:03:15 +08:00
|
|
|
|
cfg.setRegionId(idList.get(index));
|
|
|
|
|
|
index++;
|
2018-08-30 21:21:00 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
this.save(entity.getAsnIpCfgs());
|
2018-11-14 11:32:02 +08:00
|
|
|
|
asnIPRegionSendToMaat(entity.getAsnIpCfgs(),Constants.VALID_YES);
|
|
|
|
|
|
// splitAndSend(entity.getAsnIpCfgs(),Constants.VALID_YES);
|
2018-08-30 21:21:00 +08:00
|
|
|
|
}else {
|
|
|
|
|
|
if(entity.getAsnIpCfgs()!=null) {
|
|
|
|
|
|
for(AsnIpCfg cfg:entity.getAsnIpCfgs()) {
|
|
|
|
|
|
BeanUtils.copyProperties(entity, cfg, new String[]{"cfgId"});
|
2018-10-26 18:57:20 +08:00
|
|
|
|
cfg.setCreateTime(createTime);
|
2018-08-30 21:21:00 +08:00
|
|
|
|
cfg.setCreatorId(entity.getCurrentUser().getId());
|
|
|
|
|
|
cfg.setAsnIpGroup(entity.getAsnIpGroup().intValue());
|
|
|
|
|
|
cfg.setIsValid(Constants.VALID_NO);
|
2018-11-05 19:03:15 +08:00
|
|
|
|
cfg.setRegionId(idList.get(index));
|
|
|
|
|
|
index++;
|
2018-08-30 21:21:00 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
this.save(entity.getAsnIpCfgs());
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
|
2018-11-11 19:36:53 +08:00
|
|
|
|
public void delete(Integer isValid,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) {//代表下发过了
|
|
|
|
|
|
asnIpCfg.setIsValid(isValid);
|
|
|
|
|
|
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!");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
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
|
|
|
|
}
|
2018-10-26 18:57:20 +08:00
|
|
|
|
// public List<ConfigGroupInfo> findPolicyGroupInfosByType(Integer groupId) {
|
|
|
|
|
|
// // TODO Auto-generated method stub
|
|
|
|
|
|
// return asnIpCfgDao.findPolicyGroupInfosByType(groupId);
|
|
|
|
|
|
// }
|
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;
|
|
|
|
|
|
}
|
2018-11-05 16:26:02 +08:00
|
|
|
|
public ConfigGroupInfo getConfigGroupInfoByAsnNo(Long asnNo) {
|
2018-11-11 19:36:53 +08:00
|
|
|
|
ConfigGroupInfo configGroupInfo=configGroupInfoDao.getInfoByAsnNo(asnNo);
|
|
|
|
|
|
AsnCacheUtils.put(asnNo, configGroupInfo);
|
|
|
|
|
|
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
|
|
|
|
}
|
2018-11-11 19:36:53 +08:00
|
|
|
|
// public void deleteByAsnGroup(Long asnNo) {
|
|
|
|
|
|
// if(asnNo==null) {
|
|
|
|
|
|
// throw new RuntimeException("asnNo is null!");
|
|
|
|
|
|
// }
|
|
|
|
|
|
// asnIpCfgDao.deleteByAsnGroup(asnNo.longValue());
|
|
|
|
|
|
// }
|
|
|
|
|
|
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
|
|
|
|
|
|
public void deleteByAsnNo(List<Long> asnNoList) {
|
|
|
|
|
|
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 {
|
|
|
|
|
|
result=asnIpCfgDao.deleteByAsnGroup(asnNoStr.toString().substring(0,asnNoStr.toString().length()-1));
|
|
|
|
|
|
}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 {
|
|
|
|
|
|
result=asnIpCfgDao.deleteByAsnGroup(asnNoStr.toString().substring(0,asnNoStr.toString().length()-1));
|
|
|
|
|
|
}while(result>0);
|
|
|
|
|
|
asnNoList.clear();
|
|
|
|
|
|
}
|
|
|
|
|
|
}else {
|
|
|
|
|
|
StringBuilder asnNoStr=new StringBuilder();
|
|
|
|
|
|
for(Long asnNo:asnNoList) {
|
|
|
|
|
|
asnNoStr.append(asnNo);
|
|
|
|
|
|
asnNoStr.append(",");
|
|
|
|
|
|
}
|
|
|
|
|
|
int result=0;
|
|
|
|
|
|
do {
|
|
|
|
|
|
result=asnIpCfgDao.deleteByAsnGroup(asnNoStr.toString().substring(0,asnNoStr.toString().length()-1));
|
|
|
|
|
|
}while(result>0);
|
|
|
|
|
|
asnNoList.clear();
|
2018-10-26 18:57:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-12-13 20:31:59 +08:00
|
|
|
|
public void ajaxDeleteAsnIp(String ids) {
|
|
|
|
|
|
asnIpCfgDao.ajaxDeleteAsnIp(ids);
|
|
|
|
|
|
}
|
2018-08-30 21:21:00 +08:00
|
|
|
|
}
|