package com.fdkankan.common.util;

import org.joda.time.DateTime;

import java.util.Random;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;

public class NumberUtils {

    private static AtomicInteger orderNum = new AtomicInteger(10);
    private static AtomicInteger productNum = new AtomicInteger(10);
    private static AtomicInteger skuNum = new AtomicInteger(10);

    /**
     * 生成订单编号
     * @return
     */
    public static String getOrderNo() {
        long orderNo = DateTime.now().getMillis() * 10000;
        orderNo += orderNum.incrementAndGet();
        return "O"+orderNo;
    }

    /**
     * 生成订单编号
     * @return
     */
    public static String getOrderSn(){
//        DateTime dateTime = new DateTime();
//        return dateTime.toString("yyyyMMddhhmmss") +RandomUtil.generateShortUuid();
        long orderNo = DateTime.now().getMillis() * 10000;
        orderNo += orderNum.incrementAndGet();
        return "O"+orderNo;
    }

    /**
     * 生成商品编号
     * @return
     */
    public static String getGoodsNo() {
        long productNo = DateTime.now().getMillis() * 10000;
        productNo += productNum.incrementAndGet();
        return "P"+productNo;
    }

    /**
     * 生成sku编号
     * @return
     */
    public static String getSkuNo() {
        long skuNo = DateTime.now().getMillis() * 10000;
        skuNo += skuNum.incrementAndGet();
        return "U"+skuNo;
    }

    public static synchronized String create15() {
        String strDate = new DateTime().toString("yyMMddHHmmss");
        String random = getRandom620(3);
        return strDate+random;
    }

    /**
     * 获取6-10 的随机位数数字
     * @param length	想要生成的长度
     * @return result
     */
    public static String getRandom620(Integer length) {
        String result = "";
        Random rand = new Random();
        int n = 20;
        if (null != length && length > 0) {
            n = length;
        }
        int randInt = 0;
        for (int i = 0; i < n; i++) {
            randInt = rand.nextInt(10);
            result += randInt;
        }
        return result;
    }

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