浏览代码

Merge branch 'master' of http://git.dayaedu.com/yonge/mec

zouxuan 4 年之前
父节点
当前提交
d645224ce8
共有 25 个文件被更改,包括 331 次插入96 次删除
  1. 9 0
      mec-biz/src/main/java/com/ym/mec/biz/dal/dao/CourseScheduleStudentPaymentDao.java
  2. 3 0
      mec-biz/src/main/java/com/ym/mec/biz/dal/dao/StudentRegistrationDao.java
  3. 20 0
      mec-biz/src/main/java/com/ym/mec/biz/dal/entity/CourseScheduleStudentPaymentDto.java
  4. 0 11
      mec-biz/src/main/java/com/ym/mec/biz/dal/entity/StudentCourseFeeDetail.java
  5. 10 0
      mec-biz/src/main/java/com/ym/mec/biz/dal/page/MusicGroupPaymentCalenderQueryInfo.java
  6. 28 0
      mec-biz/src/main/java/com/ym/mec/biz/event/CourseStatusChangeEvent.java
  7. 30 0
      mec-biz/src/main/java/com/ym/mec/biz/event/listener/CourseEventListener.java
  8. 30 0
      mec-biz/src/main/java/com/ym/mec/biz/event/source/CourseEventSource.java
  9. 10 1
      mec-biz/src/main/java/com/ym/mec/biz/service/CourseHomeworkService.java
  10. 8 0
      mec-biz/src/main/java/com/ym/mec/biz/service/CourseScheduleStudentPaymentService.java
  11. 0 2
      mec-biz/src/main/java/com/ym/mec/biz/service/GoodsService.java
  12. 2 2
      mec-biz/src/main/java/com/ym/mec/biz/service/StudentRegistrationService.java
  13. 44 0
      mec-biz/src/main/java/com/ym/mec/biz/service/impl/CourseHomeworkServiceImpl.java
  14. 8 0
      mec-biz/src/main/java/com/ym/mec/biz/service/impl/CourseScheduleServiceImpl.java
  15. 40 3
      mec-biz/src/main/java/com/ym/mec/biz/service/impl/CourseScheduleStudentPaymentServiceImpl.java
  16. 0 36
      mec-biz/src/main/java/com/ym/mec/biz/service/impl/GoodsServiceImpl.java
  17. 38 20
      mec-biz/src/main/java/com/ym/mec/biz/service/impl/MusicGroupPaymentCalenderServiceImpl.java
  18. 6 5
      mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentRegistrationServiceImpl.java
  19. 17 0
      mec-biz/src/main/resources/config/mybatis/CourseScheduleStudentPaymentMapper.xml
  20. 3 0
      mec-biz/src/main/resources/config/mybatis/MusicGroupPaymentCalenderMapper.xml
  21. 2 6
      mec-biz/src/main/resources/config/mybatis/StudentCourseFeeDetailMapper.xml
  22. 4 0
      mec-biz/src/main/resources/config/mybatis/StudentRegistrationMapper.xml
  23. 11 2
      mec-teacher/src/main/java/com/ym/mec/teacher/controller/CourseHomeworkController.java
  24. 0 8
      mec-web/src/main/java/com/ym/mec/web/controller/GoodsController.java
  25. 8 0
      mec-web/src/main/java/com/ym/mec/web/controller/TaskController.java

+ 9 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/dao/CourseScheduleStudentPaymentDao.java

@@ -3,6 +3,7 @@ package com.ym.mec.biz.dal.dao;
 import com.ym.mec.biz.dal.dto.*;
 import com.ym.mec.biz.dal.entity.CourseSchedule;
 import com.ym.mec.biz.dal.entity.CourseScheduleStudentPayment;
+import com.ym.mec.biz.dal.entity.CourseScheduleStudentPaymentDto;
 import com.ym.mec.biz.dal.enums.GroupType;
 import com.ym.mec.common.dal.BaseDAO;
 import org.apache.ibatis.annotations.Param;
@@ -392,4 +393,12 @@ public interface CourseScheduleStudentPaymentDao extends BaseDAO<Long, CourseSch
      */
     List<StudentVipDouble11Dto> countStudentDouble11CourseTime(@Param("userIds") List<Integer> userIds,
                                                                @Param("specialActivityIds") List<Integer> specialActivityIds);
+
+    /**
+     * @describe 获取需要更新课营收的课程
+     * @author qnc99
+     * @date 2020/12/2 0002
+     * @return java.util.List<com.ym.mec.biz.dal.entity.CourseScheduleStudentPaymentDto>
+     */
+    List<CourseScheduleStudentPaymentDto> findNeedUpdateActualPriceStudentCourses();
 }

+ 3 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/dao/StudentRegistrationDao.java

@@ -18,6 +18,9 @@ public interface StudentRegistrationDao extends BaseDAO<Long, StudentRegistratio
 
     StudentRegistration lock(@Param("id") Long id);
 
+    StudentRegistration lockWithUserAndMusic(@Param("userId") Integer userId,
+                                             @Param("musicGroupId") String musicGroupId);
+
     /**
      * 获取乐团学员报名详情
      *

+ 20 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/entity/CourseScheduleStudentPaymentDto.java

@@ -0,0 +1,20 @@
+package com.ym.mec.biz.dal.entity;
+
+import com.ym.mec.biz.dal.enums.CourseStatusEnum;
+
+/**
+ * @Author qnc99
+ * @Date 2020/12/2 0002
+ */
+public class CourseScheduleStudentPaymentDto extends CourseScheduleStudentPayment{
+
+    private CourseStatusEnum courseStatus;
+
+    public CourseStatusEnum getCourseStatus() {
+        return courseStatus;
+    }
+
+    public void setCourseStatus(CourseStatusEnum courseStatus) {
+        this.courseStatus = courseStatus;
+    }
+}

+ 0 - 11
mec-biz/src/main/java/com/ym/mec/biz/dal/entity/StudentCourseFeeDetail.java

