IP公共组配置部分功能提交

This commit is contained in:
zhangwenqing
2019-06-03 14:53:39 +08:00
parent 28da266944
commit 8c766e90a8
19 changed files with 3961 additions and 4 deletions

View File

@@ -0,0 +1,74 @@
package com.nis.domain.basics;
import java.io.Serializable;
import java.util.Date;
import com.nis.domain.configuration.BaseCfg;
import com.nis.util.excel.ExcelField;
/**
* 公共分组实体
*/
public class CommonGroupInfo extends BaseCfg<CommonGroupInfo> implements Serializable{
/**
*
*/
private static final long serialVersionUID = 7931466570918016654L;
private Integer groupId;
@ExcelField(title="group_name",sort=1)
private String groupName;
@ExcelField(title="group_type",dictType="GROUP_TYPE",sort=2)
private Integer groupType;
private Integer serviceGroupId;
@ExcelField(title="desc",sort=4)
private String description;
public Integer getServiceGroupId() {
return serviceGroupId;
}
public void setServiceGroupId(Integer serviceGroupId) {
this.serviceGroupId = serviceGroupId;
}
public Integer getGroupId() {
return groupId;
}
public void setGroupId(Integer groupId) {
this.groupId = groupId;
}
public String getGroupName() {
return groupName;
}
public void setGroupName(String groupName) {
this.groupName = groupName;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public Date getEditTime() {
return editTime;
}
public void setEditTime(Date editTime) {
this.editTime = editTime;
}
public Integer getGroupType() {
return groupType;
}
public void setGroupType(Integer groupType) {
this.groupType = groupType;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
}

View File

@@ -0,0 +1,315 @@
package com.nis.domain.basics;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
import com.nis.domain.configuration.BaseCfg;
import com.nis.util.excel.ExcelField;
public class IpCommCfg extends BaseCfg<IpCommCfg> {
/**
*
*/
private static final long serialVersionUID = 4218856118489784060L;
/**
* 创建一个新的实例 BaseIpCfg.
*
*/
public IpCommCfg() {
super();
// TODO Auto-generated constructor stub
}
private String indexTable="ip_comm_cfg";
/**
* ip类型
*/
@Expose
@SerializedName("ipType")
@ExcelField(title="ip_type",dictType="IP_TYPE",sort=50)
protected Integer ipType;
@ExcelField(title="src_ip_pattern",dictType="IP_PATTERN",sort=51)
protected Integer srcIpPattern;
@ExcelField(title="client_ip",sort=52)
protected String srcIpAddress;
@ExcelField(title="dest_ip_pattern",dictType="IP_PATTERN",sort=53)
protected Integer destIpPattern;
@ExcelField(title="server_ip",sort=54)
protected String destIpAddress;
@ExcelField(title="src_port_pattern",dictType="PORT_PATTERN",sort=54)
protected Integer srcPortPattern;
@ExcelField(title="dest_port_pattern",dictType="PORT_PATTERN",sort=54)
protected Integer destPortPattern;
@ExcelField(title="client_port",sort=55)
protected String srcPort;
@ExcelField(title="server_port",sort=56)
protected String destPort;
protected Integer dnsStrategyId;
@ExcelField(title="ir_type",dictType="IR_TYPE",sort=57)
protected Integer irType;
@ExcelField(title="group_name",sort=58)
protected String groupName;
// @ExcelField(title="log_total",sort=42)
private Long totalLogs;
private Integer regionId;
private Integer groupId;
public Integer getRegionId() {
return regionId;
}
public void setRegionId(Integer regionId) {
this.regionId = regionId;
}
public Integer getGroupId() {
return groupId;
}
public void setGroupId(Integer groupId) {
this.groupId = groupId;
}
public Long getTotalLogs() {
return totalLogs;
}
public void setTotalLogs(Long totalLogs) {
this.totalLogs = totalLogs;
}
/**
* irType
* @return irType
*/
public Integer getIrType() {
return irType;
}
/**
* @param irType the irType to set
*/
public void setIrType(Integer irType) {
this.irType = irType;
}
/**
* groupName
* @return groupName
*/
public String getGroupName() {
return groupName;
}
/**
* @param groupName the groupName to set
*/
public void setGroupName(String groupName) {
this.groupName = groupName;
}
/**
* 方向
*/
@Expose
@SerializedName("direction")
@ExcelField(title="direction",dictType="DIRECTION",sort=58)
protected Integer direction ;
/**
* 协议
*/
@Expose
@SerializedName("protocol")
@ExcelField(title="protocol",dictType="PROTOCOL",sort=59)
protected Integer protocol ;
/**
* 协议ID
*/
@Expose
@SerializedName("protocolId")
protected Integer protocolId ;
/**
* 限速比例
*/
protected String ratelimit ;
/**
* ratelimit
* @return ratelimit
*/
public String getRatelimit() {
return ratelimit;
}
/**
* @param ratelimit the ratelimit to set
*/
public void setRatelimit(String ratelimit) {
this.ratelimit = ratelimit;
}
/**
* ipType
* @return ipType
*/
public Integer getIpType() {
return ipType;
}
/**
* @param ipType the ipType to set
*/
public void setIpType(Integer ipType) {
this.ipType = ipType;
}
/**
* direction
* @return direction
*/
public Integer getDirection() {
return direction;
}
/**
* @param direction the direction to set
*/
public void setDirection(Integer direction) {
this.direction = direction;
}
/**
* protocol
* @return protocol
*/
public Integer getProtocol() {
return protocol;
}
/**
* @param protocol the protocol to set
*/
public void setProtocol(Integer protocol) {
this.protocol = protocol;
}
/**
* protocolId
* @return protocolId
*/
public Integer getProtocolId() {
return protocolId;
}
/**
* @param protocolId the protocolId to set
*/
public void setProtocolId(Integer protocolId) {
this.protocolId = protocolId;
}
public Integer getSrcIpPattern() {
return srcIpPattern;
}
public void setSrcIpPattern(Integer srcIpPattern) {
this.srcIpPattern = srcIpPattern;
}
public Integer getDestIpPattern() {
return destIpPattern;
}
public void setDestIpPattern(Integer destIpPattern) {
this.destIpPattern = destIpPattern;
}
public Integer getSrcPortPattern() {
return srcPortPattern;
}
public void setSrcPortPattern(Integer srcPortPattern) {
this.srcPortPattern = srcPortPattern;
}
public Integer getDestPortPattern() {
return destPortPattern;
}
public void setDestPortPattern(Integer destPortPattern) {
this.destPortPattern = destPortPattern;
}
/**
* srcIpAddress
* @return srcIpAddress
*/
public String getSrcIpAddress() {
return srcIpAddress;
}
/**
* @param srcIpAddress the srcIpAddress to set
*/
public void setSrcIpAddress(String srcIpAddress) {
this.srcIpAddress = srcIpAddress;
}
/**
* destIpAddress
* @return destIpAddress
*/
public String getDestIpAddress() {
return destIpAddress;
}
/**
* @param destIpAddress the destIpAddress to set
*/
public void setDestIpAddress(String destIpAddress) {
this.destIpAddress = destIpAddress;
}
/**
* srcPort
* @return srcPort
*/
public String getSrcPort() {
return srcPort;
}
/**
* @param srcPort the srcPort to set
*/
public void setSrcPort(String srcPort) {
this.srcPort = srcPort;
}
/**
* destPort
* @return destPort
*/
public String getDestPort() {
return destPort;
}
/**
* @param destPort the destPort to set
*/
public void setDestPort(String destPort) {
this.destPort = destPort;
}
/**
* dnsStrategyId
* @return dnsStrategyId
*/
public Integer getDnsStrategyId() {
return dnsStrategyId;
}
/**
* @param dnsStrategyId the dnsStrategyId to set
*/
public void setDnsStrategyId(Integer dnsStrategyId) {
this.dnsStrategyId = dnsStrategyId;
}
@Override
public void initDefaultValue(){
super.initDefaultValue();
this.direction = 0;
}
public String getIndexTable() {
return indexTable;
}
public void setIndexTable(String indexTable) {
this.indexTable = indexTable;
}
public Integer getIndex() {
return index;
}
public void setIndex(Integer index) {
this.index = index;
}
}

View File

@@ -78,6 +78,14 @@ public class BaseCfg<T> extends BaseEntity<T> implements Cloneable{
protected ScheduleCfg schedule;
private String commonGroupIds; //公共组织id(考虑一个compile存在多个asn组织的情况)
protected Integer groupType; //url组以及dns组相关功能使用
protected Integer udFlag; //url组以及dns组相关功能使用 过滤数据库数据标记
public Integer getGroupType() {
return groupType;
}
public void setGroupType(Integer groupType) {
this.groupType = groupType;
}
public String getCommonGroupIds() {
return commonGroupIds;
}
@@ -85,8 +93,12 @@ public class BaseCfg<T> extends BaseEntity<T> implements Cloneable{
public void setCommonGroupIds(String commonGroupIds) {
this.commonGroupIds = commonGroupIds;
}
public Integer getUdFlag() {
return udFlag;
}
public void setUdFlag(Integer udFlag) {
this.udFlag = udFlag;
}
public String getExType() {
return exType;

View File

@@ -14,7 +14,9 @@ import java.util.Map;
import com.google.gson.annotations.Expose;
import com.nis.domain.basics.AsnGroupInfo;
import com.nis.domain.basics.AsnIpCfg;
import com.nis.domain.basics.IpCommCfg;
import com.nis.domain.basics.IpReuseIpCfg;
import com.nis.domain.basics.UrlCommCfg;
import com.nis.util.Constants;
import com.nis.util.excel.ExcelField;
@@ -88,8 +90,8 @@ public class CfgIndexInfo extends BaseCfg<CfgIndexInfo> {
private List<AsnKeywordCfg> asnKeywords;
@ExcelField(title="log_total",sort=42)
private Long totalLogs;
private List<UrlCommCfg> urlCommGroupList;
private List<IpCommCfg> ipCommGroupCfgList;
/*private CachePolicyUserRegion cachePolicyUserRegion;//缓存策略用户自定义域参数
public static class CachePolicyUserRegion{
@@ -101,6 +103,12 @@ public class CfgIndexInfo extends BaseCfg<CfgIndexInfo> {
public String getOrganization() {
return organization;
}
public List<IpCommCfg> getIpCommGroupCfgList() {
return ipCommGroupCfgList;
}
public void setIpCommGroupCfgList(List<IpCommCfg> ipCommGroupCfgList) {
this.ipCommGroupCfgList = ipCommGroupCfgList;
}
public List<AsnKeywordCfg> getAsnKeywords() {
return asnKeywords;
}
@@ -411,4 +419,11 @@ public class CfgIndexInfo extends BaseCfg<CfgIndexInfo> {
public void setTotalLogs(Long totalLogs) {
this.totalLogs = totalLogs;
}
public List<UrlCommCfg> getUrlCommGroupList() {
return urlCommGroupList;
}
public void setUrlCommGroupList(List<UrlCommCfg> urlCommGroupList) {
this.urlCommGroupList = urlCommGroupList;
}
}

View File

@@ -0,0 +1,47 @@
package com.nis.domain.configuration.template;
import com.nis.util.excel.ExcelField;
public class IpCommCfgTemplate extends IpAllTemplate{
@ExcelField(title="ip_group",align=2,sort=10)
private Integer groupId;
public Integer getGroupId() {
return groupId;
}
public void setGroupId(Integer groupId) {
this.groupId = groupId;
}
/* @Override
public String getSrcIpAddress() {
// TODO Auto-generated method stub
return super.getSrcIpAddress();
}
@Override
public String getSrcPort() {
// TODO Auto-generated method stub
return super.getSrcPort();
}
@Override
public String getDestPort() {
// TODO Auto-generated method stub
return super.getDestPort();
}
@Override
public Integer getProtocol() {
// TODO Auto-generated method stub
return super.getProtocol();
}
@Override
public Integer getDirection() {
// TODO Auto-generated method stub
return super.getDirection();
}*/
}

View File

@@ -162,6 +162,7 @@ import com.nis.web.service.SystemService;
import com.nis.web.service.UserService;
import com.nis.web.service.basics.AsnGroupInfoService;
import com.nis.web.service.basics.AsnIpCfgService;
import com.nis.web.service.basics.CommonGroupManageService;
import com.nis.web.service.basics.InnerProtectionListService;
import com.nis.web.service.basics.IpReuseIpCfgService;
import com.nis.web.service.basics.PolicyGroupInfoService;
@@ -358,6 +359,9 @@ public class BaseController {
@Autowired
protected ManipulatPolicyService manipulatPolicyService;
@Autowired
protected CommonGroupManageService commonGroupManageService;
/**
* 管理基础路径
*/

View File

@@ -0,0 +1,159 @@
package com.nis.web.controller.basics;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
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;
import com.nis.domain.Page;
import com.nis.domain.basics.CommonGroupInfo;
import com.nis.domain.basics.PolicyGroupInfo;
import com.nis.util.Constants;
import com.nis.util.LogUtils;
import com.nis.util.StringUtil;
import com.nis.web.controller.BaseController;
import com.nis.web.service.basics.CommonGroupManageService;
/**
* 公共组管理
*/
@Controller
@RequestMapping(value = "${adminPath}/basics/commonGroup")
public class CommonGroupManageController extends BaseController {
@Autowired
private CommonGroupManageService commonGroupManageService;
@RequestMapping(value = {"list", ""})
public String policyGroupList(CommonGroupInfo cfg, Model model, HttpServletRequest request, HttpServletResponse response) {
if(cfg == null)cfg=new CommonGroupInfo();
Page<CommonGroupInfo> pageCondition = new Page<CommonGroupInfo>(request, response,"r");
Page page = commonGroupManageService.findCommonGroupInfoList(pageCondition,cfg);
model.addAttribute("cfg", cfg);
model.addAttribute("page", page);
return "/basics/commonGroupList";
}
@RequestMapping(value={"/form"})
public String form(Integer groupType,String ids,Model model,String doAction,RedirectAttributes redirectAttributes) {
CommonGroupInfo groupInfo = new CommonGroupInfo();
if(!StringUtil.isEmpty(ids)){
groupInfo = commonGroupManageService.getById(Integer.parseInt(ids));
}
//groupInfo.setGroupType(groupType);
model.addAttribute("_cfg", groupInfo);
return "/basics/commonGroupForm";
}
@RequestMapping(value = "saveOrUpdate")
public String saveOrUpdate(CommonGroupInfo cfg, Model model, RedirectAttributes redirectAttributes,
String itType,Integer groupType,HttpServletRequest request) {
try {
commonGroupManageService.saveOrUpdate(cfg);
addMessage(redirectAttributes,"success","save_success");
} catch (Exception e) {
logger.error("新增失败",e);
addMessage(redirectAttributes,"error","save_failed");
LogUtils.saveLog(request, null, e, null);
}
return "redirect:" + adminPath + "/basics/commonGroup/list";
}
@RequestMapping(value={"delete"})
public String delete(RedirectAttributes redirectAttributes, Integer groupType,String ids,int isValid,HttpServletRequest request) {
try {
commonGroupManageService.deldete(ids,isValid);
addMessage(redirectAttributes,"success","delete_success");
} catch (Exception e) {
logger.error("删除失败",e);
addMessage(redirectAttributes,"error","delete_failed");
LogUtils.saveLog(request, null, e, null);
}
return "redirect:" + adminPath + "/basics/commonGroup/list";
}
@ResponseBody
@RequestMapping(value="ajaxCheckGroupUse")
public boolean ajaxCheckGroupUse(@RequestParam("groupIds")String groupIds){
return commonGroupManageService.checkIsIssued(groupIds);
}
//Group配置导出
@RequestMapping(value = "exportGroup")
public void exportGroup(Model model,HttpServletRequest request,HttpServletResponse response,
@ModelAttribute("cfg")CommonGroupInfo entity,String ids,RedirectAttributes redirectAttributes){
try {
//export data info
entity.setMenuNameCode("common_group_manage");
List<String> titleList=new ArrayList<String>();
Map<String, Class<?>> classMap=new HashMap<String, Class<?>>();
Map<String, List> dataMap=new HashMap<String, List>();
Map<String, String> noExportMap=new HashMap<String, String>();
List<CommonGroupInfo> list = new ArrayList<CommonGroupInfo>();
if (!StringUtil.isEmpty(ids)) {
list = commonGroupManageService.findGroupInfoList(ids);
} else {
Page<CommonGroupInfo> pageInfo=new Page<CommonGroupInfo>(request, response,"r");
pageInfo.setPageNo(1);
pageInfo.setPageSize(Constants.MAX_EXPORT_SIZE);
Page page = commonGroupManageService.findCommonGroupInfoList(pageInfo,entity);
list=page.getList();
}
titleList.add(entity.getMenuNameCode());
classMap.put(entity.getMenuNameCode(), CommonGroupInfo.class);
String cfgIndexInfoNoExport=",config_describe,cfg_id,block_type,do_log,action,valid_identifier,is_audit"
+ ",auditor,audit_time,letter,whether_area_block,classification,attribute,label"
+",userregion1,userregion2,userregion3,userregion4,userregion5,ir_type,";
// 时间过滤
if (entity.getSearch_create_time_start() == null ) {
cfgIndexInfoNoExport = ",config_time" + cfgIndexInfoNoExport;
}
if (entity.getSearch_edit_time_start() == null) {
cfgIndexInfoNoExport = ",edit_time" + cfgIndexInfoNoExport;
}
if (!StringUtil.isEmpty(entity.gethColumns())) {
cfgIndexInfoNoExport = "," + entity.gethColumns() + "," + cfgIndexInfoNoExport;
}
noExportMap.put(entity.getMenuNameCode(),cfgIndexInfoNoExport);
dataMap.put(entity.getMenuNameCode(), list);
String timeRange = initTimeMap(entity);
noExportMap.put("timeRange", timeRange);
if ("csv".equals(entity.getExType())) {
this._exportCsv(model, request, response, redirectAttributes, entity.getMenuNameCode(), titleList,
classMap, dataMap, noExportMap);
} else {
this._export(model, request, response, redirectAttributes, entity.getMenuNameCode(), titleList,
classMap, dataMap, noExportMap);
}
} catch (Exception e) {
logger.error("Group export failed",e);
addMessage(redirectAttributes,"error","export_failed");
LogUtils.saveLog(request, null, e, null);
}
//return "redirect:" + adminPath +"/ntc/iplist/list?functionId="+entity.getFunctionId();
}
}

View File

@@ -0,0 +1,479 @@
package com.nis.web.controller.basics;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.BlockingQueue;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.jets3t.service.ServiceException;
import org.springframework.beans.factory.annotation.Autowired;
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.multipart.MultipartFile;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import com.beust.jcommander.internal.Lists;
import com.nis.domain.FunctionRegionDict;
import com.nis.domain.FunctionServiceDict;
import com.nis.domain.Page;
import com.nis.domain.basics.CommonGroupInfo;
import com.nis.domain.basics.IpCommCfg;
import com.nis.domain.basics.PolicyGroupInfo;
import com.nis.domain.configuration.BaseIpCfg;
import com.nis.domain.configuration.CfgIndexInfo;
import com.nis.domain.configuration.IpPortCfg;
import com.nis.domain.configuration.template.IpCommCfgTemplate;
import com.nis.domain.specific.ConfigGroupInfo;
import com.nis.exceptions.MaatConvertException;
import com.nis.util.Constants;
import com.nis.util.DictUtils;
import com.nis.util.StringUtil;
import com.nis.util.excel.ImportBigExcel;
import com.nis.web.controller.BaseController;
import com.nis.web.security.UserUtils;
import com.nis.web.service.basics.IpCommGroupCfgService;
@Controller
@RequestMapping(value = "${adminPath}/basics/ip")
public class IpCommGroupController extends BaseController {
@Autowired
private IpCommGroupCfgService ipCommGroupCfgService;
@RequestMapping(value = { "/list" })
public String list(Model model, @ModelAttribute("cfg") IpCommCfg entity, HttpServletRequest request, HttpServletResponse response) {
Page<IpCommCfg> page = ipCommGroupCfgService.findPage(new Page<IpCommCfg>(request, response, "r"),entity);
List<FunctionRegionDict> regionList = DictUtils.getFunctionRegionDictList(entity.getFunctionId());
List<FunctionServiceDict> serviceList = DictUtils.getFunctionServiceDictList(entity.getFunctionId());
List<CommonGroupInfo> policyGroupInfos=commonGroupManageService.findCommonGroupInfosByType(5);
model.addAttribute("page", page);
model.addAttribute("regionList", regionList);
model.addAttribute("serviceList", serviceList);
model.addAttribute("policyGroupInfos", policyGroupInfos);
return "/basics/ipCommonGroupCfgList";
}
@RequestMapping(value = { "/addForm" })
public String addForm(Model model, @ModelAttribute("cfg") CfgIndexInfo cfg, RedirectAttributes redirectAttributes,
HttpServletRequest request, HttpServletResponse response) {
// IP Group Tyep为5
cfg.setGroupType(5);
initFormCondition(model, cfg);
List<CommonGroupInfo> groupInfos=commonGroupManageService.findCommonGroupInfosByType(5);
model.addAttribute("policyGroupInfos", groupInfos);
model.addAttribute("_cfg", cfg);
return "/basics/ipCommGroupFormAdd";
}
@RequestMapping(value = { "/save" })
@RequiresPermissions(value = { "ip:common:config" })
public String save(Model model, @ModelAttribute("cfg") CfgIndexInfo cfg, RedirectAttributes redirectAttributes,
HttpServletRequest request, HttpServletResponse response) {
try {
ipCommGroupCfgService.saveIpCommGroupCfg(cfg);
} catch (Exception e) {
logger.error("信息保存失败", e);
if (e instanceof MaatConvertException) {
addMessage(redirectAttributes, "error", e.getMessage());
} else {
addMessage(redirectAttributes, "error", "save_failed");
}
}
return "redirect:" + adminPath + "/basics/ip/list?functionId=" + cfg.getFunctionId();
}
@RequestMapping(value = { "/updateForm" })
public String updateForm(Model model, @ModelAttribute("cfg") IpCommCfg cfg, RedirectAttributes redirectAttributes, String ids,
HttpServletRequest request, HttpServletResponse response) {
cfg = ipCommGroupCfgService.get(Long.parseLong(ids));
// initUpdateFormCondition(model, cfg);
cfg.setGroupType(5);
initUpdateFormCondition(model, cfg);
List<CommonGroupInfo> groupInfos=commonGroupManageService.findCommonGroupInfosByType(5);
model.addAttribute("policyGroupInfos", groupInfos);
model.addAttribute("_cfg", cfg);
return "/basics/ipCommGroupFormUpdate";
}
@RequestMapping(value = { "/update" })
@RequiresPermissions(value = { "ip:common:config" })
public String update(Model model, HttpServletRequest request, HttpServletResponse response,
@ModelAttribute("cfg") IpCommCfg cfg, RedirectAttributes redirectAttributes) {
try {
ipCommGroupCfgService.update(cfg);
addMessage(redirectAttributes, "success", "save_success");
} catch (Exception e) {
logger.error("信息保存失败", e);
addMessage(redirectAttributes, "error", "save_failed");
}
return "redirect:" + adminPath + "/basics/ip/list?functionId=" + cfg.getFunctionId();
}
// @RequestMapping(value = { "/audit" })
// @RequiresPermissions(value = { "ip:common:config" })
// public String audit(Model model, @ModelAttribute("cfg") IpCommCfg cfg, Integer isAudit, Integer isValid,
// String ids, Integer functionId, HttpServletRequest request, HttpServletResponse response,
// RedirectAttributes redirectAttributes) {
// // 选中配置审核
// if (!StringUtil.isEmpty(ids)) {
// List<IpCommCfg> ipGroupCfgs = ipCommGroupCfgService.getByIds(ids);
// List<IpCommCfg> temp = Lists.newArrayList();
// try {
// ipCommGroupCfgService.audit(ipGroupCfgs, isAudit, isValid);
// } catch (Exception e) {
// logger.error("审核失败", e);
// addMessage(redirectAttributes, "error", "audit_failed");
// } finally {
// temp.clear();
// }
// return "redirect:" + adminPath + "/basics/ip/list?functionId=" + cfg.getFunctionId();
// } else {// 全部审核
// // 条件下所有配置审核
// Page<IpCommCfg> searchPage = new Page<IpCommCfg>(request, response, "a");
// Page<IpCommCfg> auditPage = new Page<IpCommCfg>(request, response, "a");
// BeanUtils.copyProperties(searchPage, auditPage);
//
// try {
// auditAll(auditPage, isValid, cfg);
// addMessage(redirectAttributes, "success", "audit_success");
// } catch (Exception e) {
// logger.error("配置下发失败:", e);
// if (e instanceof MaatConvertException) {
// addMessage(redirectAttributes, "error", "request_service_failed");
// } else {
// addMessage(redirectAttributes, "error", "audit_failed");
// }
//
// }
//
// return list(model, request, response, cfg);
// }
// }
@RequestMapping(value = { "/delete" })
@RequiresPermissions(value = { "ip:common:config" })
public String delete(Integer isValid, String ids, Integer functionId, RedirectAttributes redirectAttributes) {
try {
ipCommGroupCfgService.delete(ids);
addMessage(redirectAttributes, "success", "delete_success");
} catch (Exception e) {
logger.error("Delete failed", e);
if (e instanceof MaatConvertException) {
addMessage(redirectAttributes, "error", e.getMessage());
} else {
addMessage(redirectAttributes, "error", "delete_failed");
}
}
return "redirect:" + adminPath + "/basics/ip/list?functionId=" + functionId;
}
// ipComm配置导出
@RequestMapping(value = "/exportIpComm")
public void exportIpCommonCfg(Model model, HttpServletRequest request, HttpServletResponse response,
@ModelAttribute("cfg") IpCommCfg entity, String ids, RedirectAttributes redirectAttributes) {
try {
// export data info
List<String> titleList = new ArrayList<String>();
Map<String, Class<?>> classMap = new HashMap<String, Class<?>>();
Map<String, List> dataMap = new HashMap<String, List>();
Map<String, String> noExportMap = new HashMap<String, String>();
List<IpCommCfg> list = new ArrayList<IpCommCfg>();
if (!StringUtil.isEmpty(ids)) {
list = ipCommGroupCfgService.findByPage(ids);
} else {
Page<IpCommCfg> pageInfo = new Page<IpCommCfg>(request, response, "r");
pageInfo.setPageNo(1);
pageInfo.setPageSize(Constants.MAX_EXPORT_SIZE);
Page<IpCommCfg> page = ipCommGroupCfgService.findPage(pageInfo, entity);
list = page.getList();
}
//
titleList.add(entity.getMenuNameCode());
classMap.put(entity.getMenuNameCode(), IpPortCfg.class);
String cfgIndexInfoNoExport = ",block_type,do_log,action"
+ ",letter,whether_area_block,classification,attribute,label"
+ ",userregion1,userregion2,userregion3,userregion4,userregion5,src_ip_pattern,client_ip,src_port_pattern,client_port,dest_ip_pattern,dest_port_pattern,dest_port,";
// 时间过滤
if (entity.getSearch_create_time_start() == null) {
cfgIndexInfoNoExport = ",config_time" + cfgIndexInfoNoExport;
}
if (entity.getSearch_edit_time_start() == null) {
cfgIndexInfoNoExport = ",edit_time" + cfgIndexInfoNoExport;
}
if (entity.getSearch_audit_time_start() == null) {
cfgIndexInfoNoExport = ",audit_time" + cfgIndexInfoNoExport;
}
if (!StringUtil.isEmpty(entity.gethColumns())) {
cfgIndexInfoNoExport = "," + entity.gethColumns() + "," + cfgIndexInfoNoExport;
}
noExportMap.put(entity.getMenuNameCode(), cfgIndexInfoNoExport);
dataMap.put(entity.getMenuNameCode(), list);
String timeRange = initTimeMap(entity);
noExportMap.put("timeRange", timeRange);
if ("csv".equals(entity.getExType())) {
this._exportCsv(model, request, response, redirectAttributes, entity.getMenuNameCode(), titleList,
classMap, dataMap, noExportMap);
} else {
this._export(model, request, response, redirectAttributes, entity.getMenuNameCode(), titleList,
classMap, dataMap, noExportMap);
}
} catch (Exception e) {
logger.error("IpCommGroupCfg export failed", e);
addMessage(redirectAttributes, "error", "export_failed");
}
// return "redirect:" + adminPath
// +"/ntc/iplist/list?functionId="+entity.getFunctionId();
}
/**
* 批量审核
*
* @param isAudit
* @param isValid
* @param ids
* @param functionId
* @param redirectAttributes
* @return
*/
// @Override
// public void auditAll(Page page, Integer auditType, Object entity) throws Exception {
// long start = System.currentTimeMillis();
// page.setOrderBy("");
// page.setPageSize(Constants.MAAT_JSON_SEND_SIZE);
// page.setPageNo(1);
// page.setLastPage(false);
// // 携带审核状态信息的BaseCfg
// BaseCfg auditBatchCfg = new BaseCfg();
// // 携带审核条件的BaseCfg
// IpCommCfg searchIpCommGroupCfg = new IpCommCfg();
// BeanUtils.copyProperties(entity, auditBatchCfg);
// BeanUtils.copyProperties(entity, searchIpCommGroupCfg);
//
// auditType = (Integer) Reflections.invokeGetter(entity, "isAudit");
//
// // 全部审核通过,只查询当前条件下的所有未审核的配置 -批量审核通过/不通过
// if (auditType.equals(1) || auditType.equals(2)) {
//
// searchIpCommGroupCfg.setIsValid(0);
// searchIpCommGroupCfg.setIsAudit(0);
//
// if (auditType.equals(1)) {
// auditBatchCfg.setIsAudit(1);
// auditBatchCfg.setIsValid(1);
// } else {
// auditBatchCfg.setIsAudit(2);
// auditBatchCfg.setIsValid(0);
// }
// auditBatchCfg.setAuditTime(new Date());
// auditBatchCfg.setAuditorId(UserUtils.getUser().getId());
// } else {
// // 全部取消通过,只查询当前条件下的所有审核通过的配置
// searchIpCommGroupCfg.setIsValid(1);
// searchIpCommGroupCfg.setIsAudit(1);
//
// auditBatchCfg.setIsAudit(3);
// auditBatchCfg.setIsValid(0);
// auditBatchCfg.setAuditTime(new Date());
// auditBatchCfg.setAuditorId(UserUtils.getUser().getId());
// }
//
// ServiceConfigTemplateUtil serviceTemplate = new ServiceConfigTemplateUtil();
// Integer functionId = 0;
// if (auditBatchCfg != null && !StringUtil.isEmpty(auditBatchCfg.getFunctionId())) {
// functionId = auditBatchCfg.getFunctionId();
// }
// List<Map<String, Object>> serviceList = serviceTemplate.getServiceListByFunctionId(functionId);
// for (Map<String, Object> service : serviceList) {
// String tableNameXml = service.get("tableName").toString(); // 获取业务主配置表
// String serviceTypeXml = service.get("serviceType").toString(); // 业务类型 1maat 2callback
// String classNameXml = service.get("className").toString(); // 主配置Java类
// String serviceIdXml = service.get("id").toString(); // service字典表 service_id字段
// auditBatchCfg.setServiceId(Integer.valueOf(serviceIdXml));
// auditBatchCfg.setTableName(tableNameXml);
// searchIpCommGroupCfg.setServiceId(Integer.valueOf(serviceIdXml));
// searchIpCommGroupCfg.setTableName(tableNameXml);
//
// if ("1".equals(serviceTypeXml)) {// maat类配置
// // 存放域配置类型 及 对应表名
// List<Map<String, Object>> cfgList = (List<Map<String, Object>>) service.get("cfgList");
// List<Map<String, Object>> userRegionList = (List<Map<String, Object>>) service.get("userRegionList");
// int cfgType = Integer.parseInt(service.get("cfgType").toString());
// if (auditBatchCfg.getIsAudit() == 1) {
// boolean hasData = true;
//
// while (hasData) {
// page.setPageNo(1);
// page.setLastPage(false);
// List list = ipCommGroupCfgService.findPage(page, searchIpCommGroupCfg).getList();
// if(CollectionUtils.isNotEmpty(list)){
// Map<Integer,List> groupIdMap=new HashMap();
// // 配置生效处理
// if(auditBatchCfg.getIsAudit().equals(1)) {
// hasData=commonPolicyService.auditReuseCommonConfigData(page, auditBatchCfg,groupIdMap,hasData);
// Map<Integer,List> groupIpMap=new HashMap();
// if(CollectionUtils.isNotEmpty(list)) {
// for (IpCommCfg obj : (List<IpCommCfg>)list) {
// BaseCfg baseCfg=(BaseCfg)obj;
// if(!StringUtil.isEmpty(obj.getGroupId())) {
// groupIdMap.get(obj.getGroupId()).add(baseCfg);
// }else {
// List newList=new ArrayList<>();
// newList.add(baseCfg);
// groupIdMap.put(obj.getGroupId(),newList);
// }
// }
// }
//
// }
// if(hasData) {
// page.setPageNo(1);
// page.setLastPage(false);
// }
// }else{
// hasData = false;
// }
// }
// }
// } else {
// throw new RuntimeException("wrong service type " + serviceTypeXml);
// }
// }
//
// // 批量审核通过时如果没有携带isValid检索条件返回界面需要将isValid置为null
// if (!StringUtil.isEmpty(entity)) {
// BaseCfg base = (BaseCfg) entity;
// if (!StringUtil.isEmpty(base.getSeltype()) && base.getSeltype().equals("isValid")) {
// base.setIsValid(null);
// BeanUtils.copyProperties(base, entity);
// }
// }
// long end = System.currentTimeMillis();
// logger.warn("配置批量生效/失效耗时:" + (end - start));
// }
@RequestMapping(value = "import", method=RequestMethod.POST)
public String importIp(HttpServletRequest request,HttpServletResponse response,RedirectAttributes redirectAttributes,
@RequestParam("files") MultipartFile[] files, Integer serviceDictId ,Integer requestId ,String attribute ,String classify
,String regionDictIds ,String importPath) {
logger.warn("import start...");
long start=System.currentTimeMillis();
ImportBigExcel ei=null;
try {
FunctionServiceDict serviceDict = DictUtils.getFunctionServiceDict(serviceDictId);
StringBuffer errTip=new StringBuffer();
BlockingQueue<BaseIpCfg> ipPortCfgs =null;
//List<CfgIndexInfo> cfgIndexInfos = new ArrayList<CfgIndexInfo>();
for (int i = 0; i < files.length; i++) {
MultipartFile file = files[i];
ei = new ImportBigExcel(file, 0, 1);
FunctionRegionDict regionDict = DictUtils.getFunctionRegionDict(Integer.parseInt(regionDictIds.split(",")[i]));
//加载模板
loadTemplate(ei,regionDict, serviceDict);
//------------------------------------check format start----------------------------
if (regionDict.getRegionType().equals(1)) {// IP
BlockingQueue<IpCommCfgTemplate> list = ei.getDataList(IpCommCfgTemplate.class );
ipPortCfgs=this.checkIpCfgMulity(errTip,serviceDict, regionDict, null,null, list);
}
//删除文件
if(ei.getUploadFile()!=null&&ei.getUploadFile().exists()) {
ei.getUploadFile().delete();
}
//------------------------------------check format end----------------------------
Date date = new Date();
String isSend = request.getParameter("isSend")==null?"":request.getParameter("isSend");
if (regionDict.getRegionType().equals(1)) {// IP
List<BaseIpCfg> _ipPortCfgs=Lists.newArrayList(Constants.MAAT_JSON_SEND_SIZE);
while(!ipPortCfgs.isEmpty()) {
ipPortCfgs.drainTo(_ipPortCfgs, Constants.MAAT_JSON_SEND_SIZE);
int ind=0;
for (BaseIpCfg cfg : _ipPortCfgs) {
cfg.setAction(serviceDict==null?null:serviceDict.getAction());
cfg.setCfgRegionCode(regionDict.getConfigRegionCode());
cfg.setCfgType(regionDict.getConfigRegionValue());
cfg.setCreateTime(date);
cfg.setCreatorId(UserUtils.getUser().getId());
//cfg.setDoLog(2);
cfg.setCompileId(0);
cfg.setFunctionId(regionDict.getFunctionId());
if(isSend.equals("1")) {
cfg.setIsAudit(Constants.AUDIT_YES);
cfg.setIsValid(Constants.VALID_YES);
cfg.setAuditorId(UserUtils.getUser().getId());
cfg.setAuditTime(date);
}else {
cfg.setIsAudit(Constants.AUDIT_NOT_YET);
cfg.setIsValid(Constants.VALID_NO);
}
cfg.setIsAreaEffective(0);
cfg.setLable("0");
cfg.setRequestId(StringUtil.isEmpty(requestId) ? 0 : requestId);
cfg.setAttribute(attribute);
cfg.setClassify(classify);
cfg.setServiceId(serviceDict==null?null:serviceDict.getServiceId());
cfg.setTableName("ip_comm_cfg");
ind++;
}
ipCommGroupCfgService.saveAndSend(regionDict, serviceDict, _ipPortCfgs,isSend.equals("1"));
_ipPortCfgs.clear();
}
}
}
if(errTip.toString().length()>0) {
addMessage(redirectAttributes,"error", errTip.toString());
}
} catch (Exception e) {
if(ei!=null) {
if(ei.getUploadFile().exists()) {
ei.getUploadFile().delete();
}
}
if(e instanceof MaatConvertException) {
addMessage(redirectAttributes,"error", "request_service_failed");
}else if(e instanceof ServiceException) {
addMessage(redirectAttributes,"error", e.getMessage());
}else if(e instanceof IndexOutOfBoundsException){
addMessage(redirectAttributes,"error", "template_error");
}else {
addMessage(redirectAttributes,"error", "import_failed");
}
logger.error("import failed", e);
}
long end=System.currentTimeMillis();
logger.warn("import finish,cost:"+(end-start));
return "redirect:" + adminPath+ importPath;
}
@RequestMapping(value="ajaxGetGroups",method=RequestMethod.POST)
@ResponseBody
public Map<Integer,String> ajaxGetGroups(Model model,@RequestParam(required=true,value="groupIds")String groupIds){
Map<Integer,String> groupIdList=new HashMap<Integer,String>();
if(StringUtils.isNotBlank(groupIds)) {
List<PolicyGroupInfo> list=policyGroupInfoService.findPolicyByGroupInfoList(groupIds);
for(PolicyGroupInfo p:list) {
groupIdList.put(p.getGroupId(), p.getGroupName());
}
}
return groupIdList;
}
}

View File

@@ -0,0 +1,35 @@
package com.nis.web.dao.basics;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import com.nis.domain.basics.CommonGroupInfo;
import com.nis.domain.basics.PolicyGroupInfo;
import com.nis.web.dao.CrudDao;
import com.nis.web.dao.MyBatisDao;
@MyBatisDao
public interface CommonGroupManageDao extends CrudDao<CommonGroupInfo> {
List<CommonGroupInfo> findCommonGroupInfoList(CommonGroupInfo commonGroupInfo);
CommonGroupInfo getById(int id);
List<CommonGroupInfo> findCommonGroupInfosByType(int groupType);
List<CommonGroupInfo> findGroupInfoList(@Param("ids")String ids);
/*List<PolicyGroupInfo> findPolicyGroupInfos();
List<PolicyGroupInfo> findHasIPPolicyGroupInfosByType(int groupType);
List<PolicyGroupInfo> findPolicyGroupInfosHasIpRegionByType(int groupType);
List<PolicyGroupInfo> findNatPolicyGroups();
PolicyGroupInfo getInfoByAsnNo(PolicyGroupInfo policyGroupInfo);
List<PolicyGroupInfo> getHasAreaPolicyGroups(int groupType);
int insertBatch(List<PolicyGroupInfo> list);
Integer getGroupIdByGroupName(String groupName);
PolicyGroupInfo getGroupInfo(PolicyGroupInfo policyGroupInfo);
*/
}

View File

@@ -0,0 +1,272 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.nis.web.dao.basics.CommonGroupManageDao" >
<resultMap id="CommonGroupInfoMap" type="com.nis.domain.basics.CommonGroupInfo" >
<id column="group_id" property="groupId" jdbcType="INTEGER" />
<result column="group_name" property="groupName" jdbcType="VARCHAR" />
<result column="group_type" property="groupType" jdbcType="INTEGER" />
<result column="is_valid" property="isValid" jdbcType="INTEGER" />
<result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
<result column="edit_time" property="editTime" jdbcType="TIMESTAMP" />
<result column="creator_id" property="creatorId" jdbcType="INTEGER" />
<result column="editor_id" property="editorId" jdbcType="INTEGER" />
<result column="service_group_id" property="serviceGroupId" jdbcType="INTEGER" />
<result column="description" property="description" jdbcType="VARCHAR" />
</resultMap>
<sql id="CommonGroupInfoColumns">
r.group_id,r.group_name,r.group_type,r.is_valid,r.create_time,r.edit_time,
r.creator_id,r.editor_id,r.service_group_id,r.description
</sql>
<!-- 查出所有 有效数据-->
<select id="findCommonGroupInfoList" resultMap="CommonGroupInfoMap">
SELECT
<include refid="CommonGroupInfoColumns"/>
<trim prefix="," prefixOverrides=",">
, s.name as creator_name
,e.name as editor_name
</trim>
FROM policy_group_info r
left join sys_user s on r.creator_id=s.id
left join sys_user e on r.editor_id=e.id
<trim prefix="WHERE" prefixOverrides="AND |OR ">
<if test="page !=null and page.where != null and page.where != ''">
AND ${page.where}
</if>
<if test="groupName != null and groupName != ''">
AND r.group_name like concat(concat('%',#{groupName,jdbcType=VARCHAR}),'%')
</if>
<if test="groupType != null">
AND r.group_type =#{groupType }
</if>
<if test="groupType == null">
AND r.group_type NOT IN(1,2,3,4)
</if>
AND r.IS_VALID =1
<if test="creatorName != null and creatorName != ''">
AND CREATOR_NAME like concat(concat('%',#{creatorName,jdbcType=VARCHAR}),'%')
</if>
<if test="editorName != null and editorName != ''">
AND r.EDITOR_NAME like concat(concat('%',#{editorName,jdbcType=VARCHAR}),'%')
</if>
<!-- 数据范围过滤 -->
<!-- ${sqlMap.dsf} -->
</trim>
<choose>
<when test="page !=null and page.orderBy != null and page.orderBy != ''">
ORDER BY ${page.orderBy}
</when>
<otherwise>
ORDER BY r.group_id desc
</otherwise>
</choose>
</select>
<select id="getById" resultType="com.nis.domain.basics.CommonGroupInfo">
SELECT
<include refid="CommonGroupInfoColumns"/>
FROM
policy_group_info r
WHERE
r.group_id = #{groupId}
</select>
<insert id="insert" parameterType="com.nis.domain.basics.CommonGroupInfo" >
INSERT INTO policy_group_info(
IS_VALID,
CREATOR_ID,
CREATE_TIME,
GROUP_NAME,
GROUP_TYPE,
SERVICE_GROUP_ID,
DESCRIPTION
)values (
1,
#{creatorId,jdbcType=INTEGER},
#{createTime,jdbcType=TIMESTAMP},
#{groupName,jdbcType=VARCHAR},
#{groupType,jdbcType=INTEGER},
#{serviceGroupId,jdbcType=INTEGER},
#{description,jdbcType=VARCHAR}
)
</insert>
<insert id="insertBatch">
INSERT INTO policy_group_info(
IS_VALID,
CREATOR_ID,
CREATE_TIME,
GROUP_NAME,
GROUP_TYPE,
SERVICE_GROUP_ID,
DESCRIPTION
)values
<foreach collection ="list" item="info" separator =",">
(
1,
#{info.creatorId,jdbcType=INTEGER},
#{info.createTime,jdbcType=TIMESTAMP},
#{info.groupName,jdbcType=VARCHAR},
#{info.groupType,jdbcType=INTEGER},
#{info.serviceGroupId,jdbcType=INTEGER},
#{info.description,jdbcType=VARCHAR}
)
</foreach>
</insert>
<update id="update" parameterType="com.nis.domain.basics.CommonGroupInfo" >
UPDATE policy_group_info
<set>
<trim suffixOverrides=",">
<if test="groupName != null and groupName != ''" >
group_name = #{groupName,jdbcType=VARCHAR},
</if>
<if test="groupType != null" >
group_type = #{groupType,jdbcType=INTEGER},
</if>
<if test="description != null" >
description = #{description,jdbcType=VARCHAR},
</if>
<if test="isValid != null" >
is_valid = #{isValid,jdbcType=INTEGER},
</if>
<if test="editorId != null" >
editor_id = #{editorId,jdbcType=INTEGER},
</if>
<if test="editTime != null and editTime != ''" >
edit_time = #{editTime,jdbcType=TIMESTAMP},
</if>
</trim>
</set>
<where>
<if test="groupId != null" >
and group_id = #{groupId,jdbcType=INTEGER}
</if>
<if test="serviceGroupId != null" >
and service_group_id = #{serviceGroupId,jdbcType=INTEGER}
</if>
</where>
</update>
<select id="findCommonGroupInfosByType" resultMap="CommonGroupInfoMap">
SELECT
<include refid="CommonGroupInfoColumns"/>
FROM
policy_group_info r
WHERE
r.is_valid=1 and r.group_type=#{groupType,jdbcType=INTEGER}
</select>
<select id="findGroupInfoList" resultMap="CommonGroupInfoMap">
SELECT
<include refid="CommonGroupInfoColumns"/>
<trim prefix="," prefixOverrides=",">
, s.name as creator_name
,e.name as editor_name
</trim>
FROM
policy_group_info r
left join sys_user s on r.creator_id=s.id
left join sys_user e on r.editor_id=e.id
WHERE
r.group_id IN (${ids})
</select>
<!-- 查出所有 有效数据-->
<!-- <select id="findPolicyGroupInfos" resultMap="PolicyGroupInfoMap">
SELECT
<include refid="PolicyGroupInfoColumns"/>
FROM policy_group_info r
where r.is_valid=1
</select>
<select id="findNatPolicyGroups" resultMap="PolicyGroupInfoMap">
SELECT
<include refid="PolicyGroupInfoColumns"/>
FROM policy_group_info r
where r.is_valid=1 AND r.group_type = 2 OR r.group_type = 3
</select>
<select id="findHasIPPolicyGroupInfosByType" resultMap="PolicyGroupInfoMap">
SELECT
<include refid="PolicyGroupInfoColumns"/>
FROM (
SELECT DISTINCT dns_strategy_id FROM dns_ip_cfg WHERE is_valid=1 AND is_audit=1
) a
LEFT JOIN policy_group_info r ON a.dns_strategy_id=r.group_id
where r.is_valid=1 and r.group_type=#{groupType,jdbcType=INTEGER}
</select>
<select id="getInfoByAsnNo" resultType="com.nis.domain.basics.PolicyGroupInfo">
SELECT
<include refid="PolicyGroupInfoColumns"/>
FROM
policy_group_info r
<trim prefix="WHERE" prefixOverrides="AND |OR ">
<if test="groupId != null" >
AND group_id = #{groupId,jdbcType=INTEGER}
</if>
<if test="asnNo != null" >
AND asn_no = #{asnNo,jdbcType=INTEGER}
</if>
<if test="isValid != null" >
AND is_valid = #{isValid,jdbcType=INTEGER}
</if>
<if test="isValid == null" >
AND is_valid != -1
</if>
</trim>
</select>
<select id="getHasAreaPolicyGroups" resultType="com.nis.domain.basics.PolicyGroupInfo">
SELECT
<include refid="PolicyGroupInfoColumns"/>
FROM
policy_group_info r
WHERE
r.is_valid = 1 AND
r.group_type = #{groupType,jdbcType=INTEGER} AND
r.group_id IN (
SELECT ga.group_id FROM group_area_info ga WHERE ga.is_valid != -1
)
</select>
<select id="getGroupIdByGroupName" resultType="java.lang.Integer">
SELECT
r.group_id
FROM
policy_group_info r
WHERE
r.group_name = #{groupName}
</select>
<select id="getGroupInfo" resultType="com.nis.domain.basics.PolicyGroupInfo">
SELECT
<include refid="PolicyGroupInfoColumns"/>
FROM
policy_group_info r
<trim prefix="WHERE" prefixOverrides="AND |OR ">
<if test="groupName != null and groupName != ''" >
AND group_name = #{groupName,jdbcType=VARCHAR}
</if>
<if test="groupType != null" >
AND group_type = #{groupType,jdbcType=INTEGER}
</if>
<if test="asnNo != null" >
AND asn_no = #{asnNo,jdbcType=INTEGER}
</if>
<if test="isValid != null" >
AND is_valid = #{isValid,jdbcType=INTEGER}
</if>
<if test="isValid == null" >
AND is_valid != -1
</if>
</trim>
</select>
-->
</mapper>

View File

@@ -0,0 +1,31 @@
package com.nis.web.dao.basics;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import com.nis.domain.basics.IpCommCfg;
import com.nis.domain.basics.Varibles;
import com.nis.web.dao.CrudDao;
import com.nis.web.dao.MyBatisDao;
@MyBatisDao
public interface IpCommGroupCfgDao extends CrudDao<IpCommCfg>{
public List<IpCommCfg> findPage(IpCommCfg cfg);
public List<IpCommCfg> findByPage(@Param("ids")String ids);
public void delete(@Param("ids")String ids);
public void updateIssued(IpCommCfg cfg);
public List<IpCommCfg> getByIds(@Param("ids")String ids);
public List<IpCommCfg> findAllList(IpCommCfg cfg);
public List<Integer> findOtherIps(@Param("groupId")Integer groupId,@Param("cfgId")Integer cfgId);
public List<Integer> countValidIPs(@Param("groups")String groups,@Param("ids")String ids);
public int insertBatch(List<IpCommCfg> list);
public Varibles getVaribles(@Param("name")String name);
public void ajaxDeleteAsnIp(@Param("ids")String ids);
public IpCommCfg getOne(IpCommCfg cfg);
public List<Object[]> findAllIpCommGroupCfgList();
public void insertIpCommGroupCfg(IpCommCfg ipPortCfg);
public int getGroupIdCount(int groupId);
// 校验分组是否被引用
public List<IpCommCfg> getCfgInfoByGroupIds(@Param("ids")String ids);
}

View File

@@ -0,0 +1,526 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.nis.web.dao.basics.IpCommGroupCfgDao">
<resultMap id="IpCommGroupCfgMap" type="com.nis.domain.basics.IpCommCfg">
<id column="cfg_id" property="cfgId" jdbcType="BIGINT" />
<result column="cfg_desc" property="cfgDesc" jdbcType="VARCHAR" />
<result column="cfg_type" property="cfgType" jdbcType="VARCHAR" />
<result column="cfg_region_code" property="cfgRegionCode" jdbcType="INTEGER" />
<result column="ip_type" property="ipType" jdbcType="INTEGER" />
<result column="src_ip_pattern" property="srcIpPattern" jdbcType="INTEGER" />
<result column="dest_ip_pattern" property="destIpPattern" jdbcType="INTEGER" />
<result column="src_ip_address" property="srcIpAddress" jdbcType="VARCHAR" />
<result column="dest_ip_address" property="destIpAddress" jdbcType="VARCHAR" />
<result column="port_pattern" property="portPattern" jdbcType="INTEGER" />
<result column="src_port" property="srcPort" jdbcType="VARCHAR" />
<result column="dest_port" property="destPort" jdbcType="VARCHAR" />
<result column="direction" property="direction" jdbcType="INTEGER" />
<result column="protocol" property="protocol" jdbcType="INTEGER" />
<result column="protocol_id" property="protocolId" jdbcType="INTEGER" />
<result column="action" property="action" jdbcType="INTEGER" />
<result column="is_valid" property="isValid" jdbcType="INTEGER" />
<result column="is_audit" property="isAudit" jdbcType="INTEGER" />
<result column="creator_id" property="creatorId" jdbcType="INTEGER" />
<result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
<result column="editor_id" property="editorId" jdbcType="INTEGER" />
<result column="edit_time" property="editTime" jdbcType="TIMESTAMP" />
<result column="auditor_id" property="auditorId" jdbcType="INTEGER" />
<result column="audit_time" property="auditTime" jdbcType="TIMESTAMP" />
<result column="service_id" property="serviceId" jdbcType="INTEGER" />
<result column="request_id" property="requestId" jdbcType="INTEGER" />
<result column="compile_id" property="compileId" jdbcType="INTEGER" />
<result column="is_area_effective" property="isAreaEffective" jdbcType="INTEGER" />
<result column="classify" property="classify" jdbcType="VARCHAR" />
<result column="attribute" property="attribute" jdbcType="VARCHAR" />
<result column="lable" property="lable" jdbcType="VARCHAR" />
<result column="area_effective_ids" property="areaEffectiveIds" jdbcType="VARCHAR" />
<result column="function_id" property="functionId" jdbcType="INTEGER" />
<result column="ratelimit" property="ratelimit" jdbcType="VARCHAR" />
<result column="region_id" property="regionId" jdbcType="INTEGER" />
<result column="group_id" property="groupId" jdbcType="INTEGER" />
<result column="user_region1" property="userRegion1" jdbcType="VARCHAR" />
<result column="user_region2" property="userRegion2" jdbcType="VARCHAR" />
<result column="user_region3" property="userRegion3" jdbcType="VARCHAR" />
<result column="user_region4" property="userRegion4" jdbcType="VARCHAR" />
<result column="user_region5" property="userRegion5" jdbcType="VARCHAR" />
</resultMap>
<sql id="columns">
r.cfg_id,r.cfg_desc,r.cfg_type,r.cfg_region_code,r.ip_type,r.src_ip_pattern,r.src_ip_address,r.dest_ip_pattern,r.dest_ip_address,
r.src_port_pattern,r.src_port,r.dest_port_pattern,r.dest_port
,r.protocol,r.protocol_id,r.direction,r.action
,r.is_valid,r.is_audit,r.creator_id,r.create_time,r.editor_id
,r.edit_time,r.auditor_id,r.audit_time,r.service_id,r.request_id,
r.is_area_effective,r.classify,r.attribute,r.lable
,r.area_effective_ids,r.function_id,r.user_region1
,r.user_region2,r.user_region3,r.user_region4,r.user_region5,r.compile_id,r.region_id,r.group_id
</sql>
<select id="findPage" resultMap="IpCommGroupCfgMap">
select
<include refid="columns"></include>
<trim prefix="," prefixOverrides=",">
,s.name as creator_name,e.name as editor_name,u.name as auditor_name
</trim>
from ip_comm_cfg r
left join sys_user s on r.creator_id=s.id
left join sys_user e on r.editor_id=e.id
left join sys_user u on r.auditor_id=u.id
<trim prefix="WHERE" prefixOverrides="AND |OR ">
<if test="page !=null and page.where != null and page.where != ''">
AND ${page.where}
</if>
<if test="cfgId != null">
AND r.CFG_ID=#{cfgId,jdbcType=BIGINT}
</if>
<if test="cfgDesc != null and cfgDesc != ''">
AND r.CFG_DESC like concat(concat('%',#{cfgDesc,jdbcType=VARCHAR}),'%')
</if>
<if test="cfgRegionCode != null">
AND r.CFG_REGION_CODE=#{cfgRegionCode,jdbcType=INTEGER}
</if>
<if test="cfgType != null and cfgType != ''">
AND r.CFG_TYPE like concat(concat('%',#{CFG_TYPE,jdbcType=VARCHAR}),'%')
</if>
<if test="ipType != null">
AND r.IP_TYPE=#{ipType,jdbcType=INTEGER}
</if>
<if test="srcIpPattern != null">
AND r.src_ip_pattern=#{srcIpPattern,jdbcType=INTEGER}
</if>
<if test="destIpPattern != null">
AND r.dest_ip_pattern=#{destIpPattern,jdbcType=INTEGER}
</if>
<if test="srcIpAddress != null and srcIpAddress != ''">
AND r.SRC_IP_ADDRESS=#{srcIpAddress,jdbcType=VARCHAR}
</if>
<if test="destIpAddress != null and destIpAddress != ''">
AND r.DEST_IP_ADDRESS=#{destIpAddress,jdbcType=VARCHAR}
</if>
<if test="srcPortPattern != null">
AND r.src_port_pattern=#{srcPortPattern,jdbcType=INTEGER}
</if>
<if test="destPortPattern != null">
AND r.dest_port_pattern=#{destPortPattern,jdbcType=INTEGER}
</if>
<if test="srcPort != null and srcPort !=''">
AND r.SRC_PORT=#{srcPort,jdbcType=VARCHAR}
</if>
<if test="destPort != null and destPort !=''">
AND r.DEST_PORT=#{destPort,jdbcType=VARCHAR}
</if>
<if test="direction != null">
AND r.DIRECTION=#{direction,jdbcType=INTEGER}
</if>
<if test="protocol != null">
AND r.PROTOCOL=#{protocol,jdbcType=INTEGER}
</if>
<if test="protocolId != null">
AND r.PROTOCOL_ID=#{protocolId,jdbcType=INTEGER}
</if>
<if test="action != null">
AND r.ACTION=#{action,jdbcType=INTEGER}
</if>
<if test="isValid != null">
AND r.IS_VALID=#{isValid,jdbcType=INTEGER}
</if>
<if test="isValid == null">
AND r.IS_VALID != -1
</if>
<if test="isAudit != null">
AND r.IS_AUDIT=#{isAudit,jdbcType=INTEGER}
</if>
<if test="creatorName != null and creatorName !=''">
AND CREATOR_NAME like concat(concat('%',#{creatorName,jdbcType=VARCHAR}),'%')
</if>
<if test="createTime != null and createTime !=''">
AND r.CREATE_TIME=#{createTime,jdbcType=TIMESTAMP}
</if>
<if test="editorName != null and editorName !=''">
AND EDITOR_NAME like concat(concat('%',#{editorName,jdbcType=VARCHAR}),'%')
</if>
<if test="editTime != null and editTime !='' ">
AND r.EDIT_TIME=#{editTime,jdbcType=TIMESTAMP}
</if>
<if test="auditorName != null and auditorName !=''">
AND AUDITOR_NAME like concat(concat('%',#{auditorName,jdbcType=VARCHAR}),'%')
</if>
<if test="auditTime != null and auditTime !=''">
AND r.AUDIT_TIME=#{auditTime,jdbcType=TIMESTAMP}
</if>
<if test="serviceId != null">
AND r.SERVICE_ID=#{serviceId,jdbcType=INTEGER}
</if>
<if test="requestId != null">
AND r.REQUEST_ID=#{requestId,jdbcType=INTEGER}
</if>
<if test="regionId != null">
AND r.region_id=#{regionId,jdbcType=INTEGER}
</if>
<if test="isAreaEffective != null">
AND r.IS_AREA_EFFECTIVE=#{isAreaEffective,jdbcType=INTEGER}
</if>
<if test="classify != null and classify !=''">
AND r.classify like concat(concat('%',#{classify,jdbcType=VARCHAR}),'%')
</if>
<if test="attribute != null and attribute !=''">
AND r.attribute like concat(concat('%',#{attribute,jdbcType=VARCHAR}),'%')
</if>
<if test="lable != null and lable !=''">
AND r.lable like concat(concat('%',#{lable,jdbcType=VARCHAR}),'%')
</if>
<if test="areaEffectiveIds != null and areaEffectiveIds !=''">
AND r.AREA_EFFECTIVE_IDS like concat(concat('%',#{areaEffectiveIds,jdbcType=VARCHAR}),'%')
</if>
<if test="functionId != null">
AND r.FUNCTION_ID=#{functionId,jdbcType=INTEGER}
</if>
<if test="userRegion3 != null">
AND r.user_region3 like concat(concat('%',#{userRegion3,jdbcType=VARCHAR}),'%')
</if>
<!-- 数据范围过滤 -->
${sqlMap.dsf}
</trim>
<choose>
<when test="page !=null and page.orderBy != null and page.orderBy != ''">
ORDER BY ${page.orderBy}
</when>
<otherwise>
ORDER BY r.CFG_ID desc
</otherwise>
</choose>
</select>
<!-- 配置修改时检索 -->
<select id="get" resultMap="IpCommGroupCfgMap">
SELECT
<include refid="columns"></include>
FROM
ip_comm_cfg r
WHERE
r.cfg_id = #{ids} AND r.is_valid != -1
</select>
<select id="getCfgInfoByGroupIds" resultMap="IpCommGroupCfgMap">
SELECT
<include refid="columns"></include>
FROM
ip_comm_cfg r
WHERE
r.group_id IN(${ids}) AND r.is_valid != -1
</select>
<select id="getByIds" resultMap="IpCommGroupCfgMap">
select
<include refid="columns"></include>
from ip_comm_cfg r
where r.cfg_id in (${ids}) and r.is_valid !=-1
</select>
<select id="getByAsnNo" resultMap="IpCommGroupCfgMap" parameterType="java.lang.Long" >
select
<include refid="columns"></include>
from ip_comm_cfg r where r.is_valid!=-1 and r.user_region1=#{asnId}
</select>
<insert id="insertIpCommGroupCfg" parameterType="com.nis.domain.basics.IpCommCfg" >
<selectKey resultType="java.lang.Long" order="AFTER" keyProperty="cfgId">
SELECT LAST_INSERT_ID()
</selectKey>
insert into ip_comm_cfg (
CFG_DESC,
ACTION,
IS_VALID,
IS_AUDIT,
CREATOR_ID,
CREATE_TIME,
EDITOR_ID,
EDIT_TIME,
AUDITOR_ID,
AUDIT_TIME,
SERVICE_ID,
REQUEST_ID,
REGION_ID,
GROUP_ID,
COMPILE_ID,
IS_AREA_EFFECTIVE,
CLASSIFY,
ATTRIBUTE,
LABLE,
AREA_EFFECTIVE_IDS,
FUNCTION_ID,
IP_TYPE,
SRC_IP_ADDRESS,
SRC_IP_PATTERN,
DEST_IP_PATTERN,
SRC_PORT_PATTERN,
DEST_PORT_PATTERN,
SRC_PORT,
PROTOCOL,
PROTOCOL_ID,
DIRECTION,
DEST_PORT,
DEST_IP_ADDRESS,
CFG_TYPE,
CFG_REGION_CODE,
USER_REGION1,
USER_REGION2,
USER_REGION3,
USER_REGION4,
USER_REGION5,
)values (
#{cfgDesc,jdbcType=VARCHAR},
#{action,jdbcType=INTEGER},
#{isValid,jdbcType=INTEGER},
#{isAudit,jdbcType=INTEGER},
#{creatorId,jdbcType=INTEGER},
#{createTime,jdbcType=TIMESTAMP},
#{editorId,jdbcType=INTEGER},
#{editTime,jdbcType=TIMESTAMP},
#{auditorId,jdbcType=INTEGER},
#{auditTime,jdbcType=TIMESTAMP},
#{serviceId,jdbcType=INTEGER},
#{requestId,jdbcType=INTEGER},
#{regionId,jdbcType=INTEGER},
#{groupId,jdbcType=INTEGER},
#{compileId,jdbcType=INTEGER},
#{isAreaEffective,jdbcType=INTEGER},
#{classify,jdbcType=VARCHAR},
#{attribute,jdbcType=VARCHAR},
#{lable,jdbcType=VARCHAR},
#{areaEffectiveIds,jdbcType=VARCHAR},
#{functionId,jdbcType=INTEGER},
#{ipType,jdbcType=INTEGER},
#{srcIpAddress,jdbcType=VARCHAR},
#{srcIpPattern,jdbcType=INTEGER},#{destIpPattern,jdbcType=INTEGER},
#{srcPortPattern,jdbcType=INTEGER},#{destPortPattern,jdbcType=INTEGER},
#{srcPort,jdbcType=VARCHAR},
#{protocol,jdbcType=INTEGER},
#{protocolId,jdbcType=INTEGER},
#{direction,jdbcType=INTEGER},
#{destPort,jdbcType=VARCHAR},
#{destIpAddress,jdbcType=VARCHAR},
#{cfgType,jdbcType=VARCHAR},
#{cfgRegionCode,jdbcType=INTEGER},
#{userRegion1,jdbcType=VARCHAR},
#{userRegion2,jdbcType=VARCHAR},
#{userRegion3,jdbcType=VARCHAR},
#{userRegion4,jdbcType=VARCHAR},
#{userRegion5,jdbcType=VARCHAR}
)
</insert>
<insert id="insertForBatch" parameterType="com.nis.domain.basics.IpCommCfg" >
insert into ip_comm_cfg (
CFG_DESC,
ACTION,
IS_VALID,
IS_AUDIT,
CREATOR_ID,
CREATE_TIME,
EDITOR_ID,
EDIT_TIME,
AUDITOR_ID,
AUDIT_TIME,
SERVICE_ID,
REQUEST_ID,
REGION_ID,
GROUP_ID,
COMPILE_ID,
IS_AREA_EFFECTIVE,
CLASSIFY,
ATTRIBUTE,
LABLE,
AREA_EFFECTIVE_IDS,
FUNCTION_ID,
IP_TYPE,
SRC_IP_ADDRESS,
SRC_IP_PATTERN,
DEST_IP_PATTERN,
SRC_PORT_PATTERN,
DEST_PORT_PATTERN,
SRC_PORT,
PROTOCOL,
PROTOCOL_ID,
DIRECTION,
DEST_PORT,
DEST_IP_ADDRESS,
CFG_TYPE,
CFG_REGION_CODE,
USER_REGION1,
USER_REGION2,
USER_REGION3,
USER_REGION4,
USER_REGION5
)values (
#{cfgDesc,jdbcType=VARCHAR},
#{action,jdbcType=INTEGER},
#{isValid,jdbcType=INTEGER},
#{isAudit,jdbcType=INTEGER},
#{creatorId,jdbcType=INTEGER},
#{createTime,jdbcType=TIMESTAMP},
#{editorId,jdbcType=INTEGER},
#{editTime,jdbcType=TIMESTAMP},
#{auditorId,jdbcType=INTEGER},
#{auditTime,jdbcType=TIMESTAMP},
#{serviceId,jdbcType=INTEGER},
#{requestId,jdbcType=INTEGER},
#{regionId,jdbcType=INTEGER},
#{groupId,jdbcType=INTEGER},
#{compileId,jdbcType=INTEGER},
#{isAreaEffective,jdbcType=INTEGER},
#{classify,jdbcType=VARCHAR},
#{attribute,jdbcType=VARCHAR},
#{lable,jdbcType=VARCHAR},
#{areaEffectiveIds,jdbcType=VARCHAR},
#{functionId,jdbcType=INTEGER},
#{ipType,jdbcType=INTEGER},
#{srcIpAddress,jdbcType=VARCHAR},
#{srcIpPattern,jdbcType=INTEGER},#{destIpPattern,jdbcType=INTEGER},
#{srcPortPattern,jdbcType=INTEGER},#{destPortPattern,jdbcType=INTEGER},
#{srcPort,jdbcType=VARCHAR},
#{protocol,jdbcType=INTEGER},
#{protocolId,jdbcType=INTEGER},
#{direction,jdbcType=INTEGER},
#{destPort,jdbcType=VARCHAR},
#{destIpAddress,jdbcType=VARCHAR},
#{cfgType,jdbcType=VARCHAR},
#{cfgRegionCode,jdbcType=INTEGER},
#{userRegion1,jdbcType=VARCHAR},
#{userRegion2,jdbcType=VARCHAR},
#{userRegion3,jdbcType=VARCHAR},
#{userRegion4,jdbcType=VARCHAR},
#{userRegion5,jdbcType=VARCHAR}
)
</insert>
<update id="update" parameterType="com.nis.domain.basics.IpCommCfg" >
update ip_comm_cfg
<set >
<trim suffixOverrides=",">
<if test="cfgDesc != null and cfgDesc != ''" >
CFG_DESC = #{cfgDesc,jdbcType=VARCHAR},
</if>
<if test="action != null" >
ACTION = #{action,jdbcType=INTEGER},
</if>
<if test="isValid != null" >
IS_VALID = #{isValid,jdbcType=INTEGER},
</if>
<if test="isAudit != null" >
IS_AUDIT = #{isAudit,jdbcType=INTEGER},
</if>
<if test="editorId != null" >
EDITOR_ID = #{editorId,jdbcType=INTEGER},
</if>
<if test="editTime != null and editTime != ''" >
EDIT_TIME = #{editTime,jdbcType=TIMESTAMP},
</if>
<if test="auditorId != null" >
AUDITOR_ID = #{auditorId,jdbcType=INTEGER},
</if>
<if test="auditTime != null and auditTime != ''" >
AUDIT_TIME = #{auditTime,jdbcType=TIMESTAMP},
</if>
<if test="regionId != null" >
REGION_ID = #{regionId,jdbcType=TIMESTAMP},
</if>
<if test="requestId != null" >
REQUEST_ID = #{requestId,jdbcType=INTEGER},
</if>
<if test="isAreaEffective != null" >
IS_AREA_EFFECTIVE = #{isAreaEffective,jdbcType=INTEGER},
</if>
<if test="classify != null and classify != ''" >
CLASSIFY = #{classify,jdbcType=VARCHAR},
</if>
<if test="attribute != null and attribute != ''" >
ATTRIBUTE = #{attribute,jdbcType=VARCHAR},
</if>
<if test="lable != null and lable != ''" >
LABLE = #{lable,jdbcType=VARCHAR},
</if>
<if test="areaEffectiveIds != null" >
AREA_EFFECTIVE_IDS = #{areaEffectiveIds,jdbcType=VARCHAR},
</if>
<if test="functionId != null" >
FUNCTION_ID = #{functionId,jdbcType=INTEGER},
</if>
<if test="serviceId != null" >
SERVICE_ID = #{serviceId,jdbcType=INTEGER},
</if>
<if test="ipType != null" >
IP_TYPE = #{ipType,jdbcType=INTEGER},
</if>
<if test="srcIpAddress != null and srcIpAddress != ''" >
SRC_IP_ADDRESS = #{srcIpAddress,jdbcType=VARCHAR},
</if>
<if test="srcIpPattern != null" >
SRC_IP_PATTERN = #{srcIpPattern,jdbcType=INTEGER},
</if>
<if test="destIpPattern != null" >
DEST_IP_PATTERN =#{destIpPattern,jdbcType=INTEGER},
</if>
<if test="srcPortPattern != null" >
SRC_PORT_PATTERN = #{srcPortPattern,jdbcType=INTEGER},
</if>
<if test="destPortPattern != null" >
DEST_PORT_PATTERN = #{destPortPattern,jdbcType=INTEGER},
</if>
<if test="srcPort != null and srcPort != ''" >
SRC_PORT = #{srcPort,jdbcType=VARCHAR},
</if>
<if test="protocol != null" >
PROTOCOL = #{protocol,jdbcType=INTEGER},
</if>
<if test="protocolId != null" >
PROTOCOL_ID = #{protocolId,jdbcType=INTEGER},
</if>
<if test="direction != null" >
DIRECTION = #{direction,jdbcType=INTEGER},
</if>
<if test="destPort != null and destPort != ''" >
DEST_PORT = #{destPort,jdbcType=VARCHAR},
</if>
<if test="destIpAddress != null and destIpAddress != ''" >
DEST_IP_ADDRESS = #{destIpAddress,jdbcType=VARCHAR},
</if>
<if test="cfgType != null and cfgType != ''" >
CFG_TYPE = #{cfgType,jdbcType=VARCHAR},
</if>
<if test="cfgRegionCode != null " >
CFG_REGION_CODE = #{cfgRegionCode,jdbcType=INTEGER},
</if>
<if test="userRegion1 != null and userRegion1 != ''" >
USER_REGION1 = #{userRegion1,jdbcType=VARCHAR},
</if>
<if test="userRegion2 != null and userRegion2 != ''" >
USER_REGION2 = #{userRegion2,jdbcType=VARCHAR},
</if>
<if test="userRegion3 != null and userRegion3 != ''" >
USER_REGION3 = #{userRegion3,jdbcType=VARCHAR},
</if>
<if test="userRegion4 != null and userRegion4 != ''" >
USER_REGION4 = #{userRegion4,jdbcType=VARCHAR},
</if>
<if test="userRegion5 != null and userRegion5 != ''" >
USER_REGION5 = #{userRegion5,jdbcType=VARCHAR},
</if>
<if test="groupId != null and groupId != ''" >
GROUP_ID = #{groupId,jdbcType=INTEGER},
</if>
<if test="regionId != null and regionId != ''" >
REGION_ID = #{regionId,jdbcType=INTEGER},
</if>
</trim>
</set>
<where>
and cfg_id = #{cfgId,jdbcType=INTEGER}
</where>
</update>
<delete id="delete" parameterType="java.lang.String" >
delete from ip_comm_cfg where cfg_id in (${ids})
</delete>
<select id="getGroupIdCount" parameterType="java.lang.Integer" resultType="java.lang.Integer">
SELECT COUNT(cfg_id) groupCount from ip_comm_cfg
WHERE group_id= #{groupId}
and is_valid=1
</select>
</mapper>

View File

@@ -0,0 +1,235 @@
package com.nis.web.service.basics;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.nis.domain.Page;
import com.nis.domain.basics.CommonGroupInfo;
import com.nis.domain.basics.IpCommCfg;
import com.nis.domain.basics.PolicyGroupInfo;
import com.nis.domain.basics.UrlCommCfg;
import com.nis.domain.specific.ConfigGroupInfo;
import com.nis.exceptions.MaatConvertException;
import com.nis.util.ConfigServiceUtil;
import com.nis.util.StringUtil;
import com.nis.web.dao.basics.AsnIpCfgDao;
import com.nis.web.dao.basics.CommonGroupManageDao;
import com.nis.web.dao.basics.IpCommGroupCfgDao;
import com.nis.web.dao.basics.UrlCommGroupDao;
import com.nis.web.dao.specific.ConfigGroupInfoDao;
import com.nis.web.security.UserUtils;
import com.nis.web.service.BaseService;
import com.nis.web.service.SpringContextHolder;
@Service
public class CommonGroupManageService extends BaseService{
@Autowired
private CommonGroupManageDao commonGroupManageDao;
@Autowired
private ConfigGroupInfoDao configGroupInfoDao;
@Autowired
private IpCommGroupCfgDao ipCommGroupCfgDao;
@Autowired
private UrlCommGroupDao urlCommGroupDao;
@Autowired
private AsnIpCfgDao asnIpCfgDao;
public Page<CommonGroupInfo> findCommonGroupInfoList(Page<CommonGroupInfo> page, CommonGroupInfo entity) {
entity.getSqlMap().put("dsf", configScopeFilter(entity.getCurrentUser(),"r"));
entity.setPage(page);
List<CommonGroupInfo> list=commonGroupManageDao.findCommonGroupInfoList(entity);
page.setList(list);
return page;
}
public CommonGroupInfo getById(int id) {
CommonGroupInfo groupInfo=commonGroupManageDao.getById(id);
return groupInfo;
}
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
public void saveOrUpdate(CommonGroupInfo entity) throws MaatConvertException{
entity.setIsValid(1);
//新增
if(entity.getGroupId()==null){
Date createTime=new Date();
entity.setCreatorId(UserUtils.getUser().getId());
entity.setCreateTime(createTime);
//asn类型从综合服务获取groupId 非ASN组 不对config_group_info表添加数据
/*if(4==entity.getGroupType().intValue()) {
int serviceGroupId=0;
List<Integer> groupIds= ConfigServiceUtil.getId(2,1);
if(groupIds.size()>0) {
serviceGroupId=groupIds.get(0).intValue();
}else {
throw new MaatConvertException("Get asn group id failed");
}
entity.setServiceGroupId(serviceGroupId);
//新增协议分组
ConfigGroupInfo group = configGroupInfoDao.getConfigGroupInfoByGroupId(serviceGroupId);
if(group==null){
group = new ConfigGroupInfo();
group.setGroupId(serviceGroupId);
group.setGroupName(entity.getGroupName());
group.setIsIssued(0);
group.setGroupType(entity.getGroupType());
group.setAsnId(entity.getAsnNo());
configGroupInfoDao.insertConfigGroupInfo(group);
// if(group.getGroupType().intValue()==4) {
// AsnCacheUtils.put(entity.getAsnNo(), group);
// }
}
}*/
commonGroupManageDao.insert(entity);
//修改
}else{
Date editTime=new Date();
entity.setEditorId(UserUtils.getUser().getId());
entity.setEditTime(editTime);
commonGroupManageDao.update(entity);
}
}
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
public void deldete(String ids, int isValid){
//TODO 公共组删除时需检索是否有被对应公共组配置引用,被引用的公共组无法删除
IpCommGroupCfgService ipGroupCfgService = SpringContextHolder.getBean(IpCommGroupCfgService.class);
CommonGroupInfo entity=new CommonGroupInfo();
Date editTime=new Date();
entity.setEditorId(UserUtils.getUser().getId());
entity.setEditTime(editTime);
entity.setIsValid(isValid);
if(!StringUtil.isEmpty(ids)){
for (String id : ids.split(",")) {
if(!StringUtil.isEmpty(id)){
entity.setGroupId(Integer.parseInt(id));
commonGroupManageDao.update(entity);
}
}
}
}
// 查询指定类型的分组信息
public List<CommonGroupInfo> findCommonGroupInfosByType(int type) {
List<CommonGroupInfo> list=commonGroupManageDao.findCommonGroupInfosByType(type);
return list;
}
public List<CommonGroupInfo> findGroupInfoList(String ids) {
List<CommonGroupInfo> list=commonGroupManageDao.findGroupInfoList(ids);
return list;
}
/**
* 删除时校验分组是否被引用,未被引用可删除
* @param groupIds
* @return false未被引用 / true已被引用
*/
public boolean checkIsIssued(String groupIds) {
// 组织格式
Map<Integer,Set<Integer>> map = new HashMap<Integer,Set<Integer>>();
for(String str : groupIds.split(",")) {
Integer id = Integer.valueOf(str.substring(0, str.indexOf("_")));
Integer type = Integer.valueOf(str.substring(str.indexOf("_")+1));
if(map.containsKey(type)) {
Set<Integer> set = map.get(type);
set.add(id);
map.put(type, set);
}else {
Set<Integer> set = new HashSet<Integer>();
set.add(id);
map.put(type, set);
}
}
// 根据类型去相应配置查询,若存在被引用的则限制操作
Set<Integer> keySet = map.keySet();
for (Integer type : keySet) {
Set<Integer> set = map.get(type);
String str = set.toString();
String ids = str.substring(1, str.indexOf("]"));
if(type == 5) {
List<IpCommCfg> list = ipCommGroupCfgDao.getCfgInfoByGroupIds(ids);
if(list.size() > 0) {
return true;
}
}else if(type == 7) {
List<UrlCommCfg> list = urlCommGroupDao.getCfgInfoByGroupIds(ids);
if(list.size() > 0) {
return true;
}
}
}
return false;
}
/*
public List<PolicyGroupInfo> findPolicyGroupInfos() {
List<PolicyGroupInfo> list=commonGroupManageDao.findPolicyGroupInfos();
return list;
}
public List<PolicyGroupInfo> findNatPolicyGroups() {
List<PolicyGroupInfo> list=commonGroupManageDao.findNatPolicyGroups();
return list;
}
public List<PolicyGroupInfo> findPolicyGroupInfosByType(int type) {
List<PolicyGroupInfo> list=commonGroupManageDao.findPolicyGroupInfosByType(type);
return list;
}
public List<PolicyGroupInfo> findHasIpPolicyGroupInfosByType(int type) {
List<PolicyGroupInfo> list=commonGroupManageDao.findHasIPPolicyGroupInfosByType(type);
return list;
}
public List<PolicyGroupInfo> findPolicyGroupInfosHasIpRegionByType(int type) {
List<PolicyGroupInfo> list=commonGroupManageDao.findPolicyGroupInfosByType(type);
return list;
}
public boolean checkIps(String groupIds) {
for(String groupId:groupIds.split(",")) {
Integer.parseInt(groupId);
}
List<Integer> hasIpList=asnIpCfgDao.hasGroupIds(groupIds);
if(hasIpList!=null&&hasIpList.size()>0) {
return true;
}
return false;
}
public PolicyGroupInfo getInfoByAsnNo(PolicyGroupInfo policyGroupInfo){
return commonGroupManageDao.getInfoByAsnNo(policyGroupInfo);
}
*//**
* IP复用配置表单-获取拥有区域信息的策略分组
* @param groupType
* @return
*//*
public List<PolicyGroupInfo> getHasAreaPolicyGroups(int groupType) {
return commonGroupManageDao.getHasAreaPolicyGroups(groupType);
}
public Integer getGroupIdByGroupName(String groupName){
return commonGroupManageDao.getGroupIdByGroupName(groupName);
}
public PolicyGroupInfo getGroupInfo(PolicyGroupInfo policyGroupInfo){
return commonGroupManageDao.getGroupInfo(policyGroupInfo);
}*/
}

View File

@@ -0,0 +1,253 @@
package com.nis.web.service.basics;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;
import org.apache.commons.collections.CollectionUtils;
import org.apache.ibatis.session.ExecutorType;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.beust.jcommander.internal.Maps;
import com.beust.jcommander.internal.Sets;
import com.google.common.collect.Lists;
import com.nis.domain.FunctionRegionDict;
import com.nis.domain.FunctionServiceDict;
import com.nis.domain.Page;
import com.nis.domain.basics.AsnGroupInfo;
import com.nis.domain.basics.AsnIpCfg;
import com.nis.domain.basics.IpCommCfg;
import com.nis.domain.configuration.BaseIpCfg;
import com.nis.domain.configuration.CfgIndexInfo;
import com.nis.domain.maat.GroupReuseAddBean;
import com.nis.domain.maat.GroupReuseCfg;
import com.nis.domain.maat.MaatCfg;
import com.nis.domain.maat.ToMaatBean;
import com.nis.domain.maat.ToMaatResult;
import com.nis.domain.maat.MaatCfg.DigestCfg;
import com.nis.domain.maat.MaatCfg.GroupCfg;
import com.nis.domain.maat.MaatCfg.IpCfg;
import com.nis.domain.maat.MaatCfg.NumBoundaryCfg;
import com.nis.domain.maat.MaatCfg.StringCfg;
import com.nis.util.ConfigServiceUtil;
import com.nis.util.Constants;
import com.nis.util.StringUtil;
import com.nis.web.dao.basics.AsnGroupInfoDao;
import com.nis.web.dao.basics.AsnIpCfgDao;
import com.nis.web.dao.basics.IpCommGroupCfgDao;
import com.nis.web.dao.basics.PolicyGroupInfoDao;
import com.nis.web.security.UserUtils;
import com.nis.web.service.BaseService;
import com.nis.web.service.SpringContextHolder;
@Service
public class IpCommGroupCfgService extends BaseService {
@Autowired
private IpCommGroupCfgDao ipCommGroupCfgDao;
@Autowired
private PolicyGroupInfoDao policyGroupInfoDao;
/**
* @param page
* @param entity
* @return
*/
public Page<IpCommCfg> findPage(Page<IpCommCfg> page, IpCommCfg entity) {
entity.getSqlMap().put("dsf", configScopeFilter(entity.getCurrentUser(),"r"));
entity.setPage(page);
List<IpCommCfg> list=ipCommGroupCfgDao.findPage(entity);
page.setList(list);
return page;
}
public List<IpCommCfg> findByPage(String ids) {
List<IpCommCfg> list=ipCommGroupCfgDao.findByPage(ids);
return list;
}
public IpCommCfg get(Long id ) {
return ipCommGroupCfgDao.get(id);
}
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
public void save(List<IpCommCfg> entitys) {
logger.warn("Start to save IP,size:"+entitys.size());
long start=System.currentTimeMillis();
for(IpCommCfg ipCfg:entitys) {
ipCommGroupCfgDao.insert(ipCfg);
}
long end=System.currentTimeMillis();
logger.warn("Save IP finish,cost:"+(end-start));
}
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
public void update(IpCommCfg entity){
ipCommGroupCfgDao.update(entity);
}
public List<IpCommCfg> getByIds(String ids) {
if(ids==null) {
throw new RuntimeException("ids is null!");
}
return ipCommGroupCfgDao.getByIds(ids);
}
//新增
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
public void saveIpCommGroupCfg(CfgIndexInfo entity) {
//TODO 组配置更新时 需检索是否被其它配置引用,若被引用需调用相应服务接口更新配置
Date createTime=new Date();
if(CollectionUtils.isNotEmpty(entity.getIpCommGroupCfgList())) {
for (int i = 0; i < entity.getIpCommGroupCfgList().size(); i++) {
BeanUtils.copyProperties(entity, entity.getIpCommGroupCfgList().get(i), new String[]{"cfgId","userregion3"});
entity.getIpCommGroupCfgList().get(i).setRequestId(0);
entity.getIpCommGroupCfgList().get(i).setClassify("0");
entity.getIpCommGroupCfgList().get(i).setAttribute("0");
entity.getIpCommGroupCfgList().get(i).setLable("0");
entity.getIpCommGroupCfgList().get(i).setCreateTime(createTime);
entity.getIpCommGroupCfgList().get(i).setCreatorId(entity.getCurrentUser().getId());
entity.getIpCommGroupCfgList().get(i).setIsValid(Constants.VALID_NO);
entity.getIpCommGroupCfgList().get(i).setIsAudit(Constants.AUDIT_NOT_YET);
entity.getIpCommGroupCfgList().get(i).setGroupId(Integer.parseInt(entity.getUserRegion3()));
ipCommGroupCfgDao.insertForBatch(entity.getIpCommGroupCfgList().get(i));
}
}
}
// @Transactional(readOnly=false,rollbackFor=RuntimeException.class)
// public void audit(List<IpCommCfg> ipCommGroupCfgs, Integer isAudit, Integer isValid) {
// // TODO Auto-generated method stub
// Set<Integer> groupIds=Sets.newHashSet();
// if(!StringUtil.isEmpty(ipCommGroupCfgs)){
// for(IpCommCfg cfg:ipCommGroupCfgs) {
// cfg.setIsValid(isValid);
// cfg.setIsAudit(isAudit);
// cfg.setAuditorId(UserUtils.getUser().getId());
// cfg.setAuditTime(new Date());
// groupIds.add(cfg.getGroupId());
// ipCommGroupCfgDao.update(cfg);
// }
// }
// //查询有效的Ip配置个数
// for(Integer groupId:groupIds) {
// Integer groupCount=ipCommGroupCfgDao.getGroupIdCount(groupId);
// if(groupCount>0){//udFlag 设置为1
// policyGroupInfoDao.updateUdFlag(groupId, 1,5);
// }else{//udFlag 设置为0
// policyGroupInfoDao.updateUdFlag(groupId, 0,5);
// }
// }
// //下发配置时改变公共组udFlag标识
// send2Maat(ipCommGroupCfgs,isValid);
// }
// public void send2Maat(List<IpCommCfg> ipCommGroupCfgs,int isValid) {
// GroupReuseAddBean maatBean = new GroupReuseAddBean();
// List<GroupReuseCfg> groupReuseList=new ArrayList<>();
// GroupReuseCfg groupReuseCfg=new GroupReuseCfg();
// List<IpCfg> ipRegionList = groupReuseCfgAddRemoveConvert(ipCommGroupCfgs,isValid,null);
// List<StringCfg> strRegionList = new ArrayList<>();
// List<NumBoundaryCfg> numRegionList = new ArrayList<>();
// groupReuseCfg.setIpRegionList(ipRegionList);
// groupReuseCfg.setStrRegionList(strRegionList);
// groupReuseCfg.setNumRegionList(numRegionList);
// groupReuseList.add(groupReuseCfg);
// maatBean.setGroupReuseCfgList(groupReuseList);
// maatBean.setAuditTime(new Date());
// maatBean.setCreatorName(UserUtils.getUser().getName());
// maatBean.setVersion(Constants.MAAT_VERSION);
// logger.warn("IP Common Region Send To Maat start");
// long start=System.currentTimeMillis();
// if(isValid==Constants.VALID_YES) {
// maatBean.setOpAction(Constants.INSERT_ACTION);
// //调用服务接口下发配置数据
// String json=gsonToJson(maatBean);
// if(ipCommGroupCfgs.size()<=100) {
// logger.info("ip 公共组域新增配置下发配置参数:"+json);
// }else {
// logger.info("ip 公共组域新增配置下发region条数"+ipCommGroupCfgs.size());
// }
// //调用服务接口下发配置
// ToMaatResult result =ConfigServiceUtil.postGroupReuseSources(json);
// logger.info("ip 公共组域新增配置响应信息:"+result.getMsg());
// }else {
// maatBean.setOpAction(Constants.UPDATE_ACTION);
// //调用服务接口下发配置数据
// String json=gsonToJson(maatBean);
// if(ipCommGroupCfgs.size()<=100) {
// logger.info("ip 公共组域删除配置下发配置参数:"+json);
// }else {
// logger.info("ip 公共组域删除配置下发region条数"+ipCommGroupCfgs.size());
//
// }
// //调用服务接口下发配置
// ToMaatResult result = ConfigServiceUtil.put(json,3);
// logger.info("asn ip复用域删除配置响应信息"+result.getMsg());
// }
// long end=System.currentTimeMillis();
// logger.warn("IP Common Region Send To Maat finish,cost:"+(end-start));
// }
public void delete(String ids) {
// TODO 公共组配置删除时 需检索是否被其它业务配置引用,没被引用可删除
if(ids==null) {
throw new RuntimeException("ids is null!");
}
ipCommGroupCfgDao.delete(ids);
}
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
public void saveAndSend(FunctionRegionDict regionDict, FunctionServiceDict serviceDict, List<BaseIpCfg> cfgs,boolean send) {
logger.warn("Start to save IP,size:"+cfgs.size());
long start=System.currentTimeMillis();
SqlSessionFactory sqlSessionFactory=SpringContextHolder.getBean(SqlSessionFactory.class);
SqlSession batchSqlSession = null;
//需要通过新增域接口新增的ip集合
Map<Integer,Integer> groupCount=Maps.newHashMap();
List<IpCommCfg> ipCommCfgs=new ArrayList(cfgs.size());
try{
batchSqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, false);
for(BaseIpCfg cfg:cfgs) {
IpCommCfg ipCommCfg=new IpCommCfg();
BeanUtils.copyProperties(cfg, ipCommCfg);
ipCommCfgs.add(ipCommCfg);
((IpCommGroupCfgDao) batchSqlSession.getMapper(IpCommGroupCfgDao.class)).insertForBatch(ipCommCfg);
// if(send) {
// if(groupCount.containsKey(ipCommCfg.getGroupId())) {
// groupCount.put(ipCommCfg.getGroupId(), groupCount.get(ipCommCfg.getGroupId())+1);
// }else {
// groupCount.put(ipCommCfg.getGroupId(), 1);
// }
// }
}
// if(send) {
// if(groupCount.size()>0) {
// for(Entry<Integer, Integer> groupId:groupCount.entrySet()) {
// policyGroupInfoDao.updateUdFlag(groupId.getKey(), 1,5);
// }
//
// this.send2Maat(ipCommCfgs, Constants.VALID_YES);
// }
// }
batchSqlSession.commit();
}finally {
if(batchSqlSession != null){
batchSqlSession.close();
}
}
long end=System.currentTimeMillis();
logger.warn("Save IP finish,cost:"+(end-start));
cfgs.clear();
cfgs=null;
}
}