不能删除ASN 组中的最后一个ASN IP,做了前台Ajax验证

This commit is contained in:
wangxin
2018-09-03 13:02:24 +08:00
parent ff449143e6
commit ba295706f3
7 changed files with 63 additions and 9 deletions

View File

@@ -118,4 +118,12 @@ public class AsnIpController extends BaseController{
}
return false;
}
@RequestMapping(value="ajaxIsLast",method=RequestMethod.POST)
@ResponseBody
public boolean ajaxIsLast(Model model,@RequestParam(required=true,value="serviceGroupIds")String serviceGroupIds){
if(StringUtils.isNotBlank(serviceGroupIds)) {
return asnIpCfgService.hasLastIp(serviceGroupIds);
}
return false;
}
}

View File

@@ -18,4 +18,5 @@ public interface AsnIpCfgDao extends CrudDao<AsnIpCfg>{
public List<AsnIpCfg> findAllList(AsnIpCfg cfg);
public List<ConfigGroupInfo> findPolicyGroupInfosByType(@Param("groupId")Integer groupId);
public List<Integer> findOtherIps(@Param("groupId")Integer groupId,@Param("cfgId")Integer cfgId);
public List<Integer> countValidIPs(@Param("ids")String ids);
}

View File

@@ -381,10 +381,13 @@
from config_group_info c where c.group_type= #{groupId}
</select>
<select id="findOtherIps" resultType="java.lang.Integer" parameterType="java.lang.Integer">
select 1 from asn_ip_cfg where is_valid=1 and asn_ip_group=#{groupId} and cfg_id !=#{cfgId} limit 2
select 1 from asn_ip_cfg where is_valid=1 and asn_ip_group=#{groupId} and cfg_id !=#{cfgId} limit 1
</select>
<select id="hasGroupIds" resultType="java.lang.Integer" parameterType="java.lang.Integer">
select 1 from asn_ip_cfg where is_valid !=-1 and asn_ip_group in(${ids}) limit 2
select 1 from asn_ip_cfg where is_valid !=-1 and asn_ip_group in(${ids}) limit 1
</select>
<select id="countValidIPs" resultType="java.lang.Integer" parameterType="java.lang.Integer">
select count(1) from asn_ip_cfg where is_valid !=-1 and asn_ip_group in(${ids}) GROUP BY asn_ip_group;
</select>
</mapper>

View File

@@ -171,4 +171,22 @@ public class AsnIpCfgService extends CrudService<CrudDao<AsnIpCfg>, AsnIpCfg> {
// TODO Auto-generated method stub
return asnIpCfgDao.findPolicyGroupInfosByType(groupId);
}
/**
* 选中组中是否含有只剩一个未删除IP的组
* @param serviceGroupIds
* @return
*/
public boolean hasLastIp(String serviceGroupIds) {
// TODO Auto-generated method stub
for(String groupId:serviceGroupIds.split(",")) {
Long.parseLong(groupId);
}
List<Integer> countList=asnIpCfgDao.countValidIPs(serviceGroupIds);
for(Integer count:countList) {
if(count==1) {
return true;
}
}
return false;
}
}