Kaynağa Gözat

处理批量上架报错的问题。

yujia 7 yıl önce
ebeveyn
işleme
832f1e4f0b

+ 37 - 20
src/main/java/com/uas/platform/b2c/prod/commodity/service/impl/ReleaseProductByBatchServiceImpl.java

@@ -1224,16 +1224,18 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
 					rowNum, ModifyConstant.PRICE_SECOND);
 		}
 		if (!StringUtils.isEmpty(startValue) && !StringUtils.isEmpty(priceValue)) {
-			Double price = Double.valueOf(priceValue.toString());
-			Double start = Double.valueOf(startValue.toString());
-			if (validatePrice(price) && validateStartNumber(start, aProduct.getMinBuyQty())) {
-				GoodsQtyPrice qtyPrice = getOneQtyPrice(Double.valueOf(startValue.toString()), DoubleConstant.maxMinPackageQty,
-						price, aProduct.getRmbTaxRate(), aProduct.getCurrency());
-				qtyPriceList.add(qtyPrice);
-				qtyPriceList.get(0).setEnd(Double.valueOf(startValue.toString()) - 1);
-				setThirdPrice(row, isImport, rowNum, qtyPriceList, aProduct);
+			if (RegexConstant.isNumber(startValue.toString())  && RegexConstant.isNumber(priceValue.toString())) {
+				Double price = Double.valueOf(priceValue.toString());
+				Double start = Double.valueOf(startValue.toString());
+				if (validatePrice(price) && validateStartNumber(start, aProduct.getMinBuyQty())) {
+					GoodsQtyPrice qtyPrice = getOneQtyPrice(Double.valueOf(startValue.toString()), DoubleConstant.maxMinPackageQty,
+							price, aProduct.getRmbTaxRate(), aProduct.getCurrency());
+					qtyPriceList.add(qtyPrice);
+					qtyPriceList.get(0).setEnd(Double.valueOf(startValue.toString()) - 1);
+					setThirdPrice(row, isImport, rowNum, qtyPriceList, aProduct);
+				}
+				return ;
 			}
-			return ;
 		}
 		if (StringUtils.isEmpty(startValue) && StringUtils.isEmpty(priceValue)) {
 			setThirdPrice(row, isImport, rowNum, qtyPriceList, aProduct);
@@ -1262,14 +1264,16 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
 					rowNum, ModifyConstant.PRICE_THIRD);
 		}
 		if (!StringUtils.isEmpty(startValue) && !StringUtils.isEmpty(priceValue)) {
-			Double price = Double.valueOf(priceValue.toString());
-			Double start = Double.valueOf(startValue.toString());
-			Double lastEnd = qtyPriceList.get(qtyPriceList.size() - 1).getStart();
-			if (validatePrice(price) && validateStartNumber(start, lastEnd)) {
-				GoodsQtyPrice qtyPrice = getOneQtyPrice(start, DoubleConstant.maxMinPackageQty,
-						price, aProduct.getRmbTaxRate(), aProduct.getCurrency());
-				qtyPriceList.get(qtyPriceList.size() - 1).setEnd(start - 1);
-				qtyPriceList.add(qtyPrice);
+			if (RegexConstant.isNumber(startValue.toString())  && RegexConstant.isNumber(priceValue.toString())) {
+				Double price = Double.valueOf(priceValue.toString());
+				Double start = Double.valueOf(startValue.toString());
+				Double lastEnd = qtyPriceList.get(qtyPriceList.size() - 1).getStart();
+				if (validatePrice(price) && validateStartNumber(start, lastEnd)) {
+					GoodsQtyPrice qtyPrice = getOneQtyPrice(start, DoubleConstant.maxMinPackageQty,
+							price, aProduct.getRmbTaxRate(), aProduct.getCurrency());
+					qtyPriceList.get(qtyPriceList.size() - 1).setEnd(start - 1);
+					qtyPriceList.add(qtyPrice);
+				}
 			}
 		}
 	}
@@ -1337,7 +1341,11 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
 			if (cell != null && cell.getCellType() != Cell.CELL_TYPE_BLANK) {
 				switch (cellType) {
 				case Cell.CELL_TYPE_STRING :
-					cell.setCellType(HSSFCell.CELL_TYPE_STRING);
+					try {
+						cell.setCellType(HSSFCell.CELL_TYPE_STRING);
+					} catch (Exception e) {
+						throw new IllegalOperatorException("读取表格中"+ (r + 1)+"行"+ (n+1)+ "列的内容错误,需要文本格式的信息");
+					}
 					String str = cell.getStringCellValue().trim();
 //					Object data = getCellData(cell);
 //					String str = data == null ? "" : data.toString();
@@ -1348,7 +1356,11 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
 					obj = str.trim();
 					break;
 				case Cell.CELL_TYPE_NUMERIC :
-					cell.setCellType(Cell.CELL_TYPE_NUMERIC);
+					try {
+						cell.setCellType(Cell.CELL_TYPE_NUMERIC);
+					} catch (Exception e) {
+						throw new IllegalOperatorException("读取表格中"+ (r + 1)+"行"+ (n+1)+ "列的内容错误,需要数字格式的信息");
+					}
 					obj = cell.getNumericCellValue();
 					if (obj != null) {
 						if(obj.toString().indexOf("E") > 0) {
@@ -1375,7 +1387,12 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
 				}
 			}
 		} catch (Exception e) {
-			throw new IllegalOperatorException("读取表格中"+r+"行"+ (n+1)+ "列的内容错误,有可能是该单元格的格式不正确");
+			String message = e.getMessage();
+			if (message.contains("读取表格")) {
+				throw new IllegalOperatorException(message);
+			} else {
+				throw new IllegalOperatorException("读取表格中"+(r + 1)+"行"+ (n+1)+ "列的内容错误,有可能是该单元格的格式不正确");
+			}
 		}
 		return obj;
 	}