From 94b46737dafb39c7a08a2b6b08f2ddf0a63fbfb3 Mon Sep 17 00:00:00 2001 From: Xiang Date: Mon, 26 Jan 2026 09:23:56 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E9=92=89=E9=92=89=E6=B6=88=E6=81=AF?= =?UTF-8?q?=E9=99=90=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../jntyzx/constants/RedisKeyConstant.java | 11 +++++ .../modules/jntyzx/utils/MsgSendUtils.java | 47 +++++++++++++++++++ .../app/schedule/jntyzx/JtVenuePullTask.java | 12 +++-- .../jntyzx/JtVenueTomorrowPullTask.java | 3 +- 4 files changed, 67 insertions(+), 6 deletions(-) create mode 100644 xservice-core/src/main/java/com/xiang/app/modules/jntyzx/utils/MsgSendUtils.java diff --git a/xservice-core/src/main/java/com/xiang/app/modules/jntyzx/constants/RedisKeyConstant.java b/xservice-core/src/main/java/com/xiang/app/modules/jntyzx/constants/RedisKeyConstant.java index 848d41d..d7742d8 100644 --- a/xservice-core/src/main/java/com/xiang/app/modules/jntyzx/constants/RedisKeyConstant.java +++ b/xservice-core/src/main/java/com/xiang/app/modules/jntyzx/constants/RedisKeyConstant.java @@ -1,5 +1,9 @@ package com.xiang.app.modules.jntyzx.constants; +import com.xiang.xservice.basic.utils.DateUtils; + +import java.time.LocalDate; + /** * @Author: xiang * @Date: 2025-12-16 10:43 @@ -9,4 +13,11 @@ public class RedisKeyConstant { public static final String JNTYZX_ORDER_CREATE_KEY = "jntyzx:order:create:orderId:"; public static final String JNTUZX_ORDER_PEEK_KEY = "jntyzx:order:peek:user:"; + + public static final String JNTYZX_VENUE_MSG_SEND_KEY = "jntyzx:order:venue:msg:send"; + + public static String getDate() { + LocalDate now = LocalDate.now(); + return ":" + DateUtils.getDateFromDate(now); + } } diff --git a/xservice-core/src/main/java/com/xiang/app/modules/jntyzx/utils/MsgSendUtils.java b/xservice-core/src/main/java/com/xiang/app/modules/jntyzx/utils/MsgSendUtils.java new file mode 100644 index 0000000..8f653a4 --- /dev/null +++ b/xservice-core/src/main/java/com/xiang/app/modules/jntyzx/utils/MsgSendUtils.java @@ -0,0 +1,47 @@ +package com.xiang.app.modules.jntyzx.utils; + +import com.xiang.app.common.service.dingtalk.JtDingTalkFactory; +import com.xiang.app.modules.jntyzx.constants.RedisKeyConstant; +import com.xiang.xmc.service.cache.service.IRedisService; +import lombok.RequiredArgsConstructor; +import org.apache.commons.lang3.StringUtils; +import org.springframework.stereotype.Component; + +import java.util.concurrent.TimeUnit; + +/** + * @Author: xiang + * @Date: 2026-01-26 09:14 + */ +@Component +@RequiredArgsConstructor +public class MsgSendUtils { + + private final IRedisService redisService; + private final JtDingTalkFactory jtDingTalkFactory; + + /** + * 限制钉钉消息发送 1小时最多5次 + * @param redisKey redis缓存的key + * @param msgContent 消息内容 + */ + public void sendMsgRestrict1Hours(String redisKey, String msgContent) { + String key = RedisKeyConstant.JNTYZX_VENUE_MSG_SEND_KEY + RedisKeyConstant.getDate(); + String cache = (String) redisService.get(redisKey); + if (StringUtils.isNotBlank(cache)) { + int sendNum = Integer.parseInt(cache); + if (sendNum == 0) { + jtDingTalkFactory.sendMsg(msgContent); + redisService.set(key, "0", 1, TimeUnit.HOURS); + return; + } + if (sendNum > 0 && sendNum <= 5) { + jtDingTalkFactory.sendMsg(msgContent); + redisService.set(key, String.valueOf(++sendNum), 1, TimeUnit.HOURS); + } + } else { + jtDingTalkFactory.sendMsg(msgContent); + redisService.set(key, "0", 1, TimeUnit.HOURS); + } + } +} diff --git a/xservice-server/src/main/java/com/xiang/app/schedule/jntyzx/JtVenuePullTask.java b/xservice-server/src/main/java/com/xiang/app/schedule/jntyzx/JtVenuePullTask.java index de3f70a..8d6e9ed 100644 --- a/xservice-server/src/main/java/com/xiang/app/schedule/jntyzx/JtVenuePullTask.java +++ b/xservice-server/src/main/java/com/xiang/app/schedule/jntyzx/JtVenuePullTask.java @@ -1,12 +1,13 @@ package com.xiang.app.schedule.jntyzx; import com.google.common.collect.Maps; -import com.xiang.app.common.service.dingtalk.JtDingTalkFactory; +import com.xiang.app.modules.jntyzx.constants.RedisKeyConstant; import com.xiang.app.modules.jntyzx.entity.pojo.UserTokenInfoDO; import com.xiang.app.modules.jntyzx.entity.resp.query.SitePositionList; import com.xiang.app.modules.jntyzx.service.IJntyzxHttpService; import com.xiang.app.modules.jntyzx.service.IUserTokenInfoService; import com.xiang.app.modules.jntyzx.service.IVenueService; +import com.xiang.app.modules.jntyzx.utils.MsgSendUtils; import com.xiang.app.modules.jntyzx.utils.VenueInfoUtils; import com.xiang.app.modules.jntyzx.utils.WeekendUtils; import com.xiang.core.quartz.annotation.XxzJob; @@ -36,8 +37,8 @@ public class JtVenuePullTask { private final IUserTokenInfoService userTokenInfoService; private final IJntyzxHttpService jntyzxHttpService; - private final JtDingTalkFactory jtDingTalkFactory; private final IVenueService venueService; + private final MsgSendUtils msgSendUtils; @XxzJob(name = "jtVenueInfoPullTask") @GetMapping("/jtVenueInfoPullTask") @@ -71,11 +72,14 @@ public class JtVenuePullTask { return; } - StringBuffer msg = new StringBuffer("查询到20:00-22:00空闲场地信息===>\n时间:" + DateUtils.getDateFromDate(LocalDate.now())); + StringBuffer msg = new StringBuffer( + "查询到20:00-22:00空闲场地信息=====>\n时间:" + DateUtils.getDateFromDate(LocalDate.now()) + "\n"); sitePositionLists.forEach(item -> { msg.append(item.getPlaceName()).append("\n"); }); - jtDingTalkFactory.sendMsg(msg.toString()); + + String key = RedisKeyConstant.JNTYZX_VENUE_MSG_SEND_KEY + RedisKeyConstant.getDate(); + msgSendUtils.sendMsgRestrict1Hours(key, msg.toString()); } } diff --git a/xservice-server/src/main/java/com/xiang/app/schedule/jntyzx/JtVenueTomorrowPullTask.java b/xservice-server/src/main/java/com/xiang/app/schedule/jntyzx/JtVenueTomorrowPullTask.java index 275caf7..134ece3 100644 --- a/xservice-server/src/main/java/com/xiang/app/schedule/jntyzx/JtVenueTomorrowPullTask.java +++ b/xservice-server/src/main/java/com/xiang/app/schedule/jntyzx/JtVenueTomorrowPullTask.java @@ -16,7 +16,6 @@ import com.xiang.xservice.basic.utils.DateUtils; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Component; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @@ -78,7 +77,7 @@ public class JtVenueTomorrowPullTask { } map.put(sitePositionList.getPlaceName(), sitePositionList); } - StringBuffer msg = new StringBuffer("查询江体场地信息===>时间:\n" + DateUtils.getDateFromDate(LocalDate.now().plusDays(1)) + " 20:00-22:00\n"); + StringBuffer msg = new StringBuffer("查询江体场地信息=====>\n时间:" + DateUtils.getDateFromDate(LocalDate.now().plusDays(1)) + " 20:00-22:00\n"); map.forEach((placeName, sitePositionList) -> { msg.append(placeName).append("订购人:").append(sitePositionList.getContacts()).append("\n"); });