From b305b6ce82fbb975acf42af3ad450aa4c7699d5e Mon Sep 17 00:00:00 2001 From: zxl <763096477@qq.com> Date: 星期四, 26 六月 2025 14:35:46 +0800 Subject: [PATCH] 客户分析,和浏览视频记录 --- framework/src/main/java/cn/lili/modules/member/serviceimpl/FootprintServiceImpl.java | 103 ++++++++++++++++++++++++++++++++++++++++----------- 1 files changed, 81 insertions(+), 22 deletions(-) diff --git a/framework/src/main/java/cn/lili/modules/member/serviceimpl/FootprintServiceImpl.java b/framework/src/main/java/cn/lili/modules/member/serviceimpl/FootprintServiceImpl.java index 714157a..e995846 100644 --- a/framework/src/main/java/cn/lili/modules/member/serviceimpl/FootprintServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/member/serviceimpl/FootprintServiceImpl.java @@ -1,26 +1,34 @@ 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; @@ -37,23 +45,15 @@ @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; } @@ -68,7 +68,7 @@ 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); } @@ -78,7 +78,6 @@ 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); @@ -88,7 +87,7 @@ 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()); @@ -106,10 +105,70 @@ } @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); } -} \ No newline at end of file + + + +} + + -- Gitblit v1.8.0