• 顺丰单号生成规则


    顺丰的单号生成规则:顺丰单号目前12位,主要看倒数第二和第三位,我总结一下规律:如果倒数第二位为9是,看第三位进行相应的跳转(下面代码有注释),倒数第二位不为9,倒数第一位倒退一位。简单地做了个java版的递归

    package com.qinsoft.test;
    
    public class SFNext
    {
        public static void main(String[] args)
        {
            SFNext sf = new SFNext();
            sf.MakeSFNextNo("594338721914");
        }
        private void MakeSFNextNo(String currentNo)
        {
            if (currentNo.length() == 12)
            {
                String newBehindFirstBit = null;
                String frontElevenBits = currentNo.substring(0, 11);
                String behindFirstBit = currentNo.substring(11, 12);
                String behindSecondBit = currentNo.substring(10, 11);
                String behindThirdBit = currentNo.substring(9, 10);
                if (behindSecondBit == "9")
                {
                    switch (Integer.parseInt(behindThirdBit))
                    {
                    /* 倒数第三位0,1,2,4,5,7,8 跳转 4 */
                    case 0:
                    case 1:
                    case 2:
                    case 4:
                    case 5:
                    case 7:
                    case 8:
                        newBehindFirstBit = MakeLastBit(behindFirstBit, 4);
                        break;
                    /* 倒数第三位 3,6 跳转 5 */
                    case 3:
                    case 6:
                        newBehindFirstBit = MakeLastBit(behindFirstBit, 5);
                        break;
                    /* 倒数第三位 9 跳转 7 */
                    case 9:
                        newBehindFirstBit = MakeLastBit(behindFirstBit, 7);
                        break;
                    }
    
                } else
                {
                    newBehindFirstBit = MakeLastBit(behindFirstBit, 1);
                }
                int tempLength = frontElevenBits.length();
                long temp = Long.parseLong(frontElevenBits) + 1;
                String s =  ((temp+"".length() < tempLength) ? "0" + temp : temp) + newBehindFirstBit;
                System.out.println(s);
                MakeSFNextNo(s);
            } 
            else
            {
                System.out.println("没有单号了");
            }
    
        }
    
        private String MakeLastBit(String lastBit, int step)
        {
            int temp = Integer.parseInt(lastBit);
            if ((temp - step) >= 0)
            {
                return (temp - step)+"";
            } else
            {
                return (10 + (temp - step))+"";
            }
        }
    }
  • 相关阅读:
    Rest_framework-3
    Nginx 之一:编译安装nginx 1.8.1 及配置
    vmware虚拟机克隆CentOS7 出现的网络问题解决办法
    OAuth认证
    5个节点hadoop安装(zookeeper)
    hadoop完整安装
    从vmware模板克隆linux的操作
    ssh 免密码设置失败原因总结
    hadoop-2.6.0.tar.gz的集群搭建(3节点)(不含zookeeper集群安装)
    linux静态IP设置
  • 原文地址:https://www.cnblogs.com/hnhcc39/p/2854828.html
Copyright © 2020-2023  润新知