diff --git a/src/main/java/com/nis/web/dao/basics/AsnIpCfgDao.java b/src/main/java/com/nis/web/dao/basics/AsnIpCfgDao.java index 7cd66e2ff..a66c37ea7 100644 --- a/src/main/java/com/nis/web/dao/basics/AsnIpCfgDao.java +++ b/src/main/java/com/nis/web/dao/basics/AsnIpCfgDao.java @@ -37,4 +37,5 @@ public interface AsnIpCfgDao extends CrudDao{ public void updateAsnIpByAsnGroups(@Param("entity")AsnIpCfg entity,@Param("asnGroups")List asnGroups,@Param("asnIds")String asnIds); public void deleteAll(); public List findAllAsnIpCfgList(); + public List getASNIPList(AsnIpCfg entity); } diff --git a/src/main/java/com/nis/web/dao/basics/AsnIpCfgDao.xml b/src/main/java/com/nis/web/dao/basics/AsnIpCfgDao.xml index 6eef95262..07db1be18 100644 --- a/src/main/java/com/nis/web/dao/basics/AsnIpCfgDao.xml +++ b/src/main/java/com/nis/web/dao/basics/AsnIpCfgDao.xml @@ -82,6 +82,9 @@ AND r.asn_Ip_Group =#{asnIpGroup,jdbcType=INTEGER} + + AND r.user_region1 =#{userRegion1,jdbcType=INTEGER} + AND r.CFG_REGION_CODE=#{cfgRegionCode,jdbcType=INTEGER} @@ -677,4 +680,13 @@ from asn_ip_cfg r where r.is_valid !=-1 + \ No newline at end of file diff --git a/src/main/java/com/nis/web/service/basics/AsnIpCfgService.java b/src/main/java/com/nis/web/service/basics/AsnIpCfgService.java index 33414817c..9e85408ca 100644 --- a/src/main/java/com/nis/web/service/basics/AsnIpCfgService.java +++ b/src/main/java/com/nis/web/service/basics/AsnIpCfgService.java @@ -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, AsnIpCfg> { } @Transactional(readOnly=false,rollbackFor=RuntimeException.class) public void update(AsnIpCfg entity){ + //checkAsnIp(entity); List auditAsnIpList=new ArrayList<>(); List auditAsnGroupList=new ArrayList<>(); Date editTime=new Date(); @@ -657,6 +659,76 @@ public class AsnIpCfgService extends CrudService, 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 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 nowIpList=IPUtil.getIPRange(nowIp,nowIpMask); + + //根据asn 和iptype 获取asn下的所有ip(除当前IP外的) + List 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 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(",")) { diff --git a/src/main/webapp/WEB-INF/views/basics/asnIpCfgList.jsp b/src/main/webapp/WEB-INF/views/basics/asnIpCfgList.jsp index ce2df59bb..4884af0d0 100644 --- a/src/main/webapp/WEB-INF/views/basics/asnIpCfgList.jsp +++ b/src/main/webapp/WEB-INF/views/basics/asnIpCfgList.jsp @@ -152,6 +152,14 @@ +
+
+
+ +
+ +
+