From 52ebdfa90bf014880aa9503441f4215cf226c881 Mon Sep 17 00:00:00 2001 From: GYJ <1157756119@qq.com> Date: Mon, 8 Jul 2024 18:24:24 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E6=89=80=E6=9C=89?= =?UTF-8?q?=E6=A1=8C=E5=8F=B0=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../order/TbOrderInfoRepository.java | 77 ++++++++++--------- .../service/impl/SummaryServiceImpl.java | 10 ++- .../ysk/cashier/vo/ShopTableSaleInfoVo.java | 4 +- 3 files changed, 52 insertions(+), 39 deletions(-) diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/repository/order/TbOrderInfoRepository.java b/eladmin-system/src/main/java/cn/ysk/cashier/repository/order/TbOrderInfoRepository.java index 8e632eda..ec595db9 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/repository/order/TbOrderInfoRepository.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/repository/order/TbOrderInfoRepository.java @@ -1,18 +1,18 @@ /* -* Copyright 2019-2020 Zheng Jie -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ + * Copyright 2019-2020 Zheng Jie + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package cn.ysk.cashier.repository.order; import cn.ysk.cashier.pojo.order.TbOrderInfo; @@ -32,10 +32,10 @@ import java.util.Date; import java.util.List; /** -* @website https://eladmin.vip -* @author lyf -* @date 2024-03-02 -**/ + * @author lyf + * @website https://eladmin.vip + * @date 2024-03-02 + **/ public interface TbOrderInfoRepository extends JpaRepository, JpaSpecificationExecutor { @Query("SELECT new cn.ysk.cashier.vo.TbOrderPayCountVo(info.payType, SUM(info.orderAmount)) " + "FROM TbOrderInfo info " + @@ -43,7 +43,7 @@ public interface TbOrderInfoRepository extends JpaRepository:start AND info.createdAt<:end " + "AND ((info.status = 'closed') OR (info.status = 'refund' AND info.orderType != 'return')) " + "GROUP BY info.payType") - List queryTbOrderPayCount(@Param("shopId")String shopId, @Param("start") Long start, @Param("end") Long end); + List queryTbOrderPayCount(@Param("shopId") String shopId, @Param("start") Long start, @Param("end") Long end); @Query("SELECT new cn.ysk.cashier.vo.TbOrderPayCountVo('refund', SUM(info.orderAmount)) " + @@ -51,21 +51,20 @@ public interface TbOrderInfoRepository extends JpaRepository:start AND info.createdAt<:end") - TbOrderPayCountVo queryTbOrderRefund(@Param("shopId")String shopId, @Param("start") Long start, @Param("end") Long end); + TbOrderPayCountVo queryTbOrderRefund(@Param("shopId") String shopId, @Param("start") Long start, @Param("end") Long end); @Query(value = "SELECT COUNT(1) ,pay_type AS payType FROM tb_order_info Where shop_id = :shopId AND " + - " created_at BETWEEN :startTime AND :endTime AND status='closed'AND order_type <>'return' GROUP BY pay_type" ,nativeQuery = true) + " created_at BETWEEN :startTime AND :endTime AND status='closed'AND order_type <>'return' GROUP BY pay_type", nativeQuery = true) List countByShopId(@Param("shopId") String shopId, @Param("startTime") Long startTime, @Param("endTime") Long endTime); @Query("SELECT info FROM TbOrderInfo info WHERE info.source = :source AND info.shopId=:shopId") - List selTbOrdersBysource(@Param("source")Integer source,@Param("shopId") String shopId); + List selTbOrdersBysource(@Param("source") Integer source, @Param("shopId") String shopId); @Query("SELECT count(1) FROM TbOrderInfo WHERE source = :source AND shopId=:shopId") - int isRefund(@Param("source")Integer source,@Param("shopId") String shopId); + int isRefund(@Param("source") Integer source, @Param("shopId") String shopId); /** - * * @param shopId * @param startTime * @param endTime @@ -105,20 +104,21 @@ public interface TbOrderInfoRepository extends JpaRepository queryTbOrderPayCountByDayExt(@Param("shopId") Integer shopId, @Param("startTime") Date startTime, @Param("endTime") Date endTime, - @Param("currentPage") Integer currentPage, @Param("currentSize")Integer currentSize); + @Param("currentPage") Integer currentPage, @Param("currentSize") Integer currentSize); @Query(value = "SELECT ifnull( sum( order_amount ), 0 ) AS amount,trade_day as tradeDay " + "FROM tb_order_info WHERE shop_id = :shopId AND ((status = 'closed') OR ( status ='refund' AND order_type != 'return' ))" + "AND trade_day BETWEEN :startTime AND :endTime " + - "GROUP BY shop_id,trade_day",nativeQuery = true) - List queryTbOrderPaySumByDay(@Param("shopId") String shopId,@Param("startTime") Date startTime, @Param("endTime") Date endTime); + "GROUP BY shop_id,trade_day", nativeQuery = true) + List queryTbOrderPaySumByDay(@Param("shopId") String shopId, @Param("startTime") Date startTime, @Param("endTime") Date endTime); + @Query(value = "SELECT ifnull( sum( order_amount ), 0 )" + "FROM tb_order_info WHERE shop_id = :shopId AND ((status = 'closed') OR ( status ='refund' AND order_type != 'return' ))" + - "AND created_at > :startTime AND created_at < :endTime " ,nativeQuery = true) - Tuple queryPaySumByDayAll(@Param("shopId") String shopId,@Param("startTime") Long startTime, @Param("endTime") Long endTime); + "AND created_at > :startTime AND created_at < :endTime ", nativeQuery = true) + Tuple queryPaySumByDayAll(@Param("shopId") String shopId, @Param("startTime") Long startTime, @Param("endTime") Long endTime); @Query("select count(1),sum (info.payAmount) FROM TbOrderInfo info WHERE info.shopId = :shopId AND info.status = 'closed' ") @@ -128,11 +128,12 @@ public interface TbOrderInfoRepository extends JpaRepository sumByDateOrderNum(@Param("shopId") String shopId,@Param("startTime") Date startTime, @Param("endTime") Date endTime); + "GROUP BY shop_id,trade_day", nativeQuery = true) + List sumByDateOrderNum(@Param("shopId") String shopId, @Param("startTime") Date startTime, @Param("endTime") Date endTime); + @Query(value = "select count(1), sum(pay_amount) FROM tb_order_info WHERE shop_id = :shopId AND status = 'closed' " + - "AND trade_day BETWEEN :startTime AND :endTime ",nativeQuery = true) - Tuple sumByShopIdToday(@Param("shopId") String shopId,@Param("startTime") Date startTime, @Param("endTime") Date endTime); + "AND trade_day BETWEEN :startTime AND :endTime ", nativeQuery = true) + Tuple sumByShopIdToday(@Param("shopId") String shopId, @Param("startTime") Date startTime, @Param("endTime") Date endTime); @Query("SELECT new cn.ysk.cashier.vo.TbOrderPayCountByDayVo(" + "info.tradeDay," + @@ -184,6 +185,10 @@ public interface TbOrderInfoRepository extends JpaRepository :startTime AND info.createdAt < :endTime " + "AND ((info.status = 'closed') OR ( info.status ='refund' AND info.orderType != 'return' )) " + - "GROUP BY info.tableId") - List queryShopTableSaleInfo(@Param("shopId") String shopId, @Param("startTime") Long startTime, @Param("endTime") Long endTime); + "AND info.tableId = :qrcode ") + ShopTableSaleInfoVo queryShopTableSaleInfo(@Param("shopId") String shopId, @Param("qrcode") String qrcode, + @Param("startTime") Long startTime, @Param("endTime") Long endTime); + + @Query("select table.qrcode from TbShopTable table where table.shopId = :shopId") + List queryShopTableIds(@Param("shopId") Integer shopId); } 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 239253e4..8ad531a6 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 @@ -475,13 +475,21 @@ public class SummaryServiceImpl implements SummaryService { @Override public List selectSummaryTable(Integer shopId, Date startTime, Date endTime) { + List shopTableCodes = tbOrderInfoRepository.queryShopTableIds(shopId); + long start = 1704038400000L; long end = Instant.now().toEpochMilli(); if (startTime != null && endTime != null) { start = startTime.getTime(); end = endTime.getTime(); } - return tbOrderInfoRepository.queryShopTableSaleInfo(shopId.toString(), start, end); + + List list = new ArrayList<>(); + for (String shopTableCode : shopTableCodes) { + ShopTableSaleInfoVo shopTableSaleInfoVo = tbOrderInfoRepository.queryShopTableSaleInfo(shopId.toString(), shopTableCode, start, end); + list.add(shopTableSaleInfoVo); + } + return list; } @Override diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/vo/ShopTableSaleInfoVo.java b/eladmin-system/src/main/java/cn/ysk/cashier/vo/ShopTableSaleInfoVo.java index 5fef58a8..b36e8168 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/vo/ShopTableSaleInfoVo.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/vo/ShopTableSaleInfoVo.java @@ -32,7 +32,7 @@ public class ShopTableSaleInfoVo { this.tableName = tableName; this.areaId = areaId; this.areaName = areaName; - this.orderCount = orderCount; - this.orderAmount = orderAmount; + this.orderCount = orderCount == null ? 0 : orderCount; + this.orderAmount = orderAmount == null ? 0 : orderAmount; } } From de049b5791ecade1fa2f38d91fcacbb13d9541e8 Mon Sep 17 00:00:00 2001 From: GYJ <1157756119@qq.com> Date: Tue, 9 Jul 2024 09:29:02 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=8E=92=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/SummaryServiceImpl.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) 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 8ad531a6..2cbaaa54 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 @@ -489,6 +489,25 @@ public class SummaryServiceImpl implements SummaryService { ShopTableSaleInfoVo shopTableSaleInfoVo = tbOrderInfoRepository.queryShopTableSaleInfo(shopId.toString(), shopTableCode, start, end); list.add(shopTableSaleInfoVo); } + + if (!list.isEmpty()) { + list.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()); + int compareAmount = aAmount.compareTo(bAmount); + if (compareAmount != 0) { + return compareAmount; + } + + // 如果 orderAmount 相等,再比较 orderCount + Integer aCount = a.getOrderCount() == null ? 0 : Integer.parseInt(a.getOrderCount().toString()); + Integer bCount = b.getOrderCount() == null ? 0 : Integer.parseInt(b.getOrderCount().toString()); + + return aCount - bCount; + }); + } + return list; } From 507b4d4d9e5cf2453857040a441134c1bbaba47d Mon Sep 17 00:00:00 2001 From: GYJ <1157756119@qq.com> Date: Tue, 9 Jul 2024 10:38:05 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E5=A4=84=E7=90=86=E6=B2=A1=E6=9C=89?= =?UTF-8?q?=E8=AE=A2=E5=8D=95=E6=98=AF=E5=8F=B0=E6=A1=8C=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E4=B8=BA=E7=A9=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/SummaryServiceImpl.java | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) 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 2cbaaa54..e5efa3ec 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 @@ -5,11 +5,14 @@ import cn.ysk.cashier.dto.shop.ShopTableSeleInfoDto; import cn.ysk.cashier.enums.PayTypeEnum; import cn.ysk.cashier.exception.BadRequestException; import cn.ysk.cashier.mybatis.service.TbShopUserFlowService; +import cn.ysk.cashier.pojo.shop.TbShopTable; import cn.ysk.cashier.repository.ShopUserDutyDetailRepository; import cn.ysk.cashier.repository.ShopUserDutyRepository; import cn.ysk.cashier.repository.TbTokenRepository; import cn.ysk.cashier.repository.order.TbOrderDetailRepository; import cn.ysk.cashier.repository.order.TbOrderInfoRepository; +import cn.ysk.cashier.repository.shop.TbShopAreaRepository; +import cn.ysk.cashier.repository.shop.TbShopTableRepository; import cn.ysk.cashier.repository.shop.TbShopUserRepository; import cn.ysk.cashier.service.SummaryService; import cn.ysk.cashier.utils.DateUtil; @@ -56,6 +59,12 @@ public class SummaryServiceImpl implements SummaryService { @Resource private TbShopUserFlowService tbShopUserFlowService; + @Resource + private TbShopTableRepository shopTableRepository; + + @Resource + TbShopAreaRepository tbShopAreaRepository; + @Override public SummaryVO selectSummary(Integer shopId) { @@ -487,6 +496,16 @@ public class SummaryServiceImpl implements SummaryService { List 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); } @@ -495,7 +514,7 @@ public class SummaryServiceImpl implements SummaryService { // 先比较 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()); - int compareAmount = aAmount.compareTo(bAmount); + int compareAmount = bAmount.compareTo(aAmount); if (compareAmount != 0) { return compareAmount; } @@ -504,7 +523,7 @@ public class SummaryServiceImpl implements SummaryService { Integer aCount = a.getOrderCount() == null ? 0 : Integer.parseInt(a.getOrderCount().toString()); Integer bCount = b.getOrderCount() == null ? 0 : Integer.parseInt(b.getOrderCount().toString()); - return aCount - bCount; + return bCount - aCount; }); }