@@ -11,9 +11,6 @@ public class StudentCourseFeeDetail {
 	/**  */
 	private Long studentRegistrationId;
 	
-	/** 交易类型 (RECHARGE 充值,PAY_FEE 缴费) */
-	private PlatformCashAccountDetailTypeEnum type;
-	
 	/** 交易金额 */
 	private java.math.BigDecimal amount;
 	
@@ -40,14 +37,6 @@ public class StudentCourseFeeDetail {
 		return this.studentRegistrationId;
 	}
 
-	public PlatformCashAccountDetailTypeEnum getType() {
-		return type;
-	}
-
-	public void setType(PlatformCashAccountDetailTypeEnum type) {
-		this.type = type;
-	}
-
 	public void setAmount(java.math.BigDecimal amount){
 		this.amount = amount;
 	}

+ 10 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/page/MusicGroupPaymentCalenderQueryInfo.java

@@ -16,6 +16,8 @@ public class MusicGroupPaymentCalenderQueryInfo extends QueryInfo {
 	private PaymentCalenderStatusEnum status;
 
 	private String organId;
+	
+	private String batchNo;
 
 	public MusicGroupPaymentCalender.PaymentType getPaymentType() {
 		return paymentType;
@@ -56,4 +58,12 @@ public class MusicGroupPaymentCalenderQueryInfo extends QueryInfo {
 	public void setStatus(PaymentCalenderStatusEnum status) {
 		this.status = status;
 	}
+
+	public String getBatchNo() {
+		return batchNo;
+	}
+
+	public void setBatchNo(String batchNo) {
+		this.batchNo = batchNo;
+	}
 }

+ 28 - 0
mec-biz/src/main/java/com/ym/mec/biz/event/CourseStatusChangeEvent.java

@@ -0,0 +1,28 @@
+package com.ym.mec.biz.event;
+
+import org.springframework.context.ApplicationEvent;
+
+import java.util.List;
+import java.util.Set;
+
+/**
+ * @Author qnc99
+ * @Date 2020/12/2 0002
+ */
+public class CourseStatusChangeEvent extends ApplicationEvent {
+
+    private Set<Long> courseIds;
+
+    public CourseStatusChangeEvent(Object source, Set<Long> courseIds) {
+        super(source);
+        this.courseIds = courseIds;
+    }
+
+    public Set<Long> getCourseIds() {
+        return courseIds;
+    }
+
+    public void setCourseIds(Set<Long> courseIds) {
+        this.courseIds = courseIds;
+    }
+}

+ 30 - 0
mec-biz/src/main/java/com/ym/mec/biz/event/listener/CourseEventListener.java

@@ -0,0 +1,30 @@
+package com.ym.mec.biz.event.listener;
+
+import com.ym.mec.biz.event.CourseStatusChangeEvent;
+import com.ym.mec.biz.service.CourseScheduleStudentPaymentService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.event.EventListener;
+import org.springframework.scheduling.annotation.Async;
+import org.springframework.stereotype.Component;
+
+/**
+ * @Author qnc99
+ * @Date 2020/12/2 0002
+ */
+@Component
+public class CourseEventListener {
+
+    private final Logger logger = LoggerFactory.getLogger(this.getClass());
+
+    @Autowired
+    private CourseScheduleStudentPaymentService courseScheduleStudentPaymentService;
+
+    @Async
+    @EventListener
+    public void courseStatusChangeMonitor(CourseStatusChangeEvent courseStatusChangeEvent){
+        logger.info("课程状态变更:{}", courseStatusChangeEvent.getCourseIds());
+        courseScheduleStudentPaymentService.updateCourseActualPrice();
+    }
+}

+ 30 - 0
mec-biz/src/main/java/com/ym/mec/biz/event/source/CourseEventSource.java

@@ -0,0 +1,30 @@
+package com.ym.mec.biz.event.source;
+
+import com.ym.mec.biz.event.CourseStatusChangeEvent;
+import org.springframework.context.ApplicationContext;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import java.util.Set;
+
+/**
+ * @Author qnc99
+ * @Date 2020/12/2 0002
+ */
+@Service
+public class CourseEventSource {
+
+    @Resource
+    private ApplicationContext applicationContext;
+
+    /**
+     * @describe 课程状态变更
+     * @author qnc99
+     * @date 2020/12/2 0002
+     * @return void
+     */
+    public void courseStatusChange(Set<Long> courseIds){
+        applicationContext.publishEvent(new CourseStatusChangeEvent(this, courseIds));
+    }
+
+}

+ 10 - 1
mec-biz/src/main/java/com/ym/mec/biz/service/CourseHomeworkService.java

@@ -13,6 +13,15 @@ import java.util.Map;
 public interface CourseHomeworkService extends BaseService<Long, CourseHomework> {
 
 	/**
+	 * @describe 布置作业
+	 * @author qnc99
+	 * @date 2020/12/2 0002
+	 * @param courseHomework:
+	 * @return void
+	 */
+	void addCourseHomework(CourseHomework courseHomework);
+
+	/**
 	 * @describe 根据班级获取教师布置的作业
 	 * @author Joburgess
 	 * @date 2019/10/20
@@ -46,4 +55,4 @@ public interface CourseHomeworkService extends BaseService<Long, CourseHomework>
 	 * @return
 	 */
 	PageInfo<WebCourseHomeworkListDto> queryHomePage(CourseHomeWorkTemplateQueryInfo queryInfo);
-}
+}

+ 8 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/CourseScheduleStudentPaymentService.java

@@ -109,4 +109,12 @@ public interface CourseScheduleStudentPaymentService extends BaseService<Long, C
 	 */
 	List<SimpleUserDto> getCourseStudents(List<Long> courseIds);
 
+	/**
+	 * @describe 更新课程营收
+	 * @author qnc99
+	 * @date 2020/12/2 0002
+	 * @return void
+	 */
+	void updateCourseActualPrice();
+
 }

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

@@ -89,8 +89,6 @@ public interface GoodsService extends BaseService<Integer, Goods> {
      */
     void sellOrderBatchNoAllot();
 
-    void getGoodsTest(List<Integer> goodsIds);
-
     /**
      * @describe 扣减商品库存
      * @author Joburgess

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

@@ -303,11 +303,11 @@ public interface StudentRegistrationService extends BaseService<Long, StudentReg
      * @describe 更新学生乐团可用课程余额
      * @author qnc99
      * @date 2020/12/2 0002
-     * @param studentRegistrationId:
+     * @param userId:
      * @param amount:
      * @param memo:
      * @param operatorId:
      * @return boolean
      */
-    boolean updateUserSurplusCourseFee(Long studentRegistrationId, BigDecimal amount, String memo, Integer operatorId);
+    boolean updateUserSurplusCourseFee(Integer userId, String musicGroupId, BigDecimal amount, String memo, Integer operatorId);
 }

+ 44 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/impl/CourseHomeworkServiceImpl.java

@@ -1,12 +1,14 @@
 package com.ym.mec.biz.service.impl;
 
 import com.ym.mec.biz.dal.dao.CourseHomeworkDao;
+import com.ym.mec.biz.dal.dao.CourseScheduleDao;
 import com.ym.mec.biz.dal.dao.StudentCourseHomeworkDao;
 import com.ym.mec.biz.dal.dao.StudentCourseHomeworkReplyDao;
 import com.ym.mec.biz.dal.dto.Mapper;
 import com.ym.mec.biz.dal.dto.TeacherHomeworkListDto;
 import com.ym.mec.biz.dal.dto.WebCourseHomeworkListDto;
 import com.ym.mec.biz.dal.entity.CourseHomework;
+import com.ym.mec.biz.dal.entity.CourseSchedule;
 import com.ym.mec.biz.dal.entity.StudentCourseHomework;
 import com.ym.mec.biz.dal.enums.MessageTypeEnum;
 import com.ym.mec.biz.dal.enums.YesOrNoEnum;
@@ -15,11 +17,13 @@ import com.ym.mec.biz.dal.page.CourseHomeworkQueryInfo;
 import com.ym.mec.biz.service.CourseHomeworkService;
 import com.ym.mec.biz.service.SysMessageService;
 import com.ym.mec.common.dal.BaseDAO;
+import com.ym.mec.common.exception.BizException;
 import com.ym.mec.common.page.PageInfo;
 import com.ym.mec.common.service.impl.BaseServiceImpl;
 import com.ym.mec.thirdparty.message.MessageSenderPluginContext.MessageSender;
 import com.ym.mec.util.collection.MapUtil;
 import com.ym.mec.util.date.DateUtil;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Propagation;
@@ -43,6 +47,8 @@ public class CourseHomeworkServiceImpl extends BaseServiceImpl<Long, CourseHomew
 
 	@Autowired
 	private SysMessageService sysMessageService;
+	@Autowired
+	private CourseScheduleDao courseScheduleDao;
 
 	@Override
 	public BaseDAO<Long, CourseHomework> getDAO() {
@@ -50,6 +56,44 @@ public class CourseHomeworkServiceImpl extends BaseServiceImpl<Long, CourseHomew
 	}
 
 	@Override
+	public void addCourseHomework(CourseHomework courseHomework) {
+		if(Objects.isNull(courseHomework.getCourseScheduleId())){
+			throw new BizException("课程不存在");
+		}
+		if(StringUtils.isBlank(courseHomework.getContent())){
+			throw new BizException("请填写作业内容");
+		}
+		CourseSchedule courseSchedule = courseScheduleDao.get(courseHomework.getCourseScheduleId());
+		if(Objects.isNull(courseSchedule)){
+			throw new BizException("课程不存在");
+		}
+		Date date=new Date();
+		CourseHomework oldCourseHomework = courseHomeworkDao.findByCourseSchedule(courseHomework.getCourseScheduleId());
+		if(Objects.isNull(oldCourseHomework)){
+			//新增课堂作业
+			oldCourseHomework=courseHomework;
+			oldCourseHomework.setCourseScheduleId(courseSchedule.getId());
+			oldCourseHomework.setMusicGroupId(courseSchedule.getMusicGroupId());
+			oldCourseHomework.setGroupType(courseSchedule.getGroupType());
+			oldCourseHomework.setClassGroupId(courseSchedule.getClassGroupId());
+			oldCourseHomework.setExpiryDate(DateUtil.addDays(date,7));
+			oldCourseHomework.setExpectNum(courseScheduleDao.countCourseStudentNum(courseSchedule.getId()));
+			courseHomeworkDao.insert(oldCourseHomework);
+			List<StudentCourseHomework> studentCourseHomeworks = studentCourseHomeworkDao
+					.constructInitialStudentHomeworkRecordsWithPayment(courseSchedule.getId(),
+							oldCourseHomework.getId());
+			if(CollectionUtils.isEmpty(studentCourseHomeworks)){
+				throw new BizException("此课程没有学生");
+			}
+			studentCourseHomeworkDao.batchInsertStudentCourseHomeworkRecord(studentCourseHomeworks);
+		}else{
+			oldCourseHomework.setContent(courseHomework.getContent());
+			oldCourseHomework.setAttachments(courseHomework.getAttachments());
+			courseHomeworkDao.update(oldCourseHomework);
+		}
+	}
+
+	@Override
 	public List<Map<String, Object>> findTeacherCourseHomeworkByClassGroup(CourseHomeworkQueryInfo queryInfo) {
 		Map<String, Object> params = new HashMap<>();
 		MapUtil.populateMap(params, queryInfo);

+ 8 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/impl/CourseScheduleServiceImpl.java

@@ -34,6 +34,7 @@ import java.util.stream.Stream;
 import com.ym.mec.biz.dal.entity.*;
 import com.ym.mec.biz.dal.dto.*;
 import com.ym.mec.biz.dal.enums.*;
+import com.ym.mec.biz.event.source.CourseEventSource;
 import org.apache.commons.collections.ListUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.slf4j.Logger;
@@ -213,6 +214,8 @@ public class CourseScheduleServiceImpl extends BaseServiceImpl<Long, CourseSched
 	private CoursesGroupModifyLogDao coursesGroupModifyLogDao;
     @Autowired
 	private ClassGroupTeacherMapperDao classGroupTeacherMapperDao;
+    @Autowired
+	private CourseEventSource courseEventSource;
 
     private final Logger LOGGER = LoggerFactory
             .getLogger(this.getClass());
@@ -3425,6 +3428,8 @@ public class CourseScheduleServiceImpl extends BaseServiceImpl<Long, CourseSched
 		//保存日志调整信息
 		saveModifyLog(modifyLogs,courseScheduleIds);
 
+		courseEventSource.courseStatusChange(new HashSet<>(courseScheduleIds));
+
 		// 推送
 		try {
 			Set<Integer> teacherIds = newCourseSchedules.stream().map(e -> e.getActualTeacherId()).collect(Collectors.toSet());
@@ -3975,6 +3980,9 @@ public class CourseScheduleServiceImpl extends BaseServiceImpl<Long, CourseSched
 
         if (updateList.size() > 0) {
             courseScheduleDao.batchUpdate(updateList);
+
+			Set<Long> courseIds = updateList.stream().map(CourseSchedule::getId).collect(Collectors.toSet());
+			courseEventSource.courseStatusChange(courseIds);
         }
 
         // 更新班级已上课次

+ 40 - 3
mec-biz/src/main/java/com/ym/mec/biz/service/impl/CourseScheduleStudentPaymentServiceImpl.java

@@ -9,6 +9,7 @@ import com.ym.mec.biz.dal.entity.*;
 import com.ym.mec.biz.dal.enums.*;
 import com.ym.mec.biz.dal.page.CourseScheduleStudentPaymentQueryInfo;
 import com.ym.mec.biz.service.CourseScheduleStudentPaymentService;
+import com.ym.mec.biz.service.StudentRegistrationService;
 import com.ym.mec.biz.service.SysUserCashAccountService;
 import com.ym.mec.common.constant.CommonConstants;
 import com.ym.mec.common.dal.BaseDAO;
@@ -61,6 +62,8 @@ public class CourseScheduleStudentPaymentServiceImpl extends BaseServiceImpl<Lon
 	private StudentDao studentDao;
 	@Autowired
 	private SubjectDao subjectDao;
+	@Autowired
+	private StudentRegistrationService studentRegistrationService;
 
 	@Override
 	public BaseDAO<Long, CourseScheduleStudentPayment> getDAO() {
@@ -405,9 +408,9 @@ public class CourseScheduleStudentPaymentServiceImpl extends BaseServiceImpl<Lon
 			}
 		}
 		courseScheduleStudentPaymentDao.batchInsert(courseScheduleStudentPayments);
-		for (String batchNo : allBatchNos) {
-			updateForMusicGroupWithPaymentCalender(batchNo);
-		}
+//		for (String batchNo : allBatchNos) {
+//			updateForMusicGroupWithPaymentCalender(batchNo);
+//		}
 	}
 
 	@Override
@@ -571,4 +574,38 @@ public class CourseScheduleStudentPaymentServiceImpl extends BaseServiceImpl<Lon
 		}
 		return usersSimpleInfo;
 	}
