Przeglądaj źródła

新增分页工具类、洞察明细接口

wangcl 3 tygodni temu
rodzic
commit
774560aa81
13 zmienionych plików z 415 dodań i 124 usunięć
  1. 10 1
      pig-statistics/pig-statistics-api/src/main/java/com/pig4cloud/pig/statistics/api/dto/uninstall/GetUninstallInsightDTO.java
  2. 9 1
      pig-statistics/pig-statistics-api/src/main/java/com/pig4cloud/pig/statistics/api/dto/uninstall/GetUninstallTrendDTO.java
  3. 9 0
      pig-statistics/pig-statistics-api/src/main/java/com/pig4cloud/pig/statistics/api/dto/uninstall/GetUninstallTrendDetailDTO.java
  4. 2 2
      pig-statistics/pig-statistics-api/src/main/java/com/pig4cloud/pig/statistics/api/entity/uninstall/MktDeviceAction.java
  5. 2 2
      pig-statistics/pig-statistics-api/src/main/java/com/pig4cloud/pig/statistics/api/entity/uninstall/MktDeviceCount.java
  6. 2 2
      pig-statistics/pig-statistics-api/src/main/java/com/pig4cloud/pig/statistics/api/entity/uninstall/MktDeviceInterfere.java
  7. 2 1
      pig-statistics/pig-statistics-api/src/main/java/com/pig4cloud/pig/statistics/api/vo/uninstall/UninstallBeforeActionVO.java
  8. 2 1
      pig-statistics/pig-statistics-api/src/main/java/com/pig4cloud/pig/statistics/api/vo/uninstall/UninstallBeforeInterfereVO.java
  9. 0 5
      pig-statistics/pig-statistics-api/src/main/java/com/pig4cloud/pig/statistics/api/vo/uninstall/UninstallBeforeVO.java
  10. 73 0
      pig-statistics/pig-statistics-biz/src/main/java/com/pig4cloud/pig/statistics/Util/PageUtils.java
  11. 12 0
      pig-statistics/pig-statistics-biz/src/main/java/com/pig4cloud/pig/statistics/controller/UninstallAnalyseController.java
  12. 10 0
      pig-statistics/pig-statistics-biz/src/main/java/com/pig4cloud/pig/statistics/service/UninstallAnalyseService.java
  13. 282 109
      pig-statistics/pig-statistics-biz/src/main/java/com/pig4cloud/pig/statistics/service/impl/UninstallAnalyseServiceImpl.java

+ 10 - 1
pig-statistics/pig-statistics-api/src/main/java/com/pig4cloud/pig/statistics/api/dto/uninstall/GetUninstallInsightDTO.java

@@ -15,6 +15,15 @@ public class GetUninstallInsightDTO {
 	@Schema(description = "周期(周/月)")
 	private String cycle;
 
-	@Schema(description = "类型(0-active 1-before)")
+	@Schema(description = "类型")
 	private String type;
+
+	@Schema(description = "appId")
+	private String appId;
+
+	@Schema(description = "渠道")
+	private String channel;
+
+	@Schema(description = "版本")
+	private String version;
 }

+ 9 - 1
pig-statistics/pig-statistics-api/src/main/java/com/pig4cloud/pig/statistics/api/dto/uninstall/GetUninstallTrendDTO.java

@@ -18,8 +18,16 @@ public class GetUninstallTrendDTO {
 	@Schema(description = "结束时间(yyyy-MM-dd),不传则默认为当前时间")
 	private String endDate;
 
-	
 	@Schema(description = "时间单位(day/week/month),不传则默认为day")
 	private String timeUnit;
+
+	@Schema(description = "appId")
+	private String appId;
+
+	@Schema(description = "渠道")
+	private String channel;
+
+	@Schema(description = "版本")
+	private String version;
 	
 }

+ 9 - 0
pig-statistics/pig-statistics-api/src/main/java/com/pig4cloud/pig/statistics/api/dto/uninstall/GetUninstallTrendDetailDTO.java

