@ -89,158 +89,156 @@ public class BeetlConf {
@Bean
public BeetlTemplateCustomize beetlTemplateCustomize ( ) {
return new BeetlTemplateCustomize ( ) {
public void customize ( GroupTemplate groupTemplate ) {
groupTemplate . registerFunctionPackage ( "platform" , platFormService ) ;
groupTemplate . registerFunctionPackage ( "queryCondition" , new QueryParser ( ) ) ;
groupTemplate . registerFunctionPackage ( "dict" , dictDownQueryFunction ) ;
groupTemplate . registerFunctionPackage ( "user" , coreUserFunction ) ;
groupTemplate . registerFunctionPackage ( "isSignRole" , isSignRoleFunction ) ;
groupTemplate . registerFunction ( "core.orgName" , orgFunction ) ;
groupTemplate . registerFunction ( "core.functionName" , funFunction ) ;
groupTemplate . registerFunction ( "core.funAccessUrl" , funAccessUrlFunction ) ;
groupTemplate . registerFunction ( "core.menuName" , menuFunction ) ;
groupTemplate . registerFunction ( "core.searchCondition" , searchConditionFunction ) ;
groupTemplate . registerFunction ( "core.roles" , roleFunction ) ;
groupTemplate . registerFunction ( "core.file" , fileFunction ) ;
groupTemplate . registerFormat ( "xss" , new XXSDefenderFormat ( ) ) ;
groupTemplate . registerFunction ( "uuid" , new UUIDFunction ( ) ) ;
groupTemplate . registerFunction ( "session" , sessionFunction ) ;
groupTemplate . registerFunction ( "core.searchIsShow" , searchIsShowFunction ) ;
// 模板页面判断是否有按钮权限,比如canAccess
groupTemplate . registerFunction ( "canAccess" , ( paras , ctx ) - > {
Long userId = platFormService . getCurrentUser ( ) . getId ( ) ;
Long orgId = platFormService . getCurrentOrgId ( ) ;
String functionCode = ( String ) paras [ 0 ] ;
return platFormService . canAcessFunction ( userId , orgId , functionCode ) ;
} ) ;
groupTemplate . registerFunction ( "abcd" , ( paras , ctx ) - > true ) ;
groupTemplate . registerFunction ( "env" , new Function ( ) {
@Override
public String call ( Object [ ] paras , Context ctx ) {
String key = ( String ) paras [ 0 ] ;
String value = env . getProperty ( key ) ;
if ( value ! = null ) {
return getStr ( value ) ;
}
if ( paras . length = = 2 ) {
return ( String ) paras [ 1 ] ;
}
return null ;
return groupTemplate - > {
groupTemplate . registerFunctionPackage ( "platform" , platFormService ) ;
groupTemplate . registerFunctionPackage ( "queryCondition" , new QueryParser ( ) ) ;
groupTemplate . registerFunctionPackage ( "dict" , dictDownQueryFunction ) ;
groupTemplate . registerFunctionPackage ( "user" , coreUserFunction ) ;
groupTemplate . registerFunctionPackage ( "isSignRole" , isSignRoleFunction ) ;
groupTemplate . registerFunction ( "core.orgName" , orgFunction ) ;
groupTemplate . registerFunction ( "core.functionName" , funFunction ) ;
groupTemplate . registerFunction ( "core.funAccessUrl" , funAccessUrlFunction ) ;
groupTemplate . registerFunction ( "core.menuName" , menuFunction ) ;
groupTemplate . registerFunction ( "core.searchCondition" , searchConditionFunction ) ;
groupTemplate . registerFunction ( "core.roles" , roleFunction ) ;
groupTemplate . registerFunction ( "core.file" , fileFunction ) ;
groupTemplate . registerFormat ( "xss" , new XXSDefenderFormat ( ) ) ;
groupTemplate . registerFunction ( "uuid" , new UUIDFunction ( ) ) ;
groupTemplate . registerFunction ( "session" , sessionFunction ) ;
groupTemplate . registerFunction ( "core.searchIsShow" , searchIsShowFunction ) ;
// 模板页面判断是否有按钮权限,比如canAccess
groupTemplate . registerFunction ( "canAccess" , ( paras , ctx ) - > {
Long userId = platFormService . getCurrentUser ( ) . getId ( ) ;
Long orgId = platFormService . getCurrentOrgId ( ) ;
String functionCode = ( String ) paras [ 0 ] ;
return platFormService . canAcessFunction ( userId , orgId , functionCode ) ;
} ) ;
groupTemplate . registerFunction ( "abcd" , ( paras , ctx ) - > true ) ;
groupTemplate . registerFunction ( "env" , new Function ( ) {
@Override
public String call ( Object [ ] paras , Context ctx ) {
String key = ( String ) paras [ 0 ] ;
String value = env . getProperty ( key ) ;
if ( value ! = null ) {
return getStr ( value ) ;
}
private String getStr ( String str ) {
try {
return new String ( str . getBytes ( "iso8859-1" ) , StandardCharsets . UTF_8 ) ;
} catch ( UnsupportedEncodingException e ) {
throw new RuntimeException ( e ) ;
}
if ( paras . length = = 2 ) {
return ( String ) paras [ 1 ] ;
}
return null ;
}
} ) ;
private String getStr ( String str ) {
try {
return new String ( str . getBytes ( "iso8859-1" ) , StandardCharsets . UTF_8 ) ;
} catch ( UnsupportedEncodingException e ) {
throw new RuntimeException ( e ) ;
}
}
groupTemplate . registerFunction ( "dataAccessList" , ( paras , ctx ) - > dataAccessFactory . all ( ) ) ;
} ) ;
//根据相应的字符分割字符串
groupTemplate . registerFunction ( "splitString" , ( paras , ctx ) - > {
String key = ( String ) paras [ 0 ] ;
if ( key ! = null ) {
if ( paras . length > = 2 ) {
String key2 = ( String ) paras [ 1 ] ;
return Arrays . asList ( key . replace ( "\r" , "" ) . split ( key2 ) ) ;
} else {
return Arrays . asList ( key . replace ( "\r" , "" ) . split ( "\n" ) ) ;
}
}
return new ArrayList < String > ( ) ;
} ) ;
groupTemplate . registerFunction ( "dataAccessList" , ( paras , ctx ) - > dataAccessFactory . all ( ) ) ;
//判断某个字符在相应字符串中的位置
groupTemplate . registerFunction ( "indexOf" , ( paras , ctx ) - > {
String key = ( String ) paras [ 0 ] ;
String val = ( String ) paras [ 1 ] ;
if ( key ! = null ) {
return key . indexOf ( val ) > = 0 ;
//根据相应的字符分割字符串
groupTemplate . registerFunction ( "splitString" , ( paras , ctx ) - > {
String key = ( String ) paras [ 0 ] ;
if ( key ! = null ) {
if ( paras . length > = 2 ) {
String key2 = ( String ) paras [ 1 ] ;
return Arrays . asList ( key . replace ( "\r" , "" ) . split ( key2 ) ) ;
} else {
return Arrays . asList ( key . replace ( "\r" , "" ) . split ( "\n" ) ) ;
}
return false ;
} ) ;
//替换字符串中的所有相应字符
groupTemplate . registerFunction ( "replaceAll" , ( paras , ctx ) - > {
String key = ( String ) paras [ 0 ] ;
if ( key ! = null ) {
if ( paras . length > = 2 ) {
String key2 = ( String ) paras [ 1 ] ;
if ( paras . length = = 3 ) {
return key . replace ( key2 , ( String ) paras [ 2 ] ) ;
} else {
return key . replace ( key2 , "" ) ;
}
}
return new ArrayList < String > ( ) ;
} ) ;
//判断某个字符在相应字符串中的位置
groupTemplate . registerFunction ( "indexOf" , ( paras , ctx ) - > {
String key = ( String ) paras [ 0 ] ;
String val = ( String ) paras [ 1 ] ;
if ( key ! = null ) {
return key . indexOf ( val ) > = 0 ;
}
return false ;
} ) ;
//替换字符串中的所有相应字符
groupTemplate . registerFunction ( "replaceAll" , ( paras , ctx ) - > {
String key = ( String ) paras [ 0 ] ;
if ( key ! = null ) {
if ( paras . length > = 2 ) {
String key2 = ( String ) paras [ 1 ] ;
if ( paras . length = = 3 ) {
return key . replace ( key2 , ( String ) paras [ 2 ] ) ;
} else {
return key ;
return key .replace ( key2 , "" ) ;
}
} else {
return key ;
}
return null ;
} ) ;
//替换字符串中的所有相应字符
groupTemplate . registerFunction ( "replaceAll" , ( paras , ctx ) - > {
String key = ( String ) paras [ 0 ] ;
if ( key ! = null ) {
if ( paras . length > = 2 ) {
String key2 = ( String ) paras [ 1 ] ;
if ( paras . length = = 3 ) {
return key . replace ( key2 , ( String ) paras [ 2 ] ) ;
} else {
return key . replace ( key2 , "" ) ;
}
}
return null ;
} ) ;
//替换字符串中的所有相应字符
groupTemplate . registerFunction ( "replaceAll" , ( paras , ctx ) - > {
String key = ( String ) paras [ 0 ] ;
if ( key ! = null ) {
if ( paras . length > = 2 ) {
String key2 = ( String ) paras [ 1 ] ;
if ( paras . length = = 3 ) {
return key . replace ( key2 , ( String ) paras [ 2 ] ) ;
} else {
return key ;
return key . replace ( key2 , "" ) ;
}
} else {
return key ;
}
return null ;
} ) ;
//根据某个字符分割并且获取长度
groupTemplate . registerFunction ( "splitLength" , ( paras , ctx ) - > {
String key = ( String ) paras [ 0 ] ;
if ( key ! = null ) {
if ( paras . length > = 2 ) {
String key2 = ( String ) paras [ 1 ] ;
return key . replace ( "\r" , "" ) . split ( key2 ) . length ;
} else {
return key . replace ( "\r" , "" ) . split ( "," ) . length ;
}
}
return null ;
} ) ;
//根据某个字符分割并且获取长度
groupTemplate . registerFunction ( "splitLength" , ( paras , ctx ) - > {
String key = ( String ) paras [ 0 ] ;
if ( key ! = null ) {
if ( paras . length > = 2 ) {
String key2 = ( String ) paras [ 1 ] ;
return key . replace ( "\r" , "" ) . split ( key2 ) . length ;
} else {
return key . replace ( "\r" , "" ) . split ( "," ) . length ;
}
return 0 ;
} ) ;
//时间格式转换 Mon Dec 31 00:00:00 CST 2012
groupTemplate . registerFunction ( "simpleDateFormat" , ( paras , ctx ) - > {
String key = null ;
if ( paras [ 0 ] ! = null ) {
key = paras [ 0 ] . toString ( ) ;
}
return 0 ;
} ) ;
//时间格式转换 Mon Dec 31 00:00:00 CST 2012
groupTemplate . registerFunction ( "simpleDateFormat" , ( paras , ctx ) - > {
String key = null ;
if ( paras [ 0 ] ! = null ) {
key = paras [ 0 ] . toString ( ) ;
}
if ( key ! = null ) {
if ( paras . length > = 2 ) {
String key2 = paras [ 1 ] . toString ( ) ;
return TimeTool . getNowTime ( TimeTool . getTime ( key ) , key2 ) ;
} else {
return TimeTool . getNowTime ( TimeTool . getTime ( key ) ) ;
}
if ( key ! = null ) {
if ( paras . length > = 2 ) {
String key2 = paras [ 1 ] . toString ( ) ;
return TimeTool . getNowTime ( TimeTool . getTime ( key ) , key2 ) ;
} else {
return TimeTool . getNowTime ( TimeTool . getTime ( key ) ) ;
}
}
return null ;
} ) ;
//json字符串转数组
groupTemplate . registerFunction ( "JsonString" , ( paras , ctx ) - > {
String key = ( String ) paras [ 0 ] ;
if ( key ! = null ) {
return JSONObject . parse ( key ) ;
}
return new ArrayList < String > ( ) ;
} ) ;
}
}
return null ;
} ) ;
//json字符串转数组
groupTemplate . registerFunction ( "JsonString" , ( paras , ctx ) - > {
String key = ( String ) paras [ 0 ] ;
if ( key ! = null ) {
return JSONObject . parse ( key ) ;
}
return new ArrayList < String > ( ) ;
} ) ;
} ;
}