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("")); } }