From 6880363d9a3db75ba95fe3344dfb5a65196c7353 Mon Sep 17 00:00:00 2001 From: duandongmei Date: Mon, 15 Oct 2018 10:14:01 +0800 Subject: [PATCH] =?UTF-8?q?voip=E7=95=8C=E9=9D=A2=E5=8E=BB=E6=8E=89?= =?UTF-8?q?=E6=97=A0=E7=94=A8=E7=9A=84=E6=A3=80=E7=B4=A2=E6=9D=A1=E4=BB=B6?= =?UTF-8?q?=20=E6=91=98=E8=A6=81=E6=96=87=E4=BB=B6=E7=B1=BB=E5=9E=8B?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=9F=B3=E8=A7=86=E9=A2=91=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E7=B1=BB=20ip=E5=92=8Chttp=E5=A2=9E=E5=8A=A0=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E5=AF=BC=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/nis/domain/configuration/BaseCfg.java | 42 +- .../nis/domain/configuration/BaseIpCfg.java | 20 +- .../domain/configuration/BaseStringCfg.java | 31 +- .../configuration/ComplexkeywordCfg.java | 29 + .../configuration/template/IpAllTemplate.java | 85 +++ .../nis/domain/specific/ConfigGroupInfo.java | 5 + .../java/com/nis/util/excel/ExcelField.java | 4 + .../java/com/nis/util/excel/ExportExcel.java | 634 ++++++++++++++-- .../nis/web/controller/BaseController.java | 680 +++++++++++++++++- .../configuration/CommonController.java | 16 +- .../configuration/ntc/IpController.java | 147 +++- .../configuration/ntc/WebsiteController.java | 130 ++++ .../proxy/ControlController.java | 2 +- .../service/configuration/IpCfgService.java | 9 + .../configuration/WebsiteCfgService.java | 23 + src/main/resources/nis.properties | 2 +- src/main/resources/sql/truncate_tables.sql | 2 +- .../WEB-INF/include/excel/importModal.jsp | 162 +++++ src/main/webapp/WEB-INF/include/header.jsp | 2 + src/main/webapp/WEB-INF/tags/sys/delRow.tag | 12 +- .../WEB-INF/views/cfg/av/voip/voipList.jsp | 7 +- .../WEB-INF/views/cfg/ipaddr/ipList.jsp | 6 +- .../WEB-INF/views/cfg/website/httpList.jsp | 3 +- .../webapp/WEB-INF/views/log/ntc/ipList.jsp | 8 +- src/main/webapp/WEB-INF/views/report/list.jsp | 16 +- .../static/pages/scripts/importExcel.js | 29 + 26 files changed, 1981 insertions(+), 125 deletions(-) create mode 100644 src/main/java/com/nis/domain/configuration/template/IpAllTemplate.java create mode 100644 src/main/webapp/WEB-INF/include/excel/importModal.jsp create mode 100644 src/main/webapp/static/pages/scripts/importExcel.js diff --git a/src/main/java/com/nis/domain/configuration/BaseCfg.java b/src/main/java/com/nis/domain/configuration/BaseCfg.java index 52c16c1c8..09aeae7e8 100644 --- a/src/main/java/com/nis/domain/configuration/BaseCfg.java +++ b/src/main/java/com/nis/domain/configuration/BaseCfg.java @@ -36,19 +36,20 @@ public class BaseCfg extends BaseEntity implements Cloneable{ protected String showName;//表在界面上展示的名称 protected String seltype;//选中类型,页面搜索用 protected String tableName; - @ExcelField(title="userregion1") + @ExcelField(title="userregion1",sort=1001) protected String userRegion1; - @ExcelField(title="userregion2") + @ExcelField(title="userregion2",sort=1002) protected String userRegion2; - @ExcelField(title="userregion3") + @ExcelField(title="userregion3",sort=1003) protected String userRegion3; - @ExcelField(title="userregion4") + @ExcelField(title="userregion4",sort=1004) protected String userRegion4; - @ExcelField(title="userregion5") + @ExcelField(title="userregion5",sort=1005) protected String userRegion5; /** * 编译id */ + @ExcelField(title="cfg_id",sort=0) protected Integer compileId ; /** * @Fields serialVersionUID:TODO(用一句话描述这个变量表示什么) @@ -64,25 +65,25 @@ public class BaseCfg extends BaseEntity implements Cloneable{ /** * 配置描述 */ - @ExcelField(title="config_describe") + @ExcelField(title="config_describe",sort=1) protected String cfgDesc; /** * GK类型 */ @Expose - @ExcelField(title="action",dictType="SERVICE_ACTION") + @ExcelField(title="action",dictType="SERVICE_ACTION",sort=2) protected Integer action; /** * 有效标识 */ - @ExcelField(title="valid_identifier",dictType="VALID_IDENTIFIER") + @ExcelField(title="valid_identifier",dictType="VALID_IDENTIFIER",sort=9) @Expose protected Integer isValid; /** * 是否审核 */ - @ExcelField(title="is_audit",dictType="AUDIT_STATUS") + @ExcelField(title="is_audit",dictType="AUDIT_STATUS",sort=10) protected Integer isAudit; /** * 创建人员 @@ -91,12 +92,12 @@ public class BaseCfg extends BaseEntity implements Cloneable{ /** * 创建人员 */ - @ExcelField(title="creator") + @ExcelField(title="creator",sort=11) protected String creatorName; /** * 配置时间 */ - @ExcelField(title="config_time") + @ExcelField(title="config_time",sort=12) protected Date createTime; /** * 修改人员 @@ -105,12 +106,12 @@ public class BaseCfg extends BaseEntity implements Cloneable{ /** * 创建人员 */ - @ExcelField(title="editor") + @ExcelField(title="editor",sort=13) protected String editorName; /** * 修改时间 */ - @ExcelField(title="edit_time") + @ExcelField(title="edit_time",sort=14) protected Date editTime; /** * 审核人员 @@ -119,13 +120,13 @@ public class BaseCfg extends BaseEntity implements Cloneable{ /** * 审核人员 */ - @ExcelField(title="auditor") + @ExcelField(title="auditor",sort=15) protected String auditorName; /** * 审核时间 */ @Expose - @ExcelField(title="audit_time") + @ExcelField(title="audit_time",sort=16) @SerializedName("opTime") protected Date auditTime; /** @@ -141,27 +142,27 @@ public class BaseCfg extends BaseEntity implements Cloneable{ /** * 来函 */ - @ExcelField(title="letter") + @ExcelField(title="letter",sort=5) protected String requestName; /** * 是否区域gk */ - @ExcelField(title="whether_area_block",dictType="WHETHER_AREA_BLOCK") + @ExcelField(title="whether_area_block",dictType="WHETHER_AREA_BLOCK",sort=4) protected Integer isAreaEffective; /** * 分类 */ - @ExcelField(title="classification",dictType="type") + @ExcelField(title="classification",dictType="type",sort=6) protected String classify; /** * 性质 */ - @ExcelField(title="attribute",dictType="attribute") + @ExcelField(title="attribute",dictType="attribute",sort=7) protected String attribute; /** * 标签 */ - @ExcelField(title="label",dictType="label") + @ExcelField(title="label",dictType="label",sort=8) protected String lable; /** * 分类 @@ -212,6 +213,7 @@ public class BaseCfg extends BaseEntity implements Cloneable{ /** * do_log属性在界面(do_log:0不需要1记录所有日志2只记录结构化日志。默认是2) */ + @ExcelField(title="do_log",dictType="DO_LOG",sort=3) protected Integer doLog = Constants.MAAT_CFG_DOLOG_DEFAULT; diff --git a/src/main/java/com/nis/domain/configuration/BaseIpCfg.java b/src/main/java/com/nis/domain/configuration/BaseIpCfg.java index 989c85006..b92e82418 100644 --- a/src/main/java/com/nis/domain/configuration/BaseIpCfg.java +++ b/src/main/java/com/nis/domain/configuration/BaseIpCfg.java @@ -42,24 +42,24 @@ public class BaseIpCfg extends BaseCfg { */ @Expose @SerializedName("ipType") - @ExcelField(title="ip_type",dictType="IP_TYPE") + @ExcelField(title="ip_type",dictType="IP_TYPE",sort=101) protected Integer ipType; - @ExcelField(title="ip_pattern",dictType="IP_PATTERN") + @ExcelField(title="ip_pattern",dictType="IP_PATTERN",sort=102) protected Integer ipPattern; - @ExcelField(title="client_ip") + @ExcelField(title="client_ip",sort=103) protected String srcIpAddress; - @ExcelField(title="server_ip") + @ExcelField(title="server_ip",sort=104) protected String destIpAddress; - @ExcelField(title="port_pattern",dictType="PORT_PATTERN") + @ExcelField(title="port_pattern",dictType="PORT_PATTERN",sort=105) protected Integer portPattern; - @ExcelField(title="client_port") + @ExcelField(title="client_port",sort=106) protected String srcPort; - @ExcelField(title="server_port") + @ExcelField(title="server_port",sort=107) protected String destPort; protected Integer dnsStrategyId; - @ExcelField(title="ir_type",dictType="IR_TYPE") + @ExcelField(title="ir_type",dictType="IR_TYPE",sort=108) protected Integer irType; - @ExcelField(title="group_name") + @ExcelField(title="group_name",sort=109) protected String groupName; private List ntcSubscribeIdCfgList; @@ -97,12 +97,14 @@ public class BaseIpCfg extends BaseCfg { */ @Expose @SerializedName("direction") + @ExcelField(title="direction",dictType="DIRECTION",sort=110) protected Integer direction ; /** * 方向 */ @Expose @SerializedName("protocol") + @ExcelField(title="protocol",dictType="PROTOCOL",sort=111) protected Integer protocol ; /** * 协议ID diff --git a/src/main/java/com/nis/domain/configuration/BaseStringCfg.java b/src/main/java/com/nis/domain/configuration/BaseStringCfg.java index c7954007f..ddba069f6 100644 --- a/src/main/java/com/nis/domain/configuration/BaseStringCfg.java +++ b/src/main/java/com/nis/domain/configuration/BaseStringCfg.java @@ -35,7 +35,7 @@ public class BaseStringCfg extends BaseCfg { */ @Expose @SerializedName("keywords") - @ExcelField(title="key_word") + @ExcelField(title="key_word",sort=201) protected String cfgKeywords; protected String cfgKeywordsShowName; @@ -49,21 +49,30 @@ public class BaseStringCfg extends BaseCfg { * 表达式类型 */ @Expose - @ExcelField(title="expression_type") + @ExcelField(title="expression_type",dictType="EXPRESSION_TYPE",sort=202) @SerializedName("exprType") protected Integer exprType ; /** * 匹配方式 */ @Expose - @ExcelField(title="match_method") + @ExcelField(title="match_method",dictType="MATCH_METHOD",sort=203) @SerializedName("matchMethod") protected Integer matchMethod ; + /** + * 是否hex + */ + @ExcelField(title="is_hex",sort=204) + protected Integer isHex; + /** + * 是否hex + */ + @ExcelField(title="is_case_insenstive",sort=205) + protected Integer isCaseInsenstive; /** * 是否hex二进制 */ @Expose - @ExcelField(title="whether_hexbinary") @SerializedName("isHexbin") protected Integer isHexbin; @@ -167,4 +176,18 @@ public class BaseStringCfg extends BaseCfg { public void setNtcSubscribeIdCfg(NtcSubscribeIdCfg ntcSubscribeIdCfg) { this.ntcSubscribeIdCfg = ntcSubscribeIdCfg; } + public Integer getIsHex() { + return isHex=this.isHexbin; + } + public void setIsHex(Integer isHex) { + this.isHex = this.isHexbin; + } + public Integer getIsCaseInsenstive() { + return isCaseInsenstive=this.isHexbin; + } + public void setIsCaseInsenstive(Integer isCaseInsenstive) { + this.isCaseInsenstive =this.isHexbin;; + } + + } diff --git a/src/main/java/com/nis/domain/configuration/ComplexkeywordCfg.java b/src/main/java/com/nis/domain/configuration/ComplexkeywordCfg.java index e65a165d4..158a67cb0 100644 --- a/src/main/java/com/nis/domain/configuration/ComplexkeywordCfg.java +++ b/src/main/java/com/nis/domain/configuration/ComplexkeywordCfg.java @@ -12,6 +12,7 @@ import org.apache.commons.lang3.StringEscapeUtils; import com.google.gson.annotations.Expose; import com.google.gson.annotations.SerializedName; +import com.nis.util.excel.ExcelField; /** * @ClassName: BaseEnhancedStringConfig.java @@ -32,6 +33,7 @@ public class ComplexkeywordCfg extends BaseCfg{ * 匹配区域 */ @Expose + @ExcelField(title="district",sort=301) @SerializedName("district") protected String district ; protected String districtShowName; @@ -40,6 +42,7 @@ public class ComplexkeywordCfg extends BaseCfg{ */ @Expose @SerializedName("keywords") + @ExcelField(title="key_word",sort=302) protected String cfgKeywords; protected String keywordsShowName; /** @@ -47,13 +50,27 @@ public class ComplexkeywordCfg extends BaseCfg{ */ @Expose @SerializedName("exprType") + @ExcelField(title="expression_type",dictType="EXPRESSION_TYPE",sort=303) protected Integer exprType ; /** * 匹配方式 */ @Expose + @ExcelField(title="match_method",dictType="MATCH_METHOD",sort=304) @SerializedName("matchMethod") protected Integer matchMethod ; + + /** + * 是否hex + */ + @ExcelField(title="is_hex",sort=305) + protected Integer isHex; + /** + * 是否hex + */ + @ExcelField(title="is_case_insenstive",sort=306) + protected Integer isCaseInsenstive; + /** * 是否hex二进制 */ @@ -131,6 +148,18 @@ public class ComplexkeywordCfg extends BaseCfg{ public void setIsHexbin(Integer isHexbin) { this.isHexbin = isHexbin; } + public Integer getIsHex() { + return isHex= this.isHexbin; + } + public void setIsHex(Integer isHex) { + this.isHex = this.isHexbin; + } + public Integer getIsCaseInsenstive() { + return isCaseInsenstive=this.isHexbin; + } + public void setIsCaseInsenstive(Integer isCaseInsenstive) { + this.isCaseInsenstive =this.isHexbin;; + } /* (non-Javadoc) * @see com.nis.domain.configuration.BaseCfg#initDefaultValue() */ diff --git a/src/main/java/com/nis/domain/configuration/template/IpAllTemplate.java b/src/main/java/com/nis/domain/configuration/template/IpAllTemplate.java new file mode 100644 index 000000000..5ffb508b9 --- /dev/null +++ b/src/main/java/com/nis/domain/configuration/template/IpAllTemplate.java @@ -0,0 +1,85 @@ +/** + *@Title: BaseStringConfig.java + *@Package com.nis.domain.restful + *@Description TODO + *@author dell + *@date 2018年2月5日 下午5:26:02 + *@version 版本号 + */ +package com.nis.domain.configuration.template; + +import com.nis.util.excel.ExcelField; + +/** + * @Description: excel导入IP类配置 + */ +public class IpAllTemplate { + + /** + * @Fields serialVersionUID:TODO(用一句话描述这个变量表示什么) + * + * @since 1.0.0 + */ + + + + private String cfgDesc; + private String srcIpAddress; + private String destIpAddress; + private String srcPort; + private String destPort; + private Integer protocol; + private Integer direction; + + @ExcelField(title="config_describe",align=2,sort=1) + public String getCfgDesc() { + return cfgDesc; + } + public void setCfgDesc(String cfgDesc) { + this.cfgDesc = cfgDesc; + } + @ExcelField(title="client_ip",align=2,sort=2) + public String getSrcIpAddress() { + return srcIpAddress; + } + public void setSrcIpAddress(String srcIpAddress) { + this.srcIpAddress = srcIpAddress; + } + @ExcelField(title="server_ip",align=2,sort=3) + public String getDestIpAddress() { + return destIpAddress; + } + public void setDestIpAddress(String destIpAddress) { + this.destIpAddress = destIpAddress; + } + + @ExcelField(title="client_port",align=2,sort=4) + public String getSrcPort() { + return srcPort; + } + public void setSrcPort(String srcPort) { + this.srcPort = srcPort; + } + @ExcelField(title="server_port",align=2,sort=5) + public String getDestPort() { + return destPort; + } + public void setDestPort(String destPort) { + this.destPort = destPort; + } + + @ExcelField(title="protocol",align=2,sort=6) + public Integer getProtocol() { + return protocol; + } + public void setProtocol(Integer protocol) { + this.protocol = protocol; + } + @ExcelField(title="direction",align=2,sort=7) + public Integer getDirection() { + return direction; + } + public void setDirection(Integer direction) { + this.direction = direction; + } +} diff --git a/src/main/java/com/nis/domain/specific/ConfigGroupInfo.java b/src/main/java/com/nis/domain/specific/ConfigGroupInfo.java index 72f75145b..0e78c5bbd 100644 --- a/src/main/java/com/nis/domain/specific/ConfigGroupInfo.java +++ b/src/main/java/com/nis/domain/specific/ConfigGroupInfo.java @@ -2,14 +2,19 @@ package com.nis.domain.specific; import java.util.Date; +import com.google.gson.annotations.Expose; +import com.nis.util.excel.ExcelField; + public class ConfigGroupInfo { private Integer id; private Integer groupId; + @ExcelField(title="group_name",sort=302) private String groupName; private Integer isIssued; private Date insertTime; private Date updateTime; private Integer groupType; + @ExcelField(title="cfg_id",sort=301) private Integer compileId; public Integer getCompileId() { diff --git a/src/main/java/com/nis/util/excel/ExcelField.java b/src/main/java/com/nis/util/excel/ExcelField.java index b4927dab5..5bb6935b7 100644 --- a/src/main/java/com/nis/util/excel/ExcelField.java +++ b/src/main/java/com/nis/util/excel/ExcelField.java @@ -26,6 +26,10 @@ public @interface ExcelField { * 导出字段标题(需要添加批注请用“**”分隔,标题**批注,仅对导出模板有效) */ String title(); + /** + * 导出字段注释(仅对导出模板有效) + */ + String comment() default ""; /** * 字段类型(0:导出导入;1:仅导出;2:仅导入) diff --git a/src/main/java/com/nis/util/excel/ExportExcel.java b/src/main/java/com/nis/util/excel/ExportExcel.java index 4adc16375..efa0da36b 100644 --- a/src/main/java/com/nis/util/excel/ExportExcel.java +++ b/src/main/java/com/nis/util/excel/ExportExcel.java @@ -9,14 +9,17 @@ import java.io.IOException; import java.io.OutputStream; import java.lang.reflect.Field; import java.lang.reflect.Method; +import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.Date; import java.util.HashMap; +import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Properties; +import java.util.Set; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -39,11 +42,16 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.google.common.collect.Lists; +import com.nis.domain.FunctionRegionDict; +import com.nis.domain.SysDataDictionaryItem; import com.nis.domain.basics.ServiceDictInfo; import com.nis.util.DictUtils; import com.nis.util.Encodes; import com.nis.util.Reflections; import com.nis.util.StringUtil; +import com.sun.xml.internal.rngom.ast.builder.CommentList; + +import sun.util.logging.resources.logging; /** * 导出Excel文件(导出“XLSX”格式,支持大数据量导出 @see org.apache.poi.ss.SpreadsheetVersion) @@ -64,6 +72,11 @@ public class ExportExcel { */ private Sheet sheet; + /** + * 工作表对象 + */ + private Map sheets; + /** * 样式列表 */ @@ -74,10 +87,16 @@ public class ExportExcel { */ private int rownum; + /** + * 当前行号 + */ + private Map rownums; + /** * 注解列表(Object[]{ ExcelField, Field/Method }) */ List annotationList = Lists.newArrayList(); + Map> annotationMap=new HashMap<>(); /** * //递归获取cls实体对象及父级对象的属性 @@ -111,6 +130,159 @@ public class ExportExcel { getFields(list,cls.getSuperclass()); } } + public String[] validRegionFieldAndSetComment(String headerStr,String commentStr,FunctionRegionDict region,Properties msgProp){ + String[] titleInfo=new String[2]; + if(region.getIsMaat().equals(1)){//maat + if(region.getRegionType().equals(1)){//IP配置 + //ip配置需要导入的信息:srcIp srcPort destIp destPort Protocol Direction + //确定需要导入的srcIp srcPort destIp destPort信息 + if(StringUtil.isEmpty(region.getConfigIpPortShow())){//无源目的ip和端口 + if("client_ip".equals(headerStr) + || "server_ip".equals(headerStr) + || "client_port".equals(headerStr) + || "server_port".equals(headerStr) + ){ + headerStr=""; + commentStr=""; + } + }else{ + if("client_ip".equals(headerStr)){ + if(((","+region.getConfigIpPortShow()+",").indexOf(",1,") > -1) ){ + commentStr=""; + if((","+region.getConfigIpType()+",").indexOf(",4,") > -1){ + if((","+region.getConfigIpPattern()+",").indexOf(",3,") > -1){ + commentStr=commentStr+"0.0.0.0"+"\n"; + } + if((","+region.getConfigIpPattern()+",").indexOf(",2,") > -1){ + commentStr=commentStr+"0.0.0.0-1"+"\n"; + } + if((","+region.getConfigIpPattern()+",").indexOf(",1,") > -1){ + commentStr=commentStr+"0.0.0.0/16"+"\n"; + } + } + if((","+region.getConfigIpType()+",").indexOf(",6,") > -1){ + if((","+region.getConfigIpPattern()+",").indexOf(",3,") > -1){ + commentStr=commentStr+"::"+"\n"; + } + if((","+region.getConfigIpPattern()+",").indexOf(",2,") > -1){ + commentStr=commentStr+"::-::"+"\n"; + } + if((","+region.getConfigIpPattern()+",").indexOf(",1,") > -1){ + commentStr=commentStr+"::/128"+"\n"; + } + } + }else{ + headerStr=""; + commentStr=""; + } + } + if("server_ip".equals(headerStr)){ + if((","+region.getConfigIpPortShow()+",").indexOf(",3,") > -1){ + commentStr=""; + if((","+region.getConfigIpType()+",").indexOf(",4,") > -1){ + if((","+region.getConfigIpPattern()+",").indexOf(",3,") > -1){ + commentStr=commentStr+"0.0.0.0"+"\n"; + } + if((","+region.getConfigIpPattern()+",").indexOf(",2,") > -1){ + commentStr=commentStr+"0.0.0.0-1"+"\n"; + } + if((","+region.getConfigIpPattern()+",").indexOf(",1,") > -1){ + commentStr=commentStr+"0.0.0.0/16"+"\n"; + } + } + if((","+region.getConfigIpType()+",").indexOf(",6,") > -1){ + if((","+region.getConfigIpPattern()+",").indexOf(",3,") > -1){ + commentStr=commentStr+"::"+"\n"; + } + if((","+region.getConfigIpPattern()+",").indexOf(",2,") > -1){ + commentStr=commentStr+"::-::"+"\n"; + } + if((","+region.getConfigIpPattern()+",").indexOf(",1,") > -1){ + commentStr=commentStr+"::/128"+"\n"; + } + } + }else{ + headerStr=""; + commentStr=""; + } + } + if("client_port".equals(headerStr)){ + if(((","+region.getConfigIpPortShow()+",").indexOf(",2,") > -1)){ + commentStr=""; + if((","+region.getConfigPortPattern()+",").indexOf(",1,") > -1){ + commentStr=commentStr+"0["+msgProp.getProperty("val_src_port")+"]"+"\n"; + } + if((","+region.getConfigPortPattern()+",").indexOf(",2,") > -1){ + commentStr=commentStr+"0/65535["+msgProp.getProperty("val_src_port_mask")+"]"+"\n"; + } + }else{ + headerStr=""; + commentStr=""; + } + } + if("server_port".equals(headerStr)){ + if((","+region.getConfigIpPortShow()+",").indexOf(",4,") > -1){ + commentStr=""; + if((","+region.getConfigPortPattern()+",").indexOf(",1,") > -1){ + commentStr=commentStr+"0["+msgProp.getProperty("val_src_port")+"]"+"\n"; + } + if((","+region.getConfigPortPattern()+",").indexOf(",2,") > -1){ + commentStr=commentStr+"0/65535["+msgProp.getProperty("val_src_port_mask")+"]"+"\n"; + } + }else{ + headerStr=""; + commentStr=""; + } + } + } + //导入的Protocol + if("protocol".equals(headerStr)){ + if(StringUtil.isEmpty(region.getConfigProtocol())){ + headerStr=""; + commentStr=""; + }else{ + commentStr=""; + List protocol=DictUtils.getDictList("PROTOCOL"); + if(protocol !=null && protocol.size()>0){ + for (SysDataDictionaryItem sysDataDictionaryItem : protocol) { + if((","+region.getConfigProtocol()+",").indexOf(","+sysDataDictionaryItem.getItemCode()+",") >0){ + if(StringUtil.isEmpty(msgProp.getProperty(sysDataDictionaryItem.getItemValue()))){ + commentStr=commentStr+sysDataDictionaryItem.getItemCode()+":"+sysDataDictionaryItem.getItemValue()+"\n"; + }else{ + commentStr=commentStr+sysDataDictionaryItem.getItemCode()+":"+msgProp.getProperty(sysDataDictionaryItem.getItemValue())+"\n"; + } + + } + } + } + } + } + + //导入的Direction + if("direction".equals(headerStr)){ + if(StringUtil.isEmpty(region.getConfigProtocol())){ + headerStr=""; + commentStr=""; + }else{ + commentStr=""; + List direction=DictUtils.getDictList("DIRECTION"); + if(direction !=null && direction.size()>0){ + for (SysDataDictionaryItem sysDataDictionaryItem : direction) { + if(StringUtil.isEmpty(msgProp.getProperty(sysDataDictionaryItem.getItemValue()))){ + commentStr=commentStr+sysDataDictionaryItem.getItemCode()+":"+sysDataDictionaryItem.getItemValue()+"\n"; + }else{ + commentStr=commentStr+sysDataDictionaryItem.getItemCode()+":"+msgProp.getProperty(sysDataDictionaryItem.getItemValue())+"\n"; + } + } + } + } + } + } + } + titleInfo[0]=headerStr; + titleInfo[1]=commentStr; + return titleInfo; + } /** * //递归获取cls实体对象及父级对象的method * @param list @@ -225,18 +397,116 @@ public class ExportExcel { }); // Initialize List headerList = Lists.newArrayList(); + List commentList = Lists.newArrayList(); for (Object[] os : annotationList){ - String t = ((ExcelField)os[0]).title(); + String titleStr = ((ExcelField)os[0]).title(); + String commentStr = ((ExcelField)os[0]).comment(); // 如果是导出,则去掉注释 if (type==1){ - String[] ss = StringUtils.split(t, "**", 2); - if (ss.length==2){ - t = ss[0]; + commentStr=""; + } + headerList.add(titleStr); + commentList.add(commentStr); + } + initialize(title, headerList,commentList); + } + /** + * 构造函数 + * @param FunctionRegionDict region信息 + * @param msgProp 国际化配置 + * @param title 表格标题,传“空值”,表示无标题 + * @param cls 实体对象,通过annotation.ExportField获取标题 + * @param type 导出类型(1:导出数据;2:导出模板) + * @param groups 导入分组 + */ + public ExportExcel(FunctionRegionDict region,Properties msgProp,String title, Class cls, int type, int... groups){ + List list=new ArrayList(); + // Get annotation field + //递归获取cls实体对象及父级对象的属性 + getFields(list, cls); + + if(!StringUtil.isEmpty(list)){ + for (Field f : list){ + ExcelField ef = f.getAnnotation(ExcelField.class); + if (ef != null && (ef.type()==0 || ef.type()==type)){ + if (groups!=null && groups.length>0){ + boolean inGroup = false; + for (int g : groups){ + if (inGroup){ + break; + } + for (int efg : ef.groups()){ + if (g == efg){ + inGroup = true; + annotationList.add(new Object[]{ef, f}); + break; + } + } + } + }else{ + annotationList.add(new Object[]{ef, f}); + } } } - headerList.add(t); } - initialize(title, headerList); + List ms=new ArrayList(); + // Get annotation method + //递归获取cls实体对象及父级对象的属性 + getMethods(ms, cls); + if(!StringUtil.isEmpty(ms)){ + for (Method m : ms){ + ExcelField ef = m.getAnnotation(ExcelField.class); + if (ef != null && (ef.type()==0 || ef.type()==type)){ + if (groups!=null && groups.length>0){ + boolean inGroup = false; + for (int g : groups){ + if (inGroup){ + break; + } + for (int efg : ef.groups()){ + if (g == efg){ + inGroup = true; + annotationList.add(new Object[]{ef, m}); + break; + } + } + } + }else{ + annotationList.add(new Object[]{ef, m}); + } + } + } + } + // Field sorting + Collections.sort(annotationList, new Comparator() { + public int compare(Object[] o1, Object[] o2) { + return new Integer(((ExcelField)o1[0]).sort()).compareTo( + new Integer(((ExcelField)o2[0]).sort())); + }; + }); + // Initialize + List headerList = Lists.newArrayList(); + List commentList = Lists.newArrayList(); + for (Object[] os : annotationList){ + String titleStr = ((ExcelField)os[0]).title(); + String commentStr = ((ExcelField)os[0]).comment(); + + // 如果是导出,则去掉注释 + if (type==1){ + commentStr=""; + }else{ + //判断此业务导出模板内容,设置导入提示信息 + String[] titleInfo=validRegionFieldAndSetComment(titleStr,commentStr,region,msgProp); + titleStr=titleInfo[0]; + commentStr=titleInfo[1]; + } + if(!StringUtil.isEmpty(titleStr)){ + headerList.add(msgProp.getProperty(titleStr)==null?titleStr:msgProp.getProperty(titleStr)); + commentList.add(commentStr); + } + + } + initialize(title, headerList,commentList); } /** * 构造函数 @@ -283,9 +553,6 @@ public class ExportExcel { if(!StringUtil.isEmpty(ms)){ for (Method m : ms){ ExcelField ef = m.getAnnotation(ExcelField.class); - if(m.getName().equals("getSrcIpAddress")) { - System.out.println(ef.title()); - } if (ef != null && (ef.type()==0 || ef.type()==type)){ if (groups!=null && groups.length>0){ boolean inGroup = false; @@ -316,18 +583,22 @@ public class ExportExcel { }); // Initialize List headerList = Lists.newArrayList(); + List commentList = Lists.newArrayList(); for (Object[] os : annotationList){ - String t = ((ExcelField)os[0]).title(); + String titleStr = ((ExcelField)os[0]).title(); + String commentStr = ((ExcelField)os[0]).comment(); + // 如果是导出,则去掉注释 if (type==1){ - String[] ss = StringUtils.split(t, "**", 2); - if (ss.length==2){ - t = ss[0]; - } + commentStr=""; } - headerList.add(msgProp.getProperty(t)==null?t:msgProp.getProperty(t)); + if(!StringUtil.isEmpty(titleStr)){ + headerList.add(msgProp.getProperty(titleStr)==null?titleStr:msgProp.getProperty(titleStr)); + commentList.add(commentStr); + } + } - initialize(title, headerList); + initialize(title, headerList,commentList); } /** * 构造函数 @@ -347,34 +618,39 @@ public class ExportExcel { if(!StringUtil.isEmpty(list)){ for (Field f : list){ ExcelField ef = f.getAnnotation(ExcelField.class); + /*if(ef==null || StringUtil.isEmpty(ef.title())){ + break; + } + String titleP=StringUtil.isEmpty(msgProp.get(ef.title())) ? ef.title().toString():msgProp.get(ef.title()).toString(); boolean export=false; for(String column:cloumnArray) { - if(ef!=null&&column.equals(ef.title())) { + + if(ef!=null&&column.equals(titleP)) { export=true; break; } } - if(export) { - if (ef != null && (ef.type()==0 || ef.type()==type)){ - if (groups!=null && groups.length>0){ - boolean inGroup = false; - for (int g : groups){ - if (inGroup){ + if(export) {*/ + if (ef != null && (ef.type()==0 || ef.type()==type)){ + if (groups!=null && groups.length>0){ + boolean inGroup = false; + for (int g : groups){ + if (inGroup){ + break; + } + for (int efg : ef.groups()){ + if (g == efg){ + inGroup = true; + annotationList.add(new Object[]{ef, f}); break; } - for (int efg : ef.groups()){ - if (g == efg){ - inGroup = true; - annotationList.add(new Object[]{ef, f}); - break; - } - } } - }else{ - annotationList.add(new Object[]{ef, f}); } + }else{ + annotationList.add(new Object[]{ef, f}); } } + /*}*/ } } List ms=new ArrayList(); @@ -423,43 +699,46 @@ public class ExportExcel { }); // Initialize List headerList = Lists.newArrayList(); + List commentList = Lists.newArrayList(); for (Object[] os : annotationList){ - String t = ((ExcelField)os[0]).title(); + String titleStr = ((ExcelField)os[0]).title(); + String commentStr = ((ExcelField)os[0]).comment(); // 如果是导出,则去掉注释 if (type==1){ - String[] ss = StringUtils.split(t, "**", 2); - if (ss.length==2){ - t = ss[0]; - } + commentStr=""; } - headerList.add(msgProp.getProperty(t)==null?t:msgProp.getProperty(t)); + headerList.add(msgProp.getProperty(titleStr)==null?titleStr:msgProp.getProperty(titleStr)); + commentList.add(commentStr); } - initialize(title, headerList); + initialize(title, headerList,commentList); } + /** * 构造函数 * @param title 表格标题,传“空值”,表示无标题 * @param headers 表头数组 */ - public ExportExcel(String title, String[] headers) { - initialize(title, Lists.newArrayList(headers)); + public ExportExcel(String title, String[] headers, String[] comments) { + initialize(title, Lists.newArrayList(headers), Lists.newArrayList(comments)); } /** * 构造函数 * @param title 表格标题,传“空值”,表示无标题 * @param headerList 表头列表 + * @param commentList 注释列表 */ - public ExportExcel(String title, List headerList) { - initialize(title, headerList); + public ExportExcel(String title, List headerList, List commentList) { + initialize(title, headerList,commentList); } + /** * 初始化函数 * @param title 表格标题,传“空值”,表示无标题 * @param headerList 表头列表 */ - private void initialize(String title, List headerList) { + private void initialize(String title, List headerList, List commentList) { this.wb = new SXSSFWorkbook(500); this.sheet = wb.createSheet("Export"); this.styles = createStyles(wb); @@ -482,12 +761,12 @@ public class ExportExcel { for (int i = 0; i < headerList.size(); i++) { Cell cell = headerRow.createCell(i); cell.setCellStyle(styles.get("header")); - String[] ss = StringUtils.split(headerList.get(i), "**", 2); - if (ss.length==2){ - cell.setCellValue(ss[0]); + String commentStr = commentList.get(i); + if (!StringUtil.isEmpty(commentStr)){ + cell.setCellValue(headerList.get(i)); Comment comment = this.sheet.createDrawingPatriarch().createCellComment( new XSSFClientAnchor(0, 0, 0, 0, (short) i, 0, (short) i+4, 3)); - comment.setString(new XSSFRichTextString(ss[1])); + comment.setString(new XSSFRichTextString(commentStr)); cell.setCellComment(comment); }else{ cell.setCellValue(headerList.get(i)); @@ -574,6 +853,15 @@ public class ExportExcel { public Row addRow(){ return sheet.createRow(rownum++); } + /** + * 添加一行 + * @return 行对象 + */ + public Row addRow(Sheet sheet,Integer rownum,String key){ + rownum++; + rownums.put(key, rownum); + return sheet.createRow(rownum); + } /** @@ -612,9 +900,8 @@ public class ExportExcel { } else if (val instanceof Float) { cell.setCellValue((Float) val); } else if (val instanceof Date) { - DataFormat format = wb.createDataFormat(); - style.setDataFormat(format.getFormat("yyyy-MM-dd HH:mm:ss")); - cell.setCellValue((Date) val); + SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + cell.setCellValue(sdf.format(val)); } else { if (fieldType != Class.class){ cell.setCellValue((String)fieldType.getMethod("setValue", Object.class).invoke(null, val)); @@ -681,6 +968,80 @@ public class ExportExcel { } return this; } + /** + * 添加数据(通过annotation.ExportField添加数据) + * @return list 数据列表 + */ + public ExportExcel setDataList(Properties msgProp, Map dataMap, Map map){ + Set keyList=dataMap.keySet(); + for (String key : keyList) { + List list=dataMap.get(key); + for (E e : list){ + int colunm = 0; + Row row = this.addRow(sheets.get(key),rownums.get(key),key); + StringBuilder sb = new StringBuilder(); + for (Object[] os : annotationMap.get(key)){ + ExcelField ef = (ExcelField)os[0]; + Object val = null; + // Get entity value + try{ + if (StringUtils.isNotBlank(ef.value())){ + val = Reflections.invokeGetter(e, ef.value()); + }else{ + if (os[1] instanceof Field){ + val = Reflections.invokeGetter(e, ((Field)os[1]).getName()); + }else if (os[1] instanceof Method){ + val = Reflections.invokeMethod(e, ((Method)os[1]).getName(), new Class[] {}, new Object[] {}); + } + } + // If is dict, get dict label + if (StringUtils.isNotBlank(ef.dictType())){ + String valStr=val==null?"":val.toString(); + if("type".equals(ef.dictType()) || "attribute".equals(ef.dictType()) + || "label".equals(ef.dictType())){ + // Get basic info + val = getBasicInfo(ef.dictType(),map,valStr); + }else{ + //字典数据已做国际化处理 + String dict=DictUtils.getDictLabel(ef.dictType(), valStr, ""); + //如果找不到字典国际化值,把字典本身作为默认值放进去,不然导出就是空了 + val = msgProp.getProperty(dict,dict); + } + + } + if(ef.title().equals("is_hex") && !StringUtil.isEmpty(val)){ + Integer isHex=Integer.parseInt(val.toString()); + if(isHex.equals(0) || isHex.equals(2)){ + val = msgProp.getProperty("not_hex","not_hex"); + }else if(isHex.equals(1)){ + val = msgProp.getProperty("hex","hex"); + }else{ + val =""; + } + } + if(ef.title().equals("is_case_insenstive") && !StringUtil.isEmpty(val)){ + Integer isCaseSenstive=Integer.parseInt(val.toString()); + if(isCaseSenstive.equals(0) || isCaseSenstive.equals(1)){ + val = msgProp.getProperty("case_insenstive","case_insenstive"); + }else if(isCaseSenstive.equals(1)){ + val = msgProp.getProperty("case_senstive","case_senstive"); + }else{ + val =""; + } + } + }catch(Exception ex) { + // Failure to ignore + log.error("Get entity value failed",ex); + val = ""; + } + this.addCell(row, colunm++, val, ef.align(), ef.fieldType()); + sb.append(val + ", "); + } + log.debug("Write success: ["+row.getRowNum()+"] "+sb.toString()); + } + } + return this; + } /** * 添加数据(通过annotation.ExportField添加数据) * @return list 数据列表 @@ -795,6 +1156,177 @@ public class ExportExcel { } return basicInfo; } + + + + + + /************************************************************/ + /** + * 构造函数 + * @param msgProp 国际化配置 + * @param title sheet名称 + * @param cls 实体对象,通过annotation.ExportField获取标题 + * @param type 导出类型(1:导出数据;2:导出模板) + * @param groups 导入分组 + * @return + */ + public ExportExcel(Properties msgProp,List titleList,Map noExportMap,Map> clsMap, int type, int... groups){ + Map> headerMap=new HashMap>(); + Map> commentMap=new HashMap>(); + for (String title : titleList) { + String noExportField=noExportMap.get(title); + List annotationList = Lists.newArrayList(); + List list=new ArrayList(); + // Get annotation field + //递归获取cls实体对象及父级对象的属性 + getFields(list, clsMap.get(title)); + if(!StringUtil.isEmpty(list)){ + for (Field f : list){ + ExcelField ef = f.getAnnotation(ExcelField.class); + if (ef != null && (ef.type()==0 || ef.type()==type)){ + if (groups!=null && groups.length>0){ + boolean inGroup = false; + for (int g : groups){ + if (inGroup){ + break; + } + for (int efg : ef.groups()){ + if (g == efg){ + inGroup = true; + if(!StringUtil.isEmpty(ef.title()) && !(noExportField.indexOf(","+ef.title()+",") > -1)){ + annotationList.add(new Object[]{ef, f}); + } + break; + } + } + } + }else{ + if(!StringUtil.isEmpty(ef.title()) && !(noExportField.indexOf(","+ef.title()+",") > -1)){ + annotationList.add(new Object[]{ef, f}); + } + } + } + } + } + List ms=new ArrayList(); + // Get annotation method + //递归获取cls实体对象及父级对象的属性 + getMethods(ms, clsMap.get(title)); + if(!StringUtil.isEmpty(ms)){ + for (Method m : ms){ + ExcelField ef = m.getAnnotation(ExcelField.class); + if (ef != null && (ef.type()==0 || ef.type()==type)){ + if (groups!=null && groups.length>0){ + boolean inGroup = false; + for (int g : groups){ + if (inGroup){ + break; + } + for (int efg : ef.groups()){ + if (g == efg){ + inGroup = true; + if(!StringUtil.isEmpty(ef.title()) && !(noExportField.indexOf(","+ef.title()+",") > -1)){ + annotationList.add(new Object[]{ef, m}); + } + break; + } + } + } + }else{ + if(!StringUtil.isEmpty(ef.title()) && !(noExportField.indexOf(","+ef.title()+",") > -1)){ + annotationList.add(new Object[]{ef, m}); + } + + } + } + } + } + // Field sorting + Collections.sort(annotationList, new Comparator() { + public int compare(Object[] o1, Object[] o2) { + return new Integer(((ExcelField)o1[0]).sort()).compareTo( + new Integer(((ExcelField)o2[0]).sort())); + }; + }); + // Initialize + List headerList = Lists.newArrayList(); + List commentList = Lists.newArrayList(); + for (Object[] os : annotationList){ + String titleStr = ((ExcelField)os[0]).title(); + String commentStr = ((ExcelField)os[0]).comment(); + + // 如果是导出,则去掉注释 + if (type==1){ + commentStr=""; + } + if(!StringUtil.isEmpty(titleStr)){ + //去掉不需要展示的header + if(!(noExportField.indexOf(","+titleStr+",") > -1)){ + titleStr=msgProp.getProperty(titleStr)==null?titleStr:msgProp.getProperty(titleStr); + headerList.add(titleStr); + commentList.add(commentStr); + } + } + } + headerMap.put(title, headerList); + commentMap.put(title, commentList); + annotationMap.put(title, annotationList); + } + initializeMultiSheet(msgProp,titleList, headerMap,commentMap); + } + + /** + * 初始化函数 + * @param title 表格标题,传“空值”,表示无标题 + * @param headerList 表头列表 + */ + private void initializeMultiSheet(Properties msgProp,List titleList,Map> headerMap,Map> commentMap) { + this.wb = new SXSSFWorkbook(500); + int j=0; + sheets=new HashMap<>(); + rownums=new HashMap<>(); + for (String title : titleList) { + List headerList=headerMap.get(title); + List commentList=commentMap.get(title); + Sheet sheet = wb.createSheet(StringUtil.isEmpty(msgProp.get(title)) ? title:msgProp.get(title).toString()); + rownums.put(title, 0); + sheets.put(title, sheet); + this.styles = createStyles(wb); + // Create header + if (headerList == null){ + throw new RuntimeException("headerList not null!"); + } + Integer rownum=rownums.get(title); + Row headerRow = sheet.createRow(rownum++); + headerRow.setHeightInPoints(16); + for (int i = 0; i < headerList.size(); i++) { + Cell cell = headerRow.createCell(i); + cell.setCellStyle(styles.get("header")); + String commentStr = commentList.get(i); + if (!StringUtil.isEmpty(commentStr)){ + cell.setCellValue(headerList.get(i)); + Comment comment = sheet.createDrawingPatriarch().createCellComment( + new XSSFClientAnchor(0, 0, 0, 0, (short) i, 0, (short) i+4, 3)); + comment.setString(new XSSFRichTextString(commentStr)); + cell.setCellComment(comment); + }else{ + cell.setCellValue(headerList.get(i)); + } + sheet.autoSizeColumn(i); + } + for (int i = 0; i < headerList.size(); i++) { + int colWidth = sheet.getColumnWidth(i)*2; + sheet.setColumnWidth(i, colWidth < 3000 ? 3000 : colWidth); + } + j++; + } + log.debug("Initialize success."); + } + + + + /** * 输出数据流 * @param os 输出数据流 diff --git a/src/main/java/com/nis/web/controller/BaseController.java b/src/main/java/com/nis/web/controller/BaseController.java index a837b196e..0be1e97c8 100644 --- a/src/main/java/com/nis/web/controller/BaseController.java +++ b/src/main/java/com/nis/web/controller/BaseController.java @@ -7,6 +7,7 @@ import java.util.ArrayList; import java.util.Calendar; import java.util.Date; import java.util.HashMap; +import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Properties; @@ -20,12 +21,14 @@ import org.apache.commons.lang3.StringEscapeUtils; import org.apache.commons.lang3.StringUtils; import org.apache.log4j.Logger; import org.jets3t.service.ServiceException; +import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.ui.Model; import org.springframework.web.bind.WebDataBinder; import org.springframework.web.bind.annotation.InitBinder; +import org.springframework.web.multipart.MultipartFile; import org.springframework.web.servlet.mvc.support.RedirectAttributes; import com.beust.jcommander.internal.Lists; @@ -39,9 +42,12 @@ import com.nis.domain.configuration.AreaBean; import com.nis.domain.configuration.AreaIpCfg; import com.nis.domain.configuration.BaseCfg; import com.nis.domain.configuration.BaseIpCfg; +import com.nis.domain.configuration.CfgIndexInfo; import com.nis.domain.configuration.ComplexStringCfgTemplate; +import com.nis.domain.configuration.IpPortCfg; import com.nis.domain.configuration.RequestInfo; import com.nis.domain.configuration.StringCfgTemplate; +import com.nis.domain.configuration.template.IpAllTemplate; import com.nis.domain.configuration.template.IpCfgTemplate; import com.nis.domain.log.BaseLogEntity; import com.nis.domain.log.SearchReport; @@ -54,6 +60,9 @@ import com.nis.util.DictUtils; import com.nis.util.JsonMapper; import com.nis.util.StringUtil; import com.nis.util.excel.ExportExcel; +import com.nis.util.excel.ImportExcel; +import com.nis.web.dao.configuration.IpCfgDao; +import com.nis.web.security.UserUtils; import com.nis.web.service.ArchiveServcie; import com.nis.web.service.AreaService; import com.nis.web.service.DictService; @@ -605,17 +614,17 @@ public class BaseController { if(dict.getRegionType()==1){ List list = Lists.newArrayList(); list.add(new IpCfgTemplate()); - new ExportExcel(msgProp,null, IpCfgTemplate.class, 2).setDataList(msgProp,list,null). + new ExportExcel(new FunctionRegionDict(),msgProp,null, IpCfgTemplate.class, 2).setDataList(msgProp,list,null). write(request,response, fileName).dispose(); }else if(dict.getRegionType()==2){ List list = Lists.newArrayList(); list.add(new StringCfgTemplate()); - new ExportExcel(msgProp,null, StringCfgTemplate.class, 2).setDataList(msgProp,list,null). + new ExportExcel(new FunctionRegionDict(),msgProp,null, StringCfgTemplate.class, 2).setDataList(msgProp,list,null). write(request,response, fileName).dispose(); }else if(dict.getRegionType()==3){ List list = Lists.newArrayList(); list.add(new ComplexStringCfgTemplate()); - new ExportExcel(msgProp,null, ComplexStringCfgTemplate.class, 2).setDataList(msgProp,list,null). + new ExportExcel(new FunctionRegionDict(),msgProp,null, ComplexStringCfgTemplate.class, 2).setDataList(msgProp,list,null). write(request,response, fileName).dispose(); } } @@ -637,17 +646,17 @@ public class BaseController { if(dict.getRegionType()==1){ List list = Lists.newArrayList(); list.add((IpCfgTemplate)clazz.newInstance()); - new ExportExcel(msgProp,null, clazz, 2).setDataList(msgProp,list,null). + new ExportExcel(new FunctionRegionDict(),msgProp,null, clazz, 2).setDataList(msgProp,list,null). write(request,response, fileName).dispose(); }else if(dict.getRegionType()==2){ List list = Lists.newArrayList(); list.add(new StringCfgTemplate()); - new ExportExcel(msgProp,null, clazz, 2).setDataList(msgProp,list,null). + new ExportExcel(new FunctionRegionDict(),msgProp,null, clazz, 2).setDataList(msgProp,list,null). write(request,response, fileName).dispose(); }else if(dict.getRegionType()==3){ List list = Lists.newArrayList(); list.add(new ComplexStringCfgTemplate()); - new ExportExcel(msgProp,null, clazz, 2).setDataList(msgProp,list,null). + new ExportExcel(new FunctionRegionDict(),msgProp,null, clazz, 2).setDataList(msgProp,list,null). write(request,response, fileName).dispose(); } } @@ -778,6 +787,572 @@ public class BaseController { params.put("searchCfgId", entry.getCfgId()); } } + + public List checkIpCfg(FunctionServiceDict serviceDict,FunctionRegionDict regionDict,List list) throws ServiceException{ + List ipList=new ArrayList(); + Properties prop=this.getMsgProp(); + for (int i = 0; i < list.size(); i++) { + IpAllTemplate ipCfg=list.get(i); + IpPortCfg baseIpCfg=new IpPortCfg(); + baseIpCfg.setCfgDesc(ipCfg.getCfgDesc()); + if(regionDict.getIsMaat().equals(1)){ + if(regionDict.getRegionType().equals(1)){ + boolean srcIpEmpty=false; + boolean srcPortEmpty=false; + if(StringUtil.isEmpty(ipCfg.getSrcIpAddress())){ + srcIpEmpty=true; + } + if(StringUtil.isEmpty(ipCfg.getDestIpAddress())){ + if(srcIpEmpty){ + baseIpCfg.setSrcIpAddress("0.0.0.0"); + baseIpCfg.setDestIpAddress("0.0.0.0"); + baseIpCfg.setIpPattern(3); + baseIpCfg.setIpType(4); + }else{ + if(ipCfg.getSrcIpAddress().indexOf(":") > -1){ + if(ipCfg.getSrcIpAddress().indexOf("-") > -1){ + baseIpCfg.setSrcIpAddress(ipCfg.getSrcIpAddress()); + baseIpCfg.setDestIpAddress("::-::"); + baseIpCfg.setIpPattern(2); + }else if(ipCfg.getSrcIpAddress().indexOf("/") > -1){ + baseIpCfg.setSrcIpAddress(ipCfg.getSrcIpAddress()); + baseIpCfg.setDestIpAddress("::/128"); + baseIpCfg.setIpPattern(1); + }else{ + baseIpCfg.setSrcIpAddress(ipCfg.getSrcIpAddress()); + baseIpCfg.setDestIpAddress("::"); + baseIpCfg.setIpPattern(3); + } + baseIpCfg.setIpType(6); + }else{ + if(ipCfg.getSrcIpAddress().indexOf("-") > -1){ + baseIpCfg.setSrcIpAddress("0.0.0.0-"+ipCfg.getSrcIpAddress().split("-")[0].substring(0,ipCfg.getSrcIpAddress().indexOf("-")+1)+ipCfg.getSrcIpAddress().split("-")[1]); + baseIpCfg.setDestIpAddress("0.0.0.0-0.0.0.0"); + baseIpCfg.setIpPattern(2); + }else if(ipCfg.getSrcIpAddress().indexOf("/") > -1){ + baseIpCfg.setSrcIpAddress(ipCfg.getSrcIpAddress()); + baseIpCfg.setDestIpAddress("0.0.0.0/16"); + baseIpCfg.setIpPattern(1); + }else{ + baseIpCfg.setSrcIpAddress(ipCfg.getSrcIpAddress()); + baseIpCfg.setDestIpAddress("0.0.0.0"); + baseIpCfg.setIpPattern(3); + } + baseIpCfg.setIpType(4); + } + } + } else{ + if(srcIpEmpty){ + if(ipCfg.getDestIpAddress().indexOf(":") > -1){ + if(ipCfg.getDestIpAddress().indexOf("-") > -1){ + baseIpCfg.setDestIpAddress(ipCfg.getDestIpAddress()); + baseIpCfg.setSrcIpAddress("::-::"); + baseIpCfg.setIpPattern(2); + }else if(ipCfg.getDestIpAddress().indexOf("/") > -1){ + baseIpCfg.setDestIpAddress(ipCfg.getDestIpAddress()); + baseIpCfg.setSrcIpAddress("::/128"); + baseIpCfg.setIpPattern(1); + }else{ + baseIpCfg.setDestIpAddress(ipCfg.getDestIpAddress()); + baseIpCfg.setSrcIpAddress("::"); + baseIpCfg.setIpPattern(3); + } + baseIpCfg.setIpType(6); + }else{ + if(ipCfg.getDestIpAddress().indexOf("-") > -1){ + baseIpCfg.setDestIpAddress("0.0.0.0-"+ipCfg.getDestIpAddress().split("-")[0].substring(0,ipCfg.getDestIpAddress().indexOf("-")+1)+ipCfg.getDestIpAddress().split("-")[1]); + baseIpCfg.setSrcIpAddress("0.0.0.0-0.0.0.0"); + baseIpCfg.setIpPattern(2); + }else if(ipCfg.getDestIpAddress().indexOf("/") > -1){ + baseIpCfg.setDestIpAddress(ipCfg.getDestIpAddress()); + baseIpCfg.setSrcIpAddress("0.0.0.0/16"); + baseIpCfg.setIpPattern(1); + }else{ + baseIpCfg.setDestIpAddress(ipCfg.getDestIpAddress()); + baseIpCfg.setSrcIpAddress("0.0.0.0"); + baseIpCfg.setIpPattern(3); + } + baseIpCfg.setIpType(4); + } + }else{ + baseIpCfg.setSrcIpAddress(ipCfg.getSrcIpAddress()); + baseIpCfg.setDestIpAddress(ipCfg.getDestIpAddress()); + if(ipCfg.getSrcIpAddress().indexOf(":") > -1){ + baseIpCfg.setIpType(6); + }else{ + baseIpCfg.setIpType(4); + } + if(ipCfg.getSrcIpAddress().indexOf("-") > -1){ + baseIpCfg.setIpPattern(2); + }else if(ipCfg.getSrcIpAddress().indexOf("/") > -1){ + baseIpCfg.setIpPattern(1); + }else{ + baseIpCfg.setIpPattern(3); + } + } + } + + //TODO 判断源IP和目的IP的值 + //TODO 判断源IP和目的IP格式 + + if(StringUtil.isEmpty(ipCfg.getSrcPort())){ + srcPortEmpty=true; + } + if(StringUtil.isEmpty(ipCfg.getDestPort())){ + if(srcPortEmpty){ + baseIpCfg.setSrcPort("0"); + baseIpCfg.setDestPort("0"); + baseIpCfg.setPortPattern(1); + }else{ + if(ipCfg.getSrcPort().indexOf("/") > -1){ + baseIpCfg.setDestPort("0/0"); + baseIpCfg.setPortPattern(2); + }else{ + baseIpCfg.setDestPort("0"); + baseIpCfg.setPortPattern(1); + } + baseIpCfg.setSrcPort(ipCfg.getSrcPort()); + } + }else{ + if(srcPortEmpty){ + if(ipCfg.getDestPort().indexOf("/") > -1){ + baseIpCfg.setSrcPort("0/0"); + baseIpCfg.setPortPattern(2); + }else{ + baseIpCfg.setSrcPort("0"); + baseIpCfg.setPortPattern(1); + } + baseIpCfg.setDestPort(ipCfg.getSrcPort()); + }else{ + if(ipCfg.getSrcPort().indexOf("/") > -1){ + baseIpCfg.setPortPattern(2); + }else{ + baseIpCfg.setPortPattern(1); + } + baseIpCfg.setSrcPort(ipCfg.getSrcPort()); + baseIpCfg.setDestPort(ipCfg.getDestPort()); + + } + } + //TODO 判断源端口和目的端口格式 + //TODO 判断源和目的端口的值 + + if(StringUtil.isEmpty(ipCfg.getProtocol())){ + if(StringUtil.isEmpty(regionDict.getConfigProtocol())){ + baseIpCfg.setProtocol(0); + }else{ + baseIpCfg.setProtocol(Integer.parseInt(regionDict.getConfigProtocol().split(",")[0])); + } + baseIpCfg.setProtocolId(serviceDict.getProtocolId()); + }else{ + baseIpCfg.setProtocol(ipCfg.getProtocol()); + baseIpCfg.setProtocolId(serviceDict.getProtocolId()); + } + //TODO 判断Protocol的值 + + if(StringUtil.isEmpty(ipCfg.getDirection())){ + if(StringUtil.isEmpty(regionDict.getConfigDirection())){ + baseIpCfg.setDirection(0); + }else{ + baseIpCfg.setDirection(Integer.parseInt(regionDict.getConfigDirection().split(",")[0])); + } + }else{ + baseIpCfg.setDirection(ipCfg.getDirection()); + } + + //TODO 判断Direction的值 + } + } + ipList.add(baseIpCfg); + } + return ipList; + + /*List ipTypeList = DictUtils.getDictList("IP_TYPE"); + List ipPatternList = DictUtils.getDictList("IP_PATTERN"); + List portPatternList = DictUtils.getDictList("PORT_PATTERN"); + List directionList = DictUtils.getDictList("DIRECTION"); + List protocolList = DictUtils.getDictList("PROTOCOL"); + List ipsecProrocolList = DictUtils.getDictList("IPSEC_PROTOCOL"); + List tunnelProrocolList = DictUtils.getDictList("TUNNEL_PROTOCOL"); + List specialFunctionIdList = DictUtils.getDictList("SPECIAL_FUNCTION_ID"); + List irTypeList = DictUtils.getDictList("IR_TYPE"); + String specialItem=null; + for(SysDataDictionaryItem sfuncItem:specialFunctionIdList){ + if(functionId==Integer.parseInt(sfuncItem.getItemCode())){ + specialItem=sfuncItem.getItemValue(); + } + } + if("ipaddr".equals(specialItem)){ + List icmpprotocolList = DictUtils.getDictList("ICMP_PROTOCOL"); + if(action==Constants.DROP_ACTION) { + protocolList.addAll(icmpprotocolList); + } + } + StringBuffer msg=new StringBuffer(); + int line=1; + for(IpCfgTemplate value:list){ + String lineStart=String.format(prop.getProperty("line"), line)+":"; + StringBuffer errInfo=new StringBuffer(); + // ip_type check start + Integer ipType=value.getIpType(); + if(ipType==null){ + errInfo.append(String.format(prop.getProperty("can_not_null"), prop.getProperty("ip_type"))+";"); + }else{ + boolean has=false; + for(SysDataDictionaryItem ipTypeItem:ipTypeList){ + if(ipType==Integer.parseInt(ipTypeItem.getItemCode())){ + has=true; + break; + } + } + if(!has){ + errInfo.append(String.format(prop.getProperty("is_incorrect"), prop.getProperty("ip_type"))+";"); + } + } + // ip_type check end + // ip_pattern check start + Integer ipPattern=value.getIpPattern(); + if(ipPattern==null){ + errInfo.append(String.format(prop.getProperty("can_not_null"), prop.getProperty("ip_pattern"))+";"); + }else{ + boolean has=false; + for(SysDataDictionaryItem ipPatternItem:ipPatternList){ + if(ipPattern==Integer.parseInt(ipPatternItem.getItemCode())){ + has=true; + break; + } + } + if(!has){ + errInfo.append(String.format(prop.getProperty("is_incorrect"), prop.getProperty("ip_pattern"))+";"); + } + } + // ip_pattern check end + //client_ip check start + String srcIp=value.getSrcIpAddress(); + String _msg=""; + if("ipmulitiplex".equals(specialItem)) { + _msg=checkIP(prop,prop.getProperty("IP"),srcIp,ipType,ipPattern); + }else { + _msg=checkIP(prop,prop.getProperty("client_ip"),srcIp,ipType,ipPattern); + } + if(StringUtils.isNotBlank(_msg)){ + errInfo.append(_msg); + } + //client_ip check end + //server_ip check start + String destIp=value.getDestIpAddress(); + if("ipmulitiplex".equals(specialItem)) {//set 默认值 + if(ipPattern!=null&&ipType!=null) { + if(1==ipPattern.intValue()) { + if(4==ipType.intValue()) { + value.setDestIpAddress(Constants.IPV4_DEFAULT_IP_SUBNET_VALUE); + }else if(6==ipType.intValue()) { + value.setDestIpAddress(Constants.IPV6_DEFAULT_IP_SUBNET_VALUE); + }else if(46==ipType.intValue()) { + value.setDestIpAddress(Constants.IPV6_DEFAULT_IP_SUBNET_VALUE); + }else if(64==ipType.intValue()) { + value.setDestIpAddress(Constants.IPV4_DEFAULT_IP_SUBNET_VALUE); + }else if(10==ipType.intValue()) { + value.setDestIpAddress(Constants.IPV4_DEFAULT_IP_SUBNET_VALUE); + } + }else if(2==ipPattern.intValue()) { + if(4==ipType.intValue()) { + value.setDestIpAddress(Constants.IPV4_DEFAULT_IP_RANGE_VALUE); + }else if(6==ipType.intValue()) { + value.setDestIpAddress(Constants.IPV6_DEFAULT_IP_RANGE_VALUE); + }else if(46==ipType.intValue()) { + value.setDestIpAddress(Constants.IPV6_DEFAULT_IP_RANGE_VALUE); + }else if(64==ipType.intValue()) { + value.setDestIpAddress(Constants.IPV4_DEFAULT_IP_RANGE_VALUE); + }else if(10==ipType.intValue()) { + value.setDestIpAddress(Constants.IPV4_DEFAULT_IP_RANGE_VALUE); + } + }else if(3==ipPattern.intValue()) { + if(4==ipType.intValue()) { + value.setDestIpAddress(Constants.IPV4_DEFAULT_IP_VALUE); + }else if(6==ipType.intValue()) { + value.setDestIpAddress(Constants.IPV6_DEFAULT_IP_VALUE); + }else if(46==ipType.intValue()) { + value.setDestIpAddress(Constants.IPV6_DEFAULT_IP_VALUE); + }else if(64==ipType.intValue()) { + value.setDestIpAddress(Constants.IPV4_DEFAULT_IP_VALUE); + }else if(10==ipType.intValue()) { + value.setDestIpAddress(Constants.IPV4_DEFAULT_IP_VALUE); + } + } + } + }else { + if(srcIp.equals(destIp)){ + String info=String.format(prop.getProperty("are_the_same"),prop.getProperty("client_ip"),prop.getProperty("server_ip")); + errInfo.append(info+";"); + } + _msg=checkIP(prop,prop.getProperty("server_ip"),destIp,ipType,ipPattern); + if(StringUtils.isNotBlank(_msg)){ + errInfo.append(_msg); + } + } + if(!"ipmulitiplex".equals(specialItem)&&(46==ipType.intValue()||64==ipType.intValue()||10==ipType.intValue())) { + _msg=checkIp(prop, prop.getProperty("client_ip"), srcIp, prop.getProperty("server_ip"), destIp, ipType, ipPattern); + if(StringUtils.isNotBlank(_msg)){ + errInfo.append(_msg); + } + } + //server_ip check end + //port_pattern check start + Integer portPattern=value.getPortPattern(); + if(portPattern==null){ + errInfo.append(String.format(prop.getProperty("can_not_null"), prop.getProperty("port_pattern"))+";"); + }else{ + boolean has=false; + for(SysDataDictionaryItem portPatternItem:portPatternList){ + if(portPattern==Integer.parseInt(portPatternItem.getItemCode())){ + has=true; + break; + } + } + if(!has){ + errInfo.append(String.format(prop.getProperty("is_incorrect"), prop.getProperty("port_pattern"))+";"); + } + } + //port_pattern check end + //src_port check start + String srcPort=value.getSrcPort(); + if("ipmulitiplex".equals(specialItem)) { + _msg=checkPort(prop,prop.getProperty("port"), srcPort, portPattern); + }else { + _msg=checkPort(prop,prop.getProperty("client_port"), srcPort, portPattern); + } + + if(StringUtils.isNotBlank(_msg)){ + errInfo.append(_msg); + } + //src_port check end + //dest_port check start + String destPort=value.getDestPort(); + if("ipmulitiplex".equals(specialItem)) {//set 默认值 + if(portPattern!=null) { + if(2==portPattern.intValue()) { + value.setDestPort(Constants.PORT_MASK_DEFAULT); + }else if(1==portPattern.intValue()) { + value.setDestPort(Constants.PORT_DEFAULT); + } + } + }else { + _msg=checkPort(prop,prop.getProperty("server_port"), destPort, portPattern); + } + if(StringUtils.isNotBlank(_msg)){ + errInfo.append(_msg); + } + //dest_port check end + //direction check start + Integer direction=value.getDirection(); + if(direction==null){ + errInfo.append(String.format(prop.getProperty("can_not_null"), prop.getProperty("direction"))+";"); + }else{ + boolean has=false; + for(SysDataDictionaryItem directionItem:directionList){ + if(Integer.parseInt(directionItem.getItemCode())==direction.intValue()){ + has=true; + break; + } + } + if(!has){ + errInfo.append(String.format(prop.getProperty("is_incorrect"), prop.getProperty("direction"))+";"); + } + } + //direction check end + //protocol check start + Integer protocol= value.getProtocol(); + if(protocol==null){ + errInfo.append(String.format(prop.getProperty("can_not_null"), prop.getProperty("protocol"))+";"); + }else{ + if(specialItem!=null&&("ipsec".equals(specialItem)||"tunnel".equals(specialItem))){ + if("ipsec".equals(specialItem)){ + if(action==Constants.DROP_ACTION.intValue()) { + boolean has=false; + for(SysDataDictionaryItem protocolItem:ipsecProrocolList){ + if(Integer.parseInt(protocolItem.getItemCode())==protocol.intValue()){ + has=true; + break; + } + } + if(!has){ + errInfo.append(String.format(prop.getProperty("is_incorrect"), prop.getProperty("protocol"))+";"); + } + }else { + if(protocol!=0) { + errInfo.append(String.format(prop.getProperty("is_incorrect"), prop.getProperty("protocol"))+";"); + } + } + }else if("tunnel".equals(specialItem)){ + for(SysDataDictionaryItem protocolItem:tunnelProrocolList){ + if("default".equals(protocolItem.getItemValue())){ + if(protocol.intValue()!=Integer.parseInt(protocolItem.getItemCode())){ + errInfo.append(String.format(prop.getProperty("must_be"), prop.getProperty("protocol"),Integer.parseInt(protocolItem.getItemCode()))+";"); + } + break; + } + } + + } + }else{ + boolean has=false; + for(SysDataDictionaryItem protocolItem:protocolList){ + if(Integer.parseInt(protocolItem.getItemCode())==protocol.intValue()){ + has=true; + break; + } + } + if(!has){ + errInfo.append(String.format(prop.getProperty("is_incorrect"), prop.getProperty("protocol"))+";"); + } + } + + } + //protocol check end + // requestId check start + Integer requestId=value.getRequestId(); + if(requestId==null){ + if("whitelistip".equals(specialItem)) { + value.setRequestId(0); + }else { + errInfo.append(String.format(prop.getProperty("can_not_null"), prop.getProperty("letter"))+";"); + } + + }else{//查询数据库是否存在ID + if("whitelistip".equals(specialItem)) { + value.setRequestId(0); + }else { + RequestInfo info=requestInfoService.getRequestInfoById((long)requestId.intValue()); + if(info==null){ + errInfo.append(String.format(prop.getProperty("id_not_exists"),requestId, prop.getProperty("letter"))+";"); + }else if(info.getIsValid()==Constants.VALID_NO||info.getIsValid()==Constants.VALID_DEL){ + errInfo.append(String.format(prop.getProperty("id_not_valid"),requestId, prop.getProperty("letter"))+";"); + } + } + } + // requestId check end + //classification check start + String classification=value.getClassify(); + if(StringUtils.isNotBlank(classification)){ + try{ + for(String classify:classification.split(",")){ + if(StringUtils.isNotBlank(classify)){ + int c=Integer.parseInt(classify); + ServiceDictInfo dict=serviceDictInfoService.getDictById(c); + if(dict==null){ + errInfo.append(String.format(prop.getProperty("id_not_exists"),classify, prop.getProperty("classification"))+";"); + }else if(dict.getIsValid()==Constants.VALID_NO||dict.getIsValid()==Constants.VALID_DEL){ + errInfo.append(String.format(prop.getProperty("id_not_valid"),classify, prop.getProperty("classification"))+";"); + } + } + } + }catch (Exception e) { + // TODO: handle exception + errInfo.append(String.format(prop.getProperty("num_split_by_comma"), prop.getProperty("classification"))+";"); + } + } + //classification check end + //attribute check start + String attributes=value.getAttribute(); + if(StringUtils.isNotBlank(attributes)){ + try{ + for(String attribute:attributes.split(",")){ + if(StringUtils.isNotBlank(attribute)){ + int c=Integer.parseInt(attribute); + ServiceDictInfo dict=serviceDictInfoService.getDictById(c); + if(dict==null){ + errInfo.append(String.format(prop.getProperty("id_not_exists"),attribute, prop.getProperty("attribute"))+";"); + }else if(dict.getIsValid()==Constants.VALID_NO||dict.getIsValid()==Constants.VALID_DEL){ + errInfo.append(String.format(prop.getProperty("id_not_valid"),attribute, prop.getProperty("attribute"))+";"); + } + } + } + }catch (Exception e) { + // TODO: handle exception + errInfo.append(String.format(prop.getProperty("num_split_by_comma"), prop.getProperty("attribute"))+";"); + } + } + //attribute check end + //attribute check start + String labels=value.getLable(); + if(StringUtils.isNotBlank(labels)){ + try{ + for(String label:labels.split(",")){ + if(StringUtils.isNotBlank(label)){ + int c=Integer.parseInt(label); + ServiceDictInfo dict=serviceDictInfoService.getDictById(c); + if(dict==null){ + errInfo.append(String.format(prop.getProperty("id_not_exists"),label, prop.getProperty("label"))+";"); + }else if(dict.getIsValid()==Constants.VALID_NO||dict.getIsValid()==Constants.VALID_DEL){ + errInfo.append(String.format(prop.getProperty("id_not_valid"),label, prop.getProperty("label"))+";"); + } + } + } + }catch (Exception e) { + // TODO: handle exception + errInfo.append(String.format(prop.getProperty("num_split_by_comma"), prop.getProperty("label"))+";"); + } + } + //group and ir_type check start + if("ipmulitiplex".equals(specialItem)) { + Integer irType= value.getIrType(); + if(irType==null) { + errInfo.append(String.format(prop.getProperty("can_not_null"), prop.getProperty("ir_type"))+";"); + }else { + boolean has=false; + for(SysDataDictionaryItem irTypeItem:irTypeList){ + if(Integer.parseInt(irTypeItem.getItemCode())==irType.intValue()){ + has=true; + break; + } + } + if(!has){ + errInfo.append(String.format(prop.getProperty("is_incorrect"), prop.getProperty("ir_type"))+";"); + } + } + Integer dnsStrategyId=value.getDnsStrategyId(); + if(dnsStrategyId==null) { + errInfo.append(String.format(prop.getProperty("can_not_null"), prop.getProperty("group_name"))+";"); + }else { + PolicyGroupInfo group=policyGroupInfoService.getById(dnsStrategyId.intValue()); + if(group==null) { + errInfo.append(String.format(prop.getProperty("id_not_exists"),dnsStrategyId, prop.getProperty("group_name"))+";"); + }else if(group.getIsValid()==Constants.VALID_DEL||group.getIsValid()==Constants.VALID_NO) { + errInfo.append(String.format(prop.getProperty("id_not_valid"),dnsStrategyId, prop.getProperty("group_name"))+";"); + } + } + } + if("ipratelimit".equals(specialItem)) { + String ratelimit=value.getRatelimit(); + if(ratelimit==null) { + errInfo.append(String.format(prop.getProperty("can_not_null"), prop.getProperty("ratelimit"))+";"); + }else { + try { + if(Double.parseDouble(ratelimit)<0||Double.parseDouble(ratelimit)>1) { + errInfo.append(String.format(prop.getProperty("is_incorrect"), prop.getProperty("ratelimit_limit"))+";"); + } + }catch (Exception e) { + errInfo.append(String.format(prop.getProperty("is_incorrect"), prop.getProperty("ratelimit_limit"))+";"); + } + + } + } + //attribute check end + if(StringUtils.isNotBlank(errInfo.toString())){ + msg.append(lineStart).append(errInfo); + if(line"); + } + } + //group and ir_type check end + line++; + } + if(StringUtils.isNotBlank(msg.toString())){ + throw new MaatConvertException(prop.getProperty("save_failed")+"
"+msg.toString()); + }*/ + } + public void checkIpCfg(int action,int functionId ,List list) throws ServiceException{ Properties prop=this.getMsgProp(); List ipTypeList = DictUtils.getDictList("IP_TYPE"); @@ -1562,4 +2137,97 @@ public class BaseController { } return null; } + + /** + * 多域导入 + * @param redirectAttributes + * @param files + * @param serviceDictId + * @param regionDictIds + * @param requestId + */ + public void _import(RedirectAttributes redirectAttributes,MultipartFile[] files + ,Integer serviceDictId + ,String regionDictIds + ,Integer requestId) { + try { + FunctionServiceDict serviceDict=DictUtils.getFunctionServiceDict(serviceDictId); + List ipPortCfgs=new ArrayList(); + List cfgIndexInfos=new ArrayList(); + for (int i = 0; i < files.length; i++) { + MultipartFile file = files[i]; + ImportExcel ei = new ImportExcel(file, 0, 0); + + FunctionRegionDict regionDict=DictUtils.getFunctionRegionDict(Integer.parseInt(regionDictIds.split(",")[i])); + + if(regionDict.getIsMaat().equals(1)){ + if(regionDict.getRegionType().equals(1)){ + List list = ei.getDataList(IpAllTemplate.class); + ipPortCfgs=this.checkIpCfg(serviceDict,regionDict,list); + Date date=new Date(); + for(BaseIpCfg cfg : ipPortCfgs){ + CfgIndexInfo cfgIndexInfo=new CfgIndexInfo(); + cfg.setAction(serviceDict.getAction()); + cfg.setAuditorId(UserUtils.getUser().getId()); + cfg.setAuditTime(date); + cfg.setCfgRegionCode(regionDict.getConfigRegionCode()); + cfg.setCfgType(regionDict.getConfigRegionValue()); + cfg.setCreateTime(date); + cfg.setCreatorId(UserUtils.getUser().getId()); + cfg.setDoLog(1); + cfg.setFunctionId(regionDict.getFunctionId()); + cfg.setIsAudit(0); + cfg.setIsValid(0); + cfg.setIsAreaEffective(0); + cfg.setAttribute("0"); + cfg.setClassify("0"); + cfg.setLable("0"); + cfg.setRequestId(StringUtil.isEmpty(requestId) ? 0:requestId); + cfg.setServiceId(serviceDict.getServiceId()); + cfg.setTableName("ip_port_cfg"); + cfg.setCompileId(ipCfgService.getCompileId()); + + BeanUtils.copyProperties(cfg, cfgIndexInfo); + cfgIndexInfos.add(cfgIndexInfo); + } + } + } + + ipCfgService.saveBatch(ipPortCfgs, IpCfgDao.class); + ipCfgService.saveCfgIndexOf(cfgIndexInfos); + } + } catch (Exception e) { + addMessage(redirectAttributes, e.getMessage()); + e.printStackTrace(); + } + } + /** + * 多域配置导出 + * @param columns + * @param model + * @param request + * @param response + * @param entity + * @param ids + * @param redirectAttributes + */ + public void _export(Model model,HttpServletRequest request,HttpServletResponse response, + RedirectAttributes redirectAttributes + ,String functionName + ,List titleList,Map> classMap,Map dataMap + ,Map noExportMap) throws Exception{ + //获取国际化配置 + Properties msgProp = getMsgProp(); + //获取分类、性质、标签 + List fls=serviceDictInfoService.findAllFlDict(); + List xzs=serviceDictInfoService.findAllXzDict(); + List labels=serviceDictInfoService.findAllLableDict(); + Map map=new HashMap(); + map.put("fls", fls); + map.put("xzs", xzs); + map.put("labels", labels); + + String fileName = msgProp.getProperty(functionName, functionName)+"_"+DateUtils.getDate("yyyyMMddHHmmss")+".xlsx"; + new ExportExcel(msgProp,titleList,noExportMap,classMap,1).setDataList(msgProp,dataMap,map).write(response, fileName).dispose(); + } } diff --git a/src/main/java/com/nis/web/controller/configuration/CommonController.java b/src/main/java/com/nis/web/controller/configuration/CommonController.java index f9c8e9976..02f414831 100644 --- a/src/main/java/com/nis/web/controller/configuration/CommonController.java +++ b/src/main/java/com/nis/web/controller/configuration/CommonController.java @@ -11,6 +11,7 @@ package com.nis.web.controller.configuration; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; +import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Properties; @@ -18,26 +19,38 @@ import java.util.Properties; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import org.apache.axis2.databinding.types.soapencoding.Array; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.BeanUtils; import org.springframework.ui.Model; import org.springframework.web.multipart.MultipartFile; import org.springframework.web.servlet.mvc.support.RedirectAttributes; +import com.nis.domain.FunctionRegionDict; +import com.nis.domain.FunctionServiceDict; import com.nis.domain.Page; import com.nis.domain.basics.ServiceDictInfo; import com.nis.domain.configuration.BaseIpCfg; +import com.nis.domain.configuration.CfgIndexInfo; +import com.nis.domain.configuration.HttpBodyCfg; +import com.nis.domain.configuration.HttpReqHeadCfg; +import com.nis.domain.configuration.HttpResHeadCfg; import com.nis.domain.configuration.HttpUrlCfg; +import com.nis.domain.configuration.template.IpAllTemplate; import com.nis.domain.configuration.template.IpCfgTemplate; +import com.nis.domain.specific.ConfigGroupInfo; import com.nis.domain.configuration.IpPortCfg; +import com.nis.domain.configuration.NtcSubscribeIdCfg; import com.nis.exceptions.MaatConvertException; import com.nis.util.Constants; import com.nis.util.DateUtils; +import com.nis.util.DictUtils; import com.nis.util.StringUtil; import com.nis.util.excel.ExportExcel; import com.nis.util.excel.ImportExcel; import com.nis.web.controller.BaseController; import com.nis.web.dao.configuration.IpCfgDao; +import com.nis.web.security.UserUtils; /** * @ClassName: CommonController.java @@ -213,8 +226,7 @@ public class CommonController extends BaseController { addMessage(redirectAttributes, "audit_failed"); } } - public void _importIp(String cfgName,RedirectAttributes redirectAttributes,MultipartFile file,IpPortCfg ipCfg) { - redirectAttributes.addAttribute("cfgName", cfgName); + public void _importIp(RedirectAttributes redirectAttributes,MultipartFile file,IpPortCfg ipCfg) { try { ImportExcel ei = new ImportExcel(file, 0, 0); List list = ei.getDataList(IpCfgTemplate.class); diff --git a/src/main/java/com/nis/web/controller/configuration/ntc/IpController.java b/src/main/java/com/nis/web/controller/configuration/ntc/IpController.java index af6f04cae..f7809f529 100644 --- a/src/main/java/com/nis/web/controller/configuration/ntc/IpController.java +++ b/src/main/java/com/nis/web/controller/configuration/ntc/IpController.java @@ -2,7 +2,9 @@ package com.nis.web.controller.configuration.ntc; import java.util.ArrayList; import java.util.Date; +import java.util.HashMap; import java.util.List; +import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -18,18 +20,27 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.multipart.MultipartFile; import org.springframework.web.servlet.mvc.support.RedirectAttributes; +import com.nis.domain.FunctionRegionDict; +import com.nis.domain.FunctionServiceDict; import com.nis.domain.Page; import com.nis.domain.SysDataDictionaryItem; 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.NtcSubscribeIdCfg; import com.nis.domain.configuration.template.IpAddrTemplate; +import com.nis.domain.configuration.template.IpAllTemplate; import com.nis.domain.configuration.template.IpsecTemplate; import com.nis.domain.configuration.template.TunnelIpTemplate; 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.ExcelField; +import com.nis.util.excel.ExportExcel; +import com.nis.web.controller.BaseController; import com.nis.web.controller.configuration.CommonController; import com.nis.web.security.UserUtils; @@ -40,7 +51,7 @@ import com.nis.web.security.UserUtils; */ @Controller @RequestMapping("${adminPath}/ntc/iplist") -public class IpController extends CommonController{ +public class IpController extends BaseController{ @RequestMapping(value = {"list"}) // @RequiresPermissions(value={"iplist:config","iplist:confirm"},logical=Logical.OR) public String list(Model model,@ModelAttribute("cfg")CfgIndexInfo cfg,HttpServletRequest request,HttpServletResponse response) { @@ -140,7 +151,7 @@ public class IpController extends CommonController{ } return "redirect:" + adminPath +"/ntc/iplist/list?functionId="+functionId; } - //ip配置导入 + /*//ip配置导入 @RequestMapping(value = "import", method=RequestMethod.POST) public String importIp(String cfgName,RedirectAttributes redirectAttributes, @RequestParam("file") MultipartFile file,IpPortCfg cfg) { @@ -198,5 +209,137 @@ public class IpController extends CommonController{ public void exportIp(String columns,Model model,HttpServletRequest request,HttpServletResponse response, @ModelAttribute("cfg")IpPortCfg entity,String ids,RedirectAttributes redirectAttributes){ this._exportIp(columns,model, request, response, entity, ids, redirectAttributes); + }*/ + + //模板下载 + @RequestMapping(value = "import/template") + public void importFileTemplate(HttpServletRequest request,HttpServletResponse response, + RedirectAttributes redirectAttributes + ,Integer serviceDictId + ,Integer regionDictId + ,Integer requestId + ) { + try { + FunctionRegionDict regionDict=DictUtils.getFunctionRegionDict(regionDictId); + FunctionServiceDict serviceDict=DictUtils.getFunctionServiceDict(serviceDictId); + exportTemplate(request,response,redirectAttributes,regionDict,serviceDict,requestId); + } catch (Exception e) { + logger.error("export_failed", e); + } + + } + public void exportTemplate(HttpServletRequest request,HttpServletResponse response, + RedirectAttributes redirectAttributes + ,FunctionRegionDict regionDict + ,FunctionServiceDict serviceDict + ,Integer requestId) throws Exception{ + String fileName = "test.xlsx"; + //maat导入模板 + if(regionDict.getIsMaat().equals(1)){ + //ip类模板 + if(regionDict.getRegionType().equals(1)){ + List classList=new ArrayList(); + ExportExcel excel=new ExportExcel(regionDict,this.getMsgProp(),null, IpAllTemplate.class, 2); + excel.setDataList(this.getMsgProp(),classList,null). + write(request,response, fileName).dispose(); + } + //str类模板 + if(regionDict.getRegionType().equals(2)){ + /*List classList=new ArrayList(); + ExportExcel excel=new ExportExcel(this.getMsgProp(),null, IpAllTemplate.class, 2,regionDict); + excel.setDataList(this.getMsgProp(),classList,null). + write(request,response, fileName).dispose();*/ + } + //district类模板 + if(regionDict.getRegionType().equals(2)){ + /*ExportExcel excel=new ExportExcel(this.getMsgProp(),null, IpAllTemplate.class, 2,regionDict); + excel.setDataList(this.getMsgProp(),classList,null). + write(request,response, fileName).dispose();*/ + } + }else{ + //非maat导入模板 + } + } + + //ip配置导入 + @RequestMapping(value = "import", method=RequestMethod.POST) + public String importIp(RedirectAttributes redirectAttributes, + @RequestParam("files") MultipartFile[] files + ,Integer serviceDictId + ,Integer requestId + ,String regionDictIds) { + this._import(redirectAttributes, files,serviceDictId,regionDictIds,requestId); + + return "redirect:" + adminPath +"/ntc/iplist/list?functionId="+5; + } + + //ip配置导出 + @RequestMapping(value = "exportIpAddr") + public void exportIp(Model model,HttpServletRequest request,HttpServletResponse response, + @ModelAttribute("cfg")CfgIndexInfo entity,String ids,RedirectAttributes redirectAttributes){ + try { + //export data info + List titleList=new ArrayList(); + Map> classMap=new HashMap>(); + Map dataMap=new HashMap(); + Map noExportMap=new HashMap(); + + + /*//导出选中记录 + * if(!StringUtil.isEmpty(ids)){ + for(String id:ids.split(",")){ + Long.parseLong(id); + } + //List list=ipCfgService.getListByCfgIdWithName(IpPortCfg.getTablename(), entity.getFunctionId(), ids); + }else{*/ + //条件导出数据大于最大导出数,只导出最大导出条数 + entity.setTableName(IpPortCfg.getTablename()); + Page pageInfo=new Page(request, response,"a"); + if(pageInfo.getCount()>Constants.MAX_EXPORT_SIZE){ + pageInfo.setPageNo(1); + pageInfo.setPageSize(Constants.MAX_EXPORT_SIZE); + }else{ + pageInfo.setPageNo(1); + pageInfo.setPageSize(-1); + } + Page page = ipCfgService.getIpCfgList(pageInfo, entity); + titleList.add(entity.getMenuNameCode()); + titleList.add("ip_addr"); + titleList.add("asn_policy"); + classMap.put(entity.getMenuNameCode(), CfgIndexInfo.class); + classMap.put("ip_port_cfg", IpPortCfg.class); + classMap.put("asn_policy", ConfigGroupInfo.class); + String cfgIndexInfoNoExport=",group_name,userregion1,userregion2,userregion3,userregion4,userregion5,"; + String ipPortInfoNoExport=",do_log,action,config_describe,valid_identifier,is_audit,creator,creator" + + ",config_time,editor,edit_time,auditor,audit_time" + +",letter,whether_area_block,classification,attribute,label" + +",userregion1,userregion2,userregion3,userregion4,userregion5,ir_type,group_name,"; + String asnGroupInfoNoExport=""; + noExportMap.put(entity.getMenuNameCode(),cfgIndexInfoNoExport); + noExportMap.put("ip_addr", ipPortInfoNoExport); + noExportMap.put("asn_policy", asnGroupInfoNoExport); + List ipList=new ArrayList(); + List groupInfoList=new ArrayList(); + for (CfgIndexInfo cfg : page.getList()) { + CfgIndexInfo cfgIndexInfo=ipCfgService.exportIpInfo(cfg); + ipList.addAll(cfgIndexInfo.getIpPortList()); + if(!StringUtil.isEmpty(cfgIndexInfo.getAsnIpGroupName())){ + ConfigGroupInfo group=new ConfigGroupInfo(); + group.setCompileId(cfgIndexInfo.getCompileId()); + group.setGroupName(cfgIndexInfo.getAsnIpGroupName()); + groupInfoList.add(group); + } + } + dataMap.put(entity.getMenuNameCode(), page.getList()); + dataMap.put("ip_addr", ipList); + dataMap.put("asn_policy", groupInfoList); + + /*}*/ + this._export(model, request, response, redirectAttributes,entity.getMenuNameCode(),titleList,classMap,dataMap,noExportMap); + } catch (Exception e) { + logger.error("ip addr export failed",e); + addMessage(redirectAttributes, "export_failed"); + } + //return "redirect:" + adminPath +"/ntc/iplist/list?functionId="+entity.getFunctionId(); } } diff --git a/src/main/java/com/nis/web/controller/configuration/ntc/WebsiteController.java b/src/main/java/com/nis/web/controller/configuration/ntc/WebsiteController.java index 50ab696a6..7640ba214 100644 --- a/src/main/java/com/nis/web/controller/configuration/ntc/WebsiteController.java +++ b/src/main/java/com/nis/web/controller/configuration/ntc/WebsiteController.java @@ -2,7 +2,9 @@ package com.nis.web.controller.configuration.ntc; import java.util.ArrayList; import java.util.Date; +import java.util.HashMap; import java.util.List; +import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -19,6 +21,7 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.multipart.MultipartFile; import org.springframework.web.servlet.mvc.support.RedirectAttributes; +import com.nis.domain.FunctionRegionDict; import com.nis.domain.Page; import com.nis.domain.configuration.BaseStringCfg; import com.nis.domain.configuration.CfgIndexInfo; @@ -26,6 +29,7 @@ import com.nis.domain.configuration.ComplexkeywordCfg; import com.nis.domain.configuration.DnsResStrategy; import com.nis.domain.configuration.ComplexStringCfgTemplate; import com.nis.domain.configuration.template.IpCfgTemplate; +import com.nis.domain.specific.ConfigGroupInfo; import com.nis.domain.configuration.StringCfgTemplate; import com.nis.domain.configuration.HttpBodyCfg; import com.nis.domain.configuration.HttpReqHeadCfg; @@ -35,6 +39,8 @@ import com.nis.domain.configuration.IpPortCfg; import com.nis.domain.configuration.NtcSubscribeIdCfg; 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.ImportExcel; import com.nis.web.controller.BaseController; import com.nis.web.security.UserUtils; @@ -511,4 +517,128 @@ public class WebsiteController extends BaseController{ return "redirect:" + adminPath +"/ntc/website/httpList?functionId="+cfgIndex.getFunctionId(); } + + + + //ip配置导出 + @RequestMapping(value = "exportHttp") + public String exportIp(Model model,HttpServletRequest request,HttpServletResponse response, + @ModelAttribute("cfg")CfgIndexInfo entity,String ids,RedirectAttributes redirectAttributes){ + try { + //export data info + List titleList=new ArrayList(); + Map> classMap=new HashMap>(); + Map dataMap=new HashMap(); + Map noExportMap=new HashMap(); + + List regionList = DictUtils.getFunctionRegionDictList(entity.getFunctionId()); + + /*//导出选中记录 + if(!StringUtil.isEmpty(ids)){ + for(String id:ids.split(",")){ + Long.parseLong(id); + } + //List list=ipCfgService.getListByCfgIdWithName(IpPortCfg.getTablename(), entity.getFunctionId(), ids); + }else{*/ + //条件导出数据大于最大导出数,只导出最大导出条数 + Page pageInfo=new Page(request, response,"a"); + if(pageInfo.getCount()>Constants.MAX_EXPORT_SIZE){ + pageInfo.setPageNo(1); + pageInfo.setPageSize(Constants.MAX_EXPORT_SIZE); + }else{ + pageInfo.setPageNo(1); + pageInfo.setPageSize(-1); + } + Page page = websiteCfgService.getWebsiteList(pageInfo, entity); + + titleList.add(entity.getMenuNameCode()); + titleList.add("NTC_HTTP_URL"); + titleList.add("NTC_HTTP_REQ_HDR"); + titleList.add("NTC_HTTP_RES_HDR"); + titleList.add("NTC_HTTP_REQ_BODY"); + titleList.add("NTC_HTTP_RES_BODY"); + titleList.add("NTC_UNIVERSAL_IP"); + titleList.add("NTC_SUBSCRIBE_ID"); + classMap.put(entity.getMenuNameCode(), CfgIndexInfo.class); + classMap.put("NTC_HTTP_URL", HttpUrlCfg.class); + classMap.put("NTC_HTTP_REQ_HDR", HttpReqHeadCfg.class); + classMap.put("NTC_HTTP_RES_HDR", HttpResHeadCfg.class); + classMap.put("NTC_HTTP_REQ_BODY", HttpBodyCfg.class); + classMap.put("NTC_HTTP_RES_BODY", HttpBodyCfg.class); + classMap.put("NTC_UNIVERSAL_IP", IpPortCfg.class); + classMap.put("NTC_SUBSCRIBE_ID", NtcSubscribeIdCfg.class); + String cfgIndexInfoNoExport=",group_name,userregion1,userregion2,userregion3,userregion4,userregion5,"; + String httpUrlCfgNoExport=",do_log,action,config_describe,valid_identifier,is_audit,creator,creator" + + ",config_time,editor,edit_time,auditor,audit_time" + +",letter,whether_area_block,classification,attribute,label" + +",userregion1,userregion2,userregion3,userregion4,userregion5,"; + String httpReqHeadCfgNoExport=",do_log,action,config_describe,valid_identifier,is_audit,creator,creator" + + ",config_time,editor,edit_time,auditor,audit_time" + +",letter,whether_area_block,classification,attribute,label" + +",userregion1,userregion2,userregion3,userregion4,userregion5,"; + String httpResHeadCfgNoExport=",do_log,action,config_describe,valid_identifier,is_audit,creator,creator" + + ",config_time,editor,edit_time,auditor,audit_time" + +",letter,whether_area_block,classification,attribute,label" + +",userregion1,userregion2,userregion3,userregion4,userregion5,"; + String httpReqBodyCfgNoExport=",do_log,action,config_describe,valid_identifier,is_audit,creator,creator" + + ",config_time,editor,edit_time,auditor,audit_time" + +",letter,whether_area_block,classification,attribute,label" + +",userregion1,userregion2,userregion3,userregion4,userregion5,"; + String httpResBodyCfgNoExport=",do_log,action,config_describe,valid_identifier,is_audit,creator,creator" + + ",config_time,editor,edit_time,auditor,audit_time" + +",letter,whether_area_block,classification,attribute,label" + +",userregion1,userregion2,userregion3,userregion4,userregion5,"; + String ipPortCfgNoExport=",do_log,action,config_describe,valid_identifier,is_audit,creator,creator" + + ",config_time,editor,edit_time,auditor,audit_time" + +",letter,whether_area_block,classification,attribute,label" + +",userregion1,userregion2,userregion3,userregion4,userregion5,ir_type,group_name,"; + String ntcSubscribeIdCfgNoExport=",do_log,action,config_describe,valid_identifier,is_audit,creator,creator" + + ",config_time,editor,edit_time,auditor,audit_time" + +",letter,whether_area_block,classification,attribute,label" + +",userregion1,userregion2,userregion3,userregion4,userregion5,"; + noExportMap.put(entity.getMenuNameCode(),cfgIndexInfoNoExport); + noExportMap.put("NTC_HTTP_URL", httpUrlCfgNoExport); + noExportMap.put("NTC_HTTP_REQ_HDR", httpReqHeadCfgNoExport); + noExportMap.put("NTC_HTTP_RES_HDR", httpResHeadCfgNoExport); + noExportMap.put("NTC_HTTP_REQ_BODY", httpReqBodyCfgNoExport); + noExportMap.put("NTC_HTTP_RES_BODY", httpResBodyCfgNoExport); + noExportMap.put("NTC_UNIVERSAL_IP", ipPortCfgNoExport); + noExportMap.put("NTC_SUBSCRIBE_ID", ntcSubscribeIdCfgNoExport); + + List httpUrlList = new ArrayList<>(); + List httpReqHdrList = new ArrayList<>(); + List httpResHdrList = new ArrayList<>(); + List httpReqBodyList = new ArrayList<>(); + List httpResBodyList = new ArrayList<>(); + List ipPortList = new ArrayList<>(); + List subscribeIdList = new ArrayList<>(); + for (CfgIndexInfo cfg : page.getList()) { + Map maps=websiteCfgService.exportHttpCfg(cfg); + httpUrlList.addAll(maps.get("NTC_HTTP_URL")); + httpReqHdrList.addAll(maps.get("NTC_HTTP_REQ_HDR")); + httpResHdrList.addAll(maps.get("NTC_HTTP_RES_HDR")); + httpReqBodyList.addAll(maps.get("NTC_HTTP_REQ_BODY")); + httpResBodyList.addAll(maps.get("NTC_HTTP_RES_BODY")); + ipPortList.addAll(maps.get("NTC_UNIVERSAL_IP")); + subscribeIdList.addAll(maps.get("NTC_SUBSCRIBE_ID")); + } + + dataMap.put(entity.getMenuNameCode(), page.getList()); + dataMap.put("NTC_HTTP_URL", httpUrlList); + dataMap.put("NTC_HTTP_REQ_HDR", httpReqHdrList); + dataMap.put("NTC_HTTP_RES_HDR", httpResHdrList); + dataMap.put("NTC_HTTP_REQ_BODY", httpReqBodyList); + dataMap.put("NTC_HTTP_RES_BODY", httpResBodyList); + dataMap.put("NTC_UNIVERSAL_IP", ipPortList); + dataMap.put("NTC_SUBSCRIBE_ID",subscribeIdList); + + /*}*/ + this._export(model, request, response, redirectAttributes,entity.getMenuNameCode(),titleList,classMap,dataMap,noExportMap); + } catch (Exception e) { + logger.error("http export failed",e); + addMessage(redirectAttributes, "export_failed"); + } + return "redirect:" + adminPath +"/ntc/website/httpList?functionId="+entity.getFunctionId(); + } + } diff --git a/src/main/java/com/nis/web/controller/configuration/proxy/ControlController.java b/src/main/java/com/nis/web/controller/configuration/proxy/ControlController.java index 251a8719d..87e46265b 100644 --- a/src/main/java/com/nis/web/controller/configuration/proxy/ControlController.java +++ b/src/main/java/com/nis/web/controller/configuration/proxy/ControlController.java @@ -115,7 +115,7 @@ public class ControlController extends CommonController { @RequestMapping(value = "/ip/import", method=RequestMethod.POST) public String importIp(String cfgName,RedirectAttributes redirectAttributes, @RequestParam("file") MultipartFile file,IpPortCfg cfg) { - this._importIp(cfgName,redirectAttributes, file,cfg); + //this._importIp(cfgName,redirectAttributes, file,cfg); redirectAttributes.addAttribute("urlPrefix","/proxy/control/ip"); redirectAttributes.addAttribute("requiresPermissionPrefix","control:ip"); return "redirect:" + adminPath +"/proxy/control/ip/list?functionId="+cfg.getFunctionId(); diff --git a/src/main/java/com/nis/web/service/configuration/IpCfgService.java b/src/main/java/com/nis/web/service/configuration/IpCfgService.java index 570f13d22..3b222efc0 100644 --- a/src/main/java/com/nis/web/service/configuration/IpCfgService.java +++ b/src/main/java/com/nis/web/service/configuration/IpCfgService.java @@ -895,6 +895,15 @@ public class IpCfgService extends CrudService { } return entity; } + public CfgIndexInfo exportIpInfo(CfgIndexInfo entity){ + List ipPortList = ipCfgDao.getIpPortList(entity); + entity.setIpPortList(ipPortList); + if(StringUtils.isNotBlank(entity.getUserRegion4())) { + ConfigGroupInfo info=specificServiceCfgDao.getConfigGroupInfoByGroupId(Integer.parseInt(entity.getUserRegion4().trim())); + entity.setAsnIpGroupName(info.getGroupName()); + } + return entity; + } public BaseIpCfg getIpCfgById(String tableName,long id){ return ipCfgDao.getById(tableName, id); } diff --git a/src/main/java/com/nis/web/service/configuration/WebsiteCfgService.java b/src/main/java/com/nis/web/service/configuration/WebsiteCfgService.java index 257482063..4e58c35bb 100644 --- a/src/main/java/com/nis/web/service/configuration/WebsiteCfgService.java +++ b/src/main/java/com/nis/web/service/configuration/WebsiteCfgService.java @@ -2,6 +2,7 @@ package com.nis.web.service.configuration; import java.util.ArrayList; import java.util.Date; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -10,6 +11,7 @@ import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import com.nis.domain.FunctionRegionDict; import com.nis.domain.Page; import com.nis.domain.configuration.AreaIpCfg; import com.nis.domain.configuration.BaseStringCfg; @@ -76,6 +78,27 @@ public class WebsiteCfgService extends CrudService { entity.setNtcSubscribeIdCfgList(subscribeIdList); return entity; } + public Map exportHttpCfg(CfgIndexInfo entity){ + Map dataMap=new HashMap(); + List ipPortList = websiteCfgDao.getIpPortList(entity); + List httpUrlList = websiteCfgDao.getHttpUrlList(entity); + List httpReqHdrList = websiteCfgDao.getHttpReqHdrList(entity); + List httpResHdrList = websiteCfgDao.getHttpResHdrList(entity); + List subscribeIdList = stringCfgDao.findSubscribeIdCfgListByCfgIndexInfo(entity); + entity.setCfgType(Constants.HTTP_REQ_BODY_REGION); + List httpReqBodyList = websiteCfgDao.getHttpReqBodyList(entity); + entity.setCfgType(Constants.HTTP_RES_BODY_REGION); + List httpResBodyList = websiteCfgDao.getHttpResBodyList(entity); + dataMap.put("NTC_UNIVERSAL_IP", ipPortList); + dataMap.put("NTC_HTTP_URL", httpUrlList); + dataMap.put("NTC_HTTP_REQ_HDR", httpReqHdrList); + dataMap.put("NTC_HTTP_RES_HDR", httpResHdrList); + dataMap.put("NTC_HTTP_REQ_BODY", httpReqBodyList); + dataMap.put("NTC_HTTP_RES_BODY", httpResBodyList); + dataMap.put("NTC_SUBSCRIBE_ID", subscribeIdList); + + return dataMap; + } public CfgIndexInfo getSslCfg(Long cfgId){ CfgIndexInfo entity = websiteCfgDao.getCfgIndexInfo(cfgId); List ipPortList = websiteCfgDao.getIpPortList(entity); diff --git a/src/main/resources/nis.properties b/src/main/resources/nis.properties index 2c0f235ef..e53b79b14 100644 --- a/src/main/resources/nis.properties +++ b/src/main/resources/nis.properties @@ -417,7 +417,7 @@ voip_file_type=,mp3,mp4,flv,ivf,mp2v,jpg, voip_single_file_max_size=10485760 #digest File Types -digest_file_type=,txt,doc,img,docx,pptx,xlsx,xls,ppt, +digest_file_type=,txt,doc,img,docx,pptx,xlsx,xls,ppt,mp4,flv,asf,wmv,avi,mpeg,mov,dat,m4v,m4p,m4b,webm,ogv,wav,mp3, #digest File Size 10M 10485760\uff08single\uff09 digest_single_file_max_size=10485760 #digest File Size 12M 12582912\uff08total\uff09 diff --git a/src/main/resources/sql/truncate_tables.sql b/src/main/resources/sql/truncate_tables.sql index 83ea0fd6b..a43e2f046 100644 --- a/src/main/resources/sql/truncate_tables.sql +++ b/src/main/resources/sql/truncate_tables.sql @@ -28,7 +28,7 @@ DELETE FROM av_sign_sample_cfg; INSERT INTO `av_sign_sample_cfg` VALUES ('10022', '1', '1', '0', '0', '16', '1', null, '0', '2018-09-06 15:56:53', null, null, '158', '2018-09-13 16:43:54', '266', '0', '0', '0', '0', '0', '0', '0', '33', '0', '0'); DELETE FROM complex_keyword_cfg; #慎重清理config_group_info! 特定服务新增的时候会预制组号,清理之后组号找不到会影响下发 -#DELETE FROM config_group_info; +DELETE FROM config_group_info; DELETE FROM ddos_ip_cfg; DELETE FROM dns_domain_cfg; DELETE FROM dns_ip_cfg; diff --git a/src/main/webapp/WEB-INF/include/excel/importModal.jsp b/src/main/webapp/WEB-INF/include/excel/importModal.jsp new file mode 100644 index 000000000..4126f012a --- /dev/null +++ b/src/main/webapp/WEB-INF/include/excel/importModal.jsp @@ -0,0 +1,162 @@ +<%@ page contentType="text/html;charset=UTF-8"%> +<%@ include file="/WEB-INF/include/taglib.jsp"%> + + \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/include/header.jsp b/src/main/webapp/WEB-INF/include/header.jsp index 8c8e920a6..cb439566f 100644 --- a/src/main/webapp/WEB-INF/include/header.jsp +++ b/src/main/webapp/WEB-INF/include/header.jsp @@ -92,6 +92,8 @@ + + diff --git a/src/main/webapp/WEB-INF/tags/sys/delRow.tag b/src/main/webapp/WEB-INF/tags/sys/delRow.tag index 3d3e0f246..8b1d10746 100644 --- a/src/main/webapp/WEB-INF/tags/sys/delRow.tag +++ b/src/main/webapp/WEB-INF/tags/sys/delRow.tag @@ -2,6 +2,7 @@ <%@ include file="/WEB-INF/include/taglib.jsp"%> <%@ attribute name="id" type="java.lang.String" required="true"%> <%@ attribute name="url" type="java.lang.String" required="true"%> +<%@ attribute name="searchUrl" type="java.lang.String" required="false"%> <%@ attribute name="label" type="java.lang.String" required="false"%> <%@ attribute name="maxRow" type="java.lang.Long" required="false"%> @@ -25,7 +26,7 @@ - + @@ -250,12 +251,12 @@ var checkboxes=$("#${id} ${value} tbody tr td input.i-checks:checkbox"); }); return flag; } - //删除 - function exportData(url,maxRow){ + //导出 + function exportData(url,maxRow,searchUrl){ var column=[]; $("#${id} ${value} thead tr th").each(function(){ - if($(this).attr("exportColumn")){ - column.push($(this).attr("exportColumn")); + if($(this).is(":visible")){ + column.push($(this).text().trim()); } }); if(column){ @@ -280,6 +281,7 @@ var checkboxes=$("#${id} ${value} tbody tr td input.i-checks:checkbox"); $("#searchForm").attr("action",url); $("#searchForm").submit(); closeTip(); + $("#searchForm").attr("action",searchUrl); } } } diff --git a/src/main/webapp/WEB-INF/views/cfg/av/voip/voipList.jsp b/src/main/webapp/WEB-INF/views/cfg/av/voip/voipList.jsp index 6ac6ddc31..98bc98001 100644 --- a/src/main/webapp/WEB-INF/views/cfg/av/voip/voipList.jsp +++ b/src/main/webapp/WEB-INF/views/cfg/av/voip/voipList.jsp @@ -154,11 +154,10 @@ - - - + <%-- + --> --%> - + <%----%> diff --git a/src/main/webapp/WEB-INF/views/cfg/ipaddr/ipList.jsp b/src/main/webapp/WEB-INF/views/cfg/ipaddr/ipList.jsp index 971111110..5e187de4a 100644 --- a/src/main/webapp/WEB-INF/views/cfg/ipaddr/ipList.jsp +++ b/src/main/webapp/WEB-INF/views/cfg/ipaddr/ipList.jsp @@ -143,7 +143,10 @@ - + + + + @@ -163,6 +166,7 @@ + <%-- --%>
diff --git a/src/main/webapp/WEB-INF/views/cfg/website/httpList.jsp b/src/main/webapp/WEB-INF/views/cfg/website/httpList.jsp index 740f9da39..2b379aead 100644 --- a/src/main/webapp/WEB-INF/views/cfg/website/httpList.jsp +++ b/src/main/webapp/WEB-INF/views/cfg/website/httpList.jsp @@ -326,6 +326,7 @@ + <%-- --%>
@@ -336,7 +337,7 @@
diff --git a/src/main/webapp/WEB-INF/views/log/ntc/ipList.jsp b/src/main/webapp/WEB-INF/views/log/ntc/ipList.jsp index 8a57e0b50..7585ef249 100644 --- a/src/main/webapp/WEB-INF/views/log/ntc/ipList.jsp +++ b/src/main/webapp/WEB-INF/views/log/ntc/ipList.jsp @@ -52,11 +52,11 @@ - <%-- --%> - - + + + - <%-- --%> +
diff --git a/src/main/webapp/WEB-INF/views/report/list.jsp b/src/main/webapp/WEB-INF/views/report/list.jsp index 73d1755c7..b5ce3e173 100644 --- a/src/main/webapp/WEB-INF/views/report/list.jsp +++ b/src/main/webapp/WEB-INF/views/report/list.jsp @@ -365,24 +365,14 @@ function customColumnClick(){ <%-- --%> <%-- --%> - - +
- + <%-- --%> 0
-
- - -
- - - 0 -
-
-
+ <%--
--%>
<%--
--%> diff --git a/src/main/webapp/static/pages/scripts/importExcel.js b/src/main/webapp/static/pages/scripts/importExcel.js new file mode 100644 index 000000000..795a5ed03 --- /dev/null +++ b/src/main/webapp/static/pages/scripts/importExcel.js @@ -0,0 +1,29 @@ +$(function(){ + //打开导入modal + $(".import").click(function(){ + $("#import_modal").modal({ + backdrop:"static", + keyboard:false, + show:true + }); + }); + $("input[name='serviceDictId']").click(function(){ + }); + $("input[name='regionDictIds']").click(function(){ + }); +}); + +/** + * 模板下载 + * TODO 后期修改为传入regionDictId + * */ +function downLoadTemplate(path){ + var obj={ + "regionDictId":$("input[name='regionDictIds']:checked").val() + ,"serviceDictId":$("input[name='serviceDictId']:checked").val() + ,"requestId":$("select[name='requestId']").val() + }; + var params = $.param(obj); + document.location.href = path+'/ntc/iplist/import/template?' + params; + +}