yonge 3 лет назад
Родитель
Сommit
ac1b9056be

+ 9 - 8
mec-biz/src/main/java/com/ym/mec/biz/service/impl/PayServiceImpl.java

@@ -242,13 +242,13 @@ public class PayServiceImpl implements PayService {
         								totalGroupPurchaseAmount =  totalGroupPurchaseAmount.add(goodsList.stream().map(Goods :: getGroupPurchasePrice).reduce(BigDecimal.ZERO,BigDecimal :: add));
         								
         								for(Goods subGoods : goodsList){
+    										
+    										if(batchUpdateGoodsMap.get(subGoods.getId()) != null){
+    											subGoods = batchUpdateGoodsMap.get(subGoods.getId());
+    										}
         									//判断是否有内部库存
         									if(subGoods.getStockCount() > 0){
         										
-        										if(batchUpdateGoodsMap.get(subGoods.getId()) != null){
-        											subGoods = batchUpdateGoodsMap.get(subGoods.getId());
-        										}
-        										
         										groupPurchaseAmount = groupPurchaseAmount.add(subGoods.getGroupPurchasePrice());
         										subGoods.setStockCount(new AtomicInteger(subGoods.getStockCount()).decrementAndGet());
             									subGoods.setSellCount(new AtomicInteger(subGoods.getSellCount()).incrementAndGet());
@@ -271,13 +271,14 @@ public class PayServiceImpl implements PayService {
         								}
         							}else{
     									totalGroupPurchaseAmount = totalGroupPurchaseAmount.add(goods.getGroupPurchasePrice());
+    									
+    									if(batchUpdateGoodsMap.get(goods.getId()) != null){
+    										goods = batchUpdateGoodsMap.get(goods.getId());
+										}
+    									
         								//判断是否有内部库存
         								if(goods.getStockCount() > 0){
         									
-        									if(batchUpdateGoodsMap.get(goods.getId()) != null){
-        										goods = batchUpdateGoodsMap.get(goods.getId());
-    										}
-        									
     										groupPurchaseAmount = groupPurchaseAmount.add(goods.getGroupPurchasePrice());
     										goods.setStockCount(new AtomicInteger(goods.getStockCount()).decrementAndGet());
     										goods.setSellCount(new AtomicInteger(goods.getSellCount()).incrementAndGet());

+ 31 - 15
mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentPaymentOrderServiceImpl.java

@@ -799,38 +799,54 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
         //处理关闭订单
         order.setStatus(DealStatusEnum.CLOSE);
         order.setMemo("关闭订单");
+
         
         Date nowDate = new Date();
-		List<Goods> batchUpdateGoodsList = new ArrayList<Goods>();
         //增加商品库存
         List<StudentPaymentOrderDetail> studentPaymentOrderDetailList = studentPaymentOrderDetailService.queryOrderDetail(order.getId());
         String goodsIds = studentPaymentOrderDetailList.stream().filter(t -> StringUtils.isNotBlank(t.getMinuendStockGoodsIdList())).map(t -> t.getMinuendStockGoodsIdList()).collect(Collectors.joining(","));
         if(StringUtils.isNotBlank(goodsIds)){
         	GoodsProcurement goodsProcurement = null;
-        	List<GoodsProcurement> goodsProcurementList = new ArrayList<GoodsProcurement>();
         	List<Goods> goodsList = goodsService.getGoodsWithLocked(goodsIds);
-        	for(Goods subGoods : goodsList){
-				subGoods.setStockCount(new AtomicInteger(subGoods.getStockCount()).incrementAndGet());
-				subGoods.setSellCount(new AtomicInteger(subGoods.getSellCount()).decrementAndGet());
-				subGoods.setUpdateTime(nowDate);
-				batchUpdateGoodsList.add(subGoods);
+        	Map<Integer,Goods> goodsMap = goodsList.stream().collect(Collectors.toMap(Goods :: getId, t -> t));
+        	Goods goods = null;
+			Map<Integer, Goods> batchUpdateGoodsMap = new HashMap<Integer, Goods>();
+			Map<Long, GoodsProcurement> goodsProcurementMap = new HashMap<Long, GoodsProcurement>();
+        	
+        	for(String goodsIdStr : goodsIds.split(",")){
+        		if(StringUtils.isBlank(goodsIdStr)){
+					continue;
+				}
+				goods = goodsMap.get(Integer.parseInt(goodsIdStr));
+				if(batchUpdateGoodsMap.get(goods.getId()) != null){
+					goods = batchUpdateGoodsMap.get(goods.getId());
+				}
+				goods.setStockCount(new AtomicInteger(goods.getStockCount()).incrementAndGet());
+				goods.setSellCount(new AtomicInteger(goods.getSellCount()).decrementAndGet());
+				goods.setUpdateTime(nowDate);
+				
+				batchUpdateGoodsMap.put(goods.getId(), goods);
 				
 				// 进货清单
-				goodsProcurement = goodsProcurementDao.getWithStockSurplusProcurement(subGoods.getId());
+				goodsProcurement = goodsProcurementDao.getWithStockSurplusProcurement(goods.getId());
 				if(goodsProcurement != null){
+					if(goodsProcurementMap.get(goodsProcurement.getId()) != null){
+						goodsProcurement = goodsProcurementMap.get(goodsProcurement.getId());
+					}
 					goodsProcurement.setStockSoldNum(new AtomicInteger(goodsProcurement.getStockSoldNum()).decrementAndGet());
 					goodsProcurement.setUpdateTime(nowDate);
-					goodsProcurementList.add(goodsProcurement);
+					goodsProcurementMap.put(goodsProcurement.getId(), goodsProcurement);
 				}
+				
         	}
         	
-        	if(goodsProcurementList.size() > 0){
-        		goodsProcurementDao.batchUpdate(goodsProcurementList);
+        	if(goodsProcurementMap.size() > 0){
+        		goodsProcurementDao.batchUpdate(new ArrayList<GoodsProcurement>(goodsProcurementMap.values()));
         	}
-        }
-        
-        if(batchUpdateGoodsList.size() > 0){
-        	goodsService.batchUpdate(batchUpdateGoodsList);
+            
+            if(batchUpdateGoodsMap.size() > 0){
+            	goodsService.batchUpdate(new ArrayList<Goods>(batchUpdateGoodsMap.values()));
+            }
         }
         
         //如果是报名订单,订单关闭时需要更改已缴费学员数

+ 30 - 15
mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentRegistrationServiceImpl.java

@@ -1379,36 +1379,51 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
             //减去缴费人数(器乐收费,0元时不减缴费人数)
             studentPaymentOrderService.cutSubjectPlan(studentPaymentOrder);
             
-			List<Goods> batchUpdateGoodsList = new ArrayList<Goods>();
             //增加商品库存
             List<StudentPaymentOrderDetail> studentPaymentOrderDetailList = studentPaymentOrderDetailService.queryOrderDetail(studentPaymentOrder.getId());
             String goodsIds = studentPaymentOrderDetailList.stream().filter(t -> StringUtils.isNotBlank(t.getMinuendStockGoodsIdList())).map(t -> t.getMinuendStockGoodsIdList()).collect(Collectors.joining(","));
             if(StringUtils.isNotBlank(goodsIds)){
             	GoodsProcurement goodsProcurement = null;
-            	List<GoodsProcurement> goodsProcurementList = new ArrayList<GoodsProcurement>();
             	List<Goods> goodsList = goodsService.getGoodsWithLocked(goodsIds);
-            	for(Goods subGoods : goodsList){
-					subGoods.setStockCount(new AtomicInteger(subGoods.getStockCount()).incrementAndGet());
-					subGoods.setSellCount(new AtomicInteger(subGoods.getSellCount()).decrementAndGet());
-					subGoods.setUpdateTime(nowDate);
-					batchUpdateGoodsList.add(subGoods);
+            	Map<Integer,Goods> goodsMap = goodsList.stream().collect(Collectors.toMap(Goods :: getId, t -> t));
+            	Goods goods = null;
+    			Map<Integer, Goods> batchUpdateGoodsMap = new HashMap<Integer, Goods>();
+    			Map<Long, GoodsProcurement> goodsProcurementMap = new HashMap<Long, GoodsProcurement>();
+            	
+            	for(String goodsIdStr : goodsIds.split(",")){
+            		if(StringUtils.isBlank(goodsIdStr)){
+						continue;
+					}
+					goods = goodsMap.get(Integer.parseInt(goodsIdStr));
+					if(batchUpdateGoodsMap.get(goods.getId()) != null){
+						goods = batchUpdateGoodsMap.get(goods.getId());
+					}
+					goods.setStockCount(new AtomicInteger(goods.getStockCount()).incrementAndGet());
+					goods.setSellCount(new AtomicInteger(goods.getSellCount()).decrementAndGet());
+					goods.setUpdateTime(nowDate);
+					
+					batchUpdateGoodsMap.put(goods.getId(), goods);
 					
 					// 进货清单
-					goodsProcurement = goodsProcurementDao.getWithStockSurplusProcurement(subGoods.getId());
+					goodsProcurement = goodsProcurementDao.getWithStockSurplusProcurement(goods.getId());
 					if(goodsProcurement != null){
+						if(goodsProcurementMap.get(goodsProcurement.getId()) != null){
+							goodsProcurement = goodsProcurementMap.get(goodsProcurement.getId());
+						}
 						goodsProcurement.setStockSoldNum(new AtomicInteger(goodsProcurement.getStockSoldNum()).decrementAndGet());
 						goodsProcurement.setUpdateTime(nowDate);
-						goodsProcurementList.add(goodsProcurement);
+						goodsProcurementMap.put(goodsProcurement.getId(), goodsProcurement);
 					}
+					
             	}
             	
-            	if(goodsProcurementList.size() > 0){
-            		goodsProcurementDao.batchUpdate(goodsProcurementList);
+            	if(goodsProcurementMap.size() > 0){
+            		goodsProcurementDao.batchUpdate(new ArrayList<GoodsProcurement>(goodsProcurementMap.values()));
             	}
-            }
-            
-            if(batchUpdateGoodsList.size() > 0){
-            	goodsService.batchUpdate(batchUpdateGoodsList);
+                
+                if(batchUpdateGoodsMap.size() > 0){
+                	goodsService.batchUpdate(new ArrayList<Goods>(batchUpdateGoodsMap.values()));
+                }
             }
 
             //退还优惠券和余额

+ 195 - 86
mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentRepairServiceImpl.java

@@ -207,6 +207,54 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
                 }
                 //退优惠券
                 sysCouponCodeService.quit(orderByOrderNo.getCouponCodeId());
+                
+                Date nowDate = new Date();
+                //增加商品库存
+                List<StudentPaymentOrderDetail> studentPaymentOrderDetailList = studentPaymentOrderDetailService.queryOrderDetail(orderByOrderNo.getId());
+                String goodsIds = studentPaymentOrderDetailList.stream().filter(t -> StringUtils.isNotBlank(t.getMinuendStockGoodsIdList())).map(t -> t.getMinuendStockGoodsIdList()).collect(Collectors.joining(","));
+                if(StringUtils.isNotBlank(goodsIds)){
+                	GoodsProcurement goodsProcurement = null;
+                	List<Goods> goodsList = goodsService.getGoodsWithLocked(goodsIds);
+                	Map<Integer,Goods> goodsMap = goodsList.stream().collect(Collectors.toMap(Goods :: getId, t -> t));
+                	Goods goods = null;
+        			Map<Integer, Goods> batchUpdateGoodsMap = new HashMap<Integer, Goods>();
+        			Map<Long, GoodsProcurement> goodsProcurementMap = new HashMap<Long, GoodsProcurement>();
+                	
+                	for(String goodsIdStr : goodsIds.split(",")){
+                		if(StringUtils.isBlank(goodsIdStr)){
+							continue;
+						}
+						goods = goodsMap.get(Integer.parseInt(goodsIdStr));
+						if(batchUpdateGoodsMap.get(goods.getId()) != null){
+							goods = batchUpdateGoodsMap.get(goods.getId());
+						}
+						goods.setStockCount(new AtomicInteger(goods.getStockCount()).incrementAndGet());
+						goods.setSellCount(new AtomicInteger(goods.getSellCount()).decrementAndGet());
+						goods.setUpdateTime(nowDate);
+    					
+						batchUpdateGoodsMap.put(goods.getId(), goods);
+    					
+    					// 进货清单
+    					goodsProcurement = goodsProcurementDao.getWithStockSurplusProcurement(goods.getId());
+    					if(goodsProcurement != null){
+							if(goodsProcurementMap.get(goodsProcurement.getId()) != null){
+								goodsProcurement = goodsProcurementMap.get(goodsProcurement.getId());
+							}
+    						goodsProcurement.setStockSoldNum(new AtomicInteger(goodsProcurement.getStockSoldNum()).decrementAndGet());
+    						goodsProcurement.setUpdateTime(nowDate);
+							goodsProcurementMap.put(goodsProcurement.getId(), goodsProcurement);
+    					}
+						
+                	}
+                	
+                	if(goodsProcurementMap.size() > 0){
+                		goodsProcurementDao.batchUpdate(new ArrayList<GoodsProcurement>(goodsProcurementMap.values()));
+                	}
+                    
+                    if(batchUpdateGoodsMap.size() > 0){
+                    	goodsService.batchUpdate(new ArrayList<Goods>(batchUpdateGoodsMap.values()));
+                    }
+                }
             }
             StudentGoodsSell byOrderNo = studentGoodsSellDao.findByOrderNo(studentGoodsSell.getOrderNo());
             if (byOrderNo != null) {
@@ -257,11 +305,11 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
             goodsSellDto.setGoodsGroupPrice(groupPriceMap.get(goodsSellDto.getGoodsId()));
             goodsSellDto.setTotalGoodsPrice(map.get(goodsSellDto.getGoodsId()).multiply(new BigDecimal(goodsSellDto.getGoodsNum())));
         }
-        Map<Integer, List<GoodsSellDto>> goodsMap = goodsSellDtos.stream().collect(Collectors.groupingBy(GoodsSellDto::getGoodsId));
+        Map<Integer, List<GoodsSellDto>> goodsSellDtoMap = goodsSellDtos.stream().collect(Collectors.groupingBy(GoodsSellDto::getGoodsId));
         BigDecimal amount = BigDecimal.ZERO;
         BigDecimal groupAmount = BigDecimal.ZERO;
         for (Integer id : goodsIds) {
-            GoodsSellDto goodsSellDto = goodsMap.get(id).get(0);
+            GoodsSellDto goodsSellDto = goodsSellDtoMap.get(id).get(0);
             amount = amount.add(goodsSellDto.getTotalGoodsPrice());
             groupAmount = groupAmount.add(goodsSellDto.getGoodsGroupPrice());
         }
@@ -322,33 +370,44 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
         if(goodsSellDtos != null){
         	String goodsIdsStr = goodsSellDtos.stream().map(t -> t.getGoodsId().toString()).collect(Collectors.joining(","));
         	List<Goods> goodsList = goodsService.findGoodsByIds(goodsIdsStr);
-        	BigDecimal goodsPrice = goodsList.stream().map(t -> t.getGroupPurchasePrice()).reduce(BigDecimal.ZERO, BigDecimal::add);
-        	for(Goods g : goodsList){
-        		studentPaymentOrderDetail = new StudentPaymentOrderDetail();
-                studentPaymentOrderDetail.setCreateTime(date);
-                if(g.getType() == GoodsType.INSTRUMENT){
-                	studentPaymentOrderDetail.setType(OrderDetailTypeEnum.MUSICAL);
-                }else if(g.getType() == GoodsType.ACCESSORIES){
-                	studentPaymentOrderDetail.setType(OrderDetailTypeEnum.ACCESSORIES);
-                }else if(g.getType() == GoodsType.TEACHING || g.getType() == GoodsType.STAFF){
-                	studentPaymentOrderDetail.setType(OrderDetailTypeEnum.TEACHING);
-                }else{
-                	studentPaymentOrderDetail.setType(OrderDetailTypeEnum.OTHER);
-                }
-                studentPaymentOrderDetail.setGoodsIdList(g.getId() + "");
-                
-                BigDecimal tempPrice = studentPaymentOrder.getExpectAmount().multiply(g.getGroupPurchasePrice()).divide(goodsPrice, RoundingMode.UP);
-                
-                if(totalPrice.add(tempPrice).compareTo(studentPaymentOrder.getExpectAmount()) > 0){
-                	studentPaymentOrderDetail.setPrice(studentPaymentOrder.getExpectAmount().subtract(totalPrice));
-                }else{
-                	studentPaymentOrderDetail.setPrice(tempPrice);
-                }
-                studentPaymentOrderDetail.setUpdateTime(date);
-                studentPaymentOrderDetail.setPaymentOrderId(studentPaymentOrder.getId());
-                
-                totalPrice = totalPrice.add(studentPaymentOrderDetail.getPrice());
-                studentPaymentOrderDetailList.add(studentPaymentOrderDetail);
+        	BigDecimal totalGroupPurchasePrice = goodsList.stream().map(t -> t.getGroupPurchasePrice()).reduce(BigDecimal.ZERO, BigDecimal::add);
+        	
+        	Map<Integer,Goods> goodsMap = goodsList.stream().collect(Collectors.toMap(Goods :: getId, t -> t));
+        	
+        	Goods goods = null;
+        	for(String goodsIdStr : goodsIdsStr.split(",")){
+        		if(StringUtils.isBlank(goodsIdStr)){
+					continue;
+				}
+				goods = goodsMap.get(Integer.parseInt(goodsIdStr));
+				
+				if(goods != null){
+					studentPaymentOrderDetail = new StudentPaymentOrderDetail();
+	                studentPaymentOrderDetail.setCreateTime(date);
+	                if(goods.getType() == GoodsType.INSTRUMENT){
+	                	studentPaymentOrderDetail.setType(OrderDetailTypeEnum.MUSICAL);
+	                }else if(goods.getType() == GoodsType.ACCESSORIES){
+	                	studentPaymentOrderDetail.setType(OrderDetailTypeEnum.ACCESSORIES);
+	                }else if(goods.getType() == GoodsType.TEACHING || goods.getType() == GoodsType.STAFF){
+	                	studentPaymentOrderDetail.setType(OrderDetailTypeEnum.TEACHING);
+	                }else{
+	                	studentPaymentOrderDetail.setType(OrderDetailTypeEnum.OTHER);
+	                }
+	                studentPaymentOrderDetail.setGoodsIdList(goodsIdStr);
+	                
+	                BigDecimal tempPrice = studentPaymentOrder.getExpectAmount().multiply(goods.getGroupPurchasePrice()).divide(totalGroupPurchasePrice, RoundingMode.UP);
+	                
+	                if(totalPrice.add(tempPrice).compareTo(studentPaymentOrder.getExpectAmount()) > 0){
+	                	studentPaymentOrderDetail.setPrice(studentPaymentOrder.getExpectAmount().subtract(totalPrice));
+	                }else{
+	                	studentPaymentOrderDetail.setPrice(tempPrice);
+	                }
+	                studentPaymentOrderDetail.setUpdateTime(date);
+	                studentPaymentOrderDetail.setPaymentOrderId(studentPaymentOrder.getId());
+	                
+	                totalPrice = totalPrice.add(studentPaymentOrderDetail.getPrice());
+	                studentPaymentOrderDetailList.add(studentPaymentOrderDetail);
+				}
         	}
         }
         
@@ -639,32 +698,52 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
         if(StringUtils.isNotBlank(repairInfo.getGoodsJson()) && repairGoodsDtos != null){
         	String goodsIds = repairGoodsDtos.stream().map(t -> t.getId().toString()).collect(Collectors.joining(","));
         	List<Goods> goodsList = goodsService.findGoodsByIds(goodsIds);
-        	for(Goods g : goodsList){
-        		studentPaymentOrderDetail = new StudentPaymentOrderDetail();
-                studentPaymentOrderDetail.setCreateTime(date);
-                if(g.getType() == GoodsType.INSTRUMENT){
-                	studentPaymentOrderDetail.setType(OrderDetailTypeEnum.MUSICAL);
-                }else if(g.getType() == GoodsType.ACCESSORIES){
-                	studentPaymentOrderDetail.setType(OrderDetailTypeEnum.ACCESSORIES);
-                }else if(g.getType() == GoodsType.TEACHING || g.getType() == GoodsType.STAFF){
-                	studentPaymentOrderDetail.setType(OrderDetailTypeEnum.TEACHING);
-                }else{
-                	studentPaymentOrderDetail.setType(OrderDetailTypeEnum.OTHER);
-                }
-                studentPaymentOrderDetail.setGoodsIdList(g.getId() + "");
-                
-                BigDecimal tempPrice = studentPaymentOrder.getExpectAmount().subtract(repairPrice).multiply(g.getGroupPurchasePrice()).divide(goodsPrice, RoundingMode.UP);
-                
-                if(totalPrice.add(tempPrice).compareTo(studentPaymentOrder.getExpectAmount()) > 0){
-                	studentPaymentOrderDetail.setPrice(studentPaymentOrder.getExpectAmount().subtract(totalPrice));
-                }else{
-                	studentPaymentOrderDetail.setPrice(tempPrice);
-                }
-                studentPaymentOrderDetail.setUpdateTime(date);
-                studentPaymentOrderDetail.setPaymentOrderId(studentPaymentOrder.getId());
-                
-                totalPrice = totalPrice.add(studentPaymentOrderDetail.getPrice());
-                studentPaymentOrderDetailList.add(studentPaymentOrderDetail);
+        	Map<Integer,Goods> goodsMap = goodsList.stream().collect(Collectors.toMap(Goods :: getId, t -> t));
+        	Goods goods = null;
+        	BigDecimal totalGroupPurchasePrice = BigDecimal.ZERO;
+        	for(String goodsIdStr : goodsIds.split(",")){
+        		if(StringUtils.isBlank(goodsIdStr)){
+					continue;
+				}
+				goods = goodsMap.get(Integer.parseInt(goodsIdStr));
+				
+				if(goods != null){
+					totalGroupPurchasePrice = totalGroupPurchasePrice.add(goods.getGroupPurchasePrice());
+				}
+        	}
+        	for(String goodsIdStr : goodsIds.split(",")){
+        		if(StringUtils.isBlank(goodsIdStr)){
+					continue;
+				}
+				goods = goodsMap.get(Integer.parseInt(goodsIdStr));
+				
+				if(goods != null){
+					studentPaymentOrderDetail = new StudentPaymentOrderDetail();
+	                studentPaymentOrderDetail.setCreateTime(date);
+	                if(goods.getType() == GoodsType.INSTRUMENT){
+	                	studentPaymentOrderDetail.setType(OrderDetailTypeEnum.MUSICAL);
+	                }else if(goods.getType() == GoodsType.ACCESSORIES){
+	                	studentPaymentOrderDetail.setType(OrderDetailTypeEnum.ACCESSORIES);
+	                }else if(goods.getType() == GoodsType.TEACHING || goods.getType() == GoodsType.STAFF){
+	                	studentPaymentOrderDetail.setType(OrderDetailTypeEnum.TEACHING);
+	                }else{
+	                	studentPaymentOrderDetail.setType(OrderDetailTypeEnum.OTHER);
+	                }
+	                studentPaymentOrderDetail.setGoodsIdList(goodsIdStr);
+	                
+	                BigDecimal tempPrice = studentPaymentOrder.getExpectAmount().subtract(repairPrice).multiply(goods.getGroupPurchasePrice()).divide(totalGroupPurchasePrice, RoundingMode.UP);
+	                
+	                if(totalPrice.add(tempPrice).compareTo(studentPaymentOrder.getExpectAmount()) > 0){
+	                	studentPaymentOrderDetail.setPrice(studentPaymentOrder.getExpectAmount().subtract(totalPrice));
+	                }else{
+	                	studentPaymentOrderDetail.setPrice(tempPrice);
+	                }
+	                studentPaymentOrderDetail.setUpdateTime(date);
+	                studentPaymentOrderDetail.setPaymentOrderId(studentPaymentOrder.getId());
+	                
+	                totalPrice = totalPrice.add(studentPaymentOrderDetail.getPrice());
+	                studentPaymentOrderDetailList.add(studentPaymentOrderDetail);
+				}
         	}
         }
         
@@ -957,36 +1036,51 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
             saveSellOrder(studentPaymentOrder.getOrderNo());
         } else if (studentPaymentOrder.getStatus() == DealStatusEnum.CLOSE || studentPaymentOrder.getStatus() == DealStatusEnum.FAILED) {
             
-			List<Goods> batchUpdateGoodsList = new ArrayList<Goods>();
-            //增加商品库存
+        	//增加商品库存
             List<StudentPaymentOrderDetail> studentPaymentOrderDetailList = studentPaymentOrderDetailService.queryOrderDetail(studentPaymentOrder.getId());
             String goodsIds = studentPaymentOrderDetailList.stream().filter(t -> StringUtils.isNotBlank(t.getMinuendStockGoodsIdList())).map(t -> t.getMinuendStockGoodsIdList()).collect(Collectors.joining(","));
             if(StringUtils.isNotBlank(goodsIds)){
             	GoodsProcurement goodsProcurement = null;
-            	List<GoodsProcurement> goodsProcurementList = new ArrayList<GoodsProcurement>();
             	List<Goods> goodsList = goodsService.getGoodsWithLocked(goodsIds);
-            	for(Goods subGoods : goodsList){
-					subGoods.setStockCount(new AtomicInteger(subGoods.getStockCount()).incrementAndGet());
-					subGoods.setSellCount(new AtomicInteger(subGoods.getSellCount()).decrementAndGet());
-					subGoods.setUpdateTime(nowDate);
-					batchUpdateGoodsList.add(subGoods);
+            	Map<Integer,Goods> goodsMap = goodsList.stream().collect(Collectors.toMap(Goods :: getId, t -> t));
+            	Goods goods = null;
+    			Map<Integer, Goods> batchUpdateGoodsMap = new HashMap<Integer, Goods>();
+    			Map<Long, GoodsProcurement> goodsProcurementMap = new HashMap<Long, GoodsProcurement>();
+            	
+            	for(String goodsIdStr : goodsIds.split(",")){
+            		if(StringUtils.isBlank(goodsIdStr)){
+						continue;
+					}
+					goods = goodsMap.get(Integer.parseInt(goodsIdStr));
+					if(batchUpdateGoodsMap.get(goods.getId()) != null){
+						goods = batchUpdateGoodsMap.get(goods.getId());
+					}
+					goods.setStockCount(new AtomicInteger(goods.getStockCount()).incrementAndGet());
+					goods.setSellCount(new AtomicInteger(goods.getSellCount()).decrementAndGet());
+					goods.setUpdateTime(nowDate);
+					
+					batchUpdateGoodsMap.put(goods.getId(), goods);
 					
 					// 进货清单
-					goodsProcurement = goodsProcurementDao.getWithStockSurplusProcurement(subGoods.getId());
+					goodsProcurement = goodsProcurementDao.getWithStockSurplusProcurement(goods.getId());
 					if(goodsProcurement != null){
+						if(goodsProcurementMap.get(goodsProcurement.getId()) != null){
+							goodsProcurement = goodsProcurementMap.get(goodsProcurement.getId());
+						}
 						goodsProcurement.setStockSoldNum(new AtomicInteger(goodsProcurement.getStockSoldNum()).decrementAndGet());
 						goodsProcurement.setUpdateTime(nowDate);
-						goodsProcurementList.add(goodsProcurement);
+						goodsProcurementMap.put(goodsProcurement.getId(), goodsProcurement);
 					}
+					
             	}
             	
-            	if(goodsProcurementList.size() > 0){
-            		goodsProcurementDao.batchUpdate(goodsProcurementList);
+            	if(goodsProcurementMap.size() > 0){
+            		goodsProcurementDao.batchUpdate(new ArrayList<GoodsProcurement>(goodsProcurementMap.values()));
             	}
-            }
-            
-            if(batchUpdateGoodsList.size() > 0){
-            	goodsService.batchUpdate(batchUpdateGoodsList);
+                
+                if(batchUpdateGoodsMap.size() > 0){
+                	goodsService.batchUpdate(new ArrayList<Goods>(batchUpdateGoodsMap.values()));
+                }
             }
         	
         	if (studentPaymentOrder.getBalancePaymentAmount() != null && studentPaymentOrder.getBalancePaymentAmount().compareTo(BigDecimal.ZERO) > 0) {
@@ -1369,36 +1463,51 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
                 throw new BizException("维修单更新失败");
             }
             
-			List<Goods> batchUpdateGoodsList = new ArrayList<Goods>();
             //增加商品库存
             List<StudentPaymentOrderDetail> studentPaymentOrderDetailList = studentPaymentOrderDetailService.queryOrderDetail(studentPaymentOrder.getId());
             String goodsIds = studentPaymentOrderDetailList.stream().filter(t -> StringUtils.isNotBlank(t.getMinuendStockGoodsIdList())).map(t -> t.getMinuendStockGoodsIdList()).collect(Collectors.joining(","));
             if(StringUtils.isNotBlank(goodsIds)){
             	GoodsProcurement goodsProcurement = null;
-            	List<GoodsProcurement> goodsProcurementList = new ArrayList<GoodsProcurement>();
             	List<Goods> goodsList = goodsService.getGoodsWithLocked(goodsIds);
-            	for(Goods subGoods : goodsList){
-					subGoods.setStockCount(new AtomicInteger(subGoods.getStockCount()).incrementAndGet());
-					subGoods.setSellCount(new AtomicInteger(subGoods.getSellCount()).decrementAndGet());
-					subGoods.setUpdateTime(nowDate);
-					batchUpdateGoodsList.add(subGoods);
+            	Map<Integer,Goods> goodsMap = goodsList.stream().collect(Collectors.toMap(Goods :: getId, t -> t));
+            	Goods goods = null;
+    			Map<Integer, Goods> batchUpdateGoodsMap = new HashMap<Integer, Goods>();
+    			Map<Long, GoodsProcurement> goodsProcurementMap = new HashMap<Long, GoodsProcurement>();
+            	
+            	for(String goodsIdStr : goodsIds.split(",")){
+            		if(StringUtils.isBlank(goodsIdStr)){
+						continue;
+					}
+					goods = goodsMap.get(Integer.parseInt(goodsIdStr));
+					if(batchUpdateGoodsMap.get(goods.getId()) != null){
+						goods = batchUpdateGoodsMap.get(goods.getId());
+					}
+					goods.setStockCount(new AtomicInteger(goods.getStockCount()).incrementAndGet());
+					goods.setSellCount(new AtomicInteger(goods.getSellCount()).decrementAndGet());
+					goods.setUpdateTime(nowDate);
+					
+					batchUpdateGoodsMap.put(goods.getId(), goods);
 					
 					// 进货清单
-					goodsProcurement = goodsProcurementDao.getWithStockSurplusProcurement(subGoods.getId());
+					goodsProcurement = goodsProcurementDao.getWithStockSurplusProcurement(goods.getId());
 					if(goodsProcurement != null){
+						if(goodsProcurementMap.get(goodsProcurement.getId()) != null){
+							goodsProcurement = goodsProcurementMap.get(goodsProcurement.getId());
+						}
 						goodsProcurement.setStockSoldNum(new AtomicInteger(goodsProcurement.getStockSoldNum()).decrementAndGet());
 						goodsProcurement.setUpdateTime(nowDate);
-						goodsProcurementList.add(goodsProcurement);
+						goodsProcurementMap.put(goodsProcurement.getId(), goodsProcurement);
 					}
+					
             	}
             	
-            	if(goodsProcurementList.size() > 0){
-            		goodsProcurementDao.batchUpdate(goodsProcurementList);
+            	if(goodsProcurementMap.size() > 0){
+            		goodsProcurementDao.batchUpdate(new ArrayList<GoodsProcurement>(goodsProcurementMap.values()));
             	}
-            }
-            
-            if(batchUpdateGoodsList.size() > 0){
-            	goodsService.batchUpdate(batchUpdateGoodsList);
+                
+                if(batchUpdateGoodsMap.size() > 0){
+                	goodsService.batchUpdate(new ArrayList<Goods>(batchUpdateGoodsMap.values()));
+                }
             }
             
             if (studentPaymentOrder.getBalancePaymentAmount() != null && studentPaymentOrder.getBalancePaymentAmount().compareTo(BigDecimal.ZERO) > 0) {

+ 86 - 73
mec-biz/src/main/java/com/ym/mec/biz/service/impl/SubjectChangeServiceImpl.java

@@ -16,7 +16,6 @@ import java.util.Set;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.stream.Collectors;
 
-import org.apache.commons.collections.ListUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -300,42 +299,47 @@ public class SubjectChangeServiceImpl extends BaseServiceImpl<Integer, SubjectCh
 
         BigDecimal totalPrice = BigDecimal.ZERO;
         
-        List<String> changeAccessoriesList = null;
+        List<String> changeGoodsList = null;
         
         if(StringUtils.isNotBlank(subjectChange.getChangeAccessories())){
-        	changeAccessoriesList = Arrays.asList(subjectChange.getChangeAccessories().split(","));
+        	changeGoodsList = Arrays.asList(subjectChange.getChangeAccessories().split(","));
         	
-        	List<String> originalAccessories = new ArrayList<String>();
         	if(StringUtils.isNotBlank(subjectChange.getOriginalAccessories())){
-        		originalAccessories = Arrays.asList(subjectChange.getOriginalAccessories().split(","));
+        		changeGoodsList.addAll(Arrays.asList(subjectChange.getOriginalAccessories().split(",")));
         	}
-        	//changeAccessoriesList.removeAll(originalAccessories);
-        	changeAccessoriesList = ListUtils.subtract(changeAccessoriesList, originalAccessories);
         	
         	if(subjectChange.getChangeMusical() != subjectChange.getOriginalMusical()){
-        		changeAccessoriesList.add(subjectChange.getChangeMusical()+"");
+        		changeGoodsList.add(subjectChange.getChangeMusical()+"");
         	}
         }
         
-        if(changeAccessoriesList != null){
-            String goodsIdsStr = changeAccessoriesList.stream().map(t -> t.toString()).collect(Collectors.joining(","));
+        if(changeGoodsList != null){
+            String goodsIdsStr = changeGoodsList.stream().map(t -> t.toString()).collect(Collectors.joining(","));
         	List<Goods> goodsList = goodsService.findGoodsByIds(goodsIdsStr);
-        	BigDecimal goodsPrice = goodsList.stream().map(t -> t.getGroupPurchasePrice()).reduce(BigDecimal.ZERO, BigDecimal::add);
-        	for(Goods g : goodsList){
-        		studentPaymentOrderDetail = new StudentPaymentOrderDetail();
+        	Map<Integer,Goods> goodsMap = goodsList.stream().collect(Collectors.toMap(Goods :: getId, t -> t));
+        	Goods goods = null;
+        	BigDecimal goodsTotalGroupPurchasePrice = goodsList.stream().map(t -> t.getGroupPurchasePrice()).reduce(BigDecimal.ZERO, BigDecimal::add);
+        	
+        	for(String goodsIdStr : goodsIdsStr.split(",")){
+        		if(StringUtils.isBlank(goodsIdStr)){
+					continue;
+				}
+				goods = goodsMap.get(Integer.parseInt(goodsIdStr));
+				
+				studentPaymentOrderDetail = new StudentPaymentOrderDetail();
                 studentPaymentOrderDetail.setCreateTime(date);
-                if(g.getType() == GoodsType.INSTRUMENT){
+                if(goods.getType() == GoodsType.INSTRUMENT){
                 	studentPaymentOrderDetail.setType(OrderDetailTypeEnum.MUSICAL);
-                }else if(g.getType() == GoodsType.ACCESSORIES){
+                }else if(goods.getType() == GoodsType.ACCESSORIES){
                 	studentPaymentOrderDetail.setType(OrderDetailTypeEnum.ACCESSORIES);
-                }else if(g.getType() == GoodsType.TEACHING || g.getType() == GoodsType.STAFF){
+                }else if(goods.getType() == GoodsType.TEACHING || goods.getType() == GoodsType.STAFF){
                 	studentPaymentOrderDetail.setType(OrderDetailTypeEnum.TEACHING);
                 }else{
                 	studentPaymentOrderDetail.setType(OrderDetailTypeEnum.OTHER);
                 }
-                studentPaymentOrderDetail.setGoodsIdList(g.getId() + "");
+                studentPaymentOrderDetail.setGoodsIdList(goods.getId() + "");
                 
-                BigDecimal tempPrice = studentPaymentOrder.getExpectAmount().multiply(g.getGroupPurchasePrice()).divide(goodsPrice, RoundingMode.UP);
+                BigDecimal tempPrice = studentPaymentOrder.getExpectAmount().multiply(goods.getGroupPurchasePrice()).divide(goodsTotalGroupPurchasePrice, RoundingMode.UP);
                 
                 if(totalPrice.add(tempPrice).compareTo(studentPaymentOrder.getExpectAmount()) > 0){
                 	studentPaymentOrderDetail.setPrice(studentPaymentOrder.getExpectAmount().subtract(totalPrice));
@@ -827,57 +831,51 @@ public class SubjectChangeServiceImpl extends BaseServiceImpl<Integer, SubjectCh
             }
             sysUserCashAccountDetailService.insert(paymentDetail);
             
-			List<Goods> batchUpdateGoodsList = new ArrayList<Goods>();
-			
-			List<String> changeAccessoriesList = null;
-			List<String> originalAccessories = new ArrayList<String>();
-	        
-	        if(StringUtils.isNotBlank(subjectChange.getOriginalAccessories())){
-	        	changeAccessoriesList = Arrays.asList(subjectChange.getOriginalAccessories().split(","));
-	        	
-	        	if(StringUtils.isNotBlank(subjectChange.getChangeAccessories())){
-	        		originalAccessories = Arrays.asList(subjectChange.getChangeAccessories().split(","));
-	        	}
-	        	// changeAccessoriesList.removeAll(originalAccessories);
-	        	changeAccessoriesList = ListUtils.subtract(changeAccessoriesList, originalAccessories);
-	        	
-	        	if(subjectChange.getChangeMusical() != subjectChange.getOriginalMusical()){
-	        		changeAccessoriesList.add(subjectChange.getOriginalMusical()+"");
-	        	}
-	        }
-	        List<StudentPaymentOrderDetail> studentPaymentOrderDetailList = studentPaymentOrderDetailService.queryOrderDetail(subjectChange.getOriginalOrderId().longValue());
-	        String goodsIdsStr = studentPaymentOrderDetailList.stream().filter(t -> StringUtils.isNotBlank(t.getMinuendStockGoodsIdList())).map(t -> t.getMinuendStockGoodsIdList()).collect(Collectors.joining(","));
-	        originalAccessories = Arrays.asList(goodsIdsStr.split(","));
-	        originalAccessories.removeAll(changeAccessoriesList);
-	        
-	        goodsIdsStr = originalAccessories.stream().map(t -> t.toString()).collect(Collectors.joining(","));
             //增加商品库存
-            if(StringUtils.isNotBlank(goodsIdsStr)){
+            List<StudentPaymentOrderDetail> studentPaymentOrderDetailList = studentPaymentOrderDetailService.queryOrderDetail(subjectChange.getOriginalOrderId().longValue());
+            goodsIds = studentPaymentOrderDetailList.stream().filter(t -> StringUtils.isNotBlank(t.getMinuendStockGoodsIdList())).map(t -> t.getMinuendStockGoodsIdList()).collect(Collectors.joining(","));
+            if(StringUtils.isNotBlank(goodsIds)){
             	GoodsProcurement goodsProcurement = null;
-            	List<GoodsProcurement> goodsProcurementList = new ArrayList<GoodsProcurement>();
-            	List<Goods> goodsList = goodsService.getGoodsWithLocked(goodsIdsStr);
-            	for(Goods subGoods : goodsList){
-					subGoods.setStockCount(new AtomicInteger(subGoods.getStockCount()).incrementAndGet());
-					subGoods.setSellCount(new AtomicInteger(subGoods.getSellCount()).decrementAndGet());
-					subGoods.setUpdateTime(nowDate);
-					batchUpdateGoodsList.add(subGoods);
+            	List<Goods> goodsList = goodsService.getGoodsWithLocked(goodsIds);
+            	Map<Integer,Goods> goodsMap = goodsList.stream().collect(Collectors.toMap(Goods :: getId, t -> t));
+            	Goods goods = null;
+    			Map<Integer, Goods> batchUpdateGoodsMap = new HashMap<Integer, Goods>();
+    			Map<Long, GoodsProcurement> goodsProcurementMap = new HashMap<Long, GoodsProcurement>();
+            	
+            	for(String goodsIdStr : goodsIds.split(",")){
+            		if(StringUtils.isBlank(goodsIdStr)){
+						continue;
+					}
+					goods = goodsMap.get(Integer.parseInt(goodsIdStr));
+					if(batchUpdateGoodsMap.get(goods.getId()) != null){
+						goods = batchUpdateGoodsMap.get(goods.getId());
+					}
+					goods.setStockCount(new AtomicInteger(goods.getStockCount()).incrementAndGet());
+					goods.setSellCount(new AtomicInteger(goods.getSellCount()).decrementAndGet());
+					goods.setUpdateTime(nowDate);
+					
+					batchUpdateGoodsMap.put(goods.getId(), goods);
 					
 					// 进货清单
-					goodsProcurement = goodsProcurementDao.getWithStockSurplusProcurement(subGoods.getId());
+					goodsProcurement = goodsProcurementDao.getWithStockSurplusProcurement(goods.getId());
 					if(goodsProcurement != null){
+						if(goodsProcurementMap.get(goodsProcurement.getId()) != null){
+							goodsProcurement = goodsProcurementMap.get(goodsProcurement.getId());
+						}
 						goodsProcurement.setStockSoldNum(new AtomicInteger(goodsProcurement.getStockSoldNum()).decrementAndGet());
 						goodsProcurement.setUpdateTime(nowDate);
-						goodsProcurementList.add(goodsProcurement);
+						goodsProcurementMap.put(goodsProcurement.getId(), goodsProcurement);
 					}
+					
             	}
             	
-            	if(goodsProcurementList.size() > 0){
-            		goodsProcurementDao.batchUpdate(goodsProcurementList);
+            	if(goodsProcurementMap.size() > 0){
+            		goodsProcurementDao.batchUpdate(new ArrayList<GoodsProcurement>(goodsProcurementMap.values()));
             	}
-            }
-            
-            if(batchUpdateGoodsList.size() > 0){
-            	goodsService.batchUpdate(batchUpdateGoodsList);
+                
+                if(batchUpdateGoodsMap.size() > 0){
+                	goodsService.batchUpdate(new ArrayList<Goods>(batchUpdateGoodsMap.values()));
+                }
             }
         }
 
@@ -887,36 +885,51 @@ public class SubjectChangeServiceImpl extends BaseServiceImpl<Integer, SubjectCh
                 throw new BizException("声部更改订单更新失败");
             }
             
-			List<Goods> batchUpdateGoodsList = new ArrayList<Goods>();
             //增加商品库存
             List<StudentPaymentOrderDetail> studentPaymentOrderDetailList = studentPaymentOrderDetailService.queryOrderDetail(studentPaymentOrder.getId());
             String goodsIds = studentPaymentOrderDetailList.stream().filter(t -> StringUtils.isNotBlank(t.getMinuendStockGoodsIdList())).map(t -> t.getMinuendStockGoodsIdList()).collect(Collectors.joining(","));
             if(StringUtils.isNotBlank(goodsIds)){
             	GoodsProcurement goodsProcurement = null;
-            	List<GoodsProcurement> goodsProcurementList = new ArrayList<GoodsProcurement>();
             	List<Goods> goodsList = goodsService.getGoodsWithLocked(goodsIds);
-            	for(Goods subGoods : goodsList){
-					subGoods.setStockCount(new AtomicInteger(subGoods.getStockCount()).incrementAndGet());
-					subGoods.setSellCount(new AtomicInteger(subGoods.getSellCount()).decrementAndGet());
-					subGoods.setUpdateTime(nowDate);
-					batchUpdateGoodsList.add(subGoods);
+            	Map<Integer,Goods> goodsMap = goodsList.stream().collect(Collectors.toMap(Goods :: getId, t -> t));
+            	Goods goods = null;
+    			Map<Integer, Goods> batchUpdateGoodsMap = new HashMap<Integer, Goods>();
+    			Map<Long, GoodsProcurement> goodsProcurementMap = new HashMap<Long, GoodsProcurement>();
+            	
+            	for(String goodsIdStr : goodsIds.split(",")){
+            		if(StringUtils.isBlank(goodsIdStr)){
+						continue;
+					}
+					goods = goodsMap.get(Integer.parseInt(goodsIdStr));
+					if(batchUpdateGoodsMap.get(goods.getId()) != null){
+						goods = batchUpdateGoodsMap.get(goods.getId());
+					}
+					goods.setStockCount(new AtomicInteger(goods.getStockCount()).incrementAndGet());
+					goods.setSellCount(new AtomicInteger(goods.getSellCount()).decrementAndGet());
+					goods.setUpdateTime(nowDate);
+					
+					batchUpdateGoodsMap.put(goods.getId(), goods);
 					
 					// 进货清单
-					goodsProcurement = goodsProcurementDao.getWithStockSurplusProcurement(subGoods.getId());
+					goodsProcurement = goodsProcurementDao.getWithStockSurplusProcurement(goods.getId());
 					if(goodsProcurement != null){
+						if(goodsProcurementMap.get(goodsProcurement.getId()) != null){
+							goodsProcurement = goodsProcurementMap.get(goodsProcurement.getId());
+						}
 						goodsProcurement.setStockSoldNum(new AtomicInteger(goodsProcurement.getStockSoldNum()).decrementAndGet());
 						goodsProcurement.setUpdateTime(nowDate);
-						goodsProcurementList.add(goodsProcurement);
+						goodsProcurementMap.put(goodsProcurement.getId(), goodsProcurement);
 					}
+					
             	}
             	
-            	if(goodsProcurementList.size() > 0){
-            		goodsProcurementDao.batchUpdate(goodsProcurementList);
+            	if(goodsProcurementMap.size() > 0){
+            		goodsProcurementDao.batchUpdate(new ArrayList<GoodsProcurement>(goodsProcurementMap.values()));
             	}
-            }
-            
-            if(batchUpdateGoodsList.size() > 0){
-            	goodsService.batchUpdate(batchUpdateGoodsList);
+                
+                if(batchUpdateGoodsMap.size() > 0){
+                	goodsService.batchUpdate(new ArrayList<Goods>(batchUpdateGoodsMap.values()));
+                }
             }
             
             if (studentPaymentOrder.getBalancePaymentAmount() != null && studentPaymentOrder.getBalancePaymentAmount().compareTo(BigDecimal.ZERO) > 0) {