2021-10-28 08:09:50 +00:00
|
|
|
|
package cn.palmte.work.utils;
|
|
|
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
import top.jfunc.common.crypto.symmetric.AesCrypto;
|
|
|
|
|
|
import top.jfunc.common.crypto.symmetric.Base64Crypto;
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
|
|
|
|
|
|
|
public class Utils {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 解析前端的json条件,封装成map
|
|
|
|
|
|
*/
|
|
|
|
|
|
public static ConcurrentHashMap<String, String> parseMap(String jsonObject) {
|
|
|
|
|
|
ConcurrentHashMap<String, String> searchMap = new ConcurrentHashMap<String, String>();
|
|
|
|
|
|
if (StringUtils.isEmpty(jsonObject)) {
|
|
|
|
|
|
return searchMap;
|
|
|
|
|
|
}
|
|
|
|
|
|
try {
|
|
|
|
|
|
JSONObject jo = JSONObject.parseObject(jsonObject);
|
|
|
|
|
|
for (Map.Entry<String, Object> item : jo.entrySet()) {
|
|
|
|
|
|
String value = item.getValue().toString();
|
|
|
|
|
|
if (!StringUtils.isEmpty(value)) {
|
|
|
|
|
|
searchMap.put(item.getKey(), value);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
}
|
|
|
|
|
|
return searchMap;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 产生excel的名字
|
|
|
|
|
|
*/
|
|
|
|
|
|
public static String generateExcelName(String prefix) {
|
|
|
|
|
|
return prefix + "_" + DateKit.toStr(new Date(), "yyyyMMddHHmmss") + ".xls";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static final Pattern PHONE_PATTERN = Pattern.compile("^1\\d{10}$");
|
|
|
|
|
|
public static boolean isPhone(String str){
|
|
|
|
|
|
return PHONE_PATTERN.matcher(str).matches();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-11-05 04:19:01 +00:00
|
|
|
|
|
|
|
|
|
|
/**
|
2021-12-30 03:19:02 +00:00
|
|
|
|
* 保留两位小数
|
2021-11-05 04:19:01 +00:00
|
|
|
|
*/
|
|
|
|
|
|
public static String format(Number number, String defaultValue){
|
|
|
|
|
|
if (null == number) {
|
|
|
|
|
|
return defaultValue;
|
|
|
|
|
|
}else {
|
2022-01-05 13:13:36 +00:00
|
|
|
|
return new java.text.DecimalFormat("#,##0.00").format(number);
|
2021-11-05 04:19:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
public static String format(Number number){
|
2022-03-01 07:46:19 +00:00
|
|
|
|
return format(number, "0.00");
|
2021-11-05 04:19:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-01-10 08:28:22 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* 保留五位小数
|
|
|
|
|
|
*/
|
|
|
|
|
|
public static String format2(Number number, String defaultValue){
|
|
|
|
|
|
if (null == number) {
|
|
|
|
|
|
return defaultValue;
|
|
|
|
|
|
}else {
|
|
|
|
|
|
return new java.text.DecimalFormat("#,##0.00###").format(number);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
public static String format2(Number number){
|
2022-03-01 07:46:19 +00:00
|
|
|
|
return format(number, "0.00");
|
2022-01-10 08:28:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-11-05 04:19:01 +00:00
|
|
|
|
|
2021-10-28 08:09:50 +00:00
|
|
|
|
public static void main(String[] args) throws Exception {
|
|
|
|
|
|
AesCrypto aesCrypto = new AesCrypto("CDGXQHCJ-HHYC2021017");
|
|
|
|
|
|
String encoded = "fdKQaLHH1kt/pW3s4APoUA==";
|
|
|
|
|
|
byte[] decode = new Base64Crypto().decrypt(encoded.getBytes());
|
|
|
|
|
|
byte[] decrypt = aesCrypto.decrypt(decode);
|
|
|
|
|
|
System.out.println(new String(decrypt));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|