package com.fs.common.utils;

import java.text.SimpleDateFormat;
import java.util.Date;


public class OrderUtils extends Thread {
    private static long orderNum = 0L;
    private static String date ;

    public static void main(String[] args) throws InterruptedException {
        for (int i = 0; i < 10000; i++) {
            System.out.println(OrderUtils.getOrderNo());
            Thread.sleep(1000);
        }
    }

    /**
     * 生成订单编号
     * @return
     */
    public static synchronized String getOrderNo() {
        String str = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
        if(date==null||!date.equals(str)){
            date = str;
            orderNum  = 0L;
        }
        orderNum ++;
        long orderNo = Long.parseLong((date)) * 10000;
        orderNo += orderNum;
        return orderNo+"";
    }

    public static synchronized String genUserCode() {
        String year = new SimpleDateFormat("yy").format(new Date());
        String day = String.format("%tj", new Date());
        double random = Math.random() * 1000;
        int intRandom = Double.valueOf(random).intValue();
        String verifyCode = year + day + intRandom;
        return verifyCode;
    }


}
