统计数据归档查询、商品数据分类缓存、已知问题修复
This commit is contained in:
@@ -14,6 +14,7 @@ import com.czg.order.service.DataSummaryService;
|
||||
import com.czg.order.vo.DataSummaryDateAmountVo;
|
||||
import com.czg.order.vo.DataSummaryPayTypeVo;
|
||||
import com.czg.order.vo.DataSummaryProductSaleRankingVo;
|
||||
import com.czg.order.vo.TotalVo;
|
||||
import com.czg.service.order.mapper.OrderInfoMapper;
|
||||
import com.czg.service.order.mapper.ShopOrderStatisticMapper;
|
||||
import com.czg.service.order.mapper.ShopProdStatisticMapper;
|
||||
@@ -50,7 +51,15 @@ public class DataSummaryServiceImpl implements DataSummaryService {
|
||||
private ShopProdStatisticMapper shopProdStatisticMapper;
|
||||
|
||||
@Override
|
||||
public ShopOrderStatistic getTradeData(DataSummaryTradeParam param) {
|
||||
public ShopOrderStatistic getArchiveTradeData(DataSummaryTradeParam param) {
|
||||
ShopOrderStatistic shopOrderStatistic = shopOrderStatisticMapper.getTradeData(param);
|
||||
shopOrderStatistic.setCustomerUnitPrice(shopOrderStatistic.getCustomerUnitPrice().setScale(2, java.math.RoundingMode.HALF_UP));
|
||||
shopOrderStatistic.setTableTurnoverRate(shopOrderStatistic.getTableTurnoverRate().setScale(2, java.math.RoundingMode.HALF_UP));
|
||||
return shopOrderStatistic;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ShopOrderStatistic getRealTimeTradeData(DataSummaryTradeParam param) {
|
||||
List<String> funs = Arrays.asList("getPayTypeAmountCount", "getVipRechargeAmountCount", "getNewMemberCount", "getCustomerUnitPrice", "getTableTurnoverRate");
|
||||
Map<String, Object> collect = funs.parallelStream().collect(Collectors.toMap(fun -> fun, fun ->
|
||||
ReflectUtil.invoke(shopOrderStatisticMapper, fun, param)
|
||||
@@ -106,13 +115,6 @@ public class DataSummaryServiceImpl implements DataSummaryService {
|
||||
data.setDiscountAmount(discountAmount);
|
||||
data.setDiscountCount(discountCount);
|
||||
return data;
|
||||
|
||||
/*ShopOrderStatistic shopOrderStatistic = shopOrderStatisticMapper.getTradeData(param);
|
||||
long newMemberCount = shopOrderStatisticMapper.getNewMemberCount(param);
|
||||
data.setNewMemberCount(newMemberCount);
|
||||
shopOrderStatistic.setCustomerUnitPrice(shopOrderStatistic.getCustomerUnitPrice().setScale(2, java.math.RoundingMode.HALF_UP));
|
||||
shopOrderStatistic.setTableTurnoverRate(shopOrderStatistic.getTableTurnoverRate().setScale(2, java.math.RoundingMode.HALF_UP));
|
||||
return shopOrderStatistic;*/
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -129,7 +131,7 @@ public class DataSummaryServiceImpl implements DataSummaryService {
|
||||
param.setBeginDate(days.getFirst() + " 00:00:00");
|
||||
param.setEndDate(days.getLast() + " 23:59:59");
|
||||
PageHelper.startPage(PageUtil.buildPageHelp());
|
||||
PageInfo<DataSummaryProductSaleRankingVo> pageInfo = new PageInfo<>(shopProdStatisticMapper.findProdRandingSummaryPage2(param));
|
||||
PageInfo<DataSummaryProductSaleRankingVo> pageInfo = new PageInfo<>(shopProdStatisticMapper.findProdRandingSummaryPage(param));
|
||||
return PageUtil.convert(pageInfo);
|
||||
}
|
||||
|
||||
@@ -138,7 +140,7 @@ public class DataSummaryServiceImpl implements DataSummaryService {
|
||||
LocalDate now = LocalDate.now();
|
||||
LocalDate beginDate = now.plusDays(-day);
|
||||
DataSummaryDateAmountVo data = new DataSummaryDateAmountVo();
|
||||
List<DataSummaryDateAmountVo.TotalVo> total = new ArrayList<>();
|
||||
List<TotalVo> total = new ArrayList<>();
|
||||
for (int i = 1; i <= day; i++) {
|
||||
String thisDay = beginDate.plusDays(i).format(DatePattern.NORM_DATE_FORMATTER);
|
||||
OrderInfo orderInfo = orderInfoMapper.selectOneByQuery(QueryWrapper.create()
|
||||
@@ -147,7 +149,7 @@ public class DataSummaryServiceImpl implements DataSummaryService {
|
||||
.eq(OrderInfo::getTradeDay, thisDay)
|
||||
.isNotNull(OrderInfo::getPaidTime)
|
||||
);
|
||||
DataSummaryDateAmountVo.TotalVo totalVo = new DataSummaryDateAmountVo.TotalVo();
|
||||
TotalVo totalVo = new TotalVo();
|
||||
if (orderInfo != null) {
|
||||
totalVo.setOrderAmount(orderInfo.getOrderAmount());
|
||||
totalVo.setActualAmount(orderInfo.getPayAmount());
|
||||
@@ -209,4 +211,5 @@ public class DataSummaryServiceImpl implements DataSummaryService {
|
||||
public List<Long> getShopIdList() {
|
||||
return shopOrderStatisticMapper.getShopIdList();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ public class SaleSummaryServiceImpl implements SaleSummaryService {
|
||||
|
||||
@Override
|
||||
public SaleSummaryCountVo summaryCount(SaleSummaryCountParam param) {
|
||||
SaleSummaryCountVo saleSummaryCount = shopProdStatisticMapper.getSaleSummaryCount2(param);
|
||||
SaleSummaryCountVo saleSummaryCount = shopProdStatisticMapper.getSaleSummaryCount(param);
|
||||
if (saleSummaryCount == null) {
|
||||
saleSummaryCount = new SaleSummaryCountVo();
|
||||
}
|
||||
@@ -37,12 +37,12 @@ public class SaleSummaryServiceImpl implements SaleSummaryService {
|
||||
@Override
|
||||
public Page<SaleSummaryInfoVo> summaryPage(SaleSummaryCountParam param) {
|
||||
PageHelper.startPage(PageUtil.buildPageHelp());
|
||||
PageInfo<SaleSummaryInfoVo> pageInfo = new PageInfo<>(shopProdStatisticMapper.findSaleSummaryList2(param));
|
||||
PageInfo<SaleSummaryInfoVo> pageInfo = new PageInfo<>(shopProdStatisticMapper.findSaleSummaryList(param));
|
||||
return PageUtil.convert(pageInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SaleSummaryInfoVo> summaryList(SaleSummaryCountParam param) {
|
||||
return shopProdStatisticMapper.findSaleSummaryList2(param);
|
||||
return shopProdStatisticMapper.findSaleSummaryList(param);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,9 +10,9 @@ import com.czg.order.service.ShopOrderStatisticService;
|
||||
import com.czg.service.order.mapper.ShopOrderStatisticMapper;
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
@@ -23,34 +23,54 @@ import java.util.List;
|
||||
* @since 2025-03-07
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class ShopOrderStatisticServiceImpl extends ServiceImpl<ShopOrderStatisticMapper, ShopOrderStatistic> implements ShopOrderStatisticService {
|
||||
@Resource
|
||||
private DataSummaryService dataSummaryService;
|
||||
|
||||
|
||||
@Override
|
||||
public void statistic() {
|
||||
// 获取前一天
|
||||
DateTime yesterday = DateUtil.yesterday();
|
||||
public void statistic(DateTime dateTime) {
|
||||
// 获取前一天的开始时间(00:00:00)
|
||||
DateTime startOfDay = DateUtil.beginOfDay(yesterday);
|
||||
DateTime startOfDay = DateUtil.beginOfDay(dateTime);
|
||||
// 获取前一天的结束时间(23:59:59)
|
||||
DateTime endOfDay = DateUtil.endOfDay(yesterday);
|
||||
DateTime endOfDay = DateUtil.endOfDay(dateTime);
|
||||
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);
|
||||
});
|
||||
List<List<Long>> split = CollUtil.split(shopIdList, 5);
|
||||
for (List<Long> splitIdList : split) {
|
||||
splitIdList.parallelStream().forEach(shopId -> {
|
||||
DataSummaryTradeParam param = new DataSummaryTradeParam();
|
||||
param.setShopId(shopId);
|
||||
param.setBeginDate(startOfDay.toStringDefaultTimeZone());
|
||||
param.setEndDate(endOfDay.toStringDefaultTimeZone());
|
||||
ShopOrderStatistic statistic = dataSummaryService.getRealTimeTradeData(param);
|
||||
statistic.setShopId(shopId);
|
||||
statistic.setCreateDay(dateTime.toLocalDateTime().toLocalDate());
|
||||
statistic.setUpdateTime(LocalDateTime.now());
|
||||
if (statistic.getNewMemberCount() != 0L) {
|
||||
System.out.println("newMemberCount:" + statistic.getNewMemberCount());
|
||||
}
|
||||
// 如果没有订单和退款,则不更新数据,否则会产出很多数据
|
||||
if (statistic.getSaleCount() == 0
|
||||
&& statistic.getRefundCount() == 0
|
||||
&& statistic.getMemberPayCount() == 0
|
||||
&& statistic.getNewMemberCount() == 0
|
||||
) {
|
||||
log.info("店铺:{},{},没有要存档的订单统计数据", shopId, dateTime.toDateStr());
|
||||
} else {
|
||||
ShopOrderStatistic entity = getMapper().selectOneByQuery(query().eq(ShopOrderStatistic::getShopId, shopId).eq(ShopOrderStatistic::getCreateDay, dateTime.toDateStr()));
|
||||
if (entity != null) {
|
||||
statistic.setId(entity.getId());
|
||||
updateById(statistic);
|
||||
} else {
|
||||
save(statistic);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,35 +1,41 @@
|
||||
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 com.czg.order.entity.OrderDetail;
|
||||
import com.czg.order.service.OrderDetailService;
|
||||
import cn.hutool.core.util.NumberUtil;
|
||||
import com.czg.order.entity.ShopProdStatistic;
|
||||
import com.czg.order.param.DataSummaryProductSaleParam;
|
||||
import com.czg.order.service.DataSummaryService;
|
||||
import com.czg.order.service.ShopProdStatisticService;
|
||||
import com.czg.order.vo.DataSummaryProductSaleRankingVo;
|
||||
import com.czg.service.order.mapper.ShopProdStatisticMapper;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import com.czg.order.entity.ShopProdStatistic;
|
||||
import com.czg.order.service.ShopProdStatisticService;
|
||||
import com.czg.service.order.mapper.ShopProdStatisticMapper;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.Data;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 服务层实现。
|
||||
* 服务层实现。
|
||||
*
|
||||
* @author zs
|
||||
* @since 2025-03-07
|
||||
*/
|
||||
@Service
|
||||
public class ShopProdStatisticServiceImpl extends ServiceImpl<ShopProdStatisticMapper, ShopProdStatistic> implements ShopProdStatisticService{
|
||||
@Slf4j
|
||||
public class ShopProdStatisticServiceImpl extends ServiceImpl<ShopProdStatisticMapper, ShopProdStatistic> implements ShopProdStatisticService {
|
||||
@Resource
|
||||
private OrderDetailService orderDetailService;
|
||||
private DataSummaryService dataSummaryService;
|
||||
@Resource
|
||||
private ShopProdStatisticMapper shopProdStatisticMapper;
|
||||
|
||||
@Data
|
||||
private static class StatisticTask{
|
||||
private static class StatisticTask {
|
||||
private BigDecimal successCount = BigDecimal.ZERO;
|
||||
private BigDecimal successAmount = BigDecimal.ZERO;
|
||||
private BigDecimal refundCount = BigDecimal.ZERO;
|
||||
@@ -37,57 +43,42 @@ public class ShopProdStatisticServiceImpl extends ServiceImpl<ShopProdStatisticM
|
||||
}
|
||||
|
||||
@Override
|
||||
public void statistic() {
|
||||
// 获取前一天
|
||||
DateTime yesterday = DateUtil.yesterday();
|
||||
public void statistic(DateTime dateTime) {
|
||||
// 获取前一天的开始时间(00:00:00)
|
||||
DateTime startOfDay = DateUtil.beginOfDay(yesterday);
|
||||
DateTime startOfDay = DateUtil.beginOfDay(dateTime);
|
||||
// 获取前一天的结束时间(23:59:59)
|
||||
DateTime endOfDay = DateUtil.endOfDay(yesterday);
|
||||
|
||||
List<OrderDetail> orderDetails = orderDetailService.list(new QueryWrapper()
|
||||
.ge(OrderDetail::getCreateTime, startOfDay)
|
||||
.le(OrderDetail::getCreateTime, endOfDay)
|
||||
.ne(OrderDetail::getStatus, "wait-pay"));
|
||||
|
||||
|
||||
HashMap<Long, Map<Long, StatisticTask>> countInfo = new HashMap<>();
|
||||
for (OrderDetail item : orderDetails) {
|
||||
Map<Long, StatisticTask> map = countInfo.computeIfAbsent(item.getShopId(), k -> new HashMap<>());
|
||||
StatisticTask statisticTask = map.get(item.getProductId());
|
||||
if (statisticTask == null) {
|
||||
map.put(item.getProductId(), statisticTask = new StatisticTask());
|
||||
}
|
||||
if ("refunding".equals(item.getStatus()) || "refund".equals(item.getStatus()) || "part-refund".equals(item.getStatus())) {
|
||||
statisticTask.setRefundAmount(statisticTask.getRefundAmount().add(item.getReturnAmount()));
|
||||
statisticTask.setRefundCount(statisticTask.getRefundCount().add(item.getRefundNum()));
|
||||
if (item.getReturnNum().compareTo(item.getNum()) < 0) {
|
||||
statisticTask.setSuccessAmount(statisticTask.getSuccessAmount().add(item.getPayAmount().subtract(item.getReturnAmount())));
|
||||
statisticTask.setSuccessCount(statisticTask.getSuccessCount().add(item.getNum().subtract(item.getReturnAmount())));
|
||||
}
|
||||
}else {
|
||||
statisticTask.setSuccessCount(statisticTask.getSuccessCount().add(item.getNum()));
|
||||
statisticTask.setSuccessAmount(statisticTask.getSuccessAmount().add(item.getPayAmount()));
|
||||
}
|
||||
DateTime endOfDay = DateUtil.endOfDay(dateTime);
|
||||
List<Long> shopIdList = dataSummaryService.getShopIdList();
|
||||
if (CollUtil.isEmpty(shopIdList)) {
|
||||
return;
|
||||
}
|
||||
List<List<Long>> split = CollUtil.split(shopIdList, 5);
|
||||
for (List<Long> splitIdList : split) {
|
||||
splitIdList.parallelStream().forEach(shopId -> {
|
||||
DataSummaryProductSaleParam param = new DataSummaryProductSaleParam();
|
||||
param.setShopId(shopId);
|
||||
param.setBeginDate(startOfDay.toStringDefaultTimeZone());
|
||||
param.setEndDate(endOfDay.toStringDefaultTimeZone());
|
||||
// 删除之前统计数据
|
||||
getMapper().deleteByQuery(QueryWrapper.create().eq(ShopProdStatistic::getShopId, shopId).eq(ShopProdStatistic::getCreateDay, dateTime.toDateStr()));
|
||||
// 重新统计数据
|
||||
List<DataSummaryProductSaleRankingVo> list = shopProdStatisticMapper.findProdRandingSummaryPage2(param);
|
||||
for (DataSummaryProductSaleRankingVo dto : list) {
|
||||
ShopProdStatistic entity = new ShopProdStatistic();
|
||||
entity.setProdId(dto.getProductId());
|
||||
entity.setSaleCount(dto.getNumber());
|
||||
entity.setSaleAmount(dto.getAmount());
|
||||
entity.setRefundCount(dto.getRefundCount());
|
||||
entity.setRefundAmount(dto.getRefundAmount());
|
||||
entity.setShopId(shopId);
|
||||
entity.setCreateDay(dateTime.toJdkDate());
|
||||
if (NumberUtil.isLessOrEqual(entity.getSaleCount(), BigDecimal.ZERO) && NumberUtil.isLessOrEqual(entity.getRefundCount(), BigDecimal.ZERO)) {
|
||||
log.info("店铺:{},{},没有要存档的商品统计数据", shopId, dateTime.toDateStr());
|
||||
} else {
|
||||
save(entity);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
countInfo.forEach((shopId, map) -> map.forEach((productId, statisticTask) -> {
|
||||
ShopProdStatistic statistic = getOne(new QueryWrapper().eq(ShopProdStatistic::getShopId, shopId).eq(ShopProdStatistic::getCreateDay, yesterday.toSqlDate()));
|
||||
if (statistic == null) {
|
||||
statistic = new ShopProdStatistic();
|
||||
statistic.setShopId(shopId);
|
||||
statistic.setCreateDay(yesterday.toSqlDate());
|
||||
}
|
||||
statistic.setProdId(productId);
|
||||
statistic.setSaleCount(statisticTask.getSuccessCount());
|
||||
statistic.setSaleAmount(statisticTask.getSuccessAmount());
|
||||
statistic.setRefundCount(statisticTask.getRefundCount());
|
||||
statistic.setRefundAmount(statisticTask.getRefundAmount());
|
||||
saveOrUpdate(statistic);
|
||||
}));
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,25 +1,26 @@
|
||||
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 com.czg.config.RedisCst;
|
||||
import com.czg.order.entity.OrderInfo;
|
||||
import com.czg.order.service.OrderInfoService;
|
||||
import com.czg.order.entity.ShopTableOrderStatistic;
|
||||
import com.czg.order.param.TableSummaryParam;
|
||||
import com.czg.order.service.DataSummaryService;
|
||||
import com.czg.order.service.ShopTableOrderStatisticService;
|
||||
import com.czg.order.vo.TableSummaryInfoVo;
|
||||
import com.czg.service.order.mapper.ShopTableOrderStatisticMapper;
|
||||
import com.czg.utils.PageUtil;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import com.czg.order.entity.ShopTableOrderStatistic;
|
||||
import com.czg.order.service.ShopTableOrderStatisticService;
|
||||
import com.czg.service.order.mapper.ShopTableOrderStatisticMapper;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.Data;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -29,35 +30,38 @@ import java.util.List;
|
||||
* @since 2025-03-07
|
||||
*/
|
||||
@Service
|
||||
public class ShopTableOrderStatisticServiceImpl extends ServiceImpl<ShopTableOrderStatisticMapper, ShopTableOrderStatistic> implements ShopTableOrderStatisticService{
|
||||
@Slf4j
|
||||
public class ShopTableOrderStatisticServiceImpl extends ServiceImpl<ShopTableOrderStatisticMapper, ShopTableOrderStatistic> implements ShopTableOrderStatisticService {
|
||||
@Resource
|
||||
private OrderInfoService orderInfoService;
|
||||
private DataSummaryService dataSummaryService;
|
||||
@Resource
|
||||
private ShopTableOrderStatisticMapper shopTableOrderStatisticMapper;
|
||||
|
||||
@Override
|
||||
public Page<ShopTableOrderStatistic> summary(Long shopId, String startTime, String endTime) {
|
||||
Page<Object> page = PageUtil.buildPage();
|
||||
PageHelper.startPage(Math.toIntExact(page.getPageNumber()),Math.toIntExact(page.getPageSize()));
|
||||
PageHelper.startPage(Math.toIntExact(page.getPageNumber()), Math.toIntExact(page.getPageSize()));
|
||||
return PageUtil.convert(new PageInfo<>(mapper.selectSummary(shopId, startTime, endTime)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addInfo(long shopId, long tableId, long count, BigDecimal amount) {
|
||||
ShopTableOrderStatistic statistic = getOne(new QueryWrapper().eq(ShopTableOrderStatistic::getShopId, shopId).eq(ShopTableOrderStatistic::getTableId, tableId)
|
||||
.eq(ShopTableOrderStatistic::getCreateDay, DateUtil.date().toDateStr()));
|
||||
if (statistic == null) {
|
||||
statistic = new ShopTableOrderStatistic();
|
||||
statistic.setShopId(shopId);
|
||||
statistic.setTableId(tableId);
|
||||
statistic.setCreateDay(DateUtil.date().toSqlDate());
|
||||
statistic.setOrderCount(count);
|
||||
statistic.setOrderAmount(amount);
|
||||
save(statistic);
|
||||
}
|
||||
return mapper.incrInfo(shopId, tableId, count, amount, DateUtil.date().toDateStr());
|
||||
ShopTableOrderStatistic statistic = getOne(new QueryWrapper().eq(ShopTableOrderStatistic::getShopId, shopId).eq(ShopTableOrderStatistic::getTableId, tableId)
|
||||
.eq(ShopTableOrderStatistic::getCreateDay, DateUtil.date().toDateStr()));
|
||||
if (statistic == null) {
|
||||
statistic = new ShopTableOrderStatistic();
|
||||
statistic.setShopId(shopId);
|
||||
statistic.setTableId(tableId);
|
||||
statistic.setCreateDay(DateUtil.date().toSqlDate());
|
||||
statistic.setOrderCount(count);
|
||||
statistic.setOrderAmount(amount);
|
||||
save(statistic);
|
||||
}
|
||||
return mapper.incrInfo(shopId, tableId, count, amount, DateUtil.date().toDateStr());
|
||||
}
|
||||
|
||||
@Data
|
||||
private static class StatisticTask{
|
||||
private static class StatisticTask {
|
||||
private long successCount = 0;
|
||||
private BigDecimal successAmount = BigDecimal.ZERO;
|
||||
private long refundCount = 0;
|
||||
@@ -65,53 +69,46 @@ public class ShopTableOrderStatisticServiceImpl extends ServiceImpl<ShopTableOrd
|
||||
}
|
||||
|
||||
@Override
|
||||
public void statistic() {
|
||||
// 获取前一天
|
||||
DateTime yesterday = DateUtil.yesterday();
|
||||
|
||||
public void statistic(DateTime dateTime) {
|
||||
// 获取前一天的开始时间(00:00:00)
|
||||
DateTime startOfDay = DateUtil.beginOfDay(yesterday);
|
||||
|
||||
DateTime startOfDay = DateUtil.beginOfDay(dateTime);
|
||||
// 获取前一天的结束时间(23:59:59)
|
||||
DateTime endOfDay = DateUtil.endOfDay(yesterday);
|
||||
List<OrderInfo> orderInfos = orderInfoService.list(new QueryWrapper()
|
||||
.ge(OrderInfo::getCreateTime, startOfDay)
|
||||
.le(OrderInfo::getCreateTime, endOfDay)
|
||||
.ne(OrderInfo::getStatus, "unpaid").ne(OrderInfo::getStatus, "cancelled"));
|
||||
|
||||
HashMap<Long, StatisticTask> countInfo = new HashMap<>();
|
||||
for (OrderInfo item : orderInfos) {
|
||||
StatisticTask statisticTask = countInfo.get(item.getShopId());
|
||||
if (statisticTask == null) {
|
||||
countInfo.put(item.getShopId(), statisticTask = new StatisticTask());
|
||||
}
|
||||
if ("refunding".equals(item.getStatus()) || "refund".equals(item.getStatus()) || "part-refund".equals(item.getStatus())) {
|
||||
statisticTask.setRefundAmount(statisticTask.getRefundAmount().add(item.getRefundAmount()));
|
||||
statisticTask.setRefundCount(statisticTask.getRefundCount() + 1);
|
||||
if (item.getRefundAmount().compareTo(item.getPayAmount()) < 0) {
|
||||
statisticTask.setSuccessAmount(statisticTask.getSuccessAmount().add(item.getPayAmount().subtract(item.getRefundAmount())));
|
||||
}
|
||||
}else {
|
||||
statisticTask.setSuccessCount(statisticTask.getSuccessCount() + 1);
|
||||
statisticTask.setSuccessAmount(statisticTask.getSuccessAmount().add(item.getPayAmount()));
|
||||
}
|
||||
DateTime endOfDay = DateUtil.endOfDay(dateTime);
|
||||
List<Long> shopIdList = dataSummaryService.getShopIdList();
|
||||
if (CollUtil.isEmpty(shopIdList)) {
|
||||
return;
|
||||
}
|
||||
List<List<Long>> split = CollUtil.split(shopIdList, 5);
|
||||
for (List<Long> splitIdList : split) {
|
||||
splitIdList.parallelStream().forEach(shopId -> {
|
||||
TableSummaryParam param = new TableSummaryParam();
|
||||
param.setShopId(shopId);
|
||||
param.setBeginDate(startOfDay.toStringDefaultTimeZone());
|
||||
param.setEndDate(endOfDay.toStringDefaultTimeZone());
|
||||
// 删除之前统计数据
|
||||
getMapper().deleteByQuery(QueryWrapper.create().eq(ShopTableOrderStatistic::getShopId, shopId).eq(ShopTableOrderStatistic::getCreateDay, dateTime.toDateStr()));
|
||||
// 重新统计数据
|
||||
List<TableSummaryInfoVo> list = shopTableOrderStatisticMapper.findSummaryList2(param);
|
||||
for (TableSummaryInfoVo dto : list) {
|
||||
ShopTableOrderStatistic entity = new ShopTableOrderStatistic();
|
||||
entity.setTableId(dto.getTableId());
|
||||
entity.setTableCode(dto.getTableCode());
|
||||
entity.setTableName(dto.getTableName());
|
||||
entity.setAreaName(dto.getAreaName());
|
||||
entity.setOrderCount(dto.getOrderCount());
|
||||
entity.setOrderAmount(dto.getOrderAmount());
|
||||
entity.setRefundCount(dto.getRefundCount());
|
||||
entity.setRefundAmount(dto.getRefundAmount());
|
||||
entity.setShopId(shopId);
|
||||
entity.setCreateDay(dateTime.toJdkDate());
|
||||
if (entity.getOrderCount() == 0L && entity.getRefundCount() == 0L) {
|
||||
log.info("店铺:{},{},没有要存档的台桌统计数据", shopId, dateTime.toDateStr());
|
||||
} else {
|
||||
save(entity);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
countInfo.forEach((shopId, statisticTask) -> {
|
||||
ShopTableOrderStatistic statistic = getOne(new QueryWrapper().eq(ShopTableOrderStatistic::getShopId, shopId).eq(ShopTableOrderStatistic::getCreateDay, yesterday.toSqlDate()));
|
||||
if (statistic == null) {
|
||||
statistic = new ShopTableOrderStatistic();
|
||||
statistic.setShopId(shopId);
|
||||
statistic.setTableId(0L);
|
||||
statistic.setCreateDay(yesterday.toSqlDate());
|
||||
}
|
||||
statistic.setOrderCount(statisticTask.getSuccessCount());
|
||||
statistic.setOrderAmount(statisticTask.getSuccessAmount());
|
||||
statistic.setRefundCount(statisticTask.getRefundCount());
|
||||
statistic.setRefundAmount(statisticTask.getRefundAmount());
|
||||
saveOrUpdate(statistic);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ public class TableSummaryServiceImpl implements TableSummaryService {
|
||||
|
||||
@Override
|
||||
public List<TableSummaryInfoVo> summaryList(TableSummaryParam param) {
|
||||
return shopTableOrderStatisticMapper.findSummaryList2(param);
|
||||
return shopTableOrderStatisticMapper.findSummaryList(param);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -17,7 +17,8 @@
|
||||
<foreach item="day" collection="days" open="(" separator="," close=")">
|
||||
#{day}
|
||||
</foreach>
|
||||
group by t1.prod_id
|
||||
group by t1.prod_id,t2.name
|
||||
order by sum(t1.sale_count) desc
|
||||
</select>
|
||||
<select id="getSaleSummaryCount" resultType="com.czg.order.vo.SaleSummaryCountVo">
|
||||
select
|
||||
@@ -146,10 +147,12 @@
|
||||
t1.product_id,
|
||||
t1.product_name,
|
||||
sum(t1.num) as number,
|
||||
sum(t1.pay_amount) as amount
|
||||
sum(t1.pay_amount) as amount,
|
||||
sum(t1.return_num) AS refundCount,
|
||||
sum(t1.return_amount) AS refundAmount
|
||||
from tb_order_detail t1
|
||||
where t1.shop_id = #{shopId}
|
||||
and t1.status = 'done'
|
||||
and t1.status in ('part-refund','refund','done')
|
||||
<if test="beginDate != null and beginDate != ''">
|
||||
and t1.create_time >= str_to_date(#{beginDate}, '%Y-%m-%d %H:%i:%s')
|
||||
</if>
|
||||
|
||||
@@ -28,9 +28,10 @@
|
||||
</select>
|
||||
<select id="findSummaryList" resultType="com.czg.order.vo.TableSummaryInfoVo">
|
||||
select
|
||||
t1.table_code,
|
||||
t1.table_id,
|
||||
ifnull(t3.name,'N/A') as area_name,
|
||||
ifnull(t2.name,'N/A') as table_name,
|
||||
t1.table_name as table_name,
|
||||
t1.area_name as area_name,
|
||||
sum(t1.order_count) as order_count,
|
||||
sum(t1.order_amount) as order_amount,
|
||||
ifnull(sum(t1.refund_count),0) as refund_count,
|
||||
@@ -45,12 +46,13 @@
|
||||
<if test="endDate != null and endDate != ''">
|
||||
and t1.create_day <= str_to_date(#{endDate}, '%Y-%m-%d')
|
||||
</if>
|
||||
group by t1.table_id
|
||||
order by sum(t1.order_count) desc,max(t1.id) desc
|
||||
group by t1.table_code
|
||||
order by sum(t1.order_count) desc,sum(t1.order_amount) desc
|
||||
</select>
|
||||
<select id="findSummaryList2" resultType="com.czg.order.vo.TableSummaryInfoVo">
|
||||
SELECT
|
||||
t1.table_code,
|
||||
t2.id as table_id,
|
||||
ifnull(t2.NAME,t1.table_code) AS table_name,
|
||||
ifnull(t3.NAME,'未知') AS area_name,
|
||||
count( t1.id ) AS order_count,
|
||||
@@ -80,8 +82,8 @@
|
||||
SELECT
|
||||
t.product_name,
|
||||
date_format(t.create_time, '%Y-%m-%d') as create_date,
|
||||
if(t.table_name = '11111111','银收客',t.table_name) as table_name,
|
||||
concat(if(t.table_name = '11111111','银收客',t.table_name),'-',date_format(t.create_time, '%Y-%m-%d')) as tableConcatDate,
|
||||
if(t.table_name = 'NONE','银收客',t.table_name) as table_name,
|
||||
concat(if(t.table_name = 'NONE','银收客',t.table_name),'-',date_format(t.create_time, '%Y-%m-%d')) as tableConcatDate,
|
||||
t.category_name,
|
||||
t.unit_name,
|
||||
group_concat(distinct t.sku_name SEPARATOR ';') as sku_name,
|
||||
@@ -95,7 +97,7 @@
|
||||
SELECT
|
||||
t1.product_id,
|
||||
t2.table_code,
|
||||
IF(t2.table_code is null or t2.table_code = '' or t6.NAME is null, '11111111', t6.NAME) AS table_name,
|
||||
IF(t2.table_code is null or t2.table_code = '' or t6.NAME is null, 'NONE', t6.NAME) AS table_name,
|
||||
t1.create_time,
|
||||
t4.NAME AS category_name,
|
||||
t3.name as product_name,
|
||||
|
||||
Reference in New Issue
Block a user