|  | @@ -28,6 +28,7 @@ import com.yonge.cooleshow.common.constant.SysConfigConstant;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.common.entity.HttpResponseResult;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.common.exception.BizException;
 | 
	
		
			
				|  |  |  import com.yonge.toolset.base.page.PageInfo;
 | 
	
		
			
				|  |  | +import com.yonge.toolset.thirdparty.message.MessageSenderPluginContext;
 | 
	
		
			
				|  |  |  import com.yonge.toolset.utils.date.DateUtil;
 | 
	
		
			
				|  |  |  import org.apache.commons.collections.CollectionUtils;
 | 
	
		
			
				|  |  |  import org.apache.commons.lang3.StringUtils;
 | 
	
	
		
			
				|  | @@ -83,7 +84,10 @@ public class CourseGroupServiceImpl extends ServiceImpl<CourseGroupDao, CourseGr
 | 
	
		
			
				|  |  |      @Autowired
 | 
	
		
			
				|  |  |      private ImGroupService imGroupService;
 | 
	
		
			
				|  |  |      @Autowired
 | 
	
		
			
				|  |  | -    private UserOrderService orderService;
 | 
	
		
			
				|  |  | +    private UserOrderService userOrderService;
 | 
	
		
			
				|  |  | +    @Autowired
 | 
	
		
			
				|  |  | +    private SysMessageService sysMessageService;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |      @Override
 | 
	
		
			
				|  |  |      public CourseGroupDao getDao() {
 | 
	
		
			
				|  |  |          return this.baseMapper;
 | 
	
	
		
			
				|  | @@ -116,13 +120,19 @@ public class CourseGroupServiceImpl extends ServiceImpl<CourseGroupDao, CourseGr
 | 
	
		
			
				|  |  |          result.setMixStudentNum(group.getMixStudentNum());
 | 
	
		
			
				|  |  |          result.setImGroupId(group.getImGroupId());
 | 
	
		
			
				|  |  |          Optional.ofNullable(group.getTeacherId()).map(this::getSysUser)
 | 
	
		
			
				|  |  | -                .ifPresent(sysUser -> result.setTeacherName(sysUser.getRealName()));
 | 
	
		
			
				|  |  | +                .ifPresent(sysUser -> {
 | 
	
		
			
				|  |  | +                    result.setTeacherName(sysUser.getRealName());
 | 
	
		
			
				|  |  | +                    result.setUserName(sysUser.getUsername());
 | 
	
		
			
				|  |  | +                });
 | 
	
		
			
				|  |  |          Optional.ofNullable(group.getSubjectId()).map(subjectService::get)
 | 
	
		
			
				|  |  |                  .ifPresent(subject -> result.setSubjectName(subject.getName()));
 | 
	
		
			
				|  |  |          //课程组计划
 | 
	
		
			
				|  |  |          result.setPlanList(coursePlanService.queryCoursePlanByGroupId(groupId));
 | 
	
		
			
				|  |  | -        //课程组学员信息
 | 
	
		
			
				|  |  | -        result.setStudentList(courseScheduleStudentPaymentService.queryStudentInfoByGroupId(groupId));
 | 
	
		
			
				|  |  | +        //课程组已经购买成功的学员信息
 | 
	
		
			
				|  |  | +        Map<String, Object> param = new HashMap<>();
 | 
	
		
			
				|  |  | +        param.put("groupId", groupId);
 | 
	
		
			
				|  |  | +        param.put("orderState", OrderStatusEnum.PAID.getCode());
 | 
	
		
			
				|  |  | +        result.setStudentList(courseScheduleStudentPaymentService.queryStudentInfoByGroupId(param));
 | 
	
		
			
				|  |  |          //查询是否购买过该课程组
 | 
	
		
			
				|  |  |          Long id = getSysUser().getId();
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -133,13 +143,7 @@ public class CourseGroupServiceImpl extends ServiceImpl<CourseGroupDao, CourseGr
 | 
	
		
			
				|  |  |          query.setGoodType(GoodTypeEnum.LIVE.getCode());
 | 
	
		
			
				|  |  |          query.setBizId(groupId);
 | 
	
		
			
				|  |  |          query.setStatus(OrderStatusEnum.PAID.getCode());
 | 
	
		
			
				|  |  | -        List<UserOrderVo> userOrderVos = orderService.selectList(query);
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -        /*List<CourseScheduleStudentPayment> paymentList = courseScheduleStudentPaymentService.list(Wrappers.<CourseScheduleStudentPayment>lambdaQuery()
 | 
	
		
			
				|  |  | -                .eq(CourseScheduleStudentPayment::getUserId, id)
 | 
	
		
			
				|  |  | -                .eq(CourseScheduleStudentPayment::getCourseGroupId, groupId)
 | 
	
		
			
				|  |  | -        );*/
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | +        List<UserOrderVo> userOrderVos = userOrderService.selectList(query);
 | 
	
		
			
				|  |  |          result.setExistBuy(0);
 | 
	
		
			
				|  |  |          if (CollectionUtils.isNotEmpty(userOrderVos)) {
 | 
	
		
			
				|  |  |              result.setExistBuy(1);
 | 
	
	
		
			
				|  | @@ -158,32 +162,11 @@ public class CourseGroupServiceImpl extends ServiceImpl<CourseGroupDao, CourseGr
 | 
	
		
			
				|  |  |       *              <p> - search 模糊搜索关键字
 | 
	
		
			
				|  |  |       */
 | 
	
		
			
				|  |  |      public PageInfo<CourseGroupVo> queryPageLiveCourseGroup(Map<String, Object> param) {
 | 
	
		
			
				|  |  | -        //查询该月的所有课程
 | 
	
		
			
				|  |  | +        //查询该月的所有直播课程
 | 
	
		
			
				|  |  |          param.put("type", CourseScheduleEnum.LIVE.getCode());
 | 
	
		
			
				|  |  |          Page<CourseGroupVo> pageInfo = PageUtil.getPageInfo(param);
 | 
	
		
			
				|  |  |          pageInfo.setAsc("b.created_time_");
 | 
	
		
			
				|  |  |          IPage<CourseGroupVo> page = baseMapper.queryTeacherCourseGroup(pageInfo, param);
 | 
	
		
			
				|  |  | -        //学生端查询报名中的课程组需要标明该学生是否已经购买过该课程组
 | 
	
		
			
				|  |  | -        String os = WrapperUtil.toStr(param, "os");
 | 
	
		
			
				|  |  | -        if ("student".equals(os) && CollectionUtils.isNotEmpty(page.getRecords())) {
 | 
	
		
			
				|  |  | -            //获取当前课程组Id
 | 
	
		
			
				|  |  | -            List<CourseGroupVo> records = page.getRecords();
 | 
	
		
			
				|  |  | -            List<Long> groupId = records.stream().map(CourseGroupVo::getCourseGroupId).collect(Collectors.toList());
 | 
	
		
			
				|  |  | -            //根据学生id 及 课程组id集合查询购买记录
 | 
	
		
			
				|  |  | -            List<CourseScheduleStudentPayment> paymentList = courseScheduleStudentPaymentService.list(Wrappers.<CourseScheduleStudentPayment>lambdaQuery()
 | 
	
		
			
				|  |  | -                    .eq(CourseScheduleStudentPayment::getUserId, getSysUser().getId())
 | 
	
		
			
				|  |  | -                    .in(CourseScheduleStudentPayment::getCourseGroupId, groupId)
 | 
	
		
			
				|  |  | -            );
 | 
	
		
			
				|  |  | -            if (CollectionUtils.isNotEmpty(paymentList)) {
 | 
	
		
			
				|  |  | -                Map<Long, List<CourseScheduleStudentPayment>> payMap = WrapperUtil.groupList(paymentList, CourseScheduleStudentPayment::getCourseGroupId);
 | 
	
		
			
				|  |  | -                records.forEach(o -> {
 | 
	
		
			
				|  |  | -                    o.setExistBuy(0);
 | 
	
		
			
				|  |  | -                    if (payMap.containsKey(o.getCourseGroupId())) {
 | 
	
		
			
				|  |  | -                        o.setExistBuy(1);
 | 
	
		
			
				|  |  | -                    }
 | 
	
		
			
				|  |  | -                });
 | 
	
		
			
				|  |  | -            }
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  |          return PageUtil.pageInfo(page);
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -274,9 +257,11 @@ public class CourseGroupServiceImpl extends ServiceImpl<CourseGroupDao, CourseGr
 | 
	
		
			
				|  |  |          if (courseStateFunc.test(CourseGroupEnum.ING)) {
 | 
	
		
			
				|  |  |              throw new BizException("课程组进行中,无法下架/取消课程组!");
 | 
	
		
			
				|  |  |          } else if (courseStateFunc.test(CourseGroupEnum.APPLY)) {
 | 
	
		
			
				|  |  | -            //已上架没人买的课程可以下架
 | 
	
		
			
				|  |  | -            if (group.getPreStudentNum() > 0) {
 | 
	
		
			
				|  |  | -                throw new BizException("课程组已有学生购买,无法下架/取消课程组!");
 | 
	
		
			
				|  |  | +            //查询订单有人已经在支付中则无法下架
 | 
	
		
			
				|  |  | +            List<CourseScheduleStudentPayment> list = courseScheduleStudentPaymentService.list(Wrappers.<CourseScheduleStudentPayment>lambdaQuery()
 | 
	
		
			
				|  |  | +                    .eq(CourseScheduleStudentPayment::getCourseGroupId, groupId));
 | 
	
		
			
				|  |  | +            if (CollectionUtils.isNotEmpty(list)) {
 | 
	
		
			
				|  |  | +                throw new BizException("课程组已有学生付款或有待付款的订单,无法下架/取消课程组!");
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |          } else if (courseStateFunc.test(CourseGroupEnum.COMPLETE)) {
 | 
	
		
			
				|  |  |              throw new BizException("课程组已完结!");
 | 
	
	
		
			
				|  | @@ -677,17 +662,25 @@ public class CourseGroupServiceImpl extends ServiceImpl<CourseGroupDao, CourseGr
 | 
	
		
			
				|  |  |          log.info("buyLiveCourseSuccess param :{}", JSON.toJSONString(orderParam));
 | 
	
		
			
				|  |  |          String orderNo = orderParam.getOrderNo();
 | 
	
		
			
				|  |  |          //更新课程组的购买人数+1
 | 
	
		
			
				|  |  | -        CourseScheduleStudentPayment studentPayment = courseScheduleStudentPaymentService.getOne(Wrappers.<CourseScheduleStudentPayment>lambdaQuery()
 | 
	
		
			
				|  |  | +        List<CourseScheduleStudentPayment> studentPaymentList = courseScheduleStudentPaymentService.list(Wrappers.<CourseScheduleStudentPayment>lambdaQuery()
 | 
	
		
			
				|  |  |                  .eq(CourseScheduleStudentPayment::getOrderNo, orderNo)
 | 
	
		
			
				|  |  |          );
 | 
	
		
			
				|  |  | -        if (Objects.isNull(studentPayment)) {
 | 
	
		
			
				|  |  | -            throw new BizException("订单不存在!");
 | 
	
		
			
				|  |  | +        CourseScheduleStudentPayment studentPayment;
 | 
	
		
			
				|  |  | +        if (CollectionUtils.isEmpty(studentPaymentList)) {
 | 
	
		
			
				|  |  | +            log.info("buyLiveCourseSuccess >>> 订单不存在!orderParam: {}", JSON.toJSONString(orderParam));
 | 
	
		
			
				|  |  | +            throw new BizException("订单不存在");
 | 
	
		
			
				|  |  | +        } else {
 | 
	
		
			
				|  |  | +            studentPayment = studentPaymentList.get(0);
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | -        //更新课程组的购买人数+1
 | 
	
		
			
				|  |  | -        this.baseMapper.opsPreStudentNum(studentPayment.getCourseGroupId(), 1);
 | 
	
		
			
				|  |  |          //课程组信息
 | 
	
		
			
				|  |  |          CourseGroup courseGroup = this.getOne(Wrappers.<CourseGroup>lambdaQuery()
 | 
	
		
			
				|  |  |                  .eq(CourseGroup::getId, studentPayment.getCourseGroupId()));
 | 
	
		
			
				|  |  | +        if (Objects.isNull(courseGroup)) {
 | 
	
		
			
				|  |  | +            log.info("buyLiveCourseSuccess >>> 课程组不存在!orderParam: {}", JSON.toJSONString(orderParam));
 | 
	
		
			
				|  |  | +            throw new BizException("课程组不存在");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        //更新课程组的购买人数+1
 | 
	
		
			
				|  |  | +        this.baseMapper.opsPreStudentNum(studentPayment.getCourseGroupId(), 1);
 | 
	
		
			
				|  |  |          //课程信息
 | 
	
		
			
				|  |  |          List<CourseSchedule> courseList = courseScheduleService.list(Wrappers.<CourseSchedule>lambdaQuery()
 | 
	
		
			
				|  |  |                  .eq(CourseSchedule::getCourseGroupId, studentPayment.getCourseGroupId()));
 | 
	
	
		
			
				|  | @@ -719,6 +712,85 @@ public class CourseGroupServiceImpl extends ServiceImpl<CourseGroupDao, CourseGr
 | 
	
		
			
				|  |  |          });
 | 
	
		
			
				|  |  |          courseScheduleTeacherSalaryService.getDao().insertBatch(teacherSalaryList);
 | 
	
		
			
				|  |  |          log.info("buyLiveCourseSuccess ok");
 | 
	
		
			
				|  |  | +        //课程购买成功后进行消息推送
 | 
	
		
			
				|  |  | +        buyLiveSendMessage(studentPayment, courseGroup);
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    /**
 | 
	
		
			
				|  |  | +     * 课程购买成功后进行消息推送
 | 
	
		
			
				|  |  | +     *
 | 
	
		
			
				|  |  | +     * @param studentPayment 学生购买信息
 | 
	
		
			
				|  |  | +     * @param courseGroup    课程组信息
 | 
	
		
			
				|  |  | +     */
 | 
	
		
			
				|  |  | +    private void buyLiveSendMessage(CourseScheduleStudentPayment studentPayment, CourseGroup courseGroup) {
 | 
	
		
			
				|  |  | +        //查询老师信息
 | 
	
		
			
				|  |  | +        SysUser teacherInfo = getSysUser(courseGroup.getTeacherId());
 | 
	
		
			
				|  |  | +        //查询学生信息
 | 
	
		
			
				|  |  | +        SysUser studentInfo = getSysUser(studentPayment.getUserId());
 | 
	
		
			
				|  |  | +        try {
 | 
	
		
			
				|  |  | +            //极光-消息推送-学生端-通知学生购买成功-跳转到APP
 | 
	
		
			
				|  |  | +            MessageTypeEnum liveBuy = MessageTypeEnum.LIVE_BUY;
 | 
	
		
			
				|  |  | +            //查询推送跳转的url
 | 
	
		
			
				|  |  | +            String liveBuyUrl = sysMessageService.selectConfigUrl(liveBuy.getCode());
 | 
	
		
			
				|  |  | +            Map<Long, String> studentReceivers = new HashMap<>();
 | 
	
		
			
				|  |  | +            studentReceivers.put(studentInfo.getId(), studentInfo.getPhone());
 | 
	
		
			
				|  |  | +            sysMessageService.batchSendMessage(MessageSenderPluginContext.MessageSender.JIGUANG, liveBuy,
 | 
	
		
			
				|  |  | +                    studentReceivers, null, 0, null, ClientEnum.STUDENT.getCode(),
 | 
	
		
			
				|  |  | +                    teacherInfo.getUsername(), courseGroup.getName(), liveBuyUrl);
 | 
	
		
			
				|  |  | +            log.info("buyLiveCourseSuccess buyLiveSendMessage LIVE_BUY ok");
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            //短信-消息推送-学生端-通知学生购买成功-跳转到APP
 | 
	
		
			
				|  |  | +            MessageTypeEnum smsLiveBuy = MessageTypeEnum.SMS_LIVE_BUY;
 | 
	
		
			
				|  |  | +            //查询推送跳转的url
 | 
	
		
			
				|  |  | +            String smsLiveBuyUrl = sysMessageService.selectConfigUrl(smsLiveBuy.getCode());
 | 
	
		
			
				|  |  | +            Map<Long, String> smsStudentReceivers = new HashMap<>();
 | 
	
		
			
				|  |  | +            smsStudentReceivers.put(studentInfo.getId(), studentInfo.getPhone());
 | 
	
		
			
				|  |  | +            sysMessageService.batchSendMessage(MessageSenderPluginContext.MessageSender.AWSMS, smsLiveBuy,
 | 
	
		
			
				|  |  | +                    smsStudentReceivers, null, 0, null, null,
 | 
	
		
			
				|  |  | +                    teacherInfo.getUsername(), courseGroup.getName(), smsLiveBuyUrl);
 | 
	
		
			
				|  |  | +            log.info("buyLiveCourseSuccess buyLiveSendMessage SMS_BUY_LIVE ok");
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            //极光-消息推送-老师端-通知老师有学生购买课程-跳转到APP
 | 
	
		
			
				|  |  | +            MessageTypeEnum studentBuyLive = MessageTypeEnum.STUDENT_BUY_LIVE;
 | 
	
		
			
				|  |  | +            //查询推送跳转的url
 | 
	
		
			
				|  |  | +            String studentBuyLiveUrl = sysMessageService.selectConfigUrl(studentBuyLive.getCode());
 | 
	
		
			
				|  |  | +            Map<Long, String> teacherReceivers = new HashMap<>();
 | 
	
		
			
				|  |  | +            teacherReceivers.put(teacherInfo.getId(), teacherInfo.getPhone());
 | 
	
		
			
				|  |  | +            sysMessageService.batchSendMessage(MessageSenderPluginContext.MessageSender.JIGUANG, studentBuyLive,
 | 
	
		
			
				|  |  | +                    teacherReceivers, null, 0, null, ClientEnum.TEACHER.getCode(),
 | 
	
		
			
				|  |  | +                    studentInfo.getUsername(), courseGroup.getName(), studentBuyLiveUrl);
 | 
	
		
			
				|  |  | +            log.info("buyLiveCourseSuccess buyLiveSendMessage STUDENT_BUY_LIVE ok");
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            //短信-消息推送-老师端-通知老师有学生购买课程-无需跳转到APP
 | 
	
		
			
				|  |  | +            Map<Long, String> smsTeacherReceivers = new HashMap<>();
 | 
	
		
			
				|  |  | +            smsTeacherReceivers.put(teacherInfo.getId(), teacherInfo.getPhone());
 | 
	
		
			
				|  |  | +            sysMessageService.batchSendMessage(MessageSenderPluginContext.MessageSender.AWSMS, MessageTypeEnum.SMS_BUY_LIVE,
 | 
	
		
			
				|  |  | +                    smsTeacherReceivers, null, 0, null, null,
 | 
	
		
			
				|  |  | +                    studentInfo.getUsername(), courseGroup.getName());
 | 
	
		
			
				|  |  | +            log.info("buyLiveCourseSuccess buyLiveSendMessage SMS_BUY_LIVE ok");
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            //判断是否到达最低成课人数
 | 
	
		
			
				|  |  | +            if (Objects.equals(courseGroup.getPreStudentNum(), courseGroup.getMixStudentNum())) {
 | 
	
		
			
				|  |  | +                //极光-消息推送-老师端-通知老师课程最小开课人数已达标
 | 
	
		
			
				|  |  | +                MessageTypeEnum liveCompletionSuccess = MessageTypeEnum.LIVE_COMPLETION_SUCCESS;
 | 
	
		
			
				|  |  | +                Map<Long, String> liveCompletionSuccessReceivers = new HashMap<>();
 | 
	
		
			
				|  |  | +                liveCompletionSuccessReceivers.put(teacherInfo.getId(), teacherInfo.getPhone());
 | 
	
		
			
				|  |  | +                sysMessageService.batchSendMessage(MessageSenderPluginContext.MessageSender.JIGUANG, liveCompletionSuccess,
 | 
	
		
			
				|  |  | +                        liveCompletionSuccessReceivers, null, 0, null, ClientEnum.TEACHER.getCode(),
 | 
	
		
			
				|  |  | +                        courseGroup.getName());
 | 
	
		
			
				|  |  | +                log.info("buyLiveCourseSuccess buyLiveSendMessage LIVE_COMPLETION_SUCCESS ok");
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                //短信-消息推送-老师端-通知老师课程最小开课人数已达标
 | 
	
		
			
				|  |  | +                Map<Long, String> smsLiveCompletionSuccessReceivers = new HashMap<>();
 | 
	
		
			
				|  |  | +                smsLiveCompletionSuccessReceivers.put(teacherInfo.getId(), teacherInfo.getPhone());
 | 
	
		
			
				|  |  | +                sysMessageService.batchSendMessage(MessageSenderPluginContext.MessageSender.AWSMS, MessageTypeEnum.SMS_LIVE_COMPLETION_SUCCESS,
 | 
	
		
			
				|  |  | +                        smsLiveCompletionSuccessReceivers, null, 0, null, null,
 | 
	
		
			
				|  |  | +                        courseGroup.getName());
 | 
	
		
			
				|  |  | +                log.info("buyLiveCourseSuccess buyLiveSendMessage SMS_LIVE_COMPLETION_SUCCESS ok");
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        } catch (Exception ex) {
 | 
	
		
			
				|  |  | +            log.error("buyLiveCourseSuccess buyLiveSendMessage error", ex.getCause());
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @Override
 | 
	
	
		
			
				|  | @@ -751,10 +823,13 @@ public class CourseGroupServiceImpl extends ServiceImpl<CourseGroupDao, CourseGr
 | 
	
		
			
				|  |  |       * 定时将符合开售日期的未开售的直播课课程组修改为报名中状态
 | 
	
		
			
				|  |  |       */
 | 
	
		
			
				|  |  |      private void openCourseGroup() {
 | 
	
		
			
				|  |  | +        LocalDate today = LocalDate.now();
 | 
	
		
			
				|  |  | +        LocalDate yesterday = today.plusDays(-1L);
 | 
	
		
			
				|  |  |          //查询今天未开售的课程组
 | 
	
		
			
				|  |  |          List<CourseGroup> courseGroupList = this.list(Wrappers.<CourseGroup>lambdaQuery()
 | 
	
		
			
				|  |  |                  .eq(CourseGroup::getType, CourseScheduleEnum.LIVE.getCode())
 | 
	
		
			
				|  |  | -                .eq(CourseGroup::getSalesStartDate, LocalDate.now())
 | 
	
		
			
				|  |  | +                .ge(CourseGroup::getSalesStartDate, yesterday)
 | 
	
		
			
				|  |  | +                .le(CourseGroup::getSalesStartDate, today)
 | 
	
		
			
				|  |  |                  .eq(CourseGroup::getStatus, CourseGroupEnum.NOT_SALE.getCode()));
 | 
	
		
			
				|  |  |          if (CollectionUtils.isEmpty(courseGroupList)) {
 | 
	
		
			
				|  |  |              return;
 |