|
@@ -1,25 +1,19 @@
|
|
|
package com.ym.mec.biz.service.impl;
|
|
|
|
|
|
-import com.ym.mec.biz.dal.dao.GoodsDao;
|
|
|
-import com.ym.mec.biz.dal.dao.StudentDao;
|
|
|
-import com.ym.mec.biz.dal.dao.SubjectChangeDao;
|
|
|
-import com.ym.mec.biz.dal.dao.SysConfigDao;
|
|
|
-import com.ym.mec.biz.dal.entity.StudentPaymentOrder;
|
|
|
-import com.ym.mec.biz.dal.entity.SubjectChange;
|
|
|
-import com.ym.mec.biz.dal.entity.SysUserCashAccount;
|
|
|
+import com.ym.mec.biz.dal.dao.*;
|
|
|
+import com.ym.mec.biz.dal.entity.*;
|
|
|
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.exception.BizException;
|
|
|
import com.ym.mec.common.service.IdGeneratorService;
|
|
|
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;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
|
|
|
@Service
|
|
|
public class SubjectChangeServiceImpl extends BaseServiceImpl<Integer, SubjectChange> implements SubjectChangeService {
|
|
@@ -42,6 +36,12 @@ public class SubjectChangeServiceImpl extends BaseServiceImpl<Integer, SubjectCh
|
|
|
private SysConfigDao sysConfigDao;
|
|
|
@Autowired
|
|
|
private PayService payService;
|
|
|
+ @Autowired
|
|
|
+ private StudentPaymentOrderDetailDao studentPaymentOrderDetailDao;
|
|
|
+ @Autowired
|
|
|
+ private MusicGroupDao musicGroupDao;
|
|
|
+ @Autowired
|
|
|
+ private SellOrderDao sellOrderDao;
|
|
|
|
|
|
@Override
|
|
|
public BaseDAO<Integer, SubjectChange> getDAO() {
|
|
@@ -198,4 +198,71 @@ public class SubjectChangeServiceImpl extends BaseServiceImpl<Integer, SubjectCh
|
|
|
}
|
|
|
return subjectChange;
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public SubjectChange getStudentOriginal(Integer studentId, String musicGroupId) {
|
|
|
+ //1、存在历史的更换
|
|
|
+ SubjectChange subjectChange = new SubjectChange();
|
|
|
+ SubjectChange studentLastChange = subjectChangeDao.getStudentLastChange(studentId, musicGroupId);
|
|
|
+ if (studentLastChange != null) {
|
|
|
+ subjectChange.setStudentId(studentLastChange.getStudentId());
|
|
|
+ subjectChange.setOrderId(studentLastChange.getOrderId());
|
|
|
+ subjectChange.setCooperationOrganId(studentLastChange.getCooperationOrganId());
|
|
|
+ subjectChange.setMusicGroupId(studentLastChange.getMusicGroupId());
|
|
|
+ subjectChange.setOriginalCourseFee(studentLastChange.getChangeCourseFee());
|
|
|
+ subjectChange.setKitGroupPurchaseType(studentLastChange.getKitGroupPurchaseType());
|
|
|
+ subjectChange.setOriginalCost(studentLastChange.getChangeCost());
|
|
|
+
|
|
|
+ if (studentLastChange.getChangeMusical() != null) {
|
|
|
+ subjectChange.setOriginalMusical(studentLastChange.getChangeMusical());
|
|
|
+ subjectChange.setOriginalMusicalGoods(goodsDao.get(studentLastChange.getChangeMusical()));
|
|
|
+ subjectChange.setOriginalMusicalPrice(studentLastChange.getOriginalMusicalPrice());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (studentLastChange.getChangeAccessories() != null) {
|
|
|
+ subjectChange.setOriginalAccessories(studentLastChange.getChangeAccessories());
|
|
|
+ subjectChange.setOriginalAccessoriesGoods(goodsDao.findGoodsByIds(studentLastChange.getChangeAccessories()));
|
|
|
+ subjectChange.setOriginalAccessoriesPrice(studentLastChange.getChangeAccessoriesPrice());
|
|
|
+ }
|
|
|
+ return subjectChange;
|
|
|
+ }
|
|
|
+ //2.1不存在历史的更换
|
|
|
+ List<StudentPaymentOrderDetail> details = studentPaymentOrderDetailDao.getStudentApplyDetail(studentId, musicGroupId);
|
|
|
+ if (details.size() <= 0) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ MusicGroup musicGroup = musicGroupDao.get(musicGroupId);
|
|
|
+ subjectChange.setStudentId(studentId);
|
|
|
+ subjectChange.setOrganId(musicGroup.getOrganId());
|
|
|
+ subjectChange.setCooperationOrganId(musicGroup.getCooperationOrganId());
|
|
|
+ subjectChange.setMusicGroupId(musicGroupId);
|
|
|
+ String accessoriesIds = "";
|
|
|
+ BigDecimal accessoriesPrice = BigDecimal.ZERO;
|
|
|
+ for (StudentPaymentOrderDetail detail : details) {
|
|
|
+ if (detail.getType().equals(OrderDetailTypeEnum.COURSE)) {
|
|
|
+ subjectChange.setOriginalCourseFee(detail.getPrice());
|
|
|
+ } else if (detail.getType().equals(OrderDetailTypeEnum.MUSICAL)) {
|
|
|
+ subjectChange.setKitGroupPurchaseType(detail.getKitGroupPurchaseType());
|
|
|
+ int goodsId = Integer.parseInt(detail.getGoodsIdList());
|
|
|
+ subjectChange.setOriginalMusical(goodsId);
|
|
|
+ subjectChange.setOriginalMusicalGoods(goodsDao.get(goodsId));
|
|
|
+ subjectChange.setOriginalMusicalPrice(detail.getPrice());
|
|
|
+ } else {
|
|
|
+ if (StringUtils.isNotBlank(detail.getGoodsIdList())) {
|
|
|
+ accessoriesPrice = accessoriesPrice.add(detail.getPrice());
|
|
|
+ accessoriesIds = accessoriesIds.length() > 0 ? accessoriesIds + "," + detail.getGoodsIdList() : detail.getGoodsIdList();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(accessoriesIds)) {
|
|
|
+ subjectChange.setOriginalAccessories(accessoriesIds);
|
|
|
+ subjectChange.setOriginalAccessoriesGoods(goodsDao.findGoodsByIds(accessoriesIds));
|
|
|
+ subjectChange.setOriginalAccessoriesPrice(accessoriesPrice);
|
|
|
+ }
|
|
|
+ Long orderId = details.get(0).getPaymentOrderId();
|
|
|
+ //2.2 计算销售成本
|
|
|
+ BigDecimal orderSellCost = sellOrderDao.getOrderSellCost(orderId);
|
|
|
+ subjectChange.setOriginalCost(orderSellCost == null ? BigDecimal.ZERO : orderSellCost);
|
|
|
+ return subjectChange;
|
|
|
+ }
|
|
|
}
|