优化台桌统计
This commit is contained in:
@@ -59,6 +59,7 @@ public class SummaryController {
|
||||
}
|
||||
|
||||
@GetMapping("/table")
|
||||
@AnonymousGetMapping
|
||||
private Object shopSummaryTable(@RequestParam Integer shopId,
|
||||
@RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date startTime,
|
||||
@RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date endTime) {
|
||||
|
||||
@@ -17,6 +17,7 @@ package cn.ysk.cashier.repository.order;
|
||||
|
||||
import cn.ysk.cashier.pojo.order.TbOrderInfo;
|
||||
import cn.ysk.cashier.vo.ShopTableSaleInfoVo;
|
||||
import cn.ysk.cashier.vo.ShopTableVo;
|
||||
import cn.ysk.cashier.vo.TbOrderPayCountByDayVo;
|
||||
import cn.ysk.cashier.vo.TbOrderPayCountVo;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
@@ -191,4 +192,39 @@ public interface TbOrderInfoRepository extends JpaRepository<TbOrderInfo, Intege
|
||||
|
||||
@Query("select table.qrcode from TbShopTable table where table.shopId = :shopId")
|
||||
List<String> queryShopTableIds(@Param("shopId") Integer shopId);
|
||||
}
|
||||
|
||||
@Query("SELECT new cn.ysk.cashier.vo.ShopTableVo(" +
|
||||
"table.qrcode," +
|
||||
"table.shopId," +
|
||||
"table.id," +
|
||||
"table.name," +
|
||||
"table.areaId," +
|
||||
"area.name) " +
|
||||
"FROM TbShopTable table " +
|
||||
"LEFT JOIN TbShopArea as area on table.areaId = area.id " +
|
||||
"WHERE table.shopId = :shopId " +
|
||||
"AND table.qrcode is not null " +
|
||||
"AND table.qrcode != '' ")
|
||||
List<ShopTableVo> queryShopTableVoByShopId(@Param("shopId") Integer shopId);
|
||||
|
||||
@Query("SELECT new cn.ysk.cashier.vo.ShopTableSaleInfoVo(" +
|
||||
"info.id," +
|
||||
"info.shopId," +
|
||||
"info.tableId," +
|
||||
"table.name," +
|
||||
"table.areaId," +
|
||||
"area.name," +
|
||||
"COUNT(1)," +
|
||||
"SUM( info.orderAmount)) " +
|
||||
"FROM TbOrderInfo info " +
|
||||
"LEFT JOIN TbShopTable table ON info.tableId = table.qrcode " +
|
||||
"LEFT JOIN TbShopArea as area on table.areaId = area.id " +
|
||||
"WHERE info.shopId = :shopId " +
|
||||
"AND info.createdAt > :startTime AND info.createdAt < :endTime " +
|
||||
"AND ((info.status = 'closed') OR ( info.status ='refund' AND info.orderType != 'return' )) " +
|
||||
"AND table.qrcode is not null " +
|
||||
"AND table.qrcode != '' " +
|
||||
"GROUP BY info.tableId ")
|
||||
List<ShopTableSaleInfoVo> queryShopTableSaleInfo2(@Param("shopId") String shopId,
|
||||
@Param("startTime") Long startTime, @Param("endTime") Long endTime);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
package cn.ysk.cashier.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* @author GYJ
|
||||
*/
|
||||
@Data
|
||||
public class ShopTableVo {
|
||||
private String qrcode;
|
||||
private Object shopId;
|
||||
private Object tableId;
|
||||
private Object tableName;
|
||||
private Object areaId;
|
||||
private Object areaName;
|
||||
|
||||
public ShopTableVo(String qrcode, Object shopId, Object tableId, Object tableName, Object areaId, Object areaName) {
|
||||
this.qrcode = qrcode;
|
||||
this.shopId = shopId;
|
||||
this.tableId = tableId;
|
||||
this.tableName = tableName;
|
||||
this.areaId = areaId;
|
||||
this.areaName = areaName;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user