From cb181564e58487d7a2a9891a46de1eb30a39b84a Mon Sep 17 00:00:00 2001 From: dzc <2388224167@qq.com> Date: Tue, 28 Oct 2025 09:43:12 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E6=9C=AC=E5=91=A8=E5=A4=96=E9=83=A8?= =?UTF-8?q?=E5=B0=B1=E9=A4=90=E6=83=85=E5=86=B5(=E5=90=88=E4=BD=9C?= =?UTF-8?q?=E5=95=86=E5=AE=B6)=E8=90=A5=E5=85=BB=E5=88=86=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hard/api/dto/panel/PanelProductDto.java | 7 + .../panel/PanelNutritionController.java | 20 ++ .../controller/panel/PanelShopController.java | 1 + .../hard/mapper/order/HardOrderMapper.java | 8 + .../hard/service/PanelNutritionService.java | 5 + .../impl/panel/PanelNutritionServiceImpl.java | 51 ++++ .../mapper/order/HardOrderMapper.xml | 279 ++++++++---------- 7 files changed, 217 insertions(+), 154 deletions(-) diff --git a/pjcloud-hardware/pjcloud-hardware-api/src/main/java/com/bsd/pjcloud/hard/api/dto/panel/PanelProductDto.java b/pjcloud-hardware/pjcloud-hardware-api/src/main/java/com/bsd/pjcloud/hard/api/dto/panel/PanelProductDto.java index 8994bb334..fe2d93a6e 100644 --- a/pjcloud-hardware/pjcloud-hardware-api/src/main/java/com/bsd/pjcloud/hard/api/dto/panel/PanelProductDto.java +++ b/pjcloud-hardware/pjcloud-hardware-api/src/main/java/com/bsd/pjcloud/hard/api/dto/panel/PanelProductDto.java @@ -25,6 +25,13 @@ public class PanelProductDto { private List excludeClassifyIds; + private List orderStatus; + + /** + * 排除当天在食堂吃饭的数据 + */ + private String excludeCanteenPay; + private String hourTypeIsNull; private String hourType; diff --git a/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/controller/panel/PanelNutritionController.java b/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/controller/panel/PanelNutritionController.java index 73ed0436e..2e357573b 100644 --- a/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/controller/panel/PanelNutritionController.java +++ b/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/controller/panel/PanelNutritionController.java @@ -3,8 +3,10 @@ package com.bsd.pjcloud.hard.controller.panel; import cn.hutool.core.util.ObjectUtil; import com.bsd.pjcloud.common.core.constant.enums.DateRangeTypeEnum; import com.bsd.pjcloud.common.core.constant.enums.MerchantTypeEnum; +import com.bsd.pjcloud.common.core.constant.enums.YesNoEnum; import com.bsd.pjcloud.common.core.util.DateRangeTool; import com.bsd.pjcloud.common.core.util.R; +import com.bsd.pjcloud.hard.api.constant.order.HardOrderStatusEnum; import com.bsd.pjcloud.hard.api.dto.panel.PanelProductDto; import com.bsd.pjcloud.hard.api.vo.hard.PanelPorductVo; import com.bsd.pjcloud.hard.service.PanelNutritionService; @@ -37,6 +39,7 @@ public class PanelNutritionController { dto.setTotalTimeList(DateRangeTool.transitionDateTypeToDateTimeList(dto.getDateRangeType())); } dto.setMchTypeCodes(List.of(MerchantTypeEnum.CANTEEN.getType())); + dto.setOrderStatus(HardOrderStatusEnum.getPayPrice()); return R.ok(panelNutritionService.classCount(dto)); } @@ -47,6 +50,7 @@ public class PanelNutritionController { dto.setTotalTimeList(DateRangeTool.transitionDateTypeToDateTimeList(dto.getDateRangeType())); } dto.setMchTypeCodes(List.of(MerchantTypeEnum.CANTEEN.getType())); + dto.setOrderStatus(HardOrderStatusEnum.getPayPrice()); return R.ok(panelNutritionService.cuisineTop(dto)); } @@ -57,6 +61,7 @@ public class PanelNutritionController { dto.setTotalTimeList(DateRangeTool.transitionDateTypeToDateTimeList(dto.getDateRangeType())); } dto.setMchTypeCodes(List.of(MerchantTypeEnum.CANTEEN.getType())); + dto.setOrderStatus(HardOrderStatusEnum.getPayPrice()); return R.ok(panelNutritionService.nutritionByTime(dto)); } @@ -67,6 +72,7 @@ public class PanelNutritionController { dto.setTotalTimeList(DateRangeTool.transitionDateTypeToDateTimeList(dto.getDateRangeType())); } dto.setMchTypeCodes(List.of(MerchantTypeEnum.CANTEEN.getType())); + dto.setOrderStatus(HardOrderStatusEnum.getPayPrice()); return R.ok(panelNutritionService.nutritionTotal(dto)); } @@ -78,6 +84,7 @@ public class PanelNutritionController { LocalDateTime.now().withHour(23).withMinute(59).withSecond(59) }); dto.setMchTypeCodes(List.of(MerchantTypeEnum.CANTEEN.getType())); + dto.setOrderStatus(HardOrderStatusEnum.getPayPrice()); return R.ok(panelNutritionService.nutritionByTime(dto)); } @@ -89,8 +96,21 @@ public class PanelNutritionController { dto.setTotalTimeList(DateRangeTool.transitionDateTypeToDateTimeList(dto.getDateRangeType())); } dto.setMchTypeCodes(List.of(MerchantTypeEnum.CANTEEN.getType())); + dto.setOrderStatus(HardOrderStatusEnum.getPayPrice()); dto.setLimit(5L); return R.ok(panelNutritionService.repurchase(dto)); } + @PostMapping(value = "/external") + @Operation(summary = "外部就餐情况(合作商家)") + public R external(@RequestBody PanelProductDto dto) { + if (ObjectUtil.isNotEmpty(dto.getDateRangeType()) && ObjectUtil.isEmpty(dto.getTotalTimeList())) { + dto.setTotalTimeList(DateRangeTool.transitionDateTypeToDateTimeList(dto.getDateRangeType())); + } + dto.setMchTypeCodes(List.of(MerchantTypeEnum.SUPERMARKET.getType())); + dto.setOrderStatus(HardOrderStatusEnum.getPayPrice()); + dto.setExcludeCanteenPay(YesNoEnum.YES.getCode()); + return R.ok(panelNutritionService.external(dto)); + } + } diff --git a/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/controller/panel/PanelShopController.java b/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/controller/panel/PanelShopController.java index b03b48eb4..a64983ea0 100644 --- a/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/controller/panel/PanelShopController.java +++ b/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/controller/panel/PanelShopController.java @@ -120,6 +120,7 @@ public class PanelShopController { @PostMapping(value = "/mch-pay-count-top") @Operation(summary = "排行榜") public R> mchPayCountTop(@RequestBody PanelProductDto dto) { + dto.setDateRangeType(DateRangeTypeEnum.TODAY); if (ObjectUtil.isNotEmpty(dto.getDateRangeType()) && ObjectUtil.isEmpty(dto.getTotalTimeList())) { dto.setTotalTimeList(DateRangeTool.transitionDateTypeToDateTimeList(dto.getDateRangeType())); } diff --git a/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/mapper/order/HardOrderMapper.java b/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/mapper/order/HardOrderMapper.java index ac43e58ee..e688bff99 100644 --- a/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/mapper/order/HardOrderMapper.java +++ b/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/mapper/order/HardOrderMapper.java @@ -158,4 +158,12 @@ public interface HardOrderMapper extends PjcloudBaseMapper { * 复购排行榜 */ List repurchase(@Param("dto") PanelProductDto dto); + + /** + * 超市数据统计(根据时间段和日期分类统计) + * 订单表位主表,商品表为从表 + */ + List shopGroupByMonthAndHourType(@Param("dto") PanelProductDto dto); + + List shopGroupByTimeAndHourType(@Param("dto") PanelProductDto dto); } \ No newline at end of file diff --git a/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/PanelNutritionService.java b/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/PanelNutritionService.java index d93ed2508..45377b12d 100644 --- a/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/PanelNutritionService.java +++ b/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/PanelNutritionService.java @@ -35,4 +35,9 @@ public interface PanelNutritionService { * 复购排行榜 */ List repurchase(PanelProductDto dto); + + /** + * 外部就餐情况(合作商家) + */ + PanelPorductVo.HourTypeVo external(PanelProductDto dto); } diff --git a/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/impl/panel/PanelNutritionServiceImpl.java b/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/impl/panel/PanelNutritionServiceImpl.java index 69208b4bb..c340d5b05 100644 --- a/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/impl/panel/PanelNutritionServiceImpl.java +++ b/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/impl/panel/PanelNutritionServiceImpl.java @@ -4,6 +4,8 @@ import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.util.ObjectUtil; import com.bsd.pjcloud.canteen.api.feign.RemoteCanteenCategoryService; import com.bsd.pjcloud.canteen.entity.CanteenCategoryEntity; +import com.bsd.pjcloud.common.core.constant.enums.DateRangeTypeEnum; +import com.bsd.pjcloud.hard.api.constant.order.HardHourTypeEnum; import com.bsd.pjcloud.hard.api.dto.order.app.HardAppProductByClassifyDto; import com.bsd.pjcloud.hard.api.dto.order.app.HardAppProductLikeTopDto; import com.bsd.pjcloud.hard.api.dto.panel.PanelProductDto; @@ -207,6 +209,55 @@ public class PanelNutritionServiceImpl implements PanelNutritionService { return list; } + /** + * 外部就餐情况(合作商家) + */ + @Override + public PanelPorductVo.HourTypeVo external(PanelProductDto dto) { + RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes(); + List dateList = PanelPorductVo.generatePanelCanteenList(dto.getTotalTimeList(), dto.getDateRangeType()); + PanelPorductVo.HourTypeVo result = new PanelPorductVo.HourTypeVo(); + + List hourTypeList = List.of(HardHourTypeEnum.MORNING, HardHourTypeEnum.NOONING, HardHourTypeEnum.NIGHT); + for (CompletableFuture voidCompletableFuture : hourTypeList.stream().map(hourType -> CompletableFuture.runAsync(() -> { + RequestContextHolder.setRequestAttributes(requestAttributes); + PanelProductDto queryDto = BeanUtil.toBean(dto, PanelProductDto.class); + List sqlList = new ArrayList<>(); + if (ObjectUtil.equals(dto.getDateRangeType(), DateRangeTypeEnum.THIS_YEAR)) { + sqlList = hardOrderMapper.shopGroupByMonthAndHourType(queryDto); + } else { + sqlList = hardOrderMapper.shopGroupByTimeAndHourType(queryDto); + } + // 处理查询出来的数据 + List resultList = BeanUtil.copyToList(dateList, PanelPorductVo.class); + for (PanelPorductVo v : resultList) { + sqlList.stream().filter(item -> ObjectUtil.equals(item.getTime(), v.getTime())).forEach(target -> { + v.setHourType(target.getHourType()); + v.setPersonCount(target.getPersonCount()); + v.setBuyCount(target.getBuyCount()); + v.setBuyProductCount(target.getBuyProductCount()); + v.setTotalPrice(target.getTotalPrice()); + }); + } + // 组装数据 + PanelPorductVo.ProductTypeItemVo vo = PanelPorductVo.ProductTypeItemVo.builder().list(resultList).type(hourType.getType()).typeStr(hourType.getDescription()).build(); + switch (hourType) { + case MORNING: + result.setMorning(vo); + break; + case NOONING: + result.setNoon(vo); + break; + case NIGHT: + result.setEvening(vo); + break; + } + })).toList()) { + voidCompletableFuture.join(); + } + return result; + } + private void disposeRepurchaseList(List list, PanelProductDto dto) { if (ObjectUtil.isEmpty(list)) return; // 处理菜品分类 diff --git a/pjcloud-hardware/pjcloud-hardware-biz/src/main/resources/mapper/order/HardOrderMapper.xml b/pjcloud-hardware/pjcloud-hardware-biz/src/main/resources/mapper/order/HardOrderMapper.xml index 91866ecc7..840081362 100644 --- a/pjcloud-hardware/pjcloud-hardware-biz/src/main/resources/mapper/order/HardOrderMapper.xml +++ b/pjcloud-hardware/pjcloud-hardware-biz/src/main/resources/mapper/order/HardOrderMapper.xml @@ -592,40 +592,56 @@ + + c.del_flag = '0' + + and o.create_time between #{dto.totalTimeList[0]} and #{dto.totalTimeList[1]} + + + and o.hour_type = #{dto.hourType} + + + and o.merchant_type in + + #{v} + + + + and s.category_id in + + #{v} + + + + and s.category_id not in + + #{v} + + + + and o.order_status in + + #{v} + + + + @@ -633,38 +649,20 @@ select date(o.create_time) as time, o.hour_type as hourType, - SUM(a.product_count) as buyProductCount, - SUM(a.total_price) as totalPrice, + SUM(c.product_count) as buyProductCount, + SUM(c.total_price) as totalPrice, count(distinct o.id) as buyCount, count(distinct o.user_id) as personCount, s.category_id as classifyId - from hard_car a - inner join hard_parent_car p on a.parent_car_id = p.id and p.del_flag = '0' + from hard_car c + inner join hard_parent_car p on c.parent_car_id = p.id and p.del_flag = '0' inner join hard_order o on o.parent_car_id = p.id and o.del_flag = '0' and o.hour_type is not null and o.hour_type not in ('-1', 'null') - left join pjcloudx_canteen.canteen_spu s on a.product_id = s.id + left join pjcloudx_canteen.canteen_spu s on c.product_id = s.id - a.del_flag = '0' - - and o.create_time between #{dto.totalTimeList[0]} and #{dto.totalTimeList[1]} - - - and o.hour_type = #{dto.hourType} - - - and o.merchant_type in - - #{v} - - - - and s.category_id in - - #{v} - - + group by date(o.create_time) order by date(o.create_time) desc @@ -677,38 +675,20 @@ select date(o.create_time) as time, o.hour_type as hourType, - SUM(a.product_count) as buyProductCount, - SUM(a.total_price) as totalPrice, + SUM(c.product_count) as buyProductCount, + SUM(c.total_price) as totalPrice, count(distinct o.id) as buyCount, count(distinct o.user_id) as personCount, s.category_id as classifyId - from hard_car a - inner join hard_parent_car p on a.parent_car_id = p.id and p.del_flag = '0' + from hard_car c + inner join hard_parent_car p on c.parent_car_id = p.id and p.del_flag = '0' inner join hard_order o on o.parent_car_id = p.id and o.del_flag = '0' and o.hour_type is not null and o.hour_type not in ('-1', 'null') - left join pjcloudx_canteen.canteen_spu s on a.product_id = s.id + left join pjcloudx_canteen.canteen_spu s on c.product_id = s.id - a.del_flag = '0' - - and o.create_time between #{dto.totalTimeList[0]} and #{dto.totalTimeList[1]} - - - and o.hour_type = #{dto.hourType} - - - and o.merchant_type in - - #{v} - - - - and s.category_id in - - #{v} - - + group by date(o.create_time), o.hour_type order by date(o.create_time) desc @@ -721,38 +701,20 @@ select date(o.create_time) as time, o.hour_type as hourType, - SUM(a.product_count) as buyProductCount, - SUM(a.total_price) as totalPrice, + SUM(c.product_count) as buyProductCount, + SUM(c.total_price) as totalPrice, count(distinct o.id) as buyCount, count(distinct o.user_id) as personCount, s.category_id as classifyId - from hard_car a - inner join hard_parent_car p on a.parent_car_id = p.id and p.del_flag = '0' + from hard_car c + inner join hard_parent_car p on c.parent_car_id = p.id and p.del_flag = '0' inner join hard_order o on o.parent_car_id = p.id and o.del_flag = '0' and o.hour_type is not null and o.hour_type not in ('-1', 'null') - left join pjcloudx_canteen.canteen_spu s on a.product_id = s.id + left join pjcloudx_canteen.canteen_spu s on c.product_id = s.id - a.del_flag = '0' - - and o.create_time between #{dto.totalTimeList[0]} and #{dto.totalTimeList[1]} - - - and o.hour_type = #{dto.hourType} - - - and o.merchant_type in - - #{v} - - - - and s.category_id in - - #{v} - - + group by date_format(o.create_time, '%Y-%m'), o.hour_type order by date_format(o.create_time, '%Y-%m') desc @@ -763,41 +725,23 @@ select o.merchant_id as mchId, - a.product_name as productName, - sum(a.product_count) as buyProductCount, - SUM(a.total_price) as totalPrice, + c.product_name as productName, + sum(c.product_count) as buyProductCount, + SUM(c.total_price) as totalPrice, count(distinct o.id) as buyCount, count(distinct o.user_id) as personCount, s.category_id as classifyId - from hard_car a - inner join hard_parent_car p on a.parent_car_id = p.id and p.del_flag = '0' + from hard_car c + inner join hard_parent_car p on c.parent_car_id = p.id and p.del_flag = '0' inner join hard_order o on o.parent_car_id = p.id and o.del_flag = '0' and o.hour_type is not null and o.hour_type not in ('-1', 'null') - left join pjcloudx_canteen.canteen_spu s on a.product_id = s.id + left join pjcloudx_canteen.canteen_spu s on c.product_id = s.id - a.del_flag = '0' - - and o.create_time between #{dto.totalTimeList[0]} and #{dto.totalTimeList[1]} - - - and o.hour_type = #{dto.hourType} - - - and o.merchant_type in - - #{v} - - - - and s.category_id in - - #{v} - - - - and s.category_id not in - - #{v} - - + - GROUP BY a.product_id, o.user_id, o.hour_type + GROUP BY c.product_id, o.user_id, o.hour_type having COUNT(DISTINCT o.id) >= 2 - order by sum(a.product_count) desc + order by sum(c.product_count) desc limit #{dto.limit} + + + \ No newline at end of file