| | |
| | | import cn.lili.cache.Cache; |
| | | import cn.lili.cache.CachePrefix; |
| | | import cn.lili.common.security.context.UserContext; |
| | | import cn.lili.elasticsearch.EsSuffix; |
| | | import cn.lili.modules.lmk.constant.RedisKeyExpireConstant; |
| | | import cn.lili.modules.lmk.domain.entity.*; |
| | | import cn.lili.modules.lmk.domain.es.VideoIndex; |
| | | import cn.lili.modules.lmk.domain.form.*; |
| | | import cn.lili.modules.lmk.domain.query.*; |
| | | import cn.lili.modules.lmk.domain.vo.*; |
| | |
| | | import org.apache.commons.collections4.CollectionUtils; |
| | | import org.apache.commons.collections4.ListUtils; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.factory.annotation.Qualifier; |
| | | import org.springframework.stereotype.Service; |
| | | import lombok.RequiredArgsConstructor; |
| | | import cn.lili.utils.PageUtil; |
| | |
| | | private final VideoGoodsService videoGoodsService; |
| | | private final KitchenTypeService kitchenTypeService; |
| | | private final Cache cache; |
| | | |
| | | @Qualifier("videoEsServiceImpl") |
| | | private final EsService videoEsService; |
| | | |
| | | |
| | | /** |
| | | * 添加 |
| | |
| | | * @return |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Result removeById(String id) { |
| | | baseMapper.deleteById(id); |
| | | new LambdaUpdateChainWrapper<>(videoGoodsService.getBaseMapper()) |
| | | .eq(VideoGoods::getVideoId, id) |
| | | .remove(); |
| | | new LambdaUpdateChainWrapper<>(videoTagRefService.getBaseMapper()) |
| | | .eq(VideoTagRef::getVideoId, id) |
| | | .remove(); |
| | | videoEsService.deleteDocument(EsSuffix.VIDEO_INDEX_NAME, id); |
| | | return Result.ok("删除成功"); |
| | | } |
| | | |
| | |
| | | } |
| | | baseMapper.insert(video); |
| | | // 2.处理标签 |
| | | List<SimpleVideoTagVO> esTagList = new ArrayList<>(2); |
| | | List<VideoTagRef> videoTagRefs = form.getTags().stream().map(tag -> { |
| | | VideoTagRef videoTagRef = new VideoTagRef(); |
| | | videoTagRef.setVideoId(video.getId()); |
| | |
| | | } else { |
| | | videoTagRef.setVideoTagId(tag.getId()); |
| | | } |
| | | SimpleVideoTagVO esTag = new SimpleVideoTagVO(); |
| | | esTag.setVideoId(video.getId()); |
| | | esTag.setTagName(tag.getTagName()); |
| | | esTag.setId(tag.getId()); |
| | | esTagList.add(esTag); |
| | | return videoTagRef; |
| | | }).collect(Collectors.toList()); |
| | | videoTagRefService.saveBatch(videoTagRefs); |
| | | // 3. 保存视频文件信息 |
| | | lmkFileService.addByForm(form.getFileInfo()); |
| | | // 4. 处理选择的商品 |
| | | List<VideoGoods> videoGoods = new ArrayList<>(2); |
| | | if (CollectionUtils.isNotEmpty(form.getGoodsList())) { |
| | | List<VideoGoods> videoGoods = new ArrayList<>(2); |
| | | for (int i = 0; i < form.getGoodsList().size(); i++) { |
| | | VideoGoods e = new VideoGoods(); |
| | | e.setVideoId(video.getId()); |
| | |
| | | e.setGoodsSkuId(form.getGoodsList().get(i).getGoodsSkuId()); |
| | | e.setGoodsNum(form.getGoodsList().get(i).getGoodsNum()); |
| | | e.setOrderNum(i); |
| | | videoGoods.add(e); |
| | | videoGoodsService.save(e); |
| | | } |
| | | videoGoodsService.saveBatch(videoGoods); |
| | | } |
| | | // 5. 构建es中数据 |
| | | VideoIndex videoIndex = new VideoIndex(); |
| | | BeanUtils.copyProperties(video, videoIndex); |
| | | videoIndex.setCoverFileKey(video.getCoverUrl()); |
| | | List<VideoGoodsDetailVO> esGoodsList = videoGoods.stream().map(goods -> { |
| | | VideoGoodsDetailVO vo = new VideoGoodsDetailVO(); |
| | | BeanUtils.copyProperties(goods, vo); |
| | | return vo; |
| | | }).collect(Collectors.toList()); |
| | | videoIndex.setGoodsList(esGoodsList); |
| | | videoIndex.setTagList(esTagList); |
| | | videoEsService.addOrUpdateDocument(EsSuffix.VIDEO_INDEX_NAME, video.getId(), videoIndex); |
| | | return Result.ok("发布成功,视频审核中~"); |
| | | } |
| | | |
| | |
| | | new LambdaUpdateChainWrapper<>(videoTagRefService.getBaseMapper()) |
| | | .eq(VideoTagRef::getVideoId, video.getId()) |
| | | .remove(); |
| | | List<SimpleVideoTagVO> esTagList = new ArrayList<>(2); |
| | | List<VideoTagRef> videoTagRefs = form.getTags().stream().map(tag -> { |
| | | VideoTagRef videoTagRef = new VideoTagRef(); |
| | | videoTagRef.setVideoId(video.getId()); |
| | |
| | | } else { |
| | | videoTagRef.setVideoTagId(tag.getId()); |
| | | } |
| | | SimpleVideoTagVO esTag = new SimpleVideoTagVO(); |
| | | esTag.setVideoId(video.getId()); |
| | | esTag.setTagName(tag.getTagName()); |
| | | esTag.setId(tag.getId()); |
| | | esTagList.add(esTag); |
| | | return videoTagRef; |
| | | }).collect(Collectors.toList()); |
| | | videoTagRefService.saveBatch(videoTagRefs); |
| | |
| | | new LambdaUpdateChainWrapper<>(videoGoodsService.getBaseMapper()) |
| | | .eq(VideoGoods::getVideoId, video.getId()) |
| | | .remove(); |
| | | List<VideoGoods> videoGoods = new ArrayList<>(2); |
| | | if (CollectionUtils.isNotEmpty(form.getGoodsList())) { |
| | | List<VideoGoods> videoGoods = new ArrayList<>(2); |
| | | for (int i = 0; i < form.getGoodsList().size(); i++) { |
| | | VideoGoods e = new VideoGoods(); |
| | | e.setVideoId(video.getId()); |
| | |
| | | } |
| | | videoGoodsService.saveBatch(videoGoods); |
| | | } |
| | | // 5. 更新es中的数据 |
| | | VideoIndex videoIndex = new VideoIndex(); |
| | | BeanUtils.copyProperties(video, videoIndex); |
| | | videoIndex.setCoverFileKey(video.getCoverUrl()); |
| | | List<VideoGoodsDetailVO> esGoodsList = videoGoods.stream().map(goods -> { |
| | | VideoGoodsDetailVO vo = new VideoGoodsDetailVO(); |
| | | BeanUtils.copyProperties(goods, vo); |
| | | return vo; |
| | | }).collect(Collectors.toList()); |
| | | videoIndex.setGoodsList(esGoodsList); |
| | | videoIndex.setTagList(esTagList); |
| | | videoEsService.addOrUpdateDocument(EsSuffix.VIDEO_INDEX_NAME, video.getId(), videoIndex); |
| | | return Result.ok("发布成功,视频审核中~"); |
| | | } |
| | | |
| | |
| | | .eq(Video::getId, form.getId()) |
| | | .set(Video::getRecommend, form.getRecommend()) |
| | | .update(); |
| | | Map<String, Object> fields = new HashMap<>(2); |
| | | fields.put("recommend", form.getRecommend()); |
| | | videoEsService.updateSomeField(EsSuffix.VIDEO_INDEX_NAME, form.getId(), fields); |
| | | return Result.ok("设置成功"); |
| | | } |
| | | |
| | |
| | | if (form.getResult()) { |
| | | video.setStatus(VideoStatusEnum.PUBLISHED.getValue()); |
| | | video.setAuditPassTime(new Date()); |
| | | |
| | | Map<String, Object> fields = new HashMap<>(2); |
| | | fields.put("status", VideoStatusEnum.PUBLISHED.getValue()); |
| | | videoEsService.updateSomeField(EsSuffix.VIDEO_INDEX_NAME, video.getId(), fields); |
| | | } else { |
| | | video.setStatus(VideoStatusEnum.REJECT.getValue()); |
| | | } |
| | |
| | | |
| | | @Override |
| | | public Result up(String id) { |
| | | // 1. 更新数据库 |
| | | new LambdaUpdateChainWrapper<>(baseMapper) |
| | | .eq(Video::getId, id) |
| | | .set(Video::getStatus, VideoStatusEnum.PUBLISHED.getValue()) |
| | | .update(); |
| | | // 2. 更新es |
| | | Map<String, Object> fields = new HashMap<>(2); |
| | | fields.put("status", VideoStatusEnum.PUBLISHED.getValue()); |
| | | videoEsService.updateSomeField(EsSuffix.VIDEO_INDEX_NAME, id, fields); |
| | | return Result.ok("上架成功"); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public Result down(VideoDownForm form) { |
| | | // 1. 更新数据库 |
| | | new LambdaUpdateChainWrapper<>(baseMapper) |
| | | .eq(Video::getId, form.getId()) |
| | | .set(Video::getStatus, VideoStatusEnum.DISABLE.getValue()) |
| | | .update(); |
| | | // 2. 更新es |
| | | Map<String, Object> fields = new HashMap<>(2); |
| | | fields.put("status", VideoStatusEnum.DISABLE.getValue()); |
| | | videoEsService.updateSomeField(EsSuffix.VIDEO_INDEX_NAME, form.getId(), fields); |
| | | // TODO 将下架原因以通知的方式告知用户 |
| | | |
| | | return Result.ok("下架成功"); |
| | | } |
| | | |