+
+	@Override
+	@Transactional(rollbackFor = Exception.class)
+	public void updateCourseActualPrice() {
+		List<CourseScheduleStudentPaymentDto> courseScheduleStudentPayments = courseScheduleStudentPaymentDao.findNeedUpdateActualPriceStudentCourses();
+		if(CollectionUtils.isEmpty(courseScheduleStudentPayments)){
+			return;
+		}
+		List<CourseScheduleStudentPayment> needUpdates = new ArrayList<>();
+		Map<CourseStatusEnum, List<CourseScheduleStudentPaymentDto>> statusCoursesMap = courseScheduleStudentPayments.stream().collect(Collectors.groupingBy(CourseScheduleStudentPaymentDto::getCourseStatus));
+		if(statusCoursesMap.containsKey(CourseStatusEnum.NOT_START)){
+			List<CourseScheduleStudentPaymentDto> notStartCourses = statusCoursesMap.get(CourseStatusEnum.NOT_START);
+			for (CourseScheduleStudentPaymentDto notStartCourse : notStartCourses) {
+				studentRegistrationService.updateUserSurplusCourseFee(notStartCourse.getUserId(), notStartCourse.getMusicGroupId(), notStartCourse.getActualPrice(), StringUtils.join("课程状态变更到未开始,退还缴费:", notStartCourse.getCourseScheduleId()), null);
+				notStartCourse.setActualPrice(BigDecimal.ZERO);
+				needUpdates.add(notStartCourse);
+			}
+		}
+
+		if(statusCoursesMap.containsKey(CourseStatusEnum.OVER)){
+			List<CourseScheduleStudentPaymentDto> notStartCourses = statusCoursesMap.get(CourseStatusEnum.OVER);
+			for (CourseScheduleStudentPaymentDto notStartCourse : notStartCourses) {
+				boolean isUpdate = studentRegistrationService.updateUserSurplusCourseFee(notStartCourse.getUserId(), notStartCourse.getMusicGroupId(), notStartCourse.getExpectPrice().negate(), StringUtils.join("课程结束,扣除课程费用:", notStartCourse.getCourseScheduleId()), null);
+				if(!isUpdate){
+					continue;
+				}
+				notStartCourse.setActualPrice(notStartCourse.getExpectPrice());
+				needUpdates.add(notStartCourse);
+			}
+		}
+		if(!CollectionUtils.isEmpty(needUpdates)){
+			courseScheduleStudentPaymentDao.batchUpdate(needUpdates);
+		}
+	}
 }

