提交 99444a2c 作者: 沈振路

关键词回复,番茄小程序适配取链接

上级 af2131b7
......@@ -2,6 +2,7 @@ package com.yaoyaozw.customer.components;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
......@@ -9,10 +10,10 @@ import com.yaoyaozw.customer.common.R;
import com.yaoyaozw.customer.constants.ApiResultConstant;
import com.yaoyaozw.customer.constants.CustomerCommonConstant;
import com.yaoyaozw.customer.constants.CustomerMaterialConstant;
import com.yaoyaozw.customer.entity.CommonReferralBody;
import com.yaoyaozw.customer.entity.CustomerKeyword;
import com.yaoyaozw.customer.entity.ReferralEntity;
import com.yaoyaozw.customer.entity.*;
import com.yaoyaozw.customer.exception.BaseException;
import com.yaoyaozw.customer.feigns.ReferralFeignClient;
import com.yaoyaozw.customer.service.AuthorizerExpandInfoService;
import com.yaoyaozw.customer.service.AuthorizerInfoService;
import com.yaoyaozw.customer.service.CompanyAcquisitionLinkService;
import com.yaoyaozw.customer.service.ReferralEntityService;
......@@ -32,6 +33,9 @@ import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import static com.yaoyaozw.customer.constants.CustomerCommonConstant.*;
import static com.yaoyaozw.customer.constants.CustomerCommonConstant.LANDING_PAGE_VAL;
/**
* @author darker
* @date 2023/3/14 14:36
......@@ -51,6 +55,10 @@ public class CustomerKeywordComponent {
private SnowflakeComponent snowflakeComponent;
@Resource
private CompanyAcquisitionLinkService companyAcquisitionLinkService;
@Resource
private AuthorizerExpandInfoService authorizerExpandInfoService;
@Resource
private AuthorizerInfoService authorizerInfoService;
/**
* 获取链接实体
......@@ -166,7 +174,15 @@ public class CustomerKeywordComponent {
}
entity.setTxMediaUrl(uploadResult.getUrl());
entity.setTxMediaId(uploadResult.getMedia_id());
// 需要上传后台的类型不需要处理链接
// 判断需不需要处理小程序
try {
handleMp(dateStr, targetAuth, entity, sourceMaterial);
finalMaterialList.add(entity);
} catch (Exception e) {
status = 0;
result.setHasError(true);
}
entity.setStatus(status);
finalMaterialList.add(entity);
continue;
......@@ -219,6 +235,92 @@ public class CustomerKeywordComponent {
}
private void handleMp(String dateStr, AuthInfoVO targetAuth, CustomerKeyword neoEntity, CustomerKeyword sourceMaterial) {
if (!CUSTOMER_TYPE_VALUE_MINI_PROGRAM.equals(neoEntity.getType())) {
return;
}
List<ReferralEntity> referralEntityList = sourceMaterial.getReferralEntityList();
if (CollectionUtil.isEmpty(referralEntityList)) {
// 不具备处理条件
return;
}
ReferralEntity sourceReferral = referralEntityList.get(0);
// 如果参数传入的标题只是在图文上,则延用过来
if (StringUtils.isBlank(neoEntity.getMpTitle()) && StringUtils.isNotBlank(neoEntity.getExtendTitle())) {
neoEntity.setMpTitle(neoEntity.getExtendTitle());
}
if (StringUtils.isBlank(neoEntity.getMpTitle())) {
throw new BaseException("无法匹配小程序发文的标题内容");
}
// 番茄
// 重新处理 小程序appId、小程序path
String storeType;
if (StringUtils.isNotBlank(targetAuth.getStoreType())) {
storeType = targetAuth.getStoreType();
} else {
AuthorizerInfo authorizerInfo = authorizerInfoService.lambdaQuery().eq(AuthorizerInfo::getAppid, targetAuth.getAppId()).last("limit 1").one();
if (authorizerInfo == null) {
throw new BaseException("无法获取公众号信息");
}
storeType = authorizerInfo.getStoreType();
}
if (!CustomerCommonConstant.STORE_NAME_TOMATO.equals(storeType)) {
return;
}
AuthorizerExpandInfo authorizerExpandInfo = authorizerExpandInfoService.lambdaQuery().eq(AuthorizerExpandInfo::getAuthorizerAppid, neoEntity.getAppid()).last("limit 1").one();
if (authorizerExpandInfo == null) {
throw new BaseException("无法获取公众号" + neoEntity.getAppid() + "的绑定配置信息");
}
// 填入小程序appId
neoEntity.setMpAppId(authorizerExpandInfo.getMpAppid());
// 重新获取链接
ReferralEntity targetReferral = new ReferralEntity();
try {
BeanUtil.copyProperties(sourceReferral, targetReferral, "id", "accountId", "name", "referral", "materialGraphicsId", "infoId");
// 为参数设置公众号相关参数
targetReferral.setAccountId(authorizerExpandInfo.getMpDistributorId());
targetReferral.setInfoId(targetAuth.getId());
Integer newsType = targetReferral.getNewsType();
if (CustomerCommonConstant.USUAL_LINK_NEWS_TYPE.equals(newsType)) {
// 常用链接延用name
targetReferral.setName(sourceReferral.getName());
} else {
// 书籍、活动 类型, 重新构造name
handleReferralName(dateStr, targetAuth.getAccountName(), targetReferral);
}
doGetReferral(targetReferral);
} catch (Exception e) {
throw new RuntimeException("获取链接异常: " + e.getMessage());
}
targetReferral.setMaterialGraphicsId(neoEntity.getId());
String referral = targetReferral.getReferral();
// 番茄处理小程序常用链接
if (!referral.contains(GET_BOOK_ITEM)) {
referral = referral + "&" + GET_BOOK_ITEM_VAL;
}
if (!referral.contains(FROM_APPID)) {
referral = referral + "&" + FROM_APPID + "=" + authorizerExpandInfo.getFlagId();
}
if (CustomerCommonConstant.USUAL_LINK_NEWS_TYPE.equals(targetReferral.getNewsType())) {
if (referral.contains("scene=0")) {
referral = referral.replace("scene=0", "scene=1");
}
} else {
if (!referral.contains(LANDING_PAGE)) {
referral = referral + "&" + LANDING_PAGE_VAL;
}
}
targetReferral.setReferral(referral);
neoEntity.setMpPath(referral);
neoEntity.setContent("");
// 保存链接数据
if (ObjectUtil.isNull(targetReferral.getId())) {
referralEntityService.save(targetReferral);
} else {
referralEntityService.updateById(targetReferral);
}
}
/**
* 重新排序和保存文本子素材
......
......@@ -11,14 +11,16 @@ import com.yaoyaozw.customer.common.BaseResult;
import com.yaoyaozw.customer.common.GenericsResult;
import com.yaoyaozw.customer.components.CustomerKeywordComponent;
import com.yaoyaozw.customer.components.SnowflakeComponent;
import com.yaoyaozw.customer.constants.CustomerCommonConstant;
import com.yaoyaozw.customer.constants.CustomerMaterialConstant;
import com.yaoyaozw.customer.dto.follow.FollowReplySaveDTO;
import com.yaoyaozw.customer.dto.keyword.CustomerKeywordCopyDTO;
import com.yaoyaozw.customer.dto.keyword.CustomerKeywordQueryDTO;
import com.yaoyaozw.customer.dto.keyword.CustomerKeywordSaveDTO;
import com.yaoyaozw.customer.entity.CommonReferralBody;
import com.yaoyaozw.customer.entity.CustomerKeyword;
import com.yaoyaozw.customer.entity.ReferralEntity;
import com.yaoyaozw.customer.entity.*;
import com.yaoyaozw.customer.exception.BaseException;
import com.yaoyaozw.customer.mapper.CustomerKeywordMapper;
import com.yaoyaozw.customer.service.AuthorizerExpandInfoService;
import com.yaoyaozw.customer.service.AuthorizerInfoService;
import com.yaoyaozw.customer.service.CustomerKeywordService;
import com.yaoyaozw.customer.service.ReferralEntityService;
......@@ -35,12 +37,16 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import static com.yaoyaozw.customer.constants.CustomerCommonConstant.*;
import static com.yaoyaozw.customer.constants.CustomerCommonConstant.LANDING_PAGE_VAL;
/**
* @author darker
* @date 2023/3/20 11:09
......@@ -63,6 +69,10 @@ public class CustomerKeywordServiceImpl extends ServiceImpl<CustomerKeywordMappe
@Autowired
private RedisTemplate<String, Object> redisTemplate;
@Resource
private AuthorizerExpandInfoService authorizerExpandInfoService;
@Resource
private CustomerKeywordComponent customerKeywordComponent;
@Override
......@@ -124,6 +134,7 @@ public class CustomerKeywordServiceImpl extends ServiceImpl<CustomerKeywordMappe
}
entity.setTxMediaUrl(uploadResponse.getUrl());
entity.setTxMediaId(uploadResponse.getMedia_id());
handleMp(saveDto, entity);
} else if (!CustomerMaterialConstant.TENCENT_MEDIA_TYPE_TEXT.equals(entity.getType())){
// 获取书城公众号链接(图文)
ReferralEntity referralEntity;
......@@ -152,6 +163,76 @@ public class CustomerKeywordServiceImpl extends ServiceImpl<CustomerKeywordMappe
return new GenericsResult<>(String.valueOf(entity.getId()));
}
private void handleMp(CustomerKeywordSaveDTO saveDto, CustomerKeyword entity) {
if (!CUSTOMER_TYPE_VALUE_MINI_PROGRAM.equals(entity.getType())) {
return;
}
CommonReferralBody originReferralBody = saveDto.getReferralBody();
if (originReferralBody == null) {
// 不具备处理条件
return;
}
// 如果参数传入的标题只是在图文上,则延用过来
if (StringUtils.isBlank(entity.getMpTitle()) && StringUtils.isNotBlank(entity.getExtendTitle())) {
entity.setMpTitle(entity.getExtendTitle());
}
if (StringUtils.isBlank(entity.getMpTitle())) {
throw new BaseException("无法匹配小程序发文的标题内容");
}
// 番茄
// 重新处理 小程序appId、小程序path
AuthorizerInfo authorizerInfo = authorizerInfoService.lambdaQuery().eq(AuthorizerInfo::getAppid, entity.getAppid()).last("limit 1").one();
if (authorizerInfo == null) {
throw new BaseException("无法获取公众号信息");
}
String storeType = authorizerInfo.getStoreType();
if (!CustomerCommonConstant.STORE_NAME_TOMATO.equals(storeType)) {
return;
}
AuthorizerExpandInfo authorizerExpandInfo = authorizerExpandInfoService.lambdaQuery().eq(AuthorizerExpandInfo::getAuthorizerAppid, entity.getAppid()).last("limit 1").one();
if (authorizerExpandInfo == null) {
throw new BaseException("无法获取公众号" + entity.getAppid() + "的绑定配置信息");
}
// 填入小程序appId
entity.setMpAppId(authorizerExpandInfo.getMpAppid());
// 重新获取链接
ReferralEntity referralEntity;
try {
originReferralBody.setAccountId(authorizerExpandInfo.getMpDistributorId());
referralEntity = customerKeywordComponent.getCreateReferralEntity(originReferralBody);
} catch (Exception e) {
throw new RuntimeException("获取链接异常: " + e.getMessage());
}
referralEntity.setMaterialGraphicsId(entity.getId());
String referral = referralEntity.getReferral();
// 番茄处理小程序常用链接
if (!referral.contains(GET_BOOK_ITEM)) {
referral = referral + "&" + GET_BOOK_ITEM_VAL;
}
if (!referral.contains(FROM_APPID)) {
referral = referral + "&" + FROM_APPID + "=" + authorizerExpandInfo.getFlagId();
}
if (CustomerCommonConstant.USUAL_LINK_NEWS_TYPE.equals(referralEntity.getNewsType())) {
if (referral.contains("scene=0")) {
referral = referral.replace("scene=0", "scene=1");
}
} else {
if (!referral.contains(LANDING_PAGE)) {
referral = referral + "&" + LANDING_PAGE_VAL;
}
}
entity.setMpPath(referral);
entity.setContent("");
referralEntity.setReferral(referral);
// 保存链接数据
if (ObjectUtil.isNull(referralEntity.getId())) {
referralEntityService.save(referralEntity);
} else {
referralEntityService.updateById(referralEntity);
}
}
@Override
public GenericsResult<List<CommonReferralBody>> createTextItem(CommonReferralBody referralBody) {
CustomerKeyword entity = this.getById(referralBody.getMaterialGraphicsId());
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论