Compare commits
5 Commits
211cca9a4b
...
perf/order
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1ad4012070 | ||
|
|
9e599ad5ae | ||
|
|
59ebe2b349 | ||
|
|
7f35a9960d | ||
|
|
963e03c5c9 |
8
pom.xml
8
pom.xml
@@ -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>
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
}
|
||||
@@ -58,6 +58,11 @@ public class JtVenueSubscribeTask {
|
||||
if (order) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
Thread.sleep(1250);
|
||||
} catch (InterruptedException e) {
|
||||
log.error("睡眠失败~~~");
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
||||
Reference in New Issue
Block a user