From 672637fa4a4914ec9667cb15f70b67482b8a0e5e Mon Sep 17 00:00:00 2001
From: peng <peng.com>
Date: 星期四, 25 九月 2025 17:16:42 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/send_coupon' into user_action

---
 framework/src/main/java/cn/lili/modules/member/serviceimpl/FootprintServiceImpl.java |  226 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 221 insertions(+), 5 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 595e162..384a3ce 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
@@ -2,26 +2,33 @@
 
 import cn.lili.base.Result;
 import cn.lili.common.security.context.UserContext;
+import cn.lili.common.utils.StringUtils;
 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.*;
+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.modules.statistics.entity.dto.StatisticsQueryParam;
 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.text.SimpleDateFormat;
+import java.util.*;
 import java.util.stream.Collectors;
 import java.util.stream.IntStream;
 
@@ -37,6 +44,12 @@
 
     @Autowired
     private GoodsSkuService goodsSkuService;
+
+    @Autowired
+    private VideoMapper videoMapper;
+
+    @Autowired
+    private COSUtil cOSUtil;
 
     @Override
     public FootPrint saveFootprint(FootPrint footPrint) {
@@ -66,7 +79,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);
@@ -94,6 +106,61 @@
     }
 
     @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());
@@ -101,4 +168,153 @@
         return this.count(lambdaQueryWrapper);
     }
 
