Fx.utils: API function tool class related to tool class
Created by fengjy in 2020/8/4 15:11
1. Extract plain text from html
Fx.utils.htmlParseText(<String html>)
Parameter Description
| parameter | type | description |
| ------------ | ------------ | ----------------------- ----------------------------------------- |
| html | String | extract html content |
return type
APIResult
Return value description
Stirng (extracted text)
Java example
APIResult ret = Fx.utils.htmlParseText("<div class=\"drop-content-item\"><div class=\"drop-box\"><div class=\"drop-box-item drop-box -item2\"style=\"border: none\">\n" +
"<img class=\"img-icon\"style=\"width:20px;\"src=\"https://www.fxiaoke.com/ap/wp-content/uploads/2020/05/icon- live.png\"><ahref=\"/ap/live/\">Live video</a></p>RM open class, CRM usage skills, digital transformation strategy and industry application latest practice and other video content</a></p> div>");
Groovy example
def ret = Fx.utils.htmlParseText('<div class="drop-content-item"><div class="drop-box"><div class="drop-box-item drop-box-item2"style= "border: none">
<img class="img-icon"style="width:20px;"src="https://www.fxiaoke.com/ap/wp-content/uploads/2020/05/icon-live.png">< ahref="/ap/live/">Live video</a></p>RM open class, CRM usage skills, digital transformation strategy and industry application latest practice and other video content</div>')
2. Convert Chinese characters to Pinyin
Fx.utils.toPinyin(<String chinese>)
Parameter Description
| parameter | type | description |
| ------------ | ------------ | ----------------------- ----------------------------------------- |
| chinese | String | Chinese characters |
return type
APIResult
Return value description
Stirng (Pinyin of Chinese characters)
Java example
APIResult ret = Fx.utils.toPinyin("Test");
Groovy example
def ret = Fx.utils.toPinyin("Test");
3. Array splitting
Fx.utils.listPartition(<List list>, <int size>)
Parameter Description
| parameter | type | description |
| ------------ | ------------ | ----------------------- --------------------------------------|
| list | List | The array that needs to be split |
| size | int | the length of each array after splitting |
return type
List
Return value description
List (a collection of arrays split according to the specified size) return value example: [[1,2,3,],[4,5,6],[7,8,9]]
Java example
List original = Lists. newArrayList(1,2,3,4,5,6,7,8,9);
List partition = Fx.utils.listPartition(original,3);
Groovy example
List original = [1,2,3,4,5,6,7,8,9]
List partition = Fx.utils.listPartition(original,3)
4. Array deduplication
Fx.utils.listUnique(<List list>)
Parameter Description
| parameter | type | description |
| ------------ | ------------ | ----------------------- ----------------------------------------- |
| list | List | The list that needs to be deduplicated |
return type
List
Return value description
The list after deduplication
Java example
List list = Lists. newArrayList(1,1,1,2,2,3,4,5);
log.info(Fx.utils.listUnique(list));
Groovy example
def list = [1,1,1,2,2,3,4,5]
log.info(Fx.utils.listUnique(list))
5. String to byte array
Fx.utils.toUTF8Bytes(<String content>)
Parameter Description
| parameter | type | description |
| ------------ | ------------ | ----------------------- ----------------------------------------- |
| content | String | string |
return type
byte[]
Return value description
String
Java example
byte[] bytes = Fx.utils.toUTF8Bytes("Test");
Groovy example
byte[] bytes = Fx.utils.toUTF8Bytes("Test")
6. Convert byte data to string
Fx.utils.toUTF8String(<byte[] bytes>)
Parameter Description
| parameter | type | description |
| ------------ | ------------ | ----------------------- ----------------------------------------- |
| bytes | byte[] | byte array |
return type
String
Return value description
byte[]
Java example
String content = Fx.utils.toUTF8String(bytes);
Groovy example
String content = Fx.utils.toUTF8String(bytes)
7. Calculate the difference between strings
Fx.utils.getLevenshteinDistance(<String left>, <String right>)
Parameter Description
| parameter | type | description |
| ------------ | ------------ | ----------------------- ----------------------------------------- |
| left | String | compare string 1 |
| right | String | compare string 2 |
return type
int
Return value description
8. Get the request source of the terminal
Fx.utils.getRequestSource()
return type
String
Return value description
terminal name
Java example
/ / Get the source of the function execution, return a string
String source = Fx.utils.getRequestSource();
Groovy example
//Android Android
//iOSiOS
//WX WeChat
//WEB page
//FSBrowser share client
//If the query fails to return an empty string (such as behind the process), it can only be obtained when the terminal directly triggers the function (such as clicking a button)
/ / Get the source of the function execution, return a string
String source = Fx.utils.getRequestSource()
9. Return the number of days in the specified year and month
Fx.utils.daysInMonth(<Integer year>, <Integer month>)
Parameter Description
| parameter | type | description |
| ------------ | ------------ | ----------------------- ----------------------------------------- |
| year | Integer | year |
| month | Integer | month |
return type
int
Return value description
Integer
Java example
Fx.utils.daysInMonth(2020, 2); //return 29
Groovy example
Fx.utils.daysInMonth(2020, 2) //return 29
Fx.com.facishare.function.utils.daysInMonth(2020, 2) //return 29
10. Return whether the specified year is a leap year
Fx.utils.isLeapYear(<Integer year>)
Parameter Description
| parameter | type | description |
| ------------ | ------------ | ----------------------- ----------------------------------------- |
| year | Integer | year|
return type
boolean
Return value description
Boolean
Java example
Fx.utils.isLeapYear(2020); //return true
Groovy example
Fx.utils.isLeapYear(2020) //return true
11. Convert byte array to hexadecimal string
Fx.utils.encodeHex(<byte[] bytes>)
Parameter Description
| parameter | type | description |
| ------------ | ------------ | ----------------------- ----------------------------------------- |
| bytes | byte[] | byte array |
return type
String
Return value description
string
12. Convert hexadecimal string to byte array
Fx.utils.decodeHex(<String s>)
Parameter Description
| parameter | type | description |
| ------------ | ------------ | ----------------------- ----------------------------------------- |
| s | String | String |
return type
byte[]
Return value description
13. Convert map value time type to timestamp
BigDecimal type into String
Fx.utils.dataConvert(<Map data>)
Parameter Description
| parameter | type | description |
| ------------ | ------------ | ----------------------- ----------------------------------------- |
| data | Map | Map object |
return type
Map
Return value description
14. Convert digital amount to English uppercase
Fx.utils.amountToEnWords(<String currency>, <BigDecimal bigDecimal>)
Parameter Description
| parameter | type | description |
| ------------ | ------------ | ----------------------- ----------------------------------------- |
| currency | String | Currency types Currently supported are: U.S. dollar-USD, Renminbi-CNY, Euro-EUR, Hong Kong dollar-HKD |
| bigDecimal | BigDecimal | Amount Number |
return type
String
Return value description
string (English uppercase of the amount)
Java example
BigDecimal b = BigDecimal.of("1848.00"); // amount
String en = Fx.utils.amountToEnWords(currTtype, b);
log. info(en);
Groovy example
BigDecimal b = BigDecimal.of("1848.00") // amount
String en = Fx.utils.amountToEnWords(currType, b)
log. info(en)
15. Get current crm language
Fx.utils.getLang()
return type
String
Return value description
String, en: English, zh-CN: Simplified Chinese, zh-TW: Traditional Chinese
Java example
APIResult ret = Fx.utils.getLang();
log. info(ret);