+ 0 - 36
mec-biz/src/main/java/com/ym/mec/biz/service/impl/GoodsServiceImpl.java

@@ -466,42 +466,6 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods>  implement
 
 	@Override
 	@Transactional(rollbackFor = Exception.class, isolation = Isolation.READ_COMMITTED)
-	public void getGoodsTest(List<Integer> goodsIds) {
-		goodsDao.lockGoods(new ArrayList<>(goodsIds));
-		for (Integer goodsId : goodsIds) {
-			Goods tempGoods = goodsDao.get(goodsId);
-			List<Goods> childGoods = new ArrayList<>();
-			if(StringUtils.isBlank(tempGoods.getComplementGoodsIdList())){
-				childGoods.add(tempGoods);
-			}else{
-				List<Integer> complementGoodsIds = Arrays.stream(tempGoods.getComplementGoodsIdList().split(",")).map(s -> Integer.valueOf(s)).collect(Collectors.toList());
-				childGoods = goodsDao.getGoodies(complementGoodsIds);
-			}
-			for (Goods goods : childGoods) {
-				GoodsProcurement goodsProcurement;
-				if(StockType.INTERNAL.equals(goods.getStockType())||(StockType.ALL.equals(goods.getStockType())&&AccountType.INTERNAL.equals(AccountType.INTERNAL))){
-					goodsProcurement = goodsProcurementDao.getWithStockSurplusProcurement(goods.getId());
-					goods.setStockCount(new AtomicInteger(goods.getStockCount()).decrementAndGet());
-					if(Objects.nonNull(goodsProcurement)){
-						goodsProcurement.setStockSoldNum(new AtomicInteger(goodsProcurement.getStockSoldNum()).incrementAndGet());
-					}
-				}else if(StockType.EXTERNAL.equals(goods.getStockType())||(StockType.ALL.equals(goods.getStockType())&&AccountType.EXTERNAL.equals(AccountType.EXTERNAL))){
-					goodsProcurement = goodsProcurementDao.getWithTaxStockSurplusProcurement(goods.getId());
-					goods.setTaxStockCount(new AtomicInteger(goods.getTaxStockCount()).decrementAndGet());
-					if(Objects.nonNull(goodsProcurement)){
-						goodsProcurement.setTaxStockSoldNum(new AtomicInteger(goodsProcurement.getTaxStockSoldNum()).incrementAndGet());
-					}
-				}
-
-				goods.setSellCount(new AtomicInteger(goods.getSellCount()).incrementAndGet());
-
-				goodsDao.update(goods);
-			}
-		}
-	}
-
-	@Override
-	@Transactional(rollbackFor = Exception.class, isolation = Isolation.READ_COMMITTED)
 	public List<SellOrder> subtractStock(List<Integer> goodsIds, AccountType accountType) {
 		if(CollectionUtils.isEmpty(goodsIds)){
 			return Collections.emptyList();

+ 38 - 20
mec-biz/src/main/java/com/ym/mec/biz/service/impl/MusicGroupPaymentCalenderServiceImpl.java

@@ -65,7 +65,6 @@ import com.ym.mec.biz.dal.entity.MusicGroupStudentFee;
 import com.ym.mec.biz.dal.entity.MusicGroupStudentFee.PaymentStatus;
 import com.ym.mec.biz.dal.entity.Organization;
 import com.ym.mec.biz.dal.entity.OrganizationCourseUnitPriceSettings;
-import com.ym.mec.biz.dal.entity.StudentRegistration;
 import com.ym.mec.biz.dal.enums.MessageTypeEnum;
 import com.ym.mec.biz.dal.enums.MusicGroupStatusEnum;
 import com.ym.mec.biz.dal.enums.PaymentStatusEnum;
@@ -263,6 +262,7 @@ public class MusicGroupPaymentCalenderServiceImpl extends BaseServiceImpl<Long,
 			List<MusicGroupPaymentCalenderCourseSettings> newCSList = new ArrayList<MusicGroupPaymentCalenderCourseSettings>(
 					musicGroupPaymentCalenderCourseSettingsList.size());
 
+			BigDecimal totalPaymentAmount = new BigDecimal(0);
 			for (MusicGroupPaymentCalenderCourseSettings pccs : musicGroupPaymentCalenderCourseSettingsList) {
 
 				MusicGroupPaymentCalenderCourseSettings tempPccs = new MusicGroupPaymentCalenderCourseSettings();
@@ -273,23 +273,36 @@ public class MusicGroupPaymentCalenderServiceImpl extends BaseServiceImpl<Long,
 				}
 				if (i == 0) {
 					tempPccs.setCourseCurrentPrice(pccs.getCourseCurrentPrice().subtract(
-							pccs.getCourseCurrentPrice().divide(new BigDecimal(times)).setScale(2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(times - 1))));
+							pccs.getCourseCurrentPrice().divide(new BigDecimal(times), 2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(times - 1))
+									.setScale(2, BigDecimal.ROUND_DOWN)));
 					tempPccs.setCourseOriginalPrice(pccs.getCourseOriginalPrice().subtract(
-							pccs.getCourseOriginalPrice().divide(new BigDecimal(times)).setScale(2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(times - 1))));
+							pccs.getCourseOriginalPrice().divide(new BigDecimal(times), 2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(times - 1))
+									.setScale(2, BigDecimal.ROUND_DOWN)));
 					tempPccs.setCourseTotalMinuties(pccs.getCourseTotalMinuties() - pccs.getCourseTotalMinuties() / times * (times - 1));
 				} else {
-					tempPccs.setCourseCurrentPrice(pccs.getCourseCurrentPrice().divide(new BigDecimal(times)).setScale(2, BigDecimal.ROUND_DOWN));
-					tempPccs.setCourseOriginalPrice(pccs.getCourseOriginalPrice().divide(new BigDecimal(times)).setScale(2, BigDecimal.ROUND_DOWN));
+					tempPccs.setCourseCurrentPrice(pccs.getCourseCurrentPrice().divide(new BigDecimal(times), 2, BigDecimal.ROUND_DOWN));
+					tempPccs.setCourseOriginalPrice(pccs.getCourseOriginalPrice().divide(new BigDecimal(times), 2, BigDecimal.ROUND_DOWN));
 					tempPccs.setCourseTotalMinuties(pccs.getCourseTotalMinuties() / times);
 				}
