7 Commits

Author SHA1 Message Date
Xiang
1ad4012070 perf:新增日志 2026-03-05 09:16:15 +08:00
Xiang
9e599ad5ae feat:用户信息更新 2026-03-03 09:15:13 +08:00
Xiang
59ebe2b349 feat:测试代码 2026-02-25 11:09:02 +08:00
Xiang
7f35a9960d fix:控制请求 2026-02-11 15:47:58 +08:00
Xiang
963e03c5c9 fix:版本更新 2026-02-11 15:43:44 +08:00
Xiang
211cca9a4b fix:钉钉消息限制 2026-01-26 09:32:44 +08:00
Xiang
94b46737da fix:钉钉消息限制 2026-01-26 09:23:56 +08:00
12 changed files with 208 additions and 26 deletions

View File

@@ -29,7 +29,7 @@
<dependency>
<groupId>com.xiang.starter</groupId>
<artifactId>xmc-common</artifactId>
<version>1.0</version>
<version>1.1</version>
</dependency>
<dependency>
<groupId>com.xiang.starter</groupId>
@@ -44,7 +44,7 @@
<dependency>
<groupId>com.xiang.starter</groupId>
<artifactId>xmc-http-starter</artifactId>
<version>2.0-SNAPSHOT</version>
<version>2.0</version>
</dependency>
<dependency>
<groupId>com.xiang.starter</groupId>
@@ -54,12 +54,12 @@
<dependency>
<groupId>com.xiang.starter</groupId>
<artifactId>xservice-quartz-core</artifactId>
<version>1.1</version>
<version>1.2</version>
</dependency>
<dependency>
<groupId>com.xiang.starter</groupId>
<artifactId>xmc-logger-starter</artifactId>
<version>1.0</version>
<version>1.1</version>
</dependency>
</dependencies>

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

@@ -1,5 +1,6 @@
package com.xiang.app.modules.jntyzx.entity.resp.query;
import com.alibaba.fastjson.annotation.JSONField;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@@ -94,6 +95,7 @@ public class UserInfoResponse {
/**
* 封禁截止日期
*/
@JSONField(name = "restrictionDeadline")
private String restrictionDeadline;
/**
* 封禁原因
@@ -102,5 +104,6 @@ public class UserInfoResponse {
/**
* 封禁截止日期
*/
private String RestrictionDeadline;
@JSONField(name = "RestrictionDeadline")
private String RestrictionDeadline2;
}

View File

