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

feat: 新增对账更新来源表数据更新方法为批量更新

hejq 7 лет назад
Родитель
Сommit
187ead4649

+ 17 - 5
src/main/java/com/uas/platform/b2b/service/impl/PurchaseApCheckServiceImpl.java

@@ -329,15 +329,21 @@ public class PurchaseApCheckServiceImpl implements PurchaseApCheckService {
 		}
 		updateSourceInfo(sources);
         items = purchaseApCheckItemDao.save(items);
-		// TODO 把items转成主记录的形式
         List<PurchaseApCheck> apChecks = new ArrayList<>();
         apChecks.add(items.get(0).getApCheck());
         saveUserOrders(apChecks);
 		return purchaseApCheck;
 	}
 
+    /**
+     * 更新来源表数据
+     *
+     * @param list 来源库信息
+     * @return 保存结果
+     */
 	public boolean updateSourceInfo(List<SourceForApcheck> list) {
 		if (!CollectionUtils.isEmpty(list)) {
+		    List<String> sqls = new ArrayList<>();
 			for (SourceForApcheck source : list) {
 				if (source.hasInfo()) {
 					String idName = null;
@@ -366,12 +372,18 @@ public class PurchaseApCheckServiceImpl implements PurchaseApCheckService {
 					}
 					String sql = "update " + source.getSourcetable() + " set " + yCheckQtyName + " = "
 							+ source.getNewYCheckQty() + " where " + idName + " = " + source.getSourceid();
-                    commonDao.getJdbcTemplate().execute(sql);
-				} else {
-					throw new IllegalOperatorException("保存失败!");
+                    sqls.add(sql);
 				}
 			}
-			return true;
+			if (!CollectionUtils.isEmpty(sqls)) {
+			    try {
+			        commonDao.getJdbcTemplate().batchUpdate(sqls.toArray(new String[sqls.size()]));
+                } catch (RuntimeException e) {
+                    System.out.println("生成对账单批量更新来源数据失败: " + e.getMessage());
+                    throw new IllegalOperatorException("保存失败!");
+                }
+                return true;
+            }
 		}
 		throw new IllegalOperatorException("保存失败!");
 	}