(1)asn no放入eCache中

(2)导入验证采用多线程验证,优化验证速度
(3)asn ip导入方式调整(未采用多线程,因为redis承受不了)
(4)asn ip列表展示速度优化
(5)导入方式重写:采用csv模式,限制采用xlsx格式,加载80万数据不会内存溢出.
This commit is contained in:
wangxin
2018-11-11 19:36:53 +08:00
parent 40bcfea683
commit 80dde7d6a0
53 changed files with 4831 additions and 2996 deletions

View File

@@ -148,5 +148,21 @@ public class AsnIpCfg extends BaseCfg<AsnIpCfg> {
public void setRegionId(Integer regionId) {
this.regionId = regionId;
}
@Override
public String toString() {
return "AsnIpCfg [regionId=" + regionId + ", ratelimit=" + ratelimit + ", ipType=" + ipType + ", ipPattern="
+ ipPattern + ", srcIpAddress=" + srcIpAddress + ", destIpAddress=" + destIpAddress + ", portPattern="
+ portPattern + ", srcPort=" + srcPort + ", destPort=" + destPort + ", asnIpGroupName=" + asnIpGroupName
+ ", asnIpGroup=" + asnIpGroup + ", direction=" + direction + ", protocol=" + protocol + ", protocolId="
+ protocolId + ", compileId=" + compileId + ", isIssued=" + isIssued + ", userRegion1=" + userRegion1
+ ", userRegion2=" + userRegion2 + ", userRegion3=" + userRegion3 + ", userRegion4=" + userRegion4
+ ", userRegion5=" + userRegion5 + ", cfgId=" + cfgId + ", cfgDesc=" + cfgDesc + ", action=" + action
+ ", isValid=" + isValid + ", isAudit=" + isAudit + ", creatorId=" + creatorId + ", createTime="
+ createTime + ", editorId=" + editorId + ", editTime=" + editTime + ", auditorId=" + auditorId
+ ", auditTime=" + auditTime + ", serviceId=" + serviceId + ", requestId=" + requestId
+ ", cancelRequestId=" + cancelRequestId + ", requestName=" + requestName + ", isAreaEffective="
+ isAreaEffective + ", classify=" + classify + ", attribute=" + attribute + ", lable=" + lable
+ ", cfgType=" + cfgType + ", functionId=" + functionId + ", doLog=" + doLog + "]";
}
}

View File

@@ -72,5 +72,10 @@ public class PolicyGroupInfo extends BaseCfg<PolicyGroupInfo> implements Seriali
public void setAsnNo(Long asnNo) {
this.asnNo = asnNo;
}
@Override
public String toString() {
// TODO Auto-generated method stub
return super.toString();
}
}

View File

@@ -0,0 +1,26 @@
package com.nis.domain.basics;
import java.io.Serializable;
public class Varibles implements Serializable{
/**
*
*/
private static final long serialVersionUID = -5747624301389103730L;
private String variableName;
private Long value;
public String getVariableName() {
return variableName;
}
public void setVariableName(String variableName) {
this.variableName = variableName;
}
public Long getValue() {
return value;
}
public void setValue(Long value) {
this.value = value;
}
}

View File

@@ -30,6 +30,14 @@ import com.nis.web.security.UserUtils;
* @version V1.0
*/
public class BaseCfg<T> extends BaseEntity<T> implements Cloneable{
protected Integer index;//excel导入时所在的行
public Integer getIndex() {
return index;
}
public void setIndex(Integer index) {
this.index = index;
}
protected Integer areaType;
protected List<AreaBean> areaIsp;
protected List<AreaIpCfg> areaCfg;

View File

@@ -343,5 +343,10 @@ public class BaseIpCfg extends BaseCfg<BaseIpCfg> {
public void setIndexTable(String indexTable) {
this.indexTable = indexTable;
}
public Integer getIndex() {
return index;
}
public void setIndex(Integer index) {
this.index = index;
}
}

View File

@@ -245,5 +245,10 @@ public class BaseStringCfg<T> extends BaseCfg<T> {
}
return list;
}
public Integer getIndex() {
return index;
}
public void setIndex(Integer index) {
this.index = index;
}
}

View File

@@ -216,4 +216,10 @@ public class ComplexkeywordCfg extends BaseCfg<ComplexkeywordCfg>{
}
return list;
}
public Integer getIndex() {
return index;
}
public void setIndex(Integer index) {
this.index = index;
}
}

View File

