package com.yh.saas.plugin.yiliangyiyun.util;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * Created by rize on 2019/7/1.
 */
public class GeneratorUtil {

    private static  AtomicInteger orderIdCount = new AtomicInteger();
    private static  AtomicInteger tranContractCount = new AtomicInteger();

    private static  SimpleDateFormat ORDER_ID_FORMAT = new SimpleDateFormat("yyyyMMDDHHmmss");

    public static String genSixVerifyCode() {
        String time = System.nanoTime() + "";
        return time.substring(time.length() - 6);
    }

    public static String genSessionId() {
        return UUID.randomUUID().toString().replace("-","").toUpperCase();
    }


    public static String genOrderId(String head) {
        int i = orderIdCount.incrementAndGet() % 100;
        if (i < 100)
            i += 100;
        return head + ORDER_ID_FORMAT.format(new Date()) + i;
    }
    public static String genContractNo(String head) {
        int i = tranContractCount.incrementAndGet() % 100;
        if (i < 100)
            i += 100;
        return head + ORDER_ID_FORMAT.format(new Date()) + i;
    }
    public static String genFileName(){
        return UUID.randomUUID().toString().replaceAll("-", "");
    }

    public static String genUUId() {
        return UUID.randomUUID().toString().replace("-", "");
    }

}
