瀏覽代碼

Merge remote-tracking branch 'origin/release-201830-wangcz' into release-201830-wangcz

shenjj 7 年之前
父節點
當前提交
16b7a704fe

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

@@ -97,16 +97,7 @@ import java.sql.SQLException;
 import java.sql.Statement;
 import java.text.DateFormat;
 import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
+import java.util.*;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 import java.util.regex.Matcher;
@@ -462,6 +453,7 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
 			throw new IllegalOperatorException("您上传的信息超过2000条,请拆分成2000以再在上传");
 		}
 		List<ReleaseProductByBatch> batchList = new ArrayList<>(rowNum);
+		List<ReleaseProductByBatch> repeatBatchList = new ArrayList<>(rowNum);
 		String batch = createNumberService.getTimeNumber("product$goods", 8, rowNum);
 		Row headerRow = sheet.getRow(1);
 		validateModifyExcel(headerRow);
@@ -497,7 +489,7 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
 				aBatch.setReleaseCode(ReleaseStatus.lack_info.value());
 				aBatch.setReleaseStatus(ReleaseStatus.lack_info.getPhrase());
 			} else {
-				validateRepeatInExcel(batchList, aBatch, true);
+				validateRepeatInExcel(batchList, aBatch, true, repeatBatchList);
 			}
 			batchList.add(aBatch);
 			total++;
@@ -508,10 +500,11 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
 //		resetRepeatData(batchList, true, false);
 //		setDefaultTag(batchList);
 		commonDao.save(batchList, ReleaseProductByBatch.class);
+		commonDao.save(repeatBatchList, ReleaseProductByBatch.class);
 		Integer filter = releaseProductByBatchDao.getCountOfImportFail(userUU, batch, failCode);
 		modelMap.put("total", total);
 		modelMap.put("success", success);
-		modelMap.put("fail", batchList.size() - success);
+		modelMap.put("fail", batchList.size() - success + repeatBatchList.size());
 		modelMap.put("filter", filter);
 		modelMap.put("batch", batch);
 		return modelMap;
@@ -529,11 +522,12 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
 		List<Long> productIds = new ArrayList<>(batchList.size());
 		List<String> batchCodes = new ArrayList<>();
 		for (ReleaseProductByBatch aBatch : batchList) {
-			if (!StringUtilB2C.isEmpty(aBatch.getBatchCode()) && RegexConstant.isNumber(aBatch.getBatchCode())) {
+			if (!StringUtilB2C.isEmpty(aBatch.getBatchCode()) && RegexConstant.isNumber(aBatch.getBatchCode())
+					&& StringUtilB2C.isEmpty(aBatch.getErrmsg())) {
 				productIds.add(Long.parseLong(aBatch.getBatchCode()));
 				continue;
 			}
-			if (!StringUtilB2C.isEmpty(aBatch.getBatchCode())) {
+			if (!StringUtilB2C.isEmpty(aBatch.getBatchCode()) && StringUtilB2C.isEmpty(aBatch.getErrmsg())) {
 				batchCodes.add(aBatch.getBatchCode());
 			}
 		}
@@ -936,29 +930,28 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
 	 * @param 	aBatch
 	 * @param 	isImport
 	 */
-	private void validateRepeatInExcel(List<ReleaseProductByBatch> batchList, ReleaseProductByBatch aBatch, Boolean isImport) {
+	private void validateRepeatInExcel(List<ReleaseProductByBatch> batchList, ReleaseProductByBatch aBatch, Boolean isImport,
+									   List<ReleaseProductByBatch> repeatBatchList) {
 		if (CollectionUtils.isEmpty(batchList) || !StringUtils.isEmpty(aBatch.getErrmsg()))
-			return ;
-		for (ReleaseProductByBatch each : batchList) {
-			if (StringUtils.isEmpty(each.getErrmsg()) && each.equals(aBatch)) {
-				aBatch.setErrmsg(ErrorInfoConstant.REPEAT_IN_EXCEL.getInfo());
-				aBatch.setReleaseCode(ReleaseStatus.had_exists.value());
-				aBatch.setReleaseStatus(ReleaseStatus.had_exists.getPhrase());
-//				if (!isImport) {
-//					aBatch.setErrmsg(ErrorInfoConstant.REPEAT_IN_EXCEL.getInfo());
-//					aBatch.setReleaseCode(ReleaseStatus.had_exists.value());
-//					aBatch.setReleaseStatus(ReleaseStatus.had_exists.getPhrase());
-//					break;
-//				} else {
-//					if (GoodsUtil.compareWithQtyPrice(each.getPrices(), aBatch.getPrices(), each.getCurrency())) {
-//						aBatch.setErrmsg(ErrorInfoConstant.REPEAT_IN_EXCEL.getInfo());
-//						aBatch.setReleaseCode(ReleaseStatus.had_exists.value());
-//						aBatch.setReleaseStatus(ReleaseStatus.had_exists.getPhrase());
-//						break;
-//					}
-//				}
-			}
-		}
+			return;
+		Iterator<ReleaseProductByBatch> iterator = batchList.iterator();
+		while (iterator.hasNext()) {
+			ReleaseProductByBatch byBatch = iterator.next();
+			if (StringUtils.isEmpty(byBatch.getErrmsg()) && byBatch.equals(aBatch)) {
+				byBatch.setErrmsg(ErrorInfoConstant.REPEAT_IN_EXCEL.getInfo());
+				byBatch.setReleaseCode(ReleaseStatus.had_exists.value());
+				byBatch.setReleaseStatus(ReleaseStatus.had_exists.getPhrase());
+				repeatBatchList.add(byBatch);
+				iterator.remove();
+			}
+		}
+//		for (ReleaseProductByBatch each : batchList) {
+//			if (StringUtils.isEmpty(each.getErrmsg()) && each.equals(aBatch)) {
+//				aBatch.setErrmsg(ErrorInfoConstant.REPEAT_IN_EXCEL.getInfo());
+//				aBatch.setReleaseCode(ReleaseStatus.had_exists.value());
+//				aBatch.setReleaseStatus(ReleaseStatus.had_exists.getPhrase());
+//			}
+//		}
 	}
 
 	/**