peng
2025-06-13 b3bdc131a50234de457d1a7515758b2a169ba038
framework/src/main/java/cn/lili/modules/lmk/service/impl/VideoServiceImpl.java
@@ -4,6 +4,7 @@
import cn.lili.modules.lmk.domain.entity.*;
import cn.lili.modules.lmk.domain.form.*;
import cn.lili.modules.lmk.domain.query.AuthorVideoQuery;
import cn.lili.modules.lmk.domain.query.HealthVideoQuery;
import cn.lili.modules.lmk.domain.query.ManagerVideoQuery;
import cn.lili.modules.lmk.domain.vo.*;
import cn.lili.modules.lmk.enums.general.*;
@@ -413,4 +414,60 @@
        vo.setTags(tags);
        return Result.ok().data(vo);
    }
    @Override
    public Result healthVideo(HealthVideoForm form) {
        Video video = new Video();
        BeanUtils.copyProperties(form, video);
        video.setAuthorId(UserContext.getCurrentUserId());
        video.setVideoType(VideoTypeEnum.HEALTH.getValue());
        //设置填充模式 保持比例,完整显示
        video.setVideoFit("contain");
        video.setVideoContentType(VideoContentTypeEnum.VIDEO.getValue());
        video.setStatus(VideoStatusEnum.PUBLISHED.getValue());
        baseMapper.insert(video);
        return Result.ok("添加成功");
    }
    @Override
    public Result healthPage(HealthVideoQuery query) {
        IPage<VideoVO> page = PageUtil.getPage(query, VideoVO.class);
        // 1. 先查出视频信息
        baseMapper.healthPage(page, query);
        // 2. 单独查出标签信息
        if (page.getTotal() > 0) {
            Map<String, List<SimpleVideoTagVO>> tagMap = videoTagRefService.getTagsByVideoIds(
                    page.getRecords().stream().map(VideoVO::getId).collect(Collectors.toList())
            ).stream().collect(Collectors.groupingBy(SimpleVideoTagVO::getVideoId));;
            // 3. 获取视频临时访问地址、设置视频标签
            page.getRecords().forEach(v -> {
                v.setTagList(tagMap.get(v.getId()));
                v.setVideoUrl(cosUtil.getPreviewUrl(v.getVideoFileKey()));
                v.setCoverShowUrl(cosUtil.getPreviewUrl(v.getCoverUrl()));
            });
        }
        return Result.ok().data(page.getRecords()).total(page.getTotal());
    }
    @Override
    public Result updateHealthVideo(HealthVideoForm form) {
        Video entity = baseMapper.selectById(form.getId());
        Assert.notNull(entity, "记录不存在");
        BeanUtils.copyProperties(form, entity);
        baseMapper.updateById(entity);
        return Result.ok("修改成功");
    }
    @Override
    public Result delHealth(String id) {
        Video entity = baseMapper.selectById(id);
        Assert.notNull(entity, "记录不存在");
        String videoType = entity.getVideoType();
        if (!VideoTypeEnum.HEALTH.getValue().equals(videoType)) {
            log.error("删除非大健康视频视频id为------->"+id);
            return Result.error("删除失败");
        }
        baseMapper.deleteById(id);
        return Result.ok("删除成功");
    }
}