| | |
| | | package cn.lili.modules.member.serviceimpl; |
| | | |
| | | import cn.lili.base.Result; |
| | | import cn.lili.common.security.context.UserContext; |
| | | import cn.lili.modules.goods.entity.dos.GoodsSku; |
| | | import cn.lili.modules.goods.service.GoodsSkuService; |
| | | import cn.lili.modules.lmk.domain.query.FootPrintQuery; |
| | | import cn.lili.modules.lmk.domain.vo.SimpleVideoTagVO; |
| | | import cn.lili.modules.lmk.domain.vo.VideoFootInfoVo; |
| | | import cn.lili.modules.lmk.domain.vo.VideoFootVO; |
| | | import cn.lili.modules.lmk.domain.vo.VideoVO; |
| | | import cn.lili.modules.lmk.mapper.VideoMapper; |
| | | import cn.lili.modules.member.entity.dos.FootPrint; |
| | | import cn.lili.modules.member.entity.dto.FootPrintQueryParams; |
| | | import cn.lili.modules.member.mapper.FootprintMapper; |
| | | import cn.lili.modules.member.service.FootprintService; |
| | | import cn.lili.modules.search.entity.dos.EsGoodsIndex; |
| | | import cn.lili.mybatis.util.PageUtil; |
| | | import cn.lili.utils.COSUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | import java.util.Optional; |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | import java.util.stream.IntStream; |
| | | |
| | |
| | | @Autowired |
| | | private GoodsSkuService goodsSkuService; |
| | | |
| | | @Autowired |
| | | private VideoMapper videoMapper; |
| | | |
| | | @Autowired |
| | | private COSUtil cOSUtil; |
| | | |
| | | @Override |
| | | public FootPrint saveFootprint(FootPrint footPrint) { |
| | | LambdaQueryWrapper<FootPrint> queryWrapper = Wrappers.lambdaQuery(); |
| | | queryWrapper.eq(FootPrint::getMemberId, footPrint.getMemberId()); |
| | | queryWrapper.eq(FootPrint::getGoodsId, footPrint.getGoodsId()); |
| | | //如果已存在某商品记录,则更新其修改时间 |
| | | //如果不存在则添加记录 |
| | | //为了保证足迹的排序,将原本足迹删除后重新添加 |
| | | List<FootPrint> oldPrints = list(queryWrapper); |
| | | if (oldPrints != null && !oldPrints.isEmpty()) { |
| | | FootPrint oldPrint = oldPrints.get(0); |
| | | this.removeById(oldPrint.getId()); |
| | | } |
| | | footPrint.setCreateTime(new Date()); |
| | | this.save(footPrint); |
| | | //删除超过100条后的记录 |
| | | this.baseMapper.deleteLastFootPrint(footPrint.getMemberId()); |
| | | return footPrint; |
| | | } |
| | | |
| | |
| | | public boolean deleteByIds(List<String> ids) { |
| | | LambdaQueryWrapper<FootPrint> lambdaQueryWrapper = Wrappers.lambdaQuery(); |
| | | lambdaQueryWrapper.eq(FootPrint::getMemberId, UserContext.getCurrentUser().getId()); |
| | | lambdaQueryWrapper.in(FootPrint::getGoodsId, ids); |
| | | lambdaQueryWrapper.in(FootPrint::getRefId, ids); |
| | | return this.remove(lambdaQueryWrapper); |
| | | } |
| | | |
| | |
| | | Page<FootPrint> footPrintPages = this.page(PageUtil.initPage(params), params.queryWrapper()); |
| | | //定义结果 |
| | | Page<EsGoodsIndex> esGoodsIndexIPage = new Page<>(); |
| | | |
| | | if (footPrintPages.getRecords() != null && !footPrintPages.getRecords().isEmpty()) { |
| | | List<String> skuIds = footPrintPages.getRecords().stream().map(FootPrint::getSkuId).collect(Collectors.toList()); |
| | | List<GoodsSku> goodsSkuByIdFromCache = goodsSkuService.getGoodsSkuByIdFromCache(skuIds); |
| | |
| | | return null; |
| | | } |
| | | Optional<FootPrint> first = |
| | | footPrintPages.getRecords().stream().filter(j -> j.getSkuId().equals(goodsSkuByIdFromCache.get(i).getId())).findFirst(); |
| | | footPrintPages.getRecords().stream().filter(j -> goodsSkuByIdFromCache.get(i).getId().equals(j.getSkuId())).findFirst(); |
| | | return first.map(footPrint -> new EsGoodsIndex(goodsSkuByIdFromCache.get(i), footPrint.getCreateTime())).orElseGet(() -> new EsGoodsIndex(goodsSkuByIdFromCache.get(i))); |
| | | }) |
| | | .collect(Collectors.toList()); |
| | |
| | | } |
| | | |
| | | @Override |
| | | public Result videoFootPrintPage(FootPrintQuery query) { |
| | | IPage<VideoFootVO> page = cn.lili.utils.PageUtil.getPage(query,VideoFootVO.class); |
| | | videoMapper.videoFootPage(page,query); |
| | | |
| | | VideoFootInfoVo videoFootInfoVo = videoMapper.getVideoFootInfo(query.getMemberId()); |
| | | |
| | | for (VideoFootVO videoFootVO : page.getRecords()) { |
| | | videoFootVO.setCoverCOSUrl(cOSUtil.getPreviewUrl(videoFootVO.getCoverUrl())); |
| | | //计算播放进度 |
| | | if(videoFootVO.getPlayAt() == null || videoFootVO.getPlayAt().isEmpty()){ |
| | | videoFootVO.setPlayProgress(0.0); |
| | | continue; |
| | | } |
| | | |
| | | BigDecimal value = BigDecimal.valueOf(Double.parseDouble(videoFootVO.getPlayAt()) / videoFootVO.getVideoDuration()) |
| | | .setScale(2, RoundingMode.HALF_UP); |
| | | |
| | | if (value.compareTo(BigDecimal.ONE) > 0) { |
| | | // 这里可以添加处理逻辑,比如:自动修正为1.0 |
| | | value = BigDecimal.ONE; |
| | | } |
| | | |
| | | videoFootVO.setPlayProgress(value.doubleValue()); |
| | | } |
| | | |
| | | HashMap<String,Object> map = new HashMap<>(); |
| | | map.put("data", page.getRecords()); |
| | | map.put("total", page.getTotal()); |
| | | if (videoFootInfoVo == null) { |
| | | map.put("avgProgress",0); |
| | | map.put("totalDuration",0); |
| | | }else { |
| | | map.put("avgProgress",videoFootInfoVo.getAvgCompletionRate()); |
| | | map.put("totalDuration",videoFootInfoVo.getTotalDuration()); |
| | | } |
| | | return Result.ok().data(map); |
| | | } |
| | | |
| | | @Override |
| | | public Result memberActionAnalyse(String id){ |
| | | //视频分类 |
| | | List<VideoFootVO> list = videoMapper.videoFoot(id); |
| | | Map<String, Long> tagCountMap = list.stream() |
| | | .flatMap(video -> video.getTagList().stream()) // 展开所有 tag |
| | | .filter(Objects::nonNull) // 过滤 null |
| | | .collect(Collectors.groupingBy( |
| | | SimpleVideoTagVO::getTagName, // 按 tagName 分组 |
| | | Collectors.counting() // 计算每个 tagName 出现的次数 |
| | | )); |
| | | |
| | | return Result.ok().data(tagCountMap); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public long getFootprintNum() { |
| | | LambdaQueryWrapper<FootPrint> lambdaQueryWrapper = Wrappers.lambdaQuery(); |
| | | lambdaQueryWrapper.eq(FootPrint::getMemberId, Objects.requireNonNull(UserContext.getCurrentUser()).getId()); |
| | | lambdaQueryWrapper.eq(FootPrint::getDeleteFlag, false); |
| | | return this.count(lambdaQueryWrapper); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | } |
| | | |
| | | |