台桌统计报表
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
package com.czg.service.order.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.date.DateTime;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.NumberUtil;
|
||||
import com.czg.order.entity.ShopOrderStatistic;
|
||||
import com.czg.order.param.DataSummaryTradeParam;
|
||||
import com.czg.order.service.DataSummaryService;
|
||||
@@ -12,9 +11,11 @@ import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* 服务层实现。
|
||||
@@ -30,27 +31,52 @@ public class ShopOrderStatisticServiceImpl extends ServiceImpl<ShopOrderStatisti
|
||||
|
||||
@Override
|
||||
public void statistic() {
|
||||
// 获取前一天
|
||||
DateTime yesterday = DateUtil.yesterday();
|
||||
// 获取前一天的开始时间(00:00:00)
|
||||
DateTime startOfDay = DateUtil.beginOfDay(yesterday);
|
||||
// 获取前一天的结束时间(23:59:59)
|
||||
DateTime endOfDay = DateUtil.endOfDay(yesterday);
|
||||
List<Long> shopIdList = dataSummaryService.getShopIdList();
|
||||
if (CollUtil.isEmpty(shopIdList)) {
|
||||
return;
|
||||
}
|
||||
shopIdList.parallelStream().forEach(shopId -> {
|
||||
DataSummaryTradeParam param = new DataSummaryTradeParam();
|
||||
param.setShopId(shopId);
|
||||
param.setBeginDate(startOfDay.toStringDefaultTimeZone());
|
||||
param.setEndDate(endOfDay.toStringDefaultTimeZone());
|
||||
ShopOrderStatistic statistic = dataSummaryService.getTradeData(param);
|
||||
statistic.setShopId(shopId);
|
||||
statistic.setCreateDay(LocalDate.now());
|
||||
statistic.setUpdateTime(LocalDateTime.now());
|
||||
saveOrUpdate(statistic);
|
||||
|
||||
LocalDate startDate = LocalDate.of(2024, 3, 12);
|
||||
LocalDate endDate = LocalDate.of(2025, 3, 25);
|
||||
|
||||
// 生成日期流
|
||||
Stream<LocalDate> dateStream = startDate.datesUntil(endDate);
|
||||
|
||||
// 遍历日期流
|
||||
dateStream.forEach(date -> {
|
||||
String cur = date.toString();
|
||||
String a = cur + " 00:00:00";
|
||||
String b = cur + " 23:59:59";
|
||||
shopIdList.parallelStream().forEach(shopId -> {
|
||||
DataSummaryTradeParam param = new DataSummaryTradeParam();
|
||||
param.setShopId(shopId);
|
||||
param.setBeginDate(a);
|
||||
param.setEndDate(b);
|
||||
ShopOrderStatistic statistic = dataSummaryService.getTradeData(param);
|
||||
if (NumberUtil.isGreater(statistic.getSaleAmount(), BigDecimal.ZERO)) {
|
||||
statistic.setShopId(shopId);
|
||||
statistic.setCreateDay(LocalDate.now());
|
||||
statistic.setUpdateTime(LocalDateTime.now());
|
||||
saveOrUpdate(statistic);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
LocalDate startDate = LocalDate.of(2024, 3, 12);
|
||||
LocalDate endDate = LocalDate.of(2025, 3, 25);
|
||||
|
||||
// 生成日期流
|
||||
Stream<LocalDate> dateStream = startDate.datesUntil(endDate);
|
||||
|
||||
// 遍历日期流
|
||||
dateStream.forEach(date -> {
|
||||
String cur = date.toString();
|
||||
String a = cur + "00:00:00";
|
||||
String b = cur + "23:59:59";
|
||||
System.out.println(date.toString());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user