個人工具類

一、項目地址:https://gitee.com/winallt/common-utils.git

二、項目結構:

三、功能描述:

3.1、加密功能

支持MD5,Base64和AES,具體方法如下


AESUtil {
	

	/**
	 * AES加密
	 *
	 * @param data
	 * @return
	 * @throws Exception
	 */
	public static String encryptData(String data,String  key) ;

	/**
	 * AES解密
	 *
	 * @param base64Data
	 * @return
	 * @throws Exception
	 */
	public static String decryptData(String base64Data,String  key) ;
}
Base64Util {


    /**
     * 解密
     * @param encodedText
     * @return
     */
    public static String decode(String encodedText);
    /**
     * 加密
     * @param data
     * @return
     */
    public static String encode(String  data) ;

    /**
     * 解密(排除+ ,/這種在URL中必須轉移的字符)
     * @param encodedText
     * @return
     */
    public static String  decodeURL(String encodedText);

    /**
     * 解密(排除+ ,/這種在URL中必須轉移的字符)
     * @param data
     * @return
     */
    public static String encodeURL(String  data) ;

}
MD5Util {
	
	/**
	 * 轉換字節數組爲16進制字串
	 * @param b 字節數組
	 * @return 16進制字串
	 */
	public static String byteArrayToHexString(byte[] b) ;

	/**
	 * 轉換byte到16進制
	 * @param b 要轉換的byte
	 * @return 16進制格式
	 */
	private static String byteToHexString(byte b) ;

	/**
	 * MD5編碼
	 * @param origin 原始字符串
	 * @return 經過MD5加密之後的結果
	 */
	public static String MD5Encode(String origin);

}

3.2 代碼生成功能

GenJavaObjectUtils {


    /**
     *  根據word文檔生成實體類(主要用於對接三方文檔)
     * @param inputStream 輸入的文件流
     * @param entity 實體類相關配置
     * @return
     * @throws IOException
     */
    public static byte[] genEntity(InputStream inputStream, TableEntity entity) ;

    /**
     * 根據json對象生成實體類
     * @param entity
     * @return
     * @throws IOException
     */
    public static byte[] genEntity(JsonEntity entity);
}

3.3 日期對象處理

DateTimeUtils {

    /**
     * 按照指定格式 格式化LocalDateTime
     *
     * @param localDateTime
     * @param formart       默認格式爲yyyy-MM-dd HH:ss:mm
     * @return
     */
    public static String formatLocalDateTime(@NotNull LocalDateTime localDateTime, @Nullable String formart) ;

    /**
     * 按照指定格式 解析String
     *
     * @param dateTimeStr
     * @param formart     默認格式爲yyyy-MM-dd HH:ss:mm
     * @return
     */
    public static LocalDateTime parseLocalDateTime(@NotNull String dateTimeStr, @Nullable String formart);


    /**
     * Date轉LocalDateTime
     *
     * @param date
     * @param zoneId 時區
     * @return
     */
    public static LocalDateTime dateToLocalDateTime(@NotNull Date date, @Nullable ZoneId zoneId);

    /**
     * LocalDateTime轉date
     *
     * @param localDateTime
     * @param zoneOffset    時區
     * @return
     */
    public static Date localDateTimeToDate(LocalDateTime localDateTime, @Nullable ZoneOffset zoneOffset);


    /**
     * 對日期時間更改
     *
     * @param localDateTime
     * @param amount
     * @param type
     * @param zoneOffset
     * @return
     */
    public static LocalDateTime changeLocalDateTimeByType(LocalDateTime localDateTime, int amount, String type, @Nullable ZoneOffset zoneOffset) ;

    /**
     * 根據時間獲取時間戳
     *
     * @param dateTime
     * @return
     */
    public static Long localDateTimeToTimestamp(LocalDateTime dateTime, @Nullable ZoneOffset zoneOffset) ;

    /**
     * 根據時間戳獲取日期時間
     *
     * @param timestamp
     * @return
     */
    public static LocalDateTime timestampToLocalDateTime(@NotNull Long timestamp, @Nullable ZoneOffset zoneOffset) ;

    /**
     *
     * @param date
     * @param type value:start or end
     * @param formart
     * @return
     */
    public static LocalDateTime dateToDateTime(@NotNull String date, @NotNull String type, @Nullable String formart) ;

}

