@@ -1,5 +1,6 @@
package com.nis.web.controller.configuration ;
import java.util.ArrayList ;
import java.util.Date ;
import java.util.List ;
@@ -12,14 +13,16 @@ import org.springframework.stereotype.Controller;
import org.springframework.ui.Model ;
import org.springframework.web.bind.annotation.ModelAttribute ;
import org.springframework.web.bind.annotation.RequestMapping ;
import org.springframework.web.bind.annotation.RequestMethod ;
import org.springframework.web.servlet.mvc.support.RedirectAttributes ;
import com.nis.domain.Page ;
import com.nis.domain.ServiceConfigInfo ;
import com.nis.domain.basics.ServiceDictInfo ;
import com.nis.domain.basics.SysDictInfo ;
import com.nis.domain.configuration.AreaBean ;
import com.nis.domain.configuration.AreaIpCfg ;
import com.nis.domain.configuration.BaseIpCfg ;
import com.nis.domain.configuration.RequestInfo ;
import com.nis.exceptions.ServiceException ;
import com.nis.main.ConvertTool ;
import com.nis.util.Constants ;
import com.nis.web.controller.BaseController ;
@@ -124,6 +127,10 @@ public class IpCfgController extends BaseController{
ipcfg . setTableName ( tableName ) ;
ipcfg . initDefaultValue ( ) ;
ipcfg . setAction ( action ) ;
//监测缺省不需要区域管控
if ( action = = Constants . ACTION_DJ ) {
ipcfg . setIsAreaEffective ( 0 ) ;
}
ipcfg . setServiceId ( serviceId ) ;
model . addAttribute ( " _cfg " , ipcfg ) ;
model . addAttribute ( " tableName " , tableName ) ;
@@ -135,6 +142,18 @@ public class IpCfgController extends BaseController{
model . addAttribute ( " xzs " , xzs ) ;
List < ServiceDictInfo > lables = serviceDictInfoService . findLableDict ( ) ;
model . addAttribute ( " lables " , lables ) ;
List < Integer > itTypeList = new ArrayList < Integer > ( ) ;
itTypeList . add ( Constants . ITEM_TYPE_AREA ) ;
List < SysDictInfo > areas = sysDictInfoService . findAllSysDictInfo ( new SysDictInfo ( ) , itTypeList , null ) ;
model . addAttribute ( " areas " , areas ) ;
itTypeList . clear ( ) ;
itTypeList . add ( Constants . ITEM_TYPE_ISP ) ;
List < SysDictInfo > isps = sysDictInfoService . findAllSysDictInfo ( new SysDictInfo ( ) , itTypeList , null ) ;
model . addAttribute ( " isps " , isps ) ;
//初始化一个默认的地域ip给界面
AreaIpCfg areaIpCfg = new AreaIpCfg ( ) ;
areaIpCfg . initDefaultValue ( ) ;
model . addAttribute ( " _areaCfg " , areaIpCfg ) ;
} catch ( ClassNotFoundException | InstantiationException | IllegalAccessException e ) {
// TODO Auto-generated catch block
logger . error ( " 打开新增IP窗口失败 " , e ) ;
@@ -172,6 +191,12 @@ public class IpCfgController extends BaseController{
model . addAttribute ( " serviceId " , serviceId ) ;
model . addAttribute ( " action " , action ) ;
model . addAttribute ( " audit " , Constants . CFG_PAGE ) ;
if ( StringUtils . isBlank ( tableName ) ) {
ServiceConfigInfo serviceConfigInfo = serviceConfigInfoService . findSysServiceConfigInfo ( serviceId ) ;
if ( serviceConfigInfo ! = null ) {
tableName = serviceConfigInfo . getTableName ( ) ;
}
}
if ( ! StringUtils . isBlank ( tableName ) ) {
logger . info ( " table name is " + tableName ) ;
BaseIpCfg searchBean = new BaseIpCfg ( ) ;
@@ -180,6 +205,37 @@ public class IpCfgController extends BaseController{
BaseIpCfg ipCfg = ipCfgService . getIpCfgById ( searchBean ) ;
model . addAttribute ( " _cfg " , ipCfg ) ;
model . addAttribute ( " tableName " , tableName ) ;
int compileId = ipCfg . getCompileId ( ) ;
//查询配置对应的地域ip
List < AreaIpCfg > areaCfgs = ipCfgService . getAreaCfgByCompileId ( compileId ) ;
model . addAttribute ( " areaCfgs " , areaCfgs ) ;
StringBuffer areaCfgIds = new StringBuffer ( ) ;
for ( AreaIpCfg areaCfg : areaCfgs ) {
areaCfgIds . append ( areaCfg . getCfgId ( ) + " , " ) ;
}
//update时判断是否有删除地域ip
model . addAttribute ( " areaCfgIds " , areaCfgIds . toString ( ) ) ;
//初始化一个默认的地域ip给界面
AreaIpCfg areaIpCfg = new AreaIpCfg ( ) ;
areaIpCfg . initDefaultValue ( ) ;
model . addAttribute ( " _areaCfg " , areaIpCfg ) ;
//从区域生效ID中获取区域与运营商
String areaEffectiveIds = ipCfg . getAreaEffectiveIds ( ) ;
List < AreaBean > areaIspList = new ArrayList < AreaBean > ( ) ;
if ( StringUtils . isNotBlank ( areaEffectiveIds ) ) {
String [ ] areaIsps = areaEffectiveIds . split ( " , " ) ;
for ( String areaIsp : areaIsps ) {
AreaBean area = new AreaBean ( ) ;
if ( areaIsp . contains ( " : " ) ) {
area . setArea ( areaIsp . split ( " : " ) [ 0 ] ) ;
area . setIsp ( areaIsp . split ( " : " ) [ 1 ] ) ;
} else {
area . setArea ( areaIsp ) ;
}
areaIspList . add ( area ) ;
}
}
model . addAttribute ( " _areaIsps " , areaIspList ) ;
List < RequestInfo > requestInfos = requestInfoService . getAllRequestInfo ( ) ;
model . addAttribute ( " requestInfos " , requestInfos ) ;
List < ServiceDictInfo > fls = serviceDictInfoService . findAllFlDict ( ) ;
@@ -188,29 +244,14 @@ public class IpCfgController extends BaseController{
model . addAttribute ( " xzs " , xzs ) ;
List < ServiceDictInfo > lables = serviceDictInfoService . findAllLableDict ( ) ;
model . addAttribute ( " lables " , lables ) ;
} else if ( serviceId ! = null ) {
ServiceConfigInfo serviceConfigInfo = serviceConfigInfoService . findSysServiceConfigInfo ( serviceId ) ;
if ( serviceConfigInfo ! = null ) {
tableName = serviceConfigInfo . getTableName ( ) ;
if ( ! StringUtils . isBlank ( tableName ) ) {
logger . info ( " table name is " + tableName ) ;
BaseIpCfg searchBean = new BaseIpCfg ( ) ;
searchBean . setCfgId ( cfgId ) ;
searchBean . setTableName ( tableName ) ;
BaseIpCfg ipCfg = ipCfgService . getIpCfgById ( searchBean ) ;
model . addAttribute ( " _cfg " , ipCfg ) ;
model . addAttribute ( " tableName " , tableName ) ;
List < RequestInfo > requestInfos = requestInfoService . getAllRequestInfo ( ) ;
model . addAttribute ( " requestInfos " , requestInfos ) ;
List < ServiceDictInfo > fls = serviceDictInfoService . findAllFlDict ( ) ;
model . addAttribute ( " fls " , fls ) ;
List < ServiceDictInfo > xzs = serviceDictInfoService . findAllXzDict ( ) ;
model . addAttribute ( " xzs " , xzs ) ;
List < ServiceDictInfo > lables = serviceDictInfoService . findAllLableDict ( ) ;
model . addAttribute ( " lables " , lables ) ;
}
}
List < Integer > itTypeList = new ArrayList < Integer > ( ) ;
itTypeList . add ( Constants . ITEM_TYPE_AREA ) ;
List < SysDictInfo > areas = sysDictInfoService . findAllSysDictInfo ( new SysDictInfo ( ) , itTypeList , null ) ;
model . addAttribute ( " areas " , areas ) ;
itTypeList . clear ( ) ;
itTypeList . add ( Constants . ITEM_TYPE_ISP ) ;
List < SysDictInfo > isps = sysDictInfoService . findAllSysDictInfo ( new SysDictInfo ( ) , itTypeList , null ) ;
model . addAttribute ( " isps " , isps ) ;
} else {
logger . error ( " 未获取到正确的表名 " ) ;
}
@@ -228,7 +269,7 @@ public class IpCfgController extends BaseController{
* @since 1.0.0
*/
@RequestMapping ( value = { " saveOrUpdateCfg " } )
public String saveOrUpdateIpCfg ( String cfgName , Model model , BaseIpCfg ipCfg ) {
public String saveOrUpdateIpCfg ( String cfgName , Model model , BaseIpCfg ipCfg , String areaCfgIds ) {
model . addAttribute ( " cfgName " , cfgName ) ;
model . addAttribute ( " cfgType " , " ip " ) ;
model . addAttribute ( " audit " , Constants . CFG_PAGE ) ;
@@ -238,6 +279,38 @@ public class IpCfgController extends BaseController{
logger . info ( " saveOrUpdateIpCfg loaded " ) ;
try {
String tableName = ipCfg . getTableName ( ) ;
List < AreaIpCfg > areaCfg = ipCfg . getAreaCfg ( ) ;
List < AreaBean > areaIsps = ipCfg . getAreaIsp ( ) ;
if ( Constants . IS_AREA_EFFECTIVE_NO = = ipCfg . getIsAreaEffective ( ) ) {
ipCfg . setAreaEffectiveIds ( " " ) ;
ipCfg . setAreaType ( null ) ;
} else if ( Constants . IS_AREA_EFFECTIVE_YES = = ipCfg . getIsAreaEffective ( ) ) {
if ( Constants . AREA_EFFECTIVE_TYPE_AREA_ISP = = ipCfg . getAreaType ( ) & & areaIsps ! = null & & areaIsps . size ( ) > 0 ) {
StringBuffer areaEffectiveIds = new StringBuffer ( ) ;
for ( int i = 0 ; i < areaIsps . size ( ) ; i + + ) {
if ( StringUtils . isNotBlank ( areaIsps . get ( i ) . getIsp ( ) ) ) {
areaEffectiveIds . append ( areaIsps . get ( i ) . getArea ( ) + " : " + areaIsps . get ( i ) . getIsp ( ) ) ;
} else {
areaEffectiveIds . append ( areaIsps . get ( i ) . getArea ( ) ) ;
}
if ( i ! = areaIsps . size ( ) - 1 ) {
areaEffectiveIds . append ( " , " ) ;
}
}
if ( StringUtils . isBlank ( areaEffectiveIds . toString ( ) ) ) {
logger . error ( " 区域管控,且按照地域运营商管控,但是地域运营商为空! " ) ;
addMessage ( model , " save_failed " ) ;
return " /cfg/resultPage " ;
}
ipCfg . setAreaEffectiveIds ( areaEffectiveIds . toString ( ) ) ;
} else if ( Constants . AREA_EFFECTIVE_TYPE_AREA_IP = = ipCfg . getAreaType ( ) & & areaCfg ! = null & & areaCfg . size ( ) > 0 ) {
ipCfg . setAreaEffectiveIds ( " " ) ;
} else {
logger . error ( " 区域管控,但是地域+ISP以及地域IP全部为空! " ) ;
addMessage ( model , " save_failed " ) ;
return " /cfg/resultPage " ;
}
}
int serviceId = ipCfg . getServiceId ( ) ;
if ( StringUtils . isBlank ( tableName ) ) {
ServiceConfigInfo serviceConfigInfo = serviceConfigInfoService . findSysServiceConfigInfo ( serviceId ) ;
@@ -246,23 +319,98 @@ public class IpCfgController extends BaseController{
ipCfg . setTableName ( tableName ) ;
}
}
int compileId = new ConvertTool ( ) . getCompileId ( ) . intValue ( ) ;
if ( ipCfg . getCompileId ( ) = = null ) {
int compileId = new ConvertTool ( ) . getCompileId ( ) . intValue ( ) ;
ipCfg . setCompileId ( compileId ) ;
}
Date date = new Date ( ) ;
ipCfg . setIsValid ( Constants . VALID_NO ) ;
ipCfg . setIsAudit ( Constants . AUDIT_NOT_YET ) ;
ipCfg . setCompileId ( compileId ) ;
if ( ipCfg . getCfgId ( ) = = null ) {
ipCfg . setCreatorId ( ipCfg . getCurrentUser ( ) . getId ( ) ) ;
ipCfg . setCreateTime ( new Date ( ) ) ;
ipCfgService . addIpCfg ( ipCfg ) ;
ipCfg . setCreateTime ( date ) ;
if ( Constants . IS_AREA_EFFECTIVE_YES = = ipCfg . getIsAreaEffective ( ) & & areaCfg ! = null ) {
for ( AreaIpCfg area : areaCfg ) {
area . setTableName ( AreaIpCfg . getTablename ( ) ) ;
area . setServiceId ( serviceId ) ;
area . setCompileId ( ipCfg . getCompileId ( ) ) ;
area . setAction ( ipCfg . getAction ( ) ) ;
area . setIsValid ( Constants . VALID_NO ) ;
area . setIsAudit ( Constants . AUDIT_NOT_YET ) ;
area . setRequestId ( ipCfg . getRequestId ( ) ) ;
area . setClassify ( ipCfg . getClassify ( ) ) ;
area . setAttribute ( ipCfg . getAttribute ( ) ) ;
area . setLable ( ipCfg . getLable ( ) ) ;
area . setCreatorId ( ipCfg . getCurrentUser ( ) . getId ( ) ) ;
area . setCreateTime ( date ) ;
}
}
ipCfgService . addIpCfg ( ipCfg , areaCfg ) ;
} else {
ipCfg . setEditorId ( ipCfg . getCurrentUser ( ) . getId ( ) ) ;
ipCfg . setEditTime ( new Date ( ) ) ;
ipCfgService . updateIpCfg ( ipCfg ) ;
List < AreaIpCfg > updateAreaCfg = new ArrayList < > ( ) ;
List < AreaIpCfg > deleteAreaCfg = new ArrayList < > ( ) ;
List < AreaIpCfg > addAreaCfg = new ArrayList < > ( ) ;
String [ ] cfgIds = null ;
if ( ! StringUtils . isBlank ( areaCfgIds ) ) {
cfgIds = areaCfgIds . split ( " , " ) ;
}
if ( Constants . IS_AREA_EFFECTIVE_YES = = ipCfg . getIsAreaEffective ( ) & & areaCfg ! = null ) {
for ( AreaIpCfg area : areaCfg ) {
area . setTableName ( AreaIpCfg . getTablename ( ) ) ;
area . setServiceId ( serviceId ) ;
area . setCompileId ( ipCfg . getCompileId ( ) ) ;
area . setAction ( ipCfg . getAction ( ) ) ;
area . setIsValid ( Constants . VALID_NO ) ;
area . setIsAudit ( Constants . AUDIT_NOT_YET ) ;
area . setRequestId ( ipCfg . getRequestId ( ) ) ;
area . setClassify ( ipCfg . getClassify ( ) ) ;
area . setAttribute ( ipCfg . getAttribute ( ) ) ;
area . setLable ( ipCfg . getLable ( ) ) ;
if ( area . getCfgId ( ) = = null ) {
area . setCreatorId ( ipCfg . getCurrentUser ( ) . getId ( ) ) ;
area . setCreateTime ( date ) ;
addAreaCfg . add ( area ) ;
} else if ( cfgIds ! = null ) {
area . setEditorId ( ipCfg . getCurrentUser ( ) . getId ( ) ) ;
area . setEditTime ( date ) ;
boolean contains = false ;
for ( String cfgId : cfgIds ) {
if ( ! StringUtils . isBlank ( cfgId ) & & area . getCfgId ( ) . longValue ( ) = = Long . parseLong ( cfgId ) ) {
contains = true ;
break ;
}
}
if ( contains ) {
updateAreaCfg . add ( area ) ;
} else {
deleteAreaCfg . add ( area ) ;
}
}
}
} else {
if ( cfgIds ! = null ) {
for ( String cfgId : cfgIds ) {
if ( ! StringUtils . isBlank ( cfgId ) ) {
AreaIpCfg area = new AreaIpCfg ( ) ;
area . setTableName ( AreaIpCfg . getTablename ( ) ) ;
area . setIsValid ( Constants . VALID_DEL ) ;
area . setCfgId ( Long . parseLong ( cfgId ) ) ;
area . setEditorId ( ipCfg . getCurrentUser ( ) . getId ( ) ) ;
area . setEditTime ( date ) ;
deleteAreaCfg . add ( area ) ;
}
}
}
}
ipCfgService . updateIpCfg ( ipCfg , addAreaCfg , updateAreaCfg , deleteAreaCfg ) ;
}
addMessage ( model , " 保存成功,正在为您跳转页面... " ) ;
addMessage ( model , " save_success " ) ;
} catch ( Exception e ) {
logger . error ( " 保存失败 " , e ) ;
addMessage ( model , " 保存失败! " ) ;
addMessage ( model , " save_failed " ) ;
}
return " /cfg/resultPage " ;
}
@@ -314,15 +462,15 @@ public class IpCfgController extends BaseController{
}
int result = ipCfgService . auditIpCfg ( bean , ipCfg ) ;
if ( result ! = 0 ) {
addMessage ( model , " 审核成功! " ) ;
addMessage ( model , " audit_success " ) ;
} else {
addMessage ( model , " 审核失败 " ) ;
addMessage ( model , " audit_failed " ) ;
}
}
} catch ( Exception e ) {
logger . error ( " 审核失败 " , e ) ;
addMessage ( model , " 审核失败 " ) ;
addMessage ( model , " audit_failed " ) ;
}
return " /cfg/resultPage " ;
}
@@ -361,14 +509,14 @@ public class IpCfgController extends BaseController{
ipCfg . setIsValid ( Constants . VALID_DEL ) ;
int result = ipCfgService . deleteIpCfg ( ipCfg ) ;
model . addAttribute ( " tableName " , tableName ) ;
addMessage ( model , " 删除成功,正在为您跳转页面... " ) ;
addMessage ( model , " delete_success " ) ;
} else {
logger . error ( " 通过审核的配置不能删除! " ) ;
addMessage ( model , " 删除失败! " ) ;
addMessage ( model , " delete_failed " ) ;
}
} catch ( Exception e ) {
logger . error ( " 删除失败 " , e ) ;
addMessage ( model , " 删除失败! " ) ;
addMessage ( model , " delete_failed " ) ;
}
return " /cfg/resultPage " ;
}