Pu Zhibing
2025-06-18 52df64e39ef939628b5defa61f4ab65df99db423
ruoyi-modules/ruoyi-goods/src/main/java/com/ruoyi/goods/service/biz/XiaoeLiveService.java
@@ -16,6 +16,7 @@
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;
@@ -29,13 +30,7 @@
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import java.util.Arrays;
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.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
@@ -52,17 +47,19 @@
    private final RedisService redisService;
    private final RemoteConfigService remoteConfigService;
    private final RemoteShopService remoteShopService;
    /**
     * 直播首页分页列表
     *
     * @param dto
     * @return
     */
    public Page<XiaoeLiveVo> getLivePage(XiaoeLiveQueryDto dto) {
    public Page<XiaoeLiveVoV2> getLivePage(XiaoeLiveQueryDto dto) {
        //当前登录用户id
        Long userId = SecurityUtils.getUserId();
        Page<XiaoeLiveVo> livePageList = xiaoeUtils.getLivePageList(dto);
        dto.setTags(Arrays.asList("20275808", "20275805", "20275707", "20249173", "2406002"));
        Page<XiaoeLiveVoV2> livePageList = xiaoeUtils.getLivePageListV2(dto);
        if (CollectionUtil.isEmpty(livePageList.getRecords())) {
            return new Page<>();
        }
@@ -71,18 +68,18 @@
                .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()
        List<XiaoeLiveVoV2> filteredRecords = livePageList.getRecords().stream()
                .filter(item -> !item.getAliveState().equals(2)) // 过滤直播状态为已结束的记录
                .peek(item -> {
                    // 查找对应的预约记录
                    XiaoeLiveAppointment appointment = appointmentMap.get(item.getId());
                    // 如果预约记录存在且直播状态为未开始,则设置状态为已预约
                    if (item.getAliveState().equals(0) && appointment != null) {
                        item.setAppointmentState(1); // 设置为已预约
                    }
                })
                .sorted(Comparator.comparing(XiaoeLiveVo::getAliveState).reversed()) // 按照直播状态排序
                .sorted(Comparator.comparing(XiaoeLiveVoV2::getAliveState).reversed()) // 按照直播状态排序
                .collect(Collectors.toList());
        //根据直播类型过滤平台和店铺直播
        if (Objects.nonNull(dto.getLiveType())) {
@@ -164,15 +161,16 @@
        }
        return true;
    }
    /**
     * 我的直播
     *
     * @param dto
     * @return
     */
    public Page<XiaoeLiveVo> getMineLivePage(XiaoeLiveQueryDto dto) {
    public Page<XiaoeLiveVoV2> getMineLivePage(XiaoeLiveQueryDto dto) {
        Long userId = SecurityUtils.getUserId();
        Page<XiaoeLiveVo> page = new Page<>();
        Page<XiaoeLiveVoV2> page = new Page<>();
        ShopRelUserVo shopRelUserVo = remoteShopService.getShopByUserId(userId).getData();
        if (Objects.isNull(shopRelUserVo)) {
            return page;
@@ -181,17 +179,19 @@
        if (CollectionUtil.isEmpty(xiaoeLiveRecordList)) {
            return page;
        }
        Page<XiaoeLiveVo> livePageList = xiaoeUtils.getLivePageList(dto);
        dto.setTags(Arrays.asList("20275808", "20275805", "20275707", "20249173", "2406002"));
        Page<XiaoeLiveVoV2> livePageList = xiaoeUtils.getLivePageListV2(dto);
        if (CollectionUtil.isEmpty(livePageList.getRecords())) {
            return page;
        }
        //当前商家创建的直播
        Set<String> liveIdSet = xiaoeLiveRecordList.stream().map(XiaoeLiveRecord::getLiveId).collect(Collectors.toSet());
        //过滤数据
        List<XiaoeLiveVo> filteredRecords = livePageList.getRecords().stream()
        List<XiaoeLiveVoV2> filteredRecords = livePageList.getRecords().stream()
                .filter(item -> liveIdSet.contains(item.getId()) && !item.getAliveState().equals(2))
                // 按照直播状态排序
                .sorted(Comparator.comparing(XiaoeLiveVo::getAliveState).reversed()).collect(Collectors.toList());
                .sorted(Comparator.comparing(XiaoeLiveVoV2::getAliveState).reversed()).collect(Collectors.toList());
        livePageList.setRecords(filteredRecords);
        return livePageList;
    }
@@ -268,14 +268,16 @@
        }
        return xiaoeUtils.editLive(dto);
    }
    /**
     * 管理后台直播分页列表
     *
     * @param dto
     * @return
     */
    public Page<XiaoeLiveVo> getMgtLivePage(XiaoeLiveQueryDto dto) {
        Page<XiaoeLiveVo> livePageList = xiaoeUtils.getLivePageList(dto);
    public Page<XiaoeLiveVoV2> getMgtLivePage(XiaoeLiveQueryDto dto) {
        dto.setTags(Arrays.asList("20275808", "20275805", "20275707", "20249173", "2406002"));
        Page<XiaoeLiveVoV2> livePageList = xiaoeUtils.getLivePageListV2(dto);
        Long shopId = dto.getShopId();
        if (Objects.nonNull(shopId)) {
            List<XiaoeLiveRecord> xiaoeLiveRecords = xiaoeLiveRecordService.getListByShopId(shopId);
@@ -283,7 +285,7 @@
                return new Page<>();
            }
            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);
        }
        List<XiaoeLiveRecord> shopRecordList = xiaoeLiveRecordService.lambdaQuery().eq(XiaoeLiveRecord::getType, 2).list();
@@ -308,26 +310,28 @@
            xiaoeLiveRecordService.lambdaUpdate().eq(XiaoeLiveRecord::getLiveId, id).remove();
        }
    }
    /**
     * 员工端直播列表
     *
     * @param dto
     * @return
     */
    public Page<XiaoeLiveVo> getStaffLivePage(XiaoeLiveQueryDto dto) {
        Page<XiaoeLiveVo> page = new Page<>();
    public Page<XiaoeLiveVoV2> getStaffLivePage(XiaoeLiveQueryDto dto) {
        Page<XiaoeLiveVoV2> page = new Page<>();
        List<XiaoeLiveRecord> xiaoeLiveRecordList = xiaoeLiveRecordService.getMgtRecord();
        if (CollectionUtil.isEmpty(xiaoeLiveRecordList)) {
            return page;
        }
        Page<XiaoeLiveVo> livePageList = xiaoeUtils.getLivePageList(dto);
        dto.setTags(Arrays.asList("20275808", "20275805", "20275707", "20249173", "2406002"));
        Page<XiaoeLiveVoV2> livePageList = xiaoeUtils.getLivePageListV2(dto);
        if (CollectionUtil.isEmpty(livePageList.getRecords())) {
            return page;
        }
        //筛选平台创建的直播
        Set<String> liveIdSet = xiaoeLiveRecordList.stream().map(XiaoeLiveRecord::getLiveId).collect(Collectors.toSet());
        //过滤数据
        List<XiaoeLiveVo> filteredRecords = livePageList.getRecords().stream().filter(item -> liveIdSet.contains(item.getId()) && !item.getAliveState().equals(2)).collect(Collectors.toList());
        List<XiaoeLiveVoV2> filteredRecords = livePageList.getRecords().stream().filter(item -> liveIdSet.contains(item.getId()) && !item.getAliveState().equals(2)).collect(Collectors.toList());
        livePageList.setRecords(filteredRecords);
        return livePageList;
    }