354798ggg
2023-07-21 e31fe4140580a730dcb2f2aecb6ac0d7a66df7c0
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package com.product.project.management.util;
 
import com.product.util.BaseUtil;
 
public class ProjectItemUtil {
 
    /**
     *     根据同级最大编码,自动生成当前编码
     * @param oldCode    同级最大编码
     * @return
     */
    public static String autoAddOneCode(String oldCode) {
        if (BaseUtil.strIsNull(oldCode)) {
            oldCode = "000";
        }
        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;
    }
    
    public static String autoCreateCode(String parentCode) {
        if (BaseUtil.strIsNull(parentCode)) {
            return "001";
        }else {
            return parentCode+"-001";
        }
    }
    
    public static void main(String[] args) {
        System.out.println(autoCreateCode(""));
    }
}