All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.afu.utils.common.CommonUtils Maven / Gradle / Ivy

package io.afu.utils.common;

import java.text.SimpleDateFormat;
import java.util.*;

public class CommonUtils {
    /**
     * 生成uuid
     * @return String
     */
    public static String uuid(){
        return UUID.randomUUID().toString().replaceAll("-","");
    }

    /**
     * 获得一个以年月日时分秒以及uuid产生的前6个字符串的订单id,重复几率非常小
     * @return String
     */
    public static String getOrderNo(){
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddhhmmss");
        String datetime = simpleDateFormat.format(new Date());
        String uuid = UUID.randomUUID().toString().replaceAll("-","");
        String partOfUUid = uuid.substring(0,6);
        return datetime+partOfUUid.toUpperCase();
    }

    /**
     * 按照ASCII 表给Map排序并按照GET请求的形式拼接。
     * @param theMap 输入的Map参数
     * @return String
     */
    public static String sortMapByAsciiToString(Map theMap){
        List toSort = new ArrayList<>(theMap.keySet());
        Collections.sort(toSort);
        String toEdit= "";
        for (String key:toSort){
            if (toEdit.equals("")){
                toEdit = key+"="+theMap.get(key);
            }else {
                toEdit = toEdit +"&"+key+"="+theMap.get(key);
            }
        }
        return toEdit;
    }






}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy