2 Commits

Author SHA1 Message Date
Xiang
211cca9a4b fix:钉钉消息限制 2026-01-26 09:32:44 +08:00
Xiang
94b46737da fix:钉钉消息限制 2026-01-26 09:23:56 +08:00
4 changed files with 63 additions and 6 deletions

View File

@@ -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);
}
}

View File

@@ -0,0 +1,42 @@
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 && 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);
}
}
}

View File

@@ -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,15 @@ 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());
return;
}
}

View File

@@ -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");
});