|
@ -1,9 +1,16 @@ |
|
|
package com.elink.esua.epdc.commons.tools.utils; |
|
|
package com.elink.esua.epdc.commons.tools.utils; |
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
|
|
import com.elink.esua.epdc.commons.tools.constant.StrConstant; |
|
|
|
|
|
import com.elink.esua.epdc.commons.tools.exception.RenException; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
|
|
import org.apache.commons.codec.CharEncoding; |
|
|
|
|
|
import org.springframework.util.Base64Utils; |
|
|
|
|
|
|
|
|
|
|
|
import java.io.UnsupportedEncodingException; |
|
|
|
|
|
import java.text.ParseException; |
|
|
|
|
|
import java.text.SimpleDateFormat; |
|
|
import java.util.UUID; |
|
|
import java.util.UUID; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
@ -41,7 +48,7 @@ public class ModuleUtils { |
|
|
* @date 2019/9/5 14:44 |
|
|
* @date 2019/9/5 14:44 |
|
|
*/ |
|
|
*/ |
|
|
public static String generateUUID() { |
|
|
public static String generateUUID() { |
|
|
return UUID.randomUUID().toString().replace("-", ""); |
|
|
return UUID.randomUUID().toString().replace(StrConstant.HYPHEN, ""); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -68,4 +75,63 @@ public class ModuleUtils { |
|
|
return str; |
|
|
return str; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 字符串转换为base64 |
|
|
|
|
|
* |
|
|
|
|
|
* @param params |
|
|
|
|
|
* @return java.lang.String |
|
|
|
|
|
* @author work@yujt.net.cn |
|
|
|
|
|
* @date 2020/2/6 16:39 |
|
|
|
|
|
*/ |
|
|
|
|
|
public static String encodeByBase64(String params) { |
|
|
|
|
|
if (StringUtils.isEmpty(params)) { |
|
|
|
|
|
return null; |
|
|
|
|
|
} |
|
|
|
|
|
try { |
|
|
|
|
|
return Base64Utils.encodeToUrlSafeString(params.getBytes(CharEncoding.UTF_8)); |
|
|
|
|
|
} catch (UnsupportedEncodingException e) { |
|
|
|
|
|
throw new RenException("字符串编码方法异常"); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* base64解码 |
|
|
|
|
|
* |
|
|
|
|
|
* @param base64Str |
|
|
|
|
|
* @return java.lang.String |
|
|
|
|
|
* @author work@yujt.net.cn |
|
|
|
|
|
* @date 2020/2/6 16:48 |
|
|
|
|
|
*/ |
|
|
|
|
|
public static String decodeFromBase64(String base64Str) { |
|
|
|
|
|
if (StringUtils.isEmpty(base64Str)) { |
|
|
|
|
|
return null; |
|
|
|
|
|
} |
|
|
|
|
|
try { |
|
|
|
|
|
return new String(Base64Utils.decodeFromUrlSafeString(base64Str), CharEncoding.UTF_8); |
|
|
|
|
|
} catch (UnsupportedEncodingException e) { |
|
|
|
|
|
throw new RenException("字符串编码方法异常"); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 验证字符串是否是日期格式 |
|
|
|
|
|
* |
|
|
|
|
|
* @param str 被验证的字符串 |
|
|
|
|
|
* @param dateFormat 指定日期格式 |
|
|
|
|
|
* @return boolean |
|
|
|
|
|
* @author work@yujt.net.cn |
|
|
|
|
|
* @date 2020/2/7 10:53 |
|
|
|
|
|
*/ |
|
|
|
|
|
public static boolean isValidDate(String str, String dateFormat) { |
|
|
|
|
|
boolean convertSuccess = true; |
|
|
|
|
|
// 指定日期格式
|
|
|
|
|
|
SimpleDateFormat format = new SimpleDateFormat(dateFormat); |
|
|
|
|
|
try { |
|
|
|
|
|
format.setLenient(false); |
|
|
|
|
|
format.parse(str); |
|
|
|
|
|
} catch (ParseException e) { |
|
|
|
|
|
convertSuccess = false; |
|
|
|
|
|
} |
|
|
|
|
|
return convertSuccess; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|