3.4 貨幣處理

CurrencyUtils {


    /**
     * 元轉分
     *
     * @param money 支持字符串,整型,浮點型,BigDecimal
     * @return
     */
    public static BigDecimal yuanToFen(@NotNull Object money);

    /**
     * 分轉元
     *
     * @param money 支持字符串,整型,浮點型,BigDecimal
     * @return
     */
    public static BigDecimal fenToYuan(@NotNull Object money);
    /**
     * 轉漢字
     *
     * @param money 精確到分
     * @return
     */
    public static String toChinese(@NotNull BigDecimal money);
 

}

3.5 郵件發送

MailUtils {

  
    /**
     * 不定人數發送郵件
     * @param title  主題
     * @param content 內容
     * @param address 地址
     * @throws Exception
     */
    public static void send(String title, String content, String... address);

   
}

3.6 IP處理

IpUtils {

    /**
     * 添加白名單(IP4:格式爲xx.xx.xx.xx)
     */
    public static void addWhiteIp(String whiteIp);

    /**
     * 判斷是否在白名單中(IP6:格式爲xx.xx.xx.xx)
     *
     * @param ip
     * @return
     */
    public static boolean isWhiteIp(String ip);


    /**
     * 獲得內網IP
     *
     * @return 內網IP
     */
    private static String getIntranetIp() ;

    /**
     * 獲得外網IP(物理方法,可能獲取虛擬機IP)
     *
     * @return 外網IP
     */
    private static String getInternetIp() ;

    /**
     * 獲取真實公網IP(聯網獲取)
     *
     * @return
     */
    public static String getRemoteIp();
}

3.7 反射增強

ReflectUtils {

    /**
     * 獲取對象的字段(不包括父類)
     *
     * @param t
     * @param access
     * @param <T>
     * @return
     */
    public static <T> Field[] getFields(T t, boolean access);

    /**
     * 獲取對象全部屬性,包括父類的
     * @param t
     * @param <T>
     * @return
     */
    public static <T> Field[] getAllFields(T t);


    /**
     * 獲取父類泛型
     * @param bean
     * @return
     */
    public static Class getSupperGenericInstance(Object bean) ;
}

3.8 對象COPY

ModelMapperUtils {

 
    /**
     * 對象轉對象
     * @param clazz
     * @param source
     * @param <T>
     * @param <D>
     * @return
     */
    public static <T, D> T map(Class<T> clazz, final D source);

    /**
     * 對象轉集合
     * @param clazz
     * @param sources
     * @param <T>
     * @param <D>
     * @return
     */
    public static <T, D> List<T> mapList(Class<T> clazz, final Collection<D> sources) ;

    /**
     * 對象轉Map(支持屬性名和map的key值不一致)
     * @param bean
     * @param needNullParam
     * @return
     */
    public static Map<String, Object> beanToMap(Object bean, boolean needNullParam) ;
}

3.9 word模版技術

WordUtils {

  
    /**
     * 生成word文件
     *
     * @param templatePath 模板所在路徑
     * @param templateName 模板名稱
     * @param targetData  數據源
     */
    public static byte[] createDoc(String templatePath, String templateName, Object targetData) ;


    /**
     * 實現word模板填充
     *
     * @param inputStream
     *            模板輸入流
     * @param bean
     *            待填充的數據
     * @throws IOException
     */
    public static byte[] fillDocx(InputStream inputStream, Object bean) throws IOException ;

   

    /**
     * 將word轉換成html   支持 .doc and .docx
     * @param inputStream
     * @param type
     * @return
     * @throws TransformerException
     * @throws IOException
     * @throws ParserConfigurationException
     */
    public static byte[] wordToHtml(InputStream inputStream,String type,String outPutFilePath)   ;

}

3.10 爬蟲工具

WebMagicUtils {

    /**
     * 抓取
     *
     * @param beginUrl 指定開始抓取的頁面
     * @param linkReg  獲取頁面下滿足要求的鏈接
     * @param xpath    指定抓取的內容
     * @return
     */
    public Map<String, List<String>> getInfo(String beginUrl, String linkReg, Map<String, String> xpath,String proxyPath) ;

}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章