Просмотр исходного кода

调整批量上架的代码结构

yujia 7 лет назад
Родитель
Сommit
a325a9b2c2

+ 8 - 0
src/main/java/com/uas/platform/b2c/prod/commodity/dao/ProductPersonDao.java

@@ -32,6 +32,14 @@ public interface ProductPersonDao extends JpaRepository<ProductPerson, Long>, Jp
      */
     List<ProductPerson> findByProductId(Long productId);
 
+    /**
+     * 批量获取个人物料信息
+     * @param productids
+     * @return List<ProductPerson>
+     */
+    @Query(value = "select p from ProductPerson p where p.productId in (:productids)")
+    List<ProductPerson> findByProductIds(@Param("productids") List<Long> productids);
+
     /**
      * 根据enuu和userUU查询物料信息
      * @param enuu

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

@@ -268,59 +268,19 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
 		Long enUU = SystemSession.getUser().getEnterprise().getUu();
 		if (!isAPerson) {
 			//1:比较品牌、型号、是否重复,一个EXCEL中只能有一条物料信息
-			for(int i = releaseProductByBatchs.size() - 1; i > -1; i--) {
-				ReleaseProductByBatch releaseProductByBatch = releaseProductByBatchs.get(i);
-				for (int j = i - 1; j > -1; j--) {
-					ReleaseProductByBatch byBatch = releaseProductByBatchs.get(j);
-					if(releaseProductByBatch.compareSameProductTagInfo(byBatch)) {
-						releaseProductByBatch.setTag("");
-						releaseProductByBatch.setTagstr("");
-						releaseProductByBatch.addErrmsg(ErrorInfoConstant.REPEAT_IN_EXCEL.getInfo());
-						releaseProductByBatch.setReleaseStatus(ReleaseStatus.had_exists.getPhrase());
-						releaseProductByBatch.setReleaseCode(ReleaseStatus.had_exists.value());
-						if (releaseProductByBatch.getErrmsg().substring(0, 1).equals(",")) {
-							releaseProductByBatch.setErrmsg(releaseProductByBatch.getErrmsg().substring(1));
-						}
-					}
-				}
-			}
+			judgeSameReleaseProductByBatch(releaseProductByBatchs);
 		}
 		commonDao.save(releaseProductByBatchs, ReleaseProductByBatch.class);
         releaseProductByBatchDao.callReleaseExistValidProcedure(batch, enUU);
 		if (isAPerson) {
-			for (ReleaseProductByBatch releaseProductByBatch : releaseProductByBatchs) {
-                Long productid = releaseProductByBatch.getProductid();
-                if (productid != null) {
-                    List<ProductPerson> productPersonList = productPersonDao.findByProductId(productid);
-                    if (!CollectionUtils.isEmpty(productPersonList)) {
-                        releaseProductByBatch.setErrmsg(ErrorInfoConstant.REPEAT_INFO.getInfo());
-                        releaseProductByBatch.setReleaseCode(ReleaseStatus.had_exists.value());
-                        releaseProductByBatch.setReleaseStatus(ReleaseStatus.had_exists.getPhrase());
-                        total --;
-                    }
-                }
-			}
+			List<ReleaseProductByBatch> productByBatches = releaseProductByBatchDao.findByRelbatchid(batch);
+			judgeReleaseProductByBatchExistInProducts(productByBatches, total);
 		}
 		String strCount = "0";
 		if (isPcb) {
 			 releaseProductByBatchDao.callValidProcedurePcb(enUU, batch);
 		} else {
-			final Object[] obj = new Object[]{enUU, batch};
-			String sql = "/*#mycat:db_type=master*/ set @enuu = %s; set @batch = '%s'; call PRODUCT_RELEASE_VALID_V5(@enuu, @batch, @out); select @out";
-			final String updateSql = String.format(sql, obj);
-			strCount = jdbcTemplate.execute(new StatementCallback<String>() {
-
-				@Override
-				public String doInStatement(Statement stmt) throws SQLException, DataAccessException {
-					stmt.executeQuery(updateSql);
-					ResultSet rs = stmt.getResultSet();
-					if (null != rs) {
-						rs.next();
-						return rs.getString(1);
-					}
-					return "0";
-				}
-			});
+			strCount = productReleaseValid(enUU, batch);
 		}
 		Integer filter = 0, failure = 0, success = 0;
 		if (!StringUtilB2C.isEmpty(strCount)) {
@@ -349,6 +309,93 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
 		return modelMap;
 	}
 
