app ip保存优化,一个insert 多个value

This commit is contained in:
wangxin
2018-11-12 17:26:44 +08:00
parent 3240ad4de2
commit b915a53f9b
5 changed files with 77 additions and 4 deletions

View File

@@ -1,6 +1,8 @@
package com.nis.domain.configuration;
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
import com.nis.util.excel.ExcelField;
@@ -251,5 +253,20 @@ public class AppIpCfg extends BaseCfg<AppIpCfg> {
public void setBehavCode(Integer behavCode) {
this.behavCode = behavCode;
}
@Override
public String toString() {
return "AppIpCfg [compileId=" + compileId + ", ratelimit=" + ratelimit + ", appCode=" + appCode + ", behavCode="
+ behavCode + ", specServiceId=" + specServiceId + ", appName=" + appName + ", ipType=" + ipType
+ ", ipPattern=" + ipPattern + ", srcIpAddress=" + srcIpAddress + ", destIpAddress=" + destIpAddress
+ ", portPattern=" + portPattern + ", srcPort=" + srcPort + ", destPort=" + destPort + ", direction="
+ direction + ", protocol=" + protocol + ", 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
+ ", isAreaEffective=" + isAreaEffective + ", classify=" + classify + ", attribute=" + attribute
+ ", lable=" + lable + ", areaEffectiveIds=" + areaEffectiveIds + ", cfgRegionCode=" + cfgRegionCode
+ ", cfgType=" + cfgType + ", functionId=" + functionId + ", doLog=" + doLog + "]";
}
}

View File

@@ -979,7 +979,7 @@ public class BaseController {
* @throws ServiceException
*/
public BlockingQueue<DnsResStrategy> checkDnsResStrategyCfgMulity(FunctionServiceDict serviceDict, FunctionRegionDict regionDict,BlockingQueue<? extends Object> list) throws InterruptedException, ExecutionException, ServiceException{
logger.warn("start checkComplexStringCfgMulity ,size "+list.size());
logger.warn("start checkDnsResStrategyCfgMulity ,size "+list.size());
long start=System.currentTimeMillis();
BlockingQueue<DnsResStrategy> queue=new ArrayBlockingQueue<>(list.size());
ExecutorService service=Executors.newFixedThreadPool(Constants.MULITY_THREAD_SIZE);
@@ -1006,7 +1006,7 @@ public class BaseController {
}
}
long end=System.currentTimeMillis();
logger.warn("checkComplexStringCfgMulity finish,cost:"+(end-start)+",size:"+queue.size());
logger.warn("checkDnsResStrategyCfgMulity finish,cost:"+(end-start)+",size:"+queue.size());
return queue;
}

View File

@@ -49,6 +49,7 @@ public interface AppCfgDao {
public List<AppIpCfg> findAppIpList(AppIpCfg entity) ;
public AppIpCfg getAppIpCfg(Long cfgId) ;
public int insertAppIpCfg(AppIpCfg entity);
public int insertAppIpCfgBatch(List<AppIpCfg> list);
public int updateAppIpCfg(AppIpCfg entity);
//app http特征增删改查
public List<AppHttpCfg> findAppHttpList(AppHttpCfg entity) ;

View File

@@ -1709,6 +1709,33 @@
,#{userRegion3,jdbcType=VARCHAR},#{userRegion4,jdbcType=VARCHAR},#{userRegion5,jdbcType=VARCHAR}
)
</insert>
<insert id="insertAppIpCfgBatch" parameterType="com.nis.domain.configuration.AppIpCfg" >
insert into app_ip_cfg (
APP_CODE,BEHAV_CODE,SPEC_SERVICE_ID, CFG_DESC,ACTION,IS_VALID,IS_AUDIT,
CREATOR_ID,CREATE_TIME,EDITOR_ID,EDIT_TIME,AUDITOR_ID,AUDIT_TIME,
SERVICE_ID,REQUEST_ID,COMPILE_ID,IS_AREA_EFFECTIVE,CLASSIFY,
ATTRIBUTE,LABLE,AREA_EFFECTIVE_IDS,RATELIMIT,FUNCTION_ID,CFG_TYPE,CFG_REGION_CODE,
IP_TYPE, IP_PATTERN, SRC_IP_ADDRESS,DEST_IP_ADDRESS, PORT_PATTERN,SRC_PORT,DEST_PORT,
DIRECTION,PROTOCOL,DO_LOG,user_region1,user_region2,user_region3,user_region4,user_region5
)values
<foreach collection ="list" item="appIp" separator =",">
(
#{appIp.appCode,jdbcType=INTEGER},#{appIp.behavCode,jdbcType=INTEGER},#{appIp.specServiceId,jdbcType=INTEGER},
#{appIp.cfgDesc,jdbcType=VARCHAR},#{appIp.action,jdbcType=INTEGER},
#{appIp.isValid,jdbcType=INTEGER},#{appIp.isAudit,jdbcType=INTEGER},#{appIp.creatorId,jdbcType=INTEGER},
#{appIp.createTime,jdbcType=TIMESTAMP},#{appIp.editorId,jdbcType=INTEGER},#{appIp.editTime,jdbcType=TIMESTAMP},
#{appIp.auditorId,jdbcType=INTEGER},#{appIp.auditTime,jdbcType=TIMESTAMP},#{appIp.serviceId,jdbcType=INTEGER},
#{appIp.requestId,jdbcType=INTEGER},#{appIp.compileId,jdbcType=INTEGER},#{appIp.isAreaEffective,jdbcType=INTEGER},
#{appIp.classify,jdbcType=VARCHAR},#{appIp.attribute,jdbcType=VARCHAR},#{appIp.lable,jdbcType=VARCHAR},
#{appIp.areaEffectiveIds,jdbcType=VARCHAR},#{appIp.ratelimit,jdbcType=VARCHAR},#{appIp.functionId,jdbcType=INTEGER},
#{appIp.cfgType,jdbcType=VARCHAR},#{appIp.cfgRegionCode,jdbcType=INTEGER},
#{appIp.ipType,jdbcType=INTEGER}, #{appIp.ipPattern,jdbcType=INTEGER},#{appIp.srcIpAddress,jdbcType=VARCHAR},#{appIp.destIpAddress,jdbcType=VARCHAR},
#{appIp.portPattern,jdbcType=INTEGER},#{appIp.srcPort,jdbcType=VARCHAR},#{appIp.destPort,jdbcType=VARCHAR},#{appIp.direction,jdbcType=INTEGER},
#{appIp.protocol,jdbcType=INTEGER},#{appIp.doLog,jdbcType=INTEGER},#{appIp.userRegion1,jdbcType=VARCHAR},#{appIp.userRegion2,jdbcType=VARCHAR}
,#{appIp.userRegion3,jdbcType=VARCHAR},#{appIp.userRegion4,jdbcType=VARCHAR},#{appIp.userRegion5,jdbcType=VARCHAR}
)
</foreach>
</insert>
<insert id="insertAppHttpCfg" parameterType="com.nis.domain.configuration.AppHttpCfg" >
<selectKey resultType="java.lang.Long" order="AFTER" keyProperty="cfgId">
SELECT LAST_INSERT_ID()

