Compare commits
7 Commits
fix/userin
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
714bd3ce06 | ||
|
|
a20cdc46fd | ||
|
|
9d14b3b7dc | ||
|
|
eb441b03e5 | ||
|
|
d40a15cbb5 | ||
|
|
7bf6b5d5ed | ||
|
|
1ad4012070 |
@@ -16,6 +16,18 @@ public class RedisKeyConstant {
|
||||
|
||||
public static final String JNTYZX_VENUE_MSG_SEND_KEY = "jntyzx:order:venue:msg:send";
|
||||
|
||||
private static final String JNTYZX_VENUE_SUBSCRIBE_KEY = "jntyzx:venue:subscribe:";
|
||||
|
||||
private static final String JNTYZX_ORDER_CLOSE_CARD_KEY = "jntyzx:order:close:card:";
|
||||
|
||||
public static String getCloseCardKey(String username) {
|
||||
return JNTYZX_ORDER_CLOSE_CARD_KEY + username + ":" +getDate();
|
||||
}
|
||||
|
||||
public static String getVenueSubscribeKey(String placeName) {
|
||||
return JNTYZX_VENUE_SUBSCRIBE_KEY + placeName + ":" + getDate();
|
||||
}
|
||||
|
||||
public static String getDate() {
|
||||
LocalDate now = LocalDate.now();
|
||||
return ":" + DateUtils.getDateFromDate(now);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -50,6 +50,12 @@ public class OrderInfoServiceImpl implements IJtOrderService {
|
||||
return true;
|
||||
}
|
||||
|
||||
String user = (String) redisService.get(RedisKeyConstant.getCloseCardKey(userTokenInfoDO.getName()));
|
||||
if (StringUtils.isNotBlank(user)) {
|
||||
log.info("用户:{}有锁卡风险,不在请求接口!");
|
||||
return true;
|
||||
}
|
||||
|
||||
JntyzxResponse<OrderCreateResp> orderResp = jntyzxHttpService.createOrder(venueInfoDOS, userTokenInfoDO.getToken(), userTokenInfoDO.getOpenId());
|
||||
if (Objects.isNull(orderResp)) {
|
||||
return false;
|
||||
@@ -80,8 +86,13 @@ public class OrderInfoServiceImpl implements IJtOrderService {
|
||||
}
|
||||
if (orderResp.getMessage().contains("限制")) {
|
||||
log.info("改会员卡被限制,不在请求,用户:{}", userTokenInfoDO.getName());
|
||||
redisService.set(RedisKeyConstant.getCloseCardKey(userTokenInfoDO.getName()), "true");
|
||||
throw new BusinessException("会员卡被限制,不在请求");
|
||||
}
|
||||
if (orderResp.getMessage().contains("已有人预订")) {
|
||||
log.info("该场地已被人预定,更换场地, 用户:{}", userTokenInfoDO.getName());
|
||||
redisService.set(RedisKeyConstant.getVenueSubscribeKey(venueInfoDOS.get(0).getPlaceName()), "true");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,4 +25,17 @@ public class VenueInfoUtils {
|
||||
public static boolean get8210VenueInfo(SitePositionList sitePositionList) {
|
||||
return StringUtils.equals(sitePositionList.getSjName(), "20:00-21:00") || StringUtils.equals(sitePositionList.getSjName(), "21:00-22:00");
|
||||
}
|
||||
|
||||
public static int sortVenueInfo(String placeName) {
|
||||
if (placeName.contains("十号")) {
|
||||
return 0;
|
||||
}
|
||||
if (placeName.contains("二号")) {
|
||||
return 1;
|
||||
}
|
||||
if (placeName.contains("九号")) {
|
||||
return 2;
|
||||
}
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ import org.springframework.context.annotation.ComponentScan;
|
||||
@SpringBootApplication
|
||||
@ConfigurationPropertiesScan(basePackages = {
|
||||
"com.xiang.xservice.logger",
|
||||
"com.xiang.xmc.service.http"
|
||||
})
|
||||
@MapperScan(basePackages = {
|
||||
"com.xiang.app.modules.*.mapper"
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.xiang.app;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
public class HealthController {
|
||||
|
||||
@Value("${spring.profiles.active}")
|
||||
private String env;
|
||||
|
||||
@GetMapping("/actuator/health")
|
||||
public Map<String, String> checkHealth() {
|
||||
Map<String, String> map = Maps.newHashMap();
|
||||
map.put("env", env);
|
||||
map.put("status", "UP");
|
||||
log.info("cornucopia application health check success! listening in env:{}, now:{}", env, System.currentTimeMillis());
|
||||
return map;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
package com.xiang.app.schedule.jntyzx;
|
||||
|
||||
import com.xiang.app.modules.jntyzx.constants.RedisKeyConstant;
|
||||
import com.xiang.app.modules.jntyzx.entity.pojo.UserTokenInfoDO;
|
||||
import com.xiang.app.modules.jntyzx.entity.pojo.VenueInfoDO;
|
||||
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.IJtOrderService;
|
||||
import com.xiang.app.modules.jntyzx.service.IUserTokenInfoService;
|
||||
import com.xiang.app.modules.jntyzx.utils.VenueInfoUtils;
|
||||
import com.xiang.app.modules.jntyzx.utils.WeekendUtils;
|
||||
import com.xiang.core.quartz.annotation.XxzJob;
|
||||
import com.xiang.xmc.service.cache.service.IRedisService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.collections4.MapUtils;
|
||||
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;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 江体小程序场地捡漏任务 周日和周二 启动捡漏周一和周三的场地
|
||||
* @Author: xiang
|
||||
* @Date: 2026-03-23 09:23
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
public class JtVenuePickTask {
|
||||
|
||||
private final IJntyzxHttpService jntyzxHttpService;
|
||||
private final IUserTokenInfoService userTokenInfoService;
|
||||
private final IRedisService redisService;
|
||||
private final IJtOrderService jtOrderService;
|
||||
|
||||
|
||||
@XxzJob(name = "jtVenuePickTask")
|
||||
@GetMapping("jtVenuePickTask")
|
||||
public void handler() {
|
||||
log.info("江体小程序场地捡漏,time:{}", System.currentTimeMillis());
|
||||
|
||||
List<UserTokenInfoDO> availableUser = userTokenInfoService.getAvailableUser();
|
||||
if (CollectionUtils.isEmpty(availableUser)) {
|
||||
log.info("当前无可用用户查询场地信息!");
|
||||
return;
|
||||
}
|
||||
UserTokenInfoDO userTokenInfoDO = availableUser.get(0);
|
||||
|
||||
if (Objects.isNull(userTokenInfoDO)) {
|
||||
return;
|
||||
}
|
||||
String subscribeKey = RedisKeyConstant.JNTYZX_ORDER_CREATE_KEY + userTokenInfoDO.getName() + LocalDate.now();
|
||||
String subscribeValue = (String) redisService.get(subscribeKey);
|
||||
if (StringUtils.isNotBlank(subscribeValue)) {
|
||||
log.info("用户:{}今日已进行场地预定,不进行捡漏处理!", userTokenInfoDO.getName());
|
||||
return;
|
||||
}
|
||||
|
||||
String token = userTokenInfoDO.getToken();
|
||||
List<SitePositionList> sitePositionLists = jntyzxHttpService.queryAvailableTomorrow(WeekendUtils.isWeekend(), token);
|
||||
sitePositionLists = sitePositionLists.stream()
|
||||
.filter(item -> !item.getPlaceName().contains("小馆"))
|
||||
.filter(VenueInfoUtils::get8210VenueInfo)
|
||||
.filter(item -> StringUtils.equals(item.getContacts(), "0")).toList();
|
||||
if (CollectionUtils.isEmpty(sitePositionLists)) {
|
||||
log.info("目前没有可以捡漏的场地");
|
||||
return;
|
||||
}
|
||||
Map<String, List<VenueInfoDO>> map = sitePositionLists.stream().map(item -> {
|
||||
VenueInfoDO venueInfoDO = new VenueInfoDO();
|
||||
venueInfoDO.setPlaceName(item.getPlaceName());
|
||||
venueInfoDO.setPlaceId(item.getPlaceId());
|
||||
venueInfoDO.setScheduleId(Integer.valueOf(item.getScheduleId()));
|
||||
venueInfoDO.setSjName(item.getSjName());
|
||||
venueInfoDO.setMoney(item.getMoney());
|
||||
venueInfoDO.setClassName(item.getClassName());
|
||||
venueInfoDO.setClassCode(item.getClassCode());
|
||||
venueInfoDO.setAppointments(item.getAppointments());
|
||||
venueInfoDO.setCTypeCode(item.getCtypeCode());
|
||||
return venueInfoDO;
|
||||
}).collect(Collectors.groupingByConcurrent(VenueInfoDO::getPlaceName));
|
||||
|
||||
if (MapUtils.isEmpty(map)) {
|
||||
log.info("暂无可下单场地,time:{}", System.currentTimeMillis());
|
||||
return;
|
||||
}
|
||||
|
||||
List<UserTokenInfoDO> users = userTokenInfoService.getCanOrderUser();
|
||||
if (CollectionUtils.isEmpty(users)) {
|
||||
log.info("暂无可下单用户, time:{}", System.currentTimeMillis());
|
||||
return;
|
||||
}
|
||||
users.parallelStream().forEach(user -> {
|
||||
try {
|
||||
List<String> placeNameList = map.keySet().stream().sorted(Comparator.comparing(VenueInfoUtils::sortVenueInfo)).toList();
|
||||
for (String placeName : placeNameList) {
|
||||
List<VenueInfoDO> venueInfoDOList = map.get(placeName);
|
||||
String valid = (String) redisService.get(RedisKeyConstant.getVenueSubscribeKey(placeName));
|
||||
if (StringUtils.isNotBlank(valid)) {
|
||||
break;
|
||||
}
|
||||
boolean order = jtOrderService.createOrder(venueInfoDOList, user);
|
||||
if (order) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
Thread.sleep(1250);
|
||||
} catch (InterruptedException e) {
|
||||
log.error("睡眠失败~~~");
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// 关键点:异常只影响当前 user
|
||||
log.error("createOrder 异常,user={}", user.getId(), e);
|
||||
return; // 结束这个 user,不影响其他 user
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.xiang.app.schedule.jntyzx;
|
||||
|
||||
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.pojo.VenueInfoDO;
|
||||
import com.xiang.app.modules.jntyzx.service.IJtOrderService;
|
||||
@@ -8,14 +9,17 @@ import com.xiang.app.modules.jntyzx.service.IUserTokenInfoService;
|
||||
import com.xiang.app.modules.jntyzx.service.IVenueService;
|
||||
import com.xiang.app.modules.jntyzx.utils.VenueInfoUtils;
|
||||
import com.xiang.core.quartz.annotation.XxzJob;
|
||||
import com.xiang.xmc.service.cache.service.IRedisService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.collections4.MapUtils;
|
||||
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;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -30,6 +34,7 @@ public class JtVenueSubscribeTask {
|
||||
private final IJtOrderService jtOrderService;
|
||||
private final IVenueService venueService;
|
||||
private final JtDingTalkFactory jtDingTalkFactory;
|
||||
private final IRedisService redisService;
|
||||
|
||||
@XxzJob(name = "jtVenueSubscribeTask")
|
||||
@GetMapping("/jtVenueSubscribeTask")
|
||||
@@ -43,7 +48,10 @@ public class JtVenueSubscribeTask {
|
||||
return;
|
||||
}
|
||||
List<VenueInfoDO> venueInfoDOS = venueService.queryTomorrowCanBuyVenue();
|
||||
Map<String, List<VenueInfoDO>> venueInfoMap = venueInfoDOS.stream().filter(VenueInfoUtils::get8210VenueInfo).collect(Collectors.groupingByConcurrent(VenueInfoDO::getPlaceName));
|
||||
Map<String, List<VenueInfoDO>> venueInfoMap = venueInfoDOS.stream()
|
||||
.filter(VenueInfoUtils::get8210VenueInfo)
|
||||
.filter(item -> !StringUtils.contains(item.getPlaceName(), "小馆"))
|
||||
.collect(Collectors.groupingByConcurrent(VenueInfoDO::getPlaceName));
|
||||
if (MapUtils.isEmpty(venueInfoMap)) {
|
||||
log.info("暂无可下单场地,time:{}", System.currentTimeMillis());
|
||||
return;
|
||||
@@ -51,9 +59,14 @@ public class JtVenueSubscribeTask {
|
||||
|
||||
users.parallelStream().forEach(user -> {
|
||||
try {
|
||||
for (String placeName : venueInfoMap.keySet()) {
|
||||
List<String> placeNameList = venueInfoMap.keySet().stream().sorted(Comparator.comparing(VenueInfoUtils::sortVenueInfo)).toList();
|
||||
for (String placeName : placeNameList) {
|
||||
List<VenueInfoDO> venueInfoDOList = venueInfoMap.get(placeName);
|
||||
for (int i = 0; i < 10; i++) {
|
||||
String valid = (String) redisService.get(RedisKeyConstant.getVenueSubscribeKey(placeName));
|
||||
if (StringUtils.isNotBlank(valid)) {
|
||||
break;
|
||||
}
|
||||
boolean order = jtOrderService.createOrder(venueInfoDOList, user);
|
||||
if (order) {
|
||||
return;
|
||||
|
||||
@@ -4,7 +4,10 @@ spring:
|
||||
discovery:
|
||||
group: DEFAULT_GROUP
|
||||
namespace: 00131110-3ecb-4a35-8bbb-624edde1d937
|
||||
server-addr: general.xiangtech.xyz:8848
|
||||
server-addr: http://192.168.1.10:8848
|
||||
|
||||
# 是否启用健康检查
|
||||
register-enabled: true
|
||||
username: nacos
|
||||
password: nacos
|
||||
datasource:
|
||||
47
xservice-server/src/main/resources/application-outside.yml
Normal file
47
xservice-server/src/main/resources/application-outside.yml
Normal file
@@ -0,0 +1,47 @@
|
||||
spring:
|
||||
cloud:
|
||||
nacos:
|
||||
discovery:
|
||||
group: DEFAULT_GROUP
|
||||
namespace: 00131110-3ecb-4a35-8bbb-624edde1d937
|
||||
server-addr: http://general.xiangtech.xyz:8848
|
||||
# 是否启用健康检查
|
||||
register-enabled: false
|
||||
username: nacos
|
||||
password: nacos
|
||||
datasource:
|
||||
dynamic:
|
||||
primary: master
|
||||
datasource:
|
||||
master:
|
||||
url: jdbc:mysql://120.27.153.87:3306/xservice_cornucopia?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai&allowMultiQueries=true
|
||||
username: cornucopia
|
||||
password: cornucopia@123
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
sshConnect: false
|
||||
redis:
|
||||
host: r-bp1wt59a6nfyt4e3ltpd.redis.rds.aliyuncs.com
|
||||
port: 6379
|
||||
password: Xiang0000 # 如果无密码可以省略
|
||||
database: 10
|
||||
timeout: 5000
|
||||
lettuce:
|
||||
pool:
|
||||
max-active: 8
|
||||
max-idle: 8
|
||||
min-idle: 0
|
||||
max-wait: 1000
|
||||
xxz-job:
|
||||
app-name: xservice-cornucopia
|
||||
admin-address: http://192.168.1.10:10001
|
||||
namespace: 1
|
||||
|
||||
dingtalk:
|
||||
robot:
|
||||
properties:
|
||||
venue:
|
||||
name: 江南体育中心通知群
|
||||
token: 6a218646972c684c75832b0229ea93a234778af537d7469ce96bef290faf530e
|
||||
secret: SEC9018755ba86d3e5c1ed2fbfa1d6953d84bb2a6c8ebe7ed4e318457bfed5e0465
|
||||
users:
|
||||
- 450841600726084717
|
||||
@@ -4,7 +4,9 @@ spring:
|
||||
discovery:
|
||||
group: DEFAULT_GROUP
|
||||
namespace: 6f603892-e9f7-4ca4-acbc-538fa09ebec0
|
||||
server-addr: general.xiangtech.xyz:8848
|
||||
server-addr: http://192.168.32.3:8848
|
||||
# 是否启用健康检查
|
||||
register-enabled: true
|
||||
username: nacos
|
||||
password: nacos
|
||||
datasource:
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
spring:
|
||||
profiles:
|
||||
active: test
|
||||
active: local
|
||||
application:
|
||||
name: xservice-cornucopia
|
||||
main:
|
||||
|
||||
Reference in New Issue
Block a user