+				totalPaymentAmount = totalPaymentAmount.add(tempPccs.getCourseCurrentPrice());
 				newCSList.add(tempPccs);
 			}
 			musicGroupPaymentCalender.setMusicGroupPaymentCalenderCourseSettingsList(newCSList);
+			musicGroupPaymentCalender.setPaymentAmount(totalPaymentAmount);
 
 			musicGroupPaymentCalender.setPaymentPattern(musicGroupPaymentCalenderDto.getPaymentPattern());
 			musicGroupPaymentCalender.setPaymentValidEndDate(musicGroupPaymentDateRange.getPaymentValidEndDate());
 			musicGroupPaymentCalender.setPaymentValidStartDate(musicGroupPaymentDateRange.getPaymentValidStartDate());
-			musicGroupPaymentCalender.setPaymentType(musicGroupPaymentCalenderDto.getPaymentType());
+			
+			if (paymentType == PaymentType.MUSIC_APPLY) {
+				if (i == 0) {
+					musicGroupPaymentCalender.setPaymentType(paymentType);
+				} else {
+					musicGroupPaymentCalender.setPaymentType(PaymentType.MUSIC_RENEW);
+				}
+			} else {
+				musicGroupPaymentCalender.setPaymentType(paymentType);
+			}
 			musicGroupPaymentCalender.setPayUserType(musicGroupPaymentCalenderDto.getPayUserType());
 			musicGroupPaymentCalender.setStartPaymentDate(musicGroupPaymentDateRange.getStartPaymentDate());
 			musicGroupPaymentCalender.setStudentIds(musicGroupPaymentCalenderDto.getStudentIds());
