| 
					
				 | 
			
			
				@@ -1,10 +1,25 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 package com.ym.mec.biz.service.impl; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import java.util.ArrayList; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import java.util.HashMap; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import java.util.Iterator; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import java.util.List; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import java.util.Map; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import java.util.stream.Collectors; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.apache.commons.lang3.StringUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.springframework.beans.factory.annotation.Autowired; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.springframework.stereotype.Service; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.ym.mec.biz.dal.dao.MusicGroupDeliveryRecordDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.ym.mec.biz.dal.dao.StudentPaymentOrderDetailDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.ym.mec.biz.dal.dao.SubjectChangeDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.ym.mec.biz.dal.entity.Goods; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.ym.mec.biz.dal.entity.MusicGroupDeliveryRecord; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.ym.mec.biz.dal.entity.StudentPaymentOrderDetail; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.ym.mec.biz.dal.entity.SubjectChange; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.ym.mec.biz.dal.enums.DealStatusEnum; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.ym.mec.biz.service.GoodsService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.ym.mec.biz.service.MusicGroupDeliveryRecordService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.ym.mec.common.dal.BaseDAO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.ym.mec.common.service.impl.BaseServiceImpl; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -14,10 +29,74 @@ public class MusicGroupDeliveryRecordServiceImpl extends BaseServiceImpl<Long, M 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	@Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	private MusicGroupDeliveryRecordDao musicGroupDeliveryRecordDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	@Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	private StudentPaymentOrderDetailDao studentPaymentOrderDetailDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	@Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	private SubjectChangeDao subjectChangeDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	@Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	private GoodsService goodsService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	@Override 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	public BaseDAO<Long, MusicGroupDeliveryRecord> getDAO() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		return musicGroupDeliveryRecordDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	@Override 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	public List<Goods> queryDeliveryList(String musicGroupId, String deliveryBatchNo) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		//查询subject_change 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		List<SubjectChange> subjectChangeList = subjectChangeDao.queryByDeliveryBatchNo(musicGroupId, deliveryBatchNo); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		List<Integer> changeUserIdList = null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        StringBuilder goodsIdsStr = new StringBuilder(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		if(subjectChangeList != null && subjectChangeList.size() > 0){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			changeUserIdList = subjectChangeList.stream().distinct().map(t -> t.getStudentId()).collect(Collectors.toList()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			for(SubjectChange sc : subjectChangeList) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				if(StringUtils.isNotBlank(sc.getChangeAccessories())){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					goodsIdsStr.append(sc.getChangeAccessories()).append(","); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				if(sc.getChangeMusical() != null){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					goodsIdsStr.append(sc.getChangeMusical()).append(","); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		//查询student_payment_order_detail,剔除有声部更换的用户 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		List<StudentPaymentOrderDetail> studentPaymentOrderDetailList = studentPaymentOrderDetailDao.findUserApplyOrder(null, musicGroupId, DealStatusEnum.SUCCESS); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		studentPaymentOrderDetailList = studentPaymentOrderDetailList.stream().filter(t -> StringUtils.isNotBlank(t.getGoodsIdList())).collect(Collectors.toList()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		if(changeUserIdList != null && changeUserIdList.size() > 0){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			Iterator<StudentPaymentOrderDetail> iterator = studentPaymentOrderDetailList.iterator(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			while(iterator.hasNext()){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				if(changeUserIdList.contains(iterator.next().getUserId())){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					iterator.remove(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		for(StudentPaymentOrderDetail spod : studentPaymentOrderDetailList){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			goodsIdsStr.append(spod.getGoodsIdList()).append(","); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		List<Goods> goodsList = goodsService.findGoodsByIds(goodsIdsStr.toString()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		Map<Integer,Goods> goodsMap = new HashMap<Integer, Goods>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		for (Goods g : goodsList) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			if (goodsMap.containsKey(g.getId())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				g.setSellCount(goodsMap.get(g.getId()).getSellCount() + 1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			} else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				g.setSellCount(1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			goodsMap.put(g.getId(), g); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		return new ArrayList<Goods>(goodsMap.values()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 } 
			 |