商品报表 打印

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; break;
case PrinterHandler.PrintTypeEnum.PRODUCT_REPORT: case PrinterHandler.PrintTypeEnum.PRODUCT_REPORT:
getPrintMachine(shopId, printTypeEnum) Map<String, ProductReportPrintDTO> map3 = data.to(new TypeReference<>() {
.forEach(machine -> getPrinter(machine.getBrand()) });
.productReportPrint(machine, shopInfo.getShopName(), JSONObject.parseObject(data.toJSONString(), ProductReportPrintDTO.class))); for (PrintMachine machine : getPrintMachine(shopId, printTypeEnum)) {
PrinterHandler printer = getPrinter(machine.getBrand());
map3.forEach((day, value) -> printer.productReportPrint(machine, shopInfo.getShopName(), value));
}
break; break;
case PrinterHandler.PrintTypeEnum.RECHARGE: case PrinterHandler.PrintTypeEnum.RECHARGE:
getPrintMachine(shopId, printTypeEnum) getPrintMachine(shopId, printTypeEnum)

View File

@@ -23,6 +23,7 @@ import java.time.LocalDate;
import java.util.*; import java.util.*;
import java.util.function.Function; import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.LongStream;
import java.util.stream.Stream; import java.util.stream.Stream;
/** /**
@@ -86,30 +87,35 @@ public class ShopProdStatisticServiceImpl extends ServiceImpl<ShopProdStatisticM
@Override @Override
public void summaryPrint(SaleSummaryCountParam param) { public void summaryPrint(SaleSummaryCountParam param) {
Map<String, ProductReportPrintDTO> printDTO = new HashMap<>();
// 1. 获取统计数据 // 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); SaleSummaryCountVo saleSummaryCountVo = summaryCount(param);
List<ShopProdStatistic> prodStatisticList = getArchiveTradeData(param); List<ShopProdStatistic> prodStatisticList = getArchiveTradeData(param);
LocalDate currentDate = LocalDate.now();
Map<Long, String> categoryMap = shopProdCategoryService.getCategoryIdNameMap(param.getShopId());
ProductReportPrintDTO printDTO = new ProductReportPrintDTO(); ProductReportPrintDTO printDTO = new ProductReportPrintDTO();
String statisticsTime = ""; String statisticsTime = LocalDateTimeUtil.format(param.getBeginDate(), "yyyy/MM/dd");
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");
}
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.setStatisticsTime(statisticsTime);
printDTO.setOperator(param.getOperator()); printDTO.setOperator(param.getOperator());
if (saleSummaryCountVo != null) { if (saleSummaryCountVo != null) {
@@ -166,7 +172,7 @@ public class ShopProdStatisticServiceImpl extends ServiceImpl<ShopProdStatisticM
} }
printDTO.setItems(categoryItems); printDTO.setItems(categoryItems);
} }
rabbitPublisher.sendOtherPrintMsg(param.getShopId(), printDTO, "PRODUCT_REPORT"); return printDTO;
} }
@Override @Override