Commit d4aff474 authored by liming's avatar liming

异步通知游戏go服务器日常赛变更

parent aa2c56f2
package com.antai.sport.http.server.common.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.web.client.RestTemplate;
import java.nio.charset.StandardCharsets;
@Configuration
public class RestTemplateConfiguration {
@Bean
public RestTemplate restTemplate() {
SimpleClientHttpRequestFactory requestFactory =
new SimpleClientHttpRequestFactory();
// 设置连接超时,单位毫秒
requestFactory.setConnectTimeout(3000);
//设置读取超时
requestFactory.setReadTimeout(10000);
RestTemplate restTemplate = new RestTemplate();
restTemplate.setRequestFactory(requestFactory);
restTemplate.getMessageConverters().add(
new StringHttpMessageConverter(StandardCharsets.UTF_8)
);
return restTemplate;
}
}
\ No newline at end of file
...@@ -4,6 +4,7 @@ import org.mybatis.spring.annotation.MapperScan; ...@@ -4,6 +4,7 @@ import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.ComponentScan;
import org.springframework.scheduling.annotation.EnableAsync;
import springfox.documentation.oas.annotations.EnableOpenApi; import springfox.documentation.oas.annotations.EnableOpenApi;
/** /**
...@@ -15,6 +16,7 @@ import springfox.documentation.oas.annotations.EnableOpenApi; ...@@ -15,6 +16,7 @@ import springfox.documentation.oas.annotations.EnableOpenApi;
@SpringBootApplication @SpringBootApplication
@EnableOpenApi @EnableOpenApi
@EnableAsync
@ComponentScan(value = "com.antai") @ComponentScan(value = "com.antai")
@MapperScan("com.antai.**.mapper") @MapperScan("com.antai.**.mapper")
public class ManagementApiApplication { public class ManagementApiApplication {
......
package com.antai.sport.http.server.management.api.business.simplematch.service;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
import javax.annotation.Resource;
@Service
@Slf4j
public class SimpleMatchChangeNotifyService {
@Value("${simple-match-change-notify-url}")
private String simpleMatchChangeNotifyUrl;
@Resource
private RestTemplate restTemplate;
@Async("asyncTaskExecutor")
public void notifyGameServerSimpleMatchChange() {
log.info("异步通知比赛列表变更");
String result = "执行失败";
try {
result = restTemplate.getForObject(simpleMatchChangeNotifyUrl, String.class);
} catch (Exception ex) {
log.error(ex.getMessage());
}
log.info("比赛变更结果:" + result);
}
}
...@@ -39,6 +39,8 @@ public class SimpleMatchService { ...@@ -39,6 +39,8 @@ public class SimpleMatchService {
private MapPathMapper mapPathMapper; private MapPathMapper mapPathMapper;
@Resource @Resource
private SimpleMatchConverter simpleMatchConverter; private SimpleMatchConverter simpleMatchConverter;
@Resource
private SimpleMatchChangeNotifyService simpleMatchChangeNotifyService;
public SimpleMatchListResponseDTO getMatchList(SimpleMatchListRequestDTO param) { public SimpleMatchListResponseDTO getMatchList(SimpleMatchListRequestDTO param) {
Page<SimpleMatchListVO> pageParam = new Page<>(param.getPageNo(), param.getPageSize()); Page<SimpleMatchListVO> pageParam = new Page<>(param.getPageNo(), param.getPageSize());
...@@ -72,6 +74,7 @@ public class SimpleMatchService { ...@@ -72,6 +74,7 @@ public class SimpleMatchService {
simpleMatch.setStatus(10); simpleMatch.setStatus(10);
} }
simpleMatchMapper.updateById(simpleMatch); simpleMatchMapper.updateById(simpleMatch);
simpleMatchChangeNotifyService.notifyGameServerSimpleMatchChange();
} }
public SimpleMatchResponseDTO getSimpleMatch(Long matchId) { public SimpleMatchResponseDTO getSimpleMatch(Long matchId) {
...@@ -122,6 +125,7 @@ public class SimpleMatchService { ...@@ -122,6 +125,7 @@ public class SimpleMatchService {
simpleMatch.setStatus(10); simpleMatch.setStatus(10);
simpleMatchMapper.insert(simpleMatch); simpleMatchMapper.insert(simpleMatch);
} }
simpleMatchChangeNotifyService.notifyGameServerSimpleMatchChange();
} }
} }
...@@ -10,6 +10,8 @@ import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerIntercept ...@@ -10,6 +10,8 @@ import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerIntercept
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.core.task.AsyncTaskExecutor;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.transaction.annotation.EnableTransactionManagement; import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.web.method.support.HandlerMethodArgumentResolver; import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.CorsRegistry; import org.springframework.web.servlet.config.annotation.CorsRegistry;
...@@ -68,9 +70,9 @@ public class BaseConfig implements WebMvcConfigurer { ...@@ -68,9 +70,9 @@ public class BaseConfig implements WebMvcConfigurer {
} }
@Bean @Bean
public MybatisPlusInterceptor mybatisPlusInterceptor(){ public MybatisPlusInterceptor mybatisPlusInterceptor() {
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
PaginationInnerInterceptor innerInterceptor=new PaginationInnerInterceptor(); PaginationInnerInterceptor innerInterceptor = new PaginationInnerInterceptor();
innerInterceptor.setDbType(DbType.MYSQL); innerInterceptor.setDbType(DbType.MYSQL);
innerInterceptor.setOverflow(true); innerInterceptor.setOverflow(true);
interceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor()); interceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor());
...@@ -79,7 +81,17 @@ public class BaseConfig implements WebMvcConfigurer { ...@@ -79,7 +81,17 @@ public class BaseConfig implements WebMvcConfigurer {
} }
@Bean @Bean
public ConfigurationCustomizer configurationCustomizer(){ public ConfigurationCustomizer configurationCustomizer() {
return mybatisConfiguration -> mybatisConfiguration.setUseGeneratedShortKey(false); return mybatisConfiguration -> mybatisConfiguration.setUseGeneratedShortKey(false);
} }
@Bean("asyncTaskExecutor")
public AsyncTaskExecutor asyncTaskExecutor() {
ThreadPoolTaskExecutor asyncTaskExecutor = new ThreadPoolTaskExecutor();
asyncTaskExecutor.setMaxPoolSize(50);
asyncTaskExecutor.setCorePoolSize(20);
asyncTaskExecutor.setThreadNamePrefix("异步线程-");
asyncTaskExecutor.initialize();
return asyncTaskExecutor;
}
} }
...@@ -19,4 +19,6 @@ aliyun: ...@@ -19,4 +19,6 @@ aliyun:
enabled: true enabled: true
endpoint: https://oss-cn-beijing.aliyuncs.com endpoint: https://oss-cn-beijing.aliyuncs.com
bucket-name: antai-sport bucket-name: antai-sport
cdn-url: http://antai-sport.oss-cn-beijing.aliyuncs.com/ cdn-url: http://antai-sport.oss-cn-beijing.aliyuncs.com/
\ No newline at end of file
simple-match-change-notify-url: http://47.100.168.51:3281/api/match/update
\ No newline at end of file
...@@ -18,4 +18,6 @@ aliyun: ...@@ -18,4 +18,6 @@ aliyun:
enabled: true enabled: true
endpoint: https://oss-cn-beijing.aliyuncs.com endpoint: https://oss-cn-beijing.aliyuncs.com
bucket-name: antai-sport bucket-name: antai-sport
cdn-url: http://antai-sport.oss-cn-beijing.aliyuncs.com/ cdn-url: http://antai-sport.oss-cn-beijing.aliyuncs.com/
\ No newline at end of file
simple-match-change-notify-url: http://47.100.168.51:3281/api/match/update
\ No newline at end of file
...@@ -19,4 +19,6 @@ aliyun: ...@@ -19,4 +19,6 @@ aliyun:
enabled: true enabled: true
endpoint: https://oss-cn-shanghai.aliyuncs.com endpoint: https://oss-cn-shanghai.aliyuncs.com
bucket-name: shanghaijingji-sport-prod bucket-name: shanghaijingji-sport-prod
cdn-url: https://shanghaijingji-sport-prod.oss-cn-shanghai.aliyuncs.com/ cdn-url: https://shanghaijingji-sport-prod.oss-cn-shanghai.aliyuncs.com/
\ No newline at end of file
simple-match-change-notify-url: http://127.0.0.1:3281/api/match/update
\ No newline at end of file
...@@ -19,4 +19,6 @@ aliyun: ...@@ -19,4 +19,6 @@ aliyun:
enabled: true enabled: true
endpoint: https://oss-cn-beijing.aliyuncs.com endpoint: https://oss-cn-beijing.aliyuncs.com
bucket-name: antai-sport bucket-name: antai-sport
cdn-url: http://antai-sport.oss-cn-beijing.aliyuncs.com/ cdn-url: http://antai-sport.oss-cn-beijing.aliyuncs.com/
\ No newline at end of file
simple-match-change-notify-url: http://47.100.168.51:3281/api/match/update
\ No newline at end of file
...@@ -2,10 +2,10 @@ package com.antai.sport.http.server.mobile.api.business.match.bicycle.service; ...@@ -2,10 +2,10 @@ package com.antai.sport.http.server.mobile.api.business.match.bicycle.service;
import com.antai.sport.http.server.common.exception.BusinessException; import com.antai.sport.http.server.common.exception.BusinessException;
import com.antai.sport.http.server.constants.DeleteStatus; import com.antai.sport.http.server.constants.DeleteStatus;
import com.antai.sport.http.server.mobile.api.business.match.bicycle.mapper.MatchBicycleBusinessMapper;
import com.antai.sport.http.server.mobile.api.business.match.bicycle.dto.DtoMatchAutoCreate; import com.antai.sport.http.server.mobile.api.business.match.bicycle.dto.DtoMatchAutoCreate;
import com.antai.sport.http.server.mobile.api.business.match.bicycle.dto.ReqMatchBicycleSave; import com.antai.sport.http.server.mobile.api.business.match.bicycle.dto.ReqMatchBicycleSave;
import com.antai.sport.http.server.mobile.api.business.match.bicycle.dto.RespMatchBicycleList; import com.antai.sport.http.server.mobile.api.business.match.bicycle.dto.RespMatchBicycleList;
import com.antai.sport.http.server.mobile.api.business.match.bicycle.mapper.MatchBicycleBusinessMapper;
import com.antai.sport.http.server.repository.match.entity.MatchBicycle; import com.antai.sport.http.server.repository.match.entity.MatchBicycle;
import com.antai.sport.http.server.repository.match.mapper.MatchBicycleMapper; import com.antai.sport.http.server.repository.match.mapper.MatchBicycleMapper;
import com.antai.sport.http.server.repository.sport.entity.SportUser; import com.antai.sport.http.server.repository.sport.entity.SportUser;
...@@ -102,7 +102,7 @@ public class MatchBicycleService extends ServiceImpl<MatchBicycleMapper, MatchBi ...@@ -102,7 +102,7 @@ public class MatchBicycleService extends ServiceImpl<MatchBicycleMapper, MatchBi
} }
//调用游戏服务端的暂停接口 //调用游戏服务端的暂停接口
RestTemplate restTemplate = new RestTemplate(); RestTemplate restTemplate = new RestTemplate();
restTemplate.getForObject(gameServerAddress,String.class); restTemplate.getForObject(gameServerAddress, String.class);
//创建一场新的比赛 创建比赛规则:进入时间=当前时间+1分钟 开始时间=进入时间+1分钟 结束时间=开始时间+20分钟 //创建一场新的比赛 创建比赛规则:进入时间=当前时间+1分钟 开始时间=进入时间+1分钟 结束时间=开始时间+20分钟
MatchBicycle match = new MatchBicycle(); MatchBicycle match = new MatchBicycle();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment