Browse Source

处理上传数据丢失的问题

hulh 8 years ago
parent
commit
84557f43d4

+ 2 - 1
src/main/java/com/uas/platform/b2c/prod/commodity/constant/ErrorInfoConstant.java

@@ -22,7 +22,8 @@ public enum  ErrorInfoConstant {
     DELIVERY_EMPTY_INFO("G-H列:存在交期的信息为空"),
     DELIVERY_EMPTY_INFO("G-H列:存在交期的信息为空"),
     DELIVERY_VALUE_INFO("G-H列:交期只能填写1-31之间的整数值"),
     DELIVERY_VALUE_INFO("G-H列:交期只能填写1-31之间的整数值"),
     PRICE_INFO("K列:单价必须是小于1万的正数"),
     PRICE_INFO("K列:单价必须是小于1万的正数"),
-    MIN_PACKAGE_INFO("I列:最小包数量包含非数字字符");
+    MIN_PACKAGE_INFO("I列:最小包数量包含非数字字符"),
+    REPEAT_IN_EXCEL("");
 
 
     /**
     /**
      * 错误提示
      * 错误提示

+ 2 - 0
src/main/java/com/uas/platform/b2c/prod/commodity/model/ReleaseProductByBatch.java

@@ -473,6 +473,8 @@ public class ReleaseProductByBatch implements Serializable {
 	@Column(name = "rel_storename")
 	@Column(name = "rel_storename")
 	private String storeName;
 	private String storeName;
 
 
+//	private Short repeat;
+
 	@Override
 	@Override
 	public boolean equals(Object o) {
 	public boolean equals(Object o) {
 		if (this == o) return true;
 		if (this == o) return true;

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

@@ -131,7 +131,6 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
 			selfSale = false;
 			selfSale = false;
 		}
 		}
 		ModelMap modelMap = new ModelMap();
 		ModelMap modelMap = new ModelMap();
-		Set<ReleaseProductByBatch> releaseProductByBatchs = new HashSet<>();
 		// 获取第一个工作表
 		// 获取第一个工作表
 		Sheet sheet = workbook.getSheetAt(0);
 		Sheet sheet = workbook.getSheetAt(0);
 		int colNum = sheet.getRow(0).getPhysicalNumberOfCells();
 		int colNum = sheet.getRow(0).getPhysicalNumberOfCells();
@@ -149,6 +148,7 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
 			throw new IllegalOperatorException
 			throw new IllegalOperatorException
 					("您上传的信息超过2000条,请拆分成2000以再在上传");
 					("您上传的信息超过2000条,请拆分成2000以再在上传");
 		}
 		}
+		List<ReleaseProductByBatch> releaseProductByBatchs = new ArrayList<>(rowNum);
 		String batch = createNumberService.getTimeNumber("product$goods", 8, rowNum);
 		String batch = createNumberService.getTimeNumber("product$goods", 8, rowNum);
 		StoreIn storeIn = getStoreInfo(selfSale);
 		StoreIn storeIn = getStoreInfo(selfSale);
 		Row headerRow = sheet.getRow(0);
 		Row headerRow = sheet.getRow(0);
@@ -191,6 +191,7 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
 								releaseProductByBatch.setTag(null);
 								releaseProductByBatch.setTag(null);
 							}
 							}
 						}
 						}
+						validateRepeatInExcel(releaseProductByBatchs, releaseProductByBatch);
 					}
 					}
 					// 简单验证数据,防止空行保存的情况
 					// 简单验证数据,防止空行保存的情况
 					if (blankNum != 3) {
 					if (blankNum != 3) {
@@ -200,12 +201,10 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
 				}
 				}
 			}
 			}
 		}
 		}
-		List<ReleaseProductByBatch> addList = new ArrayList<>(releaseProductByBatchs.size());
-		addList.addAll(releaseProductByBatchs);
 		if (!isAPerson) {
 		if (!isAPerson) {
-			resetRepeatData(addList);
+			resetRepeatData(releaseProductByBatchs);
 		}
 		}
-		commonDao.save(addList, ReleaseProductByBatch.class);
+		commonDao.save(releaseProductByBatchs, ReleaseProductByBatch.class);
 		Long userUU = SystemSession.getUser().getUserUU();
 		Long userUU = SystemSession.getUser().getUserUU();
 		Long enUU = SystemSession.getUser().getEnterprise().getUu();
 		Long enUU = SystemSession.getUser().getEnterprise().getUu();
 		releaseProductByBatchDao.callValidProcedure(enUU, batch);
 		releaseProductByBatchDao.callValidProcedure(enUU, batch);
@@ -220,6 +219,19 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
 		return modelMap;
 		return modelMap;
 	}
 	}
 
 
+	private void validateRepeatInExcel(List<ReleaseProductByBatch> batchList, ReleaseProductByBatch aBatch) {
+		if (CollectionUtils.isEmpty(batchList) || !StringUtils.isEmpty(aBatch.getErrmsg()))
+			return ;
+		for (ReleaseProductByBatch each : batchList) {
+			if (StringUtils.isEmpty(each) && each.equals(aBatch)) {
+				aBatch.setErrmsg(ErrorInfoConstant.REPEAT_IN_EXCEL.getInfo());
+				aBatch.setReleaseCode(ReleaseStatus.had_exists.value());
+				aBatch.setReleaseStatus(ReleaseStatus.had_exists.getPhrase());
+				break;
+			}
+		}
+	}
+
 	/**
 	/**
 	 * 判断是否重复,重复则重设状态
 	 * 判断是否重复,重复则重设状态
 	 * @param data
 	 * @param data
@@ -257,7 +269,7 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
 	 * @param aProduct 单个产品
 	 * @param aProduct 单个产品
 	 * @param productSet 产品列表
 	 * @param productSet 产品列表
 	 */
 	 */
-	private Boolean validateTagInfo(ReleaseProductByBatch aProduct, Set<ReleaseProductByBatch> productSet) {
+	private Boolean validateTagInfo(ReleaseProductByBatch aProduct, List<ReleaseProductByBatch> productSet) {
 		for (ReleaseProductByBatch each : productSet) {
 		for (ReleaseProductByBatch each : productSet) {
 			if (aProduct.getBrandNameEn().equals(each.getBrandNameEn()) && aProduct.getCode().equals(each.getCode())
 			if (aProduct.getBrandNameEn().equals(each.getBrandNameEn()) && aProduct.getCode().equals(each.getCode())
 					&& aProduct.getTag().equals(each.getTag())) {
 					&& aProduct.getTag().equals(each.getTag())) {