package com.zhgd.xmgl.util;

import lombok.extern.slf4j.Slf4j;

/**
 * @program: wisdomSite
 * @description:
 * @author: Mr.Peng
 * @create: 2021-08-16 17:19
 **/
@Slf4j
public class CodeUtils {

    public static String getCode(String code) {
        String[] tempCode = code.split("\\.");
        Integer num = Integer.valueOf(tempCode[tempCode.length - 1]);
        num++;
        StringBuilder builder = new StringBuilder();
        for (int i = 0; i < tempCode.length - 1; i++) {
            builder.append(tempCode[i]).append(".");
        }
        if (num < 10) {
            builder.append("0").append(num);
        } else {
            builder.append(num);
        }
        return builder.toString();
    }

    public static String subCode(String code) {
        if (code.indexOf(".") >= 0) {
            return code.substring(0, code.lastIndexOf("."));
        } else {
            return code;
        }
    }

    public static void main(String[] args) {
        log.info(subCode("08"));
        log.info(subCode("08.01"));
        log.info(subCode("08.01.03"));
    }
}