@@ -445,14 +458,6 @@ public class MusicGroupPaymentCalenderServiceImpl extends BaseServiceImpl<Long,
 			throw new BizException("请登录");
 		}
 
-		// 不是进行中,只能创建一次缴费
-		if (musicGroup.getStatus() != MusicGroupStatusEnum.PROGRESS) {
-			List<MusicGroupPaymentCalender> list = musicGroupPaymentCalenderDao.findByMusicGroupId(musicGroupId);
-			if (list.size() > 0) {
-				throw new BizException("创建失败,已经存在缴费信息");
-			}
-		}
-		
 		List<Long> calenderIds = musicGroupPaymentCalenderList.stream().map(MusicGroupPaymentCalender :: getId).collect(Collectors.toList());
 		//删除原来数据
 		musicGroupPaymentCalenderDao.delByIds(calenderIds);
@@ -539,6 +544,7 @@ public class MusicGroupPaymentCalenderServiceImpl extends BaseServiceImpl<Long,
 			List<MusicGroupPaymentCalenderCourseSettings> newCSList = new ArrayList<MusicGroupPaymentCalenderCourseSettings>(
 					musicGroupPaymentCalenderCourseSettingsList.size());
 
+			BigDecimal totalPaymentAmount = new BigDecimal(0);
 			for (MusicGroupPaymentCalenderCourseSettings pccs : musicGroupPaymentCalenderCourseSettingsList) {
 
 				MusicGroupPaymentCalenderCourseSettings tempPccs = new MusicGroupPaymentCalenderCourseSettings();
@@ -549,23 +555,36 @@ public class MusicGroupPaymentCalenderServiceImpl extends BaseServiceImpl<Long,
 				}
 				if (i == 0) {
 					tempPccs.setCourseCurrentPrice(pccs.getCourseCurrentPrice().subtract(
-							pccs.getCourseCurrentPrice().divide(new BigDecimal(times)).setScale(2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(times - 1))));
+							pccs.getCourseCurrentPrice().divide(new BigDecimal(times), 2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(times - 1))
+									.setScale(2, BigDecimal.ROUND_DOWN)));
 					tempPccs.setCourseOriginalPrice(pccs.getCourseOriginalPrice().subtract(
-							pccs.getCourseOriginalPrice().divide(new BigDecimal(times)).setScale(2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(times - 1))));
+							pccs.getCourseOriginalPrice().divide(new BigDecimal(times), 2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(times - 1))
+									.setScale(2, BigDecimal.ROUND_DOWN)));
 					tempPccs.setCourseTotalMinuties(pccs.getCourseTotalMinuties() - pccs.getCourseTotalMinuties() / times * (times - 1));
 				} else {
-					tempPccs.setCourseCurrentPrice(pccs.getCourseCurrentPrice().divide(new BigDecimal(times)).setScale(2, BigDecimal.ROUND_DOWN));
-					tempPccs.setCourseOriginalPrice(pccs.getCourseOriginalPrice().divide(new BigDecimal(times)).setScale(2, BigDecimal.ROUND_DOWN));
+					tempPccs.setCourseCurrentPrice(pccs.getCourseCurrentPrice().divide(new BigDecimal(times), 2, BigDecimal.ROUND_DOWN));
+					tempPccs.setCourseOriginalPrice(pccs.getCourseOriginalPrice().divide(new BigDecimal(times), 2, BigDecimal.ROUND_DOWN));
 					tempPccs.setCourseTotalMinuties(pccs.getCourseTotalMinuties() / times);
 				}
+				totalPaymentAmount = totalPaymentAmount.add(tempPccs.getCourseCurrentPrice());
 				newCSList.add(tempPccs);
 			}
 			musicGroupPaymentCalender.setMusicGroupPaymentCalenderCourseSettingsList(newCSList);
+			musicGroupPaymentCalender.setPaymentAmount(totalPaymentAmount);
 
 			musicGroupPaymentCalender.setPaymentPattern(musicGroupPaymentCalenderDto.getPaymentPattern());
 			musicGroupPaymentCalender.setPaymentValidEndDate(musicGroupPaymentDateRange.getPaymentValidEndDate());
 			musicGroupPaymentCalender.setPaymentValidStartDate(musicGroupPaymentDateRange.getPaymentValidStartDate());
