台桌数据导出修改
This commit is contained in:
@@ -16,6 +16,7 @@ import cn.ysk.cashier.utils.DateUtil;
|
||||
import cn.ysk.cashier.utils.FileUtil;
|
||||
import cn.ysk.cashier.vo.*;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.beust.ah.A;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@@ -558,38 +559,77 @@ public class SummaryServiceImpl implements SummaryService {
|
||||
Map<String, List<TbOrderSalesCountByTable>> countByTableMap = countByTables.stream()
|
||||
.collect(Collectors.groupingBy(TbOrderSalesCountByTable::getTableId));
|
||||
|
||||
ConcurrentLinkedQueue<Map<String, Object>> list = new ConcurrentLinkedQueue<>();
|
||||
|
||||
ArrayList<Integer> mergeRowIndex = new ArrayList<>();
|
||||
// 比较 shopTableSeleInfoDto 的 startTime 和 endTime 是不是同一天
|
||||
boolean sameDay = cn.hutool.core.date.DateUtil.isSameDay(shopTableSeleInfoDto.getStartTime(), shopTableSeleInfoDto.getEndTime());
|
||||
|
||||
String queryDate = cn.hutool.core.date.DateUtil.format(shopTableSeleInfoDto.getStartTime(), "yyyy-MM-dd");
|
||||
if (!sameDay) {
|
||||
queryDate += " 至 " + cn.hutool.core.date.DateUtil.format(shopTableSeleInfoDto.getEndTime(), "yyyy-MM-dd");
|
||||
}
|
||||
|
||||
List<Map<String, Object>> list = new ArrayList<>();
|
||||
|
||||
List<List<Integer>> mergeList = new ArrayList<>();
|
||||
Map<String, Integer> tableStartIndexMap = new HashMap<>();
|
||||
int rowIndex = 1;
|
||||
for (ShopTableSaleInfoVo all : infoVos) {
|
||||
List<TbOrderSalesCountByTable> tables = countByTableMap.get(all.getTableCode());
|
||||
if (tables == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
BigDecimal total = BigDecimal.ZERO;
|
||||
for (TbOrderSalesCountByTable table : tables) {
|
||||
total = total.add(table.getSalesAmount().abs());
|
||||
}
|
||||
|
||||
String tableCode = all.getTableName().toString();
|
||||
if (!tableStartIndexMap.containsKey(tableCode)) {
|
||||
tableStartIndexMap.put(tableCode, rowIndex);
|
||||
}
|
||||
|
||||
for (TbOrderSalesCountByTable table : tables) {
|
||||
Map<String, Object> map = new LinkedHashMap<>();
|
||||
map.put("开始时间", shopTableSeleInfoDto.getStartTime());
|
||||
map.put("结束时间", shopTableSeleInfoDto.getEndTime());
|
||||
map.put("区域名称", all.getAreaName());
|
||||
map.put("桌台名称", all.getTableName());
|
||||
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.getSalesAmount());
|
||||
map.put("单价", table.getPrice());
|
||||
map.put("金额", table.getSalesAmount());
|
||||
map.put("销售额", total);
|
||||
map.put("退单量", table.getRefNum());
|
||||
map.put("退单额", table.getRefAmount());
|
||||
list.add(map);
|
||||
rowIndex++;
|
||||
}
|
||||
|
||||
if (!tables.isEmpty()) {
|
||||
if (mergeRowIndex.isEmpty()) {
|
||||
mergeRowIndex.add(tables.size());
|
||||
}else {
|
||||
mergeRowIndex.add(mergeRowIndex.get(mergeRowIndex.size() - 1) + tables.size());
|
||||
}
|
||||
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));
|
||||
}
|
||||
}
|
||||
FileUtil.downloadExcelAndMerge(list, 4, response, mergeRowIndex);
|
||||
|
||||
List<String> keyList = new ArrayList<>();
|
||||
keyList.add("日期");
|
||||
keyList.add("台桌");
|
||||
keyList.add("商品分类");
|
||||
keyList.add("商品名称");
|
||||
keyList.add("单位");
|
||||
keyList.add("商品规格");
|
||||
keyList.add("销量");
|
||||
keyList.add("单价");
|
||||
keyList.add("金额");
|
||||
keyList.add("销售额");
|
||||
keyList.add("退单量");
|
||||
keyList.add("退单额");
|
||||
|
||||
FileUtil.downloadAndMergeExcel(list, mergeList, keyList, response);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user