diff --git a/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/controller/panel/PanelCanteenController.java b/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/controller/panel/PanelCanteenController.java index 49be49e19..ddee43840 100644 --- a/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/controller/panel/PanelCanteenController.java +++ b/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/controller/panel/PanelCanteenController.java @@ -1,15 +1,20 @@ package com.bsd.pjcloud.hard.controller.panel; import cn.hutool.core.util.ObjectUtil; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.bsd.pjcloud.common.core.util.DateRangeTool; import com.bsd.pjcloud.common.core.util.R; +import com.bsd.pjcloud.hard.api.dto.order.HardOrderDto; import com.bsd.pjcloud.hard.api.dto.panel.PanelCanteenDto; import com.bsd.pjcloud.hard.api.vo.hard.PanelCanteenVo; +import com.bsd.pjcloud.hard.api.vo.order.HardOrderVo; +import com.bsd.pjcloud.hard.service.HardOrderService; import com.bsd.pjcloud.hard.service.PanelCanteenService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.security.SecurityRequirement; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; +import org.springdoc.core.annotations.ParameterObject; import org.springframework.http.HttpHeaders; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; @@ -25,6 +30,7 @@ import java.util.List; public class PanelCanteenController { private final PanelCanteenService panelCanteenService; + private final HardOrderService hardwareOrderService; @PostMapping(value = "/group/by-time-and-hour-type") @Operation(summary = "用餐数据统计(根据时间段和日期分类统计)") @@ -35,6 +41,15 @@ public class PanelCanteenController { return R.ok(panelCanteenService.groupByTimeAndHourType(dto)); } + @PostMapping(value = "/group/classify/by-time-and-hour-type") + @Operation(summary = "菜品分类统计(根据时间段和日期分类统计)") + public R classifyGroupByTimeAndHourType(PanelCanteenDto dto) { + if (ObjectUtil.isNotEmpty(dto.getDateRangeType()) && ObjectUtil.isNotEmpty(dto.getTotalTimeList())) { + dto.setTotalTimeList(DateRangeTool.transitionDateTypeToDateTimeList(dto.getDateRangeType())); + } + return R.ok(panelCanteenService.classifyGroupByTimeAndHourType(dto)); + } + @PostMapping(value = "/group/by-time-and-custom-hour") @Operation(summary = "用餐数据统计(根据自定义时间段和日期分类统计)") public R> groupByTimeAndCustomHour(PanelCanteenDto dto) { @@ -54,5 +69,9 @@ public class PanelCanteenController { return R.ok(panelCanteenService.top(dto)); } - + @PostMapping(value = "/new-page") + @Operation(summary = "最新的吃饭数据") + public R> newPage(@ParameterObject Page page, HardOrderDto dto) { + return R.ok(hardwareOrderService.scopePageList(page, dto, null)); + } } diff --git a/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/redis/RedisKeyExpirationListener.java b/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/redis/RedisKeyExpirationListener.java new file mode 100644 index 000000000..06d3066f6 --- /dev/null +++ b/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/redis/RedisKeyExpirationListener.java @@ -0,0 +1,68 @@ +package com.bsd.pjcloud.hard.redis; + +import cn.hutool.core.util.ObjectUtil; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.bsd.pjcloud.common.core.constant.CacheConstants; +import com.bsd.pjcloud.hard.api.constant.order.HardOrderStatusEnum; +import com.bsd.pjcloud.hard.api.constant.order.HardOrderTypeEnum; +import com.bsd.pjcloud.hard.api.constant.order.HardPayTypeEnum; +import com.bsd.pjcloud.hard.api.entity.order.HardOrderEntity; +import com.bsd.pjcloud.hard.mapper.order.HardOrderMapper; +import jakarta.annotation.Resource; +import lombok.extern.log4j.Log4j2; +import org.springframework.data.redis.connection.Message; +import org.springframework.data.redis.listener.KeyExpirationEventMessageListener; +import org.springframework.data.redis.listener.RedisMessageListenerContainer; +import org.springframework.stereotype.Component; + +import java.nio.charset.StandardCharsets; + +/** + * 监听Redis的Key过期事件 + */ +@Component +@Log4j2 +public class RedisKeyExpirationListener extends KeyExpirationEventMessageListener { + + @Resource + private HardOrderMapper hardOrderMapper; + + public RedisKeyExpirationListener(RedisMessageListenerContainer listenerContainer) { + super(listenerContainer); + } + + @Override + public void onMessage(Message message, byte[] pattern) { + String expiredKey = message.toString(); + String expiredPattern = new String(pattern, StandardCharsets.UTF_8); + + // 过期订单(扫一扫支付) + if (expiredKey.startsWith(CacheConstants.HARDER_ORDER_NON_PAY)) { + log.info("hard模块RedisKey过期,pattern|{}|key|{}|", expiredPattern, expiredKey); + disposeExpiredQrCodeScanOrder(expiredKey); + } + } + + // 删除过期的扫一扫订单 + public void disposeExpiredQrCodeScanOrder(String expiredValue) { + if (ObjectUtil.isEmpty(expiredValue)) return; + + String orderId = expiredValue.substring(CacheConstants.HARDER_ORDER_NON_PAY.length() + 1); + + HardOrderEntity order = hardOrderMapper.selectOne(new LambdaQueryWrapper() + .eq(HardOrderEntity::getId, orderId) + .eq(HardOrderEntity::getPayType, HardPayTypeEnum.WALLET_QR_CODE_SCAN.getType()) + .eq(HardOrderEntity::getOrderStatus, HardOrderStatusEnum.CREATE.getType()) + ); + if (ObjectUtil.isEmpty(order)) { + log.info("删除过期的扫一扫订单,订单不存在orderId|{}|", orderId); + return; + } + if (ObjectUtil.isEmpty(order.getWalletId()) && ObjectUtil.equals(order.getUserId(), -1L)) { + // 删除订单 + hardOrderMapper.deleteById(order.getId()); + log.info("删除过期的扫一扫订单,orderId|{}|", expiredValue); + } + } + +} diff --git a/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/PanelCanteenService.java b/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/PanelCanteenService.java index 0fee70501..b0a163919 100644 --- a/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/PanelCanteenService.java +++ b/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/PanelCanteenService.java @@ -12,6 +12,11 @@ public interface PanelCanteenService { */ PanelCanteenVo.HourTypeVo groupByTimeAndHourType(PanelCanteenDto dto); + /** + * 菜品分类统计(根据时间段和日期分类统计) + */ + PanelCanteenVo.HourTypeVo classifyGroupByTimeAndHourType(PanelCanteenDto dto); + /** * 用餐数据统计(根据自定义时间段和日期分类统计) */ diff --git a/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/impl/panel/PanelCanteenServiceImpl.java b/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/impl/panel/PanelCanteenServiceImpl.java index 7b3c806ca..3d63734e6 100644 --- a/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/impl/panel/PanelCanteenServiceImpl.java +++ b/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/impl/panel/PanelCanteenServiceImpl.java @@ -72,6 +72,15 @@ public class PanelCanteenServiceImpl implements PanelCanteenService { return result; } + /** + * 菜品分类统计(根据时间段和日期分类统计) + */ + @Override + public PanelCanteenVo.HourTypeVo classifyGroupByTimeAndHourType(PanelCanteenDto dto) { + List sqlList = hardOrderMapper.groupByTimeAndHourType(dto); + return null; + } + /** * 用餐数据统计(根据时间段和日期分类统计) */ @@ -85,7 +94,7 @@ public class PanelCanteenServiceImpl implements PanelCanteenService { */ @Override public List top(PanelCanteenDto dto) { - return hardOrderMapper.top(dto); + return hardOrderMapper.top(dto); } private List generatePanelCanteenList(LocalDateTime[] totalTimeList) {