@@ -13,7 +13,7 @@ import com.nis.util.excel.ExcelField;
/**
* @Description: excel导入字符串类配置
*/
public class AppDomainTemplate {
public class AppDomainTemplate extends BasicTemplate{
private String cfgDesc;
private String cfgKeywords;
private Integer matchMethod ;

View File

@@ -5,7 +5,7 @@ import com.nis.util.excel.ExcelField;
/**
* @Description: excel导入ASN IP类配置
*/
public class AsnIpTemplate {
public class AsnIpTemplate extends BasicTemplate{
/**
* @Fields serialVersionUID:TODO用一句话描述这个变量表示什么

View File

@@ -0,0 +1,17 @@
package com.nis.domain.configuration.template;
public class BasicTemplate {
/**
* 数据在excel中的第几行
*/
protected Integer index;
public Integer getIndex() {
return index;
}
public void setIndex(Integer index) {
this.index = index;
}
}

View File

@@ -13,7 +13,7 @@ import com.nis.util.excel.ExcelField;
/**
* @Description: excel导入增强字符串类配置
*/
public class ComplexStringAllTemplate {
public class ComplexStringAllTemplate extends BasicTemplate{
private String cfgDesc;
private String district;

View File

@@ -2,7 +2,7 @@ package com.nis.domain.configuration.template;
import com.nis.util.excel.ExcelField;
public class DnsResStrategyTemplate {
public class DnsResStrategyTemplate extends BasicTemplate{
@ExcelField(title="policy_name",align=2,sort=1)
private String cfgDesc;
@ExcelField(title="group",align=2,sort=2)

View File

@@ -14,7 +14,7 @@ import com.nis.util.excel.ExcelField;
/**
* @Description: excel导入IP类配置
*/
public class IpAllTemplate {
public class IpAllTemplate extends BasicTemplate{
/**
* @Fields serialVersionUID:TODO用一句话描述这个变量表示什么

View File

@@ -13,7 +13,7 @@ import com.nis.util.excel.ExcelField;
/**
* @Description: excel导入IP白名单配置模板
*/
public class IpWhitelistTemplate {
public class IpWhitelistTemplate extends BasicTemplate{
/**
* @Fields serialVersionUID:TODO用一句话描述这个变量表示什么

View File

@@ -13,7 +13,7 @@ import com.nis.util.excel.ExcelField;
/**
* @Description: excel导入字符串类配置
*/
public class StringAllTemplate {
public class StringAllTemplate extends BasicTemplate{
private String cfgDesc;
private String cfgKeywords;

View File

@@ -1,11 +1,17 @@
package com.nis.domain.specific;
import java.io.Serializable;
import java.util.Date;
import com.google.gson.annotations.Expose;
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
import com.nis.util.excel.ExcelField;
public class ConfigGroupInfo {
public class ConfigGroupInfo implements Serializable{
/**
*
*/
private static final long serialVersionUID = -4539188977409108742L;
private Integer id;
private Integer groupId;
@ExcelField(title="group_name",sort=302)
@@ -72,5 +78,10 @@ public class ConfigGroupInfo {
public void setGroupType(Integer groupType) {
this.groupType = groupType;
}
@Override
public String toString() {
// TODO Auto-generated method stub
return ReflectionToStringBuilder.toString(this);
}
}

View File

@@ -0,0 +1,147 @@
package com.nis.util;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.apache.log4j.Logger;
import com.nis.domain.specific.ConfigGroupInfo;
import com.nis.web.dao.specific.ConfigGroupInfoDao;
import com.nis.web.service.SpringContextHolder;
import jersey.repackaged.com.google.common.collect.Maps;
import net.sf.ehcache.Cache;
import net.sf.ehcache.Element;
/**
* asn no缓存工具类
* @author Administrator
*
*/
public class AsnCacheUtils{
private static Logger logger=Logger.getLogger(AsnCacheUtils.class);
/**
* ASN号缓存
*/
private static final String ASN_NO_CACHE = "asnNoCache";
private static final int cache_rage = 1000;
private final static ConfigGroupInfoDao configGroupInfoDao = SpringContextHolder.getBean(ConfigGroupInfoDao.class);
/**
* 获取缓存
* @param cacheName
* @param key
* @return
*/
public static ConfigGroupInfo get(Long key) {
Element element = getCache(ASN_NO_CACHE).get(key/cache_rage);
if(element!=null) {
Map<Long,ConfigGroupInfo> map=(Map<Long,ConfigGroupInfo>)element.getObjectValue();
if(map.containsKey(key)) {
return map.get(key);
}
}
return null;
}
public static Map<Long,ConfigGroupInfo> getMap(Object key) {
Element element = getCache(ASN_NO_CACHE).get(key);
return (Map<Long,ConfigGroupInfo>)element.getObjectValue();
}
/**
* 初始化缓存
*/
//@PostConstruct
public synchronized static void init() {
long start=System.currentTimeMillis();
logger.warn("AsnCacheUtils init start...");
Cache cache=getCache(ASN_NO_CACHE);
//查询总量
Long count=configGroupInfoDao.getCountByType(4);
//缓存key
boolean loadDatabase=false;
if(cache.getKeys().size()==0) {
loadDatabase=true;
}else {
long c=0l;
for(Object key:cache.getKeys()) {
c+=getMap(key).size();
}
if(c!=count) {
loadDatabase=true;
}
}
if(loadDatabase) {
List<ConfigGroupInfo> list=configGroupInfoDao.findAllList(4);
Map<Long,Map<Long,ConfigGroupInfo>> groupMap=Maps.newHashMap();
for(ConfigGroupInfo configGroupInfo:list) {
if(groupMap.containsKey(configGroupInfo.getAsnId()/cache_rage)) {
groupMap.get(configGroupInfo.getAsnId()/cache_rage)
.put(configGroupInfo.getAsnId(), configGroupInfo);
}else {
Map<Long,ConfigGroupInfo> m=Maps.newHashMap();
m.put(configGroupInfo.getAsnId(), configGroupInfo);
groupMap.put(configGroupInfo.getAsnId()/cache_rage, m);
}
}
for(Entry<Long, Map<Long, ConfigGroupInfo>> e:groupMap.entrySet()) {
Element element = new Element(e.getKey(), e.getValue());
cache.put(element);
}
}
long end=System.currentTimeMillis();
logger.warn("AsnCacheUtils init finish,cost:"+(end-start));
}
/**
* 写入ASN_NO_CACHE缓存
* @param key
* @return
*/
public static void put(Long key, ConfigGroupInfo value) {
Long _key=key/cache_rage;
Element element = getCache(ASN_NO_CACHE).get(_key);
if(element==null) {
Map<Long,ConfigGroupInfo> map=Maps.newHashMap();
map.put(key, value);
element = new Element(_key, map);
}else {
Map<Long,ConfigGroupInfo> map=(Map<Long,ConfigGroupInfo>)element.getObjectValue();
map.put(key, value);
element = new Element(_key, map);
}
getCache(ASN_NO_CACHE).put(element);
}
/**
* 从缓存中移除
* @param cacheName
* @param key
*/
public static void remove(String key) {
getCache(ASN_NO_CACHE).remove(key);
}
public static void remove(Long key) {
Long _key=key/cache_rage;
Element element = getCache(ASN_NO_CACHE).get(_key);
if(element!=null) {
Map<Long,ConfigGroupInfo> map=(Map<Long,ConfigGroupInfo>)element.getObjectValue();
if(map.containsKey(key)) {
map.remove(key);
}
if(map.isEmpty()) {
getCache(ASN_NO_CACHE).remove(_key);
}else {
element=new Element(_key,map);
getCache(ASN_NO_CACHE).put(element);
}
}
}
private static Cache getCache(String cacheName){
Cache cache = CacheUtils.getCacheManager().getCache(cacheName);
if (cache == null){
CacheUtils.getCacheManager().addCache(cacheName);
cache = CacheUtils.getCacheManager().getCache(cacheName);
cache.getCacheConfiguration().setEternal(true);
}
return cache;
}
}

View File

@@ -3,6 +3,7 @@ package com.nis.util;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Pattern;
import com.google.gson.GsonBuilder;
@@ -707,4 +708,21 @@ public final class Constants {
public static final String CERT_VALIDATE_FILE=Configurations.getStringProperty("cert_validate_file", "x509");
//证书校验成功关键字
public static final String CERT_VALIDATE_SUCCESS_INFO=Configurations.getStringProperty("cert_validate_success_info", "x509");
/**
* 一些正则的pattern预先编译,避免多次编译
*/
public static final Pattern IPV4_IP_RANGE_REGEXP_NEW_PATTERN = Pattern.compile(IPV4_IP_RANGE_REGEXP_NEW);
public static final Pattern RANGE_PATTERN = Pattern.compile("\\d+\\-\\d+");
public static final Pattern PORT_MASK_PATTERN = Pattern.compile("^[0-9]+/[0-9]+$");
public static final Pattern PORT_PATTERN = Pattern.compile("^[0-9]+$");
public static final Pattern IPV4_IP_SUBNET_ORIGINAL_PATTERN = Pattern.compile(IPV4_IP_SUBNET_REGEXP_ORIGINAL);
public static final Pattern IPV4_IP_SUBNET_PATTERN = Pattern.compile(IPV4_IP_SUBNET_REGEXP);
public static final Pattern IPV6_IP_SUBNET_PATTERN = Pattern.compile(IPV6_IP_SUBNET_REGEXP);
public static final Pattern IPV4_IP_RANGE_PATTERN = Pattern.compile(IPV4_IP_RANGE_REGEXP);
public static final Pattern IPV6_IP_RANGE_PATTERN = Pattern.compile(IPV6_IP_RANGE_REGEXP);
public static final Pattern IPV4_IP_PATTERN = Pattern.compile(IPV4_IP_REGEXP);
public static final Pattern IPV6_IP_PATTERN = Pattern.compile(IPV6_IP_REGEXP);
//IP复用maat json中的ip region单次send 最大个数
public static final Integer MAAT_JSON_SEND_SIZE=Configurations.getIntProperty("maat_json_send_size", 1000);
public static final Integer MULITY_THREAD_SIZE=Configurations.getIntProperty("mulity_thread_size", 5);
}

View File

@@ -0,0 +1,318 @@
package com.nis.util.excel;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.util.Set;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.Callable;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.jets3t.service.ServiceException;
import org.springframework.beans.BeanUtils;
import com.beust.jcommander.internal.Lists;
import com.beust.jcommander.internal.Sets;
import com.nis.domain.FunctionRegionDict;
import com.nis.domain.FunctionServiceDict;
import com.nis.domain.configuration.ComplexkeywordCfg;
import com.nis.domain.configuration.DnsResStrategy;
import com.nis.util.Constants;
import com.nis.web.service.configuration.DnsResStrategyService;
public class CheckComplexStringFormatThread implements Callable<String>{
private Logger logger=Logger.getLogger(CheckComplexStringFormatThread.class);
private BlockingQueue<? extends Object> srcQueue;
private BlockingQueue<ComplexkeywordCfg> destQueue;
private Properties prop;
private DnsResStrategyService dnsResStrategyService;
private FunctionServiceDict serviceDict;
private FunctionRegionDict regionDict;
public CheckComplexStringFormatThread(FunctionServiceDict serviceDict,FunctionRegionDict regionDict,Properties prop,BlockingQueue<? extends Object> srcQueue,BlockingQueue<ComplexkeywordCfg> destQueue) {
this.serviceDict=serviceDict;
this.regionDict=regionDict;
this.srcQueue=srcQueue;
this.destQueue=destQueue;
this.prop=prop;
}
@Override
public String call() throws Exception {
List<Object> dataList=Lists.newArrayList(Constants.MAAT_JSON_SEND_SIZE);
String msg=null;
while(!srcQueue.isEmpty()) {
int size=srcQueue.drainTo(dataList,Constants.MAAT_JSON_SEND_SIZE);
if(regionDict.getRegionType().intValue()==3) {
try {
List<ComplexkeywordCfg> cfgs=this.checkComplexStringCfg(dataList);
destQueue.addAll(cfgs);
}catch (Exception e) {
// TODO: handle exception
msg=e.getMessage();
break;
}
}
dataList.clear();
}
return msg;
}
public List<ComplexkeywordCfg> checkComplexStringCfg(
List<?> list) throws ServiceException {
logger.warn("start to validate complexString data...");
long start=System.currentTimeMillis();
List<ComplexkeywordCfg> stringList = new ArrayList<ComplexkeywordCfg>();
String exprTypeP = regionDict.getConfigExprType();
if (StringUtils.isBlank(exprTypeP)) {
throw new RuntimeException("Found String region,but exprType is Empty");
}
String matchMethodP = regionDict.getConfigMatchMethod();
if (StringUtils.isBlank(matchMethodP)) {
throw new RuntimeException("Found String region,but matchMethod is Empty");
}
String hexP = regionDict.getConfigHex();
if (StringUtils.isBlank(hexP)) {
throw new RuntimeException("Found String region,but hex is Empty");
}
String mulityKeywordsP = regionDict.getConfigMultiKeywords();
if (StringUtils.isBlank(mulityKeywordsP)) {
throw new RuntimeException("Found String region,but mulityKeywords is Empty");
}
String dirtrictP = regionDict.getConfigDistrict();
StringBuffer errTip = new StringBuffer();
Pattern pattern = Pattern.compile("\t|\r|\n|\b|\f");
for (int i = 0; i < list.size(); i++) {
StringBuffer errInfo = new StringBuffer();
ComplexkeywordCfg baseStringCfg = new ComplexkeywordCfg();
BeanUtils.copyProperties(list.get(i), baseStringCfg);
if (regionDict.getRegionType().equals(3)) {
if (regionDict.getFunctionId().equals(7)) {
Long dnsStrategyId = baseStringCfg.getDnsStrategyId();
if (dnsStrategyId != null&&dnsStrategyId>0) {
List<DnsResStrategy> dnsStrategys = dnsResStrategyService.findDnsResStrategys(dnsStrategyId,
Constants.VALID_YES, Constants.AUDIT_YES);
if (dnsStrategys == null || dnsStrategys.size() == 0) {
errInfo.append(String.format(prop.getProperty("is_incorrect"),
prop.getProperty("dns_res_strategy")) + ";");
}
}
}
String keyword = baseStringCfg.getCfgKeywords();
String district = baseStringCfg.getDistrict();
if (StringUtils.isBlank(keyword)) {
errInfo.append(
String.format(prop.getProperty("can_not_null"), prop.getProperty("key_word") + " ") + ";");
}
if (StringUtils.isNotBlank(dirtrictP)) {
if (StringUtils.isBlank(district)) {
if (dirtrictP.indexOf(",") == -1) {
baseStringCfg.setDistrict(dirtrictP);
} else {
// baseStringCfg.setDistrict(dirtrictP.split(",")[0]);
errInfo.append(
String.format(prop.getProperty("can_not_null"), prop.getProperty("district") + " ")
+ ";");
}
} else if (dirtrictP.indexOf(district) == -1) {
errInfo.append(
String.format(prop.getProperty("is_incorrect"), prop.getProperty("district") + " ")
+ ";");
} else if (dirtrictP.indexOf("others")>-1&&district.equals("others")) {
//不允许自定义匹配区域导入
errInfo.append(prop.getProperty("district")+" "+
String.format(prop.getProperty("can_not_be"), " 'others'")+ ";");
}
}
if (mulityKeywordsP.equals("0")) {
if (keyword.indexOf("\n") > -1) {
errInfo.append(
String.format(prop.getProperty("not_multiple"), prop.getProperty("key_word")) + ";");
}
Matcher m = pattern.matcher(keyword);
if (m.find()) {
errInfo.append(String.format(prop.getProperty("has_invisible_char"),
prop.getProperty("key_word") + " '" + keyword + "'") + ";");
}
} else {
boolean has = false;
Set<String> keywordSet=Sets.newHashSet();
for (String key : keyword.split("\n")) {
Matcher m = pattern.matcher(key);
if (m.find()) {
has = true;
errInfo.append(String.format(prop.getProperty("has_invisible_char"),
prop.getProperty("key_word") + " '" + key + "'") + ";");
break;
}
if(!keywordSet.contains(key)) {
keywordSet.add(key);
}else {
errInfo.append(prop.getProperty("key_word") + " '" + key + "'"+" "+prop.getProperty("repeat") + ";");
}
}
if (!has) {
if(keyword.replaceAll("\n","").length()>1024) {
errInfo.append(String.format(prop.getProperty("most_keywords"),
prop.getProperty("key_word")) + ";");
}else {
String reWord = keyword.replaceAll("\n", Constants.KEYWORD_EXPR);
baseStringCfg.setCfgKeywords(reWord);
}
}
}
Integer exprType = baseStringCfg.getExprType();
boolean has = false;
if (exprType == null) {
if (exprTypeP.indexOf(",") == -1) {
if (mulityKeywordsP.equals("0") && exprTypeP.equals("1")) {
throw new RuntimeException("region dict config error,dict id is " + regionDict.getDictId());
}
baseStringCfg.setExprType(Integer.parseInt(exprTypeP));
} else if (exprTypeP.indexOf("0") > -1 && mulityKeywordsP.equals("0")) {
baseStringCfg.setExprType(0);
} else if (exprTypeP.indexOf("1") > -1 && mulityKeywordsP.equals("1")
&& keyword.indexOf("\n") > -1) {
baseStringCfg.setExprType(1);
} else if (exprTypeP.indexOf("0") > -1 && mulityKeywordsP.equals("1")
&& keyword.indexOf("\n") == -1) {
baseStringCfg.setExprType(0);
} else {
baseStringCfg.setExprType(Integer.parseInt(exprTypeP.split(",")[0]));
}
// errInfo.append(String.format(prop.getProperty("can_not_null"),
// prop.getProperty("expression_type"))+";");
} else {
for (String exp : exprTypeP.split(",")) {
if (exp.equals(exprType.toString())) {
has = true;
break;
}
}
if (!has) {
errInfo.append(
String.format(prop.getProperty("is_incorrect"), prop.getProperty("expression_type"))
+ ";");
}
has = false;
}
exprType = baseStringCfg.getExprType();
Integer matchMethod = baseStringCfg.getMatchMethod();
if (matchMethod == null) {
if (matchMethodP.indexOf(",") == -1) {
if (exprTypeP.equals("1") && !matchMethodP.equals("0")) {
throw new RuntimeException("region dict config error,dict id is " + regionDict.getDictId());
}
baseStringCfg.setMatchMethod(Integer.parseInt(matchMethodP));
} else if (exprType != null && exprType.intValue() == 1) {
if (matchMethodP.indexOf("0") > -1) {
baseStringCfg.setMatchMethod(0);
} else {
throw new RuntimeException("region dict config error,dict id is " + regionDict.getDictId());
}
} else {
baseStringCfg.setMatchMethod(Integer.parseInt(matchMethodP.split(",")[0]));
}
// errInfo.append(String.format(prop.getProperty("can_not_null"),
// prop.getProperty("match_method"))+";");
} else {
for (String exp : matchMethodP.split(",")) {
if (exp.equals(matchMethod.toString())) {
has = true;
break;
}
}
if (!has) {
errInfo.append(String.format(prop.getProperty("is_incorrect"), prop.getProperty("match_method"))
+ ";");
}
}
Integer isHex = baseStringCfg.getIsHex();
Integer isCaseInsenstive = baseStringCfg.getIsCaseInsenstive();
if (isHex == null || isCaseInsenstive == null) {
if (isHex == null) {
if (hexP.equals("0") || hexP.equals("2")) {
baseStringCfg.setIsHex(0);
} else if (hexP.equals("1")) {
baseStringCfg.setIsHex(1);
} else {
errInfo.append(
String.format(prop.getProperty("can_not_null"), prop.getProperty("is_hex")) + ";");
}
}
if (isCaseInsenstive == null) {
if (hexP.equals("0") || hexP.equals("1")) {
baseStringCfg.setIsCaseInsenstive(0);
} else if (hexP.equals("2")) {
baseStringCfg.setIsCaseInsenstive(1);
} else {
errInfo.append(String.format(prop.getProperty("can_not_null"),
prop.getProperty("is_case_insenstive")) + ";");
}
}
} else {
if (isHex.intValue() != 0 && isHex.intValue() != 1) {
errInfo.append(
String.format(prop.getProperty("is_incorrect"), prop.getProperty("is_hex")) + ";");
}
if (isCaseInsenstive.intValue() != 0 && isCaseInsenstive.intValue() != 1) {
errInfo.append(
String.format(prop.getProperty("is_incorrect"), prop.getProperty("is_case_insenstive"))
+ ";");
}
if (hexP.indexOf("1") == -1 && isHex.intValue() == 1) {
errInfo.append(
String.format(prop.getProperty("is_incorrect"), prop.getProperty("is_hex")) + ";");
}
if (hexP.equals("1") && isHex.intValue() == 0) {
errInfo.append(
String.format(prop.getProperty("is_incorrect"), prop.getProperty("is_hex")) + ";");
}
if (hexP.indexOf("2") == -1 && isCaseInsenstive.intValue() == 1) {
errInfo.append(
String.format(prop.getProperty("is_incorrect"), prop.getProperty("is_case_insenstive"))
+ ";");
}
if (hexP.equals("2") && isCaseInsenstive.intValue() == 0) {
errInfo.append(
String.format(prop.getProperty("is_incorrect"), prop.getProperty("is_case_insenstive"))
+ ";");
}
}
isHex = baseStringCfg.getIsHex();
isCaseInsenstive = baseStringCfg.getIsCaseInsenstive();
if (isHex != null && isCaseInsenstive != null) {
if (isHex.intValue() == 0 && isCaseInsenstive.intValue() == 0) {
baseStringCfg.setIsHexbin(0);
} else if (isHex.intValue() == 1 && isCaseInsenstive.intValue() == 0) {
baseStringCfg.setIsHexbin(1);
} else if (isHex.intValue() == 0 && isCaseInsenstive.intValue() == 1) {
baseStringCfg.setIsHexbin(2);
}else {
errInfo.append(prop.getProperty("hex_case_insensitive")+ ";");
}
}
}
if (errInfo.toString().length() > 0) {//
errTip.append(String.format(prop.getProperty("line"), baseStringCfg.getIndex()) + ",");
errTip.append(errInfo);
errTip.append("<br>");
}
stringList.add(baseStringCfg);
}
if (errTip.toString().length() > 0) {
throw new ServiceException(errTip.toString());
}
long end=System.currentTimeMillis();
logger.warn("validate complexString data finish,cost:"+(end-start));
return stringList;
}
public DnsResStrategyService getDnsResStrategyService() {
return dnsResStrategyService;
}
public void setDnsResStrategyService(DnsResStrategyService dnsResStrategyService) {
this.dnsResStrategyService = dnsResStrategyService;
}
}

View File

@@ -0,0 +1,155 @@
package com.nis.util.excel;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.util.Set;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.Callable;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.jets3t.service.ServiceException;
import org.springframework.beans.BeanUtils;
import com.beust.jcommander.internal.Lists;
import com.beust.jcommander.internal.Sets;
import com.nis.domain.FunctionRegionDict;
import com.nis.domain.FunctionServiceDict;
import com.nis.domain.basics.PolicyGroupInfo;
import com.nis.domain.configuration.ComplexkeywordCfg;
import com.nis.domain.configuration.DnsResStrategy;
import com.nis.util.Constants;
import com.nis.web.service.basics.PolicyGroupInfoService;
import com.nis.web.service.configuration.DnsResStrategyService;
public class CheckDnsResStrategyFormatThread implements Callable<String>{
private Logger logger=Logger.getLogger(CheckDnsResStrategyFormatThread.class);
private BlockingQueue<? extends Object> srcQueue;
private BlockingQueue<DnsResStrategy> destQueue;
private Properties prop;
private DnsResStrategyService dnsResStrategyService;
private FunctionServiceDict serviceDict;
private FunctionRegionDict regionDict;
private PolicyGroupInfoService policyGroupInfoService;
public CheckDnsResStrategyFormatThread(FunctionServiceDict serviceDict,FunctionRegionDict regionDict,Properties prop,BlockingQueue<? extends Object> srcQueue,BlockingQueue<DnsResStrategy> destQueue) {
this.serviceDict=serviceDict;
this.regionDict=regionDict;
this.srcQueue=srcQueue;
this.destQueue=destQueue;
this.prop=prop;
}
@Override
public String call() throws Exception {
List<Object> dataList=Lists.newArrayList(Constants.MAAT_JSON_SEND_SIZE);
String msg=null;
while(!srcQueue.isEmpty()) {
int size=srcQueue.drainTo(dataList,Constants.MAAT_JSON_SEND_SIZE);
if(regionDict.getRegionType().intValue()==6) {
try {
List<DnsResStrategy> cfgs=this.checkDnsResStrategyCfg(dataList);
destQueue.addAll(cfgs);
}catch (Exception e) {
// TODO: handle exception
msg=e.getMessage();
break;
}
}
dataList.clear();
}
return msg;
}
public List<DnsResStrategy> checkDnsResStrategyCfg(List<?> list)
throws ServiceException {
List<DnsResStrategy> dnsResStrategies=Lists.newArrayList();
StringBuffer errTip = new StringBuffer();
for (int i = 0; i < list.size(); i++) {
StringBuffer errInfo = new StringBuffer();
DnsResStrategy dnsResStrategy=new DnsResStrategy();
BeanUtils.copyProperties(list.get(i), dnsResStrategy);
String groupName=dnsResStrategy.getCfgDesc();
if(StringUtils.isBlank(groupName)) {
errInfo.append(String.format(prop.getProperty("can_not_null"),
prop.getProperty("policy_name")) + ";");
}
Integer resGroup1Id=dnsResStrategy.getResGroup1Id();
if(resGroup1Id==null) {
errInfo.append(String.format(prop.getProperty("can_not_null"),
prop.getProperty("group")) + ";");
}else {
PolicyGroupInfo info=policyGroupInfoService.getById(resGroup1Id);
if(info==null) {
errInfo.append(String.format(prop.getProperty("is_incorrect"),
prop.getProperty("group")) + ";");
}
}
Integer resGroup1Num=dnsResStrategy.getResGroup1Num();
if(resGroup1Num==null) {
errInfo.append(String.format(prop.getProperty("can_not_null"),
prop.getProperty("res_group_num")) + ";");
}
String ttl=dnsResStrategy.getTtl();
if(StringUtils.isBlank(ttl)) {
errInfo.append(String.format(prop.getProperty("can_not_null"),
prop.getProperty("min_ttl")) + ";");
}else {
Pattern p=Constants.RANGE_PATTERN;
Matcher m=p.matcher(ttl);
if(!m.matches()) {
errInfo.append(String.format(prop.getProperty("is_incorrect"),
prop.getProperty("min_ttl")) + ";");
}else {
String minTtl=ttl.split("-")[0];
String maxTtl=ttl.split("-")[1];
Integer min=null,max=null;
try {
min=Integer.parseInt(minTtl);
} catch (Exception e) {
// TODO: handle exception
errInfo.append(String.format(prop.getProperty("is_incorrect"),
prop.getProperty("min_ttl")) + ";");
}
try {
max=Integer.parseInt(maxTtl);
} catch (Exception e) {
// TODO: handle exception
errInfo.append(String.format(prop.getProperty("is_incorrect"),
prop.getProperty("min_ttl")) + ";");
}
if(min.intValue()>max.intValue())
{errInfo.append(String.format(prop.getProperty("is_incorrect"),
prop.getProperty("min_ttl")) + ";");
}else {
dnsResStrategy.setMinTtl(min);
dnsResStrategy.setMaxTtl(max);
}
}
}
if (errInfo.toString().length() > 0) {//
errTip.append(String.format(prop.getProperty("line"), dnsResStrategy.getIndex()) + ",");
errTip.append(errInfo);
errTip.append("<br>");
}
dnsResStrategies.add(dnsResStrategy);
}
if (errTip.toString().length() > 0) {
throw new ServiceException(errTip.toString());
}
return dnsResStrategies;
}
public DnsResStrategyService getDnsResStrategyService() {
return dnsResStrategyService;
}
public void setDnsResStrategyService(DnsResStrategyService dnsResStrategyService) {
this.dnsResStrategyService = dnsResStrategyService;
}
public PolicyGroupInfoService getPolicyGroupInfoService() {
return policyGroupInfoService;
}
public void setPolicyGroupInfoService(PolicyGroupInfoService policyGroupInfoService) {
this.policyGroupInfoService = policyGroupInfoService;
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,330 @@
package com.nis.util.excel;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.util.Set;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.Callable;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.jets3t.service.ServiceException;
import org.springframework.beans.BeanUtils;
import com.beust.jcommander.internal.Lists;
import com.beust.jcommander.internal.Sets;
import com.nis.domain.FunctionRegionDict;
import com.nis.domain.FunctionServiceDict;
import com.nis.domain.SysDataDictionaryItem;
import com.nis.domain.configuration.BaseStringCfg;
import com.nis.util.Constants;
import com.nis.util.DictUtils;
import com.nis.web.service.configuration.DnsResStrategyService;
public class CheckStringFormatThread implements Callable<String>{
private Logger logger=Logger.getLogger(CheckStringFormatThread.class);
private BlockingQueue<? extends Object> srcQueue;
private BlockingQueue<BaseStringCfg<?>> destQueue;
private Properties prop;
private DnsResStrategyService dnsResStrategyService;
private FunctionServiceDict serviceDict;
private FunctionRegionDict regionDict;
public CheckStringFormatThread(FunctionServiceDict serviceDict,FunctionRegionDict regionDict,Properties prop,BlockingQueue<? extends Object> srcQueue,BlockingQueue<BaseStringCfg<?>> destQueue) {
this.serviceDict=serviceDict;
this.regionDict=regionDict;
this.srcQueue=srcQueue;
this.destQueue=destQueue;
this.prop=prop;
}
@Override
public String call() throws Exception {
List<Object> dataList=Lists.newArrayList(Constants.MAAT_JSON_SEND_SIZE);
String msg=null;
while(!srcQueue.isEmpty()) {
int size=srcQueue.drainTo(dataList,Constants.MAAT_JSON_SEND_SIZE);
if(regionDict.getRegionType().intValue()==2) {
try {
List<BaseStringCfg<?>> cfgs=this.checkStringCfg(dataList);
destQueue.addAll(cfgs);
}catch (Exception e) {
// TODO: handle exception
msg=e.getMessage();
break;
}
}
dataList.clear();
}
return msg;
}
public List<BaseStringCfg<?>> checkStringCfg(List<?> list) throws ServiceException {
logger.warn("start to validate stringCfg data...");
long start=System.currentTimeMillis();
List<BaseStringCfg<?>> stringList = new ArrayList<BaseStringCfg<?>>();
String exprTypeP = regionDict.getConfigExprType();
if (StringUtils.isBlank(exprTypeP)) {
throw new RuntimeException("Found String region,but exprType is Empty");
}
String matchMethodP = regionDict.getConfigMatchMethod();
if (StringUtils.isBlank(matchMethodP)) {
throw new RuntimeException("Found String region,but matchMethod is Empty");
}
String hexP = regionDict.getConfigHex();
if (StringUtils.isBlank(hexP)) {
throw new RuntimeException("Found String region,but hex is Empty");
}
String mulityKeywordsP = regionDict.getConfigMultiKeywords();
if (StringUtils.isBlank(mulityKeywordsP)) {
throw new RuntimeException("Found String region,but mulityKeywords is Empty");
}
StringBuffer errTip = new StringBuffer();
Pattern pattern = Pattern.compile("\t|\r|\n|\b|\f");
Pattern domainPattern = Pattern.compile(Constants.DOMAIN_REGEXP);
for (int i = 0; i < list.size(); i++) {
StringBuffer errInfo = new StringBuffer();
BaseStringCfg baseStringCfg = new BaseStringCfg();
BeanUtils.copyProperties(list.get(i), baseStringCfg);
if (regionDict.getRegionType().equals(2)) {
if (regionDict.getFunctionId().equals(510) && "p2p_hash".equals(regionDict.getConfigServiceType())) {
String userRegion1 = baseStringCfg.getUserRegion1();
if (StringUtils.isNotBlank(userRegion1)) {
List<SysDataDictionaryItem> hashs = DictUtils.getDictList("P2P_HASH_TYPE");
boolean has = false;
for (SysDataDictionaryItem hash : hashs) {
if (hash.getItemCode().equals(userRegion1)) {
has = true;
break;
}
}
if (!has) {
errInfo.append(String.format(prop.getProperty("is_incorrect"),
prop.getProperty("p2p_hash_type") + " ") + ";");
}
}
}
String keyword = baseStringCfg.getCfgKeywords();
if (!regionDict.getFunctionId().equals(403)) {
if (StringUtils.isBlank(keyword)) {
errInfo.append(
String.format(prop.getProperty("can_not_null"), prop.getProperty("key_word") + " ") + ";");
}
if (mulityKeywordsP.equals("0")) {
if (keyword.indexOf("\n") > -1) {
errInfo.append(
String.format(prop.getProperty("not_multiple"), prop.getProperty("key_word")) + ";");
}
Matcher m = pattern.matcher(keyword);
if (m.find()) {
errInfo.append(String.format(prop.getProperty("has_invisible_char"),
prop.getProperty("key_word") + " '" + keyword + "'") + ";");
}
} else {
boolean has = false;
Set<String> keywordSet=Sets.newHashSet();
for (String key : keyword.split("\n")) {
Matcher m = pattern.matcher(key);
if (m.find()) {
has = true;
errInfo.append(String.format(prop.getProperty("has_invisible_char"),
prop.getProperty("key_word") + " '" + key + "'") + ";");
break;
}
if(!keywordSet.contains(key)) {
keywordSet.add(key);
}else {
errInfo.append(prop.getProperty("key_word") + " '" + key + "'"+" "+prop.getProperty("repeat") + ";");
}
}
if (!has) {
if(keyword.replaceAll("\n","").length()>1024) {
errInfo.append(String.format(prop.getProperty("most_keywords"),
prop.getProperty("key_word")) + ";");
}else {
String reWord = keyword.replaceAll("\n", Constants.KEYWORD_EXPR);
baseStringCfg.setCfgKeywords(reWord);
}
}
}
}else {
if (StringUtils.isBlank(keyword)) {
errInfo.append(
String.format(prop.getProperty("can_not_null"), prop.getProperty("domain_name") + " ") + ";");
}else {
Matcher m = pattern.matcher(keyword);
if (m.find()) {
errInfo.append(String.format(prop.getProperty("has_invisible_char"),
prop.getProperty("domain_name") + " '" + keyword + "'") + ";");
}else {
m = domainPattern.matcher(keyword);
if(!m.matches()) {
errInfo.append(String.format(prop.getProperty("not_valid_domain"),
prop.getProperty("domain_name") + " '" + keyword + "'") + ";");
}else {
baseStringCfg.setDomain(keyword);
}
}
}
}
Integer exprType = baseStringCfg.getExprType();
boolean has = false;
if (exprType == null) {
if (exprTypeP.indexOf(",") == -1) {
if (mulityKeywordsP.equals("0") && exprTypeP.equals("1")) {
throw new RuntimeException("region dict config error,dict id is " + regionDict.getDictId());
}
baseStringCfg.setExprType(Integer.parseInt(exprTypeP));
} else if (exprTypeP.indexOf("0") > -1 && mulityKeywordsP.equals("0")) {
baseStringCfg.setExprType(0);
} else if (exprTypeP.indexOf("1") > -1 && mulityKeywordsP.equals("1")
&& keyword.indexOf("\n") > -1) {
baseStringCfg.setExprType(1);
} else if (exprTypeP.indexOf("0") > -1 && mulityKeywordsP.equals("1")
&& keyword.indexOf("\n") == -1) {
baseStringCfg.setExprType(0);
} else {
baseStringCfg.setExprType(Integer.parseInt(exprTypeP.split(",")[0]));
}
// errInfo.append(String.format(prop.getProperty("can_not_null"),
// prop.getProperty("expression_type"))+";");
} else {
for (String exp : exprTypeP.split(",")) {
if (exp.equals(exprType.toString())) {
has = true;
break;
}
}
if (!has) {
errInfo.append(
String.format(prop.getProperty("is_incorrect"), prop.getProperty("expression_type"))
+ ";");
}
has = false;
}
exprType = baseStringCfg.getExprType();
Integer matchMethod = baseStringCfg.getMatchMethod();
if (matchMethod == null) {
if (matchMethodP.indexOf(",") == -1) {
if (exprTypeP.equals("1") && !matchMethodP.equals("0")) {
throw new RuntimeException("region dict config error,dict id is " + regionDict.getDictId());
}
baseStringCfg.setMatchMethod(Integer.parseInt(matchMethodP));
} else if (exprType != null && exprType.intValue() == 1) {
if (matchMethodP.indexOf("0") > -1) {
baseStringCfg.setMatchMethod(0);
} else {
throw new RuntimeException("region dict config error,dict id is " + regionDict.getDictId());
}
} else {
baseStringCfg.setMatchMethod(Integer.parseInt(matchMethodP.split(",")[0]));
}
// errInfo.append(String.format(prop.getProperty("can_not_null"),
// prop.getProperty("match_method"))+";");
} else {
for (String exp : matchMethodP.split(",")) {
if (exp.equals(matchMethod.toString())) {
has = true;
break;
}
}
if (!has) {
errInfo.append(String.format(prop.getProperty("is_incorrect"), prop.getProperty("match_method"))
+ ";");
}
}
Integer isHex = baseStringCfg.getIsHex();
Integer isCaseInsenstive = baseStringCfg.getIsCaseInsenstive();
if (isHex == null || isCaseInsenstive == null) {
if (isHex == null) {
if (hexP.equals("0") || hexP.equals("2")) {
baseStringCfg.setIsHex(0);
} else if (hexP.equals("1")) {
baseStringCfg.setIsHex(1);
} else {
errInfo.append(
String.format(prop.getProperty("can_not_null"), prop.getProperty("is_hex")) + ";");
}
}
if (isCaseInsenstive == null) {
if (hexP.equals("0") || hexP.equals("1")) {
baseStringCfg.setIsCaseInsenstive(0);
} else if (hexP.equals("2")) {
baseStringCfg.setIsCaseInsenstive(1);
} else {
errInfo.append(String.format(prop.getProperty("can_not_null"),
prop.getProperty("is_case_insenstive")) + ";");
}
}
} else {
if (isHex.intValue() != 0 && isHex.intValue() != 1) {
errInfo.append(
String.format(prop.getProperty("is_incorrect"), prop.getProperty("is_hex")) + ";");
}
if (isCaseInsenstive.intValue() != 0 && isCaseInsenstive.intValue() != 1) {
errInfo.append(
String.format(prop.getProperty("is_incorrect"), prop.getProperty("is_case_insenstive"))
+ ";");
}
if (hexP.indexOf("1") == -1 && isHex.intValue() == 1) {
errInfo.append(
String.format(prop.getProperty("is_incorrect"), prop.getProperty("is_hex")) + ";");
}
if (hexP.equals("1") && isHex.intValue() == 0) {
errInfo.append(
String.format(prop.getProperty("is_incorrect"), prop.getProperty("is_hex")) + ";");
}
if (hexP.indexOf("2") == -1 && isCaseInsenstive.intValue() == 1) {
errInfo.append(
String.format(prop.getProperty("is_incorrect"), prop.getProperty("is_case_insenstive"))
+ ";");
}
if (hexP.equals("2") && isCaseInsenstive.intValue() == 0) {
errInfo.append(
String.format(prop.getProperty("is_incorrect"), prop.getProperty("is_case_insenstive"))
+ ";");
}
}
isHex = baseStringCfg.getIsHex();
isCaseInsenstive = baseStringCfg.getIsCaseInsenstive();
if (isHex != null && isCaseInsenstive != null) {
if (isHex.intValue() == 0 && isCaseInsenstive.intValue() == 0) {
baseStringCfg.setIsHexbin(0);
} else if (isHex.intValue() == 1 && isCaseInsenstive.intValue() == 0) {
baseStringCfg.setIsHexbin(1);
} else if (isHex.intValue() == 0 && isCaseInsenstive.intValue() == 1) {
baseStringCfg.setIsHexbin(2);
}else {
errInfo.append(prop.getProperty("hex_case_insensitive")+ ";");
}
}
}
if (errInfo.toString().length() > 0) {//
errTip.append(String.format(prop.getProperty("line"), baseStringCfg.getIndex()) + ",");
errTip.append(errInfo);
errTip.append("<br>");
}
stringList.add(baseStringCfg);
}
if (errTip.toString().length() > 0) {
throw new ServiceException(errTip.toString());
}
long end=System.currentTimeMillis();
logger.warn("validate stringCfg data finish,cost:"+(end-start));
return stringList;
}
public DnsResStrategyService getDnsResStrategyService() {
return dnsResStrategyService;
}
public void setDnsResStrategyService(DnsResStrategyService dnsResStrategyService) {
this.dnsResStrategyService = dnsResStrategyService;
}
}

View File

@@ -0,0 +1,525 @@
/**
* Copyright &copy; 2012-2014 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
*/
package com.nis.util.excel;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
import java.util.Properties;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import javax.xml.parsers.ParserConfigurationException;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
import org.apache.poi.ss.usermodel.DateUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.multipart.MultipartFile;
import org.xml.sax.SAXException;
import com.google.common.collect.Lists;
import com.nis.domain.FunctionRegionDict;
import com.nis.domain.FunctionServiceDict;
import com.nis.util.DictUtils;
import com.nis.util.Reflections;
/**
* 导入Excel文件支持“XLS”和“XLSX”格式
* @author ThinkGem
* @version 2013-03-10
*/
public class ImportBigExcel extends XLSXCovertCSVReader{
private static Logger log = LoggerFactory.getLogger(ImportBigExcel.class);
/**
* 标题行号
*/
private Integer headerNum;
private int sheetIndex;
private Properties props;
private File uploadFile;
private FunctionRegionDict regionDict;
private FunctionServiceDict serviceDict;
//ip相关
private boolean srcIpShow=false;
private boolean destIpShow=false;
private boolean srcPortShow=false;
private boolean destPortShow=false;
private boolean directionShow=false;
private boolean protocolShow=false;
//字符串公共属性
private boolean matchMethodShow=false;
private boolean hexShow=false;
private boolean isCaseSensitiveShow=false;
//增强字符串相关
private boolean districtShow=false;
private List<Object[]> annotationList;
private List<List<Object>> dataList=Lists.newArrayList();
/**
* 构造函数
* @param file 导入文件对象
* @param headerNum 标题行号,数据行号=标题行号+1
* @param sheetIndex 工作表编号
* @throws InvalidFormatException
* @throws IOException
*/
public ImportBigExcel(MultipartFile multipartFile, Integer headerNum, int sheetIndex)
throws InvalidFormatException, IOException {
File upFile=new File(System.currentTimeMillis()+multipartFile.getOriginalFilename());
upFile.mkdirs();
multipartFile.transferTo(upFile);
if (!upFile.exists()){
throw new RuntimeException("导入文档为空!");
}else if(upFile.getName().toLowerCase().endsWith("xls")){
throw new RuntimeException("xls not supported");
}else if(upFile.getName().toLowerCase().endsWith("xlsx")){
}else{
throw new RuntimeException("文档格式不正确!");
}
this.sheetIndex = sheetIndex;
this.headerNum = headerNum;
this.uploadFile=upFile;
log.debug("Initialize success.");
}
/**
* //递归获取cls实体对象及父级对象的属性
* wx:修改,子类覆盖父类的同名方法
* @param list
* @param cls
*/
public void getFields(List<Field> list,Class<?> cls) {
Field[] fields=cls.getDeclaredFields();
if(fields != null && fields.length > 0){
List<Field> tempList=new ArrayList<>();
for (Field field : fields) {
if(list.size()==0) {
tempList.add(field);
}else {
boolean has=false;
for(Field checkF:list) {
if(checkF.getName().equals(field.getName())) {
has=true;
break;
}
}
if(!has) {
tempList.add(field);
}
}
}
list.addAll(tempList);
}
if(cls.getSuperclass() != null){
getFields(list,cls.getSuperclass());
}
}
/**
* //递归获取cls实体对象及父级对象的method
* @param list
* @param cls
*/
public void getMethods(List<Method> list,Class<?> cls) {
Method[] methods=cls.getDeclaredMethods();
if(methods != null && methods.length > 0){
List<Method> tempList=new ArrayList<>();
for (Method method : methods) {
if(list.size()==0) {
tempList.add(method);
}else {
boolean has=false;
for(Method checkM:list) {
if(checkM.getName().equals(method.getName())) {
has=true;
break;
}
}
if(!has) {
tempList.add(method);
}
}
}
list.addAll(tempList);
}
if(cls.getSuperclass() != null){
getMethods(list,cls.getSuperclass());
}
}
/**
* 加载region,service,注解
* @param cls
* @param props
* @param regionDict
* @param serviceDict
* @param groups
*/
public void loadInitParams(Class cls,Properties props,FunctionRegionDict regionDict,FunctionServiceDict serviceDict, int... groups) {
this.props=props;
this.regionDict=regionDict;
this.serviceDict=serviceDict;
//从region中获取配置信息
Integer regionType=regionDict.getRegionType();
if(regionType==1) {
String ipPortShow=regionDict.getConfigIpPortShow();
if(StringUtils.isNotBlank(ipPortShow)) {
if(ipPortShow.indexOf("1")>-1) {
srcIpShow=true;
}
if(ipPortShow.indexOf("2")>-1) {
srcPortShow=true;
}
if(ipPortShow.indexOf("3")>-1) {
destIpShow=true;
}
if(ipPortShow.indexOf("4")>-1) {
destPortShow=true;
}
};
//协议方向等,如果只有一个值,就 不需要输入了
String direction=regionDict.getConfigDirection();
if(StringUtils.isNotBlank(direction)&&direction.indexOf(",")>-1) {
directionShow=true;
}
String protocol=regionDict.getConfigProtocol();
if(StringUtils.isNotBlank(protocol)&&protocol.indexOf(",")>-1) {
protocolShow=true;
}
//packet ip reject
if(regionDict.getFunctionId().equals(5)&&serviceDict!=null&&serviceDict.getServiceId().equals(16)) {
protocolShow=false;
}
}else if(regionType==2||regionType==3){
String matchMethod= regionDict.getConfigMatchMethod();
if(StringUtils.isNotBlank(matchMethod)&&matchMethod.indexOf(",")>-1) {
matchMethodShow=true;
}
String hex= regionDict.getConfigHex();
if(StringUtils.isNotBlank(hex)&&hex.indexOf(",")>-1) {
hexShow=true;
isCaseSensitiveShow=true;
}
String district=regionDict.getConfigDistrict();
if(StringUtils.isNotBlank(district)&&district.indexOf(",")>-1) {
districtShow=true;
}
}
List<Object[]> annotationList = Lists.newArrayList();
List<Field> fs=new ArrayList<Field>();
// Get annotation field
//递归获取cls实体对象及父级对象的属性
getFields(fs, cls);
for (Field f : fs){
//排除不需要导出的字段
if(!srcIpShow) {
if(f.getName().equalsIgnoreCase("srcIpAddress")) {
continue;
}
}
if(!destIpShow) {
if(f.getName().equalsIgnoreCase("destIpAddress")) {
continue;
}
}
if(!srcPortShow) {
if(f.getName().equalsIgnoreCase("srcPort")) {
continue;
}
}
if(!destPortShow) {
if(f.getName().equalsIgnoreCase("destPort")) {
continue;
}
}
if(!directionShow) {
if(f.getName().equalsIgnoreCase("direction")) {
continue;
}
}
if(!protocolShow) {
if(f.getName().equalsIgnoreCase("protocol")) {
continue;
}
}
if(!matchMethodShow) {
if(f.getName().equalsIgnoreCase("matchMethod")) {
continue;
}
}
if(!hexShow) {
if(f.getName().equalsIgnoreCase("isHex")) {
continue;
}
}
if(!isCaseSensitiveShow) {
if(f.getName().equalsIgnoreCase("isCaseInsenstive")) {
continue;
}
}
if(!districtShow) {
if(f.getName().equalsIgnoreCase("district")) {
continue;
}
}
ExcelField ef = f.getAnnotation(ExcelField.class);
if (ef != null && (ef.type()==0 || ef.type()==2)){
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});
}
}
}
// Get annotation method
// Method[] ms = cls.getDeclaredMethods();
List<Method> ms=new ArrayList<Method>();
// Get annotation method
//递归获取cls实体对象及父级对象的属性
getMethods(ms, cls);
for (Method m : ms){
//排除不需要导出的字段
if(!srcIpShow) {
if(m.getName().equalsIgnoreCase("get"+"srcIpAddress")||m.getName().equalsIgnoreCase("set"+"srcIpAddress")) {
continue;
}
}
if(!destIpShow) {
if(m.getName().equalsIgnoreCase("get"+"destIpAddress")||m.getName().equalsIgnoreCase("set"+"destIpAddress")) {
continue;
}
}
if(!srcPortShow) {
if(m.getName().equalsIgnoreCase("get"+"srcPort")||m.getName().equalsIgnoreCase("set"+"srcPort")) {
continue;
}
}
if(!destPortShow) {
if(m.getName().equalsIgnoreCase("get"+"destPort")||m.getName().equalsIgnoreCase("set"+"destPort")) {
continue;
}
}
if(!directionShow) {
if(m.getName().equalsIgnoreCase("get"+"direction")||m.getName().equalsIgnoreCase("set"+"direction")) {
continue;
}
}
if(!protocolShow) {
if(m.getName().equalsIgnoreCase("get"+"protocol")||m.getName().equalsIgnoreCase("set"+"protocol")) {
continue;
}
}
if(!matchMethodShow) {
if(m.getName().equalsIgnoreCase("get"+"matchMethod")||m.getName().equalsIgnoreCase("set"+"matchMethod")) {
continue;
}
}
if(!hexShow) {
if(m.getName().equalsIgnoreCase("get"+"isHex")||m.getName().equalsIgnoreCase("set"+"isHex")) {
continue;
}
}
if(!isCaseSensitiveShow) {
if(m.getName().equalsIgnoreCase("get"+"isCaseInsenstive")||m.getName().equalsIgnoreCase("set"+"isCaseInsenstive")) {
continue;
}
}
if(!districtShow) {
if(m.getName().equalsIgnoreCase("get"+"district")||m.getName().equalsIgnoreCase("set"+"district")) {
continue;
}
}
ExcelField ef = m.getAnnotation(ExcelField.class);
if (ef != null && (ef.type()==0 || ef.type()==2)){
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<Object[]>() {
public int compare(Object[] o1, Object[] o2) {
return new Integer(((ExcelField)o1[0]).sort()).compareTo(
new Integer(((ExcelField)o2[0]).sort()));
};
});
this.annotationList=annotationList;
}
@Override
public List<Object> optRows(int sheetIndex, int curRow, List<Object> rowlist) {
// TODO Auto-generated method stub
List<Object> rowlistCopy=Lists.newArrayList();
rowlistCopy.addAll(rowlist);
dataList.add(rowlistCopy);
return null;
}
/**
* 获取导入数据列表
* @param cls 导入对象类型
* @param groups 导入分组
* @throws SQLException
* @throws SAXException
* @throws ParserConfigurationException
* @throws OpenXML4JException
* @throws IOException
*/
public <E> BlockingQueue<E> getDataList(Class<E> cls) throws InstantiationException, IllegalAccessException, IOException, OpenXML4JException, ParserConfigurationException, SAXException, SQLException{
log.warn("start to load data...");
this.processOneSheet(uploadFile, this.sheetIndex);
long start=System.currentTimeMillis();
if(regionDict==null) {
throw new RuntimeException("regionDict is null!");
}
// Get excel data
BlockingQueue<E> _dataList =new ArrayBlockingQueue(dataList.size(),true);
for (int i = 0; i < dataList.size(); i++) {
E e = (E)cls.newInstance();
if(i<=headerNum) {
continue;
}
int column = 0;
List<Object> row=dataList.get(i);
StringBuilder sb = new StringBuilder();
for (Object[] os : annotationList){
Object val=row.get(column);
column++;
if (val != null){
ExcelField ef = (ExcelField)os[0];
// If is dict type, get dict value
if (StringUtils.isNotBlank(ef.dictType())){
Object val1 = DictUtils.getDictCode(ef.dictType(), val.toString(), "");
//没有获取到字典值的话会影响验证判断
if(val1!=null&&StringUtils.isNotBlank(val1.toString())) {
val=val1;
}
//log.debug("Dictionary type value: ["+i+","+colunm+"] " + val);
}
// Get param type and type cast
Class<?> valType = Class.class;
if (os[1] instanceof Field){
valType = ((Field)os[1]).getType();
}else if (os[1] instanceof Method){
Method method = ((Method)os[1]);
if ("get".equals(method.getName().substring(0, 3))){
valType = method.getReturnType();
}else if("set".equals(method.getName().substring(0, 3))){
valType = ((Method)os[1]).getParameterTypes()[0];
}
}
//log.debug("Import value type: ["+i+","+column+"] " + valType);
try {
if (valType == String.class){
String s = String.valueOf(val.toString());
//0.0.0.0表示任意IP的含义
if(StringUtils.endsWith(s, ".0") && !s.endsWith("0.0.0.0")){
val = StringUtils.substringBefore(s, ".0");
}else{
val = String.valueOf(val.toString());
}
}else if (valType == Integer.class){
val = Double.valueOf(val.toString()).intValue();
}else if (valType == Long.class){
val = Double.valueOf(val.toString()).longValue();
}else if (valType == Double.class){
val = Double.valueOf(val.toString());
}else if (valType == Float.class){
val = Float.valueOf(val.toString());
}else if (valType == Date.class){
val = DateUtil.getJavaDate((Double)val);
}else{
if (ef.fieldType() != Class.class){
val = ef.fieldType().getMethod("getValue", String.class).invoke(null, val.toString());
}else{
val = Class.forName(this.getClass().getName().replaceAll(this.getClass().getSimpleName(),
"fieldtype."+valType.getSimpleName()+"Type")).getMethod("getValue", String.class).invoke(null, val.toString());
}
}
} catch (Exception ex) {
log.info("Get cell value ["+i+","+column+"] error: " + ex.toString());
val = null;
}
// set entity value
if (os[1] instanceof Field){
Reflections.invokeSetter(e, ((Field)os[1]).getName(), val);
}else if (os[1] instanceof Method){
String mthodName = ((Method)os[1]).getName();
if ("get".equals(mthodName.substring(0, 3))){
mthodName = "set"+StringUtils.substringAfter(mthodName, "get");
}
Reflections.invokeMethod(e, mthodName, new Class[] {valType}, new Object[] {val});
}
//设置索引值
Reflections.invokeSetter(e, "index", (i+1));
}
sb.append(val+", ");
}
_dataList.offer(e);
row.clear();
log.debug("Read success: ["+i+"] "+sb.toString());
}
long end=System.currentTimeMillis();
log.warn(" load data finish,cost:"+(end-start));
return _dataList;
}
public File getUploadFile() {
return uploadFile;
}
public void setUploadFile(File uploadFile) {
this.uploadFile = uploadFile;
}
// /**
// * 导入测试
// */
// public static void main(String[] args) throws Throwable {
//
// ImportExcel ei = new ImportExcel("target/export.xlsx", 1);
//
// for (int i = ei.getDataRowNum(); i < ei.getLastDataRowNum(); i++) {
// Row row = ei.getRow(i);
// for (int j = 0; j < ei.getLastCellNum(); j++) {
// Object val = ei.getCellValue(row, j);
// System.out.print(val+", ");
// }
// System.out.print("\n");
// }
//
// }
}

View File

@@ -0,0 +1,593 @@
package com.nis.util.excel;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.apache.poi.hssf.usermodel.HSSFDataFormatter;
import org.apache.poi.hssf.usermodel.HSSFDateUtil;
import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.openxml4j.opc.PackageAccess;
import org.apache.poi.ss.usermodel.BuiltinFormats;
import org.apache.poi.ss.usermodel.DataFormatter;
import org.apache.poi.xssf.eventusermodel.ReadOnlySharedStringsTable;
import org.apache.poi.xssf.eventusermodel.XSSFReader;
import org.apache.poi.xssf.model.StylesTable;
import org.apache.poi.xssf.usermodel.XSSFCellStyle;
import org.apache.poi.xssf.usermodel.XSSFRichTextString;
import org.xml.sax.Attributes;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.DefaultHandler;
/**
* 使用CVS模式解决XLSX文件可以有效解决用户模式内存溢出的问题
* 该模式是POI官方推荐的读取大数据的模式在用户模式下数据量较大、Sheet较多、或者是有很多无用的空行的情况
* ,容易出现内存溢出,用户模式读取Excel的典型代码如下 FileInputStream file=new
* FileInputStream("c:\\test.xlsx"); Workbook wb=new XSSFWorkbook(file);
*
*
* @author 山人
*/
public abstract class XLSXCovertCSVReader {
/**
* The type of the data value is indicated by an attribute on the cell. The
* value is usually in a "v" element within the cell.
*/
enum xssfDataType {
BOOL, ERROR, FORMULA, INLINESTR, SSTINDEX, NUMBER,
}
/**
* 使用xssf_sax_API处理Excel,请参考: http://poi.apache.org/spreadsheet/how-to.html#xssf_sax_api
* <p/>
* Also see Standard ECMA-376, 1st edition, part 4, pages 1928ff, at
* http://www.ecma-international.org/publications/standards/Ecma-376.htm
* <p/>
* A web-friendly version is http://openiso.org/Ecma/376/Part4
*/
//定义前一个元素和当前元素的位置用来计算其中空的单元格数量如A6和A8等
private String preRefnum = null, refnum = null;
//定义该文档一行最大的单元格数,用来补全一行最后可能缺失的单元格
private String maxRefnum = null;
private String lastContents;
private int curCol = 0;
// private Integer type;
private List<IndexValue> rowData= new ArrayList<IndexValue>();
//excel记录行操作方法以sheet索引行索引和行元素列表为参数对sheet的一行元素进行操作元素为String类型
public abstract List<Object> optRows(int sheetIndex,int curRow, List<Object> rowlist) ;
class MyXSSFSheetHandler extends DefaultHandler {
/**
* Table with styles
*/
private StylesTable stylesTable;
/**
* Table with unique strings
*/
private ReadOnlySharedStringsTable sharedStringsTable;
/**
* Number of columns to read starting with leftmost
*/
// Set when V start element is seen
private boolean vIsOpen;
// Set when cell start element is seen;
// used when cell close element is seen.
private xssfDataType nextDataType;
private int sheetIndex = -1;
// Used to format numeric cell values.
private short formatIndex;
private String formatString;
private final DataFormatter formatter;
private int thisColumn = -1;
// The last column printed to the output stream
private int lastColumnNumber = -1;
private List<Object> rowlist = new ArrayList<Object>();
// Gathers characters as they are seen.
private StringBuffer value;
// private String[] record;
// private List<String[]> rows = new ArrayList<String[]>();
private boolean isCellNull = false;
/**
* Accepts objects needed while parsing.
*
* @param styles
* Table of styles
* @param strings
* Table of shared strings
* @param cols
* Minimum number of columns to show
* @param target
* Sink for output
*/
public MyXSSFSheetHandler(StylesTable styles,
ReadOnlySharedStringsTable strings) {
this.stylesTable = styles;
this.sharedStringsTable = strings;
this.value = new StringBuffer();
this.nextDataType = xssfDataType.NUMBER;
this.formatter = new DataFormatter();
rowlist.clear();// 每次读取都清空行集合
}
/*
* (non-Javadoc)
*
* @see
* org.xml.sax.helpers.DefaultHandler#startElement(java.lang.String,
* java.lang.String, java.lang.String, org.xml.sax.Attributes)
*/
public void startElement(String uri, String localName, String name,
Attributes attributes) throws SAXException {
if ("inlineStr".equals(name) || "v".equals(name)) {
vIsOpen = true;
// Clear contents cache
value.setLength(0);
}
// c => cell
else if ("c".equals(name)) {
// Get the cell reference
String r = attributes.getValue("r");
int firstDigit = -1;
for (int c = 0; c < r.length(); ++c) {
if (Character.isDigit(r.charAt(c))) {
firstDigit = c;
break;
}
}
thisColumn = nameToColumn(r.substring(0, firstDigit));
String cellType = attributes.getValue("t");
if(preRefnum == null){
preRefnum = attributes.getValue("r");
}
// else{
// preRefnum = refnum;
// }
//当前单元格的位置
refnum = attributes.getValue("r");
// Figure out if the value is an index in the SST
// Set up defaults.
this.nextDataType = xssfDataType.NUMBER;
this.formatIndex = -1;
this.formatString = null;
String cellStyleStr = attributes.getValue("s");
if ("b".equals(cellType))
nextDataType = xssfDataType.BOOL;
else if ("e".equals(cellType))
nextDataType = xssfDataType.ERROR;
else if ("inlineStr".equals(cellType))
nextDataType = xssfDataType.INLINESTR;
else if ("s".equals(cellType))
nextDataType = xssfDataType.SSTINDEX;
else if ("str".equals(cellType))
nextDataType = xssfDataType.FORMULA;
else if (cellStyleStr != null) {
// It's a number, but almost certainly one
// with a special style or format
int styleIndex = Integer.parseInt(cellStyleStr);
XSSFCellStyle style = stylesTable.getStyleAt(styleIndex);
this.formatIndex = style.getDataFormat();
this.formatString = style.getDataFormatString();
if (this.formatString == null)
this.formatString = BuiltinFormats
.getBuiltinFormat(this.formatIndex);
}
}
lastContents = "";
}
/*
* (non-Javadoc)
*
* @see org.xml.sax.helpers.DefaultHandler#endElement(java.lang.String,
* java.lang.String, java.lang.String)
*/
public void endElement(String uri, String localName, String name)
throws SAXException {
Object thisVal = null;
// v => contents of a cell
if ("v".equals(name)) {
// Process the value contents as required.
// Do now, as characters() may be called more than once
switch (nextDataType) {
case BOOL:
char first = value.charAt(0);
thisVal = first == '0' ? false : true;
break;
case ERROR:
thisVal = "\"ERROR:" + value.toString() + '"';
break;
case FORMULA:
// A formula could result in a string value,
// so always add double-quote characters.
thisVal = value.toString() ;
break;
case INLINESTR:
// TODO: have seen an example of this, so it's untested.
XSSFRichTextString rtsi = new XSSFRichTextString(
value.toString());
thisVal = rtsi.toString() ;
break;
case SSTINDEX:
String sstIndex = value.toString();
try {
int idx = Integer.parseInt(sstIndex);
XSSFRichTextString rtss = new XSSFRichTextString(
sharedStringsTable.getEntryAt(idx));
thisVal = rtss.toString();
} catch (NumberFormatException ex) {
System.out.println("Failed to parse SST index '" + sstIndex
+ "': " + ex.toString());
}
break;
case NUMBER:
String n = value.toString();
// 判断是否是日期格式
if (HSSFDateUtil.isADateFormat(this.formatIndex, n)) {
Double d = Double.parseDouble(n);
Date date=HSSFDateUtil.getJavaDate(d);
thisVal=date;
} else if (this.formatString != null)
thisVal = formatter.formatRawCellContents(
Double.parseDouble(n), this.formatIndex,
this.formatString);
else if(n.indexOf("E")!=-1) {//处理科学计数法
BigDecimal bd = new BigDecimal(n);
thisVal = bd.toPlainString();
}else
thisVal = n;
break;
default:
thisVal = "(TODO: Unexpected type: " + nextDataType + ")";
break;
}
// Output after we've seen the string contents
// Emit commas for any fields that were missing on this row
if (lastColumnNumber == -1) {
lastColumnNumber = 0;
}
if(!refnum.equals(preRefnum)){
int len = countNullCell(refnum, preRefnum);
for(int i=0;i<len;i++){
rowlist.add(curCol, "");
curCol++;
}
}
//判断单元格的值是否为空
if (thisVal == null || "".equals(isCellNull)) {
// isCellNull = true;// 设置单元格是否为空值
}else{
preRefnum = refnum;
}
// System.out.println("refnum="+refnum+"preRefnum="+preRefnum+"curCol="+curCol);
rowlist.add(curCol, thisVal);
rowData.add(new IndexValue(refnum,lastContents) );
curCol++;
// record[thisColumn] = thisStr;
// Update column
if (thisColumn > -1)
lastColumnNumber = thisColumn;
} else if ("row".equals(name)) {
// Print out any missing commas if needed
if (thisColumn > 0) {
sheetIndex++;
// Columns are 0 based
if (lastColumnNumber == -1) {
lastColumnNumber = 0;
}
//默认第一行为表头,以该行单元格数目为最大数目
if(sheetIndex == 0){
maxRefnum = refnum;
}
//补全一行尾部可能缺失的单元格
if(maxRefnum != null){
int len = countNullCell(maxRefnum, refnum);
for(int i=0;i<=len;i++){
rowlist.add(curCol, "");
curCol++;
}
}
if ( rowlist.get(0) != null
&& rowlist.get(1) != null)// 判断是否空行
{
optRows(sheetIndex,lastColumnNumber,rowlist);
rowlist.clear();
// rows.add(record.clone());
isCellNull = false;
// for (int i = 0; i < record.length; i++) {
// record[i] = null;
// }
}
}
rowlist.clear();
rowData.clear();
curCol = 0;
preRefnum = null;
refnum = null;
lastColumnNumber = -1;
}
}
// public List<String[]> getRows() {
// return rows;
// }
//
// public void setRows(List<String[]> rows) {
// this.rows = rows;
// }
/**
* Captures characters only if a suitable element is open. Originally
* was just "v"; extended for inlineStr also.
*/
public void characters(char[] ch, int start, int length)
throws SAXException {
if (vIsOpen)
value.append(ch, start, length);
}
/**
* Converts an Excel column name like "C" to a zero-based index.
*
* @param name
* @return Index corresponding to the specified name
*/
private int nameToColumn(String name) {
int column = -1;
for (int i = 0; i < name.length(); ++i) {
int c = name.charAt(i);
column = (column + 1) * 26 + c - 'A';
}
return column;
}
private String formateDateToString(Date date) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//格式化日期
return sdf.format(date);
}
}
// /////////////////////////////////////
private String path;
/**
* Creates a new XLSX -> CSV converter
*
* @param pkg
* The XLSX package to process
* @param output
* The PrintStream to output the CSV to
* @param minColumns
* The minimum number of columns to output, or -1 for no minimum
*/
public XLSXCovertCSVReader(
String path) {
this.path = path;
}
public XLSXCovertCSVReader(
) {
}
/**
* Parses and shows the content of one sheet using the specified styles and
* shared-strings tables.
*
* @param styles
* @param strings
* @param sheetInputStream
*/
public void processSheet(StylesTable styles,
ReadOnlySharedStringsTable strings, InputStream sheetInputStream)
throws IOException, ParserConfigurationException, SAXException {
InputSource sheetSource = new InputSource(sheetInputStream);
SAXParserFactory saxFactory = SAXParserFactory.newInstance();
SAXParser saxParser = saxFactory.newSAXParser();
XMLReader sheetParser = saxParser.getXMLReader();
MyXSSFSheetHandler handler = new MyXSSFSheetHandler(styles, strings);
sheetParser.setContentHandler(handler);
sheetParser.parse(sheetSource);
}
/**
* 初始化这个处理程序 将
*
* @throws IOException
* @throws OpenXML4JException
* @throws ParserConfigurationException
* @throws SAXException
*/
public void processOneSheet(String path,int sheetId) throws IOException, OpenXML4JException,
ParserConfigurationException, SAXException,SQLException {
OPCPackage xlsxPackage = OPCPackage.open(path, PackageAccess.READ);
ReadOnlySharedStringsTable strings = new ReadOnlySharedStringsTable(
xlsxPackage);
XSSFReader xssfReader = new XSSFReader(xlsxPackage);
List<String[]> list = null;
StylesTable styles = xssfReader.getStylesTable();
InputStream stream=xssfReader.getSheet("rId"+sheetId);
processSheet(styles, strings,stream );
stream.close();
xlsxPackage.close();
}
public void processOneSheet(File file,int sheetId) throws IOException, OpenXML4JException,
ParserConfigurationException, SAXException,SQLException {
OPCPackage xlsxPackage = OPCPackage.open(file, PackageAccess.READ);
ReadOnlySharedStringsTable strings = new ReadOnlySharedStringsTable(
xlsxPackage);
XSSFReader xssfReader = new XSSFReader(xlsxPackage);
List<String[]> list = null;
StylesTable styles = xssfReader.getStylesTable();
InputStream stream=xssfReader.getSheet("rId"+sheetId);
processSheet(styles, strings,stream );
stream.close();
xlsxPackage.close();
}
/**
* 读取Excel
*
* @param path
* 文件路径
* @param sheetName
* sheet名称
* @param minColumns
* 列总数
* @return
* @throws SAXException
* @throws ParserConfigurationException
* @throws OpenXML4JException
* @throws IOException
*/
public static void readerExcel(String path, String sheetName,
int minColumns) throws IOException, OpenXML4JException,
ParserConfigurationException, SAXException {
OPCPackage p = OPCPackage.open(path, PackageAccess.READ);
// XLSXCovertCSVReader xlsx2csv = new XLSXCovertCSVReader(p,
// sheetName);
// xlsx2csv.process(p, sheetName);
p.close();
}
public List<String> getMyDataList(List<IndexValue> dataList) {
List<String> myDataList = new ArrayList<String>();
if(dataList==null||dataList.size()<=0) return myDataList;
for(int i=0;i<dataList.size()-1;i++){
IndexValue current = dataList.get(i);
myDataList.add(current .v_value);
IndexValue next = dataList.get(i+1);
int level = next.getLevel(current);
for(int k = 0;k<level-1;k++){
myDataList.add(null);
}
if(i==dataList.size()-2){
myDataList.add(next .v_value);
}
}
return myDataList;
}
private class IndexValue{
String v_index;
String v_value;
public IndexValue(String v_index, String v_value) {
super();
this.v_index = v_index;
this.v_value = v_value;
}
@Override
public String toString() {
return "IndexValue [v_index=" + v_index + ", v_value="
+ v_value + "]";
}
public int getLevel(IndexValue p){
char[] other = p.v_index.replaceAll("[0-9]", "").toCharArray();
char[] self = this.v_index.replaceAll("[0-9]", "").toCharArray();
if(other.length!=self.length) return -1;
for(int i=0;i<other.length;i++){
if(i==other.length-1){
return self[i]-other[i];
}else{
if(self[i]!=other[i]){
return -1;
}
}
}
return -1;
}
}
/**
* 计算两个单元格之间的单元格数目(同一行)
* @param ref
* @param preRef
* @return
*/
public int countNullCell(String ref, String preRef){
//excel2007最大行数是1048576最大列数是16384最后一列列名是XFD
String xfd = ref.replaceAll("\\d+", "");
String xfd_1 = preRef.replaceAll("\\d+", "");
xfd = fillChar(xfd, 3, '@', true);
xfd_1 = fillChar(xfd_1, 3, '@', true);
char[] letter = xfd.toCharArray();
char[] letter_1 = xfd_1.toCharArray();
int res = (letter[0]-letter_1[0])*26*26 + (letter[1]-letter_1[1])*26 + (letter[2]-letter_1[2]);
return res-1;
}
/**
* 字符串的填充
* @param str
* @param len
* @param let
* @param isPre
* @return
*/
String fillChar(String str, int len, char let, boolean isPre){
int len_1 = str.length();
if(len_1 <len){
if(isPre){
for(int i=0;i<(len-len_1);i++){
str = let+str;
}
}else{
for(int i=0;i<(len-len_1);i++){
str = str+let;
}
}
}
return str;
}
public void characters(char[] ch, int start, int length)
throws SAXException {
//得到单元格内容的值
lastContents += new String(ch, start, length);
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -25,9 +25,11 @@ import com.nis.domain.Page;
import com.nis.domain.basics.AsnIpCfg;
import com.nis.domain.basics.PolicyGroupInfo;
import com.nis.domain.configuration.CfgIndexInfo;
import com.nis.domain.configuration.DnsResStrategy;
import com.nis.domain.configuration.IpPortCfg;
import com.nis.domain.specific.ConfigGroupInfo;
import com.nis.domain.specific.SpecificServiceCfg;
import com.nis.exceptions.MaatConvertException;
import com.nis.util.AsnCacheUtils;
import com.nis.util.Constants;
import com.nis.util.DictUtils;
import com.nis.web.controller.BaseController;
@@ -110,11 +112,10 @@ public class AsnIpController extends BaseController{
,String ids,Integer functionId
,RedirectAttributes redirectAttributes){
try{
asnIpCfgService.delete(functionId,isValid,ids);
asnIpCfgService.delete(isValid,ids);
addMessage(redirectAttributes,"delete_success");
}catch(Exception e){
logger.error("信息保存失败",e);
e.printStackTrace();
logger.error("Delete failed",e);
if(e instanceof MaatConvertException) {
addMessage(redirectAttributes,e.getMessage());
}else {
@@ -124,6 +125,25 @@ public class AsnIpController extends BaseController{
return "redirect:" + adminPath +"/basics/asn/list?functionId="+functionId;
}
/**
* ajax设置Name
* @param model
* @param ids
* @return
*/
@RequestMapping(value="ajaxGroupName",method=RequestMethod.POST)
@ResponseBody
public Map<String, String> ajaxGroupName(Model model,String ids){
AsnCacheUtils.init();
Map<String, String> groupMap=new HashMap<>();
for(String id:ids.split(",")) {
ConfigGroupInfo info=AsnCacheUtils.get(Long.parseLong(id));
if(info!=null) {
groupMap.put(id, info.getGroupName());
}
}
return groupMap;
}
@RequestMapping(value="ajaxServiceIdState",method=RequestMethod.POST)
@ResponseBody
public boolean ajaxServiceIdState(Model model,@RequestParam(required=true,value="serviceGroupIds")String serviceGroupIds){

View File

@@ -292,6 +292,7 @@ public class CommonController extends BaseController {
RedirectAttributes redirectAttributes,Integer functionId,Integer cfgRegionCode) {
this.importCfgTemplate(request, response, redirectAttributes, functionId, cfgRegionCode);
}
@Deprecated
public void _importFileTemplate(HttpServletRequest request,HttpServletResponse response,
RedirectAttributes redirectAttributes,Integer functionId,Integer cfgRegionCode,Class clazz) {
this.importCfgTemplate(request, response, redirectAttributes, functionId, cfgRegionCode,clazz);

View File

@@ -21,6 +21,7 @@ import com.nis.util.StringUtil;
import com.nis.web.controller.BaseController;
@Controller
@RequestMapping("${adminPath}/cfg/asnPolicy")
@Deprecated
public class AsnPolicyCfgController extends BaseController {
@RequestMapping(value = {"/list"})
public String list(Model model,HttpServletRequest request
@@ -76,29 +77,29 @@ public class AsnPolicyCfgController extends BaseController {
asnPolicyCfgService.delete(functionId, isValid, ids);
return "redirect:" + adminPath +"/cfg/asnPolicy/list?functionId="+functionId;
}
@RequestMapping(value = {"/audit"})
@RequiresPermissions(value={"asn:policy:confirm"})
public String audit(Integer isAudit,Integer isValid,String ids
,Integer functionId, RedirectAttributes redirectAttributes) {
if(!StringUtil.isEmpty(ids)){
String[] idArray = ids.split(",");
Date auditTime=new Date();
for(String id :idArray){
try {
asnPolicyCfgService.audit(isAudit,isValid,functionId,id,auditTime);
} catch (MaatConvertException e) {
e.printStackTrace();
logger.error("dns fake ip配置下发失败"+e.getMessage());
addMessage(redirectAttributes,"error","request_service_failed");
} catch (Exception e) {
e.printStackTrace();
logger.error("dns fake ip配置下发失败"+e.getMessage());
addMessage(redirectAttributes,"error","audit_failed");
}
}
}
return "redirect:" + adminPath +"/cfg/asnPolicy/list?functionId="+functionId;
}
// @RequestMapping(value = {"/audit"})
// @RequiresPermissions(value={"asn:policy:confirm"})
// public String audit(Integer isAudit,Integer isValid,String ids
// ,Integer functionId, RedirectAttributes redirectAttributes) {
// if(!StringUtil.isEmpty(ids)){
// String[] idArray = ids.split(",");
// Date auditTime=new Date();
// for(String id :idArray){
// try {
// asnPolicyCfgService.audit(isAudit,isValid,functionId,id,auditTime);
// } catch (MaatConvertException e) {
// e.printStackTrace();
// logger.error("dns fake ip配置下发失败"+e.getMessage());
// addMessage(redirectAttributes,"error","request_service_failed");
// } catch (Exception e) {
// e.printStackTrace();
// logger.error("dns fake ip配置下发失败"+e.getMessage());
// addMessage(redirectAttributes,"error","audit_failed");
// }
//
// }
//
// }
// return "redirect:" + adminPath +"/cfg/asnPolicy/list?functionId="+functionId;
// }
}

View File

@@ -418,6 +418,7 @@ public class WebsiteController extends BaseController{
}
return "redirect:" + adminPath +"/ntc/website/dnsList?functionId="+functionId;
}
@Deprecated
//下载导入模板
@RequestMapping(value = "import/template")
public void importFileTemplate(HttpServletRequest request,HttpServletResponse response,

View File

@@ -5,13 +5,14 @@ import java.util.List;
import org.apache.ibatis.annotations.Param;
import com.nis.domain.basics.AsnIpCfg;
import com.nis.domain.specific.ConfigGroupInfo;
import com.nis.domain.basics.Varibles;
import com.nis.web.dao.CrudDao;
import com.nis.web.dao.MyBatisDao;
@MyBatisDao
public interface AsnIpCfgDao extends CrudDao<AsnIpCfg>{
public List<AsnIpCfg> findPage(AsnIpCfg cfg);
public void updateValid(@Param("isValid")Integer isValid,@Param("ids")String ids);
//public void updateValid(@Param("isValid")Integer isValid,@Param("ids")String ids);
public void delete(@Param("ids")String ids);
public void updateIssued(AsnIpCfg cfg);
public List<AsnIpCfg> getByIds(@Param("ids")String ids);
public List<Integer> hasGroupIds(@Param("ids")String ids);
@@ -19,7 +20,9 @@ public interface AsnIpCfgDao extends CrudDao<AsnIpCfg>{
// public List<ConfigGroupInfo> findPolicyGroupInfosByType(@Param("groupId")Integer groupId);
public List<Integer> findOtherIps(@Param("groupId")Integer groupId,@Param("cfgId")Integer cfgId);
public List<Integer> countValidIPs(@Param("groups")String groups,@Param("ids")String ids);
public ConfigGroupInfo getInfoByAsnNo(@Param("asnId")Long asnNo);
public List<AsnIpCfg> getByAsnGroup(@Param("groupId")long groupId,@Param("asnId")long asnNo);
public void deleteByAsnGroup(@Param("groupId")long groupId,@Param("asnId")long asnNo);
public List<AsnIpCfg> getByAsnNo(@Param("asnId")long asnNo);
public int deleteByAsnGroup(@Param("asnId")String asnNo);
public int insertBatch(List<AsnIpCfg> list);
public Varibles getVaribles(@Param("name")String name);
}

View File

@@ -35,14 +35,17 @@
<result column="cfg_region_code" property="cfgRegionCode" jdbcType="INTEGER" />
<result column="cfg_type" property="cfgType" jdbcType="VARCHAR" />
<result column="asn_ip_group" property="asnIpGroup" jdbcType="INTEGER" />
<result column="asn_ip_group_name" property="asnIpGroupName" jdbcType="VARCHAR" />
<!-- <result column="asn_ip_group_name" property="asnIpGroupName" jdbcType="VARCHAR" /> -->
<result column="user_region1" property="userRegion1" jdbcType="VARCHAR" />
<result column="user_region2" property="userRegion2" jdbcType="VARCHAR" />
<result column="user_region3" property="userRegion3" jdbcType="VARCHAR" />
<result column="user_region4" property="userRegion4" jdbcType="VARCHAR" />
<result column="user_region5" property="userRegion5" jdbcType="VARCHAR" />
</resultMap>
<resultMap id="varibleMap" type="com.nis.domain.basics.Varibles">
<result column="variable_name" property="variableName" jdbcType="VARCHAR" />
<result column="value" property="value" jdbcType="VARCHAR" />
</resultMap>
<sql id="columns">
r.cfg_id,r.cfg_desc,r.ip_type,r.src_ip_address,r.ip_pattern,r.port_pattern,r.src_port
,r.protocol,r.protocol_id,r.direction,r.cfg_type,r.action,r.dest_port,r.dest_ip_address
@@ -58,10 +61,10 @@
<include refid="columns"></include>
<trim prefix="," prefixOverrides=",">
,s.name as creator_name,e.name as editor_name,u.name as auditor_name
,asn.group_name as asn_ip_group_name
<!-- ,asn.group_name as asn_ip_group_name -->
</trim>
from asn_ip_cfg r
left join config_group_info asn on asn.group_id=r.asn_ip_group
<!-- left join config_group_info asn on asn.group_id=r.asn_ip_group -->
left join sys_user s on r.creator_id=s.id
left join sys_user e on r.editor_id=e.id
left join sys_user u on r.auditor_id=u.id
@@ -206,10 +209,10 @@
from asn_ip_cfg r
where r.cfg_id in (${ids}) and is_valid !=-1
</select>
<select id="getByAsnGroup" resultMap="asnIpCfgMap" parameterType="java.lang.Long" >
<select id="getByAsnNo" resultMap="asnIpCfgMap" parameterType="java.lang.Long" >
select
<include refid="columns"></include>
from asn_ip_cfg r where r.is_valid!=-1 and r.asn_ip_group=#{groupId} and r.user_region1=#{asnId}
from asn_ip_cfg r where r.is_valid!=-1 and r.user_region1=#{asnId}
</select>
<insert id="insert" parameterType="com.nis.domain.basics.AsnIpCfg" >
insert into asn_ip_cfg (
@@ -393,15 +396,18 @@
and cfg_id = #{cfgId,jdbcType=INTEGER}
</where>
</update>
<update id="updateValid" parameterType="com.nis.domain.basics.AsnIpCfg" >
<!-- <update id="updateValid" parameterType="com.nis.domain.basics.AsnIpCfg" >
update asn_ip_cfg set is_valid=#{isValid} where cfg_id in (${ids})
</update>
</update> -->
<!-- <update id="deleteByAsnGroup" parameterType="java.lang.Integer" >
update asn_ip_cfg set is_valid=-1 where asn_ip_group=#{groupId} and user_region1=#{asnId}
</update> -->
<delete id="deleteByAsnGroup" parameterType="java.lang.Long" >
delete from asn_ip_cfg where asn_ip_group=#{groupId} and user_region1=#{asnId}
<delete id="deleteByAsnGroup" parameterType="java.lang.String" >
delete from asn_ip_cfg where user_region1 in(${asnId}) limit 10000
</delete>
<update id="delete" parameterType="java.lang.String" >
delete from asn_ip_cfg where cfg_id in (${ids})
</update>
<select id="findOtherIps" resultType="java.lang.Integer" parameterType="java.lang.Integer">
select 1 from asn_ip_cfg where is_valid=1 and asn_ip_group=#{groupId} and cfg_id !=#{cfgId} limit 1
</select>
@@ -411,8 +417,55 @@
<select id="countValidIPs" resultType="java.lang.Integer" parameterType="java.lang.String">
select count(1) from asn_ip_cfg where is_valid !=-1 and asn_ip_group in(${groups}) and cfg_id not in(${ids}) GROUP BY asn_ip_group;
</select>
<select id="getInfoByAsnNo" resultType="com.nis.domain.specific.ConfigGroupInfo" parameterType="java.lang.Long">
select id,group_id,group_name,is_issued,insert_time,update_time,group_type,compile_id,asn_id
from config_group_info c where c.asn_id= #{asnId} and c.group_type=4
<select id="getVaribles" resultMap="varibleMap" parameterType="java.lang.String">
show VARIABLES like #{name}
</select>
<insert id="insertBatch">
INSERT INTO asn_ip_cfg
(CFG_DESC,ACTION,IS_VALID,IS_AUDIT,CREATOR_ID,CREATE_TIME,EDITOR_ID,EDIT_TIME,AUDITOR_ID,
AUDIT_TIME,SERVICE_ID,REQUEST_ID,region_id,IS_AREA_EFFECTIVE,CLASSIFY,ATTRIBUTE,LABLE,
AREA_EFFECTIVE_IDS,function_id,ip_type,src_ip_address,ip_pattern,port_pattern,src_port,
protocol,protocol_id,direction,dest_port,dest_ip_address,cfg_type,cfg_region_code,
asn_ip_group,user_region1,user_region2,user_region3,user_region4,user_region5)
VALUES
<foreach collection ="list" item="asnIp" separator =",">
(#{asnIp.cfgDesc,jdbcType=VARCHAR},
#{asnIp.action,jdbcType=INTEGER},
#{asnIp.isValid,jdbcType=INTEGER},
0,
#{asnIp.creatorId,jdbcType=INTEGER},
#{asnIp.createTime,jdbcType=TIMESTAMP},
#{asnIp.editorId,jdbcType=INTEGER},
#{asnIp.editTime,jdbcType=TIMESTAMP},
#{asnIp.auditorId,jdbcType=INTEGER},
#{asnIp.auditTime,jdbcType=TIMESTAMP},
#{asnIp.serviceId,jdbcType=INTEGER},
#{asnIp.requestId,jdbcType=INTEGER},
#{asnIp.regionId,jdbcType=INTEGER},
#{asnIp.isAreaEffective,jdbcType=INTEGER},
#{asnIp.classify,jdbcType=VARCHAR},
#{asnIp.attribute,jdbcType=VARCHAR},
#{asnIp.lable,jdbcType=VARCHAR},
#{asnIp.areaEffectiveIds,jdbcType=VARCHAR},
#{asnIp.functionId,jdbcType=INTEGER},
#{asnIp.ipType,jdbcType=INTEGER},
#{asnIp.srcIpAddress,jdbcType=VARCHAR},
#{asnIp.ipPattern,jdbcType=INTEGER},
#{asnIp.portPattern,jdbcType=INTEGER},
#{asnIp.srcPort,jdbcType=VARCHAR},
#{asnIp.protocol,jdbcType=INTEGER},
#{asnIp.protocolId,jdbcType=INTEGER},
#{asnIp.direction,jdbcType=INTEGER},
#{asnIp.destPort,jdbcType=VARCHAR},
#{asnIp.destIpAddress,jdbcType=VARCHAR},
#{asnIp.cfgType,jdbcType=VARCHAR},
#{asnIp.cfgRegionCode,jdbcType=INTEGER},
#{asnIp.asnIpGroup,jdbcType=INTEGER},
#{asnIp.userRegion1,jdbcType=VARCHAR},
#{asnIp.userRegion2,jdbcType=VARCHAR},
#{asnIp.userRegion3,jdbcType=VARCHAR},
#{asnIp.userRegion4,jdbcType=VARCHAR},
#{asnIp.userRegion5,jdbcType=VARCHAR})
</foreach >
</insert>
</mapper>

View File

@@ -19,4 +19,5 @@ public interface PolicyGroupInfoDao extends CrudDao<PolicyGroupInfo> {
PolicyGroupInfo getInfoByAsnNo(PolicyGroupInfo policyGroupInfo);
List<PolicyGroupInfo> getHasAreaPolicyGroups(int groupType);
int insertBatch(List<PolicyGroupInfo> list);
}

View File

@@ -113,6 +113,30 @@
#{asnNo,jdbcType=INTEGER},
#{description,jdbcType=VARCHAR}
)
</insert>
<insert id="insertBatch">
insert into policy_group_info(
IS_VALID,
CREATOR_ID,
CREATE_TIME,
GROUP_NAME,
GROUP_TYPE,
SERVICE_GROUP_ID,
ASN_NO,
DESCRIPTION
)values
<foreach collection ="list" item="info" separator =",">
(
1,
#{info.creatorId,jdbcType=INTEGER},
#{info.createTime,jdbcType=TIMESTAMP},
#{info.groupName,jdbcType=VARCHAR},
#{info.groupType,jdbcType=INTEGER},
#{info.serviceGroupId,jdbcType=INTEGER},
#{info.asnNo,jdbcType=INTEGER},
#{info.description,jdbcType=VARCHAR}
)
</foreach>
</insert>
<update id="update" parameterType="com.nis.domain.basics.PolicyGroupInfo" >
update policy_group_info

View File

@@ -0,0 +1,22 @@
package com.nis.web.dao.specific;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import org.springframework.cache.annotation.Cacheable;
import com.nis.domain.specific.ConfigGroupInfo;
import com.nis.web.dao.CrudDao;
import com.nis.web.dao.MyBatisDao;
@MyBatisDao
public interface ConfigGroupInfoDao extends CrudDao<ConfigGroupInfo>{
List<ConfigGroupInfo> findAllList(int groupType);
void insertConfigGroupInfo(ConfigGroupInfo entity);
int insertBatch(List<ConfigGroupInfo> list);
void updateConfigGroupInfobyGroupId(ConfigGroupInfo entity);
ConfigGroupInfo getConfigGroupInfoByGroupId(Integer groupId);
@Cacheable(value="asnNoCache",key="#asnNo")
ConfigGroupInfo getInfoByAsnNo(@Param("asnId")Long asnNo);
Integer getIssuedConfigGroupInfoByGroupIds(@Param("groupIds")String groupIds);
Long getCountByType(@Param("groupType")Integer groupType);
}

View File

@@ -0,0 +1,64 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.nis.web.dao.specific.ConfigGroupInfoDao">
<resultMap id="configGroupInfoMap" type="com.nis.domain.specific.ConfigGroupInfo">
<id column="id" property="id" jdbcType="BIGINT" />
<result column="group_id" property="groupId" jdbcType="BIGINT" />
<result column="group_name" property="groupName" jdbcType="VARCHAR" />
<result column="is_issued" property="isIssued" jdbcType="INTEGER" />
<result column="insert_time" property="insertTime" jdbcType="TIMESTAMP" />
<result column="update_time" property="updateTime" jdbcType="TIMESTAMP" />
<result column="group_type" property="groupType" jdbcType="INTEGER" />
<result column="compile_id" property="compileId" jdbcType="INTEGER" />
<result column="asn_id" property="asnId" jdbcType="BIGINT" />
</resultMap>
<sql id="columns">
id,group_id,group_name,is_issued,insert_time,update_time,group_type,compile_id,asn_id
</sql>
<select id="findAllList" resultMap="configGroupInfoMap">
select
<include refid="columns"></include>
from config_group_info
where group_type =#{groupType}
</select>
<!-- 新增配置分组信息 -->
<insert id="insertConfigGroupInfo" parameterType="com.nis.domain.specific.ConfigGroupInfo" useGeneratedKeys="true">
insert into config_group_info (id,group_id,group_name,is_issued,insert_time,group_type,compile_id,asn_id)
values(#{id},#{groupId},#{groupName},#{isIssued},now(),#{groupType},#{compileId},#{asnId})
</insert>
<insert id="insertBatch">
insert into config_group_info (id,group_id,group_name,is_issued,insert_time,group_type,compile_id,asn_id)
values
<foreach collection ="list" item="info" separator =",">
(#{info.id},#{info.groupId},#{info.groupName},#{info.isIssued},now(),#{info.groupType},#{info.compileId},#{info.asnId})
</foreach>
</insert>
<!-- 修改配置分组状态信息 -->
<update id="updateConfigGroupInfobyGroupId" parameterType="com.nis.domain.specific.ConfigGroupInfo">
UPDATE config_group_info set is_issued = #{isIssued},update_time=now()
<if test="compileId != null and compileId !='' ">
,compile_id= #{compileId}
</if>
where group_id = #{groupId}
</update>
<select id="getInfoByAsnNo" resultType="com.nis.domain.specific.ConfigGroupInfo" parameterType="java.lang.Long">
select id,group_id,group_name,is_issued,insert_time,update_time,group_type,compile_id,asn_id
from config_group_info c where c.asn_id= #{asnId} and c.group_type=4
</select>
<!-- 根据groupId查出配置分组信息 -->
<select id="getConfigGroupInfoByGroupId" resultType="com.nis.domain.specific.ConfigGroupInfo" parameterType="java.lang.Integer">
select id,group_id,group_name,is_issued,insert_time,update_time,group_type,compile_id,asn_id
from config_group_info where group_id= #{groupId}
</select>
<!-- <select id="findPolicyGroupInfosByType" resultType="com.nis.domain.specific.ConfigGroupInfo" parameterType="java.lang.Integer">
select id,group_id,group_name,is_issued,insert_time,update_time,group_type,compile_id,asn_id
from config_group_info c where c.group_type= #{groupType}
</select> -->
<select id="getIssuedConfigGroupInfoByGroupIds" resultType="java.lang.Integer" parameterType="java.lang.String">
select count(1) from config_group_info c where c.group_id in(${groupIds}) and is_issued=1
</select>
<select id="getCountByType" resultType="java.lang.Long" parameterType="java.lang.Integer">
select count(1) from config_group_info c where c.group_type=${groupType}
</select>
</mapper>

View File

@@ -3,6 +3,8 @@ package com.nis.web.dao.specific;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import com.nis.domain.specific.ConfigGroupInfo;
import com.nis.domain.specific.SpecificServiceCfg;
@@ -42,14 +44,6 @@ public interface SpecificServiceCfgDao extends CrudDao<SpecificServiceCfg> {
* @return
*/
List<SpecificServiceCfg> getChildrenById(Integer specServiceId);
ConfigGroupInfo getConfigGroupInfoByGroupId(Integer groupId);
ConfigGroupInfo findPolicyGroupInfosByType(@Param("groupType")Integer groupType);
Integer getIssuedConfigGroupInfoByGroupIds(@Param("groupIds")String groupIds);
Integer insertConfigGroupInfo(ConfigGroupInfo entity);
Integer updateConfigGroupInfobyGroupId(ConfigGroupInfo entity);
Integer getParentType(Integer specServiceId);
Integer getParentCode(Integer specServiceId);
SpecificServiceCfg getRepeat(@Param("specServiceCode")Integer code, @Param("cfgType")Integer cfgType,@Param("parentId")Integer parentId);

View File

@@ -213,32 +213,4 @@
<select id="getChildrenById" resultMap="CFGResultMap" parameterType="java.lang.Integer">
SELECT * FROM specific_service_cfg s WHERE s.is_valid = 1 and s.parent_id = #{specServiceId}
</select>
<!-- 根据groupId查出配置分组信息 -->
<select id="getConfigGroupInfoByGroupId" resultType="com.nis.domain.specific.ConfigGroupInfo" parameterType="java.lang.Integer">
select id,group_id,group_name,is_issued,insert_time,update_time,group_type,compile_id,asn_id
from config_group_info c where c.group_id= #{groupId}
</select>
<select id="getIssuedConfigGroupInfoByGroupIds" resultType="java.lang.Integer" parameterType="java.lang.String">
select count(1) from config_group_info c where c.group_id in(${groupIds}) and is_issued=1
</select>
<!-- 修改配置分组状态信息 -->
<update id="updateConfigGroupInfobyGroupId" parameterType="com.nis.domain.specific.ConfigGroupInfo">
UPDATE config_group_info set is_issued = #{isIssued},update_time=now()
<if test="compileId != null and compileId !='' ">
,compile_id= #{compileId}
</if>
where group_id = #{groupId}
</update>
<!-- 新增配置分组信息 -->
<insert id="insertConfigGroupInfo" parameterType="com.nis.domain.specific.ConfigGroupInfo" useGeneratedKeys="true">
insert into config_group_info (id,group_id,group_name,is_issued,insert_time,group_type,compile_id,asn_id)
values(#{id},#{groupId},#{groupName},#{isIssued},now(),#{groupType},#{compileId},#{asnId})
</insert>
<select id="findPolicyGroupInfosByType" resultType="com.nis.domain.specific.ConfigGroupInfo" parameterType="java.lang.Integer">
select id,group_id,group_name,is_issued,insert_time,update_time,group_type,compile_id,asn_id
from config_group_info c where c.group_type= #{groupType}
</select>
</mapper>

View File

@@ -1092,12 +1092,16 @@ public abstract class BaseService {
}
//asn IP 复用转换
public List<IpCfg> groupReuseCfgAddRemoveConvert(List<? extends BaseCfg<?>> ipCfgList,Integer isValid,Integer groupId) {
logger.warn("convert data start");
long start=System.currentTimeMillis();
Date opTime=new Date();
List<IpCfg> maatIpList=new ArrayList<>();
if(ipCfgList.size()>0) {
//只用一次instanceof,取代循环中每次都用一次instanceof
if(ipCfgList.get(0) instanceof AsnIpCfg) {
for(BaseCfg<?> _cfg:ipCfgList) {
IpCfg cfg = new IpCfg();
BaseIpCfg baseIpCfg = new BaseIpCfg();
if(_cfg instanceof AsnIpCfg) {
AsnIpCfg asnIpCfg=(AsnIpCfg)_cfg;
BeanUtils.copyProperties(asnIpCfg, baseIpCfg);
BeanUtils.copyProperties(baseIpCfg, cfg);
@@ -1105,7 +1109,15 @@ public abstract class BaseService {
cfg.setRegionId(asnIpCfg.getRegionId());
String userRegion = "ASN_ID=" + asnIpCfg.getUserRegion1();
cfg.setUserRegion(userRegion);
}else if(_cfg instanceof AppIpCfg) {
cfg.setIsValid(isValid);
cfg.setAuditTime(opTime);
List<IpCfg> cfgs = ipConvert(cfg,baseIpCfg);
maatIpList.addAll(cfgs);
}
}else if(ipCfgList.get(0) instanceof AppIpCfg) {
for(BaseCfg<?> _cfg:ipCfgList) {
IpCfg cfg = new IpCfg();
BaseIpCfg baseIpCfg = new BaseIpCfg();
AppIpCfg appIpCfg=(AppIpCfg)_cfg;
BeanUtils.copyProperties(appIpCfg, baseIpCfg);
BeanUtils.copyProperties(baseIpCfg, cfg);
@@ -1113,12 +1125,15 @@ public abstract class BaseService {
cfg.setRegionId(Integer.parseInt(appIpCfg.getUserRegion1()));
String userRegion = "APP_ID=" + appIpCfg.getAppCode();
cfg.setUserRegion(userRegion);
}
cfg.setIsValid(isValid);
cfg.setAuditTime(opTime);
List<IpCfg> cfgs = ipConvert(cfg,baseIpCfg);
maatIpList.addAll(cfgs);
}
}
}
long end=System.currentTimeMillis();
logger.warn("convert data finish,cost:"+(end-start));
return maatIpList;
}
}

View File

@@ -105,10 +105,16 @@ public abstract class CrudService<D extends CrudDao<T>, T extends BaseEntity<T>>
SqlSessionFactory sqlSessionFactory=SpringContextHolder.getBean(SqlSessionFactory.class);
SqlSession batchSqlSession = null;
try{
// int batchSize=1000;
batchSqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, false);
for(int index = 0; index < data.size();index++){
T t = data.get(index);
((CrudDao<T>) batchSqlSession.getMapper(mClass)).insert(t);
// if(index>0&&index%batchSize==0) {
// batchSqlSession.commit();
// batchSqlSession.clearCache();
// logger.warn("session commit");
// }
}
batchSqlSession.commit();
}finally {

View File

@@ -1,10 +1,14 @@
package com.nis.web.service.basics;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
@@ -14,9 +18,9 @@ import org.springframework.transaction.annotation.Transactional;
import com.beust.jcommander.internal.Lists;
import com.nis.domain.Page;
import com.nis.domain.SysDataDictionaryItem;
import com.nis.domain.basics.AsnIpCfg;
import com.nis.domain.basics.PolicyGroupInfo;
import com.nis.domain.basics.Varibles;
import com.nis.domain.configuration.CfgIndexInfo;
import com.nis.domain.maat.GroupReuseAddBean;
import com.nis.domain.maat.GroupReuseCfg;
@@ -26,21 +30,23 @@ import com.nis.domain.maat.MaatCfg.StringCfg;
import com.nis.domain.maat.ToMaatResult;
import com.nis.domain.specific.ConfigGroupInfo;
import com.nis.exceptions.MaatConvertException;
import com.nis.util.AsnCacheUtils;
import com.nis.util.ConfigServiceUtil;
import com.nis.util.Constants;
import com.nis.util.DictUtils;
import com.nis.web.dao.CrudDao;
import com.nis.web.dao.basics.AsnIpCfgDao;
import com.nis.web.dao.basics.PolicyGroupInfoDao;
import com.nis.web.dao.specific.SpecificServiceCfgDao;
import com.nis.web.dao.specific.ConfigGroupInfoDao;
import com.nis.web.security.UserUtils;
import com.nis.web.service.CrudService;
@Service
public class AsnIpCfgService extends CrudService<CrudDao<AsnIpCfg>, AsnIpCfg> {
@Autowired
private AsnIpCfgDao asnIpCfgDao;
// @Autowired
// private SpecificServiceCfgDao specificServiceCfgDao;
@Autowired
private SpecificServiceCfgDao specificServiceCfgDao;
private ConfigGroupInfoDao configGroupInfoDao;
@Autowired
private PolicyGroupInfoDao policyGroupInfoDao;
/**
@@ -58,9 +64,38 @@ public class AsnIpCfgService extends CrudService<CrudDao<AsnIpCfg>, AsnIpCfg> {
public AsnIpCfg get(Long id ) {
return asnIpCfgDao.get(id);
}
// public void save(List<AsnIpCfg> entitys){
// this.saveBatch(entitys, AsnIpCfgDao.class);
// }
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
public void save(List<AsnIpCfg> entitys) {
this.saveBatch(entitys, AsnIpCfgDao.class);
logger.warn("Start to save IP");
long start=System.currentTimeMillis();
int len=0;
List<AsnIpCfg> tempList=Lists.newArrayList();
Varibles maxPacket=asnIpCfgDao.getVaribles("max_allowed_packet");
for(AsnIpCfg asnIpCfg:entitys) {
int tempLen=asnIpCfg.toString().getBytes(Charset.forName("UTF-8")).length;
if((len+tempLen)<maxPacket.getValue().longValue()) {
tempList.add(asnIpCfg);
len+=tempLen;
}else {
logger.warn("save ip size:"+tempList.size());
asnIpCfgDao.insertBatch(tempList);
tempList.clear();
tempList.add(asnIpCfg);
len=tempLen;
}
}
if(tempList.size()>0) {
logger.warn("save ip size:"+tempList.size());
asnIpCfgDao.insertBatch(tempList);
tempList.clear();
}
// entitys.clear();
long end=System.currentTimeMillis();
logger.warn("Save IP finish,cost:"+(end-start));
}
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
public void update(AsnIpCfg entity){
@@ -70,7 +105,7 @@ public class AsnIpCfgService extends CrudService<CrudDao<AsnIpCfg>, AsnIpCfg> {
if(entity.getAsnIpGroup()==null) {
throw new RuntimeException("asn group name not found!");
}
ConfigGroupInfo groupInfo=specificServiceCfgDao.getConfigGroupInfoByGroupId(entity.getAsnIpGroup());
ConfigGroupInfo groupInfo=configGroupInfoDao.getConfigGroupInfoByGroupId(entity.getAsnIpGroup());
if(groupInfo.getIsIssued()==0) {//未下发,可修改
asnIpCfgDao.update(entity);
}else {
@@ -79,53 +114,170 @@ public class AsnIpCfgService extends CrudService<CrudDao<AsnIpCfg>, AsnIpCfg> {
}
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
public void saveAsnIpBatch(Map<String,List<AsnIpCfg>> cfgs,int total) {
//需要通过删除域接口删除的ip集合
List<AsnIpCfg> toDelAsnIpCfgs=Lists.newArrayList();
//需要本地保存的IP集合
List<AsnIpCfg> toSaveAsnIpCfgs=Lists.newArrayList();
public void processGroup(Map<Long,Integer> asnNoMap){
logger.warn("Start to save group");
long start=System.currentTimeMillis();
List<PolicyGroupInfo> policyGroupInfos=Lists.newArrayList();
List<ConfigGroupInfo> configGroupInfoS=Lists.newArrayList();
Date createTime=new Date();
int len=0,len1=0;
Varibles maxPacket=asnIpCfgDao.getVaribles("max_allowed_packet");
for(Entry<Long, Integer> e:asnNoMap.entrySet()) {
PolicyGroupInfo info=new PolicyGroupInfo();
info.setAsnNo(e.getKey());
info.setDescription("Create by import excel");
info.setGroupName("Import"+e.getKey());
info.setGroupType(4);
info.setServiceGroupId(asnNoMap.get(e.getKey()));
info.setIsValid(1);
info.setCreatorId(UserUtils.getUser().getId());
info.setCreateTime(createTime);
int tempLen=info.toString().getBytes(Charset.forName("UTF-8")).length;
if((len+tempLen)<maxPacket.getValue().longValue()) {
policyGroupInfos.add(info);
len+=tempLen;
}else {
policyGroupInfoDao.insertBatch(policyGroupInfos);
policyGroupInfos.clear();
policyGroupInfos.add(info);
len=tempLen;
}
ConfigGroupInfo group=new ConfigGroupInfo();
group.setGroupId(info.getServiceGroupId());
group.setGroupName(info.getGroupName());
group.setIsIssued(0);
group.setGroupType(info.getGroupType());
group.setAsnId(info.getAsnNo());
int tempLen1=group.toString().getBytes(Charset.forName("UTF-8")).length;
if((len1+tempLen1)<maxPacket.getValue().longValue()) {
configGroupInfoS.add(group);
len1+=tempLen1;
}else {
configGroupInfoDao.insertBatch(configGroupInfoS);
configGroupInfoS.clear();
configGroupInfoS.add(group);
len1=tempLen1;
}
}
if(policyGroupInfos.size()>0) {
policyGroupInfoDao.insertBatch(policyGroupInfos);
policyGroupInfos.clear();
}
if(configGroupInfoS.size()>0) {
configGroupInfoDao.insertBatch(configGroupInfoS);
configGroupInfoS.clear();
}
//刷新缓存
AsnCacheUtils.init();
long end=System.currentTimeMillis();
logger.warn("Save group finish,cost:"+(end-start));
}
public void deleteIps(Map<Long,Integer> asnNoMap){
List<AsnIpCfg> toDelAndSendAsnIpCfgs=Lists.newArrayList();
List<Long> asnIds=Lists.newArrayList(asnNoMap.size());
for(Entry<Long, Integer> e:asnNoMap.entrySet()) {
ConfigGroupInfo configGroupInfo=AsnCacheUtils.get(e.getKey());
if(configGroupInfo==null) {
configGroupInfo=this.getConfigGroupInfoByAsnNo(e.getKey());
}
if(configGroupInfo.getIsIssued()==1) {//已下发
List<AsnIpCfg> _toDelAsnIpCfgs=this.getByAsnNo(configGroupInfo.getAsnId());
toDelAndSendAsnIpCfgs.addAll(_toDelAsnIpCfgs);
}else {
asnIds.add(e.getKey());
}
}
if(asnIds.size()>0) {
this.deleteByAsnNo(asnIds);
}
if(toDelAndSendAsnIpCfgs.size()>0) {
int pointsDataLimit = Constants.MAAT_JSON_SEND_SIZE;//限制条数
Integer size = toDelAndSendAsnIpCfgs.size();
//判断是否有必要分批
if(pointsDataLimit<size){
int part = size/pointsDataLimit;//分批数
for (int i = 0; i < part; i++) {
//pointsDataLimit条
List<AsnIpCfg> listPage = toDelAndSendAsnIpCfgs.subList(0, pointsDataLimit);
delAndSend(listPage);
//剔除
toDelAndSendAsnIpCfgs.subList(0, pointsDataLimit).clear();
}
//最后剩下的
if(!toDelAndSendAsnIpCfgs.isEmpty()){
delAndSend(toDelAndSendAsnIpCfgs);
}
}else {
delAndSend(toDelAndSendAsnIpCfgs);
}
}
}
/**
* 根据Id 批量删除
* @param entities
*/
public void deleteByIdsBatch(List<AsnIpCfg> entities) {
StringBuilder sb=new StringBuilder();
for(AsnIpCfg ip:entities) {
sb.append(ip.getCfgId());
sb.append(",");
}
sb.deleteCharAt(sb.toString().lastIndexOf(","));
asnIpCfgDao.delete(sb.toString());
}
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
public void delAndSend(List<AsnIpCfg> entities) {
deleteByIdsBatch(entities);
asnIPRegionSendToMaat(entities,Constants.VALID_NO);
}
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
public void saveAsnIpBatch(List<AsnIpCfg> cfgs){
//需要通过新增域接口新增的ip集合
List<AsnIpCfg> toAddRegionAsnIpCfgs=Lists.newArrayList();
List<SysDataDictionaryItem> isImportAll=DictUtils.getDictList("IS_ASN_IP_IMPORT_ALL");
List<Integer> idList=ConfigServiceUtil.getId(3, total);
int ind=0;
for(Entry<String,List<AsnIpCfg>> entry:cfgs.entrySet()) {
Long asnNo=Long.parseLong(entry.getKey());
ConfigGroupInfo configGroupInfo=this.getConfigGroupInfoByAsnNo(asnNo);
if(configGroupInfo==null) {//不存在则新增
PolicyGroupInfo info=new PolicyGroupInfo();
info.setAsnNo(Long.parseLong(entry.getKey()));
info.setDescription("Create by import excel");
info.setGroupName("Import"+asnNo);
info.setGroupType(4);
configGroupInfo=this.saveAsnGroup(info);
}
for(AsnIpCfg cfg:entry.getValue()) {
cfg.setAsnIpGroup(configGroupInfo.getGroupId());
cfg.setRegionId(idList.get(ind));
if(configGroupInfo.getIsIssued()==0)
cfg.setIsValid(Constants.VALID_NO);
else {
cfg.setIsValid(Constants.VALID_YES);
logger.warn("process configGroupInfo and delete IP start");
long start=System.currentTimeMillis();
for(AsnIpCfg cfg:cfgs) {
if(Constants.VALID_YES==cfg.getIsValid().intValue()) {
toAddRegionAsnIpCfgs.add(cfg);
}
ind++;
}
if(isImportAll.get(0).getItemCode().equals("1")) {//全量下发,删除已有的
if(configGroupInfo.getIsIssued()==1) {//已下发
List<AsnIpCfg> _toDelAsnIpCfgs=this.getByAsnGroup(configGroupInfo.getGroupId(), configGroupInfo.getAsnId());
toDelAsnIpCfgs.addAll(_toDelAsnIpCfgs);
long end=System.currentTimeMillis();
logger.warn("process configGroupInfo and delete IP finish,cost:"+(end-start));
this.save(cfgs);
cfgs.clear();
splitAndSend(toAddRegionAsnIpCfgs,Constants.VALID_YES);
toAddRegionAsnIpCfgs.clear();
}
this.deleteByAsnGroup(configGroupInfo.getGroupId(), configGroupInfo.getAsnId());
/**
* 分割IP region分次下发
* @param asnIpCfgs
* @param valid
*/
public void splitAndSend(List<AsnIpCfg> asnIpCfgs,Integer valid){
if(asnIpCfgs!=null&&asnIpCfgs.size()>0) {
// List<AsnIpCfg> asnIpCfgs=Lists.newArrayList(list.size());
// asnIpCfgs.addAll(list);
int pointsDataLimit = Constants.MAAT_JSON_SEND_SIZE;//限制条数
Integer size = asnIpCfgs.size();
//判断是否有必要分批
if(pointsDataLimit<size){
int part = size/pointsDataLimit;//分批数
for (int i = 0; i < part; i++) {
//pointsDataLimit条
List<AsnIpCfg> listPage = asnIpCfgs.subList(0, pointsDataLimit);
asnIPRegionSendToMaat(listPage,valid);
//剔除
asnIpCfgs.subList(0, pointsDataLimit).clear();
}
toSaveAsnIpCfgs.addAll(entry.getValue());
//最后剩下的
if(!asnIpCfgs.isEmpty()){
asnIPRegionSendToMaat(asnIpCfgs,valid);
}
this.save(toSaveAsnIpCfgs);
if(toDelAsnIpCfgs.size()>0) {
asnIPRegionSendToMaat(toDelAsnIpCfgs,Constants.VALID_NO);
}else {
asnIPRegionSendToMaat(asnIpCfgs,valid);
}
if(toAddRegionAsnIpCfgs.size()>0) {
asnIPRegionSendToMaat(toAddRegionAsnIpCfgs,Constants.VALID_YES);
}
}
/**
@@ -151,7 +303,11 @@ public class AsnIpCfgService extends CrudService<CrudDao<AsnIpCfg>, AsnIpCfg> {
maatBean.setOpAction(Constants.INSERT_ACTION);
//调用服务接口下发配置数据
String json=gsonToJson(maatBean);
if(asnIpCfgs.size()<=100) {
logger.info("asn ip复用域新增配置下发配置参数"+json);
}else {
logger.info("asn ip复用域新增配置下发region条数"+asnIpCfgs.size());
}
//调用服务接口下发配置
ToMaatResult result =ConfigServiceUtil.postGroupReuseSources(json);
logger.info("asn ip复用域新增配置响应信息"+result.getMsg());
@@ -159,14 +315,32 @@ public class AsnIpCfgService extends CrudService<CrudDao<AsnIpCfg>, AsnIpCfg> {
maatBean.setOpAction(Constants.UPDATE_ACTION);
//调用服务接口下发配置数据
String json=gsonToJson(maatBean);
if(asnIpCfgs.size()<=100) {
logger.info("asn ip复用域删除配置下发配置参数"+json);
}else {
logger.info("asn ip复用域删除配置下发region条数"+asnIpCfgs.size());
}
//调用服务接口下发配置
ToMaatResult result = ConfigServiceUtil.put(json,3);
logger.info("asn ip复用域删除配置响应信息"+result.getMsg());
}
}
/**
* 批量保存asn PolicyGroupInfo
* @param entities
* @return
* @throws MaatConvertException
*/
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
public ConfigGroupInfo saveAsnGroup(PolicyGroupInfo entity) throws MaatConvertException{
public Map<Long,ConfigGroupInfo> saveAsnGroupBatch(List<PolicyGroupInfo> entities) throws MaatConvertException{
Map<Long,ConfigGroupInfo> configGroupInfoMap=new HashMap<>(entities.size());
List<Integer> groupIds= ConfigServiceUtil.getId(2,entities.size());
if(groupIds.size()!=entities.size()) {
throw new MaatConvertException("Get asn group id failed");
}
int ind=0;
for(PolicyGroupInfo entity:entities) {
entity.setIsValid(1);
ConfigGroupInfo group=new ConfigGroupInfo();
//新增
@@ -174,30 +348,30 @@ public class AsnIpCfgService extends CrudService<CrudDao<AsnIpCfg>, AsnIpCfg> {
entity.setCreatorId(UserUtils.getUser().getId());
entity.setCreateTime(createTime);
//asn类型从综合服务获取groupId
if(4==entity.getGroupType().intValue()) {
int serviceGroupId=0;
List<Integer> groupIds= ConfigServiceUtil.getId(2,1);
if(groupIds.size()>0) {
serviceGroupId=groupIds.get(0).intValue();
}else {
throw new MaatConvertException("Get asn group id failed");
if(4!=entity.getGroupType().intValue()) {
throw new RuntimeException("ConfigGroupInfo is not asn type 4!");
}
entity.setServiceGroupId(serviceGroupId);
entity.setServiceGroupId(groupIds.get(ind).intValue());
//新增协议分组
group.setGroupId(serviceGroupId);
group.setGroupId(groupIds.get(ind).intValue());
group.setGroupName(entity.getGroupName());
group.setIsIssued(0);
group.setGroupType(entity.getGroupType());
group.setAsnId(entity.getAsnNo());
specificServiceCfgDao.insertConfigGroupInfo(group);
policyGroupInfoDao.insert(entity);
configGroupInfoDao.insertConfigGroupInfo(group);
if(group.getGroupType().intValue()==4) {
AsnCacheUtils.put(entity.getAsnNo(), group);
}
return group;
policyGroupInfoDao.insert(entity);
configGroupInfoMap.put(group.getAsnId(), group);
ind++;
}
return configGroupInfoMap;
}
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
public void saveAsnIpCfg(CfgIndexInfo entity) {
Date createTime=new Date();
ConfigGroupInfo groupInfo=specificServiceCfgDao.getConfigGroupInfoByGroupId(entity.getAsnIpGroup().intValue());
ConfigGroupInfo groupInfo=configGroupInfoDao.getConfigGroupInfoByGroupId(entity.getAsnIpGroup().intValue());
if(groupInfo==null) {
throw new RuntimeException("ConfigGroupInfo is null!");
}
@@ -221,7 +395,7 @@ public class AsnIpCfgService extends CrudService<CrudDao<AsnIpCfg>, AsnIpCfg> {
}
}
this.save(entity.getAsnIpCfgs());
asnIPRegionSendToMaat(entity.getAsnIpCfgs(),Constants.VALID_YES);
splitAndSend(entity.getAsnIpCfgs(),Constants.VALID_YES);
}else {
if(entity.getAsnIpCfgs()!=null) {
for(AsnIpCfg cfg:entity.getAsnIpCfgs()) {
@@ -238,7 +412,7 @@ public class AsnIpCfgService extends CrudService<CrudDao<AsnIpCfg>, AsnIpCfg> {
}
}
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
public void delete(Integer functionId,Integer isValid,String ids) {
public void delete(Integer isValid,String ids) {
for(String id:ids.split(",")) {
Long.parseLong(id);
}
@@ -256,11 +430,10 @@ public class AsnIpCfgService extends CrudService<CrudDao<AsnIpCfg>, AsnIpCfg> {
}
}
}
if(issuedList.size()>0) {
asnIpCfgDao.delete(ids);
//已经下发过的,调用分组复用配置删除接口
asnIPRegionSendToMaat(issuedList,Constants.VALID_NO);
}
asnIpCfgDao.updateValid(isValid, ids);
splitAndSend(issuedList,Constants.VALID_NO);
}
// public List<ConfigGroupInfo> findPolicyGroupInfosByType(Integer groupId) {
// // TODO Auto-generated method stub
@@ -288,18 +461,65 @@ public class AsnIpCfgService extends CrudService<CrudDao<AsnIpCfg>, AsnIpCfg> {
return false;
}
public ConfigGroupInfo getConfigGroupInfoByAsnNo(Long asnNo) {
return asnIpCfgDao.getInfoByAsnNo(asnNo);
ConfigGroupInfo configGroupInfo=configGroupInfoDao.getInfoByAsnNo(asnNo);
AsnCacheUtils.put(asnNo, configGroupInfo);
return configGroupInfo;
}
public List<AsnIpCfg> getByAsnGroup(Integer groupId,Long asnNo) {
if(groupId==null||asnNo==null) {
public List<AsnIpCfg> getByAsnNo(Long asnNo) {
if(asnNo==null) {
throw new RuntimeException("groupId or asnNo is null!");
}
return asnIpCfgDao.getByAsnGroup(groupId.longValue(),asnNo.longValue());
return asnIpCfgDao.getByAsnNo(asnNo.longValue());
}
public void deleteByAsnGroup(Integer groupId,Long asnNo) {
if(groupId==null||asnNo==null) {
throw new RuntimeException("groupId or asnNo is null!");
// public void deleteByAsnGroup(Long asnNo) {
// if(asnNo==null) {
// throw new RuntimeException("asnNo is null!");
// }
// asnIpCfgDao.deleteByAsnGroup(asnNo.longValue());
// }
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
public void deleteByAsnNo(List<Long> asnNoList) {
int pointsDataLimit = 1000;//限制条数
Integer size = asnNoList.size();
if(pointsDataLimit<size){
int part = size/pointsDataLimit;//分批数
for (int i = 0; i < part; i++) {
List<Long> listPage = asnNoList.subList(0, pointsDataLimit);
StringBuilder asnNoStr=new StringBuilder();
for(Long asnNo:asnNoList) {
asnNoStr.append(asnNo);
asnNoStr.append(",");
}
int result=0;
do {
result=asnIpCfgDao.deleteByAsnGroup(asnNoStr.toString().substring(0,asnNoStr.toString().length()-1));
}while(result>0);
//剔除
asnNoList.subList(0, pointsDataLimit).clear();
}
if(!asnNoList.isEmpty()){
StringBuilder asnNoStr=new StringBuilder();
for(Long asnNo:asnNoList) {
asnNoStr.append(asnNo);
asnNoStr.append(",");
}
int result=0;
do {
result=asnIpCfgDao.deleteByAsnGroup(asnNoStr.toString().substring(0,asnNoStr.toString().length()-1));
}while(result>0);
asnNoList.clear();
}
}else {
StringBuilder asnNoStr=new StringBuilder();
for(Long asnNo:asnNoList) {
asnNoStr.append(asnNo);
asnNoStr.append(",");
}
int result=0;
do {
result=asnIpCfgDao.deleteByAsnGroup(asnNoStr.toString().substring(0,asnNoStr.toString().length()-1));
}while(result>0);
asnNoList.clear();
}
asnIpCfgDao.deleteByAsnGroup(groupId.longValue(),asnNo.longValue());
}
}

View File

@@ -11,10 +11,12 @@ import com.nis.domain.Page;
import com.nis.domain.basics.PolicyGroupInfo;
import com.nis.domain.specific.ConfigGroupInfo;
import com.nis.exceptions.MaatConvertException;
import com.nis.util.AsnCacheUtils;
import com.nis.util.ConfigServiceUtil;
import com.nis.util.StringUtil;
import com.nis.web.dao.basics.AsnIpCfgDao;
import com.nis.web.dao.basics.PolicyGroupInfoDao;
import com.nis.web.dao.specific.ConfigGroupInfoDao;
import com.nis.web.dao.specific.SpecificServiceCfgDao;
import com.nis.web.security.UserUtils;
import com.nis.web.service.BaseService;
@@ -25,7 +27,8 @@ public class PolicyGroupInfoService extends BaseService{
@Autowired
private PolicyGroupInfoDao policyGroupInfoDao;
@Autowired
private SpecificServiceCfgDao specificServiceCfgDao;
// private SpecificServiceCfgDao specificServiceCfgDao;
private ConfigGroupInfoDao configGroupInfoDao;
@Autowired
private AsnIpCfgDao asnIpCfgDao;
@@ -86,7 +89,7 @@ public class PolicyGroupInfoService extends BaseService{
}
entity.setServiceGroupId(serviceGroupId);
//新增协议分组
ConfigGroupInfo group = specificServiceCfgDao.getConfigGroupInfoByGroupId(serviceGroupId);
ConfigGroupInfo group = configGroupInfoDao.getConfigGroupInfoByGroupId(serviceGroupId);
if(group==null){
group = new ConfigGroupInfo();
group.setGroupId(serviceGroupId);
@@ -94,7 +97,11 @@ public class PolicyGroupInfoService extends BaseService{
group.setIsIssued(0);
group.setGroupType(entity.getGroupType());
group.setAsnId(entity.getAsnNo());
specificServiceCfgDao.insertConfigGroupInfo(group);
configGroupInfoDao.insertConfigGroupInfo(group);
if(group.getGroupType().intValue()==4) {
AsnCacheUtils.put(entity.getAsnNo(), group);
}
}
}
policyGroupInfoDao.insert(entity);
@@ -126,7 +133,7 @@ public class PolicyGroupInfoService extends BaseService{
for(String groupId:groupIds.split(",")) {
Integer.parseInt(groupId);
}
Integer count=specificServiceCfgDao.getIssuedConfigGroupInfoByGroupIds(groupIds);
Integer count=configGroupInfoDao.getIssuedConfigGroupInfoByGroupIds(groupIds);
if(count>0) return true;
return false;
}

View File

@@ -52,6 +52,7 @@ import com.nis.web.dao.configuration.AppCfgDao;
import com.nis.web.dao.configuration.AreaIpCfgDao;
import com.nis.web.dao.configuration.IpCfgDao;
import com.nis.web.dao.configuration.StringCfgDao;
import com.nis.web.dao.specific.ConfigGroupInfoDao;
import com.nis.web.dao.specific.SpecificServiceCfgDao;
import com.nis.web.security.UserUtils;
import com.nis.web.service.BaseService;
@@ -75,6 +76,8 @@ public class AppCfgService extends BaseService {
protected IpCfgDao ipCfgDao;
@Autowired
protected SpecificServiceCfgDao specificServiceCfgDao;
@Autowired
protected ConfigGroupInfoDao configGroupInfoDao;
public Page<AppPolicyCfg> findAppPolicyList(Page<AppPolicyCfg> page, AppPolicyCfg entity) {
entity.getSqlMap().put("dsf", configScopeFilter(entity.getCurrentUser(), "r"));
@@ -322,8 +325,8 @@ public class AppCfgService extends BaseService {
* @throws Exception
*/
@Transactional(readOnly = false, rollbackFor = RuntimeException.class)
public void saveAppIpCfg(List<BaseIpCfg> cfgs,SpecificServiceCfg specificServiceCfg) throws Exception {
ConfigGroupInfo configGroupInfo=specificServiceCfgDao.getConfigGroupInfoByGroupId(specificServiceCfg.getGroupId());
public void saveAppIpCfg(List<BaseIpCfg> cfgs,SpecificServiceCfg specificServiceCfg){
ConfigGroupInfo configGroupInfo=configGroupInfoDao.getConfigGroupInfoByGroupId(specificServiceCfg.getGroupId());
if(configGroupInfo==null) {//一般特定服务的组号是新增之后就有的,不会进入这一步。
Integer groupId = ConfigServiceUtil.getId(2, 1).get(0);
Integer compileId=ConfigServiceUtil.getId(1, 1).get(0);
@@ -334,7 +337,7 @@ public class AppCfgService extends BaseService {
configGroupInfo.setIsIssued(0);
configGroupInfo.setGroupType(1);
configGroupInfo.setCompileId(compileId);
specificServiceCfgDao.insertConfigGroupInfo(configGroupInfo);
configGroupInfoDao.insertConfigGroupInfo(configGroupInfo);
//更新group_id
specificServiceCfg.setOpTime(new Date());
specificServiceCfgDao.update(specificServiceCfg);
@@ -355,7 +358,7 @@ public class AppCfgService extends BaseService {
if (entity.getCfgId() == null) {
SpecificServiceCfg specificServiceCfg=specificServiceCfgDao.getBySpecServiceId(entity.getSpecServiceId());
ConfigGroupInfo configGroupInfo=specificServiceCfgDao.getConfigGroupInfoByGroupId(specificServiceCfg.getGroupId());
ConfigGroupInfo configGroupInfo=configGroupInfoDao.getConfigGroupInfoByGroupId(specificServiceCfg.getGroupId());
if(configGroupInfo==null) {//一般特定服务的组号是新增之后就有的,不会进入这一步。
Integer groupId = ConfigServiceUtil.getId(2, 1).get(0);
Integer compileId=ConfigServiceUtil.getId(1, 1).get(0);
@@ -366,7 +369,7 @@ public class AppCfgService extends BaseService {
configGroupInfo.setIsIssued(0);
configGroupInfo.setGroupType(1);
configGroupInfo.setCompileId(compileId);
specificServiceCfgDao.insertConfigGroupInfo(configGroupInfo);
configGroupInfoDao.insertConfigGroupInfo(configGroupInfo);
//更新group_id
specificServiceCfg.setOpTime(new Date());
specificServiceCfgDao.update(specificServiceCfg);
@@ -408,7 +411,7 @@ public class AppCfgService extends BaseService {
//app ip的编译ID存于configGroupInfo中
if((configGroupInfo.getCompileId()==null)||(compileId.intValue()!=configGroupInfo.getCompileId().intValue())) {
configGroupInfo.setCompileId(entity.getCompileId());
specificServiceCfgDao.updateConfigGroupInfobyGroupId(configGroupInfo);
configGroupInfoDao.updateConfigGroupInfobyGroupId(configGroupInfo);
}
// 保存区域IP信息
if (entity.getAreaCfg() != null) {
@@ -514,7 +517,7 @@ public class AppCfgService extends BaseService {
}
@Transactional(readOnly = false, rollbackFor = RuntimeException.class)
public void saveAppDomainCfg(List<BaseStringCfg<?>> cfgs) throws Exception {
public void saveAppDomainCfg(List<BaseStringCfg<?>> cfgs){
for(BaseStringCfg cfg:cfgs) {
AppDomainCfg entity=new AppDomainCfg();
BeanUtils.copyProperties(cfg, entity);
@@ -1169,7 +1172,7 @@ public class AppCfgService extends BaseService {
Integer specServiceId= entitys.get(0).getSpecServiceId();
SpecificServiceCfg specificServiceCfg=specificServiceCfgDao.getBySpecServiceId(specServiceId);
//String businessType=specificServiceCfg.getBusinessType();
ConfigGroupInfo configGroupInfo=specificServiceCfgDao.getConfigGroupInfoByGroupId(specificServiceCfg.getGroupId());
ConfigGroupInfo configGroupInfo=configGroupInfoDao.getConfigGroupInfoByGroupId(specificServiceCfg.getGroupId());
if(configGroupInfo==null) {
Integer groupId = ConfigServiceUtil.getId(2, 1).get(0);
specificServiceCfg.setGroupId(groupId);
@@ -1179,7 +1182,7 @@ public class AppCfgService extends BaseService {
configGroupInfo.setIsIssued(0);
configGroupInfo.setCompileId(entitys.get(0).getCompileId());
configGroupInfo.setGroupType(1);
specificServiceCfgDao.insertConfigGroupInfo(configGroupInfo);
configGroupInfoDao.insertConfigGroupInfo(configGroupInfo);
//更新group_id
specificServiceCfg.setOpTime(new Date());
specificServiceCfgDao.update(specificServiceCfg);
@@ -1226,7 +1229,7 @@ public class AppCfgService extends BaseService {
logger.info("app协议IP配置下发响应信息" + result.getMsg());
configGroupInfo.setIsIssued(1);
configGroupInfo.setUpdateTime(new Date());
specificServiceCfgDao.updateConfigGroupInfobyGroupId(configGroupInfo);
configGroupInfoDao.updateConfigGroupInfobyGroupId(configGroupInfo);
}else if(configGroupInfo.getIsIssued()==1) {//已经下发,分组复用下发
GroupReuseAddBean maatBean = new GroupReuseAddBean();
List<GroupReuseCfg> groupReuseList=new ArrayList<>();

View File

@@ -26,6 +26,7 @@ import com.nis.util.ConfigServiceUtil;
import com.nis.util.Constants;
import com.nis.web.dao.basics.AsnIpCfgDao;
import com.nis.web.dao.configuration.AsnPolicyCfgDao;
import com.nis.web.dao.specific.ConfigGroupInfoDao;
import com.nis.web.dao.specific.SpecificServiceCfgDao;
import com.nis.web.security.UserUtils;
import com.nis.web.service.BaseService;
@@ -36,7 +37,8 @@ public class AsnPolicyCfgService extends BaseService {
@Autowired
private AsnIpCfgDao asnIpCfgDao;
@Autowired
private SpecificServiceCfgDao specificServiceCfgDao;
//private SpecificServiceCfgDao specificServiceCfgDao;
private ConfigGroupInfoDao configGroupInfoDao;
/**
* @param page
* @param entity
@@ -96,124 +98,125 @@ public class AsnPolicyCfgService extends BaseService {
* @param ids cfgId
* @param functionId
*/
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
public void audit(Integer isAudit,Integer isValid,Integer functionId,String id,Date auditTime){
CfgIndexInfo entity=asnPolicyCfgDao.get(Long.valueOf(id));
entity.setIsAudit(isAudit);
entity.setIsValid(isValid);
entity.setAuditorId(UserUtils.getUser().getId());
entity.setAuditTime(auditTime);
asnPolicyCfgDao.updateCfgIndexInfo(entity);
ToMaatBean maatBean = new ToMaatBean();
MaatCfg maatCfg = new MaatCfg();
List<MaatCfg> configCompileList = new ArrayList<>();
List<GroupCfg> groupRelationList = new ArrayList<>();
List<IpCfg> ipRegionList = new ArrayList<>();
List<StringCfg> strRegionList = new ArrayList<>();
List<NumBoundaryCfg> numRegionList = new ArrayList<>();
List<DigestCfg> digestRegionList = new ArrayList<>();
List<IpCfg> areaIpRegionList = new ArrayList<>();
if(isAudit==Constants.AUDIT_YES) {
ConfigGroupInfo group=specificServiceCfgDao.getConfigGroupInfoByGroupId(Integer.parseInt(entity.getUserRegion1()));
if(group.getIsIssued()==1) {//复用,值下编译跟分组
maatCfg.initDefaultValue();
BeanUtils.copyProperties(entity, maatCfg);
maatCfg.setAction(entity.getAction());
maatCfg.setAuditTime(entity.getAuditTime());
maatCfg.setIpRegionList(ipRegionList);
maatCfg.setStrRegionList(strRegionList);
maatCfg.setNumRegionList(numRegionList);
maatCfg.setDigestRegionList(digestRegionList);
maatCfg.setGroupRelationList(groupRelationList);
maatCfg.setAreaIpRegionList(areaIpRegionList);
maatCfg.setIsValid(entity.getIsValid());
//group
GroupCfg groupCfg=new GroupCfg();
groupCfg.setCompileId(entity.getCompileId());
groupCfg.setGroupId(Integer.parseInt(entity.getUserRegion1()));
groupCfg.setIsValid(Constants.VALID_YES);
groupCfg.setAuditTime(auditTime);
groupRelationList.add(groupCfg);
maatCfg.setGroupNum(groupRelationList.size());
configCompileList.add(maatCfg);
maatBean.setConfigCompileList(configCompileList);
maatBean.setAuditTime(entity.getAuditTime());
maatBean.setCreatorName(entity.getCurrentUser().getName());
maatBean.setVersion(Constants.MAAT_VERSION);
maatBean.setOpAction(Constants.INSERT_ACTION);
//调用服务接口下发配置数据
String json=gsonToJson(maatBean);
logger.info("asn策略组复用配置下发配置参数"+json);
//调用服务接口下发配置
ToMaatResult result = ConfigServiceUtil.postMaatCfg(json);
logger.info("asn策略组复用配置下发响应信息"+result.getMsg());
}else {//首次下发
maatCfg.initDefaultValue();
BeanUtils.copyProperties(entity, maatCfg);
maatCfg.setAction(entity.getAction());
maatCfg.setAuditTime(entity.getAuditTime());
maatCfg.setStrRegionList(strRegionList);
maatCfg.setNumRegionList(numRegionList);
maatCfg.setDigestRegionList(digestRegionList);
maatCfg.setGroupRelationList(groupRelationList);
maatCfg.setAreaIpRegionList(areaIpRegionList);
maatCfg.setIsValid(entity.getIsValid());
//group
GroupCfg groupCfg=new GroupCfg();
groupCfg.setCompileId(entity.getCompileId());
groupCfg.setGroupId(Integer.parseInt(entity.getUserRegion1()));
groupCfg.setIsValid(Constants.VALID_YES);
groupCfg.setAuditTime(auditTime);
groupRelationList.add(groupCfg);
maatCfg.setGroupNum(groupRelationList.size());
//region
//查询asn group id下所有的 ip
AsnIpCfg asnIpCfg=new AsnIpCfg();
asnIpCfg.setAsnIpGroup(Integer.parseInt(entity.getUserRegion1()));
List<AsnIpCfg> allAsnIpCfgs=asnIpCfgDao.findAllList(asnIpCfg);
ipRegionList.addAll(groupReuseCfgAddRemoveConvert(allAsnIpCfgs,Constants.VALID_YES,null));
maatCfg.setIpRegionList(ipRegionList);
configCompileList.add(maatCfg);
maatBean.setConfigCompileList(configCompileList);
maatBean.setAuditTime(entity.getAuditTime());
maatBean.setCreatorName(entity.getCurrentUser().getName());
maatBean.setVersion(Constants.MAAT_VERSION);
maatBean.setOpAction(Constants.INSERT_ACTION);
//调用服务接口下发配置数据
String json=gsonToJson(maatBean);
logger.info("asn策略配置下发配置参数"+json);
//调用服务接口下发配置
ToMaatResult result = ConfigServiceUtil.postMaatCfg(json);
logger.info("asn策略配置下发响应信息"+result.getMsg());
ConfigGroupInfo info=new ConfigGroupInfo();
info.setIsIssued(1);
info.setGroupId(Integer.parseInt(entity.getUserRegion1()));
specificServiceCfgDao.updateConfigGroupInfobyGroupId(info);
AsnIpCfg cfg=new AsnIpCfg();
cfg.setIsValid(Constants.VALID_YES);
cfg.setAsnIpGroup(Integer.parseInt(entity.getUserRegion1()));
asnIpCfgDao.updateIssued(cfg);
}
}else if(isAudit==Constants.AUDIT_NOT_YES) {//取消审核通过
maatCfg.setCompileId(entity.getCompileId());
maatCfg.setServiceId(entity.getServiceId());
maatCfg.setIsValid(0);//无效
configCompileList.add(maatCfg);
maatBean.setConfigCompileList(configCompileList);
maatBean.setAuditTime(entity.getAuditTime());
maatBean.setCreatorName(entity.getCurrentUser().getName());
maatBean.setVersion(Constants.MAAT_VERSION);
maatBean.setOpAction(Constants.UPDATE_ACTION);
//调用服务接口取消配置
String json=gsonToJson(maatBean);
logger.info("asn策略取消下发配置参数"+json);
//调用服务接口下发配置
ToMaatResult result = ConfigServiceUtil.put(json,1);
logger.info("asn策略取消配置响应信息"+result.getMsg());
}else {
throw new RuntimeException("unknown isAudit value "+isAudit);
}
}
// @Transactional(readOnly=false,rollbackFor=RuntimeException.class)
// @Deprecated
// public void audit(Integer isAudit,Integer isValid,Integer functionId,String id,Date auditTime){
// CfgIndexInfo entity=asnPolicyCfgDao.get(Long.valueOf(id));
// entity.setIsAudit(isAudit);
// entity.setIsValid(isValid);
// entity.setAuditorId(UserUtils.getUser().getId());
// entity.setAuditTime(auditTime);
// asnPolicyCfgDao.updateCfgIndexInfo(entity);
// ToMaatBean maatBean = new ToMaatBean();
// MaatCfg maatCfg = new MaatCfg();
// List<MaatCfg> configCompileList = new ArrayList<>();
// List<GroupCfg> groupRelationList = new ArrayList<>();
// List<IpCfg> ipRegionList = new ArrayList<>();
// List<StringCfg> strRegionList = new ArrayList<>();
// List<NumBoundaryCfg> numRegionList = new ArrayList<>();
// List<DigestCfg> digestRegionList = new ArrayList<>();
// List<IpCfg> areaIpRegionList = new ArrayList<>();
// if(isAudit==Constants.AUDIT_YES) {
// ConfigGroupInfo group=configGroupInfoDao.getConfigGroupInfoByGroupId(Integer.parseInt(entity.getUserRegion1()));
// if(group.getIsIssued()==1) {//复用,值下编译跟分组
// maatCfg.initDefaultValue();
// BeanUtils.copyProperties(entity, maatCfg);
// maatCfg.setAction(entity.getAction());
// maatCfg.setAuditTime(entity.getAuditTime());
// maatCfg.setIpRegionList(ipRegionList);
// maatCfg.setStrRegionList(strRegionList);
// maatCfg.setNumRegionList(numRegionList);
// maatCfg.setDigestRegionList(digestRegionList);
// maatCfg.setGroupRelationList(groupRelationList);
// maatCfg.setAreaIpRegionList(areaIpRegionList);
// maatCfg.setIsValid(entity.getIsValid());
// //group
// GroupCfg groupCfg=new GroupCfg();
// groupCfg.setCompileId(entity.getCompileId());
// groupCfg.setGroupId(Integer.parseInt(entity.getUserRegion1()));
// groupCfg.setIsValid(Constants.VALID_YES);
// groupCfg.setAuditTime(auditTime);
// groupRelationList.add(groupCfg);
// maatCfg.setGroupNum(groupRelationList.size());
// configCompileList.add(maatCfg);
// maatBean.setConfigCompileList(configCompileList);
// maatBean.setAuditTime(entity.getAuditTime());
// maatBean.setCreatorName(entity.getCurrentUser().getName());
// maatBean.setVersion(Constants.MAAT_VERSION);
// maatBean.setOpAction(Constants.INSERT_ACTION);
// //调用服务接口下发配置数据
// String json=gsonToJson(maatBean);
// logger.info("asn策略组复用配置下发配置参数"+json);
// //调用服务接口下发配置
// ToMaatResult result = ConfigServiceUtil.postMaatCfg(json);
// logger.info("asn策略组复用配置下发响应信息"+result.getMsg());
// }else {//首次下发
// maatCfg.initDefaultValue();
// BeanUtils.copyProperties(entity, maatCfg);
// maatCfg.setAction(entity.getAction());
// maatCfg.setAuditTime(entity.getAuditTime());
// maatCfg.setStrRegionList(strRegionList);
// maatCfg.setNumRegionList(numRegionList);
// maatCfg.setDigestRegionList(digestRegionList);
// maatCfg.setGroupRelationList(groupRelationList);
// maatCfg.setAreaIpRegionList(areaIpRegionList);
// maatCfg.setIsValid(entity.getIsValid());
// //group
// GroupCfg groupCfg=new GroupCfg();
// groupCfg.setCompileId(entity.getCompileId());
// groupCfg.setGroupId(Integer.parseInt(entity.getUserRegion1()));
// groupCfg.setIsValid(Constants.VALID_YES);
// groupCfg.setAuditTime(auditTime);
// groupRelationList.add(groupCfg);
// maatCfg.setGroupNum(groupRelationList.size());
// //region
// //查询asn group id下所有的 ip
// AsnIpCfg asnIpCfg=new AsnIpCfg();
// asnIpCfg.setAsnIpGroup(Integer.parseInt(entity.getUserRegion1()));
// List<AsnIpCfg> allAsnIpCfgs=asnIpCfgDao.findAllList(asnIpCfg);
// ipRegionList.addAll(groupReuseCfgAddRemoveConvert(allAsnIpCfgs,Constants.VALID_YES,null));
// maatCfg.setIpRegionList(ipRegionList);
// configCompileList.add(maatCfg);
// maatBean.setConfigCompileList(configCompileList);
// maatBean.setAuditTime(entity.getAuditTime());
// maatBean.setCreatorName(entity.getCurrentUser().getName());
// maatBean.setVersion(Constants.MAAT_VERSION);
// maatBean.setOpAction(Constants.INSERT_ACTION);
//
// //调用服务接口下发配置数据
// String json=gsonToJson(maatBean);
// logger.info("asn策略配置下发配置参数"+json);
// //调用服务接口下发配置
// ToMaatResult result = ConfigServiceUtil.postMaatCfg(json);
// logger.info("asn策略配置下发响应信息"+result.getMsg());
// ConfigGroupInfo info=new ConfigGroupInfo();
// info.setIsIssued(1);
// info.setGroupId(Integer.parseInt(entity.getUserRegion1()));
// configGroupInfoDao.updateConfigGroupInfobyGroupId(info);
// AsnIpCfg cfg=new AsnIpCfg();
// cfg.setIsValid(Constants.VALID_YES);
// cfg.setAsnIpGroup(Integer.parseInt(entity.getUserRegion1()));
// asnIpCfgDao.updateIssued(cfg);
// }
// }else if(isAudit==Constants.AUDIT_NOT_YES) {//取消审核通过
// maatCfg.setCompileId(entity.getCompileId());
// maatCfg.setServiceId(entity.getServiceId());
// maatCfg.setIsValid(0);//无效
// configCompileList.add(maatCfg);
// maatBean.setConfigCompileList(configCompileList);
// maatBean.setAuditTime(entity.getAuditTime());
// maatBean.setCreatorName(entity.getCurrentUser().getName());
// maatBean.setVersion(Constants.MAAT_VERSION);
// maatBean.setOpAction(Constants.UPDATE_ACTION);
// //调用服务接口取消配置
// String json=gsonToJson(maatBean);
// logger.info("asn策略取消下发配置参数"+json);
// //调用服务接口下发配置
// ToMaatResult result = ConfigServiceUtil.put(json,1);
// logger.info("asn策略取消配置响应信息"+result.getMsg());
// }else {
// throw new RuntimeException("unknown isAudit value "+isAudit);
// }
//
// }
}

View File

@@ -41,7 +41,7 @@ import com.nis.web.dao.basics.AsnIpCfgDao;
import com.nis.web.dao.configuration.AreaIpCfgDao;
import com.nis.web.dao.configuration.IpCfgDao;
import com.nis.web.dao.configuration.StringCfgDao;
import com.nis.web.dao.specific.SpecificServiceCfgDao;
import com.nis.web.dao.specific.ConfigGroupInfoDao;
import com.nis.web.security.UserUtils;
import com.nis.web.service.CrudService;
@@ -59,7 +59,8 @@ public class IpCfgService extends CrudService<IpCfgDao,BaseIpCfg> {
@Autowired
protected AreaIpCfgDao areaIpCfgDao;
@Autowired
protected SpecificServiceCfgDao specificServiceCfgDao;
//protected SpecificServiceCfgDao specificServiceCfgDao;
protected ConfigGroupInfoDao configGroupInfoDao;
@Autowired
protected AsnIpCfgDao asnIpCfgDao;
/**
@@ -731,7 +732,7 @@ public class IpCfgService extends CrudService<IpCfgDao,BaseIpCfg> {
List<DigestCfg> digestRegionList = new ArrayList<>();
List<IpCfg> areaIpRegionList = new ArrayList<>();
if(isAudit==Constants.AUDIT_YES) {
ConfigGroupInfo group=specificServiceCfgDao.getConfigGroupInfoByGroupId(Integer.parseInt(entity.getUserRegion4()));
ConfigGroupInfo group=configGroupInfoDao.getConfigGroupInfoByGroupId(Integer.parseInt(entity.getUserRegion4()));
if(group.getIsIssued()==1) {//复用,只下编译跟分组
maatCfg.initDefaultValue();
BeanUtils.copyProperties(entity, maatCfg);
@@ -810,9 +811,10 @@ public class IpCfgService extends CrudService<IpCfgDao,BaseIpCfg> {
ToMaatResult result = ConfigServiceUtil.postMaatCfg(json);
logger.info("ipaddr asn配置下发响应信息"+result.getMsg());
ConfigGroupInfo info=new ConfigGroupInfo();
BeanUtils.copyProperties(group, info);
info.setIsIssued(1);
info.setGroupId(Integer.parseInt(entity.getUserRegion4()));
specificServiceCfgDao.updateConfigGroupInfobyGroupId(info);
//info.setGroupId(Integer.parseInt(entity.getUserRegion4()));
configGroupInfoDao.updateConfigGroupInfobyGroupId(info);
AsnIpCfg cfg=new AsnIpCfg();
cfg.setIsValid(Constants.VALID_YES);
cfg.setAsnIpGroup(Integer.parseInt(entity.getUserRegion4()));
@@ -907,7 +909,7 @@ public class IpCfgService extends CrudService<IpCfgDao,BaseIpCfg> {
entity.setIpPortList(ipPortList);
entity.setNtcSubscribeIdCfgList(subscribeIdList);
if(StringUtils.isNotBlank(entity.getUserRegion4())) {
ConfigGroupInfo info=specificServiceCfgDao.getConfigGroupInfoByGroupId(Integer.parseInt(entity.getUserRegion4().trim()));
ConfigGroupInfo info=configGroupInfoDao.getConfigGroupInfoByGroupId(Integer.parseInt(entity.getUserRegion4().trim()));
entity.setAsnIpGroupName(info.getGroupName());
}
return entity;
@@ -916,7 +918,7 @@ public class IpCfgService extends CrudService<IpCfgDao,BaseIpCfg> {
List<IpPortCfg> ipPortList = ipCfgDao.getIpPortList(entity);
entity.setIpPortList(ipPortList);
if(StringUtils.isNotBlank(entity.getUserRegion4())) {
ConfigGroupInfo info=specificServiceCfgDao.getConfigGroupInfoByGroupId(Integer.parseInt(entity.getUserRegion4().trim()));
ConfigGroupInfo info=configGroupInfoDao.getConfigGroupInfoByGroupId(Integer.parseInt(entity.getUserRegion4().trim()));
entity.setAsnIpGroupName(info.getGroupName());
}
return entity;

View File

@@ -0,0 +1,36 @@
package com.nis.web.service.specific;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.nis.domain.specific.ConfigGroupInfo;
import com.nis.web.dao.specific.ConfigGroupInfoDao;
import com.nis.web.service.BaseService;
@Service
public class ConfigGroupInfoService extends BaseService{
@Autowired
private ConfigGroupInfoDao configGroupInfoDao;
public List<ConfigGroupInfo> findAllList(int groupType){
return configGroupInfoDao.findAllList(groupType);
}
public ConfigGroupInfo insertConfigGroupInfo(ConfigGroupInfo entity) {
configGroupInfoDao.insertConfigGroupInfo(entity);
return entity;
}
public ConfigGroupInfo updateConfigGroupInfobyGroupId(ConfigGroupInfo entity) {
configGroupInfoDao.updateConfigGroupInfobyGroupId(entity);
return entity;
}
public ConfigGroupInfo getConfigGroupInfoByGroupId(Integer groupId) {
return configGroupInfoDao.getConfigGroupInfoByGroupId(groupId);
}
public ConfigGroupInfo getInfoByAsnNo(Long asnNo) {
return configGroupInfoDao.getInfoByAsnNo(asnNo);
}
public Integer getIssuedConfigGroupInfoByGroupIds(String groupIds) {
return configGroupInfoDao.getIssuedConfigGroupInfoByGroupIds(groupIds);
}
}

View File

@@ -11,8 +11,10 @@ import com.beust.jcommander.internal.Lists;
import com.nis.domain.Page;
import com.nis.domain.specific.ConfigGroupInfo;
import com.nis.domain.specific.SpecificServiceCfg;
import com.nis.util.AsnCacheUtils;
import com.nis.util.ConfigServiceUtil;
import com.nis.util.Constants;
import com.nis.web.dao.specific.ConfigGroupInfoDao;
import com.nis.web.dao.specific.SpecificServiceCfgDao;
import com.nis.web.service.BaseService;
@@ -21,6 +23,8 @@ public class SpecificServiceCfgService extends BaseService{
@Autowired
private SpecificServiceCfgDao specificServiceCfgDao;
@Autowired
private ConfigGroupInfoDao configGroupInfoDao;
/**
* 根据id查询对象
@@ -76,14 +80,14 @@ public class SpecificServiceCfgService extends BaseService{
specificServiceCfg.setGroupId(groupId);
}
//新增协议分组
ConfigGroupInfo group = specificServiceCfgDao.getConfigGroupInfoByGroupId(specificServiceCfg.getGroupId());
ConfigGroupInfo group = configGroupInfoDao.getConfigGroupInfoByGroupId(specificServiceCfg.getGroupId());
if(group==null){
group = new ConfigGroupInfo();
group.setGroupId(specificServiceCfg.getGroupId());
group.setGroupName(specificServiceCfg.getSpecServiceName());
group.setIsIssued(0);
group.setGroupType(1);
specificServiceCfgDao.insertConfigGroupInfo(group);
configGroupInfoDao.insertConfigGroupInfo(group);
}
if(specificServiceCfg.getSpecServiceId()==null){//新增
if(specificServiceCfg.getIsLeaf()==null){

View File

@@ -27,5 +27,6 @@
<!-- 简单页面缓存
<cache name="SimplePageCachingFilter" maxEntriesLocalHeap="100" eternal="false" overflowToDisk="true"
timeToIdleSeconds="120" timeToLiveSeconds="120" memoryStoreEvictionPolicy="LFU"/> -->
<!-- asn no缓存 -->
<cache name="asnNoCache" maxEntriesLocalHeap="10000" eternal="false" timeToIdleSeconds="0" timeToLiveSeconds="6000" overflowToDisk="true"/>
</ehcache>

View File

@@ -55,5 +55,6 @@
properties="replicateAsynchronously=true, replicatePuts=true, replicateUpdates=true,
replicateUpdatesViaCopy=false, replicateRemovals=true "/>
</cache> -->
<!-- asn no缓存 -->
<cache name="asnNoCache" maxEntriesLocalHeap="10000" eternal="false" timeToIdleSeconds="0" timeToLiveSeconds="6000" overflowToDisk="true"/>
</ehcache>

View File

@@ -546,3 +546,7 @@ ipv4_ip_range_regexp_new=^(0|1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|[1-9])\\.(0|1\\d
ipv4_ip_subnet_regexp_original=^(0|1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|[1-9])\\.(0|1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)\\.(0|1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)\\.(0|1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)/(3[0-2]|1[0-9]|2[0-9]|[0-9])$
#\u57df\u540d\u9a8c\u8bc1\u6b63\u5219
domain_regexp=^(?=^.{3,255}$)[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(\\.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+$
#IP复用maat json中的ip region单次send 最大个数
maat_json_send_size=2000
#导入验证的线程数量
mulity_thread_size=5

View File

@@ -247,7 +247,7 @@
<bean id="multipartResolver"
class="com.nis.interceptor.MultipartFileIntercepter" >
<property name="defaultEncoding" value="utf-8"></property>
<property name="maxUploadSize" value="5242880"></property><!-- 5*1024*1024 -->
<property name="maxUploadSize" value="20917520"></property><!-- 5*1024*1024 -->
</bean>
<bean

View File

@@ -247,6 +247,7 @@
<%-- <th><spring:message code="seq"/></th> --%>
<th><spring:message code="config_describe"/></th>
<th><spring:message code="group"/></th>
<th><spring:message code="asn_no"/></th>
<th><spring:message code="ip_type"/></th>
<th><spring:message code="IP"/></th>
<%-- <th><spring:message code="port"/></th> --%>
@@ -274,8 +275,8 @@
<tr>
<td><input type="checkbox" class="i-checks" id="${cfg.cfgId}" isValid="${cfg.isValid}" serviceGroupId="${cfg.asnIpGroup}" value="0"></td>
<td>${cfg.cfgDesc }</td>
<td>${cfg.asnIpGroupName }
</td>
<td class="configGroup" asnNo="${cfg.userRegion1}">${cfg.asnIpGroup }</td>
<td>${cfg.userRegion1}</td>
<td>
<c:forEach items="${fns:getDictList('IP_TYPE')}" var="ipTypeC">
<c:if test="${cfg.ipType==ipTypeC.itemCode}"><spring:message code="${ipTypeC.itemValue }"/></c:if>

View File

@@ -4,7 +4,7 @@ $(function(){
if($(this).attr("id")&&$(this).attr("id")!=''){
ids.push($(this).attr("id"));
}
ids.push($(this).attr("id"));
//ids.push($(this).attr("id"));
});
$(".behavCode").each(function(){
if($(this).attr("id")&&$(this).attr("id")!=''){
@@ -32,4 +32,26 @@ $(function(){
}
});
}
var asnNos=[];
$(".configGroup").each(function(){
if($(this).attr("asnNo")&&$(this).attr("asnNo")!=''){
asnNos.push($(this).attr("asnNo"));
}
});
if(asnNos.length>0){
var pathName=window.document.location.pathname.substring(0,window.document.location.pathname.indexOf("/nis")+4);
$.ajax({
type:'post',
async:false,
url:pathName+'/basics/asn/ajaxGroupName',
data:{"ids":asnNos.join(",")},
success:function(data){
if(data){
for(var ind in data){
$("[class='configGroup'][asnNo='"+ind+"']").html(data[ind]);
}
}
}
});
}
});