+	/**
+	 * 判断是存在相同的信息
+	 * @param releaseProductByBatchs
+	 */
+	private void judgeSameReleaseProductByBatch(List<ReleaseProductByBatch> releaseProductByBatchs) {
+		if (CollectionUtils.isEmpty(releaseProductByBatchs)) {
+			return ;
+		}
+		for(int i = releaseProductByBatchs.size() - 1; i > -1; i--) {
+			ReleaseProductByBatch releaseProductByBatch = releaseProductByBatchs.get(i);
+			for (int j = i - 1; j > -1; j--) {
+				ReleaseProductByBatch byBatch = releaseProductByBatchs.get(j);
+				if(releaseProductByBatch.compareSameProductTagInfo(byBatch)) {
+					releaseProductByBatch.setTag("");
+					releaseProductByBatch.setTagstr("");
+					releaseProductByBatch.addErrmsg(ErrorInfoConstant.REPEAT_IN_EXCEL.getInfo());
+					releaseProductByBatch.setReleaseStatus(ReleaseStatus.had_exists.getPhrase());
+					releaseProductByBatch.setReleaseCode(ReleaseStatus.had_exists.value());
+					if (releaseProductByBatch.getErrmsg().substring(0, 1).equals(",")) {
+						releaseProductByBatch.setErrmsg(releaseProductByBatch.getErrmsg().substring(1));
+					}
+				}
+			}
+		}
+	}
+
+
+	/**
+	 * 根据上传的信息,查看是否在个人物料库已存在。
+	 * @param releaseProductByBatchs
+	 * @param total
+	 */
+	private void judgeReleaseProductByBatchExistInProducts(List<ReleaseProductByBatch> releaseProductByBatchs, Integer total) {
+		List<Long> ids = new ArrayList<>();
+		for (ReleaseProductByBatch releaseProductByBatch : releaseProductByBatchs) {
+			Long productid = releaseProductByBatch.getProductid();
+			if (productid != null) {
+				ids.add(productid);
+			}
+		}
+		if (CollectionUtils.isNotEmpty(ids)) {
+			List<ProductPerson> productPersons = productPersonDao.findByProductIds(ids);
+			if (!CollectionUtils.isEmpty(productPersons)) {
+				for (ReleaseProductByBatch releaseProductByBatch : releaseProductByBatchs) {
+					if (releaseProductByBatch.getProductid() != null) {
+						for (ProductPerson productPerson : productPersons) {
+							if (releaseProductByBatch.getProductid().longValue() == productPerson.getProductId().longValue()) {
+								releaseProductByBatch.setErrmsg(ErrorInfoConstant.REPEAT_INFO.getInfo());
+								releaseProductByBatch.setReleaseCode(ReleaseStatus.had_exists.value());
+								releaseProductByBatch.setReleaseStatus(ReleaseStatus.had_exists.getPhrase());
+								total --;
+							}
+						}
+					}
+				}
+
+			}
+		}
+	}
+
+
+	/**
+	 * 调用存储过程
+	 * @param enUU 企业的enUU
+	 * @param batch 批次
+	 * @return 验证结果
+	 */
+	private String productReleaseValid(Long enUU, String batch) {
+		final Object[] obj = new Object[]{enUU, batch};
+		String sql = "/*#mycat:db_type=master*/ set @enuu = %s; set @batch = '%s'; call PRODUCT_RELEASE_VALID_V5(@enuu, @batch, @out); select @out";
+		final String updateSql = String.format(sql, obj);
+		String strCount = jdbcTemplate.execute(new StatementCallback<String>() {
+
+			@Override
+			public String doInStatement(Statement stmt) throws SQLException, DataAccessException {
+				stmt.executeQuery(updateSql);
+				ResultSet rs = stmt.getResultSet();
+				if (null != rs) {
+					rs.next();
+					return rs.getString(1);
+				}
+				return "0";
+			}
+		});
+		return strCount;
+	}
+
 	@Override
 	public ModelMap modifyByWorkbook(Workbook workbook) {
 		ModelMap modelMap = new ModelMap();