2018-08-30 21:21:00 +08:00
|
|
|
|
package com.nis.web.service.basics;
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
|
|
|
|
import com.nis.domain.Page;
|
|
|
|
|
|
import com.nis.domain.basics.AsnIpCfg;
|
|
|
|
|
|
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;
|
|
|
|
|
|
import com.nis.util.ConfigServiceUtil;
|
|
|
|
|
|
import com.nis.util.Constants;
|
|
|
|
|
|
import com.nis.web.dao.CrudDao;
|
|
|
|
|
|
import com.nis.web.dao.basics.AsnIpCfgDao;
|
|
|
|
|
|
import com.nis.web.dao.specific.SpecificServiceCfgDao;
|
|
|
|
|
|
import com.nis.web.service.CrudService;
|
|
|
|
|
|
@Service
|
|
|
|
|
|
public class AsnIpCfgService extends CrudService<CrudDao<AsnIpCfg>, AsnIpCfg> {
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
private AsnIpCfgDao asnIpCfgDao;
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
private SpecificServiceCfgDao specificServiceCfgDao;
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @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);
|
|
|
|
|
|
}
|
|
|
|
|
|
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
|
|
|
|
|
|
public void save(List<AsnIpCfg> entitys){
|
|
|
|
|
|
Date createTime=new Date();
|
|
|
|
|
|
for(AsnIpCfg entity:entitys) {
|
|
|
|
|
|
entity.setCreateTime(createTime);
|
|
|
|
|
|
entity.setCreatorId(entity.getCurrentUser().getId());
|
|
|
|
|
|
entity.setRegionId(ConfigServiceUtil.getId(3, 1).get(0));
|
|
|
|
|
|
}
|
|
|
|
|
|
this.saveBatch(entitys, AsnIpCfgDao.class);
|
|
|
|
|
|
}
|
|
|
|
|
|
@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!");
|
|
|
|
|
|
}
|
|
|
|
|
|
ConfigGroupInfo groupInfo=specificServiceCfgDao.getConfigGroupInfoByGroupId(entity.getAsnIpGroup());
|
|
|
|
|
|
if(groupInfo.getIsIssued()==0) {//未下发,可修改
|
|
|
|
|
|
asnIpCfgDao.update(entity);
|
|
|
|
|
|
}else {
|
|
|
|
|
|
throw new RuntimeException("asn group is issued, cannot update asn ip!");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
|
|
|
|
|
|
public void saveAsnIpCfg(CfgIndexInfo entity) {
|
|
|
|
|
|
Date crateTime=new Date();
|
|
|
|
|
|
ConfigGroupInfo groupInfo=specificServiceCfgDao.getConfigGroupInfoByGroupId(entity.getAsnIpGroup().intValue());
|
2018-09-27 14:27:47 +08:00
|
|
|
|
if(groupInfo==null) {
|
|
|
|
|
|
throw new RuntimeException("ConfigGroupInfo is null!");
|
|
|
|
|
|
}
|
2018-08-30 21:21:00 +08:00
|
|
|
|
if(groupInfo.getIsIssued()==1) {//如果已经下发,则需要下到综合服务中
|
|
|
|
|
|
if(entity.getAsnIpCfgs()!=null) {
|
|
|
|
|
|
for(AsnIpCfg cfg:entity.getAsnIpCfgs()) {
|
|
|
|
|
|
BeanUtils.copyProperties(entity, cfg, new String[]{"cfgId"});
|
|
|
|
|
|
cfg.setCreateTime(crateTime);
|
|
|
|
|
|
cfg.setCreatorId(entity.getCurrentUser().getId());
|
|
|
|
|
|
cfg.setAsnIpGroup(entity.getAsnIpGroup());
|
|
|
|
|
|
cfg.setIsValid(Constants.VALID_YES);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
this.save(entity.getAsnIpCfgs());
|
|
|
|
|
|
GroupReuseAddBean maatBean = new GroupReuseAddBean();
|
|
|
|
|
|
List<GroupReuseCfg> groupReuseList=new ArrayList<>();
|
|
|
|
|
|
GroupReuseCfg groupReuseCfg=new GroupReuseCfg();
|
2018-09-07 20:18:59 +08:00
|
|
|
|
List<IpCfg> ipRegionList = groupReuseCfgAddRemoveConvert(entity.getAsnIpCfgs(),Constants.VALID_YES,null);
|
2018-08-30 21:21:00 +08:00
|
|
|
|
List<StringCfg> strRegionList = new ArrayList<>();
|
|
|
|
|
|
List<NumBoundaryCfg> numRegionList = new ArrayList<>();
|
|
|
|
|
|
groupReuseCfg.setIpRegionList(ipRegionList);
|
|
|
|
|
|
groupReuseCfg.setStrRegionList(strRegionList);
|
|
|
|
|
|
groupReuseCfg.setNumRegionList(numRegionList);
|
|
|
|
|
|
groupReuseList.add(groupReuseCfg);
|
|
|
|
|
|
maatBean.setGroupReuseCfgList(groupReuseList);
|
|
|
|
|
|
maatBean.setAuditTime(crateTime);
|
|
|
|
|
|
maatBean.setCreatorName(entity.getCurrentUser().getName());
|
|
|
|
|
|
maatBean.setVersion(Constants.MAAT_VERSION);
|
|
|
|
|
|
maatBean.setOpAction(Constants.INSERT_ACTION);
|
|
|
|
|
|
//调用服务接口下发配置数据
|
|
|
|
|
|
String json=gsonToJson(maatBean);
|
|
|
|
|
|
logger.info("asn ip复用域新增配置下发配置参数:"+json);
|
|
|
|
|
|
//调用服务接口下发配置
|
|
|
|
|
|
ToMaatResult result = ConfigServiceUtil.postGroupReuseSources(json);
|
|
|
|
|
|
logger.info("asn ip复用域新增配置响应信息:"+result.getMsg());
|
|
|
|
|
|
}else {
|
|
|
|
|
|
if(entity.getAsnIpCfgs()!=null) {
|
|
|
|
|
|
for(AsnIpCfg cfg:entity.getAsnIpCfgs()) {
|
|
|
|
|
|
BeanUtils.copyProperties(entity, cfg, new String[]{"cfgId"});
|
|
|
|
|
|
cfg.setCreateTime(crateTime);
|
|
|
|
|
|
cfg.setCreatorId(entity.getCurrentUser().getId());
|
|
|
|
|
|
cfg.setAsnIpGroup(entity.getAsnIpGroup().intValue());
|
|
|
|
|
|
cfg.setIsValid(Constants.VALID_NO);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
this.save(entity.getAsnIpCfgs());
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
|
|
|
|
|
|
public void delete(Integer functionId,Integer isValid,String ids) {
|
|
|
|
|
|
for(String id:ids.split(",")) {
|
|
|
|
|
|
Long.parseLong(id);
|
|
|
|
|
|
}
|
|
|
|
|
|
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!");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if(issuedList.size()>0) {
|
|
|
|
|
|
//已经下发过的,调用分组复用配置删除接口
|
|
|
|
|
|
GroupReuseAddBean maatBean = new GroupReuseAddBean();
|
|
|
|
|
|
List<GroupReuseCfg> groupReuseList=new ArrayList<>();
|
|
|
|
|
|
GroupReuseCfg groupReuseCfg=new GroupReuseCfg();
|
2018-09-07 20:18:59 +08:00
|
|
|
|
List<IpCfg> ipRegionList = groupReuseCfgAddRemoveConvert(issuedList,Constants.VALID_NO,null);
|
2018-08-30 21:21:00 +08:00
|
|
|
|
List<StringCfg> strRegionList = new ArrayList<>();
|
|
|
|
|
|
List<NumBoundaryCfg> numRegionList = new ArrayList<>();
|
|
|
|
|
|
groupReuseCfg.setIpRegionList(ipRegionList);
|
|
|
|
|
|
groupReuseCfg.setStrRegionList(strRegionList);
|
|
|
|
|
|
groupReuseCfg.setNumRegionList(numRegionList);
|
|
|
|
|
|
groupReuseList.add(groupReuseCfg);
|
|
|
|
|
|
maatBean.setGroupReuseCfgList(groupReuseList);
|
|
|
|
|
|
maatBean.setAuditTime(new Date());
|
|
|
|
|
|
maatBean.setCreatorName(new AsnIpCfg().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());
|
|
|
|
|
|
}
|
|
|
|
|
|
asnIpCfgDao.updateValid(isValid, ids);
|
|
|
|
|
|
}
|
|
|
|
|
|
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-08-30 21:21:00 +08:00
|
|
|
|
}
|