【fix sonar】YouBianCodeUtil文件

This commit is contained in:
梁琦涛
2023-03-10 18:06:03 +08:00
parent ea95382ed9
commit 7b9232f122
@@ -37,31 +37,31 @@ public class YouBianCodeUtil {
String num = getStrNum(1); String num = getStrNum(1);
newcode = zimu + num; newcode = zimu + num;
} else { } else {
String before_code = code.substring(0, code.length() - 1- NUM_LENGTH); String beforeCode = code.substring(0, code.length() - 1- NUM_LENGTH);
String after_code = code.substring(code.length() - 1 - NUM_LENGTH,code.length()); String afterCode = code.substring(code.length() - 1 - NUM_LENGTH,code.length());
char after_code_zimu = after_code.substring(0, 1).charAt(0); char afterCodeZimu = afterCode.substring(0, 1).charAt(0);
Integer after_code_num = Integer.parseInt(after_code.substring(1)); int afterCodeNum = Integer.parseInt(afterCode.substring(1));
String nextNum; String nextNum;
char nextZimu; char nextZimu;
// 先判断数字等于999*,则计数从1重新开始,递增 // 先判断数字等于999*,则计数从1重新开始,递增
if (after_code_num == getMaxNumByLength(NUM_LENGTH)) { if (afterCodeNum == getMaxNumByLength(NUM_LENGTH)) {
nextNum = getNextStrNum(0); nextNum = getNextStrNum(0);
} else { } else {
nextNum = getNextStrNum(after_code_num); nextNum = getNextStrNum(afterCodeNum);
} }
// 先判断数字等于999*,则字母从A重新开始,递增 // 先判断数字等于999*,则字母从A重新开始,递增
if(after_code_num == getMaxNumByLength(NUM_LENGTH)) { if(afterCodeNum == getMaxNumByLength(NUM_LENGTH)) {
nextZimu = getNextZiMu(after_code_zimu); nextZimu = getNextZiMu(afterCodeZimu);
}else{ }else{
nextZimu = after_code_zimu; nextZimu = afterCodeZimu;
} }
// 例如Z99,下一个code就是Z99A01 // 例如Z99,下一个code就是Z99A01
if ('Z' == after_code_zimu && getMaxNumByLength(NUM_LENGTH) == after_code_num) { if ('Z' == afterCodeZimu && getMaxNumByLength(NUM_LENGTH) == afterCodeNum) {
newcode = code + (nextZimu + nextNum); newcode = code + (nextZimu + nextNum);
} else { } else {
newcode = before_code + (nextZimu + nextNum); newcode = beforeCode + (nextZimu + nextNum);
} }
} }
return newcode; return newcode;
@@ -108,8 +108,7 @@ public class YouBianCodeUtil {
* @return * @return
*/ */
private static String getStrNum(int num) { private static String getStrNum(int num) {
String s = String.format("%0" + NUM_LENGTH + "d", num); return String.format("%0" + NUM_LENGTH + "d", num);
return s;
} }
/** /**
@@ -146,11 +145,11 @@ public class YouBianCodeUtil {
if(length==0){ if(length==0){
return 0; return 0;
} }
String max_num = ""; StringBuilder maxNum = new StringBuilder();
for (int i=0;i<length;i++){ for (int i=0;i<length;i++){
max_num = max_num + "9"; maxNum.append("9");
} }
return Integer.parseInt(max_num); return Integer.parseInt(maxNum.toString());
} }
public static String[] cutYouBianCode(String code){ public static String[] cutYouBianCode(String code){
if(code==null || StringUtil.isNullOrEmpty(code)){ if(code==null || StringUtil.isNullOrEmpty(code)){