网站HTTP配置增加区域ip配置信息处理。

This commit is contained in:
zhangwei
2018-05-28 15:47:33 +08:00
parent 317e3ae048
commit da189660d8
6 changed files with 164 additions and 18 deletions

View File

@@ -8,6 +8,8 @@
*/
package com.nis.domain.configuration;
import com.nis.util.Constants;
/**
* @ClassName: HttpDomainConfig.java
* @Description: TODO

View File

@@ -59,46 +59,88 @@ public class WebsiteController extends BaseController{
public String httpForm(Model model,String ids,CfgIndexInfo entity) {
if(StringUtils.isNotBlank(ids)){
entity = websiteCfgService.getHttpCfg(Long.parseLong(ids));
//设置http各类配置的配置域类型
IpPortCfg ipCfg = new IpPortCfg();
ipCfg.setCfgType(Constants.HTTP_IP_REGION);
entity.setIpPort(ipCfg);
HttpUrlCfg urlCfg = new HttpUrlCfg();
urlCfg.setCfgType(Constants.HTTP_URL_REGION);
entity.setHttpUrl(urlCfg);
HttpReqHeadCfg reqHdrCfg = new HttpReqHeadCfg();
reqHdrCfg.setCfgType(Constants.HTTP_REQ_HEAD_REGION);
entity.setHttpReqHdr(reqHdrCfg);
HttpResHeadCfg resHdrCfg = new HttpResHeadCfg();
resHdrCfg.setCfgType(Constants.HTTP_RES_HEAD_REGION);
entity.setHttpResHdr(resHdrCfg);
HttpBodyCfg reqBodyCfg = new HttpBodyCfg();
reqBodyCfg.setCfgType(Constants.HTTP_REQ_BODY_REGION);
entity.setHttpReqBody(reqBodyCfg);
HttpBodyCfg resBodyCfg = new HttpBodyCfg();
resBodyCfg.setCfgType(Constants.HTTP_RES_BODY_REGION);
entity.setHttpResBody(resBodyCfg);
if(entity.getIpPortList().size()==0){
entity.getIpPortList().add(new IpPortCfg());
entity.getIpPortList().add(ipCfg);
}
if(entity.getHttpUrlList().size()==0){
entity.getHttpUrlList().add(new HttpUrlCfg());
entity.getHttpUrlList().add(urlCfg);
}
if(entity.getHttpReqHdrList().size()==0){
entity.getHttpReqHdrList().add(new HttpReqHeadCfg());
entity.getHttpReqHdrList().add(reqHdrCfg);
}
if(entity.getHttpResHdrList().size()==0){
entity.getHttpResHdrList().add(new HttpResHeadCfg());
entity.getHttpResHdrList().add(resHdrCfg);
}
if(entity.getHttpReqBodyList().size()==0){
entity.getHttpReqBodyList().add(new HttpBodyCfg());
entity.getHttpReqBodyList().add(reqBodyCfg);
}
if(entity.getHttpResBodyList().size()==0){
entity.getHttpResBodyList().add(new HttpBodyCfg());
entity.getHttpResBodyList().add(resBodyCfg);
}
model.addAttribute("areaCfgs", entity.getAreaCfg());
}else{
//设置http各类配置的配置域类型
IpPortCfg ipCfg = new IpPortCfg();
ipCfg.setCfgType(Constants.HTTP_IP_REGION);
entity.setIpPort(ipCfg);
HttpUrlCfg urlCfg = new HttpUrlCfg();
urlCfg.setCfgType(Constants.HTTP_URL_REGION);
entity.setHttpUrl(urlCfg);
HttpReqHeadCfg reqHdrCfg = new HttpReqHeadCfg();
reqHdrCfg.setCfgType(Constants.HTTP_REQ_HEAD_REGION);
entity.setHttpReqHdr(reqHdrCfg);
HttpResHeadCfg resHdrCfg = new HttpResHeadCfg();
resHdrCfg.setCfgType(Constants.HTTP_RES_HEAD_REGION);
entity.setHttpResHdr(resHdrCfg);
HttpBodyCfg reqBodyCfg = new HttpBodyCfg();
reqBodyCfg.setCfgType(Constants.HTTP_REQ_BODY_REGION);
entity.setHttpReqBody(reqBodyCfg);
HttpBodyCfg resBodyCfg = new HttpBodyCfg();
resBodyCfg.setCfgType(Constants.HTTP_RES_BODY_REGION);
entity.setHttpResBody(resBodyCfg);
List<IpPortCfg> ipList=new ArrayList<IpPortCfg>();
ipList.add(new IpPortCfg());
ipList.add(ipCfg);
entity.setIpPortList(ipList);
List<HttpUrlCfg> urlList=new ArrayList<HttpUrlCfg>();
urlList.add(new HttpUrlCfg());
urlList.add(urlCfg);
entity.setHttpUrlList(urlList);
List<HttpReqHeadCfg> reqHdrList=new ArrayList<HttpReqHeadCfg>();
reqHdrList.add(new HttpReqHeadCfg());
reqHdrList.add(reqHdrCfg);
entity.setHttpReqHdrList(reqHdrList);
List<HttpResHeadCfg> resHdrList=new ArrayList<HttpResHeadCfg>();
resHdrList.add(new HttpResHeadCfg());
resHdrList.add(resHdrCfg);
entity.setHttpResHdrList(resHdrList);
List<HttpBodyCfg> reqBodyList=new ArrayList<HttpBodyCfg>();
reqBodyList.add(new HttpBodyCfg());
reqBodyList.add(reqBodyCfg);
entity.setHttpReqBodyList(reqBodyList);
List<HttpBodyCfg> resBodyList=new ArrayList<HttpBodyCfg>();
resBodyList.add(new HttpBodyCfg());
resBodyList.add(resBodyCfg);
entity.setHttpResBodyList(resBodyList);
}
initFormCondition(model,entity);
model.addAttribute("_cfg", entity);
model.addAttribute("_cfg", entity);
return "/cfg/website/httpForm";
}
@RequestMapping(value = {"saveHttpCfg"})

View File

@@ -16,4 +16,6 @@ import com.nis.web.dao.MyBatisDao;
@MyBatisDao
public interface AreaIpCfgDao extends CrudDao<AreaIpCfg>{
public List<AreaIpCfg> getByCompileId(@Param("compileId") int compileId) ;
public void saveAreaIpCfg(AreaIpCfg entity);
public void deleteAreaIpCfg(AreaIpCfg entity);
}

View File

@@ -53,4 +53,80 @@
AND IS_VALID!=-1
</trim>
</select>
<!-- insert area_ip_cfg表信息 -->
<insert id="saveAreaIpCfg" parameterType="com.nis.domain.configuration.AreaIpCfg" >
<selectKey resultType="java.lang.Long" order="AFTER" keyProperty="cfgId">
SELECT LAST_INSERT_ID()
</selectKey>
insert into area_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,
COMPILE_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
)values (
#{cfgDesc,jdbcType=VARCHAR},
#{action,jdbcType=INTEGER},
0,
0,
#{creatorId,jdbcType=INTEGER},
#{createTime,jdbcType=TIMESTAMP},
#{editorId,jdbcType=INTEGER},
#{editTime,jdbcType=TIMESTAMP},
#{auditorId,jdbcType=INTEGER},
#{auditTime,jdbcType=TIMESTAMP},
#{serviceId,jdbcType=INTEGER},
#{requestId,jdbcType=INTEGER},
#{compileId,jdbcType=INTEGER},
#{isAreaEffective,jdbcType=INTEGER},
#{classify,jdbcType=VARCHAR},
#{attribute,jdbcType=VARCHAR},
#{lable,jdbcType=VARCHAR},
#{areaEffectiveIds,jdbcType=VARCHAR},
#{functionId,jdbcType=INTEGER},
#{ipType,jdbcType=INTEGER},
#{srcIpAddress,jdbcType=VARCHAR},
#{ipPattern,jdbcType=INTEGER},
#{portPattern,jdbcType=INTEGER},
#{srcPort,jdbcType=VARCHAR},
#{protocol,jdbcType=INTEGER},
#{protocolId,jdbcType=INTEGER},
#{direction,jdbcType=INTEGER},
#{destPort,jdbcType=VARCHAR},
#{destIpAddress,jdbcType=VARCHAR},
#{cfgType,jdbcType=VARCHAR},
#{cfgRegionCode,jdbcType=INTEGER}
)
</insert>
<!-- 删除区域IP配置 -->
<delete id="deleteAreaIpCfg" >
delete from area_ip_cfg where compile_id=#{compileId} and function_id=#{functionId}
</delete>
</mapper>

View File

@@ -16,6 +16,7 @@ import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import com.nis.domain.Page;
import com.nis.domain.configuration.AreaIpCfg;
import com.nis.domain.configuration.BaseIpCfg;
import com.nis.domain.configuration.CfgIndexInfo;
import com.nis.domain.configuration.HttpBodyCfg;
@@ -25,6 +26,7 @@ import com.nis.domain.configuration.HttpUrlCfg;
import com.nis.domain.configuration.IpPortCfg;
import com.nis.exceptions.MaatConvertException;
import com.nis.util.ConfigServiceUtil;
import com.nis.web.dao.configuration.AreaIpCfgDao;
import com.nis.web.dao.configuration.IpCfgDao;
import com.nis.web.dao.configuration.WebsiteCfgDao;
import com.nis.web.service.BaseService;
@@ -39,6 +41,8 @@ import com.nis.web.service.CrudService;
public class WebsiteCfgService extends CrudService<WebsiteCfgDao,CfgIndexInfo> {
@Autowired
protected WebsiteCfgDao websiteCfgDao;
@Autowired
protected AreaIpCfgDao areaIpCfgDao;
public CfgIndexInfo getHttpCfg(Long cfgId){
CfgIndexInfo entity = websiteCfgDao.getCfgIndexInfo(cfgId);
@@ -48,12 +52,14 @@ public class WebsiteCfgService extends CrudService<WebsiteCfgDao,CfgIndexInfo> {
List<HttpResHeadCfg> httpResHdrList = websiteCfgDao.getHttpResHdrList(entity);
List<HttpBodyCfg> httpReqBodyList = websiteCfgDao.getHttpReqBodyList(entity);
List<HttpBodyCfg> httpResBodyList = websiteCfgDao.getHttpResBodyList(entity);
List<AreaIpCfg> areaCfg = areaIpCfgDao.getByCompileId(entity.getCompileId());
entity.setIpPortList(ipPortList);
entity.setHttpReqBodyList(httpReqBodyList);
entity.setHttpReqHdrList(httpReqHdrList);
entity.setHttpResBodyList(httpResBodyList);
entity.setHttpResHdrList(httpResHdrList);
entity.setHttpUrlList(httpUrlList);
entity.setAreaCfg(areaCfg);
return entity;
}
public Page<CfgIndexInfo> getHttpList(Page<CfgIndexInfo> page, CfgIndexInfo entity){
@@ -130,6 +136,13 @@ public class WebsiteCfgService extends CrudService<WebsiteCfgDao,CfgIndexInfo> {
websiteCfgDao.saveHttpBodyCfg(cfg);
}
}
//保存区域IP信息
if(entity.getAreaCfg()!=null){
for(AreaIpCfg cfg:entity.getAreaCfg()){
BeanUtils.copyProperties(entity, cfg,new String[]{"cfgRegionCode","cfgType"});
areaIpCfgDao.saveAreaIpCfg(cfg);
}
}
} catch (Exception e) {
e.printStackTrace();
logger.info("获取编译ID出错");
@@ -145,6 +158,10 @@ public class WebsiteCfgService extends CrudService<WebsiteCfgDao,CfgIndexInfo> {
websiteCfgDao.deleteHttpReqHdrCfg(entity);
websiteCfgDao.deleteHttpResHdrCfg(entity);
websiteCfgDao.deleteHttpBodyCfg(entity);
AreaIpCfg area = new AreaIpCfg();
area.setCompileId(entity.getCompileId());
area.setFunctionId(entity.getFunctionId());
areaIpCfgDao.deleteAreaIpCfg(area);
entity.setCreateTime(new Date());
entity.setCreatorId(entity.getCurrentUser().getId());
if(entity.getIpPortList()!=null){
@@ -183,6 +200,13 @@ public class WebsiteCfgService extends CrudService<WebsiteCfgDao,CfgIndexInfo> {
websiteCfgDao.saveHttpBodyCfg(cfg);
}
}
//保存区域IP信息
if(entity.getAreaCfg()!=null){
for(AreaIpCfg cfg:entity.getAreaCfg()){
BeanUtils.copyProperties(entity, cfg,new String[]{"cfgDesc","cfgRegionCode","cfgType"});
areaIpCfgDao.saveAreaIpCfg(cfg);
}
}
}