|  | @@ -1,7 +1,6 @@
 | 
	
		
			
				|  |  |  package com.yonge.cooleshow.biz.dal.service.impl;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  import com.alibaba.fastjson.JSON;
 | 
	
		
			
				|  |  | -import com.alipay.api.domain.AccountRecord;
 | 
	
		
			
				|  |  |  import com.baomidou.mybatisplus.core.metadata.IPage;
 | 
	
		
			
				|  |  |  import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 | 
	
		
			
				|  |  |  import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 | 
	
	
		
			
				|  | @@ -13,8 +12,8 @@ import com.yonge.cooleshow.biz.dal.dao.CourseGroupDao;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.biz.dal.dto.CheckCourseTimeDto;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.biz.dal.dto.LiveCourseGroupDto;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.biz.dal.dto.LiveCourseGroupDto.CoursePlanDto;
 | 
	
		
			
				|  |  | +import com.yonge.cooleshow.biz.dal.dto.LiveSaleOutDto;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.biz.dal.dto.UserAccountRecordDto;
 | 
	
		
			
				|  |  | -import com.yonge.cooleshow.biz.dal.dto.req.OrderRefundReq;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.biz.dal.dto.req.OrderReq;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.biz.dal.dto.search.*;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.biz.dal.entity.*;
 | 
	
	
		
			
				|  | @@ -23,7 +22,6 @@ import com.yonge.cooleshow.biz.dal.service.*;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.biz.dal.support.WrapperUtil;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.biz.dal.vo.*;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.biz.dal.vo.res.OrderCreateRes;
 | 
	
		
			
				|  |  | -import com.yonge.cooleshow.biz.dal.vo.res.RefundCreateRes;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.common.constant.SysConfigConstant;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.common.entity.HttpResponseResult;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.common.enums.PostStatusEnum;
 | 
	
	
		
			
				|  | @@ -41,13 +39,13 @@ import org.slf4j.Logger;
 | 
	
		
			
				|  |  |  import org.slf4j.LoggerFactory;
 | 
	
		
			
				|  |  |  import org.springframework.beans.BeanUtils;
 | 
	
		
			
				|  |  |  import org.springframework.beans.factory.annotation.Autowired;
 | 
	
		
			
				|  |  | -import org.springframework.context.annotation.Bean;
 | 
	
		
			
				|  |  |  import org.springframework.stereotype.Service;
 | 
	
		
			
				|  |  |  import org.springframework.transaction.annotation.Transactional;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  import java.math.BigDecimal;
 | 
	
		
			
				|  |  |  import java.math.RoundingMode;
 | 
	
		
			
				|  |  |  import java.time.LocalDate;
 | 
	
		
			
				|  |  | +import java.time.ZoneId;
 | 
	
		
			
				|  |  |  import java.util.*;
 | 
	
		
			
				|  |  |  import java.util.concurrent.TimeUnit;
 | 
	
		
			
				|  |  |  import java.util.concurrent.atomic.AtomicBoolean;
 | 
	
	
		
			
				|  | @@ -1071,13 +1069,13 @@ public class CourseGroupServiceImpl extends ServiceImpl<CourseGroupDao, CourseGr
 | 
	
		
			
				|  |  |          List<CourseGroup> courseGroupList = this.list(Wrappers.<CourseGroup>lambdaQuery()
 | 
	
		
			
				|  |  |                  .eq(CourseGroup::getType, CourseScheduleEnum.LIVE.getCode())
 | 
	
		
			
				|  |  |                  .eq(CourseGroup::getSalesEndDate, LocalDate.now().plusDays(-1))
 | 
	
		
			
				|  |  | -                .eq(CourseGroup::getStatus, CourseGroupEnum.APPLY.getCode()));
 | 
	
		
			
				|  |  | +                .in(CourseGroup::getStatus, CourseGroupEnum.APPLY.getCode(),CourseGroupEnum.OUT_SALE.getCode()));
 | 
	
		
			
				|  |  |          if (CollectionUtils.isEmpty(courseGroupList)) {
 | 
	
		
			
				|  |  |              return;
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          courseGroupList.forEach(courseGroup -> {
 | 
	
		
			
				|  |  |              try {
 | 
	
		
			
				|  |  | -                if (courseGroup.getPreStudentNum() >= courseGroup.getMixStudentNum()) {
 | 
	
		
			
				|  |  | +                if (courseGroup.getPreStudentNum() >= courseGroup.getMixStudentNum() &&courseGroup.getStatus().equals(CourseGroupEnum.APPLY.getCode())) {
 | 
	
		
			
				|  |  |                      //人数达标则修改课程组为进行中状态
 | 
	
		
			
				|  |  |                      courseGroup.setStatus(CourseGroupEnum.ING.getCode());
 | 
	
		
			
				|  |  |                      //创建群聊 并添加人员到群中
 | 
	
	
		
			
				|  | @@ -1135,6 +1133,10 @@ public class CourseGroupServiceImpl extends ServiceImpl<CourseGroupDao, CourseGr
 | 
	
		
			
				|  |  |       * @param courseGroup 课程组
 | 
	
		
			
				|  |  |       */
 | 
	
		
			
				|  |  |      private void sendMessage(CourseGroup courseGroup) {
 | 
	
		
			
				|  |  | +        // 直播课下架后,不推送直播课成课失败消息
 | 
	
		
			
				|  |  | +        if (courseGroup.getStatus().equals(CourseGroupEnum.OUT_SALE.getCode())) {
 | 
	
		
			
				|  |  | +            return;
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  |          // 发短信
 | 
	
		
			
				|  |  |          try {
 | 
	
		
			
				|  |  |              SysUser user = sysUserFeignService.queryUserById(courseGroup.getTeacherId());
 | 
	
	
		
			
				|  | @@ -1266,5 +1268,54 @@ public class CourseGroupServiceImpl extends ServiceImpl<CourseGroupDao, CourseGr
 | 
	
		
			
				|  |  |          result.setAvatar(sysUser.getAvatar());
 | 
	
		
			
				|  |  |          return result;
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    @Override
 | 
	
		
			
				|  |  | +    @Transactional
 | 
	
		
			
				|  |  | +    public Boolean liveSaleOut(LiveSaleOutDto dto) {
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        CourseGroup liveCourseGroupVo = this.getById(dto.getCourseGroupId());
 | 
	
		
			
				|  |  | +        if (liveCourseGroupVo == null || !CourseScheduleEnum.LIVE.getCode().equals(liveCourseGroupVo.getType())) {
 | 
	
		
			
				|  |  | +            throw new BizException("没找到课程组信息");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        // 条件检查
 | 
	
		
			
				|  |  | +        if(dto.getStatus() == 0 && StringUtils.isEmpty(dto.getReason())) {
 | 
	
		
			
				|  |  | +            throw  new BizException("请填写下架原因");
 | 
	
		
			
				|  |  | +        } else if (dto.getStatus() == 0  && !CourseGroupEnum.APPLY.getCode().equals(liveCourseGroupVo.getStatus())) {
 | 
	
		
			
				|  |  | +            throw new BizException("只能下架销售中的课程组");
 | 
	
		
			
				|  |  | +        } else if (dto.getStatus() == 1  && !CourseGroupEnum.OUT_SALE.getCode().equals(liveCourseGroupVo.getStatus())) {
 | 
	
		
			
				|  |  | +            throw new BizException("只能上架被下架的课程组");
 | 
	
		
			
				|  |  | +        } else if ( LocalDate.now().compareTo(liveCourseGroupVo.getSalesEndDate().toInstant().atZone(ZoneId.systemDefault()).toLocalDate()) > 0) {
 | 
	
		
			
				|  |  | +            throw new BizException("课程组售卖时间已结束,不能操作");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        if (dto.getStatus() == 0) {
 | 
	
		
			
				|  |  | +            liveCourseGroupVo.setStatus(CourseGroupEnum.OUT_SALE.getCode());
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            // 发送下架消息
 | 
	
		
			
				|  |  | +            sendOutSaleMessage(dto, liveCourseGroupVo);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        } else {
 | 
	
		
			
				|  |  | +            liveCourseGroupVo.setStatus(CourseGroupEnum.APPLY.getCode());
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        return this.updateById(liveCourseGroupVo);
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    private void sendOutSaleMessage(LiveSaleOutDto dto, CourseGroup liveCourseGroupVo) {
 | 
	
		
			
				|  |  | +        // 发送课程下架通知
 | 
	
		
			
				|  |  | +        try {
 | 
	
		
			
				|  |  | +            SysUser user = sysUserFeignService.queryUserById(liveCourseGroupVo.getTeacherId());
 | 
	
		
			
				|  |  | +            Map<Long, String> receivers = new HashMap<>();
 | 
	
		
			
				|  |  | +            receivers.put(user.getId(), user.getPhone());
 | 
	
		
			
				|  |  | +            sysMessageService.batchSendMessage(MessageSenderPluginContext.MessageSender.JIGUANG, MessageTypeEnum.LIVE_COURSE_OUT_SALE_REASON,
 | 
	
		
			
				|  |  | +                                               receivers, null, 0, null, ClientEnum.TEACHER.getCode(),
 | 
	
		
			
				|  |  | +                                               liveCourseGroupVo.getName(), dto.getReason());
 | 
	
		
			
				|  |  | +        } catch (Exception e) {
 | 
	
		
			
				|  |  | +            log.warn("直播课下架推送发送失败,{}", e.getMessage());
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 |