给商品excel导入增加校验:校验条码是否是正整数
This commit is contained in:
parent
3cfa290847
commit
d923c8f11a
@ -296,6 +296,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不是正整数";
|
||||
/**
|
||||
* 单据信息
|
||||
* type = 85
|
||||
|
||||
@ -496,6 +496,16 @@ public class MaterialService {
|
||||
String wholesaleDecimal = ExcelUtils.getContent(src, i, 13); //销售价
|
||||
String lowDecimal = ExcelUtils.getContent(src, i, 14); //最低售价
|
||||
String enabled = ExcelUtils.getContent(src, i, 15); //状态
|
||||
//校验基础条码是否是正整数
|
||||
if(!StringUtil.isPositiveInteger(barCode)) {
|
||||
throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_BARCODE_NOT_INTEGER_CODE,
|
||||
String.format(ExceptionConstants.MATERIAL_BARCODE_NOT_INTEGER_MSG, barCode));
|
||||
}
|
||||
//校验副条码是否是正整数
|
||||
if(StringUtil.isNotEmpty(manyBarCode) && !StringUtil.isPositiveInteger(manyBarCode)) {
|
||||
throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_BARCODE_NOT_INTEGER_CODE,
|
||||
String.format(ExceptionConstants.MATERIAL_BARCODE_NOT_INTEGER_MSG, manyBarCode));
|
||||
}
|
||||
//校验条码是否存在
|
||||
List<MaterialVo4Unit> basicMaterialList = getMaterialByBarCode(barCode);
|
||||
if(basicMaterialList!=null && basicMaterialList.size()>0) {
|
||||
|
||||
@ -275,6 +275,28 @@ public class StringUtil {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断对象是否为正整数
|
||||
* @param value
|
||||
* @return
|
||||
*/
|
||||
public static boolean isPositiveInteger(Object value) {
|
||||
if(value!=null) {
|
||||
String str = value.toString();
|
||||
if(isNotEmpty(str)) {
|
||||
if((str.matches("[0-9]+"))&&(Integer.parseInt(str)>0)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* sql注入过滤,保障sql的安全执行
|
||||
* @param originStr
|
||||
|
||||
Loading…
Reference in New Issue
Block a user