| | |
| | | import com.ruoyi.goods.domain.dto.XiaoeLiveQueryDto; |
| | | import com.ruoyi.goods.domain.pojo.live.XiaoeLiveAppointment; |
| | | import com.ruoyi.goods.domain.pojo.live.XiaoeLiveRecord; |
| | | import com.ruoyi.goods.domain.vo.XiaoeLiveDetailVOV2; |
| | | import com.ruoyi.goods.domain.vo.XiaoeLiveVo; |
| | | import com.ruoyi.goods.domain.vo.XiaoeLiveVoV2; |
| | | import com.ruoyi.goods.service.live.IXiaoeLiveAppointmentService; |
| | | import com.ruoyi.goods.service.live.IXiaoeLiveRecordService; |
| | | import com.ruoyi.goods.utils.XiaoeUtils; |
| | |
| | | import java.util.Comparator; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Objects; |
| | | import java.util.Set; |
| | | import java.util.concurrent.TimeUnit; |
| | |
| | | //已预约的记录 |
| | | List<XiaoeLiveAppointment> appointments = xiaoeLiveAppointmentService.lambdaQuery() |
| | | .gt(XiaoeLiveAppointment::getAliveStartAt, DateUtils.getNowDate()).eq(XiaoeLiveAppointment::getUserId, userId).list(); |
| | | //处理获取到的直播数据 |
| | | Map<String, XiaoeLiveAppointment> appointmentMap = appointments.stream().collect(Collectors.toMap(XiaoeLiveAppointment::getLiveId, appointment -> appointment)); |
| | | // 处理直播数据 |
| | | List<XiaoeLiveVo> filteredRecords = livePageList.getRecords().stream() |
| | | .filter(item -> !item.getAliveState().equals(2)) |
| | | .flatMap(item -> appointments.stream().map(appointment -> { |
| | | //直播状态为未开始 且 预约记录存在 设置状态为已预约 |
| | | if (item.getAliveState().equals(0) && appointment.getLiveId().equals(item.getId())) { |
| | | item.setAppointmentState(1); |
| | | .filter(item -> !item.getAliveState().equals(2)) // 过滤直播状态为已结束的记录 |
| | | .peek(item -> { |
| | | // 查找对应的预约记录 |
| | | XiaoeLiveAppointment appointment = appointmentMap.get(item.getId()); |
| | | |
| | | // 如果预约记录存在且直播状态为未开始,则设置状态为已预约 |
| | | if (item.getAliveState().equals(0) && appointment != null) { |
| | | item.setAppointmentState(1); // 设置为已预约 |
| | | } |
| | | return item; |
| | | })).sorted(Comparator.comparing(XiaoeLiveVo::getAliveState).reversed()) |
| | | }) |
| | | .sorted(Comparator.comparing(XiaoeLiveVo::getAliveState).reversed()) // 按照直播状态排序 |
| | | .collect(Collectors.toList()); |
| | | //根据直播类型过滤平台和店铺直播 |
| | | if (Objects.nonNull(dto.getLiveType())) { |
| | | List<XiaoeLiveRecord> liveRecordList = xiaoeLiveRecordService.lambdaQuery().eq(XiaoeLiveRecord::getType, dto.getLiveType()).list(); |
| | | if (CollUtil.isNotEmpty(liveRecordList)) { |
| | | List<String> liveIdList = liveRecordList.stream().map(XiaoeLiveRecord::getLiveId).collect(Collectors.toList()); |
| | | filteredRecords = filteredRecords.stream().filter(item -> liveIdList.contains(item.getId())).collect(Collectors.toList()); |
| | | } |
| | | } |
| | | livePageList.setRecords(filteredRecords); |
| | | return livePageList; |
| | | } |
| | |
| | | * @param id |
| | | * @return |
| | | */ |
| | | public XiaoeLiveVo getLiveDetail(String id) { |
| | | return xiaoeUtils.getLiveDetail(id); |
| | | public XiaoeLiveDetailVOV2 getLiveDetail(String id) { |
| | | return xiaoeUtils.getLiveDetailV2(id); |
| | | } |
| | | /** |
| | | * 预约直播 |
| | |
| | | xiaoeLiveAppointmentService.save(xiaoeLiveAppointment); |
| | | /// 若为C端用户向 redis 添加预约记录 |
| | | if (sysUser.getUserType().equals("03")) { |
| | | // 如果活动在1小时内生成自动开始任务的延时任务 |
| | | Date checkTime = DateUtils.addMinutes(new Date(), 61); |
| | | // 获取当前时间 |
| | | Date nowTime = new Date(); |
| | | |
| | |
| | | long startTimeDifference = aliveStartAt.getTime() - nowTime.getTime(); |
| | | startTimeDifference = Math.max(startTimeDifference, 3000L); // 确保差值至少为3秒 |
| | | |
| | | // 根据条件判断是否创建延时任务 |
| | | if (checkTime.compareTo(aliveStartAt) > 0 || nowTime.compareTo(aliveStartAt) > 0) { |
| | | // 获取延时任务 |
| | | DelayTask startDelayTask = remoteConfigService.getDelayTask(DelayTaskEnum.LIVE_APPOINTMENT_TASK.getCode() + "-" + xiaoeLiveAppointment.getId()).getData(); |
| | | // 创建或者更新延时任务 |
| | |
| | | |
| | | // 添加新的延时任务 |
| | | remoteConfigService.addDelayTask(startDelayTask); |
| | | } |
| | | } |
| | | } |
| | | return true; |
| | |
| | | * @param dto |
| | | * @return |
| | | */ |
| | | public Page<XiaoeLiveVo> getMgtLivePage(XiaoeLiveQueryDto dto) { |
| | | Page<XiaoeLiveVo> livePageList = xiaoeUtils.getLivePageList(dto); |
| | | public Page<XiaoeLiveVoV2> getMgtLivePage(XiaoeLiveQueryDto dto) { |
| | | Page<XiaoeLiveVoV2> livePageList = xiaoeUtils.getLivePageListV2(dto); |
| | | Long shopId = dto.getShopId(); |
| | | if (Objects.nonNull(shopId)) { |
| | | List<XiaoeLiveRecord> xiaoeLiveRecords = xiaoeLiveRecordService.getListByShopId(shopId); |
| | | if (CollUtil.isNotEmpty(xiaoeLiveRecords)) { |
| | | List<String> liveIdList = xiaoeLiveRecords.stream().map(XiaoeLiveRecord::getLiveId).collect(Collectors.toList()); |
| | | List<XiaoeLiveVo> filteredList = livePageList.getRecords().stream().filter(item -> liveIdList.contains(item.getId())).collect(Collectors.toList()); |
| | | List<XiaoeLiveVoV2> filteredList = livePageList.getRecords().stream().filter(item -> liveIdList.contains(item.getId())).collect(Collectors.toList()); |
| | | livePageList.setRecords(filteredList); |
| | | } |
| | | } |