-			musicGroupPaymentCalender.setPaymentType(musicGroupPaymentCalenderDto.getPaymentType());
+			
+			if (paymentType == PaymentType.MUSIC_APPLY) {
+				if (i == 0) {
+					musicGroupPaymentCalender.setPaymentType(paymentType);
+				} else {
+					musicGroupPaymentCalender.setPaymentType(PaymentType.MUSIC_RENEW);
+				}
+			} else {
+				musicGroupPaymentCalender.setPaymentType(paymentType);
+			}
 			musicGroupPaymentCalender.setPayUserType(musicGroupPaymentCalenderDto.getPayUserType());
 			musicGroupPaymentCalender.setStartPaymentDate(musicGroupPaymentDateRange.getStartPaymentDate());
 			musicGroupPaymentCalender.setStudentIds(musicGroupPaymentCalenderDto.getStudentIds());
@@ -1145,7 +1164,6 @@ public class MusicGroupPaymentCalenderServiceImpl extends BaseServiceImpl<Long,
 		calender.setActualNum(actualNum + 1);
 		calender.setUpdateTime(date);
 		musicGroupPaymentCalenderDao.update(calender);
-		courseScheduleStudentPaymentService.updateForMusicGroupWithPaymentCalender(calender.getBatchNo());
 		return musicGroupStudentFee;
 	}
 

+ 6 - 5
mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentRegistrationServiceImpl.java

@@ -1281,8 +1281,8 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
 
     @Override
     @Transactional(rollbackFor = Exception.class, isolation = Isolation.READ_COMMITTED)
