zoukankan      html  css  js  c++  java
  • 生成流水号DEMO

    /**
    * @auth lengzj
    * @param firstNo 前缀
    * @param lastNo 已存在最大编号
    * @param dateFormatStr 日期格式规则
    * @param leng 末尾长度
    * 例如:XS 201903 001
    * @return
    */
    public static String creatSerialNum(String firstNo,String lastNo,String dateFormatStr,int leng){
    SimpleDateFormat format= new SimpleDateFormat(dateFormatStr);
    String date=format.format(new Date());
    /**
    * 此处可以冲数据库中查询然后进行比较,如果为空默认为lastno如果部位空
    * 讲取出的流水号作为temp,然后截取,累加返回。
    */
    StringBuffer sb=new StringBuffer();
    String temp=lastNo.substring(lastNo.length()-leng, lastNo.length());

    int num = (int)Math.pow(10,leng)-1;

    if(Integer.parseInt(temp)>=1&&Integer.parseInt(temp)<num){
    temp=String.valueOf(Integer.parseInt(temp)+1);
    }

    String seat="";
    for(int i=0;i<leng-temp.length();i++){
    seat=seat+"0";
    }
    temp=seat+temp;

    lastNo=firstNo+date+temp;
    return lastNo;

    }


    public static void main(String[] args) {
    String no=creatSerialNum("NNN","NNN201903200001","yyyyMMdd",4);
    System.out.println("流水号"+' '+no);

    }
  • 相关阅读:
    虚拟内存分页机制的页面置换
    wait函数的作用
    Kubernetes中Pod生命周期
    ufw 禁用端口未生效
    Kubernetes各个组件的概念
    Kubernetes存储卷的使用
    虚拟内存分页机制的地址映射
    GUNgettext 无效
    响应HTTP服务的shell脚本
    yaml语法
  • 原文地址:https://www.cnblogs.com/lengzhijun/p/4919417.html
Copyright © 2011-2022 走看看