Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package com.czg.service.order.mapper;
|
||||
|
||||
import com.czg.order.vo.OrderDetailPrintVo;
|
||||
import com.mybatisflex.core.BaseMapper;
|
||||
import com.czg.order.entity.OrderDetail;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
@@ -14,4 +15,7 @@ import java.util.List;
|
||||
*/
|
||||
public interface OrderDetailMapper extends BaseMapper<OrderDetail> {
|
||||
void createOrderDetails(@Param("orderId") Long orderId,@Param("orderDetails") List<OrderDetail> orderDetails);
|
||||
|
||||
|
||||
List<OrderDetailPrintVo> getOrderDetailPrint(Long orderId);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.czg.service.order.mapper;
|
||||
import com.czg.account.vo.HandoverCategoryListVo;
|
||||
import com.czg.account.vo.HandoverProductListVo;
|
||||
import com.czg.order.entity.OrderInfo;
|
||||
import com.czg.order.vo.OrderDetailPrintVo;
|
||||
import com.mybatisflex.core.BaseMapper;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.czg.service.order.mapper;
|
||||
|
||||
import com.mybatisflex.core.BaseMapper;
|
||||
import com.czg.order.entity.ShopOrderStatistic;
|
||||
|
||||
/**
|
||||
* 映射层。
|
||||
*
|
||||
* @author zs
|
||||
* @since 2025-03-07
|
||||
*/
|
||||
public interface ShopOrderStatisticMapper extends BaseMapper<ShopOrderStatistic> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.czg.service.order.mapper;
|
||||
|
||||
import com.mybatisflex.core.BaseMapper;
|
||||
import com.czg.order.entity.ShopProdStatistic;
|
||||
|
||||
/**
|
||||
* 映射层。
|
||||
*
|
||||
* @author zs
|
||||
* @since 2025-03-07
|
||||
*/
|
||||
public interface ShopProdStatisticMapper extends BaseMapper<ShopProdStatistic> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.czg.service.order.mapper;
|
||||
|
||||
import com.mybatisflex.core.BaseMapper;
|
||||
import com.czg.order.entity.ShopTableOrderStatistic;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 台桌订单统计表 映射层。
|
||||
*
|
||||
* @author zs
|
||||
* @since 2025-03-07
|
||||
*/
|
||||
public interface ShopTableOrderStatisticMapper extends BaseMapper<ShopTableOrderStatistic> {
|
||||
|
||||
List<ShopTableOrderStatistic> selectSummary(Long shopId, String startTime, String endTime);
|
||||
|
||||
boolean incrInfo(long shopId, long tableId, long count, BigDecimal amount, String dateStr);
|
||||
|
||||
}
|
||||
@@ -1,11 +1,11 @@
|
||||
package com.czg.service.order.service.impl;
|
||||
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import com.czg.order.entity.OrderDetail;
|
||||
import com.czg.order.service.OrderDetailService;
|
||||
import com.czg.order.vo.OrderDetailPrintVo;
|
||||
import com.czg.service.order.mapper.OrderDetailMapper;
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import org.apache.dubbo.config.annotation.DubboService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -15,12 +15,16 @@ import java.util.List;
|
||||
* @author ww
|
||||
* @since 2025-02-13
|
||||
*/
|
||||
@Service
|
||||
@DubboService
|
||||
public class OrderDetailServiceImpl extends ServiceImpl<OrderDetailMapper, OrderDetail> implements OrderDetailService{
|
||||
public class OrderDetailServiceImpl extends ServiceImpl<OrderDetailMapper, OrderDetail> implements OrderDetailService {
|
||||
|
||||
@Override
|
||||
public void createOrderDetails(Long orderId, List<OrderDetail> orderDetails) {
|
||||
getMapper().createOrderDetails(orderId, orderDetails);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<OrderDetailPrintVo> getOrderDetailPrint(Long orderId) {
|
||||
return getMapper().getOrderDetailPrint(orderId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@ import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.dubbo.config.annotation.DubboReference;
|
||||
import org.apache.dubbo.config.annotation.DubboService;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
@@ -33,7 +32,6 @@ import java.util.*;
|
||||
* @since 2025-02-28 11:29
|
||||
*/
|
||||
@DubboService
|
||||
@Service
|
||||
@Slf4j
|
||||
public class OrderInfoRpcServiceImpl implements OrderInfoRpcService {
|
||||
|
||||
|
||||
@@ -26,9 +26,7 @@ import com.czg.order.service.CashierCartService;
|
||||
import com.czg.order.service.OrderDetailService;
|
||||
import com.czg.order.service.OrderInfoService;
|
||||
import com.czg.order.service.OrderPaymentService;
|
||||
import com.czg.order.vo.HistoryOrderVo;
|
||||
import com.czg.order.vo.OrderDetailSmallVO;
|
||||
import com.czg.order.vo.OrderInfoVo;
|
||||
import com.czg.order.vo.*;
|
||||
import com.czg.resp.CzgResult;
|
||||
import com.czg.service.RedisService;
|
||||
import com.czg.service.order.enums.OrderStatusEnums;
|
||||
@@ -36,6 +34,7 @@ import com.czg.service.order.mapper.OrderInfoMapper;
|
||||
import com.czg.utils.AssertUtil;
|
||||
import com.czg.utils.CzgStrUtils;
|
||||
import com.czg.utils.PageUtil;
|
||||
import com.mybatisflex.core.BaseMapper;
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import com.mybatisflex.core.update.UpdateChain;
|
||||
@@ -134,6 +133,24 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
|
||||
return CzgResult.success(historyOrder(orderId, null));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CzgResult<HistoryOrderPrintVo> getOrderByIdPrint(Long orderId) {
|
||||
HistoryOrderPrintVo historyOrderVo = getOneAs(new QueryWrapper()
|
||||
.eq(OrderInfo::getId, orderId), HistoryOrderPrintVo.class);
|
||||
List<OrderDetailPrintVo> orderDetails = orderDetailService.getOrderDetailPrint(orderId);
|
||||
Map<String, List<OrderDetailPrintVo>> resultMap = new HashMap<>();
|
||||
// 遍历订单详情列表
|
||||
for (OrderDetailPrintVo orderDetail : orderDetails) {
|
||||
orderDetail.initGift();
|
||||
// 获取当前订单详情的 placeNum
|
||||
Integer placeNum = orderDetail.getPlaceNum();
|
||||
// 检查 Map 中是否已经存在该 placeNum 对应的列表
|
||||
resultMap.computeIfAbsent(placeNum.toString(), k -> new ArrayList<>()).add(orderDetail);
|
||||
}
|
||||
historyOrderVo.setDetailMap(resultMap);
|
||||
return CzgResult.success(historyOrderVo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HistoryOrderVo historyOrder(Long orderId, String tableCode) {
|
||||
if (orderId == null && StrUtil.isBlank(tableCode)) {
|
||||
@@ -643,6 +660,7 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
|
||||
private OrderInfo initOrderInfo(OrderInfoAddDTO param, ShopInfo shopInfo, ShopTable table) {
|
||||
OrderInfo orderInfo = new OrderInfo();
|
||||
if (param.getOrderId() != null) {
|
||||
orderInfo.setUserId(param.getUserId());
|
||||
orderInfo = getById(param.getOrderId());
|
||||
if (!OrderStatusEnums.UNPAID.getCode().equals(orderInfo.getStatus())) {
|
||||
throw new ValidateException("生成订单失败,订单已结束,请重新下单");
|
||||
@@ -709,6 +727,9 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
|
||||
} else {
|
||||
orderInfo.setDiscountRatio(BigDecimal.ZERO);
|
||||
}
|
||||
if (orderInfo.getOrderAmount().compareTo(BigDecimal.ZERO) == 0) {
|
||||
orderInfo.setStatus(OrderStatusEnums.DONE.getCode());
|
||||
}
|
||||
saveOrUpdate(orderInfo);
|
||||
}
|
||||
|
||||
|
||||
@@ -42,6 +42,7 @@ import com.mybatisflex.core.update.UpdateChain;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.NonNull;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.dubbo.config.annotation.DubboReference;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@@ -51,11 +52,15 @@ import java.time.LocalDateTime;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* @author ww
|
||||
* @description
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class PayServiceImpl implements PayService {
|
||||
|
||||
@@ -99,9 +104,6 @@ public class PayServiceImpl implements PayService {
|
||||
private OrderInfo checkPay(CheckOrderPay checkOrderPay) {
|
||||
OrderInfo orderInfo = orderInfoService.checkOrderPay(checkOrderPay);
|
||||
if (orderInfo.getOrderAmount().compareTo(BigDecimal.ZERO) == 0) {
|
||||
orderInfoService.upOrderInfo(orderInfo, orderInfo.getOrderAmount(),
|
||||
LocalDateTime.now(), null, PayEnums.CASH_PAY);
|
||||
redisService.del(RedisCst.classKeyExpired.EXPIRED_ORDER + orderInfo.getId());
|
||||
throw new PaySuccessException();
|
||||
}
|
||||
return orderInfo;
|
||||
@@ -473,7 +475,7 @@ public class PayServiceImpl implements PayService {
|
||||
shopUserService.updateMoney(shopUser.getShopId(), shopUserMoneyEditDTO);
|
||||
userFlowService.updateRefund(inFlow.getId(), refPayParam.getRefAmount());
|
||||
if (giftFlow != null) {
|
||||
userFlowService.updateRefund( giftFlow.getId(), giftFlow.getAmount());
|
||||
userFlowService.updateRefund(giftFlow.getId(), giftFlow.getAmount());
|
||||
}
|
||||
//移除优惠券
|
||||
inRecordService.remove(QueryWrapper.create()
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
package com.czg.service.order.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.date.DateTime;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.czg.order.entity.OrderInfo;
|
||||
import com.czg.order.service.OrderInfoService;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import com.czg.order.entity.ShopOrderStatistic;
|
||||
import com.czg.order.service.ShopOrderStatisticService;
|
||||
import com.czg.service.order.mapper.ShopOrderStatisticMapper;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 服务层实现。
|
||||
*
|
||||
* @author zs
|
||||
* @since 2025-03-07
|
||||
*/
|
||||
@Service
|
||||
public class ShopOrderStatisticServiceImpl extends ServiceImpl<ShopOrderStatisticMapper, ShopOrderStatistic> implements ShopOrderStatisticService {
|
||||
@Resource
|
||||
private OrderInfoService orderInfoService;
|
||||
|
||||
|
||||
@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<OrderInfo> orderInfos = orderInfoService.list(new QueryWrapper()
|
||||
.ge(OrderInfo::getCreateTime, startOfDay)
|
||||
.le(OrderInfo::getCreateTime, endOfDay)
|
||||
.ne(OrderInfo::getStatus, "unpaid").ne(OrderInfo::getStatus, "cancelled"));
|
||||
|
||||
HashMap<Long, ShopOrderStatistic> countInfo = new HashMap<>();
|
||||
for (OrderInfo item : orderInfos) {
|
||||
ShopOrderStatistic statisticTask = countInfo.get(item.getShopId());
|
||||
if (statisticTask == null) {
|
||||
countInfo.put(item.getShopId(), statisticTask = new ShopOrderStatistic());
|
||||
}
|
||||
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.setSaleAmount(statisticTask.getSaleAmount().add(item.getPayAmount().subtract(item.getRefundAmount())));
|
||||
}
|
||||
} else {
|
||||
statisticTask.setSaleCount(statisticTask.getSaleCount() + 1);
|
||||
statisticTask.setSaleAmount(statisticTask.getSaleAmount().add(item.getPayAmount()));
|
||||
}
|
||||
|
||||
switch (item.getPayType()) {
|
||||
case "wechat-mini":
|
||||
statisticTask.setWechatPayAmount(statisticTask.getWechatPayAmount().add(item.getPayAmount()));
|
||||
statisticTask.setWechatPayCount(statisticTask.getWechatPayCount() + 1);
|
||||
break;
|
||||
case "main-scan", "back-scan":
|
||||
statisticTask.setScanPayAmount(statisticTask.getScanPayAmount().add(item.getPayAmount()));
|
||||
statisticTask.setScanPayCount(statisticTask.getScanPayCount() + 1);
|
||||
break;
|
||||
case "alipay-mini":
|
||||
statisticTask.setAliPayAmount(statisticTask.getAliPayAmount().add(item.getPayAmount()));
|
||||
statisticTask.setAliPayCount(statisticTask.getAliPayCount() + 1);
|
||||
break;
|
||||
case "vip-pay":
|
||||
statisticTask.setMemberPayAmount(statisticTask.getMemberPayAmount().add(item.getPayAmount()));
|
||||
statisticTask.setMemberPayCount(statisticTask.getMemberPayCount() + 1);
|
||||
break;
|
||||
case "credit-pay":
|
||||
statisticTask.setCreditPayAmount(statisticTask.getCreditPayAmount().add(item.getPayAmount()));
|
||||
statisticTask.setCreditPayCount(statisticTask.getCreditPayCount() + 1);
|
||||
break;
|
||||
case "cash-pay":
|
||||
statisticTask.setCashPayAmount(statisticTask.getCashPayAmount().add(item.getPayAmount()));
|
||||
statisticTask.setCashPayCount(statisticTask.getCashPayCount() + 1);
|
||||
|
||||
}
|
||||
|
||||
countInfo.forEach((shopId, info) -> {
|
||||
ShopOrderStatistic statistic = getOne(new QueryWrapper().eq(ShopOrderStatistic::getShopId, shopId).eq(ShopOrderStatistic::getCreateDay, yesterday.toSqlDate()));
|
||||
if (statistic == null) {
|
||||
statistic = new ShopOrderStatistic();
|
||||
}
|
||||
BeanUtil.copyProperties(info, statistic);
|
||||
saveOrUpdate(statistic);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
package com.czg.service.order.service.impl;
|
||||
|
||||
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 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 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{
|
||||
@Resource
|
||||
private OrderDetailService orderDetailService;
|
||||
@Data
|
||||
private static class StatisticTask{
|
||||
private BigDecimal successCount = BigDecimal.ZERO;
|
||||
private BigDecimal successAmount = BigDecimal.ZERO;
|
||||
private BigDecimal refundCount = BigDecimal.ZERO;
|
||||
private BigDecimal refundAmount = BigDecimal.ZERO;
|
||||
}
|
||||
|
||||
@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<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()));
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
package com.czg.service.order.service.impl;
|
||||
|
||||
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.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 org.springframework.stereotype.Service;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 台桌订单统计表 服务层实现。
|
||||
*
|
||||
* @author zs
|
||||
* @since 2025-03-07
|
||||
*/
|
||||
@Service
|
||||
public class ShopTableOrderStatisticServiceImpl extends ServiceImpl<ShopTableOrderStatisticMapper, ShopTableOrderStatistic> implements ShopTableOrderStatisticService{
|
||||
@Resource
|
||||
private OrderInfoService orderInfoService;
|
||||
|
||||
@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()));
|
||||
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());
|
||||
}
|
||||
|
||||
@Data
|
||||
private static class StatisticTask{
|
||||
private long successCount = 0;
|
||||
private BigDecimal successAmount = BigDecimal.ZERO;
|
||||
private long refundCount = 0;
|
||||
private BigDecimal refundAmount = BigDecimal.ZERO;
|
||||
}
|
||||
|
||||
@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<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()));
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
@@ -22,4 +22,10 @@
|
||||
now(), now())
|
||||
</foreach>
|
||||
</insert>
|
||||
<select id="getOrderDetailPrint" resultType="com.czg.order.vo.OrderDetailPrintVo">
|
||||
select detail.*, product.category_id as categoryId
|
||||
from tb_order_detail detail
|
||||
left join tb_product product on product.id = detail.product_id
|
||||
where order_id = #{orderId}
|
||||
</select>
|
||||
</mapper>
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.czg.service.order.mapper.ShopOrderStatisticMapper">
|
||||
|
||||
</mapper>
|
||||
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.czg.service.order.mapper.ShopProdStatisticMapper">
|
||||
|
||||
</mapper>
|
||||
@@ -0,0 +1,29 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.czg.service.order.mapper.ShopTableOrderStatisticMapper">
|
||||
<update id="incrInfo">
|
||||
update tb_shop_table_order_statistic set order_count=order_count + #{count}, order_amount=order_amount + #{count}
|
||||
where shop_id = #{shopId} and table_id = #{tableId} and create_day=#{date}
|
||||
</update>
|
||||
|
||||
<select id="selectSummary" resultType="com.czg.order.entity.ShopTableOrderStatistic">
|
||||
SELECT
|
||||
a.table_id as tableId, b.name as name, sum(a.order_count) as orderCount, sum(a.order_amount) as orderAmount
|
||||
FROM
|
||||
tb_shop_table_order_statistic as a
|
||||
left join tb_shop_table as b on a.table_id = b.id
|
||||
WHERE
|
||||
a.shop_id = #{shopId}
|
||||
<if test="startTime != null and startTime != ''">
|
||||
AND a.create_day >= #{startTime}
|
||||
</if>
|
||||
<if test="endTime != null and endTime != ''">
|
||||
and a.create_day <= #{endTime}
|
||||
</if>
|
||||
GROUP BY
|
||||
a.table_id
|
||||
order by a.id desc
|
||||
</select>
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user