统计数据归档查询、商品数据分类缓存、已知问题修复
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);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,6 @@ package com.czg.controller.admin;
|
||||
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.thread.ThreadUtil;
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.czg.account.service.ShopConfigService;
|
||||
import com.czg.annotation.SaStaffCheckPermission;
|
||||
import com.czg.config.RabbitPublisher;
|
||||
@@ -72,22 +70,9 @@ public class ProductController {
|
||||
public CzgResult<List<ProductDTO>> getProductList(ProductDTO param) {
|
||||
Long shopId = StpKit.USER.getShopId(0L);
|
||||
param.setShopId(shopId);
|
||||
ProductDTO cacheParam = new ProductDTO();
|
||||
cacheParam.setShopId(shopId);
|
||||
List<ProductDTO> data = getProductCacheList(cacheParam, param);
|
||||
productService.refreshProductStock(param, data);
|
||||
return CzgResult.success(data);
|
||||
}
|
||||
|
||||
private List<ProductDTO> getProductCacheList(ProductDTO cacheParam, ProductDTO param) {
|
||||
List<ProductDTO> productList = productService.getProductList(cacheParam);
|
||||
if (StrUtil.isNotEmpty(param.getName())) {
|
||||
productList = productList.stream().filter(obj -> StrUtil.contains(obj.getName(), param.getName())).toList();
|
||||
}
|
||||
if (ObjUtil.isNotNull(param.getCategoryId())) {
|
||||
productList = productList.stream().filter(obj -> param.getCategoryId().equals(obj.getCategoryId())).toList();
|
||||
}
|
||||
return productList;
|
||||
List<ProductDTO> productList = productService.getProductCacheList(param);
|
||||
productService.refreshProductStock(param, productList);
|
||||
return CzgResult.success(productList);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -160,6 +145,9 @@ public class ProductController {
|
||||
Long shopId = StpKit.USER.getShopId(0L);
|
||||
param.setShopId(shopId);
|
||||
productService.updateProductStock(param);
|
||||
ThreadUtil.execAsync(() -> {
|
||||
rabbitPublisher.sendProductInfoChangeMsg(Convert.toStr(shopId));
|
||||
});
|
||||
return CzgResult.success();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.czg.controller.user;
|
||||
|
||||
import com.czg.product.dto.ProdGroupDTO;
|
||||
import com.czg.product.param.ShopProductSkuParam;
|
||||
import com.czg.product.service.ProdGroupService;
|
||||
import com.czg.product.service.UProductService;
|
||||
@@ -21,7 +20,6 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
/**
|
||||
@@ -57,19 +55,13 @@ public class UProductController {
|
||||
@GetMapping("/miniApp/group/query")
|
||||
public CzgResult<List<ShopGroupProductVo>> queryGroupProductList() {
|
||||
Long shopId = StpKit.USER.getShopId(0L);
|
||||
ProdGroupDTO param = new ProdGroupDTO();
|
||||
List<ProdGroupDTO> prodGroupList = prodGroupService.getProdGroupList(param);
|
||||
Map<Long, ProdGroupDTO> groupMap = prodGroupList.stream().collect(Collectors.toMap(ProdGroupDTO::getId, i -> i));
|
||||
List<ShopGroupProductVo> list = uProductService.queryGroupProductList(shopId);
|
||||
Map<Long, Integer> productStock = uProductService.findShopProductStock(shopId);
|
||||
list.forEach(item -> {
|
||||
uProductService.refreshProductStock(productStock, item.getProductList());
|
||||
ProdGroupDTO config = groupMap.get(item.getId());
|
||||
item.getProductList().forEach(prod -> {
|
||||
prod.setIsSaleTime(uProductService.calcIsSaleTime(prod.getDays(), prod.getStartTime(), prod.getEndTime()));
|
||||
if (config != null) {
|
||||
prod.setIsSaleTime(uProductService.calcIsSaleTime(config.getUseTime(), config.getSaleStartTime(), config.getSaleEndTime()));
|
||||
}
|
||||
prod.setIsSaleTime(uProductService.calcIsSaleTime(item.getUseTime(), item.getSaleStartTime(), item.getSaleEndTime()));
|
||||
});
|
||||
});
|
||||
return CzgResult.success(list);
|
||||
|
||||
Reference in New Issue
Block a user