统计数据归档查询、商品数据分类缓存、已知问题修复
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package com.czg.controller;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.thread.ThreadUtil;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.czg.CzgPayUtils;
|
||||
import com.czg.entity.CzgBaseRespParams;
|
||||
@@ -9,10 +11,9 @@ import com.czg.task.StatisticTask;
|
||||
import com.czg.utils.AssertUtil;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @author ww
|
||||
@@ -32,7 +33,7 @@ public class NotifyController {
|
||||
|
||||
|
||||
@RequestMapping("/payCallBack")
|
||||
public String notifyCallBack(@RequestBody CzgBaseRespParams respParams){
|
||||
public String notifyCallBack(@RequestBody CzgBaseRespParams respParams) {
|
||||
JSONObject czg = CzgPayUtils.getCzg(respParams);
|
||||
AssertUtil.isNull(czg, "支付回调数据为空");
|
||||
log.info("支付回调数据为:{}", czg);
|
||||
@@ -41,7 +42,7 @@ public class NotifyController {
|
||||
}
|
||||
|
||||
@RequestMapping("/refundCallBack")
|
||||
public String refundCallBack(@RequestBody CzgBaseRespParams respParams){
|
||||
public String refundCallBack(@RequestBody CzgBaseRespParams respParams) {
|
||||
JSONObject czg = CzgPayUtils.getCzg(respParams);
|
||||
AssertUtil.isNull(czg, "退款回调数据为空");
|
||||
log.info("退款回调数据为:{}", czg);
|
||||
@@ -51,8 +52,18 @@ public class NotifyController {
|
||||
|
||||
@Resource
|
||||
private PrintMqListener printMqListener;
|
||||
|
||||
@RequestMapping("/test")
|
||||
public void test(@RequestParam String id) {
|
||||
printMqListener.orderPrint(id);
|
||||
}
|
||||
|
||||
@GetMapping("/anew/statistic/history/data")
|
||||
public String statistic(@RequestParam String now) {
|
||||
String format = DateUtil.format(new Date(), "yyyyMMddHHmm");
|
||||
if (format.equals(now)) {
|
||||
ThreadUtil.execAsync(() -> statisticTask.statisticHistoryData());
|
||||
}
|
||||
return SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ public class DataSummaryController {
|
||||
if (param.getShopId() == null) {
|
||||
param.setShopId(shopId);
|
||||
}
|
||||
ShopOrderStatistic data = dataSummaryService.getTradeData(param);
|
||||
ShopOrderStatistic data = dataSummaryService.getArchiveTradeData(param);
|
||||
return CzgResult.success(data);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,13 +1,27 @@
|
||||
package com.czg.task;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.date.DateTime;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.czg.order.entity.ShopOrderStatistic;
|
||||
import com.czg.order.entity.ShopProdStatistic;
|
||||
import com.czg.order.entity.ShopTableOrderStatistic;
|
||||
import com.czg.order.service.ShopOrderStatisticService;
|
||||
import com.czg.order.service.ShopProdStatisticService;
|
||||
import com.czg.order.service.ShopTableOrderStatisticService;
|
||||
import com.czg.service.order.mapper.ShopOrderStatisticMapper;
|
||||
import com.czg.service.order.mapper.ShopProdStatisticMapper;
|
||||
import com.czg.service.order.mapper.ShopTableOrderStatisticMapper;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import com.mybatisflex.core.row.DbChain;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Administrator
|
||||
*/
|
||||
@@ -20,15 +34,81 @@ public class StatisticTask {
|
||||
private ShopProdStatisticService shopProdStatisticService;
|
||||
@Resource
|
||||
private ShopOrderStatisticService shopOrderStatisticService;
|
||||
@Resource
|
||||
private ShopOrderStatisticMapper shopOrderStatisticMapper;
|
||||
@Resource
|
||||
private ShopProdStatisticMapper shopProdStatisticMapper;
|
||||
@Resource
|
||||
private ShopTableOrderStatisticMapper shopTableOrderStatisticMapper;
|
||||
|
||||
// @Scheduled(cron = "1/6 * * * * ? ")
|
||||
/**
|
||||
* 基础统计
|
||||
*
|
||||
* @param dateTime 日期时间
|
||||
*/
|
||||
private void baseStatistic(DateTime dateTime) {
|
||||
try {
|
||||
shopOrderStatisticService.statistic(dateTime);
|
||||
} catch (Exception e) {
|
||||
log.error("统计订单数据失败", e);
|
||||
}
|
||||
try {
|
||||
shopProdStatisticService.statistic(dateTime);
|
||||
} catch (Exception e) {
|
||||
log.error("统计商品数据失败", e);
|
||||
}
|
||||
try {
|
||||
shopTableOrderStatisticService.statistic(dateTime);
|
||||
} catch (Exception e) {
|
||||
log.error("统计桌台数据失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
// @Scheduled(cron = "1/6 * * * * ? ")
|
||||
@Scheduled(cron = "0 0 8 * * ?")
|
||||
public void run() {
|
||||
long start = System.currentTimeMillis();
|
||||
log.info("定时任务执行,开始统计数据");
|
||||
shopOrderStatisticService.statistic();
|
||||
shopProdStatisticService.statistic();
|
||||
shopTableOrderStatisticService.statistic();
|
||||
// 获取前一天
|
||||
DateTime yesterday = DateUtil.yesterday();
|
||||
baseStatistic(yesterday);
|
||||
log.info("定时任务执行完毕,耗时:{}ms", start - System.currentTimeMillis());
|
||||
}
|
||||
|
||||
@Scheduled(cron = "0 0,15,30,45 * * * ? ")
|
||||
public void run2() {
|
||||
long start = System.currentTimeMillis();
|
||||
log.info("定时任务2执行,开始统计数据");
|
||||
// 获取当天
|
||||
DateTime today = DateUtil.date();
|
||||
baseStatistic(today);
|
||||
log.info("定时任务2执行完毕,耗时:{}ms", start - System.currentTimeMillis());
|
||||
}
|
||||
|
||||
/**
|
||||
* 统计历史数据
|
||||
*/
|
||||
public void statisticHistoryData() {
|
||||
// 指定开始日期
|
||||
LocalDate startDate = LocalDate.of(2024, 3, 1);
|
||||
// 指定结束日期
|
||||
LocalDate endDate = LocalDate.now();
|
||||
List<Long> shopIdList = DbChain.table("tb_shop_info").select("id").objListAs(Long.class);
|
||||
List<List<Long>> split = CollUtil.split(shopIdList, 10);
|
||||
// 1.清除历史统计的数据
|
||||
for (List<Long> splitIdList : split) {
|
||||
splitIdList.parallelStream().forEach(shopId -> {
|
||||
shopOrderStatisticMapper.deleteByQuery(QueryWrapper.create().eq(ShopOrderStatistic::getShopId, shopId));
|
||||
shopProdStatisticMapper.deleteByQuery(QueryWrapper.create().eq(ShopProdStatistic::getShopId, shopId));
|
||||
shopTableOrderStatisticMapper.deleteByQuery(QueryWrapper.create().eq(ShopTableOrderStatistic::getShopId, shopId));
|
||||
});
|
||||
}
|
||||
// 2.开始从2024-3-1开始统计数据
|
||||
startDate.datesUntil(endDate.plusDays(1)).forEach(date -> {
|
||||
System.out.println(date.toString());
|
||||
DateTime dateTime = DateUtil.parseDate(date.toString());
|
||||
System.out.println(dateTime);
|
||||
baseStatistic(dateTime);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user