fix:钉钉消息限制
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user