|
|
@@ -31,12 +31,15 @@ import org.springframework.data.redis.core.ReactiveRedisTemplate;
|
|
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
import org.springframework.data.relational.core.query.Criteria;
|
|
|
import org.springframework.data.relational.core.query.Query;
|
|
|
+import org.springframework.http.server.reactive.ServerHttpRequest;
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
+import org.springframework.web.server.ServerWebExchange;
|
|
|
import reactor.core.publisher.Mono;
|
|
|
|
|
|
import java.io.ByteArrayOutputStream;
|
|
|
import java.io.IOException;
|
|
|
+import java.net.InetSocketAddress;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
import java.util.stream.Collectors;
|
|
|
@@ -79,7 +82,9 @@ public class PlanNewCommonOutController {
|
|
|
* @return {@link Mono}<{@link RStatus}<{@link PlanNewCommon}>>
|
|
|
*/
|
|
|
@GetMapping("getPlanNewCommonH5")
|
|
|
- public Mono<RStatus<byte[]>> getPlanNewCommonH5(@RequestParam("code") String code) {
|
|
|
+ public Mono<RStatus<byte[]>> getPlanNewCommonH5(@RequestParam("code") String code, ServerWebExchange exchange) {
|
|
|
+
|
|
|
+
|
|
|
Mono<PlanNewCommon> planNewCommonMono = template.selectOne(Query.query(Criteria.where("code").is(code)), PlanNewCommon.class)
|
|
|
.switchIfEmpty(Mono.error(new BaseException("计划code异常")))
|
|
|
.onErrorResume(throwable -> Mono.error(new Exception(throwable.getMessage() + "1")));
|
|
|
@@ -128,11 +133,29 @@ public class PlanNewCommonOutController {
|
|
|
Image image = imageList.get(RandomUtil.randomInt(0, imageList.size()));
|
|
|
h5ImageAndText.setImage(image.image());
|
|
|
}
|
|
|
-
|
|
|
List<Material> materialList = tuple.getT4();
|
|
|
if (!materialList.isEmpty()) {
|
|
|
Material material = materialList.get(RandomUtil.randomInt(0, materialList.size()));
|
|
|
- h5ImageAndText.setName(material.content());
|
|
|
+ String clientIP = exchange.getRequest().getHeaders().getFirst("X-Forwarded-For");
|
|
|
+ if ((clientIP == null || clientIP.isEmpty()) && Objects.nonNull(exchange.getRequest().getRemoteAddress())) {
|
|
|
+ clientIP = exchange.getRequest().getRemoteAddress().getAddress().getHostAddress();
|
|
|
+ }
|
|
|
+ String content = material.content();
|
|
|
+ if (StrUtil.isNotBlank(clientIP)) {
|
|
|
+ JSONObject ipInfo = ipAnalyzeServiceInterface.getIpInfo(clientIP);
|
|
|
+ if (null != ipInfo) {
|
|
|
+ String city = ipInfo.getStr("city");
|
|
|
+ if (StrUtil.isNotBlank(city)) {
|
|
|
+ content = city + content;
|
|
|
+ } else {
|
|
|
+ String province = ipInfo.getStr("region");
|
|
|
+ if (StrUtil.isNotBlank(province)) {
|
|
|
+ content = province + content;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ h5ImageAndText.setName(content);
|
|
|
h5ImageAndText.setRemark(material.remark());
|
|
|
}
|
|
|
h5ImageAndTextList.add(h5ImageAndText);
|