Showing
5 changed files
with
39 additions
and
5 deletions
| ... | @@ -44,6 +44,11 @@ public @interface RepeatSubmit { | ... | @@ -44,6 +44,11 @@ public @interface RepeatSubmit { |
| 44 | String message() default "不允许重复提交,请稍后再试"; | 44 | String message() default "不允许重复提交,请稍后再试"; |
| 45 | 45 | ||
| 46 | /** | 46 | /** |
| 47 | + * 是否根据登录用户ID加锁 | ||
| 48 | + */ | ||
| 49 | + boolean isLockByLoginUser() default true; | ||
| 50 | + | ||
| 51 | + /** | ||
| 47 | * 方法执行完自动释放锁 | 52 | * 方法执行完自动释放锁 |
| 48 | */ | 53 | */ |
| 49 | boolean methodAutoUnlock() default true; | 54 | boolean methodAutoUnlock() default true; | ... | ... |
| ... | @@ -110,7 +110,11 @@ public class RepeatSubmitAspect { | ... | @@ -110,7 +110,11 @@ public class RepeatSubmitAspect { |
| 110 | } | 110 | } |
| 111 | } | 111 | } |
| 112 | } | 112 | } |
| 113 | + if (requestLock.isLockByLoginUser()) { | ||
| 113 | final var operatorId = LoginContextHolder.hasLogin() ? LoginContextHolder.getId() : null; | 114 | final var operatorId = LoginContextHolder.hasLogin() ? LoginContextHolder.getId() : null; |
| 114 | return requestLock.prefix() + (operatorId != null ? CommonConstants.COLON + operatorId : "") + (sb.length() > 0 ? CommonConstants.UNDERLINE + sb : ""); | 115 | return requestLock.prefix() + (operatorId != null ? CommonConstants.COLON + operatorId : "") + (sb.length() > 0 ? CommonConstants.UNDERLINE + sb : ""); |
| 116 | + } else { | ||
| 117 | + return requestLock.prefix() + (sb.length() > 0 ? CommonConstants.UNDERLINE + sb : ""); | ||
| 118 | + } | ||
| 115 | } | 119 | } |
| 116 | } | 120 | } | ... | ... |
| ... | @@ -9,7 +9,7 @@ import io.lettuce.core.resource.ClientResources; | ... | @@ -9,7 +9,7 @@ import io.lettuce.core.resource.ClientResources; |
| 9 | import io.lettuce.core.tracing.BraveTracing; | 9 | import io.lettuce.core.tracing.BraveTracing; |
| 10 | import org.redisson.Redisson; | 10 | import org.redisson.Redisson; |
| 11 | import org.redisson.api.RedissonClient; | 11 | import org.redisson.api.RedissonClient; |
| 12 | -import org.redisson.client.codec.StringCodec; | 12 | +import org.redisson.codec.JsonJacksonCodec; |
| 13 | import org.redisson.config.Config; | 13 | import org.redisson.config.Config; |
| 14 | import org.springframework.beans.factory.annotation.Autowired; | 14 | import org.springframework.beans.factory.annotation.Autowired; |
| 15 | import org.springframework.beans.factory.annotation.Qualifier; | 15 | import org.springframework.beans.factory.annotation.Qualifier; |
| ... | @@ -68,7 +68,7 @@ public class RedisConfig { | ... | @@ -68,7 +68,7 @@ public class RedisConfig { |
| 68 | @Value(REDIS_PORT) final String port, | 68 | @Value(REDIS_PORT) final String port, |
| 69 | @Value(REDIS_DATABASE) final int dbToken) { | 69 | @Value(REDIS_DATABASE) final int dbToken) { |
| 70 | final var config = new Config(); | 70 | final var config = new Config(); |
| 71 | - config.setCodec(StringCodec.INSTANCE); | 71 | + config.setCodec(new JsonJacksonCodec()); |
| 72 | 72 | ||
| 73 | config.useSingleServer() | 73 | config.useSingleServer() |
| 74 | .setAddress("redis://" + url + ":" + port) | 74 | .setAddress("redis://" + url + ":" + port) | ... | ... |
| ... | @@ -15,8 +15,15 @@ import org.springframework.http.converter.StringHttpMessageConverter; | ... | @@ -15,8 +15,15 @@ import org.springframework.http.converter.StringHttpMessageConverter; |
| 15 | import org.springframework.web.client.DefaultResponseErrorHandler; | 15 | import org.springframework.web.client.DefaultResponseErrorHandler; |
| 16 | import org.springframework.web.client.RestTemplate; | 16 | import org.springframework.web.client.RestTemplate; |
| 17 | 17 | ||
| 18 | +import javax.net.ssl.SSLContext; | ||
| 19 | +import javax.net.ssl.TrustManager; | ||
| 20 | +import javax.net.ssl.X509TrustManager; | ||
| 18 | import java.io.IOException; | 21 | import java.io.IOException; |
| 19 | import java.nio.charset.StandardCharsets; | 22 | import java.nio.charset.StandardCharsets; |
| 23 | +import java.security.KeyManagementException; | ||
| 24 | +import java.security.NoSuchAlgorithmException; | ||
| 25 | +import java.security.SecureRandom; | ||
| 26 | +import java.security.cert.X509Certificate; | ||
| 20 | import java.util.ArrayList; | 27 | import java.util.ArrayList; |
| 21 | import java.util.concurrent.TimeUnit; | 28 | import java.util.concurrent.TimeUnit; |
| 22 | 29 | ||
| ... | @@ -40,8 +47,26 @@ public class RestTemplateConfig { | ... | @@ -40,8 +47,26 @@ public class RestTemplateConfig { |
| 40 | private Integer keepAliveDuration; | 47 | private Integer keepAliveDuration; |
| 41 | 48 | ||
| 42 | @Bean | 49 | @Bean |
| 43 | - public OkHttpClient okHttpClient() { | 50 | + public OkHttpClient okHttpClient() throws NoSuchAlgorithmException, KeyManagementException { |
| 51 | + TrustManager[] trustAllCertificates = new TrustManager[]{ | ||
| 52 | + new X509TrustManager() { | ||
| 53 | + @Override | ||
| 54 | + public void checkClientTrusted(X509Certificate[] chain, String authType) {} | ||
| 55 | + | ||
| 56 | + @Override | ||
| 57 | + public void checkServerTrusted(X509Certificate[] chain, String authType) {} | ||
| 58 | + | ||
| 59 | + @Override | ||
| 60 | + public X509Certificate[] getAcceptedIssuers() { | ||
| 61 | + return new X509Certificate[0]; | ||
| 62 | + } | ||
| 63 | + } | ||
| 64 | + }; | ||
| 65 | + SSLContext sslContext = SSLContext.getInstance("TLS"); | ||
| 66 | + sslContext.init(null, trustAllCertificates, new SecureRandom()); | ||
| 44 | return new OkHttpClient.Builder() | 67 | return new OkHttpClient.Builder() |
| 68 | + .sslSocketFactory(sslContext.getSocketFactory(), (X509TrustManager) trustAllCertificates[0]) | ||
| 69 | + .hostnameVerifier((hostname, session) -> true) | ||
| 45 | .connectTimeout(connectTimeout, TimeUnit.SECONDS) | 70 | .connectTimeout(connectTimeout, TimeUnit.SECONDS) |
| 46 | .readTimeout(readTimeout, TimeUnit.SECONDS) | 71 | .readTimeout(readTimeout, TimeUnit.SECONDS) |
| 47 | .writeTimeout(writeTimeout, TimeUnit.SECONDS) | 72 | .writeTimeout(writeTimeout, TimeUnit.SECONDS) | ... | ... |
| ... | @@ -68,7 +68,7 @@ public class OrderController { | ... | @@ -68,7 +68,7 @@ public class OrderController { |
| 68 | @ApiOperation(value = "创建订单") | 68 | @ApiOperation(value = "创建订单") |
| 69 | @PostMapping("/orders") | 69 | @PostMapping("/orders") |
| 70 | @ResponseStatus(HttpStatus.OK) | 70 | @ResponseStatus(HttpStatus.OK) |
| 71 | - @RepeatSubmit(prefix = "createOrder") | 71 | + @RepeatSubmit(prefix = "createOrder", isLockByLoginUser = false) |
| 72 | public CreateOrderResponse createOrder(@Valid @RequestBody CreateOrderDto createOrderDto) { | 72 | public CreateOrderResponse createOrder(@Valid @RequestBody CreateOrderDto createOrderDto) { |
| 73 | return orderService.createOrder(createOrderDto); | 73 | return orderService.createOrder(createOrderDto); |
| 74 | } | 74 | } |
| ... | @@ -76,7 +76,7 @@ public class OrderController { | ... | @@ -76,7 +76,7 @@ public class OrderController { |
| 76 | @ApiOperation(value = "院区端创建订单") | 76 | @ApiOperation(value = "院区端创建订单") |
| 77 | @PostMapping("/operator/orders") | 77 | @PostMapping("/operator/orders") |
| 78 | @ResponseStatus(HttpStatus.OK) | 78 | @ResponseStatus(HttpStatus.OK) |
| 79 | - @RepeatSubmit(prefix = "createOrder") | 79 | + @RepeatSubmit(prefix = "createOrder", isLockByLoginUser = false) |
| 80 | public CreateOrderResponse createOrderByOperator(@Valid @RequestBody OrderDbDTO.OperatorCreateOrderDto createOrderDto) { | 80 | public CreateOrderResponse createOrderByOperator(@Valid @RequestBody OrderDbDTO.OperatorCreateOrderDto createOrderDto) { |
| 81 | return orderService.orderCreation(createOrderDto); | 81 | return orderService.orderCreation(createOrderDto); |
| 82 | } | 82 | } | ... | ... |
-
Please register or login to post a comment