经营日报/日结单
This commit is contained in:
@@ -141,6 +141,8 @@ public class ShopOrderStatistic implements Serializable {
|
|||||||
*/
|
*/
|
||||||
@ExcelProperty("现金支付金额")
|
@ExcelProperty("现金支付金额")
|
||||||
private BigDecimal cashPayAmount;
|
private BigDecimal cashPayAmount;
|
||||||
|
@ExcelIgnore
|
||||||
|
private BigDecimal cashPayAmountOriginal;
|
||||||
/**
|
/**
|
||||||
* 现金支付笔数
|
* 现金支付笔数
|
||||||
*/
|
*/
|
||||||
@@ -151,6 +153,8 @@ public class ShopOrderStatistic implements Serializable {
|
|||||||
*/
|
*/
|
||||||
@ExcelProperty("微信小程序支付金额")
|
@ExcelProperty("微信小程序支付金额")
|
||||||
private BigDecimal wechatPayAmount;
|
private BigDecimal wechatPayAmount;
|
||||||
|
@ExcelIgnore
|
||||||
|
private BigDecimal wechatPayAmountOriginal;
|
||||||
/**
|
/**
|
||||||
* 微信小程序支付笔数
|
* 微信小程序支付笔数
|
||||||
*/
|
*/
|
||||||
@@ -161,6 +165,8 @@ public class ShopOrderStatistic implements Serializable {
|
|||||||
*/
|
*/
|
||||||
@ExcelProperty("支付宝小程序支付金额")
|
@ExcelProperty("支付宝小程序支付金额")
|
||||||
private BigDecimal alipayPayAmount;
|
private BigDecimal alipayPayAmount;
|
||||||
|
@ExcelIgnore
|
||||||
|
private BigDecimal alipayPayAmountOriginal;
|
||||||
/**
|
/**
|
||||||
* 支付宝小程序支付笔数
|
* 支付宝小程序支付笔数
|
||||||
*/
|
*/
|
||||||
@@ -171,6 +177,8 @@ public class ShopOrderStatistic implements Serializable {
|
|||||||
*/
|
*/
|
||||||
@ExcelProperty("扫码收款金额")
|
@ExcelProperty("扫码收款金额")
|
||||||
private BigDecimal backScanPayAmount;
|
private BigDecimal backScanPayAmount;
|
||||||
|
@ExcelIgnore
|
||||||
|
private BigDecimal backScanPayAmountOriginal;
|
||||||
/**
|
/**
|
||||||
* 被扫收款笔数
|
* 被扫收款笔数
|
||||||
*/
|
*/
|
||||||
@@ -181,6 +189,8 @@ public class ShopOrderStatistic implements Serializable {
|
|||||||
*/
|
*/
|
||||||
@ExcelProperty("二维码收款金额")
|
@ExcelProperty("二维码收款金额")
|
||||||
private BigDecimal mainScanPayAmount;
|
private BigDecimal mainScanPayAmount;
|
||||||
|
@ExcelIgnore
|
||||||
|
private BigDecimal mainScanPayAmountOriginal;
|
||||||
/**
|
/**
|
||||||
* 二维码收款笔数
|
* 二维码收款笔数
|
||||||
*/
|
*/
|
||||||
@@ -191,6 +201,8 @@ public class ShopOrderStatistic implements Serializable {
|
|||||||
*/
|
*/
|
||||||
@ExcelProperty("挂账支付金额")
|
@ExcelProperty("挂账支付金额")
|
||||||
private BigDecimal creditPayAmount;
|
private BigDecimal creditPayAmount;
|
||||||
|
@ExcelIgnore
|
||||||
|
private BigDecimal creditPayAmountOriginal;
|
||||||
/**
|
/**
|
||||||
* 挂账支付笔数
|
* 挂账支付笔数
|
||||||
*/
|
*/
|
||||||
@@ -202,6 +214,8 @@ public class ShopOrderStatistic implements Serializable {
|
|||||||
*/
|
*/
|
||||||
@ExcelProperty("会员消费金额")
|
@ExcelProperty("会员消费金额")
|
||||||
private BigDecimal memberPayAmount;
|
private BigDecimal memberPayAmount;
|
||||||
|
@ExcelIgnore
|
||||||
|
private BigDecimal memberPayAmountOriginal;
|
||||||
/**
|
/**
|
||||||
* 会员消费笔数
|
* 会员消费笔数
|
||||||
*/
|
*/
|
||||||
@@ -221,6 +235,9 @@ public class ShopOrderStatistic implements Serializable {
|
|||||||
*/
|
*/
|
||||||
@ExcelProperty("订单退款金额")
|
@ExcelProperty("订单退款金额")
|
||||||
private BigDecimal refundAmount;
|
private BigDecimal refundAmount;
|
||||||
|
|
||||||
|
@ExcelIgnore
|
||||||
|
private Long refundCount;
|
||||||
@ExcelProperty("订单挂账退款金额")
|
@ExcelProperty("订单挂账退款金额")
|
||||||
private BigDecimal creditRefundAmount;
|
private BigDecimal creditRefundAmount;
|
||||||
/**
|
/**
|
||||||
@@ -389,12 +406,63 @@ public class ShopOrderStatistic implements Serializable {
|
|||||||
@ExcelProperty("净利润率(%)")
|
@ExcelProperty("净利润率(%)")
|
||||||
private BigDecimal netProfitRate;
|
private BigDecimal netProfitRate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 抖音团购
|
||||||
|
*/
|
||||||
@ExcelIgnore
|
@ExcelIgnore
|
||||||
private BigDecimal douyinGroup;
|
private BigDecimal douyinGroup;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 美团团购
|
||||||
|
*/
|
||||||
@ExcelIgnore
|
@ExcelIgnore
|
||||||
private BigDecimal meituanGroup;
|
private BigDecimal meituanGroup;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 整单退款数量
|
||||||
|
*/
|
||||||
|
@ExcelIgnore
|
||||||
|
private Long refundAllNum;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 整单退款金额
|
||||||
|
*/
|
||||||
|
@ExcelIgnore
|
||||||
|
private BigDecimal refundAllAmount;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 单菜品退款数量
|
||||||
|
*/
|
||||||
|
@ExcelIgnore
|
||||||
|
private Long refundItemNum;
|
||||||
|
/**
|
||||||
|
* 单菜品退款金额
|
||||||
|
*/
|
||||||
|
@ExcelIgnore
|
||||||
|
private BigDecimal refundItemAmount;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 折扣订单数量
|
||||||
|
*/
|
||||||
|
@ExcelIgnore
|
||||||
|
private Long discountOrderNum;
|
||||||
|
/**
|
||||||
|
* 折扣订单金额
|
||||||
|
*/
|
||||||
|
@ExcelIgnore
|
||||||
|
private BigDecimal discountOrderAmount;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 待支付订单数量
|
||||||
|
*/
|
||||||
|
@ExcelIgnore
|
||||||
|
private Long unpaidOrderNum;
|
||||||
|
/**
|
||||||
|
* 待支付订单金额
|
||||||
|
*/
|
||||||
|
@ExcelIgnore
|
||||||
|
private BigDecimal unpaidOrderAmount;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建时间
|
* 创建时间
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -208,9 +208,22 @@ public interface ShopOrderStatisticMapper extends BaseMapper<ShopOrderStatistic>
|
|||||||
" SUM(CASE WHEN pay_type = 'cash_pay' THEN pay_amount ELSE 0 END) AS cashPayAmount," +
|
" SUM(CASE WHEN pay_type = 'cash_pay' THEN pay_amount ELSE 0 END) AS cashPayAmount," +
|
||||||
" SUM(CASE WHEN pay_type = 'credit_pay' THEN pay_amount ELSE 0 END) AS creditPayAmount," +
|
" SUM(CASE WHEN pay_type = 'credit_pay' THEN pay_amount ELSE 0 END) AS creditPayAmount," +
|
||||||
" SUM(CASE WHEN pay_type = 'free_pay' THEN order_amount ELSE 0 END) AS backDiscountAmount," +
|
" SUM(CASE WHEN pay_type = 'free_pay' THEN order_amount ELSE 0 END) AS backDiscountAmount," +
|
||||||
|
|
||||||
|
" SUM(CASE WHEN pay_type = 'main_scan' THEN pay_amount ELSE 0 END) AS mainScanPayAmountOriginal," +
|
||||||
|
" SUM(CASE WHEN pay_type = 'back_scan' THEN pay_amount ELSE 0 END) AS backScanPayAmountOriginal," +
|
||||||
|
" SUM(CASE WHEN pay_type = 'wechat_mini' THEN pay_amount ELSE 0 END) AS wechatPayAmountOriginal," +
|
||||||
|
" SUM(CASE WHEN pay_type = 'alipay_mini' THEN pay_amount ELSE 0 END) AS alipayPayAmountOriginal," +
|
||||||
|
" SUM(CASE WHEN pay_type = 'vip_pay' THEN pay_amount ELSE 0 END) AS memberPayAmountOriginal," +
|
||||||
|
" SUM(CASE WHEN pay_type = 'cash_pay' THEN pay_amount ELSE 0 END) AS cashPayAmountOriginal," +
|
||||||
|
" SUM(CASE WHEN pay_type = 'credit_pay' THEN pay_amount ELSE 0 END) AS creditPayAmountOriginal," +
|
||||||
" " +
|
" " +
|
||||||
" SUM(CASE WHEN pay_type = 'vip_pay' THEN refund_amount ELSE 0 END) AS memberRefundAmount," +
|
" SUM(CASE WHEN pay_type = 'vip_pay' THEN refund_amount ELSE 0 END) AS memberRefundAmount," +
|
||||||
" SUM(CASE WHEN pay_type = 'credit_pay' THEN refund_amount ELSE 0 END) AS creditRefundAmount," +
|
" SUM(CASE WHEN pay_type = 'credit_pay' THEN refund_amount ELSE 0 END) AS creditRefundAmount," +
|
||||||
|
|
||||||
|
" SUM(CASE WHEN status = 'refund' THEN refund_amount ELSE 0 END) AS refundAllAmount," +
|
||||||
|
" SUM(CASE WHEN status = 'refund' THEN 1 ELSE 0 END) AS refundAllNum," +
|
||||||
|
" SUM(CASE WHEN discount_all_amount>0 THEN 1 ELSE 0 END) AS discountOrderNum," +
|
||||||
|
" SUM(CASE WHEN discount_all_amount>0 THEN discount_all_amount ELSE 0 END) AS discountOrderAmount," +
|
||||||
" " +
|
" " +
|
||||||
" SUM(CASE WHEN pay_type = 'vip_pay' THEN 1 ELSE 0 END) as memberPayCount," +
|
" SUM(CASE WHEN pay_type = 'vip_pay' THEN 1 ELSE 0 END) as memberPayCount," +
|
||||||
" SUM(CASE WHEN pay_type = 'cash_pay' THEN 1 ELSE 0 END) as cashPayCount," +
|
" SUM(CASE WHEN pay_type = 'cash_pay' THEN 1 ELSE 0 END) as cashPayCount," +
|
||||||
@@ -221,6 +234,7 @@ public interface ShopOrderStatisticMapper extends BaseMapper<ShopOrderStatistic>
|
|||||||
" SUM(CASE WHEN pay_type = 'credit_pay' THEN 1 ELSE 0 END) as creditPayCount," +
|
" SUM(CASE WHEN pay_type = 'credit_pay' THEN 1 ELSE 0 END) as creditPayCount," +
|
||||||
" " +
|
" " +
|
||||||
" IFNULL(SUM(refund_amount), 0) as refundAmount," +
|
" IFNULL(SUM(refund_amount), 0) as refundAmount," +
|
||||||
|
" SUM(CASE WHEN refund_amount > 0 THEN 1 END) AS refundCount," +
|
||||||
" SUM(CASE WHEN refund_type = 'cash' or pay_type = 'cash_pay' THEN refund_amount ELSE 0 END) as cashRefundAmount," +
|
" SUM(CASE WHEN refund_type = 'cash' or pay_type = 'cash_pay' THEN refund_amount ELSE 0 END) as cashRefundAmount," +
|
||||||
" " +
|
" " +
|
||||||
" IFNULL(SUM(new_customer_discount_amount), 0) as newCustomerDiscountAmount," +
|
" IFNULL(SUM(new_customer_discount_amount), 0) as newCustomerDiscountAmount," +
|
||||||
@@ -239,6 +253,35 @@ public interface ShopOrderStatisticMapper extends BaseMapper<ShopOrderStatistic>
|
|||||||
"and paid_time is not null")
|
"and paid_time is not null")
|
||||||
ShopOrderStatistic getOrderStatSingleDate(Long shopId, LocalDate tradeDay);
|
ShopOrderStatistic getOrderStatSingleDate(Long shopId, LocalDate tradeDay);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统计待支付数据 当日实时数据/昨日数据落地
|
||||||
|
*/
|
||||||
|
@Select("SELECT " +
|
||||||
|
" SUM(CASE WHEN origin_amount > 0 THEN origin_amount ELSE 0 END) AS unpaidOrderAmount, " +
|
||||||
|
" SUM(CASE WHEN origin_amount > 0 THEN 1 ELSE 0 END) AS unpaidOrderNum " +
|
||||||
|
"FROM " +
|
||||||
|
" tb_order_info " +
|
||||||
|
"WHERE " +
|
||||||
|
" shop_id = #{shopId} " +
|
||||||
|
" AND status = 'unpaid'" +
|
||||||
|
" AND trade_day = #{tradeDay} ;")
|
||||||
|
ShopOrderStatistic getUnpaidOrder(Long shopId, LocalDate tradeDay);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统计退菜
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Select("SELECT" +
|
||||||
|
" sum(CASE WHEN detail.refund_num then detail.refund_num else 0 end) as refundItemNum," +
|
||||||
|
" sum(CASE WHEN detail.return_amount>0 then 1 else 0 end) as refundItemAmount " +
|
||||||
|
" FROM" +
|
||||||
|
" tb_order_info `order`" +
|
||||||
|
" INNER JOIN tb_order_detail detail ON `order`.id = detail.order_id" +
|
||||||
|
" WHERE" +
|
||||||
|
" `order`.shop_id = #{shopId}" +
|
||||||
|
" AND `order`.trade_day = #{tradeDay}" +
|
||||||
|
" AND `order`.paid_time IS NOT NULL")
|
||||||
|
ShopOrderStatistic getRefundItem(Long shopId, LocalDate tradeDay);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 统计某日用户用户余额数据 当日实时数据/昨日数据落地
|
* 统计某日用户用户余额数据 当日实时数据/昨日数据落地
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package com.czg.service.order.print;
|
|||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.alibaba.fastjson2.JSONObject;
|
import com.alibaba.fastjson2.JSONObject;
|
||||||
|
import com.alibaba.fastjson2.TypeReference;
|
||||||
import com.czg.account.dto.HandoverRecordDTO;
|
import com.czg.account.dto.HandoverRecordDTO;
|
||||||
import com.czg.account.entity.PrintMachine;
|
import com.czg.account.entity.PrintMachine;
|
||||||
import com.czg.account.entity.ShopInfo;
|
import com.czg.account.entity.ShopInfo;
|
||||||
@@ -196,14 +197,20 @@ public class PrintConfig implements ApplicationRunner {
|
|||||||
.stockPrint(machine, shopInfo.getShopName(), JSONObject.parseObject(data.toJSONString(), StockPrintDTO.class)));
|
.stockPrint(machine, shopInfo.getShopName(), JSONObject.parseObject(data.toJSONString(), StockPrintDTO.class)));
|
||||||
break;
|
break;
|
||||||
case PrinterHandler.PrintTypeEnum.DAY_REPORT:
|
case PrinterHandler.PrintTypeEnum.DAY_REPORT:
|
||||||
getPrintMachine(shopId, printTypeEnum)
|
Map<String, DayReportPrintDTO> map1 = data.to(new TypeReference<>() {
|
||||||
.forEach(machine -> getPrinter(machine.getBrand())
|
});
|
||||||
.dayReportPrint(machine, shopInfo.getShopName(), JSONObject.parseObject(data.toJSONString(), DayReportPrintDTO.class)));
|
for (PrintMachine machine : getPrintMachine(shopId, printTypeEnum)) {
|
||||||
|
PrinterHandler printer = getPrinter(machine.getBrand());
|
||||||
|
map1.forEach((day, value) -> printer.dayReportPrint(machine, shopInfo.getShopName(), value));
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case PrinterHandler.PrintTypeEnum.DAY_ORDER:
|
case PrinterHandler.PrintTypeEnum.DAY_ORDER:
|
||||||
getPrintMachine(shopId, printTypeEnum)
|
Map<String, DaySettlePrintDTO> map2 = data.to(new TypeReference<>() {
|
||||||
.forEach(machine -> getPrinter(machine.getBrand())
|
});
|
||||||
.daySettlePrint(machine, shopInfo.getShopName(), JSONObject.parseObject(data.toJSONString(), DaySettlePrintDTO.class)));
|
for (PrintMachine machine : getPrintMachine(shopId, printTypeEnum)) {
|
||||||
|
PrinterHandler printer = getPrinter(machine.getBrand());
|
||||||
|
map2.forEach((day, value) -> printer.daySettlePrint(machine, shopInfo.getShopName(), value));
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case PrinterHandler.PrintTypeEnum.PRODUCT_REPORT:
|
case PrinterHandler.PrintTypeEnum.PRODUCT_REPORT:
|
||||||
getPrintMachine(shopId, printTypeEnum)
|
getPrintMachine(shopId, printTypeEnum)
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package com.czg.service.order.service.impl;
|
package com.czg.service.order.service.impl;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.hutool.core.date.LocalDateTimeUtil;
|
import cn.hutool.core.date.LocalDateTimeUtil;
|
||||||
|
import cn.hutool.core.util.NumberUtil;
|
||||||
import com.czg.config.RabbitPublisher;
|
import com.czg.config.RabbitPublisher;
|
||||||
import com.czg.excel.ExcelExportUtil;
|
import com.czg.excel.ExcelExportUtil;
|
||||||
import com.czg.exception.CzgException;
|
import com.czg.exception.CzgException;
|
||||||
@@ -16,9 +18,14 @@ import jakarta.annotation.Resource;
|
|||||||
import jakarta.servlet.http.HttpServletResponse;
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.math.RoundingMode;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.stream.LongStream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author yjjie
|
* @author yjjie
|
||||||
@@ -104,24 +111,195 @@ public class FinanceStsServiceImpl implements FinanceStsService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void printDayReport(SaleSummaryCountParam param) {
|
public void printDayReport(SaleSummaryCountParam param) {
|
||||||
DayReportPrintDTO dayReportPrintDTO = new DayReportPrintDTO();
|
Map<String, DayReportPrintDTO> dayReportMap = buildDayReportPrint(param);
|
||||||
|
if (CollUtil.isEmpty(dayReportMap)) {
|
||||||
|
throw new CzgException("无可打印数据");
|
||||||
|
}
|
||||||
// 打印经营日报
|
// 打印经营日报
|
||||||
rabbitPublisher.sendOtherPrintMsg(param.getShopId(), dayReportPrintDTO, "DAY_REPORT");
|
rabbitPublisher.sendOtherPrintMsg(param.getShopId(), dayReportMap, "DAY_REPORT");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void printDaySettle(SaleSummaryCountParam param) {
|
public void printDaySettle(SaleSummaryCountParam param) {
|
||||||
|
Map<String, DaySettlePrintDTO> daySettleMap = buildDaySettlePrint(param);
|
||||||
|
if (CollUtil.isEmpty(daySettleMap)) {
|
||||||
|
throw new CzgException("无可打印数据");
|
||||||
|
}
|
||||||
// 打印日结单
|
// 打印日结单
|
||||||
rabbitPublisher.sendOtherPrintMsg(param.getShopId(), buildDaySettlePrint(param), "DAY_ORDER");
|
rabbitPublisher.sendOtherPrintMsg(param.getShopId(), daySettleMap, "DAY_ORDER");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private Map<String, DayReportPrintDTO> buildDayReportPrint(SaleSummaryCountParam param) {
|
private Map<String, DayReportPrintDTO> buildDayReportPrint(SaleSummaryCountParam param) {
|
||||||
return null;
|
Map<String, DayReportPrintDTO> dayReportMap = new HashMap<>();
|
||||||
|
if (param.getBeginDate() != null && param.getEndDate() != null) {
|
||||||
|
// 计算相差天数
|
||||||
|
long days = java.time.temporal.ChronoUnit.DAYS.between(param.getBeginDate(), param.getEndDate());
|
||||||
|
List<LocalDate> dateList = LongStream.rangeClosed(0, days)
|
||||||
|
.mapToObj(param.getBeginDate()::plusDays)
|
||||||
|
.toList();
|
||||||
|
for (LocalDate localDate : dateList) {
|
||||||
|
DayReportPrintDTO dayReportPrintDTO = new DayReportPrintDTO();
|
||||||
|
FinanceStsQueryParam financeStsQueryParam = new FinanceStsQueryParam();
|
||||||
|
financeStsQueryParam.setQueryDate(localDate);
|
||||||
|
ShopOrderStatistic statisticData = getStatisticData(financeStsQueryParam);
|
||||||
|
// ====================== 核心:填充DTO ======================
|
||||||
|
// 1. 填充基础信息
|
||||||
|
dayReportPrintDTO.setStatisticsTime(localDate.toString());
|
||||||
|
dayReportPrintDTO.setOperator(param.getOperator());
|
||||||
|
|
||||||
|
|
||||||
|
// 2. 填充 营业统计 BusinessSts
|
||||||
|
DayReportPrintDTO.BusinessSts businessSts = new DayReportPrintDTO.BusinessSts();
|
||||||
|
businessSts.setOriginAmount(statisticData.getOriginAmount()); // 订单原价总额
|
||||||
|
businessSts.setTurnover(statisticData.getPayAmount()); // 营业额=实付金额
|
||||||
|
businessSts.setDiscountAmount(statisticData.getDiscountAmount()); // 优惠总金额
|
||||||
|
businessSts.setOrderCount(statisticData.getOrderCount()); // 订单总数
|
||||||
|
businessSts.setRefundAmount(statisticData.getRefundAmount()); // 退款金额
|
||||||
|
// 退款订单数 实体无直接字段,用refundCount/自定义计算
|
||||||
|
businessSts.setRefundOrderCount(statisticData.getRefundCount() == null ? 0L : statisticData.getRefundCount());
|
||||||
|
// 计算折前/折后单均价
|
||||||
|
businessSts.setAverageOrderAmount(calcAvg(statisticData.getOriginAmount(), statisticData.getOrderCount()));
|
||||||
|
businessSts.setAverageTurnover(calcAvg(statisticData.getPayAmount(), statisticData.getOrderCount()));
|
||||||
|
dayReportPrintDTO.setTurnover(businessSts);
|
||||||
|
|
||||||
|
// 3. 填充 收入来源(原价统计)sourceIncome
|
||||||
|
DayReportPrintDTO.Income sourceIncome = new DayReportPrintDTO.Income();
|
||||||
|
sourceIncome.setCash(statisticData.getCashPayAmount());
|
||||||
|
sourceIncome.setWechat(statisticData.getWechatPayAmount());
|
||||||
|
sourceIncome.setAlipay(statisticData.getAlipayPayAmount());
|
||||||
|
sourceIncome.setMeituan(statisticData.getMeituanGroup());
|
||||||
|
sourceIncome.setDouyin(statisticData.getDouyinGroup());
|
||||||
|
|
||||||
|
sourceIncome.setBarScan(statisticData.getBackScanPayAmount()); // 扫码收款
|
||||||
|
sourceIncome.setSelfScan(statisticData.getMainScanPayAmount()); // 二维码收款
|
||||||
|
sourceIncome.setOwed(statisticData.getCreditPayAmount()); // 挂账
|
||||||
|
sourceIncome.setBalance(statisticData.getMemberPayAmount()); // 余额支付
|
||||||
|
sourceIncome.setRecharge(statisticData.getRechargeAmount()); // 充值
|
||||||
|
// other 无对应字段设为0
|
||||||
|
sourceIncome.setOther(NumberUtil.add(sourceIncome.getBarScan(), sourceIncome.getSelfScan(), sourceIncome.getOwed(), sourceIncome.getBalance(), sourceIncome.getRecharge()));
|
||||||
|
dayReportPrintDTO.setSourceIncome(sourceIncome);
|
||||||
|
|
||||||
|
// 4. 填充 实收统计 actualIncome (和来源一致,按业务需求调整)
|
||||||
|
DayReportPrintDTO.Income actualIncome = new DayReportPrintDTO.Income();
|
||||||
|
actualIncome.setCash(statisticData.getCashPayAmount());
|
||||||
|
actualIncome.setWechat(statisticData.getWechatPayAmount());
|
||||||
|
actualIncome.setAlipay(statisticData.getAlipayPayAmount());
|
||||||
|
actualIncome.setBarScan(statisticData.getBackScanPayAmount());
|
||||||
|
actualIncome.setSelfScan(statisticData.getMainScanPayAmount());
|
||||||
|
actualIncome.setOwed(statisticData.getCreditPayAmount());
|
||||||
|
actualIncome.setBalance(statisticData.getMemberPayAmount());
|
||||||
|
actualIncome.setRecharge(statisticData.getRechargeAmount());
|
||||||
|
actualIncome.setMeituan(statisticData.getMeituanGroup());
|
||||||
|
actualIncome.setDouyin(statisticData.getDouyinGroup());
|
||||||
|
actualIncome.setOther(NumberUtil.add(actualIncome.getBarScan(), actualIncome.getSelfScan(), actualIncome.getOwed(), actualIncome.getBalance(), actualIncome.getRecharge()));
|
||||||
|
dayReportPrintDTO.setActualIncome(actualIncome);
|
||||||
|
|
||||||
|
// 5. 填充 优惠统计 DiscountSts
|
||||||
|
DayReportPrintDTO.DiscountSts discountSts = new DayReportPrintDTO.DiscountSts();
|
||||||
|
discountSts.setNewConsumerDiscount(statisticData.getNewCustomerDiscountAmount()); // 新客立减
|
||||||
|
discountSts.setFreeCashAmount(statisticData.getBackDiscountAmount()); // 霸王餐
|
||||||
|
discountSts.setFullMinusAmount(statisticData.getFullDiscountAmount()); // 满减
|
||||||
|
discountSts.setCouponAmount(statisticData.getCouponDiscountAmount()); // 优惠券
|
||||||
|
discountSts.setMemberDiscount(statisticData.getMemberDiscountAmount()); // 会员折扣
|
||||||
|
discountSts.setPointsDiscountAmount(statisticData.getPointDiscountAmount()); // 积分抵扣
|
||||||
|
discountSts.setOrderDiscount(statisticData.getOrderPriceDiscountAmount()); // 订单改价
|
||||||
|
dayReportPrintDTO.setDiscountSta(discountSts);
|
||||||
|
// 加入结果集
|
||||||
|
dayReportMap.put(localDate.toString(), dayReportPrintDTO);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return dayReportMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<String, DaySettlePrintDTO> buildDaySettlePrint(SaleSummaryCountParam param) {
|
private Map<String, DaySettlePrintDTO> buildDaySettlePrint(SaleSummaryCountParam param) {
|
||||||
return null;
|
Map<String, DaySettlePrintDTO> dayReportMap = new HashMap<>();
|
||||||
|
if (param.getBeginDate() != null && param.getEndDate() != null) {
|
||||||
|
// 计算相差天数
|
||||||
|
long days = java.time.temporal.ChronoUnit.DAYS.between(param.getBeginDate(), param.getEndDate());
|
||||||
|
List<LocalDate> dateList = LongStream.rangeClosed(0, days)
|
||||||
|
.mapToObj(param.getBeginDate()::plusDays)
|
||||||
|
.toList();
|
||||||
|
for (LocalDate localDate : dateList) {
|
||||||
|
DaySettlePrintDTO printDTO = new DaySettlePrintDTO();
|
||||||
|
FinanceStsQueryParam param1 = new FinanceStsQueryParam();
|
||||||
|
param1.setQueryDate(localDate);
|
||||||
|
ShopOrderStatistic data = getStatisticData(param1);
|
||||||
|
printDTO.setOperator(param.getOperator());
|
||||||
|
// ===================== 1.基础信息 =====================
|
||||||
|
printDTO.setStatisticsTime(localDate.toString());
|
||||||
|
// ===================== 2.营业统计 BusinessSts =====================
|
||||||
|
DaySettlePrintDTO.BusinessSts business = new DaySettlePrintDTO.BusinessSts();
|
||||||
|
business.setOriginAmount(data.getOriginAmount()); // 订单原价总额
|
||||||
|
business.setTurnover(data.getPayAmount()); // 营业额=实付金额
|
||||||
|
business.setDiscountAmount(data.getDiscountAmount()); // 优惠总金额
|
||||||
|
business.setOrderCount(data.getOrderCount()); // 订单总数
|
||||||
|
business.setRefundOrderCount(data.getRefundCount());
|
||||||
|
business.setRefundAmount(data.getRefundAmount()); // 退款金额
|
||||||
|
business.setCash(data.getCashPayAmount()); // 现金收款
|
||||||
|
|
||||||
|
printDTO.setTurnover(business);
|
||||||
|
|
||||||
|
// ===================== 3.收款构成 Income =====================
|
||||||
|
DaySettlePrintDTO.Income income = new DaySettlePrintDTO.Income();
|
||||||
|
income.setCash(data.getCashPayAmount()); // 现金
|
||||||
|
income.setWechat(data.getWechatPayAmount()); // 微信
|
||||||
|
income.setAlipay(data.getAlipayPayAmount()); // 支付宝
|
||||||
|
// 团购 = 美团 + 抖音
|
||||||
|
income.setGroup(NumberUtil.add(data.getMeituanGroup(), data.getDouyinGroup()));
|
||||||
|
printDTO.setIncome(income);
|
||||||
|
|
||||||
|
// ===================== 4.优惠统计 DiscountSts =====================
|
||||||
|
DaySettlePrintDTO.DiscountSts discount = new DaySettlePrintDTO.DiscountSts();
|
||||||
|
discount.setNewConsumerDiscount(data.getNewCustomerDiscountAmount()); // 新客立减
|
||||||
|
discount.setFreeCashAmount(data.getBackDiscountAmount()); // 霸王餐
|
||||||
|
discount.setFullMinusAmount(data.getFullDiscountAmount()); // 满减
|
||||||
|
discount.setCouponAmount(data.getCouponDiscountAmount()); // 优惠券
|
||||||
|
discount.setMemberDiscount(data.getMemberDiscountAmount()); // 会员折扣
|
||||||
|
discount.setPointsDiscountAmount(data.getPointDiscountAmount()); // 积分抵扣
|
||||||
|
discount.setOrderDiscount(data.getOrderPriceDiscountAmount()); // 订单改价
|
||||||
|
printDTO.setDiscountSta(discount);
|
||||||
|
|
||||||
|
// ===================== 5.敏感操作记录 OperationRecord =====================
|
||||||
|
List<DaySettlePrintDTO.OperationRecord> records = new ArrayList<>();
|
||||||
|
// 退单
|
||||||
|
records.add(new DaySettlePrintDTO.OperationRecord()
|
||||||
|
.setOperation("退单")
|
||||||
|
.setCount(data.getRefundAllNum() == null ? 0L : data.getRefundAllNum())
|
||||||
|
.setAmount(data.getRefundAllAmount()));
|
||||||
|
// 退菜
|
||||||
|
records.add(new DaySettlePrintDTO.OperationRecord()
|
||||||
|
.setOperation("退菜")
|
||||||
|
.setCount(data.getRefundItemNum() == null ? 0L : data.getRefundItemNum())
|
||||||
|
.setAmount(data.getRefundItemAmount()));
|
||||||
|
// 折扣
|
||||||
|
records.add(new DaySettlePrintDTO.OperationRecord()
|
||||||
|
.setOperation("折扣")
|
||||||
|
.setCount(data.getDiscountOrderNum() == null ? 0L : data.getDiscountOrderNum())
|
||||||
|
.setAmount(data.getDiscountOrderAmount()));
|
||||||
|
// 未结款
|
||||||
|
records.add(new DaySettlePrintDTO.OperationRecord()
|
||||||
|
.setOperation("未结款")
|
||||||
|
.setCount(data.getUnpaidOrderNum() == null ? 0L : data.getUnpaidOrderNum())
|
||||||
|
.setAmount(data.getUnpaidOrderAmount()));
|
||||||
|
printDTO.setOperationRecords(records);
|
||||||
|
|
||||||
|
// 加入结果
|
||||||
|
dayReportMap.put(localDate.toString(), printDTO);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return dayReportMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 计算平均值:金额 / 数量,空值安全处理
|
||||||
|
*/
|
||||||
|
private BigDecimal calcAvg(BigDecimal amount, Long count) {
|
||||||
|
if (amount == null || count == null || count == 0) {
|
||||||
|
return BigDecimal.ZERO;
|
||||||
|
}
|
||||||
|
return amount.divide(new BigDecimal(count), 2, RoundingMode.HALF_UP);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ShopOrderStatistic getStatisticData(FinanceStsQueryParam param) {
|
private ShopOrderStatistic getStatisticData(FinanceStsQueryParam param) {
|
||||||
|
|||||||
@@ -148,11 +148,12 @@ public class ShopOrderStatisticServiceImpl extends ServiceImpl<ShopOrderStatisti
|
|||||||
ShopOrderStatistic result = new ShopOrderStatistic();
|
ShopOrderStatistic result = new ShopOrderStatistic();
|
||||||
|
|
||||||
ShopOrderStatistic onlineStat = mapper.getOnlineStatSingleDate(shopId, day);
|
ShopOrderStatistic onlineStat = mapper.getOnlineStatSingleDate(shopId, day);
|
||||||
// log.info("onlineStat:{}", JSONObject.toJSONString(onlineStat));
|
|
||||||
ShopOrderStatistic orderStat = mapper.getOrderStatSingleDate(shopId, day);
|
ShopOrderStatistic orderStat = mapper.getOrderStatSingleDate(shopId, day);
|
||||||
// log.info("orderStat:{}", JSONObject.toJSONString(orderStat));
|
//待支付统计
|
||||||
|
ShopOrderStatistic unpaidOrder = mapper.getUnpaidOrder(shopId, day);
|
||||||
|
//退菜数量/金额
|
||||||
|
ShopOrderStatistic refundItem = mapper.getRefundItem(shopId, day);
|
||||||
ShopOrderStatistic userFlowStat = mapper.getShopUserFlowStatSingleDate(shopId, day);
|
ShopOrderStatistic userFlowStat = mapper.getShopUserFlowStatSingleDate(shopId, day);
|
||||||
// log.info("userFlowStat:{}", JSONObject.toJSONString(userFlowStat));
|
|
||||||
Long discountCount = mapper.countDiscountOrder(shopId, day);
|
Long discountCount = mapper.countDiscountOrder(shopId, day);
|
||||||
BigDecimal discountAmount = mapper.countDiscountAmount(shopId, day);
|
BigDecimal discountAmount = mapper.countDiscountAmount(shopId, day);
|
||||||
Long tableCount = mapper.countShopTable(shopId);
|
Long tableCount = mapper.countShopTable(shopId);
|
||||||
@@ -170,6 +171,14 @@ public class ShopOrderStatisticServiceImpl extends ServiceImpl<ShopOrderStatisti
|
|||||||
if (userFlowStat != null) {
|
if (userFlowStat != null) {
|
||||||
BeanUtil.copyProperties(userFlowStat, result, copyOptions);
|
BeanUtil.copyProperties(userFlowStat, result, copyOptions);
|
||||||
}
|
}
|
||||||
|
if (unpaidOrder != null) {
|
||||||
|
BeanUtil.copyProperties(unpaidOrder, result, copyOptions);
|
||||||
|
}
|
||||||
|
if (refundItem != null) {
|
||||||
|
BeanUtil.copyProperties(refundItem, result, copyOptions);
|
||||||
|
}
|
||||||
|
//TODO 团购 抖音 美团 统计 走宏哥那获取
|
||||||
|
|
||||||
|
|
||||||
result.setShopId(shopId);
|
result.setShopId(shopId);
|
||||||
result.setStatisticDate(day);
|
result.setStatisticDate(day);
|
||||||
|
|||||||
Reference in New Issue
Block a user