【fix sonar】YouBianCodeUtil文件
This commit is contained in:
+15
-16
@@ -37,31 +37,31 @@ public class YouBianCodeUtil {
|
||||
String num = getStrNum(1);
|
||||
newcode = zimu + num;
|
||||
} else {
|
||||
String before_code = code.substring(0, code.length() - 1- NUM_LENGTH);
|
||||
String after_code = code.substring(code.length() - 1 - NUM_LENGTH,code.length());
|
||||
char after_code_zimu = after_code.substring(0, 1).charAt(0);
|
||||
Integer after_code_num = Integer.parseInt(after_code.substring(1));
|
||||
String beforeCode = code.substring(0, code.length() - 1- NUM_LENGTH);
|
||||
String afterCode = code.substring(code.length() - 1 - NUM_LENGTH,code.length());
|
||||
char afterCodeZimu = afterCode.substring(0, 1).charAt(0);
|
||||
int afterCodeNum = Integer.parseInt(afterCode.substring(1));
|
||||
|
||||
String nextNum;
|
||||
char nextZimu;
|
||||
// 先判断数字等于999*,则计数从1重新开始,递增
|
||||
if (after_code_num == getMaxNumByLength(NUM_LENGTH)) {
|
||||
if (afterCodeNum == getMaxNumByLength(NUM_LENGTH)) {
|
||||
nextNum = getNextStrNum(0);
|
||||
} else {
|
||||
nextNum = getNextStrNum(after_code_num);
|
||||
nextNum = getNextStrNum(afterCodeNum);
|
||||
}
|
||||
// 先判断数字等于999*,则字母从A重新开始,递增
|
||||
if(after_code_num == getMaxNumByLength(NUM_LENGTH)) {
|
||||
nextZimu = getNextZiMu(after_code_zimu);
|
||||
if(afterCodeNum == getMaxNumByLength(NUM_LENGTH)) {
|
||||
nextZimu = getNextZiMu(afterCodeZimu);
|
||||
}else{
|
||||
nextZimu = after_code_zimu;
|
||||
nextZimu = afterCodeZimu;
|
||||
}
|
||||
|
||||
// 例如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);
|
||||
} else {
|
||||
newcode = before_code + (nextZimu + nextNum);
|
||||
newcode = beforeCode + (nextZimu + nextNum);
|
||||
}
|
||||
}
|
||||
return newcode;
|
||||
@@ -108,8 +108,7 @@ public class YouBianCodeUtil {
|
||||
* @return
|
||||
*/
|
||||
private static String getStrNum(int num) {
|
||||
String s = String.format("%0" + NUM_LENGTH + "d", num);
|
||||
return s;
|
||||
return String.format("%0" + NUM_LENGTH + "d", num);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -146,11 +145,11 @@ public class YouBianCodeUtil {
|
||||
if(length==0){
|
||||
return 0;
|
||||
}
|
||||
String max_num = "";
|
||||
StringBuilder maxNum = new StringBuilder();
|
||||
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){
|
||||
if(code==null || StringUtil.isNullOrEmpty(code)){
|
||||
|
||||
Reference in New Issue
Block a user