View File

@@ -1,5 +1,6 @@
package com.nis.web.service.configuration;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@@ -13,7 +14,10 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.google.common.collect.Lists;
import com.nis.domain.Page;
import com.nis.domain.basics.AsnIpCfg;
import com.nis.domain.basics.Varibles;
import com.nis.domain.configuration.AppByteCfg;
import com.nis.domain.configuration.AppDomainCfg;
import com.nis.domain.configuration.AppHeaderCfg;
@@ -48,6 +52,7 @@ import com.nis.util.Constants;
import com.nis.util.DictUtils;
import com.nis.util.StringUtil;
import com.nis.util.StringUtils;
import com.nis.web.dao.basics.AsnIpCfgDao;
import com.nis.web.dao.configuration.AppCfgDao;
import com.nis.web.dao.configuration.AreaIpCfgDao;
import com.nis.web.dao.configuration.IpCfgDao;
@@ -78,6 +83,8 @@ public class AppCfgService extends BaseService {
protected SpecificServiceCfgDao specificServiceCfgDao;
@Autowired
protected ConfigGroupInfoDao configGroupInfoDao;
@Autowired
protected AsnIpCfgDao asnIpCfgDao;
public Page<AppPolicyCfg> findAppPolicyList(Page<AppPolicyCfg> page, AppPolicyCfg entity) {
entity.getSqlMap().put("dsf", configScopeFilter(entity.getCurrentUser(), "r"));
@@ -326,6 +333,8 @@ public class AppCfgService extends BaseService {
*/
@Transactional(readOnly = false, rollbackFor = RuntimeException.class)
public void saveAppIpCfg(List<BaseIpCfg> cfgs,SpecificServiceCfg specificServiceCfg){
logger.warn("Start to save IP");
long start=System.currentTimeMillis();
ConfigGroupInfo configGroupInfo=configGroupInfoDao.getConfigGroupInfoByGroupId(specificServiceCfg.getGroupId());
if(configGroupInfo==null) {//一般特定服务的组号是新增之后就有的,不会进入这一步。
Integer groupId = ConfigServiceUtil.getId(2, 1).get(0);
@@ -343,13 +352,32 @@ public class AppCfgService extends BaseService {
specificServiceCfgDao.update(specificServiceCfg);
}
Integer compileId = configGroupInfo.getCompileId();
Varibles maxPacket=asnIpCfgDao.getVaribles("max_allowed_packet");
List<AppIpCfg> tempList=Lists.newArrayList();
int len=0;
for(BaseIpCfg cfg:cfgs) {
AppIpCfg entity=new AppIpCfg();
BeanUtils.copyProperties(cfg, entity);
entity.setCompileId(compileId);
appCfgDao.insertAppIpCfg(entity);
int tempLen=entity.toString().getBytes(Charset.forName("UTF-8")).length;
if((len+tempLen)<maxPacket.getValue().longValue()) {
tempList.add(entity);
len+=tempLen;
}else {
appCfgDao.insertAppIpCfgBatch(tempList);
tempList.clear();
tempList.add(entity);
len=tempLen;
}
}
if(tempList.size()>0) {
logger.warn("save ip size:"+tempList.size());
appCfgDao.insertAppIpCfgBatch(tempList);
tempList.clear();
}
long end=System.currentTimeMillis();
logger.warn("Save IP finish,cost:"+(end-start));
}
@Transactional(readOnly = false, rollbackFor = RuntimeException.class)
public void saveOrUpdateAppIpCfg(AppIpCfg entity) throws Exception {
// 设置区域运营商信息