• 票号自动生成(按照一定的规则)


    public static Map<Object, Object> invoiceNumberMap;// 票号
    public static final int FOUR_COUNT = 4; // 4位序列号(0001-9999)
    static {
    invoiceNumberMap = new HashMap<Object, Object>();
    }

    /**
    * 得到新的批次号或编号的序列号(001-999)
    * @param map
    * @param key
    * @return
    * @throws Exception
    */
    private Object getNewSerial(Object serialNum, int count) throws Exception {
    String prefix = "";
    if (serialNum == null) {
    for (int i = 0; i < count - 1; i++) {
    prefix += "0";
    }
    return prefix + "1";
    }
    String aSerialNum = serialNum.toString();
    for (int i=0; i<aSerialNum.length(); i++) {
    if (aSerialNum.charAt(i) == '0') {
    prefix += "0";
    } else {
    break;
    }
    }
    int suffix = Integer.parseInt(aSerialNum.substring(prefix.length())) + 1;
    prefix = "";
    for (int i=0; i<count - (suffix + "").length(); i++) {
    prefix += "0";
    }
    return prefix + suffix;
    }
    /**
    *
    *取收据的票号 生成规则: 例:
    *规则:SD+YYYYMMDDD+自增值。示例:201808290003
    /

    public synchronized String getinNum () throws Exception {
    StringBuffer serialNo = new StringBuffer("SD");
    serialNo.append(getCurDate());
    Object newSearial = this.getNewSerial(invoiceNumberMap.get(serialNo.toString()), FOUR_COUNT);
    serialNo.append(newSearial);
    addSerialToSerialMapForServiceNo(invoiceNumberMap, serialNo.toString());
    return serialNo.toString();
    }

    private void addSerialToSerialMapForServiceNo(Map<Object, Object> map, String serialNo) {
    int index = serialNo.length() - 4;
    String key = serialNo.substring(0, index);
    String value = serialNo.substring(index + 1);
    map.put(key, value);
    }

  • 相关阅读:
    codechef Taxi Driver
    BZOJ2190 SDOI2008 仪仗队
    BZOJ 1070: [SCOI2007]修车
    BZOJ 1066 [SCOI2007]蜥蜴
    最大流模板
    表达式计算
    codechef Polo the Penguin and the Tree
    LCA 求 树中两个点的距离
    Baby Step Giant Step model
    POJ 1330 Nearest Common Ancestors (LCA,dfs+ST在线算法)
  • 原文地址:https://www.cnblogs.com/lingding/p/10475102.html
Copyright © 2020-2023  润新知