|
@@ -1114,8 +1114,8 @@ public class StoreOperationalStatisticsServiceImpl implements StoreOperationalSt
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
- public IPage<StoreOperationalStatisticsHistory> getHistoryList(Integer storeId, Integer page, Integer size) {
|
|
|
|
|
- log.info("StoreOperationalStatisticsServiceImpl.getHistoryList - storeId={}, page={}, size={}", storeId, page, size);
|
|
|
|
|
|
|
+ public IPage<StoreOperationalStatisticsHistory> getHistoryList(Integer storeId, Integer page, Integer size, String createdTime) {
|
|
|
|
|
+ log.info("StoreOperationalStatisticsServiceImpl.getHistoryList - storeId={}, page={}, size={}, createdTime={}", storeId, page, size, createdTime);
|
|
|
|
|
|
|
|
// 参数校验
|
|
// 参数校验
|
|
|
if (storeId == null || storeId <= 0) {
|
|
if (storeId == null || storeId <= 0) {
|
|
@@ -1133,6 +1133,11 @@ public class StoreOperationalStatisticsServiceImpl implements StoreOperationalSt
|
|
|
.eq(StoreOperationalStatisticsHistory::getDeleteFlag, 0)
|
|
.eq(StoreOperationalStatisticsHistory::getDeleteFlag, 0)
|
|
|
.orderByDesc(StoreOperationalStatisticsHistory::getQueryTime);
|
|
.orderByDesc(StoreOperationalStatisticsHistory::getQueryTime);
|
|
|
|
|
|
|
|
|
|
+ // created_time 可选:与 query_time 为同一天(query_time 格式 yyyy-MM-dd HH:mm:ss,created_time 格式 yyyy-MM-dd)
|
|
|
|
|
+ if (StringUtils.hasText(createdTime)) {
|
|
|
|
|
+ wrapper.apply("DATE(query_time) = {0}", createdTime.trim());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
// 执行分页查询
|
|
// 执行分页查询
|
|
|
IPage<StoreOperationalStatisticsHistory> result = statisticsHistoryMapper.selectPage(pageObj, wrapper);
|
|
IPage<StoreOperationalStatisticsHistory> result = statisticsHistoryMapper.selectPage(pageObj, wrapper);
|
|
|
|
|
|
|
@@ -2298,7 +2303,58 @@ public class StoreOperationalStatisticsServiceImpl implements StoreOperationalSt
|
|
|
throw new RuntimeException("生成图片并转PDF上传失败: " + e.getMessage(), e);
|
|
throw new RuntimeException("生成图片并转PDF上传失败: " + e.getMessage(), e);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public String generateStatisticsComparisonPdfByHistoryId(Integer storeId, Integer historyId) {
|
|
|
|
|
+ log.info("StoreOperationalStatisticsServiceImpl.generateStatisticsComparisonPdfByHistoryId - storeId={}, historyId={}", storeId, historyId);
|
|
|
|
|
+
|
|
|
|
|
+ if (storeId == null || storeId <= 0) {
|
|
|
|
|
+ throw new IllegalArgumentException("店铺ID不能为空且必须大于0");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (historyId == null || historyId <= 0) {
|
|
|
|
|
+ throw new IllegalArgumentException("历史记录ID不能为空且必须大于0");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 1. 根据 historyId 查询历史记录
|
|
|
|
|
+ StoreOperationalStatisticsHistory history = getHistoryById(historyId);
|
|
|
|
|
+ if (!storeId.equals(history.getStoreId())) {
|
|
|
|
|
+ throw new IllegalArgumentException("历史记录与店铺ID不匹配");
|
|
|
|
|
+ }
|
|
|
|
|
+ String statisticsDataJson = history.getStatisticsData();
|
|
|
|
|
+ if (statisticsDataJson == null || statisticsDataJson.trim().isEmpty()) {
|
|
|
|
|
+ throw new IllegalArgumentException("该历史记录无统计数据(statistics_data为空)");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 2. 将 statistics_data 的 JSON 转为 StoreOperationalStatisticsComparisonVo
|
|
|
|
|
+ StoreOperationalStatisticsComparisonVo comparison = JSON.parseObject(statisticsDataJson.trim(), StoreOperationalStatisticsComparisonVo.class);
|
|
|
|
|
+ if (comparison == null) {
|
|
|
|
|
+ throw new RuntimeException("解析统计数据对比JSON失败");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ // 3. 生成图片
|
|
|
|
|
+ byte[] imageBytes = StatisticsComparisonImageUtil.generateImage(comparison);
|
|
|
|
|
+ java.io.ByteArrayInputStream imageInputStream = new java.io.ByteArrayInputStream(imageBytes);
|
|
|
|
|
+ byte[] pdfBytes = ImageToPdfUtil.imageToPdfBytes(imageInputStream);
|
|
|
|
|
+ if (pdfBytes == null || pdfBytes.length == 0) {
|
|
|
|
|
+ throw new RuntimeException("图片转PDF失败");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 4. 上传PDF到OSS
|
|
|
|
|
+ String ossFilePath = "statistics/comparison_" + storeId + "_" + RandomCreateUtil.getRandomNum(8) + ".pdf";
|
|
|
|
|
+ java.io.ByteArrayInputStream pdfInputStream = new java.io.ByteArrayInputStream(pdfBytes);
|
|
|
|
|
+ String pdfUrl = aliOSSUtil.uploadFile(pdfInputStream, ossFilePath);
|
|
|
|
|
+ log.info("根据历史记录生成统计数据对比PDF并上传成功 - storeId={}, historyId={}, pdfUrl={}", storeId, historyId, pdfUrl);
|
|
|
|
|
+
|
|
|
|
|
+ // 5. 更新该历史记录的 PDF URL
|
|
|
|
|
+ updateHistoryPdfUrl(historyId, pdfUrl);
|
|
|
|
|
+ return pdfUrl;
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("根据历史记录生成统计数据对比PDF失败 - storeId={}, historyId={}, error={}", storeId, historyId, e.getMessage(), e);
|
|
|
|
|
+ throw new RuntimeException("生成PDF报告失败: " + e.getMessage(), e);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 获取统计数据对比(不保存历史记录)
|
|
* 获取统计数据对比(不保存历史记录)
|
|
|
* 用于 generateStatisticsComparisonPdf 方法,避免重复保存历史记录
|
|
* 用于 generateStatisticsComparisonPdf 方法,避免重复保存历史记录
|