|
@@ -33,11 +33,14 @@ import org.springframework.data.r2dbc.core.R2dbcEntityTemplate;
|
|
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
import org.springframework.data.relational.core.query.Criteria;
|
|
import org.springframework.data.relational.core.query.Criteria;
|
|
|
import org.springframework.data.relational.core.query.Query;
|
|
import org.springframework.data.relational.core.query.Query;
|
|
|
|
|
+
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
+import org.springframework.web.server.ServerWebExchange;
|
|
|
import reactor.core.publisher.Mono;
|
|
import reactor.core.publisher.Mono;
|
|
|
|
|
|
|
|
import java.io.ByteArrayOutputStream;
|
|
import java.io.ByteArrayOutputStream;
|
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
|
|
|
+
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
@@ -68,13 +71,7 @@ public class PlanNewCommonOutController {
|
|
|
private PlanServiceInterface planServiceInterface;
|
|
private PlanServiceInterface planServiceInterface;
|
|
|
private static final ConcurrentHashMap<String, Integer> MAP = new ConcurrentHashMap<>();
|
|
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信息
|
|
* 通过 code 获取计划配置H5信息
|
|
@@ -83,7 +80,7 @@ public class PlanNewCommonOutController {
|
|
|
* @return {@link Mono}<{@link RStatus}<{@link PlanNewCommon}>>
|
|
* @return {@link Mono}<{@link RStatus}<{@link PlanNewCommon}>>
|
|
|
*/
|
|
*/
|
|
|
@GetMapping("getPlanNewCommonH5")
|
|
@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)
|
|
Mono<PlanNewCommon> planNewCommonMono = template.selectOne(Query.query(Criteria.where("code").is(code)), PlanNewCommon.class)
|
|
|
.switchIfEmpty(Mono.error(new BaseException("计划code异")))
|
|
.switchIfEmpty(Mono.error(new BaseException("计划code异")))
|
|
|
.onErrorResume(throwable -> 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()));
|
|
Image image = imageList.get(RandomUtil.randomInt(0, imageList.size()));
|
|
|
h5ImageAndText.setImage(image.image());
|
|
h5ImageAndText.setImage(image.image());
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
List<Material> materialList = tuple.getT4();
|
|
List<Material> materialList = tuple.getT4();
|
|
|
if (!materialList.isEmpty()) {
|
|
if (!materialList.isEmpty()) {
|
|
|
Material material = materialList.get(RandomUtil.randomInt(0, materialList.size()));
|
|
Material material = materialList.get(RandomUtil.randomInt(0, materialList.size()));
|
|
|
- h5ImageAndText.setName(material.content());
|
|
|
|
|
|
|
+ String content = material.content();
|
|
|
|
|
+ String clientIP=null ;//exchange.getRequest().getHeaders().getFirst("X-Forwarded-For");
|
|
|
|
|
+ if ( Objects.nonNull(exchange.getRequest().getRemoteAddress())) {
|
|
|
|
|
+ clientIP = exchange.getRequest().getRemoteAddress().getAddress().getHostAddress();
|
|
|
|
|
+ }
|
|
|
|
|
+ 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());
|
|
h5ImageAndText.setRemark(material.remark());
|
|
|
}
|
|
}
|
|
|
h5ImageAndTextList.add(h5ImageAndText);
|
|
h5ImageAndTextList.add(h5ImageAndText);
|
|
@@ -173,6 +188,9 @@ public class PlanNewCommonOutController {
|
|
|
*/
|
|
*/
|
|
|
@PostMapping("kefuList")
|
|
@PostMapping("kefuList")
|
|
|
public Mono<RStatus<byte[]>> kefuList(@RequestBody KefuRequest request) {
|
|
public Mono<RStatus<byte[]>> kefuList(@RequestBody KefuRequest request) {
|
|
|
|
|
+ if (null == request.getCode() || request.getCode().isEmpty()) {
|
|
|
|
|
+ return Mono.error(new BaseException("code为空"));
|
|
|
|
|
+ }
|
|
|
Mono<PlanNewCommon> code = template.selectOne(Query.query(Criteria.where("code").is(request.getCode())), PlanNewCommon.class)
|
|
Mono<PlanNewCommon> code = template.selectOne(Query.query(Criteria.where("code").is(request.getCode())), PlanNewCommon.class)
|
|
|
.switchIfEmpty(Mono.error(new BaseException("code查询返回结构为空")))
|
|
.switchIfEmpty(Mono.error(new BaseException("code查询返回结构为空")))
|
|
|
.onErrorResume(throwable -> Mono.error(new BaseException("code查询返回结构为空")));
|
|
.onErrorResume(throwable -> Mono.error(new BaseException("code查询返回结构为空")));
|
|
@@ -262,6 +280,9 @@ public class PlanNewCommonOutController {
|
|
|
*/
|
|
*/
|
|
|
@PostMapping("domainSelect")
|
|
@PostMapping("domainSelect")
|
|
|
public Mono<RStatus<DomainSelectRes>> domainSelect(@RequestBody OutDomainRequest request) {
|
|
public Mono<RStatus<DomainSelectRes>> domainSelect(@RequestBody OutDomainRequest request) {
|
|
|
|
|
+ if (null == request.getCode() || request.getCode().isEmpty()) {
|
|
|
|
|
+ return Mono.error(new BaseException("code为空"));
|
|
|
|
|
+ }
|
|
|
if (1 == request.getTypePlan()) {
|
|
if (1 == request.getTypePlan()) {
|
|
|
// 加群裂变
|
|
// 加群裂变
|
|
|
return this.getPlanNew(request);
|
|
return this.getPlanNew(request);
|
|
@@ -496,6 +517,9 @@ public class PlanNewCommonOutController {
|
|
|
*/
|
|
*/
|
|
|
@PostMapping("getCommonMaterial")
|
|
@PostMapping("getCommonMaterial")
|
|
|
public Mono<RStatus<PlanNewCommonMaterialRes>> getCommonMaterial(@RequestBody PlanNewCommonMaterialReq request) {
|
|
public Mono<RStatus<PlanNewCommonMaterialRes>> getCommonMaterial(@RequestBody PlanNewCommonMaterialReq request) {
|
|
|
|
|
+ if (null == request.getCode() || request.getCode().isEmpty()) {
|
|
|
|
|
+ return Mono.error(new BaseException("code为空"));
|
|
|
|
|
+ }
|
|
|
Mono<PlanNewCommon> planNewCommonMono = template.selectOne(Query.query(Criteria.where("code").is(request.getCode())), PlanNewCommon.class)
|
|
Mono<PlanNewCommon> planNewCommonMono = template.selectOne(Query.query(Criteria.where("code").is(request.getCode())), PlanNewCommon.class)
|
|
|
.switchIfEmpty(Mono.error(new BaseException("计划code异常 返回结果为空")))
|
|
.switchIfEmpty(Mono.error(new BaseException("计划code异常 返回结果为空")))
|
|
|
.onErrorResume(throwable -> Mono.error(new BaseException("计划code异常")));
|
|
.onErrorResume(throwable -> Mono.error(new BaseException("计划code异常")));
|
|
@@ -684,7 +708,12 @@ public class PlanNewCommonOutController {
|
|
|
// Mono<byte[]> res = resMono1.flatMap(f -> Mono.just(Objects.requireNonNull(this.compressData(JSONUtil.toJsonStr(f)))));
|
|
// Mono<byte[]> res = resMono1.flatMap(f -> Mono.just(Objects.requireNonNull(this.compressData(JSONUtil.toJsonStr(f)))));
|
|
|
return RStatus.successList(resMono1);
|
|
return RStatus.successList(resMono1);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+ private QrcodeInfo getQrcodeInfo(GoRequest goRequest) {
|
|
|
|
|
+ Optional<Item> first = goRequest.getItem().stream().filter(ff -> "cover".equals(ff.getT()) ).findFirst();
|
|
|
|
|
+ Optional<Item> first3 = goRequest.getItem().stream().filter(ff -> "title".equals(ff.getT())).findFirst();
|
|
|
|
|
+ QrcodeInfo qrcodeInfo = new QrcodeInfo(null,first.isPresent()?first.get().getV():"",first3.isPresent()?first3.get().getV():"");
|
|
|
|
|
+ return qrcodeInfo;
|
|
|
|
|
+ }
|
|
|
/**
|
|
/**
|
|
|
* 设置二维码 生成图片
|
|
* 设置二维码 生成图片
|
|
|
*/
|
|
*/
|
|
@@ -704,34 +733,60 @@ public class PlanNewCommonOutController {
|
|
|
PlanNewBackgroupPoster fxSetting = fm.getFxSetting();
|
|
PlanNewBackgroupPoster fxSetting = fm.getFxSetting();
|
|
|
goRequest = setNameVal(posterTemplate, fxSetting, fm.getSpare());
|
|
goRequest = setNameVal(posterTemplate, fxSetting, fm.getSpare());
|
|
|
}
|
|
}
|
|
|
- String ret;
|
|
|
|
|
- if (Objects.nonNull(goRequest)) {
|
|
|
|
|
- ret = goGenerateService.goGenerate(JSONUtil.toJsonStr(goRequest));
|
|
|
|
|
- } else {
|
|
|
|
|
-
|
|
|
|
|
- ret = goGenerateService.goGenerate(posterTemplate);
|
|
|
|
|
|
|
+ QrcodeInfo stringBuilder = getQrcodeInfo(goRequest);
|
|
|
|
|
+ Mono<QrcodeInfo> qrcodeInfoMono=Mono.just(new QrcodeInfo(null,null,null));
|
|
|
|
|
+ List<Item> collect = goRequest.getItem()
|
|
|
|
|
+ .stream()
|
|
|
|
|
+ .filter(filter -> "cusqrcode".equals(filter.getT())
|
|
|
|
|
+ && filter.getIsRandom()
|
|
|
|
|
+ && 1 == filter.getType()).collect(Collectors.toList());
|
|
|
|
|
+ if (!collect.isEmpty()) {
|
|
|
|
|
+ qrcodeInfoMono = template.insert(stringBuilder)
|
|
|
|
|
+ .onErrorResume(throwable -> Mono.error(new BaseException("插入QrcodeInfo异常::::" + throwable.getMessage())));
|
|
|
}
|
|
}
|
|
|
- if (Objects.nonNull(ret)) {
|
|
|
|
|
- JSONObject jsonObject1;
|
|
|
|
|
- try {
|
|
|
|
|
- jsonObject1 = JSONUtil.parseObj(ret);
|
|
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- return Mono.error(new BaseException(e.getMessage() + "---" + JSONUtil.parseObj(goRequest) + " error:" + LogExceptionStackTrace.erroStackTrace(e).toString()));
|
|
|
|
|
- }
|
|
|
|
|
- if (jsonObject1.containsKey("code") && jsonObject1.get("code", Integer.class) == 0 && jsonObject1.containsKey("data")) {
|
|
|
|
|
- JSONObject data = jsonObject1.get("data", JSONObject.class);
|
|
|
|
|
- if (data.containsKey("Url")) {
|
|
|
|
|
- String url = data.get("Url", String.class);
|
|
|
|
|
- if (Objects.nonNull(request.getWx_user_id()) && !request.getWx_user_id().isEmpty() && 3 != fm.getPlanNew().type()) {
|
|
|
|
|
- fm.setQsGenerateImagesUrl(url);
|
|
|
|
|
- } else {
|
|
|
|
|
- fm.setFxGenerateImagesUrl(url);
|
|
|
|
|
|
|
+
|
|
|
|
|
+ return Mono.zip(Mono.just(fm),qrcodeInfoMono).flatMap(fm1->{
|
|
|
|
|
+ if (Objects.nonNull(fm1.getT2().id())) {
|
|
|
|
|
+ goRequest.getItem()
|
|
|
|
|
+ .stream()
|
|
|
|
|
+ .filter(filter -> "cusqrcode".equals(filter.getT())
|
|
|
|
|
+ && filter.getIsRandom()
|
|
|
|
|
+ && 1 == filter.getType()).collect(Collectors.toList()).forEach(fe -> {
|
|
|
|
|
+ if (Objects.nonNull(fe.getV())) {
|
|
|
|
|
+ if (fe.getV().contains("?")){
|
|
|
|
|
+ String cusqrcode = fe.getV() + "&id=" + fm1.getT2().id();
|
|
|
|
|
+ fe.setV(cusqrcode);
|
|
|
|
|
+ }else{
|
|
|
|
|
+ String cusqrcode = fe.getV() + "?id=" + fm1.getT2().id();
|
|
|
|
|
+ fe.setV(cusqrcode);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ String ret = goGenerateService.goGenerate(JSONUtil.toJsonStr(goRequest));
|
|
|
|
|
+ if (Objects.nonNull(ret)) {
|
|
|
|
|
+ JSONObject jsonObject1;
|
|
|
|
|
+ try {
|
|
|
|
|
+ jsonObject1 = JSONUtil.parseObj(ret);
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ throw new BaseException(e.getMessage() + "---" + JSONUtil.parseObj(goRequest));
|
|
|
|
|
+ }
|
|
|
|
|
+ if (jsonObject1.containsKey("code") && jsonObject1.get("code", Integer.class) == 0 && jsonObject1.containsKey("data")) {
|
|
|
|
|
+ JSONObject data = jsonObject1.get("data", JSONObject.class);
|
|
|
|
|
+ if (data.containsKey("Url")) {
|
|
|
|
|
+ String url = data.get("Url", String.class);
|
|
|
|
|
+ if (Objects.nonNull(request.getWx_user_id()) && !request.getWx_user_id().isEmpty() && 3 != fm.getPlanNew().type()) {
|
|
|
|
|
+ fm1.getT1().setQsGenerateImagesUrl(url);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ fm1.getT1().setFxGenerateImagesUrl(url);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- }
|
|
|
|
|
- return Mono.just(fm);
|
|
|
|
|
|
|
+ return Mono.just(fm);
|
|
|
|
|
+ });
|
|
|
});
|
|
});
|
|
|
return resMono1;
|
|
return resMono1;
|
|
|
}
|
|
}
|