From 19624d2e73bd627a46a60b93c53f1ef3b9d6df75 Mon Sep 17 00:00:00 2001 From: 2210088963 <2210088963@qq.com> Date: Tue, 11 Feb 2025 08:58:15 +0800 Subject: [PATCH] =?UTF-8?q?1.=E5=A2=9E=E5=8A=A0=E4=BA=86=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E7=8E=B0=E5=9C=BA=E5=A4=A7=E5=B1=8F=E5=92=8C=E6=A0=8F=E7=9B=AE?= =?UTF-8?q?=E5=B0=81=E8=A3=85=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/LiveChannelController.java | 13 +++ .../platform/modules/live/dto/ChannelDTO.java | 12 +++ .../modules/live/dto/LiveSceneDTO.java | 12 +++ .../live/service/LiveChannelService.java | 3 + .../service/impl/LiveChannelServiceImpl.java | 99 +++++++++++++++++-- 5 files changed, 133 insertions(+), 6 deletions(-) create mode 100644 src/main/java/com/platform/modules/live/dto/ChannelDTO.java create mode 100644 src/main/java/com/platform/modules/live/dto/LiveSceneDTO.java diff --git a/src/main/java/com/platform/modules/live/controller/LiveChannelController.java b/src/main/java/com/platform/modules/live/controller/LiveChannelController.java index 224fc4f..cb1b849 100644 --- a/src/main/java/com/platform/modules/live/controller/LiveChannelController.java +++ b/src/main/java/com/platform/modules/live/controller/LiveChannelController.java @@ -1,5 +1,6 @@ package com.platform.modules.live.controller; +import java.util.HashMap; import java.util.Map; import com.platform.modules.live.service.LiveChannelTenantService; @@ -188,4 +189,16 @@ public class LiveChannelController extends AbstractController{ return R.ok(); } + /** + * 查询现场大屏和栏目封装 + * @return 集合 + */ + @PostMapping("/appView") + public HashMap appView() { + return liveChannelService.appView(); + } + + + + } diff --git a/src/main/java/com/platform/modules/live/dto/ChannelDTO.java b/src/main/java/com/platform/modules/live/dto/ChannelDTO.java new file mode 100644 index 0000000..82821c7 --- /dev/null +++ b/src/main/java/com/platform/modules/live/dto/ChannelDTO.java @@ -0,0 +1,12 @@ +package com.platform.modules.live.dto; + +import lombok.Data; + +import java.util.List; +@Data +public class ChannelDTO { + private Integer channelId; + private String channelName; + private List liveScenes; +} + diff --git a/src/main/java/com/platform/modules/live/dto/LiveSceneDTO.java b/src/main/java/com/platform/modules/live/dto/LiveSceneDTO.java new file mode 100644 index 0000000..d3137a0 --- /dev/null +++ b/src/main/java/com/platform/modules/live/dto/LiveSceneDTO.java @@ -0,0 +1,12 @@ +package com.platform.modules.live.dto; + +import lombok.Data; + +@Data +public class LiveSceneDTO { + private Integer id; + private String title; + private String titleImage; + + +} diff --git a/src/main/java/com/platform/modules/live/service/LiveChannelService.java b/src/main/java/com/platform/modules/live/service/LiveChannelService.java index dc73ee5..0c6d677 100644 --- a/src/main/java/com/platform/modules/live/service/LiveChannelService.java +++ b/src/main/java/com/platform/modules/live/service/LiveChannelService.java @@ -1,5 +1,6 @@ package com.platform.modules.live.service; +import java.util.HashMap; import java.util.Map; import com.baomidou.mybatisplus.service.IService; @@ -48,4 +49,6 @@ public interface LiveChannelService extends IService { JSONArray getAllChannelByTenant(Long tenantId); PageUtils pageAll(Map params); + + HashMap appView(); } diff --git a/src/main/java/com/platform/modules/live/service/impl/LiveChannelServiceImpl.java b/src/main/java/com/platform/modules/live/service/impl/LiveChannelServiceImpl.java index b4d36cf..5ba0662 100644 --- a/src/main/java/com/platform/modules/live/service/impl/LiveChannelServiceImpl.java +++ b/src/main/java/com/platform/modules/live/service/impl/LiveChannelServiceImpl.java @@ -1,11 +1,17 @@ package com.platform.modules.live.service.impl; -import java.util.ArrayList; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; +import java.util.function.Function; +import java.util.stream.Collectors; +import com.platform.modules.live.constants.SceneConstants; +import com.platform.modules.live.dto.ChannelDTO; +import com.platform.modules.live.dto.LiveSceneDTO; +import com.platform.modules.live.entity.LiveSceneChannelEntity; +import com.platform.modules.live.entity.LiveSceneEntity; +import com.platform.modules.live.service.LiveSceneService; +import io.swagger.models.auth.In; +import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -31,8 +37,14 @@ public class LiveChannelServiceImpl extends ServiceImpl params){ //检索记录 @@ -339,4 +351,79 @@ private LiveChannelDao liveChannelDao; page.setRecords(list); return new PageUtils(page); } + + @Override + public HashMap appView() { + HashMap map = new HashMap<>(); + //1.查询轮播大图 + List sceneEntities = liveSceneService.selectList(new EntityWrapper() + .eq("delete_flag", 0) + .eq("scene_state", SceneConstants.SCENE_PROD) + .eq("carousel_image", 1) + ); + // 将 LiveSceneEntity 转换为 LiveSceneDTO + List liveScenes = sceneEntities.stream() + .map(this::convertToDTO) + .collect(Collectors.toList()); + + map.put("carouselScene", liveScenes); + +// 2.按照栏目封装现场 + List channelEntities = liveChannelService.selectList(null); + List collect = channelEntities.stream().map(this::convertToB).collect(Collectors.toList()); + // 为每个 ChannelDTO 获取 liveScenes + if(CollectionUtils.isNotEmpty(collect)){ + + collect.forEach(channelDTO -> { + // 获取当前频道的所有 LiveSceneChannelEntity + List entityList = liveSceneChannelService.selectList( + new EntityWrapper().eq("channel_id", channelDTO.getChannelId()) + ); + List liveSceneEntities= null; + if(CollectionUtils.isNotEmpty(entityList)) { + // 提取所有的 scene_id 并获取对应的 LiveSceneEntity + Set sceneIds = entityList.stream() + .map(LiveSceneChannelEntity::getSceneId) + .collect(Collectors.toSet()); + liveSceneEntities = liveSceneService.selectList(new EntityWrapper() + .in("id", sceneIds) + .eq("delete_flag", 0) + .eq("scene_state", SceneConstants.SCENE_PROD) + .orderBy("priority", false) + ); + } + + // 将 LiveSceneEntity 转换为 LiveSceneDTO + if(CollectionUtils.isNotEmpty(liveSceneEntities)){ + + List scenes = liveSceneEntities.stream() + .map(this::convertToDTO) + .collect(Collectors.toList()); + + // 设置 ChannelDTO 的 liveScenes 属性 + channelDTO.setLiveScenes(scenes); + + } + }); + + } + map.put("sceneGroupByChannel", collect); + + return map; + } + + private LiveSceneDTO convertToDTO(LiveSceneEntity entity) { + LiveSceneDTO dto = new LiveSceneDTO(); + dto.setId(entity.getId()); + dto.setTitle(entity.getTitle()); + dto.setTitleImage(entity.getTitleImage()); + return dto; + } + + private ChannelDTO convertToB(LiveChannelEntity a) { + ChannelDTO channelDTO = new ChannelDTO(); + channelDTO.setChannelId(a.getId()); + channelDTO.setChannelName(a.getName()); + return channelDTO; + } }