package com.tzy.base;

import com.tzy.common.utils.StringUtils;
import lombok.extern.slf4j.Slf4j;

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

/**
 * 编码的生成规则
 */
@Slf4j
public class RandomUtil {
    //组团工单
    public static String GROUP_INFO = "GI";
    //组团直播
    public static String GROUP_LIVES = "GL";
    //组团用户订单
    public static String GROUP_USER_ORDER = "GU";
    //商品（市场方面的商品）- 代购
    private static String CARD_GOODS = "PG";
    //商户编码 merchant_info
    public static String MERCHANT_CODE = "MC";
    //用户会员码 VIP_CODE
    public static String VIP_CODE = "V";
    //优惠券 COUPON_CARD
    public static String COUPON_CARD = "CC";
    //热点咨询 news_Hot
    public static String news_Hot = "NH";
    //退款单号 REFUND_NO
    public static String REFUND_NO = "RN";
    //系统通知
    public static String SYS_NOTICE = "SN";
    //checklist
    public static String CHECKLIST = "CK";
    //SKU
    public static String SKU = "SK";
    /**
     *
     * @param type
     * @return
     */
    public static String getRandom(String type){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
        // 2 + 14 + 指定随机数(4)
        String randomCode = type + sdf.format(new Date()) + random(4) + random(10);
        if(randomCode.length() > 20){
            return randomCode.substring(0,20);
        }
        return randomCode;
    }

    /**
     *
     * @param length
     * @return
     */
    public static String random(Integer length){
        Random random = new Random();
        String randstr = ""+random.nextInt();
        if(StringUtils.isNotEmpty(randstr)){
            randstr = randstr.replaceAll("-", "").replaceAll("\\\\.", "");
            if(randstr.length() > length) randstr = randstr.substring(0, length);
        }
        return randstr;
    }

    public static void main(String[] args) {
        //System.out.println(RandomUtil.getRandom(RandomUtil.MERCHANT_CODE));
        //System.out.println(RandomUtil.getRandom(RandomUtil.GROUP_USER_ORDER));
       System.out.println((1/3)*1000);
        //System.out.println(SnowFlakeUtil.getId());
    }

}
