商品报表 打印

This commit is contained in:
2026-04-21 11:02:33 +08:00
parent 2410e965de
commit 0d4d20eca7
2 changed files with 33 additions and 24 deletions

View File

@@ -214,9 +214,12 @@ public class PrintConfig implements ApplicationRunner {
}
break;
case PrinterHandler.PrintTypeEnum.PRODUCT_REPORT:
getPrintMachine(shopId, printTypeEnum)
.forEach(machine -> getPrinter(machine.getBrand())
.productReportPrint(machine, shopInfo.getShopName(), JSONObject.parseObject(data.toJSONString(), ProductReportPrintDTO.class)));
Map<String, ProductReportPrintDTO> map3 = data.to(new TypeReference<>() {
});
for (PrintMachine machine : getPrintMachine(shopId, printTypeEnum)) {
PrinterHandler printer = getPrinter(machine.getBrand());
map3.forEach((day, value) -> printer.productReportPrint(machine, shopInfo.getShopName(), value));
}
break;
case PrinterHandler.PrintTypeEnum.RECHARGE:
getPrintMachine(shopId, printTypeEnum)

View File

@@ -23,6 +23,7 @@ import java.time.LocalDate;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.LongStream;
import java.util.stream.Stream;
/**
@@ -86,40 +87,45 @@ public class ShopProdStatisticServiceImpl extends ServiceImpl<ShopProdStatisticM
@Override
public void summaryPrint(SaleSummaryCountParam param) {
Map<String, ProductReportPrintDTO> printDTO = new HashMap<>();
// 1. 获取统计数据
Map<Long, String> categoryMap = shopProdCategoryService.getCategoryIdNameMap(param.getShopId());
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) {
SaleSummaryCountParam queryDay = new SaleSummaryCountParam()
.setShopId(param.getShopId())
.setBeginDate(localDate)
.setEndDate(localDate);
ProductReportPrintDTO print = buildProductReportPrint(queryDay, categoryMap);
printDTO.put(localDate.toString(), print);
}
}
rabbitPublisher.sendOtherPrintMsg(param.getShopId(), printDTO, "PRODUCT_REPORT");
}
private ProductReportPrintDTO buildProductReportPrint(SaleSummaryCountParam param, Map<Long, String> categoryMap) {
SaleSummaryCountVo saleSummaryCountVo = summaryCount(param);
List<ShopProdStatistic> prodStatisticList = getArchiveTradeData(param);
LocalDate currentDate = LocalDate.now();
Map<Long, String> categoryMap = shopProdCategoryService.getCategoryIdNameMap(param.getShopId());
ProductReportPrintDTO printDTO = new ProductReportPrintDTO();
String statisticsTime = "";
if ("today".equals(param.getRangeType())) {
statisticsTime = LocalDateTimeUtil.format(currentDate, "yyyy/MM/dd");
}
if ("yesterday".equals(param.getRangeType())) {
statisticsTime = LocalDateTimeUtil.format(currentDate.minusDays(1), "yyyy/MM/dd");
}
String statisticsTime = LocalDateTimeUtil.format(param.getBeginDate(), "yyyy/MM/dd");
if (param.getBeginDate().isAfter(currentDate)) {
throw new CzgException("开始时间不能晚于当前时间");
}
if (param.getBeginDate().equals(param.getEndDate())) {
statisticsTime = LocalDateTimeUtil.format(param.getBeginDate(), "yyyy/MM/dd");
}
if (param.getEndDate().isBefore(currentDate)) {
statisticsTime = LocalDateTimeUtil.format(param.getBeginDate(), "yyyy/MM/dd") + " ~ " + LocalDateTimeUtil.format(param.getEndDate(), "yyyy/MM/dd");
}
printDTO.setStatisticsTime(statisticsTime);
printDTO.setOperator(param.getOperator());
if (saleSummaryCountVo != null) {
printDTO.setTotalProductCount(saleSummaryCountVo.getSaleCount());
printDTO.setTotalActualAmount(saleSummaryCountVo.getTotalAmount());
}else {
} else {
printDTO.setTotalProductCount(BigDecimal.ZERO);
printDTO.setTotalActualAmount(BigDecimal.ZERO);
}
if(CollUtil.isNotEmpty(prodStatisticList)){
if (CollUtil.isNotEmpty(prodStatisticList)) {
// 4. 先按分类ID分组商品
Map<Long, List<ShopProdStatistic>> groupByCategory = prodStatisticList.stream()
.collect(Collectors.groupingBy(ShopProdStatistic::getCategoryId));
@@ -166,7 +172,7 @@ public class ShopProdStatisticServiceImpl extends ServiceImpl<ShopProdStatisticM
}
printDTO.setItems(categoryItems);
}
rabbitPublisher.sendOtherPrintMsg(param.getShopId(), printDTO, "PRODUCT_REPORT");
return printDTO;
}
@Override