zoukankan      html  css  js  c++  java
  • 顺丰单号生成规则

    顺丰的单号生成规则:顺丰单号目前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))+"";
            }
        }
    }
  • 相关阅读:
    自考新教材--p78
    自考新教材--p76_2
    自考新教材--p76_1
    自考新教材--p75
    自考新教材--p70
    自考新教材--p69
    以HTML5及其衍生技术为基础的B/S架构实时视频监控解决方案
    智能化安防视频监控行业发展是如何转变的?
    摄像头视频监控是如何与流媒体服务器云平台连接的?
    如何实现摄像头监控数据实时存储及传输?
  • 原文地址:https://www.cnblogs.com/hnhcc39/p/2854828.html
Copyright © 2011-2022 走看看