diff --git a/sql/add_new_db.sql b/sql/add_new_db.sql index 4a3ef10..4794cd9 100644 --- a/sql/add_new_db.sql +++ b/sql/add_new_db.sql @@ -55,3 +55,8 @@ alter table aijinan.live_report 1 autoLiveTask AutoLiveTask 0/30 * * * * ? 0 This is a test job 2025-02-08 10:55:23 2 likeSyncTask syncLikesToDatabase 0/15 * * * * ? 0 自动将redis的点赞数存储在数据库中 3 likeSyncTask syncReportLikesToDatabase 0/15 * * * * ? 0 自动将redis的点赞数存储在数据库中 2025-02-20 11:07:00 + + + +alter table aijinan.live_channel + add column title_show int default '0' COMMENT '是否显示别名 0 不显示 1显示'; diff --git a/src/main/java/com/platform/config/ShiroConfig.java b/src/main/java/com/platform/config/ShiroConfig.java index e958cb6..9bad91a 100644 --- a/src/main/java/com/platform/config/ShiroConfig.java +++ b/src/main/java/com/platform/config/ShiroConfig.java @@ -59,6 +59,8 @@ public class ShiroConfig { shiroFilter.setFilters(filters); Map filterMap = new LinkedHashMap<>(); + filterMap.put("/live/channel/appView", "anon"); + filterMap.put("/webjars/**", "anon"); // filterMap.put("/druid/**", "anon"); filterMap.put("/app/**", "anon"); 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 517702d..b46ce6e 100644 --- a/src/main/java/com/platform/modules/live/controller/LiveChannelController.java +++ b/src/main/java/com/platform/modules/live/controller/LiveChannelController.java @@ -2,10 +2,18 @@ package com.platform.modules.live.controller; import java.util.Date; import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.CopyOnWriteArrayList; +import cn.hutool.core.collection.CollectionUtil; +import cn.hutool.db.meta.Column; import com.platform.modules.live.entity.LiveChannelComponentEntity; import com.platform.modules.live.service.LiveChannelTenantService; import com.platform.modules.live.service.impl.LiveChannelComponentServiceImpl; +import com.platform.modules.sys.dao.SysConfigDao; +import com.platform.modules.sys.entity.SysConfigEntity; +import com.platform.modules.sys.service.impl.SysConfigServiceImpl; +import io.swagger.models.auth.In; import org.apache.commons.lang3.StringUtils; import org.apache.http.HttpStatus; import org.apache.shiro.authz.annotation.RequiresPermissions; @@ -42,6 +50,12 @@ import springfox.documentation.annotations.ApiIgnore; public class LiveChannelController extends AbstractController{ @Autowired private LiveChannelService liveChannelService; + + + @Autowired + private SysConfigServiceImpl sysConfigService; + @Autowired + private SysConfigDao sysConfigDao; @Autowired private LiveChannelComponentServiceImpl liveChannelComponentService; @@ -193,6 +207,16 @@ public class LiveChannelController extends AbstractController{ * * @return 集合 */ + @PostMapping("/channelAppView") + public R channelAppView() { + return R.ok().put("appView",liveChannelService.channelAppView(copyOnWriteArrayList,liveChannelComponentEntity)); + } + + /** + * 查询APP端口现场大屏和栏目封装 + * + * @return 集合 + */ @PostMapping("/appView") public R appView() { return R.ok().put("appView",liveChannelService.appView()); @@ -224,6 +248,13 @@ public class LiveChannelController extends AbstractController{ return R.error("组件ID错误"); } + + // 缓存待提交的栏目修改(线程安全) + public CopyOnWriteArrayList copyOnWriteArrayList = new CopyOnWriteArrayList<>(); + + public LiveChannelComponentEntity liveChannelComponentEntity = new LiveChannelComponentEntity(); + + /** * 保存修改后的组件属性信息 * @param liveChannel 需要修改栏目的属性信息 根据ComponentType去区分是否为轮播大图 @@ -232,33 +263,67 @@ public class LiveChannelController extends AbstractController{ @PostMapping("/saveMessage") public R saveMessage(@RequestBody LiveChannelEntity liveChannel){ if(liveChannel.getComponentType().equals("lunbodatu")) { - LiveChannelComponentEntity liveChannelComponentEntity = new LiveChannelComponentEntity(); - liveChannelComponentEntity.setId(liveChannel.getId()); + liveChannelComponentEntity.setId(4); liveChannelComponentEntity.setDefaultCount(liveChannel.getComponentCount()); - liveChannelComponentService.updateById(liveChannelComponentEntity); +// liveChannelComponentService.updateById(liveChannelComponentEntity); + }else { - LiveChannelEntity entity = new LiveChannelEntity(); - entity.setId(liveChannel.getId()); - entity.setPriority(liveChannel.getPriority()); - entity.setIsDisplay(liveChannel.getIsDisplay()); - entity.setComponentType(liveChannel.getComponentType()); - entity.setComponentLayout(liveChannel.getComponentLayout()); - entity.setComponentCount(liveChannel.getComponentCount()); - entity.setTitleSetting(liveChannel.getTitleSetting()); - entity.setLastUpdateUser(getUserId()); - entity.setLastUpdateDate(new Date()); - liveChannelService.updateById(entity); + LiveChannelEntity liveChannelEntity = liveChannelService.selectById(liveChannel.getId()); + + + liveChannelEntity = getLiveChannelEntity(liveChannelEntity,liveChannel); + // 使用同步块保证原子性:检查、删除旧值、添加新值 +// synchronized (copyOnWriteArrayList) { + // 删除所有相同ID的旧数据 + LiveChannelEntity finalLiveChannelEntity = liveChannelEntity; + copyOnWriteArrayList.removeIf(e -> e.getId().equals(finalLiveChannelEntity.getId())); + // 添加新数据(覆盖) + copyOnWriteArrayList.add(liveChannelEntity); +// } } return R.ok(); } + private LiveChannelEntity getLiveChannelEntity(LiveChannelEntity liveChannelOld,LiveChannelEntity liveChannel) { + + liveChannelOld.setId(liveChannel.getId()); + liveChannelOld.setPriority(liveChannel.getPriority()); + liveChannelOld.setIsDisplay(liveChannel.getIsDisplay()); + liveChannelOld.setComponentType(liveChannel.getComponentType()); + liveChannelOld.setComponentLayout(liveChannel.getComponentLayout()); + liveChannelOld.setComponentCount(liveChannel.getComponentCount()); + liveChannelOld.setTitleSetting(liveChannel.getTitleSetting()); + liveChannelOld.setTitleShow(liveChannel.getTitleShow()); + liveChannelOld.setLastUpdateUser(getUserId()); + liveChannelOld.setLastUpdateDate(new Date()); + return liveChannelOld; + } + /** * 点击保存后,更新信息同步到APP 暂未实现 * @return */ @GetMapping("/updateToAPP") - public R updateToAPP(){ + public R updateToAPP( Integer style){ + + if(liveChannelComponentEntity.getId()!=null){ + liveChannelComponentService.updateById(liveChannelComponentEntity); + } + + if(CollectionUtil.isNotEmpty(copyOnWriteArrayList)) { + boolean isSuccess = liveChannelService.updateBatchById(copyOnWriteArrayList); + if(isSuccess){ + copyOnWriteArrayList.clear(); + } + } + if(style == 1 || style == 2 || style == 3){ + String pageStyle = "PAGE_STYLE"; + SysConfigEntity sysConfig = sysConfigDao.getPageStyle(pageStyle); + sysConfig.setValue(String.valueOf(style)); + sysConfigDao.updateById(sysConfig); + + } return R.ok(); } diff --git a/src/main/java/com/platform/modules/live/dto/ChannelDTO.java b/src/main/java/com/platform/modules/live/dto/ChannelDTO.java index a08fbad..549611c 100644 --- a/src/main/java/com/platform/modules/live/dto/ChannelDTO.java +++ b/src/main/java/com/platform/modules/live/dto/ChannelDTO.java @@ -16,5 +16,6 @@ public class ChannelDTO { private String componentLayout; private String identify; private List liveScenes; + private Integer titleShow; } diff --git a/src/main/java/com/platform/modules/live/dto/LiveSceneDTO.java b/src/main/java/com/platform/modules/live/dto/LiveSceneDTO.java index 07e969e..6291af4 100644 --- a/src/main/java/com/platform/modules/live/dto/LiveSceneDTO.java +++ b/src/main/java/com/platform/modules/live/dto/LiveSceneDTO.java @@ -8,5 +8,6 @@ public class LiveSceneDTO { private String title; private String titleImage; private Integer liveState; + private String liveImageShow; } diff --git a/src/main/java/com/platform/modules/live/entity/LiveChannelEntity.java b/src/main/java/com/platform/modules/live/entity/LiveChannelEntity.java index 73687a0..a047800 100644 --- a/src/main/java/com/platform/modules/live/entity/LiveChannelEntity.java +++ b/src/main/java/com/platform/modules/live/entity/LiveChannelEntity.java @@ -79,6 +79,8 @@ public class LiveChannelEntity implements Serializable { private String titleSetting; // 标题设置 + private Integer titleShow; + @TableField(exist=false) private LiveChannelComponentEntity liveChannelComponent; @@ -266,4 +268,12 @@ public class LiveChannelEntity implements Serializable { public void setLiveChannelComponent(LiveChannelComponentEntity liveChannelComponent) { this.liveChannelComponent = liveChannelComponent; } + + public Integer getTitleShow() { + return titleShow; + } + + public void setTitleShow(Integer titleShow) { + this.titleShow = titleShow; + } } 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 6751efa..df684ab 100644 --- a/src/main/java/com/platform/modules/live/service/LiveChannelService.java +++ b/src/main/java/com/platform/modules/live/service/LiveChannelService.java @@ -2,9 +2,11 @@ package com.platform.modules.live.service; import java.util.HashMap; import java.util.Map; +import java.util.concurrent.CopyOnWriteArrayList; import com.baomidou.mybatisplus.service.IService; import com.platform.common.utils.PageUtils; +import com.platform.modules.live.entity.LiveChannelComponentEntity; import com.platform.modules.live.entity.LiveChannelEntity; import net.sf.json.JSONArray; @@ -53,4 +55,6 @@ public interface LiveChannelService extends IService { HashMap appView(); LiveChannelEntity getChannelComponent(Integer channelId); + + HashMap channelAppView(CopyOnWriteArrayList list,LiveChannelComponentEntity liveChannel); } diff --git a/src/main/java/com/platform/modules/live/service/impl/LiveChannelComponentServiceImpl.java b/src/main/java/com/platform/modules/live/service/impl/LiveChannelComponentServiceImpl.java index 1b796ea..bb6867c 100644 --- a/src/main/java/com/platform/modules/live/service/impl/LiveChannelComponentServiceImpl.java +++ b/src/main/java/com/platform/modules/live/service/impl/LiveChannelComponentServiceImpl.java @@ -3,9 +3,13 @@ package com.platform.modules.live.service.impl; import com.baomidou.mybatisplus.service.impl.ServiceImpl; import com.platform.modules.live.dao.LiveChannelComponentDao; import com.platform.modules.live.entity.LiveChannelComponentEntity; +import com.platform.modules.live.entity.LiveChannelEntity; import com.platform.modules.live.service.LiveChannelComponentService; import org.springframework.stereotype.Service; +import java.util.List; + @Service("liveChannelComponentService") public class LiveChannelComponentServiceImpl extends ServiceImpl implements LiveChannelComponentService { + } 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 8fcffa0..3b2b5cb 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,6 +1,7 @@ package com.platform.modules.live.service.impl; import java.util.*; +import java.util.concurrent.CopyOnWriteArrayList; import java.util.function.Function; import java.util.stream.Collectors; @@ -17,13 +18,9 @@ import com.platform.modules.plm.util.MaterialUtils; import com.platform.modules.sys.dao.SysConfigDao; import com.platform.modules.sys.entity.SysConfigEntity; import com.platform.modules.sys.service.impl.SysConfigServiceImpl; -import io.swagger.models.auth.In; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; -import org.springframework.beans.BeanInfoFactory; -import org.springframework.beans.factory.BeanFactoryUtils; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import com.baomidou.mybatisplus.mapper.EntityWrapper; @@ -370,6 +367,7 @@ private LiveChannelDao liveChannelDao; return new PageUtils(page); } + @Override public HashMap appView() { @@ -471,6 +469,135 @@ private LiveChannelDao liveChannelDao; return map; } + @Override + public HashMap channelAppView(CopyOnWriteArrayList copyOnWriteArrayList,LiveChannelComponentEntity liveChannelComponentEntity) { + + + HashMap map = new HashMap<>(); + //1.查询轮播大图 + + + LiveChannelComponentEntity liveChannelComponent = liveChannelComponentService.selectOne(new EntityWrapper() + .eq("component_type", "lunbodatu")); + + Integer count = liveChannelComponentEntity.getId() == null ? liveChannelComponent.getDefaultCount() : liveChannelComponentEntity.getDefaultCount(); + + + List sceneEntities = liveSceneService.selectList(new EntityWrapper() + .eq("delete_flag", 0) + .eq("scene_state", SceneConstants.SCENE_PROD) + .eq("carousel_image", 1) + .last("limit " + count)); + // 将 LiveSceneEntity 转换为 LiveSceneDTO + List liveScenes = sceneEntities.stream() + .map(this::convertToDTO) + .collect(Collectors.toList()); + + map.put("carouselScene", liveScenes); + +// 2.按照栏目封装现场 + + + Wrapper wrapper = new EntityWrapper() + .eq("is_delete", 0) + .eq("is_display", 1) + .orderBy("priority", false); + + List channelEntities = liveChannelService.selectList(wrapper); + + // 如果缓存和数据库都有数据,则以缓存中的数据覆盖数据库中的数据 + if (CollectionUtils.isNotEmpty(channelEntities) && CollectionUtils.isNotEmpty(copyOnWriteArrayList)) { + Map cachedMap = copyOnWriteArrayList.stream() + .collect(Collectors.toMap(LiveChannelEntity::getId, Function.identity())); + channelEntities.forEach(entity -> { + if (cachedMap.containsKey(entity.getId())) { + // 使用缓存中的数据覆盖数据库中的数据 + LiveChannelEntity cachedEntity = cachedMap.get(entity.getId()); + entity.setPriority(cachedEntity.getPriority()); + entity.setIsDisplay(cachedEntity.getIsDisplay()); + entity.setComponentType(cachedEntity.getComponentType()); + entity.setComponentLayout(entity.getComponentLayout()); + entity.setComponentCount(cachedEntity.getComponentCount()); + entity.setTitleSetting(cachedEntity.getTitleSetting()); + entity.setTitleShow(cachedEntity.getTitleShow()); + + } + }); + } + + +// List channelEntities = liveChannelService.selectList(wrapper); + 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()) + ); + + + if(channelDTO.getComponentCount() == null) { + LiveChannelComponentEntity channelComponentEntity = liveChannelComponentService.selectOne(new EntityWrapper() + .eq("component_type", channelDTO.getComponentType())); + channelDTO.setComponentCount(channelComponentEntity.getDefaultCount()); + } + 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) + .last("limit " + channelDTO.getComponentCount()) + ); + + //1.重置当前栏目所有现场的channel_display字段为false + liveChannelDao.resetChannelDisplay(channelDTO.getChannelName()); + //2.将所有查询到的现场的channel_display字段设置为true + liveSceneEntities.forEach(liveSceneEntity -> { + liveChannelDao.updateChannelDisplay(liveSceneEntity.getId()); + liveSceneEntity.setTitleImage( MaterialUtils.getMaterialUrl(liveSceneEntity.getTitleImage(), foreignProperties.getMediaurl())); + }); + + } + + // 将 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); + + //3.获取页面风格 + String pageStyle = "PAGE_STYLE"; + SysConfigEntity sysConfig = sysConfigDao.getPageStyle(pageStyle); + if(sysConfig == null){ + sysConfig = new SysConfigEntity(); + sysConfig.setKey("PAGE_STYLE"); + sysConfig.setValue("1"); + sysConfig.setRemark("页面风格(页面风格:基础蓝色、喜庆红色、哀悼灰色)"); + sysConfigDao.insert(sysConfig); + } + map.put("pageStyle", sysConfig.getValue()); + return map; + } + @Override public LiveChannelEntity getChannelComponent(Integer channalId) { @@ -496,16 +623,19 @@ private LiveChannelDao liveChannelDao; dto.setTitle(entity.getTitle()); dto.setTitleImage(entity.getTitleImage()); dto.setLiveState(entity.getLiveState()); + dto.setLiveImageShow(MaterialUtils.getMaterialUrl(entity.getTitleImage(), foreignProperties.getMediaurl())); return dto; } private ChannelDTO convertToB(LiveChannelEntity a) { ChannelDTO channelDTO = new ChannelDTO(); + channelDTO.setChannelId(a.getId()); channelDTO.setChannelName(a.getName()); channelDTO.setComponentCount(a.getComponentCount()); channelDTO.setComponentType(a.getComponentType()); channelDTO.setTitleSetting(a.getTitleSetting()); + channelDTO.setTitleShow(a.getTitleShow()); channelDTO.setPriority(a.getPriority()); channelDTO.setIsDisplay(a.getIsDisplay()); channelDTO.setComponentLayout(a.getComponentLayout()); diff --git a/src/main/java/com/platform/modules/live/service/impl/LiveSceneServiceImpl.java b/src/main/java/com/platform/modules/live/service/impl/LiveSceneServiceImpl.java index cb46e1a..73c347b 100644 --- a/src/main/java/com/platform/modules/live/service/impl/LiveSceneServiceImpl.java +++ b/src/main/java/com/platform/modules/live/service/impl/LiveSceneServiceImpl.java @@ -2524,7 +2524,6 @@ public class LiveSceneServiceImpl extends ServiceImpl sceneEntityList = this.baseMapper.querySort(page, params); - if (null == sceneEntityList || sceneEntityList.size() == 0) return null; @@ -2537,7 +2536,8 @@ public class LiveSceneServiceImpl extends ServiceImpl