|
@@ -1,4 +1,6 @@
|
|
|
package com.yonge.cooleshow.biz.dal.service.impl;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.Date;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
@@ -17,6 +19,7 @@ import com.yonge.cooleshow.biz.dal.enums.CourseGroupEnum;
|
|
|
import com.yonge.cooleshow.biz.dal.enums.CourseScheduleEnum;
|
|
|
import com.yonge.cooleshow.biz.dal.service.*;
|
|
|
import com.yonge.cooleshow.biz.dal.support.PageUtil;
|
|
|
+import com.yonge.cooleshow.biz.dal.support.WrapperUtil;
|
|
|
import com.yonge.cooleshow.biz.dal.vo.CourseGroupVo;
|
|
|
import com.yonge.cooleshow.biz.dal.vo.LiveCourseInfoVo;
|
|
|
import com.yonge.cooleshow.common.constant.SysConfigConstant;
|
|
@@ -32,6 +35,7 @@ import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
+import rx.subjects.Subject;
|
|
|
|
|
|
import java.time.LocalDate;
|
|
|
import java.util.*;
|
|
@@ -258,6 +262,22 @@ public class CourseGroupServiceImpl extends ServiceImpl<CourseGroupDao, CourseGr
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 批量检查学生课时在数据库是否重复
|
|
|
+ *
|
|
|
+ * @param studentId 老师id
|
|
|
+ * @param timeList 时间集合
|
|
|
+ */
|
|
|
+ private <T> void batchCheckStudentCourseTime(Long studentId, List<T> timeList, Function<T, Date> startTimeFun, Function<T, Date> endTimeFun) {
|
|
|
+ //再校验数据库中课程时间和传入时间是否有交集
|
|
|
+ timeList.forEach(o -> {
|
|
|
+ boolean checkDataTime = courseScheduleService.checkStudentCourseTime(studentId, startTimeFun.apply(o), endTimeFun.apply(o));
|
|
|
+ if (checkDataTime) {
|
|
|
+ throw new BizException("预计安排在" + DateUtil.dateToString(startTimeFun.apply(o), "yyyy年MM月dd号 HH点mm分") + "的课程时间存在冲突!");
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 自动排课
|
|
|
* <p>自动排课规则及场景:总5节课,填入2节,需要自动补3节
|
|
|
* <p>1.把前面2节课的时间循环+1周直到填满5节课为止
|
|
@@ -420,6 +440,75 @@ public class CourseGroupServiceImpl extends ServiceImpl<CourseGroupDao, CourseGr
|
|
|
return redissonClient.getMap(key);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 学生购买直播课程组
|
|
|
+ *
|
|
|
+ * @param param 传入参数
|
|
|
+ * <p> - groupId 直播课程组id
|
|
|
+ * <p> - studentId 学员id
|
|
|
+ */
|
|
|
+ public void buyLiveCourse(Map<String, Object> param) {
|
|
|
+ Long studentId = WrapperUtil.toLong(param, "studentId", "学员id不能为空!");
|
|
|
+ Long groupId = WrapperUtil.toLong(param, "groupId", "课程组id不能为空!");
|
|
|
+ //学生信息
|
|
|
+ getSysUser(studentId);
|
|
|
+ //课程组信息
|
|
|
+ CourseGroup liveCourseGroup = this.getOne(Wrappers.<CourseGroup>lambdaQuery()
|
|
|
+ .eq(CourseGroup::getId, groupId)
|
|
|
+ .eq(CourseGroup::getType, CourseScheduleEnum.LIVE.getCode())
|
|
|
+ );
|
|
|
+ if (Objects.isNull(liveCourseGroup)) {
|
|
|
+ throw new BizException("课程组不存在!");
|
|
|
+ }
|
|
|
+ //课程信息
|
|
|
+ List<CourseSchedule> courseList = courseScheduleService.list(Wrappers.<CourseSchedule>lambdaQuery()
|
|
|
+ .eq(CourseSchedule::getCourseGroupId, groupId)
|
|
|
+ );
|
|
|
+ if (CollectionUtils.isEmpty(courseList)) {
|
|
|
+ throw new BizException("课程组课程不存在!");
|
|
|
+ }
|
|
|
+ //校验购买的课程组每节课时间是否和自己的课时冲突
|
|
|
+ batchCheckStudentCourseTime(studentId, courseList, CourseSchedule::getStartTime, CourseSchedule::getEndTime);
|
|
|
+ //todo 写订单 返回订单号数据(订单号 金额 等等)
|
|
|
+ String orderNo = "";
|
|
|
+ Date now = new Date();
|
|
|
+ //写course_schedule_student_payment表 作为记录锁定时间用,防止重复购买,如果支付失败则删除该数据
|
|
|
+ List<CourseScheduleStudentPayment> studentPaymentList = new ArrayList<>();
|
|
|
+ courseList.forEach(course -> {
|
|
|
+ CourseScheduleStudentPayment studentPayment = new CourseScheduleStudentPayment();
|
|
|
+ studentPayment.setUserId(studentId);
|
|
|
+ studentPayment.setCourseGroupId(groupId);
|
|
|
+ studentPayment.setCourseId(course.getId());
|
|
|
+ studentPayment.setOrderNo(orderNo);
|
|
|
+ studentPayment.setOriginalPrice(liveCourseGroup.getCoursePrice());
|
|
|
+ studentPayment.setExpectPrice(liveCourseGroup.getCoursePrice());
|
|
|
+ studentPayment.setActualPrice(liveCourseGroup.getCoursePrice());
|
|
|
+ studentPayment.setCreatedTime(now);
|
|
|
+ studentPayment.setUpdatedTime(now);
|
|
|
+ studentPayment.setCourseType(liveCourseGroup.getType());
|
|
|
+ studentPaymentList.add(studentPayment);
|
|
|
+ });
|
|
|
+ courseScheduleStudentPaymentService.getDao().insertBatch(studentPaymentList);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 学生购买直播课程成功-回调成功
|
|
|
+ */
|
|
|
+ public void buyLiveCourseSuccess() {
|
|
|
+ //写course_group表 pre_student_num_(预计上课人数) +1
|
|
|
+ //写入课酬表计算-根据课程组总金额计算分配到每节课的金额
|
|
|
+ //修改订单为成功
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 学生购买直播课失败-回调
|
|
|
+ */
|
|
|
+ public void buyLiveCourseFailed() {
|
|
|
+ //修改 course_group表 pre_student_num_(预计上课人数) - 1
|
|
|
+ //删除 course_schedule_student_payment表 数据
|
|
|
+ //修改订单为失败
|
|
|
+ }
|
|
|
+
|
|
|
private SysUser getSysUser(Long userId) {
|
|
|
return Optional.ofNullable(userId)
|
|
|
.map(sysUserFeignService::queryUserById)
|