优化台桌统计

This commit is contained in:
GYJ
2024-08-08 10:41:12 +08:00
parent 9e13d1ff98
commit b218436a1c
4 changed files with 87 additions and 20 deletions

View File

@@ -39,6 +39,8 @@ import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.function.Function;
import java.util.stream.Collectors;
@Service
@RequiredArgsConstructor
@@ -504,7 +506,9 @@ public class SummaryServiceImpl implements SummaryService {
@Override
public List<ShopTableSaleInfoVo> selectSummaryTable(Integer shopId, Date startTime, Date endTime) {
List<String> shopTableCodes = tbOrderInfoRepository.queryShopTableIds(shopId);
// List<String> shopTableCodes = tbOrderInfoRepository.queryShopTableIds(shopId);
List<ShopTableVo> tableVos = tbOrderInfoRepository.queryShopTableVoByShopId(shopId);
long start = 1704038400000L;
long end = Instant.now().toEpochMilli();
@@ -513,24 +517,23 @@ public class SummaryServiceImpl implements SummaryService {
end = endTime.getTime();
}
List<ShopTableSaleInfoVo> list = new ArrayList<>();
for (String shopTableCode : shopTableCodes) {
ShopTableSaleInfoVo shopTableSaleInfoVo = tbOrderInfoRepository.queryShopTableSaleInfo(shopId.toString(), shopTableCode, start, end);
if (shopTableSaleInfoVo.getTableId() == null) {
TbShopTable table = shopTableRepository.findByQrcode(shopTableCode);
if (table != null) {
shopTableSaleInfoVo.setShopId(shopId);
shopTableSaleInfoVo.setTableId(table.getId());
shopTableSaleInfoVo.setTableName(table.getName());
shopTableSaleInfoVo.setAreaId(table.getAreaId());
shopTableSaleInfoVo.setAreaName(tbShopAreaRepository.findById(table.getAreaId()).get().getName());
}
}
list.add(shopTableSaleInfoVo);
}
List<ShopTableSaleInfoVo> saleInfoVo = tbOrderInfoRepository.queryShopTableSaleInfo2(shopId.toString(), start, end);
if (!list.isEmpty()) {
list.sort((a, b) -> {
Map<String, ShopTableVo> tableMap = tableVos.stream()
.collect(Collectors.toMap(ShopTableVo::getQrcode, Function.identity()));
saleInfoVo.parallelStream().forEach(vo -> {
ShopTableVo tableVo = tableMap.get(vo.getTableId());
if (tableVo != null) {
vo.setShopId(shopId);
vo.setTableId(tableVo.getTableId());
vo.setTableName(tableVo.getTableName());
vo.setAreaId(tableVo.getAreaId());
vo.setAreaName(tableVo.getAreaName());
}
});
if (!saleInfoVo.isEmpty()) {
saleInfoVo.sort((a, b) -> {
// 先比较 orderAmount
BigDecimal aAmount = a.getOrderAmount() == null ? BigDecimal.ZERO : new BigDecimal(a.getOrderAmount().toString());
BigDecimal bAmount = b.getOrderAmount() == null ? BigDecimal.ZERO : new BigDecimal(b.getOrderAmount().toString());
@@ -547,7 +550,7 @@ public class SummaryServiceImpl implements SummaryService {
});
}
return list;
return saleInfoVo;
}
@Override