Generate orders based on time

Source: Internet
Author: User

Package util;Import Java. Util. Date;Import Java. Util. Random;Import Java. Util. UUID;/** * Generate Order ID * */public class Orderinfoidutil {public static String getorderinfoid () {random rd=new random ();int M1=rd. Nextint( -);//Generate a random number of 0-23int M2=rd. Nextint( -);String s="ABCDEGHIJKLMNOPQRSTUVWXYZ";Char Rdstring1=s. CharAt(M1)//Get random characters based on random indexChar 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+ One);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", -);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);}}

Generate orders based on time

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.