Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -8,6 +8,8 @@ import com.czg.order.vo.DataSummaryPayTypeVo;
|
||||
import com.czg.order.vo.DataSummaryProductSaleRankingVo;
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 数据统计Service接口
|
||||
*
|
||||
@@ -24,4 +26,5 @@ public interface DataSummaryService {
|
||||
|
||||
DataSummaryPayTypeVo getSummaryPayTypeData(Long shopId, Integer day);
|
||||
|
||||
List<Long> getShopIdList();
|
||||
}
|
||||
|
||||
@@ -28,4 +28,6 @@ public interface ShopOrderStatisticMapper extends BaseMapper<ShopOrderStatistic>
|
||||
BigDecimal getCustomerUnitPrice(DataSummaryTradeParam param);
|
||||
|
||||
BigDecimal getTableTurnoverRate(DataSummaryTradeParam param);
|
||||
|
||||
List<Long> getShopIdList();
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ public class FeiPrinter extends PrinterHandler implements PrinterImpl {
|
||||
|
||||
PrintInfoDTO printInfoDTO = new PrintInfoDTO().setShopName(shopInfo.getShopName())
|
||||
.setPrintType("普通打印").setPickupNum(getPickupNum(orderInfo))
|
||||
.setOrderNo(orderInfo.getOrderNo()).setTradeDate(DateUtil.date().toDateStr()).setOperator("【POS-1】001").setPayAmount(orderInfo.getPayAmount().toPlainString())
|
||||
.setOrderNo(orderInfo.getOrderNo()).setTradeDate(DateUtil.format(orderInfo.getCreateTime(), "yyyy-MM-dd HH:mm:ss")).setOperator("【POS-1】001").setPayAmount(orderInfo.getPayAmount().toPlainString())
|
||||
.setOriginalAmount(orderInfo.getOriginAmount().toPlainString()).setReturn(isReturn(orderInfo))
|
||||
.setBalance(balance).setPayType((ObjectUtil.isEmpty(orderInfo.getPayType()) || ObjectUtil.isNull(orderInfo.getPayType()) ? "" : orderInfo.getPayType())).setIntegral("0")
|
||||
.setOutNumber(orderInfo.getTakeCode()).setPrintTitle("结算单")
|
||||
@@ -116,7 +116,7 @@ public class FeiPrinter extends PrinterHandler implements PrinterImpl {
|
||||
|
||||
PrintInfoDTO printInfoDTO = new PrintInfoDTO().setShopName(shopInfo.getShopName())
|
||||
.setPrintType("普通打印").setPickupNum(getPickupNum(orderInfo))
|
||||
.setOrderNo(orderInfo.getOrderNo()).setTradeDate(DateUtil.date().toDateStr()).setOperator("【POS-1】001").setPayAmount(orderInfo.getPayAmount().toPlainString())
|
||||
.setOrderNo(orderInfo.getOrderNo()).setTradeDate(DateUtil.format(orderInfo.getCreateTime(), "yyyy-MM-dd HH:mm:ss")).setOperator("【POS-1】001").setPayAmount(orderInfo.getPayAmount().toPlainString())
|
||||
.setOriginalAmount(orderInfo.getOriginAmount().toPlainString()).setReturn(isReturn(orderInfo))
|
||||
.setBalance(balance).setPayType((ObjectUtil.isEmpty(orderInfo.getPayType()) || ObjectUtil.isNull(orderInfo.getPayType()) ? "" : orderInfo.getPayType())).setIntegral("0")
|
||||
.setOutNumber(orderInfo.getTakeCode()).setPrintTitle(isPre ? "预结算单" : "结算单")
|
||||
|
||||
@@ -149,8 +149,17 @@ public abstract class PrinterHandler {
|
||||
.eq(PrintMachine::getShopId, shopId)
|
||||
.eq(PrintMachine::getSubType, subType)
|
||||
.eq(PrintMachine::getConnectionType, "网络");
|
||||
|
||||
if (StrUtil.isNotEmpty(printMethod)) {
|
||||
wrapper.in(PrintMachine::getPrintMethod, Arrays.asList(printMethod, "all"));
|
||||
List<String> arrayList = switch (printMethod) {
|
||||
case "all" ->Arrays.asList("one", "normal", "all");
|
||||
case "one" -> Arrays.asList("one", "all");
|
||||
case "normal" -> Arrays.asList("normal", "all");
|
||||
default -> new ArrayList<>();
|
||||
};
|
||||
if (!arrayList.isEmpty()) {
|
||||
wrapper.in(PrintMachine::getPrintMethod, arrayList);
|
||||
}
|
||||
}
|
||||
if ("callTicket".equals(printType)) {
|
||||
printType = "queue";
|
||||
|
||||
@@ -134,7 +134,7 @@ public class YxyPrinter extends PrinterHandler implements PrinterImpl {
|
||||
protected void returnOrderPrint(OrderInfo orderInfo, PrintMachine machine, String balance, List<OrderDetail> detailList) {
|
||||
ShopInfo shopInfo = shopInfoService.getById(orderInfo.getShopId());
|
||||
PrintInfoDTO printInfoDTO = new PrintInfoDTO().setShopName(shopInfo.getShopName()).setPrintType("普通打印").setPickupNum(getPickupNum(orderInfo))
|
||||
.setOrderNo(orderInfo.getOrderNo()).setTradeDate(DateUtil.date().toDateStr()).setOperator("【POS-1】001").setPayAmount(orderInfo.getPayAmount().toPlainString())
|
||||
.setOrderNo(orderInfo.getOrderNo()).setTradeDate(DateUtil.format(orderInfo.getCreateTime(), "yyyy-MM-dd HH:mm:ss")).setOperator("【POS-1】001").setPayAmount(orderInfo.getPayAmount().toPlainString())
|
||||
.setOriginalAmount(orderInfo.getOriginAmount().toPlainString()).setReturn(isReturn(orderInfo))
|
||||
.setBalance(balance).setPayType((ObjectUtil.isEmpty(orderInfo.getPayType()) || ObjectUtil.isNull(orderInfo.getPayType()) ? "" : orderInfo.getPayType())).setIntegral("0")
|
||||
.setOutNumber(orderInfo.getTakeCode()).setPrintTitle("结算单")
|
||||
@@ -156,7 +156,7 @@ public class YxyPrinter extends PrinterHandler implements PrinterImpl {
|
||||
protected void normalOrderPrint(OrderInfo orderInfo, boolean isPre, PrintMachine machine, String balance, List<OrderDetail> detailList) {
|
||||
ShopInfo shopInfo = shopInfoService.getById(orderInfo.getShopId());
|
||||
PrintInfoDTO printInfoDTO = new PrintInfoDTO().setShopName(shopInfo.getShopName()).setPrintType("普通打印").setPickupNum(getPickupNum(orderInfo))
|
||||
.setOrderNo(orderInfo.getOrderNo()).setTradeDate(DateUtil.date().toDateStr()).setOperator("【POS-1】001").setPayAmount(orderInfo.getPayAmount().toPlainString())
|
||||
.setOrderNo(orderInfo.getOrderNo()).setTradeDate(DateUtil.format(orderInfo.getCreateTime(), "yyyy-MM-dd HH:mm:ss")).setOperator("【POS-1】001").setPayAmount(orderInfo.getPayAmount().toPlainString())
|
||||
.setOriginalAmount(orderInfo.getOriginAmount().toPlainString()).setReturn(isReturn(orderInfo))
|
||||
.setBalance(balance).setPayType((ObjectUtil.isEmpty(orderInfo.getPayType()) || ObjectUtil.isNull(orderInfo.getPayType()) ? "" : orderInfo.getPayType())).setIntegral("0")
|
||||
.setOutNumber(orderInfo.getTakeCode()).setPrintTitle(isPre ? "预结算单" : "结算单")
|
||||
|
||||
@@ -87,6 +87,7 @@ public class DataSummaryServiceImpl implements DataSummaryService {
|
||||
data.setMemberPayAmount(sum1.getOrDefault("orderPay", BigDecimal.ZERO).abs());
|
||||
data.setMemberPayCount(count1.getOrDefault("orderPay", 0L));
|
||||
data.setSaleAmount(NumberUtil.add(data.getWechatPayAmount(), data.getAliPayAmount(), data.getScanPayAmount(), data.getCashPayAmount(), data.getCreditPayAmount()));
|
||||
data.setSaleCount(NumberUtil.add(data.getWechatPayCount(), data.getAliPayCount(), data.getScanPayCount(), data.getCashPayCount(), data.getCreditPayCount()).longValue());
|
||||
BigDecimal refundAmount = list.stream().filter(item -> item.get("payType") != null).map(item -> Convert.toBigDecimal(item.get("refund"), BigDecimal.ZERO)).reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
data.setRefundAmount(refundAmount);
|
||||
long refundCount = list.stream().filter(item -> item.get("payType") != null).map(item -> Convert.toLong(item.get("refundCount"), 0L)).reduce(0L, Long::sum);
|
||||
@@ -203,4 +204,9 @@ public class DataSummaryServiceImpl implements DataSummaryService {
|
||||
data.setCountPayType(total);
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Long> getShopIdList() {
|
||||
return shopOrderStatisticMapper.getShopIdList();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,33 +1,20 @@
|
||||
package com.czg.service.order.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.date.DateTime;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import com.czg.account.entity.ShopTable;
|
||||
import com.czg.account.entity.ShopUserFlow;
|
||||
import com.czg.account.service.ShopTableService;
|
||||
import com.czg.account.service.ShopUserFlowService;
|
||||
import com.czg.order.entity.OrderInfo;
|
||||
import com.czg.order.entity.ShopOrderStatistic;
|
||||
import com.czg.order.service.OrderInfoService;
|
||||
import com.czg.order.param.DataSummaryTradeParam;
|
||||
import com.czg.order.service.DataSummaryService;
|
||||
import com.czg.order.service.ShopOrderStatisticService;
|
||||
import com.czg.service.order.mapper.ShopOrderStatisticMapper;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.dubbo.config.annotation.DubboReference;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 服务层实现。
|
||||
@@ -38,11 +25,7 @@ import java.util.stream.Collectors;
|
||||
@Service
|
||||
public class ShopOrderStatisticServiceImpl extends ServiceImpl<ShopOrderStatisticMapper, ShopOrderStatistic> implements ShopOrderStatisticService {
|
||||
@Resource
|
||||
private OrderInfoService orderInfoService;
|
||||
@DubboReference
|
||||
private ShopUserFlowService shopUserFlowService;
|
||||
@DubboReference
|
||||
private ShopTableService shopTableService;
|
||||
private DataSummaryService dataSummaryService;
|
||||
|
||||
|
||||
@Override
|
||||
@@ -53,108 +36,21 @@ public class ShopOrderStatisticServiceImpl extends ServiceImpl<ShopOrderStatisti
|
||||
DateTime startOfDay = DateUtil.beginOfDay(yesterday);
|
||||
// 获取前一天的结束时间(23:59:59)
|
||||
DateTime endOfDay = DateUtil.endOfDay(yesterday);
|
||||
List<OrderInfo> orderInfos = orderInfoService.list(new QueryWrapper()
|
||||
.ge(OrderInfo::getPaidTime, startOfDay)
|
||||
.le(OrderInfo::getPaidTime, endOfDay)
|
||||
.ne(OrderInfo::getStatus, "unpaid").ne(OrderInfo::getStatus, "cancelled"));
|
||||
|
||||
// 统计充值记录
|
||||
Map<Long, BigDecimal> flowMap = shopUserFlowService.list(new QueryWrapper()
|
||||
.ge(ShopUserFlow::getCreateTime, startOfDay.toLocalDateTime())
|
||||
.le(ShopUserFlow::getCreateTime, endOfDay.toLocalDateTime())
|
||||
.in(ShopUserFlow::getBizCode, CollUtil.newArrayList("cashIn", "wechatIn", "alipayIn", "awardIn"))).stream()
|
||||
.collect(Collectors.groupingBy(
|
||||
ShopUserFlow::getShopId,
|
||||
Collectors.reducing(
|
||||
BigDecimal.ZERO,
|
||||
ShopUserFlow::getAmount,
|
||||
BigDecimal::add
|
||||
)
|
||||
));
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
BigDecimal bigDecimal = flowMap.get(item.getShopId());
|
||||
if (bigDecimal != null) {
|
||||
statisticTask.setRechargeAmount(bigDecimal);
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
List<Long> shopIdList = dataSummaryService.getShopIdList();
|
||||
if (CollUtil.isEmpty(shopIdList)) {
|
||||
return;
|
||||
}
|
||||
|
||||
countInfo.forEach((shopId, info) -> {
|
||||
ShopOrderStatistic statistic = getOne(new QueryWrapper().eq(ShopOrderStatistic::getShopId, shopId).eq(ShopOrderStatistic::getCreateDay, yesterday.toSqlDate()));
|
||||
if (statistic == null) {
|
||||
statistic = new ShopOrderStatistic();
|
||||
statistic.setShopId(shopId);
|
||||
statistic.setCreateDay(LocalDate.now());
|
||||
}
|
||||
BigDecimal totalAmount = statistic.getSaleAmount().add(statistic.getRefundAmount());
|
||||
BigDecimal totalCount = BigDecimal.valueOf(statistic.getSaleCount() + statistic.getRefundCount());
|
||||
// 充值金额
|
||||
// statistic.setRechargeAmount(BigDecimal.ZERO);
|
||||
//客单价
|
||||
if (totalAmount.compareTo(BigDecimal.ZERO) != 0) {
|
||||
statistic.setCustomerUnitPrice(totalAmount.divide(totalCount, 2, RoundingMode.DOWN));
|
||||
}
|
||||
|
||||
// 查询台桌数量
|
||||
long count = shopTableService.count(new QueryWrapper().eq(ShopTable::getShopId, shopId));
|
||||
|
||||
//翻台率
|
||||
if (count > 0) {
|
||||
statistic.setTableTurnoverRate(totalCount.subtract(BigDecimal.valueOf(count)).divide(BigDecimal.valueOf(count), 2, RoundingMode.DOWN).multiply(BigDecimal.valueOf(100)));
|
||||
}
|
||||
statistic.setUpdateTime(LocalDateTime.now());
|
||||
BeanUtil.copyProperties(info, statistic);
|
||||
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);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -120,4 +120,7 @@
|
||||
]]>
|
||||
</if>
|
||||
</select>
|
||||
<select id="getShopIdList" resultType="java.lang.Long">
|
||||
select id from tb_shop_info order by id
|
||||
</select>
|
||||
</mapper>
|
||||
|
||||
Reference in New Issue
Block a user