IP增加交集校验方法,暂时不开放
This commit is contained in:
@@ -37,4 +37,5 @@ public interface AsnIpCfgDao extends CrudDao<AsnIpCfg>{
|
||||
public void updateAsnIpByAsnGroups(@Param("entity")AsnIpCfg entity,@Param("asnGroups")List<AsnGroupInfo> asnGroups,@Param("asnIds")String asnIds);
|
||||
public void deleteAll();
|
||||
public List<Object[]> findAllAsnIpCfgList();
|
||||
public List<AsnIpCfg> getASNIPList(AsnIpCfg entity);
|
||||
}
|
||||
|
||||
@@ -82,6 +82,9 @@
|
||||
<if test="asnIpGroup != null and asnIpGroup != ''">
|
||||
AND r.asn_Ip_Group =#{asnIpGroup,jdbcType=INTEGER}
|
||||
</if>
|
||||
<if test="userRegion1 != null and userRegion1 != ''">
|
||||
AND r.user_region1 =#{userRegion1,jdbcType=INTEGER}
|
||||
</if>
|
||||
<if test="cfgRegionCode != null">
|
||||
AND r.CFG_REGION_CODE=#{cfgRegionCode,jdbcType=INTEGER}
|
||||
</if>
|
||||
@@ -677,4 +680,13 @@
|
||||
from asn_ip_cfg r
|
||||
where r.is_valid !=-1
|
||||
</select>
|
||||
<select id="getASNIPList" resultMap="asnIpCfgMap" >
|
||||
select
|
||||
cfg_id,dest_ip_address
|
||||
from asn_ip_cfg r
|
||||
where r.is_valid!=-1
|
||||
and r.is_audit!=3
|
||||
and r.ip_type=#{ipType}
|
||||
and r.user_region1 = #{userRegion1}
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -37,6 +37,7 @@ import com.nis.domain.specific.ConfigGroupInfo;
|
||||
import com.nis.exceptions.MaatConvertException;
|
||||
import com.nis.util.ConfigServiceUtil;
|
||||
import com.nis.util.Constants;
|
||||
import com.nis.util.IPUtil;
|
||||
import com.nis.util.StringUtil;
|
||||
import com.nis.web.dao.CrudDao;
|
||||
import com.nis.web.dao.basics.AsnGroupInfoDao;
|
||||
@@ -104,6 +105,7 @@ public class AsnIpCfgService extends CrudService<CrudDao<AsnIpCfg>, AsnIpCfg> {
|
||||
}
|
||||
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
|
||||
public void update(AsnIpCfg entity){
|
||||
//checkAsnIp(entity);
|
||||
List<AsnIpCfg> auditAsnIpList=new ArrayList<>();
|
||||
List<AsnGroupInfo> auditAsnGroupList=new ArrayList<>();
|
||||
Date editTime=new Date();
|
||||
@@ -657,6 +659,76 @@ public class AsnIpCfgService extends CrudService<CrudDao<AsnIpCfg>, AsnIpCfg> {
|
||||
asnIPRegionSendToMaat(auditAsnIpList,Constants.VALID_YES,Constants.OPACTION_POST);
|
||||
}*/
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算用户修改后的IP段
|
||||
* @param entity
|
||||
*/
|
||||
public void checkAsnIp(AsnIpCfg entity) {
|
||||
long start=System.currentTimeMillis();
|
||||
logger.info("开始计算ASN IP:");
|
||||
List<String[]> resultIpList=new ArrayList<>();
|
||||
boolean flag=true;
|
||||
if(!StringUtil.isEmpty(entity.getId())) {
|
||||
AsnIpCfg oldAsnIp=asnIpCfgDao.getOne(entity);
|
||||
if(oldAsnIp.getDestIpAddress().equals(entity.getDestIpAddress())) {
|
||||
flag=false;
|
||||
}
|
||||
}
|
||||
//开始校验
|
||||
if(flag) {
|
||||
String nowIp=entity.getDestIpAddress().split("/")[0];
|
||||
int nowIpMask=Integer.parseInt(entity.getDestIpAddress().split("/")[1]);
|
||||
List<String> nowIpList=IPUtil.getIPRange(nowIp,nowIpMask);
|
||||
|
||||
//根据asn 和iptype 获取asn下的所有ip(除当前IP外的)
|
||||
List<AsnIpCfg> asnIpList=asnIpCfgDao.getASNIPList(entity);
|
||||
int equal=0;
|
||||
int containsLeftAndRight=0;
|
||||
int containsLeft=0;
|
||||
int containsRight=0;
|
||||
int whithoutLeftAndRight=0;
|
||||
String equalStr="";
|
||||
String containsLeftAndRightStr="";
|
||||
String containsLeftStr="";
|
||||
String containsRightStr="";
|
||||
String whithoutLeftAndRightStr="";
|
||||
for (AsnIpCfg asnIpCfg : asnIpList) {
|
||||
String ip=asnIpCfg.getDestIpAddress().split("/")[0];
|
||||
int ipMask=Integer.parseInt(asnIpCfg.getDestIpAddress().split("/")[1]);
|
||||
List<String> ipList=IPUtil.getIPRange(ip, ipMask);
|
||||
//左等 && 右等
|
||||
if((nowIpList.get(0).equals(ipList.get(0))) && (nowIpList.get(nowIpList.size()-1).equals(ipList.get(ipList.size()-1)))) {
|
||||
equal++;
|
||||
equalStr+=asnIpCfg.getDestIpAddress()+",";
|
||||
//左在里面,右在里面
|
||||
}else if((ipList.contains(nowIpList.get(0))) && (ipList.contains(nowIpList.get(nowIpList.size()-1)))) {
|
||||
containsLeftAndRight++;
|
||||
containsLeftAndRightStr+=asnIpCfg.getDestIpAddress()+",";
|
||||
//只有左在里面
|
||||
}else if(ipList.contains(nowIpList.get(0))){
|
||||
containsLeft++;
|
||||
containsLeftStr+=asnIpCfg.getDestIpAddress()+",";
|
||||
//只有右在里面
|
||||
}else if(ipList.contains(nowIpList.get(nowIpList.size()-1))){
|
||||
containsRight++;
|
||||
containsRightStr+=asnIpCfg.getDestIpAddress()+",";
|
||||
//旧的左右都在新的里面
|
||||
}else if(nowIpList.contains(ipList.get(ipList.size()-1)) && nowIpList.contains(ipList.get(0))){
|
||||
whithoutLeftAndRight++;
|
||||
whithoutLeftAndRightStr+=asnIpCfg.getDestIpAddress()+",";
|
||||
}
|
||||
}
|
||||
logger.info("完全匹配:("+equal+")"+equalStr);
|
||||
logger.info("中间交集(被包含):("+containsLeftAndRight+")"+containsLeftAndRightStr);
|
||||
logger.info("左侧交集:("+containsLeft+")"+containsLeftStr);
|
||||
logger.info("右侧交集:("+containsLeft+")"+containsLeftStr);
|
||||
logger.info("中间交集(包含):("+whithoutLeftAndRight+")"+whithoutLeftAndRightStr);
|
||||
}
|
||||
long end=System.currentTimeMillis();
|
||||
logger.info("结束计算ASN IP:"+(end-start));
|
||||
}
|
||||
|
||||
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
|
||||
public void delete(String ids) {
|
||||
/*for(String id:ids.split(",")) {
|
||||
|
||||
@@ -152,6 +152,14 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="pull-left">
|
||||
<div class="input-group">
|
||||
<div class="input-group-btn">
|
||||
<span class="form-control" ><spring:message code="asn_no"/></span>
|
||||
</div>
|
||||
<input name="userRegion1" id="userRegion1" type="text" class="form-control input-medium" value="${cfg.userRegion1}" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="pull-left">
|
||||
<button type="button" class="btn blue" onClick="return page()"> <i class="fa fa-search"></i> <spring:message code="search"/> </button>
|
||||
<button type="button" class="btn btn-default" id="resetBtn"> <i class="fa fa-refresh"></i> <spring:message code="reset"/> </button>
|
||||
|
||||
Reference in New Issue
Block a user