zoukankan      html  css  js  c++  java
  • C#生成唯一订单号

    今天系统出了一个问题,发现生成的订单号存在重复的情况了,这是要命的bug,不马上解决,就会有投诉了

    经过改进后的代码我先简单的放一下,后面在慢慢的写清楚整个流程

     string key = "";
                string[] yCode = { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J" };
                Random ran = new Random();
                int randKey = ran.Next(0, 99);
                //获取微秒 ( 底层 api )
                double l = (DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0)).TotalSeconds;
                string unix = Convert.ToString((System.DateTime.Now.Ticks - TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1, 0, 0, 0, 0)).Ticks) / 1000);
               // key = yCode[DateTime.Now.Year - 2011] + Convert.ToString(DateTime.Now.Month, 16).ToUpper() + DateTime.Now.Day + (unix.Substring(unix.Length - 6)) + l.ToString().Substring(0, 5) + randKey.ToString().PadLeft(2, '0');
                key = "ST" + Convert.ToString(DateTime.Now.Month, 16).ToUpper() + DateTime.Now.Day + (unix.Substring(unix.Length - 6)) + l.ToString().Substring(0, 5) + randKey.ToString().PadLeft(2, '0');
    

      

  • 相关阅读:
    旋转数组中的最小数字
    二叉树的遍历:先序,中序,后序,递归,非递归,层次遍历
    重建二叉树
    Combination Sum II
    Combination Sum
    红黑树
    python 时间模块
    docker 常用命令
    python request 和requests 的区别
    python 面试题1
  • 原文地址:https://www.cnblogs.com/wohexiaocai/p/6930991.html
Copyright © 2011-2022 走看看