@@ -21,6 +21,15 @@ public class GetUninstallTrendDetailDTO {
 	@Schema(description = "时间单位(week/month)")
 	private String timeUnit;
 
+	@Schema(description = "appId")
+	private String appId;
+
+	@Schema(description = "渠道")
+	private String channel;
+
+	@Schema(description = "版本")
+	private String version;
+
 	@Schema(description = "页码")
 	private Integer pageNum;
 

+ 2 - 2
pig-statistics/pig-statistics-api/src/main/java/com/pig4cloud/pig/statistics/api/entity/uninstall/MktDeviceAction.java

@@ -20,8 +20,8 @@ public class MktDeviceAction {
     private String appId; // 应用ID
     private String channel; // 渠道
     private String appVersion; // 应用版本
-    private String actionType; // 操作类型
-    private String actionValue; // 操作值
+    private Integer actionType; // 操作类型
+    private Integer actionValue; // 操作值
     private Integer triggerCount; // 触发次数
     private String ext1;
     private String ext2;

+ 2 - 2
pig-statistics/pig-statistics-api/src/main/java/com/pig4cloud/pig/statistics/api/entity/uninstall/MktDeviceCount.java

@@ -20,8 +20,8 @@ public class MktDeviceCount {
     private String appId; // 应用ID
     private String channel; // 渠道
     private String appVersion; // 应用版本
-    private String type; // 分布类型
-    private String countRange; // 次数区间
+    private Integer type; // 分布类型
+    private Integer countRange; // 次数区间
     private Integer num; // 设备数/次数
     private Double rate; // 占比(%)
     private String ext1;

+ 2 - 2
pig-statistics/pig-statistics-api/src/main/java/com/pig4cloud/pig/statistics/api/entity/uninstall/MktDeviceInterfere.java

@@ -20,8 +20,8 @@ public class MktDeviceInterfere {
     private String appId; // 应用ID
     private String channel; // 渠道
     private String appVersion; // 应用版本
-    private String interfereType; // 干预类型
-    private String countRange; // 次数区间
+    private Integer interfereType; // 干预类型
+    private Integer countRange; // 次数区间
     private Integer num; // 次数
     private String ext1;
     private String ext2;

+ 2 - 1
pig-statistics/pig-statistics-api/src/main/java/com/pig4cloud/pig/statistics/api/vo/uninstall/UninstallBeforeActionVO.java

@@ -4,6 +4,7 @@ package com.pig4cloud.pig.statistics.api.vo.uninstall;
 import io.swagger.v3.oas.annotations.media.Schema;
 import lombok.Data;
 
+import java.util.List;
 import java.util.Map;
 
 /**
@@ -19,6 +20,6 @@ public class UninstallBeforeActionVO {
 	private String actionType;
 
 	@Schema(description = "值")
-	private Map<String, Integer> value;
+	private List<Map<String, Integer>> value;
 
 }

+ 2 - 1
pig-statistics/pig-statistics-api/src/main/java/com/pig4cloud/pig/statistics/api/vo/uninstall/UninstallBeforeInterfereVO.java

@@ -4,6 +4,7 @@ package com.pig4cloud.pig.statistics.api.vo.uninstall;
 import io.swagger.v3.oas.annotations.media.Schema;
 import lombok.Data;
 
+import java.util.List;
 import java.util.Map;
 
 /**
@@ -19,5 +20,5 @@ public class UninstallBeforeInterfereVO {
 	private String type;
 
 	@Schema(description = "值")
-	private Map<String, Integer> value;
+	private List<Map<String, Integer>> value;
 }

+ 0 - 5
pig-statistics/pig-statistics-api/src/main/java/com/pig4cloud/pig/statistics/api/vo/uninstall/UninstallBeforeVO.java

@@ -21,9 +21,4 @@ public class UninstallBeforeVO {
 	@Schema(description = "卸载前7天使用次数分布")
 	private List<UninstallBeforeSevenVO> uninstallBeforeSevens;
 
-	@Schema(description = "卸载前干扰指标")
-	private List<UninstallBeforeInterfereVO> uninstallBeforeInterferences;
-
-	@Schema(description = "卸载前行为还原")
-	private List<UninstallBeforeActionVO> uninstallBeforeActions;
 }

+ 73 - 0
pig-statistics/pig-statistics-biz/src/main/java/com/pig4cloud/pig/statistics/Util/PageUtils.java

@@ -0,0 +1,73 @@
+package com.pig4cloud.pig.statistics.Util;
+
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * 分页工具类
+ * @author wcl
+ * @date 2025/8/20 15:00
+ * @description: 分页工具类,提供通用的分页逻辑处理
+ */
+public class PageUtils {
+
+    /**
+     * 构建分页结果
+     * @param data 原始数据列表
+     * @param pageNum 页码
+     * @param pageSize 每页大小
+     * @param <T> 数据类型
+     * @return 分页结果
+     */
+    public static <T> Page<T> buildPage(List<T> data, Integer pageNum, Integer pageSize) {
+        int currentPage = pageNum == null ? 1 : pageNum;
+        int size = pageSize == null ? 10 : pageSize;
+        
+        // 如果pageSize超过数据总量,则返回所有数据
+        if (size >= data.size()) {
+            Page<T> page = new Page<>();
+            page.setCurrent(1);
+            page.setSize(data.size());
+            page.setTotal(data.size());
+            page.setPages(1);
+            page.setRecords(data);
+            return page;
+        }
+        
+        // 确保页码在有效范围内
+        int totalPages = (data.size() + size - 1) / size;
+        if (currentPage > totalPages && totalPages > 0) {
+            currentPage = totalPages;
+        }
+        if (currentPage < 1) {
+            currentPage = 1;
+        }
+        
+        // 计算分页索引
+        int fromIndex = (currentPage - 1) * size;
+        int toIndex = Math.min(fromIndex + size, data.size());
+        List<T> pageRecords = fromIndex < data.size() ? data.subList(fromIndex, toIndex) : Collections.emptyList();
+        
+        // 构建分页结果
+        Page<T> page = new Page<>();
+        page.setCurrent(currentPage);
+        page.setSize(size);
+        page.setTotal(data.size());
+        page.setPages(totalPages);
+        page.setRecords(pageRecords);
+        
+        return page;
+    }
+    
+    /**
+     * 构建分页结果(重载方法,支持默认分页参数)
+     * @param data 原始数据列表
+     * @param <T> 数据类型
+     * @return 分页结果(默认第1页,每页10条)
+     */
+    public static <T> Page<T> buildPage(List<T> data) {
+        return buildPage(data, 1, 10);
+    }
+} 

+ 12 - 0
pig-statistics/pig-statistics-biz/src/main/java/com/pig4cloud/pig/statistics/controller/UninstallAnalyseController.java

@@ -52,6 +52,18 @@ public class UninstallAnalyseController {
 		return R.ok(uninstallAnalyseService.uninstallBefore(dto));
 	}
 
+	@PostMapping("/uninstallInterfere")
+	@Operation(summary = "卸载洞察-体验干扰")
+	public R<UninstallBeforeInterfereVO> uninstallInterfere(@RequestBody GetUninstallInsightDTO dto) {
+		return R.ok(uninstallAnalyseService.uninstallInterfere(dto));
+	}
+
+	@PostMapping("/uninstallAction")
+	@Operation(summary = "卸载洞察-行为还原")
+	public R<UninstallBeforeActionVO> uninstallAction(@RequestBody GetUninstallInsightDTO dto) {
+		return R.ok(uninstallAnalyseService.uninstallAction(dto));
+	}
+
 	@PostMapping("/uninstallAfter")
 	@Operation(summary = "卸载洞察-卸载后流失")
 	public R<List<UninstallOfterAPPOV>> uninstallAfter(@RequestBody GetUninstallInsightDTO dto) {

+ 10 - 0
pig-statistics/pig-statistics-biz/src/main/java/com/pig4cloud/pig/statistics/service/UninstallAnalyseService.java

@@ -39,6 +39,16 @@ public interface UninstallAnalyseService {
 	 */
 	UninstallBeforeVO uninstallBefore(GetUninstallInsightDTO dto);
 
+	/**
+	 * 体验干扰
+	 */
+	UninstallBeforeInterfereVO uninstallInterfere(GetUninstallInsightDTO dto);
+
+	/**
+	 * 行为还原
+	 */
+	UninstallBeforeActionVO uninstallAction(GetUninstallInsightDTO dto);
+
 	/**
 	 * 卸载后流失
 	 */

+ 282 - 109
pig-statistics/pig-statistics-biz/src/main/java/com/pig4cloud/pig/statistics/service/impl/UninstallAnalyseServiceImpl.java

@@ -3,6 +3,7 @@ package com.pig4cloud.pig.statistics.service.impl;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.pig4cloud.pig.statistics.Util.ConfigUtils;
+import com.pig4cloud.pig.statistics.Util.PageUtils;
 import com.pig4cloud.pig.statistics.api.dto.uninstall.*;
 import com.pig4cloud.pig.statistics.api.entity.ConfigItem;
 import com.pig4cloud.pig.statistics.api.entity.uninstall.*;
@@ -10,13 +11,15 @@ import com.pig4cloud.pig.statistics.api.vo.uninstall.*;
 import com.pig4cloud.pig.statistics.mapper.*;
 import com.pig4cloud.pig.statistics.service.UninstallAnalyseService;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import java.time.DayOfWeek;
 import java.time.LocalDate;
-import java.time.format.DateTimeFormatter;
+import java.time.temporal.TemporalAdjusters;
 import java.util.*;
+import java.util.stream.Collectors;
 
 /**
  * @author: wcl
@@ -42,104 +45,171 @@ public class UninstallAnalyseServiceImpl implements UninstallAnalyseService {
 
     @Override
     public UninstallTrendVO getUninstallTrend(GetUninstallTrendDTO dto) {
-		LocalDate startDate, endDate;
-		if (dto.getStartDate() == null) {
-			LocalDate now = LocalDate.now();
-			startDate = now.minusWeeks(1).with(DayOfWeek.MONDAY);
-			endDate = now.minusWeeks(1).with(DayOfWeek.SUNDAY);
-		} else {
-			startDate = LocalDate.parse(dto.getStartDate());
-			endDate = dto.getEndDate() != null ? LocalDate.parse(dto.getEndDate()) : startDate;
-		}
-
+        LocalDate startDate, endDate;
+        String timeUnit = dto.getTimeUnit() == null ? "week" : dto.getTimeUnit();
+        LocalDate now = LocalDate.now();
+        if ("week".equalsIgnoreCase(timeUnit)) {
+            if (now.getDayOfWeek().getValue() < DayOfWeek.THURSDAY.getValue()) {
+                startDate = now.minusWeeks(2).with(DayOfWeek.MONDAY);
+                endDate = now.minusWeeks(2).with(DayOfWeek.SUNDAY);
+            } else {
+                startDate = now.minusWeeks(1).with(DayOfWeek.MONDAY);
+                endDate = now.minusWeeks(1).with(DayOfWeek.SUNDAY);
+            }
+        } else if ("month".equalsIgnoreCase(timeUnit)) {
+            if (now.getDayOfMonth() < 4) {
+                LocalDate lastMonth = now.minusMonths(2);
+                startDate = lastMonth.withDayOfMonth(1);
+                endDate = lastMonth.with(TemporalAdjusters.lastDayOfMonth());
+            } else {
+                LocalDate lastMonth = now.minusMonths(1);
+                startDate = lastMonth.withDayOfMonth(1);
+                endDate = lastMonth.with(TemporalAdjusters.lastDayOfMonth());
+            }
+        } else {
+            startDate = now;
+            endDate = now;
+        }
+        // 支持前端传参覆盖
+        if (!StringUtils.isEmpty(dto.getStartDate())) {
+            startDate = LocalDate.parse(dto.getStartDate());
+        }
+        if (!StringUtils.isEmpty(dto.getEndDate())) {
+            endDate = LocalDate.parse(dto.getEndDate());
+        }
         QueryWrapper<MktTrendSummary> wrapper = new QueryWrapper<>();
         wrapper.between("stat_date", startDate, endDate);
+        if (!StringUtils.isEmpty(dto.getAppId())) {
+            wrapper.eq("app_id", dto.getAppId());
+        }
+        if (!StringUtils.isEmpty(dto.getChannel())) {
+            wrapper.eq("channel", dto.getChannel());
+        }
+        if (!StringUtils.isEmpty(dto.getVersion())) {
+            wrapper.eq("app_version", dto.getVersion());
+        }
+        wrapper.eq("stat_cycle", timeUnit);
         List<MktTrendSummary> list = mktTrendSummaryMapper.selectList(wrapper);
-        UninstallTrendVO vo = new UninstallTrendVO();
-        if (!list.isEmpty()) {
-            // 这里只取第一个,实际可按业务聚合
-            MktTrendSummary summary = list.get(0);
-            vo.setStartDate(summary.getStatDate() != null ? summary.getStatDate().toString() : null);
-            vo.setUninstallCounts(summary.getCount());
-            vo.setUninstallRates(summary.getRate());
-            // 其他字段可根据VO结构补充
+
+		UninstallTrendVO vo = new UninstallTrendVO();
+
+        int uninstallCount = 0, recallCount = 0;
+		Double uninstallRate = 0.0, recallRate = 0.0;
+        if (list != null && !list.isEmpty()) {
+			for (MktTrendSummary summary : list) {
+				if (summary.getTrendType() != null) {
+					// 卸载
+					if (summary.getTrendType() == 0) {
+						uninstallCount += summary.getCount();
+						uninstallRate += summary.getRate();
+					}
+					// 召回
+					else if (summary.getTrendType() == 1) {
+						recallCount += summary.getCount();
+						recallRate += summary.getRate();
+					}
+				}
+			}
         }
+		vo.setStartDate(String.valueOf(startDate));
+		vo.setEndDate(String.valueOf(endDate));
+        vo.setUninstallCounts(uninstallCount);
+        vo.setRecallCounts(recallCount);
+		vo.setUninstallRates(uninstallRate);
+		vo.setRecallRates(recallRate);
+
         return vo;
     }
 
     @Override
     public Page<UninstallTrendDtlVO> getUninstallTrendDetail(GetUninstallTrendDetailDTO dto) {
-        // 假设dto有pageNum和pageSize字段
+        // 分页参数
         int pageNum = dto.getPageNum() == null ? 1 : dto.getPageNum();
         int pageSize = dto.getPageSize() == null ? 10 : dto.getPageSize();
-        Page<MktTrendSummary> page = new Page<>(pageNum, pageSize);
+
+        String timeUnit = StringUtils.isEmpty(dto.getTimeUnit()) ? "week" : dto.getTimeUnit();
         QueryWrapper<MktTrendSummary> wrapper = new QueryWrapper<>();
-        wrapper.eq("stat_date", dto.getStartDate());
-        Page<MktTrendSummary> entityPage = mktTrendSummaryMapper.selectPage(page, wrapper);
-        Page<UninstallTrendDtlVO> voPage = new Page<>();
-        voPage.setCurrent(entityPage.getCurrent());
-        voPage.setSize(entityPage.getSize());
-        voPage.setTotal(entityPage.getTotal());
-        voPage.setPages(entityPage.getPages());
-        List<UninstallTrendDtlVO> voList = new ArrayList<>();
-        for (MktTrendSummary summary : entityPage.getRecords()) {
-            UninstallTrendDtlVO vo = new UninstallTrendDtlVO();
-            vo.setStartDate(summary.getStatDate() != null ? summary.getStatDate().toString() : null);
-            vo.setUninstallCounts(summary.getCount());
-            // 其他字段可根据VO结构补充
-            voList.add(vo);
+
+        if (!StringUtils.isEmpty(dto.getAppId())) {
+            wrapper.eq("app_id", dto.getAppId());
         }
-        voPage.setRecords(voList);
-        return voPage;
+        if (!StringUtils.isEmpty(dto.getChannel())) {
+            wrapper.eq("channel", dto.getChannel());
+        }
+        if (!StringUtils.isEmpty(dto.getVersion())) {
+            wrapper.eq("app_version", dto.getVersion());
+        }
+        wrapper.eq("stat_cycle", timeUnit);
+        
+        List<MktTrendSummary> list = mktTrendSummaryMapper.selectList(wrapper);
+        log.info("查询结果数量: {}", list.size());
+        
+        // 使用Stream API优化分组和统计逻辑
+        List<UninstallTrendDtlVO> voList = new ArrayList<>(list.stream()
+				.collect(Collectors.groupingBy(
+						summary -> getCycleKey(summary.getStatDate(), timeUnit),
+						TreeMap::new,
+						Collectors.collectingAndThen(
+								Collectors.toList(),
+								summaries -> buildUninstallTrendDtlVO(summaries, timeUnit)
+						)
+				))
+				.values());
+        
+        log.info("分页参数: pageNum={}, pageSize={}, voList.size={}", pageNum, pageSize, voList.size());
+        
+        // 使用PageUtils工具类处理分页
+        return PageUtils.buildPage(voList, pageNum, pageSize);
+    }
+    
+    /**
+     * 获取周期分组key
+     */
+    private String getCycleKey(Date statDate, String timeUnit) {
+        LocalDate date = statDate.toInstant().atZone(java.time.ZoneId.systemDefault()).toLocalDate();
+        if ("week".equalsIgnoreCase(timeUnit)) {
+            return date.with(DayOfWeek.MONDAY).toString();
+        } else if ("month".equalsIgnoreCase(timeUnit)) {
+            return date.withDayOfMonth(1).toString();
+        } else {
+            return date.toString();
+        }
+    }
+    
+    /**
+     * 构建卸载趋势明细VO
+     */
+    private UninstallTrendDtlVO buildUninstallTrendDtlVO(List<MktTrendSummary> summaries, String timeUnit) {
+        LocalDate start = LocalDate.parse(getCycleKey(summaries.get(0).getStatDate(), timeUnit));
+        LocalDate end;
+        
+        if ("week".equalsIgnoreCase(timeUnit)) {
+            end = start.with(DayOfWeek.SUNDAY);
+        } else if ("month".equalsIgnoreCase(timeUnit)) {
+            end = start.with(TemporalAdjusters.lastDayOfMonth());
+        } else {
+            end = start;
+        }
+        
+        // 使用Stream API统计数据
+        int uninstallCount = summaries.stream()
+            .filter(summary -> summary.getTrendType() != null && summary.getTrendType() == 0)
+            .mapToInt(MktTrendSummary::getCount)
+            .sum();
+            
+        int recallCount = summaries.stream()
+            .filter(summary -> summary.getTrendType() != null && summary.getTrendType() == 1)
+            .mapToInt(MktTrendSummary::getCount)
+            .sum();
+        
+        UninstallTrendDtlVO vo = new UninstallTrendDtlVO();
+        vo.setStartDate(start.toString());
+        vo.setEndDate(end.toString());
+        vo.setUninstallCounts(uninstallCount);
+        vo.setRecallCounts(recallCount);
+        
+        return vo;
     }
-
-	private int generateRandomCount(int min, int max) {
-		return new Random().nextInt(max - min + 1) + min;
-	}
-
-	/**
-	 * 生成时间点列表
-	 */
-	private List<String> generateTimePoints(String startDate, String endDate, String timeUnit) {
-		List<String> timePoints = new ArrayList<>();
-		DateTimeFormatter formatter;
-		int stepDays;
-		
-		switch (timeUnit) {
-			case "day":
-				formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
-				stepDays = 1;
-				break;
-			case "week":
-				formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
-				stepDays = 7;
-				break;
-			case "month":
-				formatter = DateTimeFormatter.ofPattern("yyyy-MM");
-				stepDays = 30; // 简化处理
-				break;
-			default:
-				throw new IllegalArgumentException("不支持的timeUnit: " + timeUnit);
-		}
-		
-		LocalDate start = LocalDate.parse(startDate);
-		LocalDate end = LocalDate.parse(endDate);
-		
-		LocalDate current = start;
-		while (!current.isAfter(end)) {
-			timePoints.add(current.format(formatter));
-			current = current.plusDays(stepDays);
-		}
-		
-		return timePoints;
-	}
-
-	/**
-	 * 计算比率列表
-	 */
-	private Double calculateRates(Integer numerators, int denominator) {
-		return (double)numerators / denominator * 100;
-	}
 
 	@Override
 	public UninstallInsightVO getUninstallDeviceActive(GetUninstallInsightDTO dto) {
@@ -147,8 +217,17 @@ public class UninstallAnalyseServiceImpl implements UninstallAnalyseService {
 	}
 
 	public UninstallInsightVO getUninstallDeviceActiveVO(GetUninstallInsightDTO dto) {
+
+		Map<String, LocalDate> timeRangeMap = getTimeRangeMap(StringUtils.isEmpty(dto.getType()) ? "week" : dto.getType());
 		QueryWrapper<MktDeviceTime> wrapper = new QueryWrapper<>();
 		wrapper.eq("type", dto.getType());
+		// 添加时间范围查询
+		wrapper.between("stat_date", timeRangeMap.get("startDate"), timeRangeMap.get("endDate"));
+		// 动态添加其他查询条件
+		if (!StringUtils.isEmpty(dto.getAppId())) wrapper.eq("app_id", dto.getAppId());
+		if (!StringUtils.isEmpty(dto.getChannel())) wrapper.eq("channel", dto.getChannel());
+		if (!StringUtils.isEmpty(dto.getVersion())) wrapper.eq("app_version", dto.getVersion());
+		
 		List<MktDeviceTime> list = mktDeviceTimeMapper.selectList(wrapper);
 		List<InstallStockVO> voList = new ArrayList<>();
 		for (MktDeviceTime entity : list) {
@@ -164,11 +243,57 @@ public class UninstallAnalyseServiceImpl implements UninstallAnalyseService {
 		return result;
 	}
 
+	private Map<String, LocalDate> getTimeRangeMap(String timeUnit) {
+
+		Map<String, LocalDate> timeRangeMap = new HashMap<>();
+		// 根据当前日期计算查询时间范围
+		LocalDate now = LocalDate.now();
+		LocalDate startDate, endDate;
+		if (StringUtils.isEmpty(timeUnit)) timeUnit = "week";
+
+		if ("week".equalsIgnoreCase(timeUnit)) {
+			// 默认查上周:本周一~三查上上周,本周四~日查上周
+			if (now.getDayOfWeek().getValue() < DayOfWeek.THURSDAY.getValue()) {
+				startDate = now.minusWeeks(2).with(DayOfWeek.MONDAY);
+				endDate = now.minusWeeks(2).with(DayOfWeek.SUNDAY);
+			} else {
+				startDate = now.minusWeeks(1).with(DayOfWeek.MONDAY);
+				endDate = now.minusWeeks(1).with(DayOfWeek.SUNDAY);
+			}
+		} else if ("month".equalsIgnoreCase(timeUnit)) {
+			// 查上月:本月1-3号查上上月,本月4号及以后查上月
+			if (now.getDayOfMonth() < 4) {
+				LocalDate lastMonth = now.minusMonths(2);
+				startDate = lastMonth.withDayOfMonth(1);
+				endDate = lastMonth.with(TemporalAdjusters.lastDayOfMonth());
+			} else {
+				LocalDate lastMonth = now.minusMonths(1);
+				startDate = lastMonth.withDayOfMonth(1);
+				endDate = lastMonth.with(TemporalAdjusters.lastDayOfMonth());
+			}
+		} else {
+			// 默认查上周
+			if (now.getDayOfWeek().getValue() < DayOfWeek.THURSDAY.getValue()) {
+				startDate = now.minusWeeks(2).with(DayOfWeek.MONDAY);
+				endDate = now.minusWeeks(2).with(DayOfWeek.SUNDAY);
+			} else {
+				startDate = now.minusWeeks(1).with(DayOfWeek.MONDAY);
+				endDate = now.minusWeeks(1).with(DayOfWeek.SUNDAY);
+			}
+		}
+		timeRangeMap.put("startDate", startDate);
+		timeRangeMap.put("endDate", endDate);
+		return timeRangeMap;
+	}
+
 	@Override
 	public UninstallBeforeVO uninstallBefore(GetUninstallInsightDTO dto) {
 		// 1. 卸载时间差分布
 		QueryWrapper<MktDeviceTime> timeWrapper = new QueryWrapper<>();
 		timeWrapper.eq("type", dto.getType());
+		if (!StringUtils.isEmpty(dto.getAppId())) timeWrapper.eq("app_id", dto.getAppId());
+		if (!StringUtils.isEmpty(dto.getChannel())) timeWrapper.eq("channel", dto.getChannel());
+		if (!StringUtils.isEmpty(dto.getVersion())) timeWrapper.eq("app_version", dto.getVersion());
 		List<MktDeviceTime> timeList = mktDeviceTimeMapper.selectList(timeWrapper);
 		List<UninstallTimeDiffVO> timeDiffs = new ArrayList<>();
 		for (MktDeviceTime entity : timeList) {
@@ -182,53 +307,101 @@ public class UninstallAnalyseServiceImpl implements UninstallAnalyseService {
 		// 2. 卸载前7天使用次数分布
 		QueryWrapper<MktDeviceCount> countWrapper = new QueryWrapper<>();
 		countWrapper.eq("type", dto.getType());
+		if (!StringUtils.isEmpty(dto.getAppId())) countWrapper.eq("app_id", dto.getAppId());
+		if (!StringUtils.isEmpty(dto.getChannel())) countWrapper.eq("channel", dto.getChannel());
+		if (!StringUtils.isEmpty(dto.getVersion())) countWrapper.eq("app_version", dto.getVersion());
 		List<MktDeviceCount> countList = mktDeviceCountMapper.selectList(countWrapper);
 		List<UninstallBeforeSevenVO> beforeSevens = new ArrayList<>();
 		for (MktDeviceCount entity : countList) {
 			UninstallBeforeSevenVO vo = new UninstallBeforeSevenVO();
-			ConfigItem configValue = ConfigUtils.getConfigValue("Count_range", entity.getCountRange());
+			ConfigItem configValue = ConfigUtils.getConfigValue("Count_range", String.valueOf(entity.getCountRange()));
 
 			vo.setTime(configValue.getLabel());
 			vo.setCount(entity.getNum());
 			vo.setRate(entity.getRate());
 			beforeSevens.add(vo);
 		}
+
+
+		UninstallBeforeVO result = new UninstallBeforeVO();
+		result.setUninstallTimeDiffs(timeDiffs);
+		result.setUninstallBeforeSevens(beforeSevens);
+		return result;
+	}
+
+	/**
+	 * 体验干扰
+	 *
+	 * @param dto
+	 */
+	@Override
+	public UninstallBeforeInterfereVO uninstallInterfere(GetUninstallInsightDTO dto) {
+
+		UninstallBeforeInterfereVO result = new UninstallBeforeInterfereVO();
+		ConfigItem configValue = null;
+		if (!StringUtils.isEmpty(dto.getType())){
+			configValue = ConfigUtils.getConfigValue("Interfere_type", dto.getType());
+		}
+		List<Map<String, Integer>> value = new ArrayList<>();
 		// 3. 卸载前干扰指标
 		QueryWrapper<MktDeviceInterfere> interfereWrapper = new QueryWrapper<>();
+		interfereWrapper.eq("interfere_type", dto.getType());
+		if (!StringUtils.isEmpty(dto.getAppId())) interfereWrapper.eq("app_id", dto.getAppId());
+		if (!StringUtils.isEmpty(dto.getChannel())) interfereWrapper.eq("channel", dto.getChannel());
+		if (!StringUtils.isEmpty(dto.getVersion())) interfereWrapper.eq("app_version", dto.getVersion());
 		List<MktDeviceInterfere> interfereList = mktDeviceInterfereMapper.selectList(interfereWrapper);
 		Map<String, Map<String, Integer>> interfereMap = new LinkedHashMap<>();
 		for (MktDeviceInterfere entity : interfereList) {
-			ConfigItem configValue = ConfigUtils.getConfigValue("Count_range", entity.getCountRange());
-			interfereMap.computeIfAbsent(entity.getInterfereType(), k -> new LinkedHashMap<>())
-				.put(configValue.getLabel(), entity.getNum());
+			Map<String, Integer> map = new HashMap<>();
+			ConfigItem countValue = ConfigUtils.getConfigValue("Count_range", String.valueOf(entity.getCountRange()));
+			map.put(countValue.getLabel(), entity.getNum());
+			value.add(map);
+		}
+		if (configValue != null) {
+			result.setType(configValue.getLabel());
+		}else {
+			result.setType("");
 		}
-		List<UninstallBeforeInterfereVO> interfereVOList = new ArrayList<>();
-		for (Map.Entry<String, Map<String, Integer>> entry : interfereMap.entrySet()) {
-			UninstallBeforeInterfereVO vo = new UninstallBeforeInterfereVO();
-			vo.setType(entry.getKey());
-			vo.setValue(entry.getValue());
-			interfereVOList.add(vo);
+		result.setValue(value);
+		return result;
+	}
+
+	/**
+	 * 行为还原
+	 *
+	 * @param dto
+	 */
+	@Override
+	public UninstallBeforeActionVO uninstallAction(GetUninstallInsightDTO dto) {
+
+		UninstallBeforeActionVO result = new UninstallBeforeActionVO();
+		ConfigItem configValue = null;
+		if (!StringUtils.isEmpty(dto.getType())){
+			configValue = ConfigUtils.getConfigValue("Action_type", dto.getType());
 		}
 		// 4. 卸载前行为还原
 		QueryWrapper<MktDeviceAction> actionWrapper = new QueryWrapper<>();
+		actionWrapper.eq("actionType", dto.getType());
+		if (!StringUtils.isEmpty(dto.getAppId())) actionWrapper.eq("app_id", dto.getAppId());
+		if (!StringUtils.isEmpty(dto.getChannel())) actionWrapper.eq("channel", dto.getChannel());
+		if (!StringUtils.isEmpty(dto.getVersion())) actionWrapper.eq("app_version", dto.getVersion());
 		List<MktDeviceAction> actionList = mktDeviceActionMapper.selectList(actionWrapper);
-		Map<String, Map<String, Integer>> actionMap = new LinkedHashMap<>();
+		List<Map<String, Integer>> list = new ArrayList<>();
 		for (MktDeviceAction entity : actionList) {
-			actionMap.computeIfAbsent(entity.getActionType(), k -> new LinkedHashMap<>())
-				.put(entity.getActionValue(), entity.getTriggerCount());
+			Map<String, Integer> map = new HashMap<>();
+			ConfigItem actionType = ConfigUtils.getConfigValue("Action_type", String.valueOf(entity.getActionType()));
+			map.put(actionType.getLabel(), entity.getTriggerCount());
+
+			list.add(map);
 		}
-		List<UninstallBeforeActionVO> actionVOList = new ArrayList<>();
-		for (Map.Entry<String, Map<String, Integer>> entry : actionMap.entrySet()) {
-			UninstallBeforeActionVO vo = new UninstallBeforeActionVO();
-			vo.setActionType(entry.getKey());
-			vo.setValue(entry.getValue());
-			actionVOList.add(vo);
+		result.setValue(list);
+
+		if (configValue != null) {
+			result.setActionType(configValue.getLabel());
+		}else {
+			result.setActionType("");
 		}
-		UninstallBeforeVO result = new UninstallBeforeVO();
-		result.setUninstallTimeDiffs(timeDiffs);
-		result.setUninstallBeforeSevens(beforeSevens);
-		result.setUninstallBeforeInterferences(interfereVOList);
-		result.setUninstallBeforeActions(actionVOList);
+
 		return result;
 	}