# Function classification

Version requirements: v2.3 or above

Functions start with fn., such as fn.date.timestamp(), date is the category, and the gateway has built-in functions of the following categories:

  • Public class fn.common
  • Date class fn.date
  • String class fn.string
  • Codec class fn.codec
  • Math fn.math
  • Data list class fn.list

Example:

# Reference value

Reference values are supported in functions, such as:

fn.string.concat({step1.result.channelCode},{step1.result.nonce})

{step1.result.channelCode} represents the reference value, which refers to the result of step1

fn.string.concat({step1.result.channelCode},{g.account.name})

{g.account.name} represents a reference value, which refers to the public resource "account.name". Starting with g represents a reference to a public resource.

# Nested calls

Supports multiple nested calls, such as:

fn.codec.md5(
     fn.date.add(
         fn.date.add(
             "2021-07-09 22:44:55",
             "yyyy-MM-dd HH:mm:ss",
             1, 
             fn.math.addExact(999,1)
         ),
         "yyyy-MM-dd HH:mm:ss",
         fn.math.addExact(0,1),
         1000
     )
)
fn.string.toUpperCase(
     fn.codec.sha256(
         fn.string.concat(
             {step1.result.channelCode},
             {step1.result.nonce},
             {step1.result.timestamp},
             {step1.result.appSecret}
         )
     )
)

# Public class fn.common

Function Return value type Purpose Parameter description
fn.common.iif(
boolean exprResult,
Object truepart,
Object falsepart)
Object Conditional judgment function, when the first parameter
is true, return the second parameters, otherwise
return the third one
fn.common.iif(true,1,2) returns 1
exprResult: reference value or return value of the function
truepart: first parameter The return value when it is true
falsepart The return value when the first parameter is false
fn.common.equals(
Object obj1, Object obj2)
boolean Determine whether two objects are equal obj1: Object 1
obj2: Object 2
fn.common.isNull(
Object obj)
boolean Determine whether the object is null obj: object
fn.common.isNotNull(
Object obj)
boolean Determine whether the object is not null obj: object
fn.common.isBlank(
String str)
boolean Determine whether the string is empty Str: string
fn.common.isNotBlank(
String str)
boolean Determine whether the string is not empty Str: string
fn.common.isEmpty(
Object obj)
boolean Determine whether the object is empty, mainly used for
List/Map/array/string type objects
obj: object
fn.common.isEmpty(
Object obj)
boolean Determine whether the object is not empty, mainly used for
List/Map/array/string type objects
obj: object
fn.common.and(
Boolean... objs)
boolean Version requirement: v2.7.1 or above
and logical function
objs: Boolean value, multiple
fn.common.or(
Boolean... objs)
boolean Version requirement: v2.7.1 or above
or logical function
objs: Boolean value, multiple
fn.common.not(
Boolean obj)
boolean Version requirement: v2.7.1 or above
Non-logical function
obj: Boolean value
fn.common.emptyList() List Version requirement: v2.7.3 or above
Create an empty list or empty array function
fn.common.emptyMap() Map Version requirement: v2.7.3 or above
Create empty object function

# Date class fn.date

Common date formats:

-yyyy-MM-ddHH:mm:ss

-yyyy-MM-dd

-HH:mm:ss

-HH:mm

  • yyyy-MM-dd HH:mm:ss Z

  • Other reference date format specifications

Function Return value type Purpose Parameter description
fn.date.timestamp() long Generate the current timestamp
fn.date.getTime(String date,
String pattern,
String timeZone)
long Get the timestamp corresponding to the date
fn.date.getTime("2021-08-04" ,"yyyy-MM-dd")
date: date
pattern: date format,
timeZone: [optional] time zone, default East Eighth Zone
For example: GMT+08:00
fn.date.now(String pattern,
String timeZone)
String Get the current time, such as getting the current date:
fn.date.now("yyyy-MM-dd")
pattern: Date format,
Commonly used formats are:
yyyy-MM-dd HH:mm:ss
yyyy-MM-dd
HH:mm:ss
HH:mm
yyyy-MM-dd HH:mm:ss Z
timeZone [Optional] Time zone, default is East Eighth District
For example: GMT+08:00
fn.date.add(String date,
String pattern,
int field, int amount,
String timeZone)
String Add time to date, such as time
" 2021-08-04 14:23:12"Add 5 hours:
fn.date.add("2021-08-04 14:23:12",
"yyyy-MM-dd HH:mm:ss", 4, 5)
Get: 2021-08-04 19:23:12
date: date
pattern: date format of the date parameter
field: date field
1 for millisecond
2 for second
3 for minute
4 for hour
5 for date
6 for month
7 for year
amount: time amount
timeZone [optional] time zone, default East Eighth District
For example: GMT+08:00
fn.date.formatTs(long timestamp,
String pattern,
String timeZone)
String Format timestamp to date timestamp: timestamp
pattern: target date format
timeZone [Optional] Time zone, default is East Eighth District
For example: GMT+08:00
fn.date.changePattern(String dateStr,
String sourcePattern,
String targetPattern,
String timeZone)
String Convert date to another format dateStr: date
sourcePattern: date format of dateStr parameter
targetPattern: target date format
timeZone [optional] time zone, default East Eight Zones
For example: GMT+08:00

