|
|
@@ -20,7 +20,9 @@ import com.webflux.launchadmin.mysql.entity.planNew.*;
|
|
|
import com.webflux.launchadmin.mysql.service.planNew.goGenerate.GoGenerateService;
|
|
|
import com.webflux.launchadmin.mysql.service.planNew.structure.GoRequest;
|
|
|
import com.webflux.launchadmin.mysql.service.planNew.structure.Item;
|
|
|
+import com.webflux.launchadmin.mysql.service.readBookPlan.data.AvatarInfo;
|
|
|
import jakarta.annotation.Resource;
|
|
|
+import lombok.Data;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.data.domain.Sort;
|
|
|
@@ -44,6 +46,8 @@ public class ReadBookPlanServicesImpl implements ReadBookPlanServicesInterface{
|
|
|
private R2dbcEntityTemplate template;
|
|
|
@Value("${go.data.contactWay}")
|
|
|
private String contactWayUrl;
|
|
|
+ @Value("${go.data.getAvatarByWxUid}")
|
|
|
+ private String getAvatarByWxUid;
|
|
|
@Resource
|
|
|
private GoGenerateService goGenerateService;
|
|
|
@Value("${go.data.createImage}")
|
|
|
@@ -66,7 +70,7 @@ public class ReadBookPlanServicesImpl implements ReadBookPlanServicesInterface{
|
|
|
BeanUtil.copyProperties(jsonObject, goRequest);
|
|
|
return readBookGenerateImagePasePoster(goRequest,
|
|
|
goGenerateService.setCusqrcodeSetV(goRequest),//设置自定义二维码
|
|
|
- setQrcodeV(goRequest, request, plan));//设置二维码
|
|
|
+ setQrcodeV(goRequest, request, plan), request);//设置二维码
|
|
|
}).flatMap(s -> {
|
|
|
ReadBookGetPosterImageRes readBookGetPosterImageRes = new ReadBookGetPosterImageRes();
|
|
|
readBookGetPosterImageRes.setPosterImagesUrl(s);
|
|
|
@@ -88,7 +92,7 @@ public class ReadBookPlanServicesImpl implements ReadBookPlanServicesInterface{
|
|
|
.flatMap(f1 -> {
|
|
|
Material material = f1.get(RandomUtil.randomInt(0, f1.size()));
|
|
|
ReadBookGetOneMaterialRes res = new ReadBookGetOneMaterialRes();
|
|
|
- res.setPosterImagesUrl(material.content());
|
|
|
+ res.setContent(material.content());
|
|
|
return Mono.just(res);
|
|
|
});
|
|
|
return readBookGetOneMaterialResMono;
|
|
|
@@ -116,6 +120,51 @@ public class ReadBookPlanServicesImpl implements ReadBookPlanServicesInterface{
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ public AvatarInfo getAvatarByWxUid(String wxExternalUserid) {
|
|
|
+ String body;
|
|
|
+ String url = getAvatarByWxUid + "?wxExternalUserid="+wxExternalUserid;
|
|
|
+ try {
|
|
|
+ body = HttpUtil.get(url, 100000);
|
|
|
+ } catch (Exception e) {
|
|
|
+ String format = StrUtil.format("请求【getAvatarByWxUid】errrr:{} wxExternalUserid:{} Get请求url:{}", e.getMessage(), wxExternalUserid, url);
|
|
|
+ log.error(format);
|
|
|
+ throw new BaseException(format);
|
|
|
+ }
|
|
|
+ if (Objects.isNull(body)||"".equals(body.trim()) ) {
|
|
|
+ String format = StrUtil.format("请求【getAvatarByWxUid】返回结果异常:{} wxExternalUserid:{} Get请求url:{}", body, wxExternalUserid, url);
|
|
|
+ log.error(format);
|
|
|
+ throw new BaseException(format);
|
|
|
+ }
|
|
|
+ JSONObject jsonObject;
|
|
|
+ try {
|
|
|
+ jsonObject = JSONUtil.parseObj(body);
|
|
|
+ }catch (Exception e){
|
|
|
+ String format = StrUtil.format("请求【getAvatarByWxUid】返回结果解析JSONERRR:{} wxExternalUserid:{} Get请求url:{} Body:{}", e.getMessage(), wxExternalUserid, url,body);
|
|
|
+ log.error(format);
|
|
|
+ throw new BaseException(format);
|
|
|
+ }
|
|
|
+ if (jsonObject.containsKey("code")
|
|
|
+ && Objects.nonNull(jsonObject.get("code"))
|
|
|
+ && jsonObject.get("code", Integer.class) == 200
|
|
|
+ && jsonObject.containsKey("data")
|
|
|
+ && Objects.nonNull(jsonObject.get("data"))
|
|
|
+ ) {
|
|
|
+ try {
|
|
|
+ return jsonObject.get("data", AvatarInfo.class);
|
|
|
+ }catch (Exception e){
|
|
|
+ String format = StrUtil.format("请求【getAvatarByWxUid】返回结果解析name,avatar失败:{} wxExternalUserid:{} Get请求url:{} Body:{}",
|
|
|
+ e.getMessage(),
|
|
|
+ wxExternalUserid,
|
|
|
+ url,body);
|
|
|
+ log.error(format);
|
|
|
+ throw new BaseException(format);
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ String format = StrUtil.format("请求【getAvatarByWxUid】返回结果失败 wxExternalUserid:{} Get请求url:{} Body:{}", wxExternalUserid, url,body);
|
|
|
+ log.error(format);
|
|
|
+ throw new BaseException(format);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
public String byCustomerIdGetUrl(Long channelCodeId) {
|
|
|
//?channelCodeId=941873&state=1
|
|
|
@@ -158,7 +207,7 @@ public class ReadBookPlanServicesImpl implements ReadBookPlanServicesInterface{
|
|
|
|
|
|
public Mono<String> readBookGenerateImagePasePoster(GoRequest goRequest,
|
|
|
Mono<List<StringBuilder>> stringBuilderMono,
|
|
|
- Mono<Boolean> booleanMono){
|
|
|
+ Mono<Boolean> booleanMono,ReadBookPlanGetImageReq request){
|
|
|
List<Item> imageGroup = goRequest.getItem().stream().filter(ft -> "image".equals(ft.getT()) && ft.getIsRandom()).collect(Collectors.toList());
|
|
|
ArrayList<Long> imageGroupId = new ArrayList<>();
|
|
|
if ( Objects.nonNull(imageGroup) && !imageGroup.isEmpty()) {
|
|
|
@@ -188,7 +237,7 @@ public class ReadBookPlanServicesImpl implements ReadBookPlanServicesInterface{
|
|
|
getTextListsPlan(textIds),
|
|
|
getImageType1Plan(imageGroupId2),
|
|
|
booleanMono ,
|
|
|
- getTextListsTitleSaveOrUpdatePlan( goRequest));
|
|
|
+ getTextListsTitleSaveOrUpdatePlan( goRequest), request);
|
|
|
}
|
|
|
//背景
|
|
|
private Mono<List<Image>> getBgImage(Long id) {
|
|
|
@@ -227,6 +276,22 @@ public class ReadBookPlanServicesImpl implements ReadBookPlanServicesInterface{
|
|
|
private Material getMaterialNull() {
|
|
|
return new Material(null, null, null, null, null, null, null, null, null, null, null);
|
|
|
}
|
|
|
+
|
|
|
+ public Boolean setNicknameAndHead(String wxExternalUserid,GoRequest goRequest) {
|
|
|
+ List<Item> collect = goRequest.getItem().stream().filter(fc -> "nickname".equals(fc.getT()) || "head".equals(fc.getT())).collect(Collectors.toList());
|
|
|
+ if (!collect.isEmpty()) {
|
|
|
+ AvatarInfo avatarByWxUid = getAvatarByWxUid(wxExternalUserid);
|
|
|
+ collect.forEach(item -> {
|
|
|
+ if(item.getT().equals("nickname")){
|
|
|
+ item.setV(avatarByWxUid.getName());
|
|
|
+ }
|
|
|
+ if(item.getT().equals("head")){
|
|
|
+ item.setV(avatarByWxUid.getAvatar());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
public Mono<String> readBookGenerateImage(GoRequest goRequest,
|
|
|
Mono<List<StringBuilder>> stringBuilderMono,
|
|
|
Mono<List<Image>> bgImage,
|
|
|
@@ -234,10 +299,19 @@ public class ReadBookPlanServicesImpl implements ReadBookPlanServicesInterface{
|
|
|
Mono<List<Material>> text,
|
|
|
Mono<List<Image>> coverFm,
|
|
|
Mono<Boolean> booleanMono ,
|
|
|
- Mono<List<Material>> title) {
|
|
|
- Mono<String> stringMono = Mono.zip(bgImage, images, text, stringBuilderMono,coverFm,booleanMono,title).flatMap(f -> {
|
|
|
+ Mono<List<Material>> title,
|
|
|
+ ReadBookPlanGetImageReq request) {
|
|
|
+ Mono<String> stringMono = Mono.zip(bgImage,
|
|
|
+ images,
|
|
|
+ text,
|
|
|
+ stringBuilderMono,
|
|
|
+ coverFm,
|
|
|
+ booleanMono,
|
|
|
+ title,
|
|
|
+ Mono.just(setNicknameAndHead(request.getWxExternalUserid(),goRequest) )).flatMap(f -> {
|
|
|
List<StringBuilder> t4 = f.getT4();//自定义二维码
|
|
|
Boolean t6 = f.getT6();
|
|
|
+ Boolean t8 = f.getT8();
|
|
|
Optional<Item> first2 = goRequest.getItem().stream().filter(fc -> "cusqrcode".equals(fc.getT()) && (Objects.isNull(fc.getV()) || "".equals(fc.getV()))).findFirst();
|
|
|
if (first2.isPresent()) {
|
|
|
return Mono.error(new BaseException("自定义二维码素材为空"));
|