+    @Override
+    public Result getViewAndCompletionRateCount(StatisticsQueryParam queryParam) {
+        Date startTime = null;
+        Date endTime = new Date(); // 缁撴潫鏃堕棿榛樿鏄綋鍓嶆椂闂�
+        List<String> dateList = new ArrayList<>();
+
+        Calendar calendar = Calendar.getInstance(); // 鐢ㄤ簬鏃ユ湡璁$畻鐨勬棩鍘嗗疄渚�
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+        int days = 0;
+        switch (queryParam.getSearchType()) {
+            case "TODAY":
+                // 浠婂ぉ锛氫粠浠婂ぉ0鐐瑰埌鐜板湪
+                calendar.setTime(new Date()); // 閲嶇疆涓哄綋鍓嶆椂闂�
+                calendar.set(Calendar.HOUR_OF_DAY, 0); // 灏忔椂璁句负0锛�24灏忔椂鍒讹級
+                calendar.set(Calendar.MINUTE, 0);      // 鍒嗛挓璁句负0
+                calendar.set(Calendar.SECOND, 0);      // 绉掕涓�0
+                calendar.set(Calendar.MILLISECOND, 0); // 姣璁句负0
+                startTime = calendar.getTime();        // 寰楀埌浠婂ぉ0鐐圭殑Date瀵硅薄
+                dateList.add(sdf.format(startTime));
+                break;
+            case "YESTERDAY":
+                // 鏄ㄥぉ锛氫粠鏄ㄥぉ0鐐瑰埌鏄ㄥぉ23:59:59.999
+                calendar.setTime(new Date());
+                calendar.add(Calendar.DATE, -1); // 鏃ユ湡鍑�1澶╋紙鍙樹负鏄ㄥぉ锛�
+
+                // 璁剧疆鏄ㄥぉ0鐐�
+                calendar.set(Calendar.HOUR_OF_DAY, 0);
+                calendar.set(Calendar.MINUTE, 0);
+                calendar.set(Calendar.SECOND, 0);
+                calendar.set(Calendar.MILLISECOND, 0);
+                startTime = calendar.getTime();
+
+                // 璁剧疆鏄ㄥぉ23:59:59.999
+                calendar.set(Calendar.HOUR_OF_DAY, 23);
+                calendar.set(Calendar.MINUTE, 59);
+                calendar.set(Calendar.SECOND, 59);
+                calendar.set(Calendar.MILLISECOND, 999);
+                endTime = calendar.getTime();
+
+                dateList.add(sdf.format(startTime));
+                break;
+            case "LAST_SEVEN":
+                // 杩囧幓涓冨ぉ锛氫粠7澶╁墠0鐐瑰埌鐜板湪锛堝惈浠婂ぉ鍏�7澶╋級
+                calendar.setTime(new Date());
+                calendar.add(Calendar.DATE, -6); // 鏃ユ湡鍑�6澶╋紙7澶╁墠鐨勪粖澶╋級
+
+                // 璁剧疆7澶╁墠0鐐�
+                calendar.set(Calendar.HOUR_OF_DAY, 0);
+                calendar.set(Calendar.MINUTE, 0);
+                calendar.set(Calendar.SECOND, 0);
+                calendar.set(Calendar.MILLISECOND, 0);
+                startTime = calendar.getTime();
+
+                days = 7;
+                // 寰幆鐢熸垚7澶╃殑鏃ユ湡瀛楃涓�
+                Calendar tempCalendar = Calendar.getInstance();
+                tempCalendar.setTime(startTime);
+                for (int i = 0; i < days; i++) {
+                    dateList.add(sdf.format(tempCalendar.getTime()));
+                    tempCalendar.add(Calendar.DATE, 1); // 姣忓ぉ绱姞1澶�
+                }
+                break;
+            case "LAST_THIRTY":
+                // 杩囧幓30澶╋細浠�30澶╁墠0鐐瑰埌鐜板湪锛堝惈浠婂ぉ鍏�30澶╋級
+                calendar.setTime(new Date());
+                calendar.add(Calendar.DATE, -29); // 鏃ユ湡鍑�29澶╋紙30澶╁墠鐨勪粖澶╋級
+
+                // 璁剧疆30澶╁墠0鐐�
+                calendar.set(Calendar.HOUR_OF_DAY, 0);
+                calendar.set(Calendar.MINUTE, 0);
+                calendar.set(Calendar.SECOND, 0);
+                calendar.set(Calendar.MILLISECOND, 0);
+                startTime = calendar.getTime();
+
+                days = 30;
+                // 寰幆鐢熸垚30澶╃殑鏃ユ湡瀛楃涓�
+                Calendar tempCalendar30 = Calendar.getInstance();
+                tempCalendar30.setTime(startTime);
+                for (int i = 0; i < days; i++) {
+                    dateList.add(sdf.format(tempCalendar30.getTime()));
+                    tempCalendar30.add(Calendar.DATE, 1); // 姣忓ぉ绱姞1澶�
+                }
+                break;
+            default:
+                return Result.error("涓嶆敮鎸佺殑鏃堕棿鑼冨洿绫诲瀷");
+        }
+        if ("goods".equals(queryParam.getCurrentType())){
+            List<Map<String, Object>> maps = baseMapper.selectViewAndCompletionRateCountByDay(startTime, endTime,queryParam.getCurrentLimit());
+            Map<String,Long> viewPrintMap = maps.stream()
+                    .collect(Collectors.toMap(
+                            map -> {
+                                String goodsId = Objects.toString(map.get("GoodsId"), ""); // 绌哄�煎鐞�
+                                String goodsName = Objects.toString(map.get("GoodsName"), ""); // 绌哄�煎鐞�
+                                return goodsName + " | " + goodsId; // 鐢▅鍒嗛殧锛屾柟渚垮悗缁媶鍒�
+                            },
+                            map-> Long.valueOf(map.get("view_count").toString()),
+                            (existing, replacement) -> existing,
+                            LinkedHashMap::new  // 鎸囧畾浣跨敤 LinkedHashMap锛屼繚鐣欐彃鍏ラ『搴�
+                    ));
+            List<String> yData = new ArrayList<>();
+            List<Long> xData = new ArrayList<>();
+
+            for (Map.Entry<String, Long> entry : viewPrintMap.entrySet()){
+                yData.add(entry.getKey());
+                xData.add(entry.getValue());
+            }
+            Map<String,Object> data = new HashMap<>();
+            data.put("yData", yData);
+            data.put("xData", xData);
+            return Result.ok().data(data);
+        }else{
+            List<Map<String, Object>> maps = baseMapper.selectEachVideoStats(startTime, endTime,queryParam.getCurrentLimit());
+            Map<String, VideoViewCompletionRateVO> viewPrintMap = maps.stream()
+                    .collect(Collectors.toMap(
+                            map -> {
+                                String videoId = Objects.toString(map.get("video_id"), ""); // 绌哄�煎鐞�
+                                String videoName = Objects.toString(map.get("title"), ""); // 绌哄�煎鐞�
+                                return videoName + " | " + videoId; // 鐢▅鍒嗛殧锛屾柟渚垮悗缁媶鍒�
+                            },
+                            map-> {
+                                VideoViewCompletionRateVO vo = new VideoViewCompletionRateVO();
+                                vo.setTotal_views(Long.valueOf(map.get("total_views").toString()));
+                                vo.setComplete_rate(map.get("complete_rate").toString());
+                                return vo;
+                            },
+                            (existing, replacement) -> existing,
+                            LinkedHashMap::new  // 鎸囧畾浣跨敤 LinkedHashMap锛屼繚鐣欐彃鍏ラ『搴�
+                    ));
+            List<String> yData = new ArrayList<>();
+            List<Long> xData = new ArrayList<>();
+            List<String> rateData = new ArrayList<>();
+
+            for (Map.Entry<String, VideoViewCompletionRateVO> entry : viewPrintMap.entrySet()){
+                yData.add(entry.getKey());
+                xData.add(entry.getValue().getTotal_views());
+                rateData.add(entry.getValue().getComplete_rate());
+            }
+            Map<String,Object> data = new HashMap<>();
+            data.put("yData", yData);
+            data.put("xData", xData);
+            data.put("rateData", rateData);
+            return Result.ok().data(data);
+        }
+
+    }
+
+
 }
+
+

--
Gitblit v1.8.0