# Date format specification

Letter Description Example
G Era code AD
y year 2018(yyyy),18(yy)
M Month July(MMMM), Jul(MMM), 07(MM)
w The result of the week of the year 16
W Results for the week of the month 3
D Day of the year 266
d day 09(dd), 9(d)
F Day of the week 4
E Day of the week Tuesday, Tue
u Day of the week, where 1 represents Monday, 2 represents Tuesday, and so on 2
a AM or PM mark AM
H Hour of day (0-23) 12
k hour of day (1-24) 23
K AM/PM hour in 12-hour format (0-11) 0
h Hour in am/pm, representing 12-hour format (1-12) 12
m minutes 59
s seconds 35
S milliseconds 978
z Time zone Pacific Standard Time; PST; GMT-08:00
Z Time zone offset in hours (RFC mode) -0800
X Time zone offset in ISO format -08; -0800; -08:00

# String class fn.string

Function Return value type Purpose Parameter description
fn.string.equals(String str1,
String str1)
Boolean Whether str1 is equal to str2 str1: string
str2: string
fn.string.equalsIgnoreCase(
String str1,tring str1)
Boolean Whether str1 is equal to (not case sensitive) str2 str1: string
str2: string
fn.string.compare(String str1,
String str1)
Int Compare str1 and str2
Str1 is less than str2 and return -1,
str1 is equal to str2 and return 0,
str1 is greater than str2 and returns 1
str1: string
str2: string
fn.string.concat(String... strs) String Concatenate strings, such as:
fn.string.concat("a","b","c")
Return: abc
Strs: string, multiple
fn.string.concatws(
String separator,
String... strs)
String Concatenate strings, such as:
fn.string.concatws("-","a" ,"b","c")
Return: a-b-c
separator: separator
Strs: string, multiple
fn.string.substring(String str,
int beginIndex, int endIndex)
String Intercept string, such as:
fn.string.substring("abcd",1,2)<br/ >Return: b
fn.string.substring("abcd",1)
Return: bcd
str: string
beginIndex: start subscript
endIndex: [optional 】End subscript
fn.string.indexOf(String str,
String substr)
Int Returns the subscript of the substring, such as:
fn.string.indexOf("abcd", "bd")
Return: 1
str: string
substr: substring
fn.string.startsWith(String str,
String prefix)
Bool Whether the string starts with the specified prefix,
For example:
fn.string.startsWith("abcd", "bd ")
Return: 1
str: string
prefix: prefix
fn.string.endsWith(String str,
String suffix)
Bool Whether the string ends with the specified suffix,
For example:
fn.string.endsWith("abcd","bd")
Return: 1
str: string
suffix: suffix
fn.string.toUpperCase(String str) String Convert to uppercase,
For example:
fn.string.toUpperCase("abcd")
Return: ABCD
str: string
fn.string.toLowerCase(String str) String Convert to lowercase,
For example:
fn.string.toLowerCase("aBCd")
Return: abcd
str: string
fn.string.uuid() String Get UUID,
such as:
fn.string.uuid()
fn.string.replace(String str,
String target,
String replacement)
String Replace the specified string,
such as:
fn.string.replace("abcd ", "bc","111")
Return: a111d
str: string
target: string to be replaced
replacement: replacement string
fn.string.replaceAll(String str,
String regex,
String replacement)
String Replace the string matched by the regular expression,
such as:
fn.string .replaceAll("abcbcd", "bc","111")
Return: a111111d
str: string
regex: regular expression used to match
the string to be replaced< br/>replacement: replacement string
fn.string.replaceFirst(String str,
String regex,
String replacement)
String Replace the first string that matches the regular expression
,
such as:
fn.string.replaceFirst("abcbcd", "bc","111")
Return: a111bcd
str: string
regex: regular expression used for matching
String to be replaced
replacement: string to be replaced

# Codec class fn.codec

Function Return value type Purpose Parameter description
fn.codec.md5(String data) String MD5 encryption, such as:
fn.codec.md5("abc")
Return:
900150983cd24fb0d6963f7
d28e17f72
data : Data that needs to be encrypted
fn.codec.sha1(String data) String SHA1 encryption, such as:
fn.codec.sha1("abc")
Return:
a9993e364706816aba3e2571
7850c26c9cd0d89d
data : Data that needs to be encrypted
fn.codec.sha256(String data) String SHA256 encryption, such as:
fn.codec.sha256("abc")
data: data to be encrypted
fn.codec.sha384(String data) String SHA384 encryption, such as:
fn.codec.sha384("abc")
data: data to be encrypted
fn.codec.sha512(String data) String SHA512 encryption, such as:
fn.codec.sha512("abc")
data: data to be encrypted
fn.codec.base64Encode(
String data)
String base64 encryption, such as:
fn.codec.base64Encode(
"Introduction to Base64 Encoding")
Return:
QmFzZTY057yW56CB5LuL57uN
data: data to be encrypted
fn.codec.base64Decode(
String data)
String base64 decryption, such as:
fn.codec.base64Decode(
"QmFzZTY057yW56CB5LuL57uN")
Return:
Introduction to Base64 encoding
data: data to be decrypted
fn.codec.aesEncrypt(
String data, String key)
String AES encryption, such as:
fn.codec.aesEncrypt("abc",
"1234567812345678")
data: Data to be encrypted
key: key
fn.codec.aesDecrypt(
String data, String key)
String AES decryption, such as:
fn.codec.aesDecrypt("abc",
"1234567812345678")
data: Data to be decrypted
key: key
fn.codec.desEncrypt(
String data, String key)
String DES encryption, such as:
fn.codec.desEncrypt("abc",
"123456781234567812345
67812345678 ")
data: data to be encrypted
key: key
fn.codec.desDecrypt(
String data, String key)
String DES encryption, such as:
fn.codec.desDecrypt("abc",
"123456781234567812345
67812345678 ")
data: data to be decrypted
key: key

# Math class fn.math

Mathematics functions are divided into two categories: integers and floating point numbers. If you are not sure about the type of input parameters, you can use floating point number functions.

Function Return value type Purpose Parameter description
fn.math.absExact(long a) Long Get the absolute value, such as:
fn.math.absExact(-32)
Return: 32
fn.math.absExact(5 )
Return: 5
a: integer
fn.math.negateExact(long a) Long Negation, such as:
fn.math.negateExact(-3)
Return: 3
fn.math.negateExact(5)
Return: -5
a: integer
fn.math.addExact(
long x, long y)
Long Add two integers, such as:
fn.math.addExact(3,2)
Return: 5
x : integer
y: integer
fn.math.subtractExact(
long x, long y)
Long Subtract two integers, such as:
fn.math.subtractExact(3,2)
Return: 1
x : integer
y: integer
fn.math.multiplyExact(
long x, long y)
Long Multiply two integers, such as:
fn.math.multiplyExact(3,2)
Return: 6
x : integer
y: integer
fn.math.maxExact(
long x, long y)
Long Take the maximum value of two integers, such as:
fn.math.maxExact(3,2)
Return: 3
x: integer
y: integer
fn.math.minExact
(long x, long y)
Long Take the minimum value of two integers, such as:
fn.math.minExact(3,2)
Return: 2
x: integer
y: integer
fn.math.mod(long x, long y) Long Modulo, such as:
fn.math.mod(3,2)
Return: 1
x: integer
y: integer
fn.math.pow(double a,
double b)
double Power, such as:
fn.math.pow(3,2)
Return: 9
a: float Point
b: Floating point number
fn.math.sqrt(double a) double Square root, such as:
fn.math.sqrt(9)
Return: 3
a: floating point number
fn.math.random() double Get a random number and return a floating point number between 0 and 1
fn.math.absDecimal(
double a)
double Get the absolute value, such as:
fn.math.absDecimal(-3.2)
Return: 3.2
fn.math .absDecimal(5.1)
Return: 5.1
a: floating point number
fn.math.negateDecimal(
double a)
double Negation, such as:
fn.math.negateDecimal(-3.2)
Return: 3.2
fn.math. negateDecimal(5.2)
Return: -5.2
a: floating point number
fn.math.addDecimal(
double x, double y)
double Add two floating point numbers, such as:
fn.math.addDecimal(3.1,2.2)
Return: 5.3
x: floating point number
y: floating point number
fn.math.subtractDecimal(
double x, double y)
double Subtract two floating point numbers, such as:
fn.math.subtractDecimal(3.1,2.2)
Return: 0.9
x: floating point number
y: floating point number
fn.math.multiplyDecimal(
double x, double y)
double Multiply two floating point numbers, such as:
fn.math.multiplyDecimal(3.2,2)
Return: 6.4
x: floating point number
y: floating point number
fn.math.divideDecimal(
double x, double y)
double Divide two floating point numbers, such as:
fn.math.divideDecimal(4.2,2)
Return: 2.1
x: floating point number
y: floating point number
fn.math.maxDecimal(
double x, double y)
double Take the maximum value of two integers, such as:
fn.math.maxDecimal(3.2,2)
Return: 3.2
x: floating point number
y: floating point number
fn.math.minDecimal(
double x, double y)
double Take the minimum value of two integers, such as:
fn.math.minDecimal(3.2,2)
Return: 2
x: floating point number
y: floating point number
fn.math.scaleDecimal(
double a, int scale)
double Set the number of decimal places and round, such as:
fn.math.scaleDecimal(3.236787,2)
Return: 3.24
a: floating point number
scale: number of decimal places retained
fn.math.compare(
double x, double y)
int Compare x and y
If x is less than y, return -1,
x is equal to y, return 0,
x is greater than y and returns 1
x: floating point number
y: floating point number
fn.math.equals(
double x, double y)
Boolean Determine whether x is equal to y x: floating point number
y: floating point number
fn.math.lt(
double x, double y)
Boolean Determine whether x is less than y x: floating point number
y: floating point number
fn.math.le(
double x, double y)
Boolean Determine whether x is less than or equal to y x: floating point number
y: floating point number
fn.math.gt(
double x, double y)
Boolean Determine whether x is greater than y x: floating point number
y: floating point number
fn.math.ge(
double x, double y)
Boolean Determine whether x is greater than or equal to y x: floating point number
y: floating point number

# Data list class fn.list

Function Return value type Purpose Parameter description
fn.list.expand(
List<List<Object>> data)
ListList<Object> Expand a two-dimensional array (list) into a one-dimensional array (list),
For example:
data=[[{a:1}],[{a:2}],[{a:3}]]
fn.list.expand(data)<br/ >Return: [{a:1},{a:2},{a:3}]
data: two-dimensional array (list)
fn.list.merge(
List<Object>... data)
List<Object> Merge multiple lists into one, such as:
data1=[{a: 1}]
data2=[{a:2}]
data3=[{a:3}]
fn.list.merge(data1,data2,data3)
Return :[{a:1},{a:2},{a:3}]
data: list, can be multiple
fn.list.extract(
List<Map<String, Object>> data,
String... fields)
List<Map<String, Object>> Extract only some fields in the list, such as:
data=[
{a:1,b:4,c:7},
{a:2,b:5,c :8},
{a:3,b:6,c:9}
]
fn.list.extract(data, "a", "c")
Return: [
{a:1,c:7},
{a:2,c:8},
{a:3,c:9}
]
data: list
fields: [optional] fields, there can be multiple
fn.list.join(
List<Map<String, Object>> dest,
List<Map<String, Object>> src,
String joinField,
String... fields)
List<Map<String, Object>> Merge 2 list fields, you can only merge specified fields, such as:
dest=[
{a:1,b:4,c:7},
{a:2,b:5,c:8},
{a:3,b:6,c:9 }
]
src=[
{a:1,d:444,e:777},
{a:2,d:555,e:888}<br/ />]
fn.list.join(dest,src, "a", "d")
Return: [
{a:1,b:4,c:7,d :444},
{a:2,b:5,c:8,d:555},
{a:3,b:6,c:9}
]
dest : Target list
src: The merged list
joinField: The field associated with the two lists
Format:
The associated field of the dest list: The
associated field of the src list , such as: userName:uname,
If the associated fields of the two lists are the same, you can
fill in only one, such as: userName
fields: [Optional] The fields that need to be merged in the merged list, Multiple fields are allowed. If left blank, all fields will be merged
fn.list.rename(
List<Map<String, Object>> data,
String... fieldPairs)
List<Map<String, Object>> Rename some fields in the list, such as:
data=[< br/>{a:1,b:4,c:7},
{a:2,b:5,c:8},
{a:3,b:6,c: 9}
]
fn.list.rename(data, "a:apple", "c:cat")
Return: [
{apple:1,b:4 ,cat:7},
{apple:2,b:5,cat:8},
{apple:3,b:6,cat:9}
]
data: list
fieldPairs: [Optional] The field pairs to be renamed
can be multiple. Format:
Original field name: New field name, such as: c:cat
fn.list.removeFields(
List<Map<String, Object>> data,
String... fields)
List<Map<String, Object>> Delete some fields in the list, such as:
data=[
{a:1,b:4,c:7},
{a:2,b:5,c: 8},
{a:3,b:6,c:9}
]
fn.list.removeFields(data, "b")
Return: [
{a:1,c:7},
{a:2,c:8},
{a:3,c:9}
]
data: list<br/ />fields: [Optional]
fields to be deleted, there can be multiple
fn.list.emptyList() List Version requirement: v2.7.3 or above
Create an empty list or empty array function