354798ggg
2023-06-06 c39259bd1486839b25909b4623c24648a34ead49
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package com.product.base.util;
 
import com.product.util.BaseUtil;
 
public class UnUnitCodeUtil {
 
    
    /**
     *     根据同级最大编码,自动生成当前编码
     * @param oldCode    同级最大编码
     * @return
     */
    public static String autoCreateCode(String oldCode) {
        String lastCode = null;
        String prefixCode = null;
        if (oldCode.contains("-")) {
            lastCode = oldCode.substring(oldCode.lastIndexOf("-")+1, oldCode.length());
            prefixCode = oldCode.substring(0, oldCode.lastIndexOf("-")+1);
        }else {
            lastCode = oldCode;
        }
        
        int codeNum = Integer.parseInt(lastCode);
        codeNum++;
        
        String finalLastCode;
        if (codeNum<10) {
            finalLastCode="00"+codeNum;
        }else if(codeNum<100) {
            finalLastCode = "0"+codeNum;
        }else {
            finalLastCode = ""+codeNum;
        }
        
        return (BaseUtil.strIsNull(prefixCode)) ? finalLastCode:prefixCode+finalLastCode;
    }
}