yonge 4 years ago
parent
commit
959b2333a4

+ 4 - 4
mec-biz/src/main/java/com/ym/mec/biz/dal/dao/SellOrderDao.java

@@ -130,10 +130,10 @@ public interface SellOrderDao extends BaseDAO<Integer, SellOrder> {
     /**
      * 获取订单的销售成本
      *
-     * @param orderId
+     * @param orderIdList
      * @return
      */
-    BigDecimal getOrderSellCost(@Param("orderId") Long orderId);
+    BigDecimal getOrderSellCost(@Param("orderIdList") List<Long> orderIdList);
 
     /**
      * 获取声部更换的销售、成本
@@ -189,10 +189,10 @@ public interface SellOrderDao extends BaseDAO<Integer, SellOrder> {
     /**
      * 获取退货的sellOrder
      *
-     * @param orderId
+     * @param orderIdList
      * @return
      */
-    List<SellOrder> getRefundSellOrder(@Param("orderId") Long orderId);
+    List<SellOrder> getRefundSellOrder(@Param("orderIdList") List<Long> orderIdList);
 
     /**
      * 获取订单的各类型费用

+ 2 - 2
mec-biz/src/main/java/com/ym/mec/biz/service/SellOrderService.java

@@ -65,10 +65,10 @@ public interface SellOrderService extends BaseService<Integer, SellOrder> {
 
     /**
      * 获取订单退货的sellOrder
-     * @param orderId
+     * @param orderIdList
      * @return
      */
-    List<SellOrder> getRefundSellOrder(Long orderId);
+    List<SellOrder> getRefundSellOrder(List<Long> orderIdList);
 
 
     /**

+ 11 - 7
mec-biz/src/main/java/com/ym/mec/biz/service/impl/MusicGroupServiceImpl.java

@@ -1956,12 +1956,15 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
             
             List<StudentPaymentOrder> studentPaymentOrderList = new ArrayList<StudentPaymentOrder>();
             
-			if (studentRegistration.getMusicGroupPaymentCalenderId() == null) {
-				StudentPaymentOrder studentPaymentOrder = studentPaymentOrderService.findMusicGroupApplyOrderByStatus(userId, musicGroupId, SUCCESS);
-				if (studentPaymentOrder != null) {
-					studentPaymentOrderList.add(studentPaymentOrder);
-				}
-			} else {
+            if (studentRegistration.getMusicGroupPaymentCalenderId() == null) {
+    			if(currentStudentMusicGroupStatus == StudentMusicGroupStatusEnum.NORMAL || (currentStudentMusicGroupStatus == StudentMusicGroupStatusEnum.APPLY && studentRegistration.getPaymentStatus() == PaymentStatusEnum.YES)){
+    				StudentPaymentOrder studentPaymentOrder = studentPaymentOrderService.findMusicGroupApplyOrderByStatus(userId, musicGroupId, SUCCESS);
+    				if (studentPaymentOrder != null) {
+    					studentPaymentOrderList.add(studentPaymentOrder);
+    				}
+    			}
+    			
+    		} else {
 				studentPaymentOrderList = studentPaymentOrderService.queryByBatchNo(userId, studentRegistration.getMusicGroupPaymentCalenderId() + "",
 						DealStatusEnum.SUCCESS);
 			}
@@ -2225,12 +2228,13 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
         List<StudentPaymentOrder> studentPaymentOrderList = new ArrayList<StudentPaymentOrder>();
         
 		if (studentRegistration.getMusicGroupPaymentCalenderId() == null) {
-			if(currentStudentMusicGroupStatus == StudentMusicGroupStatusEnum.NORMAL){
+			if(currentStudentMusicGroupStatus == StudentMusicGroupStatusEnum.NORMAL || (currentStudentMusicGroupStatus == StudentMusicGroupStatusEnum.APPLY && studentRegistration.getPaymentStatus() == PaymentStatusEnum.YES)){
 				StudentPaymentOrder studentPaymentOrder = studentPaymentOrderService.findMusicGroupApplyOrderByStatus(userId, musicGroupId, SUCCESS);
 				if (studentPaymentOrder != null) {
 					studentPaymentOrderList.add(studentPaymentOrder);
 				}
 			}
+			
 		} else {
 			studentPaymentOrderList = studentPaymentOrderService.queryByBatchNo(sysUser.getId(), studentRegistration.getMusicGroupPaymentCalenderId() + "",
 					DealStatusEnum.SUCCESS);

+ 3 - 2
mec-biz/src/main/java/com/ym/mec/biz/service/impl/SellOrderServiceImpl.java

@@ -8,6 +8,7 @@ import com.ym.mec.biz.dal.enums.*;
 import com.ym.mec.biz.service.*;
 import com.ym.mec.common.dal.BaseDAO;
 import com.ym.mec.common.service.impl.BaseServiceImpl;
+
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -353,8 +354,8 @@ public class SellOrderServiceImpl extends BaseServiceImpl<Integer, SellOrder> im
     }
 
     @Override
-    public List<SellOrder> getRefundSellOrder(Long orderId) {
-        return sellOrderDao.getRefundSellOrder(orderId);
+    public List<SellOrder> getRefundSellOrder(List<Long> orderIdList) {
+        return sellOrderDao.getRefundSellOrder(orderIdList);
     }
 
     @Override

+ 0 - 5
mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentInstrumentServiceImpl.java

@@ -397,11 +397,6 @@ public class StudentInstrumentServiceImpl extends BaseServiceImpl<Long, StudentI
         studentInstrument.setChangeOrderId(subjectChange.getOrderId().longValue());
         studentInstrument.setGoodsId(subjectChange.getChangeMusical());
         
-        Goods goods = goodsDao.get(subjectChange.getChangeMusical());
-		if (goods == null) {
-			throw new BizException("商品[{}]不存在", subjectChange.getChangeMusical());
-		}
-        studentInstrument.setGoodsCategoryId(goods.getGoodsCategoryId());
         if (studentInstrument.getId() == null) {
             addStudentInstrument(studentInstrument);
             return true;

+ 53 - 7
mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentRegistrationServiceImpl.java

@@ -73,6 +73,7 @@ import com.ym.mec.biz.dal.entity.CloudTeacherOrder;
 import com.ym.mec.biz.dal.entity.CooperationOrgan;
 import com.ym.mec.biz.dal.entity.CourseSchedule;
 import com.ym.mec.biz.dal.entity.CourseScheduleStudentPayment;
+import com.ym.mec.biz.dal.entity.Goods;
 import com.ym.mec.biz.dal.entity.MusicGroup;
 import com.ym.mec.biz.dal.entity.MusicGroupPaymentCalender;
 import com.ym.mec.biz.dal.entity.MusicGroupPaymentCalenderCourseSettings;
@@ -329,14 +330,59 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
     }
 
     @Override
-    public List<StudentPaymentOrderDetail> queryFeeDetail(Integer studentId, String musicGroupId) {
-    	
-    	List<StudentPaymentOrder> studentPaymentOrderList = studentPaymentOrderService.queryByCondition(GroupType.MUSIC, musicGroupId, studentId, DealStatusEnum.SUCCESS, OrderTypeEnum.APPLY);
-    	
-    	List<Long> orderIdList = studentPaymentOrderList.stream().map(t -> t.getId()).collect(Collectors.toList());
+	public List<StudentPaymentOrderDetail> queryFeeDetail(Integer studentId, String musicGroupId) {
 
-        return studentPaymentOrderDetailService.getOrderDetail(orderIdList);
-    }
+		List<StudentPaymentOrder> studentPaymentOrderList = studentPaymentOrderService.queryByCondition(GroupType.MUSIC, musicGroupId, studentId,
+				DealStatusEnum.SUCCESS, OrderTypeEnum.APPLY);
+
+		List<Long> orderIdList = studentPaymentOrderList.stream().map(t -> t.getId()).collect(Collectors.toList());
+
+		List<StudentPaymentOrderDetail> studentPaymentOrderDetailList = studentPaymentOrderDetailService.getOrderDetail(orderIdList);
+
+		SubjectChange studentLastChange = subjectChangeDao.getStudentLastChange(studentId, musicGroupId);
+		
+		if (studentLastChange != null) {
+			Iterator<StudentPaymentOrderDetail> iterator = studentPaymentOrderDetailList.iterator();
+			StudentPaymentOrderDetail spod = null;
+			while (iterator.hasNext()) {
+				spod = iterator.next();
+				if (spod.getType() == OrderDetailTypeEnum.ACCESSORIES || spod.getType() == OrderDetailTypeEnum.MUSICAL) {
+					iterator.remove();
+				}
+			}
+
+			if (StringUtils.isNoneBlank(studentLastChange.getChangeAccessories())) {
+				StudentPaymentOrderDetail detail = new StudentPaymentOrderDetail();
+				detail.setGoodsIdList(studentLastChange.getChangeAccessories());
+				List<Goods> goods = goodsDao.findGoodsByIds(detail.getGoodsIdList());
+				if (goods != null && goods.size() > 0) {
+					detail.setName(goods.stream().map(t -> t.getName()).collect(Collectors.joining(",")));
+				}
+				detail.setPaymentOrderId((long) studentLastChange.getOriginalOrderId());
+				detail.setPrice(studentLastChange.getChangeAccessoriesPrice());
+				detail.setType(OrderDetailTypeEnum.ACCESSORIES);
+				detail.setCreateTime(studentLastChange.getCreateTime());
+
+				studentPaymentOrderDetailList.add(detail);
+			}
+			if (studentLastChange.getChangeMusical() != null) {
+				StudentPaymentOrderDetail detail = new StudentPaymentOrderDetail();
+				detail.setGoodsIdList(studentLastChange.getChangeMusical() + "");
+				List<Goods> goods = goodsDao.findGoodsByIds(detail.getGoodsIdList());
+				if (goods != null && goods.size() > 0) {
+					detail.setName(goods.stream().map(t -> t.getName()).collect(Collectors.joining(",")));
+				}
+				detail.setPaymentOrderId((long) studentLastChange.getOriginalOrderId());
+				detail.setPrice(studentLastChange.getChangeMusicalPrice());
+				detail.setType(OrderDetailTypeEnum.MUSICAL);
+				detail.setCreateTime(studentLastChange.getCreateTime());
+
+				studentPaymentOrderDetailList.add(detail);
+			}
+		}
+
+		return studentPaymentOrderDetailList;
+	}
 
     @Override
     public List<Map<String, Object>> getNoClassStuBySubjectId(String musicGroupId, String actualSubjectId) {

+ 36 - 11
mec-biz/src/main/java/com/ym/mec/biz/service/impl/SubjectChangeServiceImpl.java

@@ -1,5 +1,7 @@
 package com.ym.mec.biz.service.impl;
 
+import static com.ym.mec.biz.dal.enums.DealStatusEnum.SUCCESS;
+
 import com.ym.mec.biz.dal.dao.*;
 import com.ym.mec.biz.dal.entity.*;
 import com.ym.mec.biz.dal.enums.*;
@@ -13,6 +15,7 @@ import com.ym.mec.common.service.impl.BaseServiceImpl;
 import com.ym.mec.thirdparty.message.MessageSenderPluginContext;
 import com.ym.mec.util.collection.MapUtil;
 import com.ym.mec.util.date.DateUtil;
+
 import org.apache.commons.lang3.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -72,6 +75,8 @@ public class SubjectChangeServiceImpl extends BaseServiceImpl<Integer, SubjectCh
     private StudentInstrumentService studentInstrumentService;
     @Autowired
     private MusicGroupPurchaseListDao musicGroupPurchaseListDao;
+    @Autowired
+    private StudentRegistrationDao studentRegistrationDao;
 
     private final Logger logger = LoggerFactory.getLogger(this.getClass());
 
@@ -334,11 +339,14 @@ public class SubjectChangeServiceImpl extends BaseServiceImpl<Integer, SubjectCh
 
     @Override
     public SubjectChange getStudentOriginal(Integer studentId, String musicGroupId) {
+    	
         //1、存在历史的更换
         SubjectChange subjectChange = new SubjectChange();
         SubjectChange studentLastChange = subjectChangeDao.getStudentLastChange(studentId, musicGroupId);
         if (studentLastChange != null) {
-            Set<Integer> refundSellOrderGoodsIds = getRefundGoodsId(studentLastChange.getOrderId().longValue());
+        	List<Long> orderIdList = new ArrayList<Long>();
+        	orderIdList.add(studentLastChange.getOrderId().longValue());
+        	Set<Integer> refundSellOrderGoodsIds = getRefundGoodsId(orderIdList);
             subjectChange.setStudentId(studentLastChange.getStudentId());
             subjectChange.setOrderId(studentLastChange.getOrderId());
             subjectChange.setCooperationOrganId(studentLastChange.getCooperationOrganId());
@@ -374,12 +382,30 @@ public class SubjectChangeServiceImpl extends BaseServiceImpl<Integer, SubjectCh
             return subjectChange;
         }
         //2.1不存在历史的更换
-        List<StudentPaymentOrderDetail> details = studentPaymentOrderDetailDao.getStudentApplyDetail(studentId, musicGroupId);
-        if (details.size() <= 0) {
-            return null;
-        }
-
-        Set<Integer> refundSellOrderGoodsIds = getRefundGoodsId(details.get(0).getPaymentOrderId());
+        StudentRegistration studentRegistration = studentRegistrationDao.queryByUserIdAndMusicGroupId(studentId, musicGroupId);
+        if (studentRegistration == null) {
+            throw new BizException("用户注册信息不存在");
+        }
+        
+        List<StudentPaymentOrder> studentPaymentOrderList = new ArrayList<StudentPaymentOrder>();
+        
+		if (studentRegistration.getMusicGroupPaymentCalenderId() == null) {
+			if(studentRegistration.getMusicGroupStatus() == StudentMusicGroupStatusEnum.NORMAL){
+				StudentPaymentOrder studentPaymentOrder = studentPaymentOrderService.findMusicGroupApplyOrderByStatus(studentId, musicGroupId, SUCCESS);
+				if (studentPaymentOrder != null) {
+					studentPaymentOrderList.add(studentPaymentOrder);
+				}
+			}
+		} else {
+			studentPaymentOrderList = studentPaymentOrderService.queryByBatchNo(studentId, studentRegistration.getMusicGroupPaymentCalenderId() + "",
+					DealStatusEnum.SUCCESS);
+		}
+        
+        List<Long> paymentOrderIdList = studentPaymentOrderList.stream().map(t -> t.getId()).collect(Collectors.toList());
+
+        List<StudentPaymentOrderDetail> details = studentPaymentOrderDetailDao.getWithIds(paymentOrderIdList);
+
+        Set<Integer> refundSellOrderGoodsIds = getRefundGoodsId(details.stream().map(t -> t.getPaymentOrderId()).collect(Collectors.toList()));
 
         MusicGroup musicGroup = musicGroupDao.get(musicGroupId);
         subjectChange.setStudentId(studentId);
@@ -423,15 +449,14 @@ public class SubjectChangeServiceImpl extends BaseServiceImpl<Integer, SubjectCh
             BigDecimal price = accessoriesGoods.stream().map(Goods::getGroupPurchasePrice).reduce(BigDecimal.ZERO, BigDecimal::add);
             subjectChange.setOriginalAccessoriesPrice(price);
         }
-        Long orderId = details.get(0).getPaymentOrderId();
         //2.2 计算销售成本
-        BigDecimal orderSellCost = sellOrderDao.getOrderSellCost(orderId);
+        BigDecimal orderSellCost = sellOrderDao.getOrderSellCost(paymentOrderIdList);
         subjectChange.setOriginalCost(orderSellCost == null ? BigDecimal.ZERO : orderSellCost);
         return subjectChange;
     }
 
-    private Set<Integer> getRefundGoodsId(Long orderId) {
-        List<SellOrder> refundSellOrders = sellOrderService.getRefundSellOrder(orderId);
+    private Set<Integer> getRefundGoodsId(List<Long> orderIdList) {
+        List<SellOrder> refundSellOrders = sellOrderService.getRefundSellOrder(orderIdList);
         Set<Integer> refundSellOrderGoodsIds = refundSellOrders.stream().filter(e -> e.getParentGoodsId() == null).map(SellOrder::getGoodsId).collect(Collectors.toSet());
         Set<Integer> refundSellOrderParentGoodsId = refundSellOrders.stream().filter(e -> e.getParentGoodsId() != null).map(SellOrder::getParentGoodsId).collect(Collectors.toSet());
         refundSellOrderGoodsIds.addAll(refundSellOrderParentGoodsId);

+ 9 - 3
mec-biz/src/main/resources/config/mybatis/SellOrderMapper.xml

@@ -508,7 +508,10 @@
     <select id="getOrderSellCost" resultType="decimal">
         SELECT SUM(sell_cost_ * num_)
         FROM sell_order
-        WHERE order_id_ = #{orderId}
+        WHERE order_id_ IN
+        <foreach collection="orderIdList" item="orderId" open="(" close=")" separator=",">
+            #{orderId}
+        </foreach>
     </select>
 
     <!-- 获取分部学校的收入支出(声部更改) -->
@@ -579,8 +582,11 @@
     <select id="getRefundSellOrder" resultMap="SellOrder">
         SELECT *
         FROM sell_order
-        WHERE order_id_ = #{orderId}
-          AND status_ = 1
+        WHERE status_ = 1
+          and order_id_ in
+          <foreach collection="orderIdList" item="orderId" open="(" close=")" separator=",">
+            #{orderId}
+        </foreach>
     </select>
 
 

+ 6 - 0
mec-biz/src/main/resources/config/mybatis/StudentInstrumentMapper.xml

@@ -90,6 +90,12 @@
             <if test="delFlag != null">
                 del_flag_ = #{delFlag},
             </if>
+            <if test="goodsCategoryId != null">
+                goods_category_id_ = #{goodsCategoryId},
+            </if>
+            <if test="goodsCategoryName != null">
+                goods_category_name_ = #{goodsCategoryName},
+            </if>
             update_time = NOW(),
         </set>
         where id_ = #{id}

+ 1 - 3
mec-biz/src/main/resources/config/mybatis/StudentRegistrationMapper.xml

@@ -359,9 +359,7 @@
             <if test="noneNeedCloudTeacher != null">
                 none_need_cloud_teacher_ =#{noneNeedCloudTeacher},
             </if>
-            <if test="musicGroupPaymentCalenderId != null">
-                music_group_payment_calender_id_ =#{musicGroupPaymentCalenderId},
-            </if>
+                music_group_payment_calender_id_ =#{musicGroupPaymentCalenderId}
         </set>
         WHERE id_ = #{id}
     </update>