不能删除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;
}
}

View File

@@ -1138,4 +1138,5 @@ is_issued=Is Issued
asn_ip_configuration=ASN IP Configuration
asn_policy=ASN Policy
asn_ip_group=ASN IP Group
can_not_delete_has_ip_asn_group=Can not delete ASN group which has ASN IP
can_not_delete_has_ip_asn_group=Can not delete ASN group which has ASN IP
last_ip_in_asn_group=Can not delete last IP in an ASN group

View File

@@ -1135,4 +1135,5 @@ is_issued=\u662F\u5426\u4E0B\u53D1
asn_ip_configuration=ASN IP\u914D\u7F6E
asn_policy=ASN\u7B56\u7565
asn_ip_group=ASN IP\u7EC4
can_not_delete_has_ip_asn_group=\u4E0D\u80FD\u5220\u9664\u5305\u542BASN IP\u7684 ASN\u7EC4
can_not_delete_has_ip_asn_group=\u4E0D\u80FD\u5220\u9664\u5305\u542BASN IP\u7684 ASN\u7EC4
last_ip_in_asn_group=\u4E0D\u80FD\u5220\u9664ASN\u7EC4\u4E2D\u7684\u6700\u540E\u4E00\u4E2AIP

View File

@@ -49,13 +49,35 @@ function del(url){
if(validateAllNoAudit(checkboxes)){
top.$.jBox.tip("<spring:message code='has_prohibit_delete'/>", "<spring:message code='info'/>");
return;
}else{
doAll(checkboxes,url);
}else{
var serviceGroupIds=[],canDel=true;
$(checkboxes).filter(":checked").each(function(){
if($(this).attr("serviceGroupId")){
serviceGroupIds.push($(this).attr("serviceGroupId"));
}
}else{
top.$.jBox.tip("<spring:message code='one_more'/>", "<spring:message code='info'/>");
return;
})
if(serviceGroupIds.length>0){
$.ajax({
type:'post',
url:'${ctx}/basics/asn/ajaxIsLast',
data:{"serviceGroupIds":serviceGroupIds.join(',')},
async:false,
success:function(data,textStatus){//处理返回结果
if(data){
top.$.jBox.tip('<spring:message code="last_ip_in_asn_group"/>');
canDel=false;
}
}
});
}
if(canDel){
doAll(checkboxes,url);
}
}
}else{
top.$.jBox.tip("<spring:message code='one_more'/>", "<spring:message code='info'/>");
return;
}
}
//修改配置
function update(url){