|
|
@@ -33,11 +33,14 @@ import org.springframework.data.r2dbc.core.R2dbcEntityTemplate;
|
|
|
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.web.bind.annotation.*;
|
|
|
+import org.springframework.web.server.ServerWebExchange;
|
|
|
import reactor.core.publisher.Mono;
|
|
|
|
|
|
import java.io.ByteArrayOutputStream;
|
|
|
import java.io.IOException;
|
|
|
+
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
import java.util.stream.Collectors;
|
|
|
@@ -68,13 +71,7 @@ public class PlanNewCommonOutController {
|
|
|
private PlanServiceInterface planServiceInterface;
|
|
|
private static final ConcurrentHashMap<String, Integer> MAP = new ConcurrentHashMap<>();
|
|
|
|
|
|
- // @Scheduled(cron = "1 1 4 * * ?")
|
|
|
- // @SchedulerLock(name = "launch:PlanNewCommonOutController:clearUserContextHashMap", lockAtLeastFor = "PT5S", lockAtMostFor = "PT15M")
|
|
|
- // public void clearUserContextHashMap() {
|
|
|
- // log.info("清空计划-H5用户Map数据》》》》》》》》》》》》》》》》》》》》》》开始");
|
|
|
- // MAP.clear();
|
|
|
- // log.info("清空计划-H5用户Map数据》》》》》》》》》》》》》》》》》》》》》》 结束");
|
|
|
- // }
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 通过 code 获取计划配置H5信息
|
|
|
@@ -83,7 +80,7 @@ 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 BaseException("计划code异")));
|
|
|
@@ -132,11 +129,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);
|