This repository has been archived on 2025-09-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
k18-ntcs-web-ntc/src/main/java/com/nis/web/service/basics/AsnIpCfgService.java

198 lines
7.7 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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());
if(groupInfo==null) {
throw new RuntimeException("ConfigGroupInfo is null!");
}
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();
List<IpCfg> ipRegionList = groupReuseCfgAddRemoveConvert(entity.getAsnIpCfgs(),Constants.VALID_YES,null);
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();
List<IpCfg> ipRegionList = groupReuseCfgAddRemoveConvert(issuedList,Constants.VALID_NO,null);
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);
}
/**
* 选中组中是否含有只剩一个未删除IP的组
* @param serviceGroupIds
* @return
*/
public boolean hasLastIp(String serviceGroupIds,String ids) {
// TODO Auto-generated method stub
for(String groupId:serviceGroupIds.split(",")) {
Long.parseLong(groupId);
}
List<Integer> countList=asnIpCfgDao.countValidIPs(serviceGroupIds,ids);
if(countList.size()==0) {
return true;
}
for(Integer count:countList) {
if(count==0) {
return true;
}
}
return false;
}
}