分组配置管理删除分组下最后一条域配置时增加提示信息

This commit is contained in:
zhangwenqing
2019-06-11 17:25:10 +08:00
parent 2b23095c9d
commit bbda5e233f
17 changed files with 345 additions and 27 deletions

View File

@@ -21,7 +21,7 @@ public class IpCommCfg extends BaseCfg<IpCommCfg> {
super();
// TODO Auto-generated constructor stub
}
private static String indexTable="ip_comm_cfg";
private static final String indexTable="ip_comm_cfg";
/**
* ip类型
*/
@@ -300,12 +300,9 @@ public class IpCommCfg extends BaseCfg<IpCommCfg> {
this.direction = 0;
}
public String getIndexTable() {
public static String getIndexTable() {
return indexTable;
}
public void setIndexTable(String indexTable) {
this.indexTable = indexTable;
}
public Integer getIndex() {
return index;
}

View File

@@ -13,6 +13,7 @@ import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
@@ -83,6 +84,12 @@ public class CommonGroupManageController extends BaseController {
return "redirect:" + adminPath + "/basics/commonGroup/list";
}
@ResponseBody
@RequestMapping(value="ajaxCheckIsLastOneCfg",method=RequestMethod.POST)
public List<Integer> ajaxCheckIsLastOneCfg(Model model, String grouIdAndCfgId, Integer groupType){
return commonGroupManageService.ajaxCheckIsLastOneCfg(grouIdAndCfgId, groupType);
}
// 数据导出
@RequestMapping(value = "exportGroup")
public void exportGroup(Model model,@ModelAttribute("cfg")CommonGroupInfo entity,String ids,RedirectAttributes redirectAttributes,

View File

@@ -116,9 +116,9 @@ public class DomainCommGroupController extends BaseController{
}
@RequestMapping(value = {"/delete"})
public String delete(String compileIds, String ids, Integer functionId, RedirectAttributes redirectAttributes){
public String delete(String groupIds, String ids, Integer functionId, RedirectAttributes redirectAttributes){
try{
domainCommGroupService.delete(ids,compileIds);
domainCommGroupService.delete(ids,groupIds);
addMessage(redirectAttributes,"success","delete_success");
}catch(Exception e){
logger.error("Delete failed",e);

View File

@@ -125,9 +125,9 @@ public class IpCommGroupController extends BaseController {
@RequestMapping(value = { "/delete" })
@RequiresPermissions(value = { "ip:common:config" })
public String delete(String compileIds, String ids, Integer functionId, RedirectAttributes redirectAttributes) {
public String delete(String groupIds, String ids, Integer functionId, RedirectAttributes redirectAttributes) {
try {
ipCommGroupCfgService.delete(ids, compileIds);
ipCommGroupCfgService.delete(ids, groupIds);
addMessage(redirectAttributes, "success", "delete_success");
} catch (Exception e) {
logger.error("Delete failed", e);

View File

@@ -116,9 +116,9 @@ public class ScriberIdCommGroupController extends BaseController{
}
@RequestMapping(value = {"/delete"})
public String delete(String compileIds, String ids, Integer functionId, RedirectAttributes redirectAttributes){
public String delete(String groupIds, String ids, Integer functionId, RedirectAttributes redirectAttributes){
try{
scriberIdCommGroupService.delete(ids,compileIds);
scriberIdCommGroupService.delete(ids,groupIds);
addMessage(redirectAttributes,"success","delete_success");
}catch(Exception e){
logger.error("Delete failed",e);

View File

@@ -116,9 +116,9 @@ public class UrlCommGroupController extends BaseController{
}
@RequestMapping(value = {"/delete"})
public String delete(String compileIds, String ids, Integer functionId, RedirectAttributes redirectAttributes){
public String delete(String groupIds, String ids, Integer functionId, RedirectAttributes redirectAttributes){
try{
urlCommGroupService.delete(ids,compileIds);
urlCommGroupService.delete(ids,groupIds);
addMessage(redirectAttributes,"success","delete_success");
}catch(Exception e){
logger.error("Delete failed",e);

View File

@@ -22,4 +22,8 @@ public interface CommonGroupManageDao extends CrudDao<CommonGroupInfo> {
CommonGroupInfo getGroupInfo(CommonGroupInfo searchCfg);
Integer getCompileIdByGroupId(String groupId);
// 校验是否是当前引用Group的最后一条配置
public Integer ajaxCheckIsLastOneCfg(@Param("groupId")Integer groupId, @Param("cfgIds")String CfgIds, @Param("tableName")String indextable);
}

View File

@@ -205,5 +205,22 @@
</if>
</trim>
</select>
<select id="getCompileIdByGroupId" resultType="java.lang.Integer">
SELECT
compile_id
FROM
cfg_index_info
WHERE
common_group_ids LIKE concat(concat('%',#{groupId,jdbcType=VARCHAR}),'%') AND is_valid != -1
</select>
<select id="ajaxCheckIsLastOneCfg" resultType="java.lang.Integer">
SELECT
COUNT(1)
FROM
${tableName} r
WHERE
r.group_id = #{groupId} AND r.cfg_id NOT IN(${cfgIds})
</select>
</mapper>

View File

@@ -203,4 +203,55 @@ public class CommonGroupManageService extends BaseService{
}
/**
* 校验执行删除操作后分组下域配置是否为空
* @param serviceGroupIds
* @param groupType
* @return
*/
public List<Integer> ajaxCheckIsLastOneCfg(String grouIdAndCfgId, Integer groupType) {
// 组织格式
Map<Integer,List<Integer>> map = new HashMap<Integer,List<Integer>>();
for(String str : grouIdAndCfgId.split(",")) {
Integer groupId = Integer.valueOf(str.substring(0, str.indexOf("_")));
Integer cfgId = Integer.valueOf(str.substring(str.indexOf("_")+1));
if(map.containsKey(groupId)) {
List<Integer> list = map.get(groupId);
list.add(cfgId);
map.put(groupId, list);
}else {
List<Integer> list = new ArrayList<Integer>();
list.add(cfgId);
map.put(groupId, list);
}
}
List<Integer> resultList = new ArrayList<Integer>();
for (Integer groupId : map.keySet()) {
List<Integer> cfgIdList = map.get(groupId);
String cfgIds = "";
for (Integer cfgId : cfgIdList) {
cfgIds += "," + cfgId;
}
Integer size = 0;
if(groupType == 5) { // IP
size = commonGroupManageDao.ajaxCheckIsLastOneCfg(groupId, cfgIds.substring(1), IpCommCfg.getIndexTable());
}else if(groupType == 7) { // URL
size = commonGroupManageDao.ajaxCheckIsLastOneCfg(groupId, cfgIds.substring(1), UrlCommCfg.getTablename());
}else if(groupType == 8) { // Domain
size = commonGroupManageDao.ajaxCheckIsLastOneCfg(groupId, cfgIds.substring(1), DomainCommCfg.getTablename());
}else if(groupType == 9) { // ScriberId
size = commonGroupManageDao.ajaxCheckIsLastOneCfg(groupId, cfgIds.substring(1), ScriberIdCommCfg.getTablename());
}
if(size == 0) { // 0为分组下的最后一条配置获取配置ID提示
Integer compileId = commonGroupManageDao.getCompileIdByGroupId(","+groupId+",");
if(compileId != null) {
resultList.add(compileId);
}
}
}
return resultList;
}
}

View File

@@ -128,8 +128,8 @@ public class IpCommGroupCfgService extends BaseService {
}
public void delete(String ids, String compileIds) {
List<PolicyGroupInfo> policyGroupInfos=policyGroupInfoDao.findPolicyByServiceGroupInfoList(compileIds);
public void delete(String ids, String groupIds) {
List<PolicyGroupInfo> policyGroupInfos=policyGroupInfoDao.findPolicyByServiceGroupInfoList(groupIds);
if(ids==null) {
throw new RuntimeException("ids is null!");
}