@@ -5,9 +5,7 @@ import com.alibaba.fastjson2.JSONObject;
import com.alibaba.fastjson2.TypeReference;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.xiang.app.modules.jntyzx.constants.RedisKeyConstant;
import com.xiang.app.modules.jntyzx.constants.UrlConstant;
import com.xiang.app.modules.jntyzx.entity.pojo.OrderInfoDO;
import com.xiang.app.modules.jntyzx.entity.pojo.VenueInfoDO;
import com.xiang.app.modules.jntyzx.entity.req.SubscribeRequest;
import com.xiang.app.modules.jntyzx.entity.req.SubscribeVo;
@@ -20,10 +18,7 @@ import com.xiang.app.modules.jntyzx.manage.IOrderCreateInfoManage;
import com.xiang.app.modules.jntyzx.service.IJntyzxHttpService;
import com.xiang.app.modules.jntyzx.utils.JntyzxSaltEncodeUtils;
import com.xiang.xmc.service.cache.service.IRedisService;
import com.xiang.xmc.service.http.helper.BaseHttpHelp;
import com.xiang.xmc.service.http.helper.HttpHelper;
import com.xiang.xmc.service.http.helper.HttpHelperFactory;
import com.xiang.xservice.basic.utils.Base64;
import com.xiang.xservice.basic.utils.JsonUtils;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@@ -32,9 +27,6 @@ import org.jetbrains.annotations.NotNull;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.nio.charset.StandardCharsets;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
import java.util.Objects;
@@ -154,14 +146,15 @@ public class JntyzxHttpServiceImpl implements IJntyzxHttpService {
Map<String, String> params = Maps.newHashMap();
params.put("X-Access-Token", token);
String resp = HttpHelper.doPost(UrlConstant.ADD_SUBSCRIBE, params, JsonUtils.toJsonString(subscribeRequest));
log.info("[江体小程序] 羽毛球场地下单响应结果:{}", resp);
if (StringUtils.isBlank(resp)) {
log.info("请求结果为空");
log.info("[resp] 请求结果为空");
return null;
}
JntyzxResponse<OrderCreateResp> response = JSON.parseObject(resp, new TypeReference<JntyzxResponse<OrderCreateResp>>() {
});
if (Objects.isNull(response)) {
log.info("请求结果为空");
log.info("[res ==> response] 请求结果为空");
return null;
}
return response;

View File

@@ -71,10 +71,10 @@ public class UserTokenInfoServiceImpl implements IUserTokenInfoService {
log.info("【心跳监测】查询用户信息为空,无需操作");
return true;
}
userTokenInfoDOS.parallelStream().forEach(this::healthDeclaration);
userTokenInfoDOS.forEach(this::healthDeclaration);
// 信息更新
userTokenInfoDOS = userTokenInfoManage.list();
userTokenInfoDOS.parallelStream().forEach(this::queryMemberCardInfo);
userTokenInfoDOS.forEach(this::queryMemberCardInfo);
return true;
}
@@ -123,18 +123,18 @@ public class UserTokenInfoServiceImpl implements IUserTokenInfoService {
if (response.getSuccess()) {
UserInfoResponse userInfoResponse = response.getResult();
userTokenInfoDO.setMemberCardNo(userInfoResponse.getConsCard());
if (StringUtils.isNotBlank(userInfoResponse.getRestrictionDeadline())) {
if (StringUtils.isNotBlank(userInfoResponse.getRestrictionDeadline2())) {
userTokenInfoDO.setIsRestriction(1);
userTokenInfoDO.setIsOrder(0);
UserRestrictionInfo userRestrictionInfo = userRestrictionManage.queryByUserId(userTokenInfoDO.getId());
if (Objects.isNull(userRestrictionInfo)) {
userRestrictionInfo = new UserRestrictionInfo();
userRestrictionInfo.setUserId(userTokenInfoDO.getId());
userRestrictionInfo.setRestrictionDeadline(DateUtils.getDateTimeFromStr(userInfoResponse.getRestrictionDeadline()));
userRestrictionInfo.setRestrictionDeadline(DateUtils.getDateTimeFromStr(userInfoResponse.getRestrictionDeadline2()));
userRestrictionInfo.setRestrictionDesc(userInfoResponse.getRestrictionDescription());
userRestrictionManage.save(userRestrictionInfo);
} else {
userRestrictionInfo.setRestrictionDeadline(DateUtils.getDateTimeFromStr(userInfoResponse.getRestrictionDeadline()));
userRestrictionInfo.setRestrictionDeadline(DateUtils.getDateTimeFromStr(userInfoResponse.getRestrictionDeadline2()));
userRestrictionInfo.setRestrictionDesc(userInfoResponse.getRestrictionDescription());
userRestrictionManage.updateById(userRestrictionInfo);
}

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

@@ -0,0 +1,90 @@
package com.xiang.app.debugger;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import lombok.extern.slf4j.Slf4j;
import java.util.List;
import java.util.Map;
/**
* @Author: xiang
* @Date: 2026-02-25 10:23
*/
@Slf4j
public class OrderTest {
private static final UserTest userA = new UserTest(1L, "123");
private static final UserTest userB = new UserTest(2L, "234");
private static final UserTest userC = new UserTest(3L, "345");
private static final List<UserTest> users = Lists.newArrayList(userA, userB, userC);
private static final VenueInfoTest v1 = new VenueInfoTest(1L, "一号场地");
private static final VenueInfoTest v2 = new VenueInfoTest(2L, "二号场地");
private static final VenueInfoTest v3 = new VenueInfoTest(3L, "三号场地");
private static final Map<String, VenueInfoTest> venueInfoMap = Maps.newHashMap();
static {
venueInfoMap.put(v1.getPlaceName(), v1);
venueInfoMap.put(v2.getPlaceName(), v2);
venueInfoMap.put(v3.getPlaceName(), v3);
}
public static void main(String[] args) {
OrderTest orderTest = new OrderTest();
orderTest.test();
}
public void test() {
users.parallelStream().forEach(user -> {
try {
for (String placeName : venueInfoMap.keySet()) {
VenueInfoTest venueInfoTest = venueInfoMap.get(placeName);
for (int i = 0; i < 10; i++) {
boolean order = createOrder(venueInfoTest, user);
if (order) {
return;
}
try {
log.info("睡眠中 1.25s");
Thread.sleep(1250);
} catch (InterruptedException e) {
log.error("睡眠失败~~~");
}
}
}
} catch (Exception e) {
// 关键点:异常只影响当前 user
log.error("createOrder 异常user={}", user.getId(), e);
return; // 结束这个 user不影响其他 user
}
});
}
private boolean createOrder(VenueInfoTest venueInfoTest, UserTest userTest) {
log.info("用户:{}======>请求三方接口中", userTest.getUsername());
String order = order(venueInfoTest, userTest);
log.info("用户:{}======>请求结果::{}", userTest.getUsername(), order);
if (order.contains("成功")) {
return true;
}
if (order.contains("锁卡")) {
return true;
}
return false;
}
private String order(VenueInfoTest venueInfoTest, UserTest userTest) {
String msg = "";
if (venueInfoTest.getId() == 1L && userTest.getId() == 2L) {
msg = "用户" + userTest.getUsername() + "预定成功!";
return msg;
}
if (userTest.getId() == 1L) {
msg = "用户" + userTest.getUsername() + "频繁请求接口,将锁卡";
return msg;
}
if (venueInfoTest.getId() == 2L) {
msg = "场地" + venueInfoTest.getPlaceName() + "已被预订";
}
return msg;
}
}

View File

@@ -0,0 +1,16 @@
package com.xiang.app.debugger;
import lombok.AllArgsConstructor;
import lombok.Data;
/**
* @Author: xiang
* @Date: 2026-02-25 10:24
*/
@Data
@AllArgsConstructor
public class UserTest {
private Long id;
private String username;
}

View File

@@ -0,0 +1,18 @@
package com.xiang.app.debugger;
import lombok.AllArgsConstructor;
import lombok.Data;
/**
* @Author: xiang
* @Date: 2026-02-25 10:28
*/
@Data
@AllArgsConstructor
public class VenueInfoTest {
private Long id;
private String placeName;
}

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

@@ -58,6 +58,11 @@ public class JtVenueSubscribeTask {
if (order) {
return;
}
try {
Thread.sleep(1250);
} catch (InterruptedException e) {
log.error("睡眠失败~~~");
}
}
}
} catch (Exception e) {

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