diff --git a/eladmin-common/src/main/java/cn/ysk/cashier/utils/FileUtil.java b/eladmin-common/src/main/java/cn/ysk/cashier/utils/FileUtil.java index 8fd0a8b8..bddaa89d 100644 --- a/eladmin-common/src/main/java/cn/ysk/cashier/utils/FileUtil.java +++ b/eladmin-common/src/main/java/cn/ysk/cashier/utils/FileUtil.java @@ -248,7 +248,18 @@ public class FileUtil extends cn.hutool.core.io.FileUtil { Row row = sheet.createRow(i + 1); for (int j = 0; j < keyList.size(); j++) { Cell cell = row.createCell(j); - cell.setCellValue(map.get(keyList.get(j)) == null ? "" : map.get(keyList.get(j)).toString()); + String value = map.get(keyList.get(j)) == null ? "" : map.get(keyList.get(j)).toString(); + cell.setCellValue(value); + + if (j == 11 && !"0".equals(value)) { + cell.setCellValue("-" + value); + setCellBackground(cell, IndexedColors.YELLOW, workbook); + } + + if (j == 12 && !"0.00".equals(value)) { + cell.setCellValue("-" + value); + setCellBackground(cell, IndexedColors.YELLOW, workbook); + } } } @@ -268,6 +279,13 @@ public class FileUtil extends cn.hutool.core.io.FileUtil { } } + private static void setCellBackground(Cell cell, IndexedColors color, Workbook workbook) { + CellStyle style = workbook.createCellStyle(); + style.setFillForegroundColor(color.getIndex()); + style.setFillPattern(FillPatternType.SOLID_FOREGROUND); + cell.setCellStyle(style); + } + /** * 输入标题到excel * diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/controller/shop/SummaryController.java b/eladmin-system/src/main/java/cn/ysk/cashier/controller/shop/SummaryController.java index 0b50667c..efd3df02 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/controller/shop/SummaryController.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/controller/shop/SummaryController.java @@ -1,6 +1,5 @@ package cn.ysk.cashier.controller.shop; -import cn.ysk.cashier.annotation.rest.AnonymousGetMapping; import cn.ysk.cashier.annotation.rest.AnonymousPostMapping; import cn.ysk.cashier.dto.BaseQueryDto; import cn.ysk.cashier.dto.shop.ShopTableSaleInfoDto; diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/dto/shop/ExportTableStsDataDto.java b/eladmin-system/src/main/java/cn/ysk/cashier/dto/shop/ExportTableStsDataDto.java deleted file mode 100644 index dc94bde3..00000000 --- a/eladmin-system/src/main/java/cn/ysk/cashier/dto/shop/ExportTableStsDataDto.java +++ /dev/null @@ -1,18 +0,0 @@ -package cn.ysk.cashier.dto.shop; - -import lombok.Data; - -import java.util.List; -import java.util.Map; - -/** - * @author yijiegong - */ -@Data -public class ExportTableStsDataDto { - private String dateStr; - - private List> data; - - private List> mergeCells; -} diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/SummaryServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/SummaryServiceImpl.java index aacb65f7..2868aee6 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/SummaryServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/SummaryServiceImpl.java @@ -1,8 +1,9 @@ package cn.ysk.cashier.service.impl; +import cn.hutool.core.date.DateTime; import cn.hutool.core.util.ObjectUtil; -import cn.ysk.cashier.dto.ShopSummaryDto; import cn.ysk.cashier.dto.BaseQueryDto; +import cn.ysk.cashier.dto.ShopSummaryDto; import cn.ysk.cashier.dto.shop.ShopTableSaleInfoDto; import cn.ysk.cashier.enums.PayTypeEnum; import cn.ysk.cashier.exception.BadRequestException; @@ -36,6 +37,7 @@ import java.time.Instant; import java.time.LocalDate; import java.time.format.DateTimeFormatter; import java.util.*; +import java.util.concurrent.CountDownLatch; import java.util.concurrent.CompletableFuture; import java.util.function.Function; import java.util.stream.Collectors; @@ -93,7 +95,7 @@ public class SummaryServiceImpl implements SummaryService { sale.put("inAmount", flowMap.get("inAmount")); //会员 充值金额 sale.put("outAmount", flowMap.get("outAmount"));//会员 退款金额 - sale.put("incomeAmountAll",incomeAmount);//总实收 销售实收 + sale.put("incomeAmountAll", incomeAmount);//总实收 销售实收 List payCountVos = initPaysCount(); List payCounts = tbOrderInfoRepository.queryTbOrderPayCount( param.getShopId().toString(), null, param.getStartTime().getTime(), param.getEndTime().getTime()); @@ -111,79 +113,78 @@ public class SummaryServiceImpl implements SummaryService { param.getShopId().longValue(), DateUtil.getStrTime(param.getStartTime()), DateUtil.getStrTime(param.getEndTime())); for (TbOrderPayCountVo payCountVo : payCountVos) { BigDecimal payAmount = new BigDecimal(payCountVo.getPayAmount().toString()); - switch (payCountVo.getPayType()){ + switch (payCountVo.getPayType()) { case "微信小程序": - payCountVo.setPayAmount(payCountMap.containsKey("wx_lite")?payAmount.add(payCountMap.get("wx_lite")):payAmount); + payCountVo.setPayAmount(payCountMap.containsKey("wx_lite") ? payAmount.add(payCountMap.get("wx_lite")) : payAmount); break; case "支付宝小程序": - payCountVo.setPayAmount(payCountMap.containsKey("ali_lite")?payAmount.add(payCountMap.get("ali_lite")):payAmount); + payCountVo.setPayAmount(payCountMap.containsKey("ali_lite") ? payAmount.add(payCountMap.get("ali_lite")) : payAmount); break; case "主扫收款": - payCountVo.setPayAmount(payCountMap.containsKey("scanCode")?payAmount.add(payCountMap.get("scanCode")):payAmount); + payCountVo.setPayAmount(payCountMap.containsKey("scanCode") ? payAmount.add(payCountMap.get("scanCode")) : payAmount); break; case "收款码收款": - if(payCountMap.containsKey("ALIPAY")){ + if (payCountMap.containsKey("ALIPAY")) { payAmount = payAmount.add(payCountMap.get("ALIPAY")); } - if(payCountMap.containsKey("WECHAT")){ + if (payCountMap.containsKey("WECHAT")) { payAmount = payAmount.add(payCountMap.get("WECHAT")); } payCountVo.setPayAmount(payAmount); break; case "现金": - payCountVo.setPayAmount(payCountMap.containsKey("cash")?payAmount.add(payCountMap.get("cash")):payAmount); + payCountVo.setPayAmount(payCountMap.containsKey("cash") ? payAmount.add(payCountMap.get("cash")) : payAmount); break; case "会员": - payCountVo.setPayAmount(payCountMap.containsKey("deposit")?payAmount.add(payCountMap.get("deposit")):payAmount); + payCountVo.setPayAmount(payCountMap.containsKey("deposit") ? payAmount.add(payCountMap.get("deposit")) : payAmount); break; case "充值": payCountVo.setPayAmount(payAmount.add(vipSaveAmount)); break; } } - sale.put("payCount",payCountVos); - result.put("sale",sale); + sale.put("payCount", payCountVos); + result.put("sale", sale); vip.put("useAmount", flowMap.get("useAmount"));//会员消费金额 - vip.put("newFlow",newFlow);//新增会员数 - vip.put("useNum",flowMap.get("useNum"));//会员消费笔数 - result.put("vip",vip); + vip.put("newFlow", newFlow);//新增会员数 + vip.put("useNum", flowMap.get("useNum"));//会员消费笔数 + result.put("vip", vip); BigDecimal saleAmount = new BigDecimal(orderMap.get("saleAmount").toString()).subtract(new BigDecimal(orderMap.get("saveAmount").toString())); //客单价 - if(saleAmount.compareTo(BigDecimal.ZERO) == 0){ - count.put("unitPrice",BigDecimal.ZERO); - }else { - count.put("unitPrice",saleAmount.divide(new BigDecimal(orderMap.get("saleNum").toString()),2,RoundingMode.DOWN)); + if (saleAmount.compareTo(BigDecimal.ZERO) == 0) { + count.put("unitPrice", BigDecimal.ZERO); + } else { + count.put("unitPrice", saleAmount.divide(new BigDecimal(orderMap.get("saleNum").toString()), 2, RoundingMode.DOWN)); } BigDecimal saleNum = new BigDecimal(orderMap.get("saleNum").toString()); - if(saleNum.compareTo(BigDecimal.ZERO) == 0 || saleNum.compareTo(new BigDecimal(tables)) < 0){ - count.put("turnoverRate","0%");//翻台率 - }else { + if (saleNum.compareTo(BigDecimal.ZERO) == 0 || saleNum.compareTo(new BigDecimal(tables)) < 0) { + count.put("turnoverRate", "0%");//翻台率 + } else { BigDecimal turnoverRate = saleNum.divide(new BigDecimal(tables), 4, RoundingMode.DOWN).subtract(BigDecimal.ONE) .multiply(new BigDecimal("100")); count.put("turnoverRate", turnoverRate.setScale(2, RoundingMode.DOWN) + "%"); } - count.put("saveAmount",orderMap.get("saveAmount"));//优惠金额 - count.put("saveNum",orderMap.get("saveNum"));//优惠单数 - result.put("count",count); + count.put("saveAmount", orderMap.get("saveAmount"));//优惠金额 + count.put("saveNum", orderMap.get("saveNum"));//优惠单数 + result.put("count", count); return result; } - public List initPaysCount(){ + public List initPaysCount() { List payCountVos = new ArrayList<>(); - payCountVos.add(new TbOrderPayCountVo("https://cashier-oss.oss-cn-beijing.aliyuncs.com/static/wx.png","微信小程序","1",BigDecimal.ZERO)); - payCountVos.add(new TbOrderPayCountVo("https://cashier-oss.oss-cn-beijing.aliyuncs.com/static/ali.png","支付宝小程序","1",BigDecimal.ZERO)); - payCountVos.add(new TbOrderPayCountVo("https://cashier-oss.oss-cn-beijing.aliyuncs.com/static/scan.png","主扫收款","1",BigDecimal.ZERO)); - payCountVos.add(new TbOrderPayCountVo("https://cashier-oss.oss-cn-beijing.aliyuncs.com/static/bscan.png","收款码收款","1",BigDecimal.ZERO)); - payCountVos.add(new TbOrderPayCountVo("https://cashier-oss.oss-cn-beijing.aliyuncs.com/static/cash.png","现金","1",BigDecimal.ZERO)); - payCountVos.add(new TbOrderPayCountVo("https://cashier-oss.oss-cn-beijing.aliyuncs.com/static/vipIn.png","充值","1",BigDecimal.ZERO)); + payCountVos.add(new TbOrderPayCountVo("https://cashier-oss.oss-cn-beijing.aliyuncs.com/static/wx.png", "微信小程序", "1", BigDecimal.ZERO)); + payCountVos.add(new TbOrderPayCountVo("https://cashier-oss.oss-cn-beijing.aliyuncs.com/static/ali.png", "支付宝小程序", "1", BigDecimal.ZERO)); + payCountVos.add(new TbOrderPayCountVo("https://cashier-oss.oss-cn-beijing.aliyuncs.com/static/scan.png", "主扫收款", "1", BigDecimal.ZERO)); + payCountVos.add(new TbOrderPayCountVo("https://cashier-oss.oss-cn-beijing.aliyuncs.com/static/bscan.png", "收款码收款", "1", BigDecimal.ZERO)); + payCountVos.add(new TbOrderPayCountVo("https://cashier-oss.oss-cn-beijing.aliyuncs.com/static/cash.png", "现金", "1", BigDecimal.ZERO)); + payCountVos.add(new TbOrderPayCountVo("https://cashier-oss.oss-cn-beijing.aliyuncs.com/static/vipIn.png", "充值", "1", BigDecimal.ZERO)); // payCountVos.add(new TbOrderPayCountVo("","会员支付","1",BigDecimal.ZERO)); return payCountVos; } - @Override - public Map productSaleDate(Integer shopId, Integer day,Integer page,Integer size) { + public Map productSaleDate(Integer shopId, Integer day, Integer page, Integer size) { Pageable pageable = PageRequest.of(page, size); Date startTime = new Date(); Date endTime = new Date(); @@ -201,14 +202,14 @@ public class SummaryServiceImpl implements SummaryService { endTime = DateUtil.getDayEnd(); } HashMap map = new HashMap<>(); - Page tbOrderSalesCountByDayVos = detailRepository.queryTbOrderSalesCountByDay(shopId, null, null, startTime, endTime,pageable); + Page tbOrderSalesCountByDayVos = detailRepository.queryTbOrderSalesCountByDay(shopId, null, null, startTime, endTime, pageable); TbOrderSalesCountByDayVo tbOrderSalesCountByDayVo = detailRepository.queryTbOrderSalesCountByDaysummaryCount(shopId, null, null, startTime, endTime); - TbOrderPayCountVo zong =new TbOrderPayCountVo("el-icon-coin","总金额","1",tbOrderSalesCountByDayVo.getSalesAmount()); - TbOrderPayCountVo xiaoliang =new TbOrderPayCountVo("el-icon-goods","销售量","0",tbOrderSalesCountByDayVo.getSalesNum()); + TbOrderPayCountVo zong = new TbOrderPayCountVo("el-icon-coin", "总金额", "1", tbOrderSalesCountByDayVo.getSalesAmount()); + TbOrderPayCountVo xiaoliang = new TbOrderPayCountVo("el-icon-goods", "销售量", "0", tbOrderSalesCountByDayVo.getSalesNum()); List countStockByDayVos = tbOrderDetailRepository.countStockByDay(shopId, startTime, endTime); map.put("productCount", xiaoliang); map.put("productSum", zong); - map.put("countList", countStockByDayVos) ; + map.put("countList", countStockByDayVos); map.put("productList", tbOrderSalesCountByDayVos); return map; } @@ -257,7 +258,7 @@ public class SummaryServiceImpl implements SummaryService { sumDateVO = dataMap.get(tradeDayString); } else { // 如果不存在,则创建新的SumDateVO对象,amount设为0 - sumDateVO = new SumDateVO(tradeDayString, BigDecimal.ZERO,BigDecimal.ZERO, BigDecimal.ZERO); + sumDateVO = new SumDateVO(tradeDayString, BigDecimal.ZERO, BigDecimal.ZERO, BigDecimal.ZERO); } // 将SumDateVO对象添加到列表中 sumDateList.add(sumDateVO); @@ -397,7 +398,7 @@ public class SummaryServiceImpl implements SummaryService { } } for (TbOrderSalesCountByDayV2Vo product : products) { - if("sku".equals(product.getTypeEnum())){ + if ("sku".equals(product.getTypeEnum())) { for (TbOrderSalesCountByDayV2Vo skus : product.getSkus()) { Map map = new LinkedHashMap<>(); map.put("商品分类", product.getCateName()); @@ -409,7 +410,7 @@ public class SummaryServiceImpl implements SummaryService { map.put("退 单 量", skus.getRefNum()); list.add(map); } - }else { + } else { Map map = new LinkedHashMap<>(); map.put("商品分类", product.getCateName()); map.put("商品名称", product.getName()); @@ -475,82 +476,171 @@ public class SummaryServiceImpl implements SummaryService { @Override public void downloadTableSaleInfo(ShopTableSaleInfoDto shopTableSaleInfoDto, HttpServletResponse response) throws IOException { if (shopTableSaleInfoDto.getStartTime() == null) { - shopTableSaleInfoDto.setStartTime(DateUtil.toDate(DateUtil.fromTimeStamp(1704038400L))); + // 设置开始时间为30天前 + shopTableSaleInfoDto.setStartTime(cn.hutool.core.date.DateUtil.offsetDay(new Date(), -30)); } if (shopTableSaleInfoDto.getEndTime() == null) { shopTableSaleInfoDto.setEndTime(new Date()); } - List infoVos = selectSummaryTable(shopTableSaleInfoDto.getShopId(), shopTableSaleInfoDto.getStartTime(), shopTableSaleInfoDto.getEndTime()); - - infoVos.add(new ShopTableSaleInfoVo(99999, shopTableSaleInfoDto.getShopId(), null, "", "收银台", null, null, null, null)); - - List countByTables = tbOrderDetailRepository.queryTbOrderSalesCountByTable(shopTableSaleInfoDto.getShopId(), shopTableSaleInfoDto.getStartTime(), shopTableSaleInfoDto.getEndTime()); - - Map> countByTableMap = countByTables.stream() - .collect(Collectors.groupingBy(TbOrderSalesCountByTable::getTableId)); - - - // 比较 shopTableSaleInfoDto 的 startTime 和 endTime 是不是同一天 - boolean sameDay = cn.hutool.core.date.DateUtil.isSameDay(shopTableSaleInfoDto.getStartTime(), shopTableSaleInfoDto.getEndTime()); - - String queryDate = cn.hutool.core.date.DateUtil.format(shopTableSaleInfoDto.getStartTime(), "yyyy-MM-dd"); - if (!sameDay) { - queryDate += " 至 " + cn.hutool.core.date.DateUtil.format(shopTableSaleInfoDto.getEndTime(), "yyyy-MM-dd"); + // 计算开始时间和结束时间相差天数 + long diff = shopTableSaleInfoDto.getEndTime().getTime() - shopTableSaleInfoDto.getStartTime().getTime(); + long day = diff / (1000 * 60 * 60 * 24) + 1; + if (day > 31) { + throw new BadRequestException("时间范围不能超过31天"); } - List> list = new ArrayList<>(); + ThreadGroup threadGroup = new ThreadGroup("MyThreadGroup"); + CountDownLatch countDownLatch = new CountDownLatch((int) day); + Map> infoVoMap = new HashMap<>(); + Map> countByTableMap = new HashMap<>(); + Set tableCodeSet = new HashSet<>(); + for (int i = 0; i < day; i++) { + DateTime date = cn.hutool.core.date.DateUtil.offsetDay(shopTableSaleInfoDto.getStartTime(), i); + + Thread thread = new Thread(threadGroup, () -> { + try { + String dateKey = cn.hutool.core.date.DateUtil.format(date, "yyyy-MM-dd"); + DateTime start = cn.hutool.core.date.DateUtil.beginOfDay(date); + DateTime end = cn.hutool.core.date.DateUtil.endOfDay(date); + List infoVos = selectSummaryTable(shopTableSaleInfoDto.getShopId(), + start, end); + infoVos.add(new ShopTableSaleInfoVo(99999, shopTableSaleInfoDto.getShopId(), null, "", "收银台", null, null, null, null)); + infoVoMap.put(dateKey, infoVos); + + List countByTables = tbOrderDetailRepository.queryTbOrderSalesCountByTable( + shopTableSaleInfoDto.getShopId(), + start, end); + + if (countByTables != null && !countByTables.isEmpty()) { + Map> ctMap = countByTables.stream() + .collect(Collectors.groupingBy(TbOrderSalesCountByTable::getTableId)); + + ctMap.forEach((k, v) -> { + countByTableMap.put(dateKey + "-" + k, v); + }); + } + + for (ShopTableSaleInfoVo infoVo : infoVos) { + tableCodeSet.add(infoVo.getTableCode()); + } + + countDownLatch.countDown(); + } catch (Exception e) { + e.printStackTrace(); + } + }); + thread.start(); + } + + // 等待所有线程完成 + try { + countDownLatch.await(); + + System.out.println("所有线程执行完成"); + } catch (InterruptedException e) { + e.printStackTrace(); + } + + List> finalDataList = new ArrayList<>(); List> mergeList = new ArrayList<>(); - Map tableStartIndexMap = new HashMap<>(); + + // 桌子 --- list【天--- list【商品】】 + Map>>> dataList = new HashMap<>(); int rowIndex = 1; - for (ShopTableSaleInfoVo all : infoVos) { - List tables = countByTableMap.get(all.getTableCode()); - if (tables == null) { - continue; + // 用于记录每个日期首次出现的行索引 + Map dateFirstRowIndex = new HashMap<>(); + for (String tableCode : tableCodeSet) { + Map>> dayMap = new HashMap<>(); + BigDecimal totalAmount = BigDecimal.ZERO; + List> totalList = new ArrayList<>(); + for (int i = 0; i < day; i++) { + DateTime date = cn.hutool.core.date.DateUtil.offsetDay(shopTableSaleInfoDto.getStartTime(), i); + String queryDate = cn.hutool.core.date.DateUtil.format(date, "yyyy-MM-dd"); + + List> maps = dayMap.computeIfAbsent(queryDate, k -> new ArrayList<>()); + + List infoVos = infoVoMap.get(queryDate); + if (infoVos == null) { + continue; + } + + for (ShopTableSaleInfoVo infoVo : infoVos) { + String valueKey = queryDate + "-" + infoVo.getTableCode(); + List countByTables = countByTableMap.get(valueKey); + if (countByTables == null) { + continue; + } + + if (!tableCode.equals(infoVo.getTableCode())) { + continue; + } + + BigDecimal total = BigDecimal.ZERO; + for (TbOrderSalesCountByTable table : countByTables) { + total = total.add(table.getSalesAmount().abs()); + } + + totalAmount = totalAmount.add(total); + + String dateRowKey = queryDate + tableCode; + + for (TbOrderSalesCountByTable table : countByTables) { + Map map = new LinkedHashMap<>(); + map.put("台桌", infoVo.getTableName()); + map.put("日期", queryDate); + map.put("商品分类", table.getCateName()); + map.put("商品名称", table.getProductName()); + map.put("单位", table.getUnitName()); + map.put("商品规格", table.getProductSkuName()); + map.put("销量", table.getSalesNum()); + map.put("单价", table.getPrice()); + map.put("金额", table.getSalesAmount()); + map.put("销售额", total); + map.put("退单量", table.getRefNum()); + map.put("退单额", table.getRefAmount()); + maps.add(map); + totalList.add(map); + finalDataList.add(map); + + // 记录每个日期首次出现的行索引 + if (!dateFirstRowIndex.containsKey(dateRowKey)) { + dateFirstRowIndex.put(dateRowKey, finalDataList.size()); + } + } + + // 确定日期列的合并区域范围 + if (dateFirstRowIndex.containsKey(dateRowKey)) { + int startRow = dateFirstRowIndex.get(dateRowKey); + int endRow = finalDataList.size(); + if (endRow - startRow > 0) { + mergeList.add(Arrays.asList(startRow, endRow, 1, 1)); + mergeList.add(Arrays.asList(startRow, endRow, 9, 9)); + } + } + } + + } - BigDecimal total = BigDecimal.ZERO; - for (TbOrderSalesCountByTable table : tables) { - total = total.add(table.getSalesAmount().abs()); + if (finalDataList.size() - rowIndex > 0) { + mergeList.add(Arrays.asList(rowIndex, finalDataList.size(), 0, 0)); + mergeList.add(Arrays.asList(rowIndex, finalDataList.size(), 10, 10)); + } + rowIndex = finalDataList.size() + 1; + + for (Map map : totalList) { + map.put("总销售额", totalAmount); } - String tableCode = all.getTableName().toString(); - if (!tableStartIndexMap.containsKey(tableCode)) { - tableStartIndexMap.put(tableCode, rowIndex); - } - - for (TbOrderSalesCountByTable table : tables) { - Map map = new LinkedHashMap<>(); - map.put("日期", queryDate); - map.put("台桌", all.getTableName()); - map.put("商品分类", table.getCateName()); - map.put("商品名称", table.getProductName()); - map.put("单位", table.getUnitName()); - map.put("商品规格", table.getProductSkuName()); - map.put("销量", table.getSalesNum()); - map.put("单价", table.getPrice()); - map.put("金额", table.getSalesAmount()); - map.put("销售额", total); - map.put("退单量", table.getRefNum()); - map.put("退单额", table.getRefAmount()); - list.add(map); - rowIndex++; - } - - int start = tableStartIndexMap.get(tableCode); - int end = rowIndex - 1; - if (end - start > 0) { - mergeList.add(Arrays.asList(start, end, 0, 0)); - mergeList.add(Arrays.asList(start, end, 1, 1)); - mergeList.add(Arrays.asList(start, end, 9, 9)); - } + dataList.put(tableCode, dayMap); } List keyList = new ArrayList<>(); - keyList.add("日期"); keyList.add("台桌"); + keyList.add("日期"); keyList.add("商品分类"); keyList.add("商品名称"); keyList.add("单位"); @@ -559,9 +649,10 @@ public class SummaryServiceImpl implements SummaryService { keyList.add("单价"); keyList.add("金额"); keyList.add("销售额"); + keyList.add("总销售额"); keyList.add("退单量"); keyList.add("退单额"); - FileUtil.downloadAndMergeExcel(list, mergeList, keyList, response); + FileUtil.downloadAndMergeExcel(finalDataList, mergeList, keyList, response); } } diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/utils/FileUtils.java b/eladmin-system/src/main/java/cn/ysk/cashier/utils/FileUtils.java deleted file mode 100644 index f6e9437c..00000000 --- a/eladmin-system/src/main/java/cn/ysk/cashier/utils/FileUtils.java +++ /dev/null @@ -1,78 +0,0 @@ -package cn.ysk.cashier.utils; - -import cn.ysk.cashier.dto.shop.ExportTableStsDataDto; -import org.apache.poi.ss.usermodel.*; -import org.apache.poi.ss.util.CellRangeAddress; -import org.apache.poi.xssf.usermodel.XSSFWorkbook; - -import javax.servlet.ServletOutputStream; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; -import java.util.List; -import java.util.Map; - -/** - * @author yijiegong - */ -public class FileUtils { - /** - * 该方法用于导出台桌数据统计,不通用 - */ - public static void downloadTableDataStsToExcel(List dataList, List keyList, HttpServletResponse response) throws IOException { -// String tempPath = SYS_TEM_DIR + IdUtil.fastSimpleUUID() + ".xlsx"; - // 创建工作簿 - Workbook workbook = new XSSFWorkbook(); - - for (ExportTableStsDataDto exportTableStsDataDto : dataList) { - - Sheet sheet = workbook.createSheet(exportTableStsDataDto.getDateStr()); - - for (List mergeDatum : exportTableStsDataDto.getMergeCells()) { - sheet.addMergedRegion(new CellRangeAddress(mergeDatum.get(0), mergeDatum.get(1), mergeDatum.get(2), mergeDatum.get(3))); - } - - Row row0 = sheet.createRow(0); - for (int i = 0; i < keyList.size(); i++) { - Cell cell = row0.createCell(i); - cell.setCellValue(keyList.get(i)); - } - for (int i = 0; i < exportTableStsDataDto.getData().size(); i++) { - Map map = exportTableStsDataDto.getData().get(i); - Row row = sheet.createRow(i + 1); - for (int j = 0; j < keyList.size(); j++) { - Cell cell = row.createCell(j); - String value = map.get(keyList.get(j)) == null ? "" : map.get(keyList.get(j)).toString(); - cell.setCellValue(value); - - if (j == 10 && !"0".equals(value)) { - cell.setCellValue("-" + value); - setCellBackground(cell, IndexedColors.YELLOW, workbook); - } - - if (j == 11 && !"0.00".equals(value)) { - cell.setCellValue("-" + value); - setCellBackground(cell, IndexedColors.YELLOW, workbook); - } - } - } - } - - // response为HttpServletResponse对象 - response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8"); - response.setHeader("Content-Disposition", "attachment;filename=file.xlsx"); - - try (ServletOutputStream out = response.getOutputStream()) { - workbook.write(out); - out.flush(); - } catch (IOException e) { - e.printStackTrace(); - } - } - - private static void setCellBackground(Cell cell, IndexedColors color, Workbook workbook) { - CellStyle style = workbook.createCellStyle(); - style.setFillForegroundColor(color.getIndex()); - style.setFillPattern(FillPatternType.SOLID_FOREGROUND); - cell.setCellStyle(style); - } -} diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/vo/TbOrderSalesCountByTable.java b/eladmin-system/src/main/java/cn/ysk/cashier/vo/TbOrderSalesCountByTable.java index c8875f73..b1b8a8ed 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/vo/TbOrderSalesCountByTable.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/vo/TbOrderSalesCountByTable.java @@ -61,4 +61,11 @@ public class TbOrderSalesCountByTable { salesNum=salesNum-refNum; salesAmount=salesAmount.subtract(refAmount); } + + public String getTableId() { + if (tableId == null) { + return ""; + } + return tableId; + } }