Sfoglia il codice sorgente

修改查询逻辑

wangcl 3 settimane fa
parent
commit
037feada9a

+ 3 - 0
pig-statistics/pig-statistics-api/src/main/java/com/pig4cloud/pig/statistics/api/dto/uninstall/GetUninstallInsightDTO.java

@@ -14,4 +14,7 @@ public class GetUninstallInsightDTO {
 
 	@Schema(description = "周期(周/月)")
 	private String cycle;
+
+	@Schema(description = "类型(0-active 1-before)")
+	private String type;
 }

+ 3 - 0
pig-statistics/pig-statistics-api/src/main/java/com/pig4cloud/pig/statistics/api/dto/uninstall/GetUninstallTrendDTO.java

@@ -15,6 +15,9 @@ public class GetUninstallTrendDTO {
 	@Schema(description = "开始时间(yyyy-MM-dd),不传则默认为当周第一天")
 	private String startDate;
 
+	@Schema(description = "结束时间(yyyy-MM-dd),不传则默认为当前时间")
+	private String endDate;
+
 	
 	@Schema(description = "时间单位(day/week/month),不传则默认为day")
 	private String timeUnit;

+ 1 - 0
pig-statistics/pig-statistics-api/src/main/java/com/pig4cloud/pig/statistics/api/entity/ConfigItem.java

@@ -11,6 +11,7 @@ import lombok.Data;
 @Data
 public class ConfigItem {
 
+	private String key; // config_key
 	private String value; // config_value
 	private String label; // config_label
 }

+ 27 - 1
pig-statistics/pig-statistics-biz/src/main/java/com/pig4cloud/pig/statistics/Util/ConfigUtils.java

@@ -1,7 +1,7 @@
 package com.pig4cloud.pig.statistics.Util;
 
 
-import com.pig4cloud.pig.statistics.api.entity.user.ConfigItem;
+import com.pig4cloud.pig.statistics.api.entity.ConfigItem;
 import com.pig4cloud.pig.statistics.mapper.SysConfigMapper;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.redis.core.RedisTemplate;
@@ -28,6 +28,11 @@ public class ConfigUtils {
 		ConfigUtils.redisTemplate = redisTemplate;
 	}
 
+	/**
+	 * 获取配置项
+	 * @param configKey 配置项key
+	 * @return 配置项
+	 */
 	public static List<ConfigItem> getConfigValues(String configKey) {
 		String cacheKey = CONFIG_CACHE_PREFIX + configKey;
 		List<ConfigItem> cached = (List<ConfigItem>) redisTemplate.opsForValue().get(cacheKey);
@@ -42,4 +47,25 @@ public class ConfigUtils {
 	public static void clearConfigCache(String configKey) {
 		redisTemplate.delete(CONFIG_CACHE_PREFIX + configKey);
 	}
+
+	/**
+	 * 获取一条配置
+	 * @param configKey
+	 * @param configValue
+	 * @return
+	 */
+	public static ConfigItem getConfigValue(String configKey , String configValue) {
+
+		ConfigItem configItem = new ConfigItem();
+		List<ConfigItem> configValues = getConfigValues(configKey);
+
+		for (ConfigItem item : configValues) {
+			if (item.getValue().equals(configValue)) {
+				configItem = item;
+				break;
+			}
+		}
+
+		return configItem;
+	}
 }

+ 1 - 1
pig-statistics/pig-statistics-biz/src/main/java/com/pig4cloud/pig/statistics/mapper/SysConfigMapper.java

@@ -16,6 +16,6 @@ import java.util.List;
 @Mapper
 public interface SysConfigMapper {
 
-	@Select("SELECT config_value as value, config_label as label FROM sys_config WHERE config_key = #{configKey} AND enable = 1 ORDER BY sort ASC")
+	@Select("SELECT config_key as key , config_value as value, config_label as label FROM sys_config WHERE config_key = #{configKey} AND enable = 1 ORDER BY sort ASC")
 	List<ConfigItem> selectByConfigKey(@Param("configKey") String configKey);
 }

+ 26 - 8
pig-statistics/pig-statistics-biz/src/main/java/com/pig4cloud/pig/statistics/service/impl/UninstallAnalyseServiceImpl.java

@@ -2,7 +2,9 @@ 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.api.dto.uninstall.*;
+import com.pig4cloud.pig.statistics.api.entity.ConfigItem;
 import com.pig4cloud.pig.statistics.api.entity.uninstall.*;
 import com.pig4cloud.pig.statistics.api.vo.uninstall.*;
 import com.pig4cloud.pig.statistics.mapper.*;
@@ -11,6 +13,7 @@ import lombok.extern.slf4j.Slf4j;
 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.util.*;
@@ -39,8 +42,18 @@ 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;
+		}
+
         QueryWrapper<MktTrendSummary> wrapper = new QueryWrapper<>();
-        wrapper.eq("stat_date", dto.getStartDate());
+        wrapper.between("stat_date", startDate, endDate);
         List<MktTrendSummary> list = mktTrendSummaryMapper.selectList(wrapper);
         UninstallTrendVO vo = new UninstallTrendVO();
         if (!list.isEmpty()) {
@@ -135,12 +148,13 @@ public class UninstallAnalyseServiceImpl implements UninstallAnalyseService {
 
 	public UninstallInsightVO getUninstallDeviceActiveVO(GetUninstallInsightDTO dto) {
 		QueryWrapper<MktDeviceTime> wrapper = new QueryWrapper<>();
-		wrapper.eq("type", "insight");
+		wrapper.eq("type", dto.getType());
 		List<MktDeviceTime> list = mktDeviceTimeMapper.selectList(wrapper);
 		List<InstallStockVO> voList = new ArrayList<>();
 		for (MktDeviceTime entity : list) {
 			InstallStockVO vo = new InstallStockVO();
-			vo.setTime(entity.getTimeRange());
+			ConfigItem configValue = ConfigUtils.getConfigValue("Time-range", entity.getTimeRange());
+			vo.setTime(configValue.getLabel());
 			vo.setUninstallCount(entity.getDeviceCount());
 			vo.setUninstallRate(entity.getRate());
 			voList.add(vo);
@@ -154,24 +168,27 @@ public class UninstallAnalyseServiceImpl implements UninstallAnalyseService {
 	public UninstallBeforeVO uninstallBefore(GetUninstallInsightDTO dto) {
 		// 1. 卸载时间差分布
 		QueryWrapper<MktDeviceTime> timeWrapper = new QueryWrapper<>();
-		timeWrapper.eq("type", "before");
+		timeWrapper.eq("type", dto.getType());
 		List<MktDeviceTime> timeList = mktDeviceTimeMapper.selectList(timeWrapper);
 		List<UninstallTimeDiffVO> timeDiffs = new ArrayList<>();
 		for (MktDeviceTime entity : timeList) {
 			UninstallTimeDiffVO vo = new UninstallTimeDiffVO();
-			vo.setTime(entity.getTimeRange());
+			ConfigItem configValue = ConfigUtils.getConfigValue("Time-range", entity.getTimeRange());
+			vo.setTime(configValue.getLabel());
 			vo.setCount(entity.getDeviceCount());
 			vo.setRate(entity.getRate());
 			timeDiffs.add(vo);
 		}
 		// 2. 卸载前7天使用次数分布
 		QueryWrapper<MktDeviceCount> countWrapper = new QueryWrapper<>();
-		countWrapper.eq("type", "before");
+		countWrapper.eq("type", dto.getType());
 		List<MktDeviceCount> countList = mktDeviceCountMapper.selectList(countWrapper);
 		List<UninstallBeforeSevenVO> beforeSevens = new ArrayList<>();
 		for (MktDeviceCount entity : countList) {
 			UninstallBeforeSevenVO vo = new UninstallBeforeSevenVO();
-			vo.setTime(entity.getCountRange());
+			ConfigItem configValue = ConfigUtils.getConfigValue("Count_range", entity.getCountRange());
+
+			vo.setTime(configValue.getLabel());
 			vo.setCount(entity.getNum());
 			vo.setRate(entity.getRate());
 			beforeSevens.add(vo);
@@ -181,8 +198,9 @@ public class UninstallAnalyseServiceImpl implements UninstallAnalyseService {
 		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(entity.getCountRange(), entity.getNum());
+				.put(configValue.getLabel(), entity.getNum());
 		}
 		List<UninstallBeforeInterfereVO> interfereVOList = new ArrayList<>();
 		for (Map.Entry<String, Map<String, Integer>> entry : interfereMap.entrySet()) {