@@ -1,4 +1,5 @@
package com.nis.web.controller.configuration ;
import java.util.ArrayList ;
import java.util.Date ;
import java.util.List ;
@@ -6,6 +7,8 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse ;
import org.apache.commons.lang3.StringUtils ;
import org.apache.shiro.authz.annotation.Logical ;
import org.apache.shiro.authz.annotation.RequiresPermissions ;
import org.springframework.stereotype.Controller ;
import org.springframework.ui.Model ;
import org.springframework.web.bind.annotation.ModelAttribute ;
@@ -14,6 +17,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import com.nis.domain.Page ;
import com.nis.domain.ServiceConfigInfo ;
import com.nis.domain.configuration.AreaIpCfg ;
import com.nis.domain.configuration.BaseIpCfg ;
import com.nis.domain.configuration.BaseStringCfg ;
import com.nis.util.Constants ;
import com.nis.web.controller.BaseController ;
@@ -26,8 +30,23 @@ import com.nis.web.controller.BaseController;
@Controller
@RequestMapping ( " ${adminPath}/cfg/string " )
public class StringCfgController extends BaseController {
/**
*
* stringCfgList(列表界面)
* (这里描述这个方法适用条件 – 可选)
* @param model
* @param audit
* @param cfgName
* @param stringCfg
* @param request
* @param response
* @return
*String
* @exception
* @since 1.0.0
*/
@RequestMapping ( value = { " list " } )
@RequiresPermissions ( value = { " cfg:string:view " } )
public String stringCfgList ( Model model , Integer audit , String cfgName , @ModelAttribute ( " cfg " ) BaseStringCfg stringCfg , HttpServletRequest request , HttpServletResponse response ) {
model . addAttribute ( " cfgName " , cfgName ) ;
model . addAttribute ( " audit " , audit ) ;
@@ -42,7 +61,21 @@ public class StringCfgController extends BaseController{
if ( ! StringUtils . isBlank ( tableName ) ) {
logger . info ( " table name is " + tableName ) ;
stringCfg . setTableName ( tableName ) ;
Page < BaseStringCfg > page = stringCfgService . find Page( new Page < BaseStringCfg > ( request , response , " r " ) , stringCfg ) ;
Page < BaseStringCfg > search Page= new Page < BaseStringCfg > ( request , response , " r " ) ;
String addWhrere = null ;
if ( audit = = Constants . CFG_PAGE ) { //
addWhrere = " r.is_audit in ( " + Constants . AUDIT_NOT_YET + " , " + Constants . AUDIT_NO + " ) " ;
} else if ( audit = = Constants . AUDIT_PAGE ) {
addWhrere = " r.is_audit in ( " + Constants . AUDIT_NOT_YET + " , " + Constants . AUDIT_YES + " ) " ;
}
if ( addWhrere ! = null ) {
if ( StringUtils . isNotBlank ( searchPage . getWhere ( ) ) ) {
searchPage . setWhere ( searchPage . getWhere ( ) + " AND " + addWhrere ) ;
} else {
searchPage . setWhere ( addWhrere ) ;
}
}
Page < BaseStringCfg > page = stringCfgService . findPage ( searchPage , stringCfg ) ;
model . addAttribute ( " page " , page ) ;
model . addAttribute ( " action " , stringCfg . getAction ( ) ) ;
model . addAttribute ( " tableName " , tableName ) ;
@@ -57,7 +90,8 @@ public class StringCfgController extends BaseController{
}
@RequestMapping ( value = { " form " } )
public String stringCfgForm ( int action , String cfgName , Integer serviceId , Model model , HttpServletRequest request , HttpServletResponse response ) {
@RequiresPermissions ( value = { " cfg:string:add " } )
public String stringCfgForm ( int action , String cfgName , Integer serviceId , Model model ) {
model . addAttribute ( " cfgName " , cfgName ) ;
model . addAttribute ( " action " , action ) ;
model . addAttribute ( " serviceId " , serviceId ) ;
@@ -101,7 +135,8 @@ public class StringCfgController extends BaseController{
return " /cfg/stringCfgForm " ;
}
@RequestMapping ( value = { " updateForm " } )
public String updateStringCfgForm ( String tableName , int action , long cfgId , String cfgName , Integer serviceId , Model model ) {
@RequiresPermissions ( value = { " cfg:string:edit " } )
public String updateStringCfgForm ( String tableName , int action , int compileId , String cfgName , Integer serviceId , Model model ) {
model . addAttribute ( " cfgName " , cfgName ) ;
model . addAttribute ( " serviceId " , serviceId ) ;
model . addAttribute ( " action " , action ) ;
@@ -116,9 +151,9 @@ public class StringCfgController extends BaseController{
}
logger . info ( " table name is " + tableName ) ;
BaseStringCfg searchBean = new BaseStringCfg ( ) ;
searchBean . setCfg Id ( cfg Id ) ;
searchBean . setCompile Id ( compile Id ) ;
searchBean . setTableName ( tableName ) ;
BaseStringCfg stringCfg = stringCfgService . getStringCfgById ( searchBean ) ;
BaseStringCfg stringCfg = stringCfgService . get ( searchBean ) ;
model . addAttribute ( " _cfg " , stringCfg ) ;
model . addAttribute ( " tableName " , tableName ) ;
initUpdateFormCondition ( model , stringCfg ) ;
@@ -140,6 +175,7 @@ public class StringCfgController extends BaseController{
* @since 1.0.0
*/
@RequestMapping ( value = { " saveOrUpdateCfg " } )
@RequiresPermissions ( value = { " cfg:string:add " , " cfg:string:edit " } , logical = Logical . OR )
public String saveOrUpdateStringCfg ( String cfgName , Model model , BaseStringCfg stringCfg , String areaCfgIds ) {
model . addAttribute ( " cfgName " , cfgName ) ;
model . addAttribute ( " cfgType " , " string " ) ;
@@ -166,52 +202,65 @@ public class StringCfgController extends BaseController{
* @exception
* @since 1.0.0
*/
@RequestMapping ( value = { " auditCfg " } )
public String auditStringCfg ( String cfgName , BaseStringCfg stringCfg , Model model ) {
@RequestMapping ( value = { " audit " } )
@RequiresPermissions ( value = { " cfg:string:audit " } )
public String auditStringCfg ( String cfgName , int serviceId , int isAudit , int action , String tableName , String ids , Model model ) {
model . addAttribute ( " cfgName " , cfgName ) ;
model . addAttribute ( " audit " , Constants . AUDIT_PAGE ) ;
model . addAttribute ( " cfgType " , " string " ) ;
model . addAttribute ( " serviceId " , stringCfg . getS erviceId ( ) );
model . addAttribute ( " action " , stringCfg . getAction ( ) ) ;
model . addAttribute ( " serviceId " , serviceId ) ;
model . addAttribute ( " action " , action ) ;
try {
String tableName = stringCfg . getTableName ( ) ;
int serviceId = stringCfg . getServiceId ( ) ;
String maatTable = null ;
ServiceConfigInfo serviceConfigInfo = serviceConfigInfoService . findSysServiceConfigInfo ( serviceId ) ;
if ( serviceConfigInfo ! = null ) {
if ( StringUtils . isBlank ( tableName ) ) {
tableName = serviceConfigInfo . getTableName ( ) ;
stringCfg . setTableName ( tableName ) ;
}
maatTable = serviceConfigInfo . getMaatTable ( ) ;
}
BaseStringCfg bean = stringCfgService . getStringCfgById ( stringCfg ) ;
bean . setTableName ( tableName ) ;
int audit = bean . getIsAudit ( ) . intValue ( ) ;
if ( audit = = Constants . AUDIT_YES & & stringCfg . getIsAudit ( ) ! = Constants . AUDIT_NOT_YES ) {
logger . error ( " 审核通过的配置只能取消审核通过! " ) ;
} else {
stringCfg . setAuditorId ( stringCfg . g etCurrentUser ( ) . getId ( ) ) ;
stringCfg . setAuditTime ( new Date ( ) ) ;
bean . setIsAudit ( stringCfg . getIsAudit ( ) ) ;
if ( stringCfg . getIsAudit ( ) = = Constants . AUDIT_NOT_YES ) { //取消审核通过, 设置有效标志为0
stringCfg . setIsValid ( Constants . VALID_NO ) ;
bean . setIsValid ( Constants . VALID_NO ) ;
bean . setMaatTable ( maatTable ) ;
} else if ( stringCfg . getIsAudit ( ) = = Constants . AUDIT_YES ) { //审核通过, 设置有效标志为1
stringCfg . setIsValid ( Constants . VALID_YES ) ;
b ean. setIsValid ( Constants . VALID_YES ) ;
b ean. setMaatTable ( maatTabl e ) ;
if ( StringUtils . isNotBlank ( ids ) ) {
List < BaseStringCfg > beans = stringCfgService . getList ( tableName , ids ) ;
List < BaseStringCfg > auditBeans = new ArrayList < > ( ) ;
List < AreaIpCfg > auditAreaBeans = new ArrayList < > ( ) ;
Date date = new Date ( ) ;
for ( BaseStringCfg bean : beans ) {
BaseStringCfg auditBean = new BaseStringCfg ( ) ;
auditBean . s etTableName ( tableName ) ;
auditBean . setCfgId ( bean . getCfgId ( ) ) ;
bean . setTableName ( tableName ) ;
int audit = bean . getIsAudit ( ) . intValue ( ) ;
if ( audit = = Constants . AUDIT_YES & & isAudit ! = Constants . AUDIT_NOT_YES ) {
logger . error ( " 审核通过的配置只能取消审核通过! " ) ;
addMessage ( model , " audit_failed " ) ;
return " /cfg/resultPage " ;
} else {
auditB ean. setAuditorId ( bean . getCurrentUser ( ) . getId ( ) ) ;
auditB ean. setAuditTime ( dat e ) ;
auditBean . setIsAudit ( isAudit ) ;
bean . setAuditorId ( bean . getCurrentUser ( ) . getId ( ) ) ;
bean . setAuditTime ( date ) ;
bean . setIsAudit ( isAudit ) ;
if ( isAudit = = Constants . AUDIT_NOT_YES ) { //取消审核通过, 设置有效标志为0
auditBean . setIsValid ( Constants . VALID_NO ) ;
auditBean . setMaatTable ( maatTable ) ;
bean . setIsValid ( Constants . VALID_NO ) ;
bean . setMaatTable ( maatTable ) ;
} else if ( isAudit = = Constants . AUDIT_YES ) { //审核通过, 设置有效标志为1
auditBean . setIsValid ( Constants . VALID_YES ) ;
auditBean . setMaatTable ( maatTable ) ;
bean . setIsValid ( Constants . VALID_YES ) ;
bean . setMaatTable ( maatTable ) ;
}
List < AreaIpCfg > areaCfg = ipCfgService . getAreaCfgByCompileId ( bean . getCompileId ( ) ) ;
bean . setAreaCfg ( areaCfg ) ;
auditAreaBeans . addAll ( areaCfg ) ;
}
auditBeans . add ( auditBean ) ;
}
int result = stringCfgService . auditStringCfg ( b ean, stringCfg ) ;
if ( result ! = 0 ) {
addMessage ( model , " audit_success " ) ;
} else {
addMessage ( model , " audit_failed " ) ;
}
stringCfgService . auditStringCfg ( isAudit , auditB eans , auditAreaBeans , beans ) ;
}
addMessage ( model , " audit_success " ) ;
} catch ( Exception e ) {
// TODO: handle exception
logger . error ( " 审核失败 " , e ) ;
@@ -228,8 +277,9 @@ public class StringCfgController extends BaseController{
* @exception
* @since 1.0.0
*/
@RequestMapping ( value = { " deleteCfg " } )
public String deleteStringCfg ( String tableName , int action , long cfgId , int compileId , String cfgName , Integer serviceId , Model model ) {
@RequestMapping ( value = { " delete " } )
@RequiresPermissions ( value = { " cfg:string:delete " } )
public String deleteStringCfg ( String tableName , int action , String ids , String cfgName , Integer serviceId , Model model ) {
model . addAttribute ( " serviceId " , serviceId ) ;
model . addAttribute ( " cfgName " , cfgName ) ;
model . addAttribute ( " action " , action ) ;
@@ -244,33 +294,31 @@ public class StringCfgController extends BaseController{
}
}
model . addAttribute ( " tableName " , tableName ) ;
int audit = stringCfgService . getIsAudit ( tableName , cfgId ) ;
List < AreaIpCfg > areaCfg = ipCfgService . get AreaCfgByCompileId ( compileId ) ;
if ( areaCfg ! = null & & areaCfg . size ( ) > 0 ) {
for ( AreaIpCfg c : areaCfg ) {
c . setTableName ( AreaIpCfg . getTablename ( ) ) ;
List < BaseStringCfg > stringCfgs = new ArrayList < BaseStringCfg > ( ) ;
List < AreaIpCfg > areaCfgs = new ArrayList < AreaIp Cfg> ( ) ;
Date date = new Date ( ) ;
i f( StringUtils . isNotBlank ( ids ) ) {
for ( String compileIdStr : ids . split ( " , " ) ) {
List < AreaIpCfg > areaCfg = ipCfgService . getAreaCfgByCompileId ( Integer . parseInt ( compileIdStr ) ) ;
if ( areaCfg ! = null & & areaCfg . size ( ) > 0 ) {
for ( AreaIpCfg c : areaCfg ) {
c . setTableName ( AreaIpCfg . getTablename ( ) ) ;
c . setEditorId ( c . getCurrentUser ( ) . getId ( ) ) ;
c . setEditTime ( date ) ;
}
}
areaCfgs . addAll ( areaCfg ) ;
BaseStringCfg stringCfg = new BaseStringCfg ( ) ;
stringCfg . setCompileId ( Integer . parseInt ( compileIdStr ) ) ;
stringCfg . setTableName ( tableName ) ;
stringCfg . setEditorId ( stringCfg . getCurrentUser ( ) . getId ( ) ) ;
stringCfg . setEditTime ( date ) ;
stringCfg . setIsValid ( Constants . VALID_DEL ) ;
stringCfgs . add ( stringCfg ) ;
}
}
//未审核时可删除
if ( audit ! = Constants . AUDIT_YES & & audit ! = Constants . AUDIT_NOT_YES ) {
BaseStringCfg stringCfg = new BaseStringCfg ( ) ;
stringCfg . setCfgId ( cfgId ) ;
stringCfg . setTableName ( tableName ) ;
stringCfg . setEditorId ( stringCfg . getCurrentUser ( ) . getId ( ) ) ;
stringCfg . setEditTime ( new Date ( ) ) ;
stringCfg . setIsValid ( Constants . VALID_DEL ) ;
int result = stringCfgService . deleteStringCfg ( stringCfg , areaCfg ) ;
if ( result = = 0 ) {
addMessage ( model , " delete_failed " ) ;
} else {
addMessage ( model , " delete_success " ) ;
}
} else {
logger . error ( " 通过审核/取消审核通过的配置不能删除! " ) ;
addMessage ( model , " delete_failed " ) ;
}
stringCfgService . deleteStringCfg ( stringCfgs , areaCfgs ) ;
addMessage ( model , " delete_success " ) ;
} catch ( Exception e ) {
logger . error ( " 删除失败 " , e ) ;
addMessage ( model , " delete_failed " ) ;