码迷,mamicode.com
首页 > 其他好文 > 详细

根据时间生成订单

时间:2015-02-27 18:30:41      阅读:168      评论:0      收藏:0      [点我收藏+]

标签:

package util;

import java.util.Date;
import java.util.Random;
import java.util.UUID;

/**
 * 生成订单Id
 *
 */
public class OrderInfoIdUtil {

    public static String getOrderInfoId(){
         Random rd=new Random();
            int m1=rd.nextInt(24);//生成0-23的随机数
            int m2=rd.nextInt(24);
            String s="abcdeghijklmnopqrstuvwxyz";
            char rdString1=s.charAt(m1);//根据随机的索引获得随机的字符
            char rdString2=s.charAt(m2);
            String ss = String.valueOf(9999-(System.currentTimeMillis()/1000000)%10000);
            while(ss.length()<4){
                ss = "0"+ss;
            }
            String u0 = String.valueOf(ss.charAt(0));
            String u1 = String.valueOf(ss.charAt(1));
            String u2 = String.valueOf(ss.charAt(2));
            String u3 = String.valueOf(ss.charAt(3));
            int iu1 = Integer.parseInt(u1);
            char rdStringiu1=s.charAt(iu1);
            int iu2 = Integer.parseInt(u2);
            char rdStringiu2=s.charAt(iu2+11);
            StringBuffer s0 = new StringBuffer() ;
                         s0.append(String.valueOf(rdStringiu1));
                         s0.append(String.valueOf(rdStringiu2));
                         s0.append(u0);
                         s0.append(u3);
                         s0.append(String.valueOf(rdString1));
                         s0.append(String.valueOf(rdString2));
                         s0.append(String.valueOf(System.currentTimeMillis()%1000000));

            System.out.println(s0);
        return s0.toString();
    }

    public static String getOrderInfId(){
        String sa  = "SO";
        Date d = new Date();
        String u = DateUtil.getCurDateString(d);
        u = u.replace("-", "");
        sa += u;
        RedisUtils rs = RedisUtils.getInstance();
        rs.setString("orderinfo", 50);
        if(rs.getString("orderinfoday")==null){
             rs.setString("orderinfoday", u);
             rs.setString("orderinfo", 1);
        }else{
            if(!rs.getString("orderinfoday").equals(u)){
                 rs.setString("orderinfoday", u);
                 rs.setString("orderinfo", 1);
            }else{
            rs.incrString("orderinfo");
            }
        }
        String uu = rs.getString("orderinfo");
        while(uu.length()<3){
            uu = "0"+uu;
        }
        return sa+uu;   
    }

    public static void main(String[] args){
        String i = getOrderInfId();
        System.out.println(i);
        String uuid=UUID.randomUUID().toString();
        System.out.println(uuid);
    }
}

根据时间生成订单

标签:

原文地址:http://blog.csdn.net/u011328015/article/details/43969907

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!