package com.hwrj.cloud.common.util;

import org.apache.catalina.User;

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

public class InvitationCodeUtil {

    private static final String[] storeInvitationChars={"a","c","b","d","f","e","h","i","j","k","l","m","n","o","p"
            ,"q","r","s","t","u","v","w","x","y","z","0","1","2","3","4","5","6","7","8","9"};
    /**
     * @author liushuaic
     * @date 2015/11/18 14:53
     * @desc  生成邀请码
     * 格式： 15（年）+01（月）+18（日）+id
     * */
    public static Integer generateInvitationCode(CompanyInfo companyInfo){
        Date date= Calendar.getInstance().getTime();
        SimpleDateFormat sdf2=new SimpleDateFormat("YYMMdd");
        String dateStr= sdf2.format(date);
        return Integer.valueOf(dateStr+companyInfo.getId().toString());
    }
    /**
     * @author liushuaic
     * @date 2015/11/26 18:01
     * @desc  生成邀请码
     * 格式： abcd12
     * */
    public static String generateInvitationCodeTwo(CompanyInfo user){
        String userIdStr=user.getId().toString();
        int forSize=5-userIdStr.length();
        String randomStr="";
        for(int i=0;i<forSize;i++){
            Random random=new Random();
            int randomIndex=random.nextInt(35);
            randomStr=randomStr+storeInvitationChars[randomIndex];
        }
        return randomStr+userIdStr;
    }
    public static void main(String[] args) {
        //System.out.println(storeInvitationChars.length);
        CompanyInfo user=new CompanyInfo();
        user.setId(23l);
        String invitationCode=InvitationCodeUtil.generateInvitationCodeTwo(user);
        System.out.println(invitationCode);
    }
}