-    public boolean updateUserSurplusCourseFee(Long studentRegistrationId, BigDecimal amount, String memo, Integer operatorId) {
-        StudentRegistration studentRegistration = studentRegistrationDao.lock(studentRegistrationId);
+    public boolean updateUserSurplusCourseFee(Integer userId, String musicGroupId, BigDecimal amount, String memo, Integer operatorId) {
+        StudentRegistration studentRegistration = studentRegistrationDao.lockWithUserAndMusic(userId, musicGroupId);
         if(Objects.isNull(studentRegistration)){
             throw new BizException("学员注册信息不存在");
         }
@@ -1291,13 +1291,14 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
             return true;
         }
 
-        if(studentRegistration.getSurplusCourseFee().compareTo(amount)<0){
+        studentRegistration.setSurplusCourseFee(studentRegistration.getSurplusCourseFee().add(amount));
+
+        if(BigDecimal.ZERO.compareTo(studentRegistration.getSurplusCourseFee())>0){
             return false;
         }
-        studentRegistration.setSurplusCourseFee(studentRegistration.getSurplusCourseFee().add(amount));
 
         StudentCourseFeeDetail studentCourseFeeDetail = new StudentCourseFeeDetail();
-        studentCourseFeeDetail.setStudentRegistrationId(studentRegistrationId);
+        studentCourseFeeDetail.setStudentRegistrationId(studentRegistration.getId());
         studentCourseFeeDetail.setAmount(amount);
         studentCourseFeeDetail.setSurplusCourseFee(studentRegistration.getSurplusCourseFee());
         studentCourseFeeDetail.setMemo(memo);

+ 17 - 0
mec-biz/src/main/resources/config/mybatis/CourseScheduleStudentPaymentMapper.xml

@@ -30,6 +30,10 @@
 		<result column="freePracticeTimes" property="freePracticeCourseTimes" />
 	</resultMap>
 
+	<resultMap id="CourseScheduleStudentPaymentDto" type="com.ym.mec.biz.dal.entity.CourseScheduleStudentPaymentDto" extends="CourseScheduleStudentPayment">
+		<result column="course_status_" property="courseStatus" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
+	</resultMap>
+
 	<!-- 根据主键查询一条记录 -->
 	<select id="get" resultMap="CourseScheduleStudentPayment" >
 		SELECT * FROM course_schedule_student_payment WHERE id_ = #{id}
@@ -619,4 +623,17 @@
 		GROUP BY
 			cssp.user_id_
     </select>
+
+	<select id="findNeedUpdateActualPriceStudentCourses" resultMap="CourseScheduleStudentPaymentDto">
+		SELECT
+			cssp.*,
+			cs.status_ course_status_
+		FROM
+			course_schedule_student_payment cssp
+		LEFT JOIN course_schedule cs ON cs.id_ = cssp.course_schedule_id_
+		WHERE
+			cssp.batch_no_ IS NOT NULL
+			AND ((cs.status_ = 'OVER' AND (cssp.actual_price_ IS NULL OR cssp.actual_price_ &lt;= 0))
+			OR ( cs.status_ = 'NOT_START' AND (cssp.actual_price_ IS NOT NULL AND cssp.actual_price_ &gt; 0)))
+	</select>
 </mapper>

+ 3 - 0
mec-biz/src/main/resources/config/mybatis/MusicGroupPaymentCalenderMapper.xml

@@ -248,6 +248,9 @@
             <if test="musicGroupId != null">
                 AND mgpc.music_group_id_ = #{musicGroupId}
             </if>
+            <if test="batchNo != null">
+                AND mgpc.batch_no_ = #{batchNo}
+            </if>
             <if test="payUserType != null">
                 AND mgpc.pay_user_type_ = #{payUserType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
             </if>

+ 2 - 6
mec-biz/src/main/resources/config/mybatis/StudentCourseFeeDetailMapper.xml

@@ -8,7 +8,6 @@
 	
 	<resultMap type="com.ym.mec.biz.dal.entity.StudentCourseFeeDetail" id="StudentCourseFeeDetail">
 		<result column="student_registration_id_" property="studentRegistrationId" />
-		<result column="type_" property="type" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler" />
 		<result column="amount_" property="amount" />
 		<result column="surplus_course_fee_" property="surplusCourseFee" />
 		<result column="memo_" property="memo" />
@@ -24,16 +23,13 @@
 	
 	<!-- 向数据库增加一条记录 -->
 	<insert id="insert" parameterType="com.ym.mec.biz.dal.entity.StudentCourseFeeDetail" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
-		INSERT INTO student_course_fee_detail (student_registration_id_,type_,amount_,surplus_course_fee_,memo_,operator_,create_time_,update_time_)
-		VALUES(#{studentRegistrationId},#{type,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},#{amount},#{surplusCourseFee},#{memo},#{operator},NOW(),NOW())
+		INSERT INTO student_course_fee_detail (student_registration_id_,amount_,surplus_course_fee_,memo_,operator_,create_time_,update_time_)
+		VALUES(#{studentRegistrationId},#{amount},#{surplusCourseFee},#{memo},#{operator},NOW(),NOW())
 	</insert>
 
 	<update id="update" parameterType="com.ym.mec.biz.dal.entity.StudentCourseFeeDetail">
 		UPDATE student_course_fee_detail
 		<set>
-			<if test="type!=null">
-				type_ = #{type,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
-			</if>
 			<if test="amount!=null">
 				amount_ = #{amount},
 			</if>

+ 4 - 0
mec-biz/src/main/resources/config/mybatis/StudentRegistrationMapper.xml

@@ -87,6 +87,10 @@
         SELECT * FROM student_registration WHERE id_ = #{id} FOR UPDATE
     </select>
 
+    <select id="lockWithUserAndMusic" resultMap="StudentRegistration">
+        SELECT * FROM student_registration WHERE user_id_ = #{userId} AND music_group_id_=#{musicGroupId} FOR UPDATE
+    </select>
+
     <!-- 全查询 -->
     <select id="findAll" resultMap="StudentRegistration">
         SELECT *

+ 11 - 2
mec-teacher/src/main/java/com/ym/mec/teacher/controller/CourseHomeworkController.java

@@ -3,6 +3,7 @@ package com.ym.mec.teacher.controller;
 import com.ym.mec.auth.api.client.SysUserFeignService;
 import com.ym.mec.auth.api.entity.SysUser;
 import com.ym.mec.biz.dal.dto.CourseHomeworkStudentDetailDto;
+import com.ym.mec.biz.dal.entity.CourseHomework;
 import com.ym.mec.biz.dal.entity.ExtracurricularExercisesReply;
 import com.ym.mec.biz.dal.entity.StudentCourseHomework;
 import com.ym.mec.biz.dal.enums.YesOrNoEnum;
@@ -11,6 +12,7 @@ import com.ym.mec.biz.service.CourseHomeworkService;
 import com.ym.mec.biz.service.ExtracurricularExercisesReplyService;
 import com.ym.mec.biz.service.StudentCourseHomeworkService;
 import com.ym.mec.common.controller.BaseController;
+import com.ym.mec.common.entity.HttpResponseResult;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -31,7 +33,7 @@ import java.util.Objects;
 public class CourseHomeworkController extends BaseController {
 
     @Autowired
-    private CourseHomeworkService courseScheduleService;
+    private CourseHomeworkService courseHomeworkService;
     @Autowired
     private StudentCourseHomeworkService studentCourseHomeworkService;
     @Autowired
@@ -39,6 +41,13 @@ public class CourseHomeworkController extends BaseController {
     @Autowired
     private SysUserFeignService sysUserFeignService;
 
+    @ApiOperation(value = "布置课堂作业")
+    @GetMapping("/addCourseHomework")
+    public HttpResponseResult addCourseHomework(CourseHomework courseHomework){
+        courseHomeworkService.addCourseHomework(courseHomework);
+        return succeed();
+    }
+
     @ApiOperation(value = "根据班级获取教师布置的作业")
     @GetMapping("/findTeacherCourseHomeworkByClassGroup")
     public Object findTeacherCourseHomeworkByClassGroup(CourseHomeworkQueryInfo queryInfo){
@@ -47,7 +56,7 @@ public class CourseHomeworkController extends BaseController {
             return failed(HttpStatus.FORBIDDEN,"请登录");
         }
         queryInfo.setUserId(sysUser.getId().longValue());
-        return succeed(courseScheduleService.findTeacherCourseHomeworkByClassGroup(queryInfo));
+        return succeed(courseHomeworkService.findTeacherCourseHomeworkByClassGroup(queryInfo));
     }
 
     @ApiOperation(value = "根据课程计划获取需要交作业的学生")

+ 0 - 8
mec-web/src/main/java/com/ym/mec/web/controller/GoodsController.java

@@ -122,12 +122,4 @@ public class GoodsController extends BaseController {
     public Object findGoodsBySubId(Integer subjectId,String type){
         return succeed(goodsService.findGoodsBySubId(subjectId,type));
     }
-
-    @GetMapping("getGoodsTest")
-    @Transactional(rollbackFor = Exception.class)
-    public HttpResponseResult getGoodsTest(Integer goodsId){
-        goodsService.getGoodsTest(Arrays.asList(goodsId));
-//        goodsService.subtractStock(Arrays.asList(goodsId), AccountType.INTERNAL);
-        return succeed();
-    }
 }

+ 8 - 0
mec-web/src/main/java/com/ym/mec/web/controller/TaskController.java

@@ -78,6 +78,9 @@ public class TaskController extends BaseController {
 	@Autowired
 	private StudentGoodsSellService studentGoodsSellService;
 
+	@Autowired
+	private CourseScheduleStudentPaymentService courseScheduleStudentPaymentService;
+
 	@GetMapping(value = "/autoAffirmReceiveTask")
 	// 自动确认收货
 	public void affirmReceive(){
@@ -288,4 +291,9 @@ public class TaskController extends BaseController {
 	public void operatingReport(){
 		operatingReportService.statistics();
 	}
+
+	@GetMapping("/updateCourseActualPrice")
+	public void updateCourseActualPrice(){
+		courseScheduleStudentPaymentService.updateCourseActualPrice();
+	}
 }