Excel导入,校验商品条码长度为4到40位

This commit is contained in:
季圣华
2023-03-01 23:14:42 +08:00
parent d2e56aa3ae
commit 4bbce58f3f
3 changed files with 33 additions and 11 deletions

View File

@@ -287,9 +287,9 @@ public class ExceptionConstants {
//商品-单位匹配不上
public static final int MATERIAL_UNIT_MATE_CODE = 8000006;
public static final String MATERIAL_UNIT_MATE_MSG = "抱歉,商品条码:%s的单位匹配不上请完善计量单位信息";
//商品条码不是正整数
public static final int MATERIAL_BARCODE_NOT_INTEGER_CODE = 8000007;
public static final String MATERIAL_BARCODE_NOT_INTEGER_MSG = "商品条码:%s不是正整数";
//商品条码长度应该为4到40位
public static final int MATERIAL_BARCODE_LENGTH_ERROR_CODE = 8000007;
public static final String MATERIAL_BARCODE_LENGTH_ERROR_MSG = "商品条码长度应该为4到40位";
//序列号和批号只能有一项
public static final int MATERIAL_ENABLE_MUST_ONE_CODE = 8000008;
public static final String MATERIAL_ENABLE_MUST_ONE_MSG = "抱歉,商品条码:%s的序列号和批号不能同时填1";

View File

@@ -545,15 +545,15 @@ public class MaterialService {
throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_ENABLED_ERROR_CODE,
String.format(ExceptionConstants.MATERIAL_ENABLED_ERROR_MSG, i+1));
}
//校验基础条码是否是正整数
if(!StringUtil.isPositiveLong(barCode)) {
throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_BARCODE_NOT_INTEGER_CODE,
String.format(ExceptionConstants.MATERIAL_BARCODE_NOT_INTEGER_MSG, barCode));
//校验基础条码长度为4到40位
if(!StringUtil.checkBarCodeLength(barCode)) {
throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_BARCODE_LENGTH_ERROR_CODE,
String.format(ExceptionConstants.MATERIAL_BARCODE_LENGTH_ERROR_MSG, barCode));
}
//校验副条码是否是正整数
if(StringUtil.isNotEmpty(manyBarCode) && !StringUtil.isPositiveLong(manyBarCode)) {
throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_BARCODE_NOT_INTEGER_CODE,
String.format(ExceptionConstants.MATERIAL_BARCODE_NOT_INTEGER_MSG, manyBarCode));
//校验副条码长度为4到40位
if(StringUtil.isNotEmpty(manyBarCode) && !StringUtil.checkBarCodeLength(manyBarCode)) {
throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_BARCODE_LENGTH_ERROR_CODE,
String.format(ExceptionConstants.MATERIAL_BARCODE_LENGTH_ERROR_MSG, manyBarCode));
}
//批量校验excel中有无重复条码
batchCheckExistBarCodeByParam(mList, barCode, manyBarCode);

View File

@@ -317,6 +317,28 @@ public class StringUtil {
}
}
/**
* 校验条码长度为4到40位
* @param value
* @return
*/
public static boolean checkBarCodeLength(Object value) {
if(value!=null) {
String str = value.toString();
if(isNotEmpty(str)) {
if(str.length()>=4 && str.length()<=40 ) {
return true;
} else {
return false;
}
} else {
return false;
}
} else {
return false;
}
}
/**
* 判断对象是否为数字(含小数)
* @param str