|
|
@@ -3,6 +3,8 @@ package shop.alien.store.service.impl;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
@@ -189,7 +191,9 @@ public class StoreOperationalStatisticsServiceImpl implements StoreOperationalSt
|
|
|
comparison.setServiceQualityData(buildServiceQualityDataComparison(currentStatistics.getServiceQualityData(), previousStatistics.getServiceQualityData()));
|
|
|
comparison.setPriceListRanking(buildPriceListRankingComparison(currentStatistics.getPriceListRanking(), previousStatistics.getPriceListRanking()));
|
|
|
|
|
|
- // 不再在此处保存历史记录,历史记录只在 generateStatisticsComparisonPdf 接口中保存
|
|
|
+ // 保存历史记录(不包含PDF URL,PDF URL只在 generateStatisticsComparisonPdf 接口中保存)
|
|
|
+ saveStatisticsHistory(storeId, currentStartTime, currentEndTime,
|
|
|
+ previousStartTime, previousEndTime, comparison, null);
|
|
|
|
|
|
return comparison;
|
|
|
}
|
|
|
@@ -291,9 +295,9 @@ public class StoreOperationalStatisticsServiceImpl implements StoreOperationalSt
|
|
|
StoreOperationalStatisticsVo.ServiceQualityData service = statistics.getServiceQualityData();
|
|
|
Map<String, Object> serviceData = new HashMap<>();
|
|
|
serviceData.put("storeScore", service.getStoreRating() != null ? service.getStoreRating().doubleValue() : 0.0);
|
|
|
- serviceData.put("tasteScore", service.getTasteRating() != null ? service.getTasteRating().doubleValue() : 0.0);
|
|
|
- serviceData.put("environmentScore", service.getEnvironmentRating() != null ? service.getEnvironmentRating().doubleValue() : 0.0);
|
|
|
- serviceData.put("serviceScore", service.getServiceRating() != null ? service.getServiceRating().doubleValue() : 0.0);
|
|
|
+ serviceData.put("scoreOne", service.getScoreOne() != null ? service.getScoreOne().doubleValue() : 0.0);
|
|
|
+ serviceData.put("scoreTwo", service.getScoreTwo() != null ? service.getScoreTwo().doubleValue() : 0.0);
|
|
|
+ serviceData.put("scoreThree", service.getScoreThree() != null ? service.getScoreThree().doubleValue() : 0.0);
|
|
|
serviceData.put("ratingCount", service.getTotalReviews() != null ? service.getTotalReviews() : 0L);
|
|
|
serviceData.put("goodRatingCount", service.getPositiveReviews() != null ? service.getPositiveReviews() : 0L);
|
|
|
serviceData.put("midRatingCount", service.getNeutralReviews() != null ? service.getNeutralReviews() : 0L);
|
|
|
@@ -543,10 +547,10 @@ public class StoreOperationalStatisticsServiceImpl implements StoreOperationalSt
|
|
|
.orElse(0.0);
|
|
|
serviceQualityData.setStoreRating(BigDecimal.valueOf(avgScore).setScale(1, RoundingMode.HALF_UP));
|
|
|
|
|
|
- // TODO: 口味评分、环境评分、服务评分需要根据评价详情表查询
|
|
|
- serviceQualityData.setTasteRating(BigDecimal.ZERO);
|
|
|
- serviceQualityData.setEnvironmentRating(BigDecimal.ZERO);
|
|
|
- serviceQualityData.setServiceRating(BigDecimal.ZERO);
|
|
|
+ // TODO: 评分1、评分2、评分3需要根据评价详情表查询
|
|
|
+ serviceQualityData.setScoreOne(BigDecimal.ZERO);
|
|
|
+ serviceQualityData.setScoreTwo(BigDecimal.ZERO);
|
|
|
+ serviceQualityData.setScoreThree(BigDecimal.ZERO);
|
|
|
|
|
|
// 评价数量
|
|
|
serviceQualityData.setTotalReviews((long) evaluations.size());
|
|
|
@@ -583,9 +587,9 @@ public class StoreOperationalStatisticsServiceImpl implements StoreOperationalSt
|
|
|
serviceQualityData.setNegativeReviewAppealsSuccessRatio(BigDecimal.ZERO);
|
|
|
} else {
|
|
|
serviceQualityData.setStoreRating(BigDecimal.ZERO);
|
|
|
- serviceQualityData.setTasteRating(BigDecimal.ZERO);
|
|
|
- serviceQualityData.setEnvironmentRating(BigDecimal.ZERO);
|
|
|
- serviceQualityData.setServiceRating(BigDecimal.ZERO);
|
|
|
+ serviceQualityData.setScoreOne(BigDecimal.ZERO);
|
|
|
+ serviceQualityData.setScoreTwo(BigDecimal.ZERO);
|
|
|
+ serviceQualityData.setScoreThree(BigDecimal.ZERO);
|
|
|
serviceQualityData.setTotalReviews(0L);
|
|
|
serviceQualityData.setPositiveReviews(0L);
|
|
|
serviceQualityData.setNeutralReviews(0L);
|
|
|
@@ -747,9 +751,9 @@ public class StoreOperationalStatisticsServiceImpl implements StoreOperationalSt
|
|
|
current = new StoreOperationalStatisticsVo.ServiceQualityData();
|
|
|
}
|
|
|
comparison.setStoreRating(buildComparisonData(current.getStoreRating(), previous.getStoreRating()));
|
|
|
- comparison.setTasteRating(buildComparisonData(current.getTasteRating(), previous.getTasteRating()));
|
|
|
- comparison.setEnvironmentRating(buildComparisonData(current.getEnvironmentRating(), previous.getEnvironmentRating()));
|
|
|
- comparison.setServiceRating(buildComparisonData(current.getServiceRating(), previous.getServiceRating()));
|
|
|
+ comparison.setScoreOne(buildComparisonData(current.getScoreOne(), previous.getScoreOne()));
|
|
|
+ comparison.setScoreTwo(buildComparisonData(current.getScoreTwo(), previous.getScoreTwo()));
|
|
|
+ comparison.setScoreThree(buildComparisonData(current.getScoreThree(), previous.getScoreThree()));
|
|
|
comparison.setTotalReviews(buildComparisonData(current.getTotalReviews(), previous.getTotalReviews()));
|
|
|
comparison.setPositiveReviews(buildComparisonData(current.getPositiveReviews(), previous.getPositiveReviews()));
|
|
|
comparison.setNeutralReviews(buildComparisonData(current.getNeutralReviews(), previous.getNeutralReviews()));
|
|
|
@@ -786,13 +790,42 @@ public class StoreOperationalStatisticsServiceImpl implements StoreOperationalSt
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ // 收集需要查询名称的priceId(如果名称为空)
|
|
|
+ List<Integer> needQueryPriceIds = new ArrayList<>();
|
|
|
+ for (StoreOperationalStatisticsVo.PriceListRanking curr : current) {
|
|
|
+ if (curr.getPriceId() != null &&
|
|
|
+ (curr.getPriceListItemName() == null || curr.getPriceListItemName().trim().isEmpty())) {
|
|
|
+ needQueryPriceIds.add(curr.getPriceId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 批量查询价目表名称
|
|
|
+ Map<Integer, String> priceNameMap = new HashMap<>();
|
|
|
+ if (!needQueryPriceIds.isEmpty()) {
|
|
|
+ LambdaQueryWrapper<StorePrice> priceWrapper = new LambdaQueryWrapper<>();
|
|
|
+ priceWrapper.in(StorePrice::getId, needQueryPriceIds)
|
|
|
+ .eq(StorePrice::getDeleteFlag, 0);
|
|
|
+ List<StorePrice> prices = storePriceMapper.selectList(priceWrapper);
|
|
|
+ for (StorePrice price : prices) {
|
|
|
+ if (price.getId() != null && price.getName() != null) {
|
|
|
+ priceNameMap.put(price.getId(), price.getName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
// 遍历当期数据,构建对比
|
|
|
for (StoreOperationalStatisticsVo.PriceListRanking curr : current) {
|
|
|
StoreOperationalStatisticsComparisonVo.PriceListRankingComparison comparison =
|
|
|
new StoreOperationalStatisticsComparisonVo.PriceListRankingComparison();
|
|
|
|
|
|
comparison.setPriceId(curr.getPriceId());
|
|
|
- comparison.setPriceListItemName(curr.getPriceListItemName());
|
|
|
+
|
|
|
+ // 设置价目表名称,如果为空则从查询结果中获取
|
|
|
+ String priceListItemName = curr.getPriceListItemName();
|
|
|
+ if (priceListItemName == null || priceListItemName.trim().isEmpty()) {
|
|
|
+ priceListItemName = priceNameMap.get(curr.getPriceId());
|
|
|
+ }
|
|
|
+ comparison.setPriceListItemName(priceListItemName);
|
|
|
|
|
|
// 获取上期对应的价目表数据
|
|
|
StoreOperationalStatisticsVo.PriceListRanking prev = previousMap.get(curr.getPriceId());
|
|
|
@@ -942,15 +975,27 @@ public class StoreOperationalStatisticsServiceImpl implements StoreOperationalSt
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public List<StoreOperationalStatisticsHistory> getHistoryList(Integer storeId) {
|
|
|
- log.info("StoreOperationalStatisticsServiceImpl.getHistoryList - storeId={}", storeId);
|
|
|
+ public IPage<StoreOperationalStatisticsHistory> getHistoryList(Integer storeId, Integer page, Integer size) {
|
|
|
+ log.info("StoreOperationalStatisticsServiceImpl.getHistoryList - storeId={}, page={}, size={}", storeId, page, size);
|
|
|
+
|
|
|
+ // 参数校验
|
|
|
+ int pageNum = page > 0 ? page : 1;
|
|
|
+ int pageSize = size > 0 ? size : 10;
|
|
|
|
|
|
+ // 构建分页对象
|
|
|
+ IPage<StoreOperationalStatisticsHistory> pageObj = new Page<>(pageNum, pageSize);
|
|
|
+
|
|
|
+ // 构建查询条件
|
|
|
LambdaQueryWrapper<StoreOperationalStatisticsHistory> wrapper = new LambdaQueryWrapper<>();
|
|
|
wrapper.eq(StoreOperationalStatisticsHistory::getStoreId, storeId)
|
|
|
.eq(StoreOperationalStatisticsHistory::getDeleteFlag, 0)
|
|
|
.orderByDesc(StoreOperationalStatisticsHistory::getQueryTime);
|
|
|
|
|
|
- return statisticsHistoryMapper.selectList(wrapper);
|
|
|
+ // 执行分页查询
|
|
|
+ IPage<StoreOperationalStatisticsHistory> result = statisticsHistoryMapper.selectPage(pageObj, wrapper);
|
|
|
+
|
|
|
+ log.info("查询历史统计记录列表成功 - storeId={}, 共{}条记录,当前页{}条", storeId, result.getTotal(), result.getRecords().size());
|
|
|
+ return result;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -1189,12 +1234,12 @@ public class StoreOperationalStatisticsServiceImpl implements StoreOperationalSt
|
|
|
// 累加评分(需要计算平均值)
|
|
|
accumulator.put("storeScoreSum", getBigDecimalValue(accumulator, "storeScoreSum")
|
|
|
.add(getBigDecimalValue(data, "storeScore")));
|
|
|
- accumulator.put("tasteScoreSum", getBigDecimalValue(accumulator, "tasteScoreSum")
|
|
|
- .add(getBigDecimalValue(data, "tasteScore")));
|
|
|
- accumulator.put("environmentScoreSum", getBigDecimalValue(accumulator, "environmentScoreSum")
|
|
|
- .add(getBigDecimalValue(data, "environmentScore")));
|
|
|
- accumulator.put("serviceScoreSum", getBigDecimalValue(accumulator, "serviceScoreSum")
|
|
|
- .add(getBigDecimalValue(data, "serviceScore")));
|
|
|
+ accumulator.put("scoreOneSum", getBigDecimalValue(accumulator, "scoreOneSum")
|
|
|
+ .add(getBigDecimalValue(data, "scoreOne")));
|
|
|
+ accumulator.put("scoreTwoSum", getBigDecimalValue(accumulator, "scoreTwoSum")
|
|
|
+ .add(getBigDecimalValue(data, "scoreTwo")));
|
|
|
+ accumulator.put("scoreThreeSum", getBigDecimalValue(accumulator, "scoreThreeSum")
|
|
|
+ .add(getBigDecimalValue(data, "scoreThree")));
|
|
|
|
|
|
// 累加Long类型字段
|
|
|
accumulator.put("ratingCount", getLongValue(accumulator, "ratingCount") +
|
|
|
@@ -1371,19 +1416,19 @@ public class StoreOperationalStatisticsServiceImpl implements StoreOperationalSt
|
|
|
// 计算平均评分
|
|
|
if (count > 0) {
|
|
|
BigDecimal storeScoreSum = getBigDecimalValue(accumulator, "storeScoreSum");
|
|
|
- BigDecimal tasteScoreSum = getBigDecimalValue(accumulator, "tasteScoreSum");
|
|
|
- BigDecimal environmentScoreSum = getBigDecimalValue(accumulator, "environmentScoreSum");
|
|
|
- BigDecimal serviceScoreSum = getBigDecimalValue(accumulator, "serviceScoreSum");
|
|
|
+ BigDecimal scoreOneSum = getBigDecimalValue(accumulator, "scoreOneSum");
|
|
|
+ BigDecimal scoreTwoSum = getBigDecimalValue(accumulator, "scoreTwoSum");
|
|
|
+ BigDecimal scoreThreeSum = getBigDecimalValue(accumulator, "scoreThreeSum");
|
|
|
|
|
|
vo.setStoreRating(storeScoreSum.divide(BigDecimal.valueOf(count), 2, RoundingMode.HALF_UP));
|
|
|
- vo.setTasteRating(tasteScoreSum.divide(BigDecimal.valueOf(count), 2, RoundingMode.HALF_UP));
|
|
|
- vo.setEnvironmentRating(environmentScoreSum.divide(BigDecimal.valueOf(count), 2, RoundingMode.HALF_UP));
|
|
|
- vo.setServiceRating(serviceScoreSum.divide(BigDecimal.valueOf(count), 2, RoundingMode.HALF_UP));
|
|
|
+ vo.setScoreOne(scoreOneSum.divide(BigDecimal.valueOf(count), 2, RoundingMode.HALF_UP));
|
|
|
+ vo.setScoreTwo(scoreTwoSum.divide(BigDecimal.valueOf(count), 2, RoundingMode.HALF_UP));
|
|
|
+ vo.setScoreThree(scoreThreeSum.divide(BigDecimal.valueOf(count), 2, RoundingMode.HALF_UP));
|
|
|
} else {
|
|
|
vo.setStoreRating(BigDecimal.ZERO);
|
|
|
- vo.setTasteRating(BigDecimal.ZERO);
|
|
|
- vo.setEnvironmentRating(BigDecimal.ZERO);
|
|
|
- vo.setServiceRating(BigDecimal.ZERO);
|
|
|
+ vo.setScoreOne(BigDecimal.ZERO);
|
|
|
+ vo.setScoreTwo(BigDecimal.ZERO);
|
|
|
+ vo.setScoreThree(BigDecimal.ZERO);
|
|
|
}
|
|
|
|
|
|
vo.setTotalReviews(getLongValue(accumulator, "ratingCount"));
|
|
|
@@ -1425,6 +1470,26 @@ public class StoreOperationalStatisticsServiceImpl implements StoreOperationalSt
|
|
|
private List<StoreOperationalStatisticsVo.PriceListRanking> convertToPriceListRankingVo(Map<Integer, Map<String, Long>> accumulator) {
|
|
|
List<StoreOperationalStatisticsVo.PriceListRanking> result = new ArrayList<>();
|
|
|
|
|
|
+ // 如果累加器为空,直接返回
|
|
|
+ if (accumulator == null || accumulator.isEmpty()) {
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 批量查询价目表名称
|
|
|
+ List<Integer> priceIds = new ArrayList<>(accumulator.keySet());
|
|
|
+ Map<Integer, String> priceNameMap = new HashMap<>();
|
|
|
+ if (!priceIds.isEmpty()) {
|
|
|
+ LambdaQueryWrapper<StorePrice> priceWrapper = new LambdaQueryWrapper<>();
|
|
|
+ priceWrapper.in(StorePrice::getId, priceIds)
|
|
|
+ .eq(StorePrice::getDeleteFlag, 0);
|
|
|
+ List<StorePrice> prices = storePriceMapper.selectList(priceWrapper);
|
|
|
+ for (StorePrice price : prices) {
|
|
|
+ if (price.getId() != null && price.getName() != null) {
|
|
|
+ priceNameMap.put(price.getId(), price.getName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
// 转换为列表并按浏览量降序排序
|
|
|
for (Map.Entry<Integer, Map<String, Long>> entry : accumulator.entrySet()) {
|
|
|
StoreOperationalStatisticsVo.PriceListRanking ranking = new StoreOperationalStatisticsVo.PriceListRanking();
|
|
|
@@ -1434,8 +1499,8 @@ public class StoreOperationalStatisticsServiceImpl implements StoreOperationalSt
|
|
|
ranking.setVisitors(data.getOrDefault("visitorCount", 0L));
|
|
|
ranking.setShares(data.getOrDefault("shareCount", 0L));
|
|
|
|
|
|
- // 获取价目表名称(如果需要)
|
|
|
- // ranking.setPriceListItemName(...);
|
|
|
+ // 根据id查询价目表名称
|
|
|
+ ranking.setPriceListItemName(priceNameMap.getOrDefault(entry.getKey(), null));
|
|
|
|
|
|
result.add(ranking);
|
|
|
}
|