提交 af2131b7 作者: 沈振路

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

上级 e6f4a987
...@@ -2,6 +2,7 @@ package com.yaoyaozw.customer.components; ...@@ -2,6 +2,7 @@ package com.yaoyaozw.customer.components;
import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONUtil; import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
...@@ -10,12 +11,12 @@ import com.yaoyaozw.customer.common.R; ...@@ -10,12 +11,12 @@ import com.yaoyaozw.customer.common.R;
import com.yaoyaozw.customer.constants.ApiResultConstant; import com.yaoyaozw.customer.constants.ApiResultConstant;
import com.yaoyaozw.customer.constants.CustomerCommonConstant; import com.yaoyaozw.customer.constants.CustomerCommonConstant;
import com.yaoyaozw.customer.constants.CustomerMaterialConstant; import com.yaoyaozw.customer.constants.CustomerMaterialConstant;
import com.yaoyaozw.customer.dto.follow.FollowReplySaveDTO;
import com.yaoyaozw.customer.dto.follow.NewsMessageReplyEntity; import com.yaoyaozw.customer.dto.follow.NewsMessageReplyEntity;
import com.yaoyaozw.customer.entity.CommonReferralBody; import com.yaoyaozw.customer.entity.*;
import com.yaoyaozw.customer.entity.CustomerFollowReply; import com.yaoyaozw.customer.exception.BaseException;
import com.yaoyaozw.customer.entity.CustomerFollowReplyMultiNews;
import com.yaoyaozw.customer.entity.ReferralEntity;
import com.yaoyaozw.customer.feigns.ReferralFeignClient; import com.yaoyaozw.customer.feigns.ReferralFeignClient;
import com.yaoyaozw.customer.service.AuthorizerExpandInfoService;
import com.yaoyaozw.customer.service.AuthorizerInfoService; import com.yaoyaozw.customer.service.AuthorizerInfoService;
import com.yaoyaozw.customer.service.CompanyAcquisitionLinkService; import com.yaoyaozw.customer.service.CompanyAcquisitionLinkService;
import com.yaoyaozw.customer.service.ReferralEntityService; import com.yaoyaozw.customer.service.ReferralEntityService;
...@@ -36,6 +37,9 @@ import java.util.ArrayList; ...@@ -36,6 +37,9 @@ import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import static com.yaoyaozw.customer.constants.CustomerCommonConstant.*;
import static com.yaoyaozw.customer.constants.CustomerCommonConstant.FROM_APPID;
/** /**
* @author darker * @author darker
* @date 2023/3/14 14:36 * @date 2023/3/14 14:36
...@@ -57,6 +61,10 @@ public class FollowReplyComponent { ...@@ -57,6 +61,10 @@ public class FollowReplyComponent {
private RedisTemplate<String, Object> redisTemplate; private RedisTemplate<String, Object> redisTemplate;
@Resource @Resource
private CompanyAcquisitionLinkService companyAcquisitionLinkService; private CompanyAcquisitionLinkService companyAcquisitionLinkService;
@Resource
private AuthorizerExpandInfoService authorizerExpandInfoService;
@Resource
private AuthorizerInfoService authorizerInfoService;
/** /**
* 获取链接实体 * 获取链接实体
...@@ -174,7 +182,15 @@ public class FollowReplyComponent { ...@@ -174,7 +182,15 @@ public class FollowReplyComponent {
} }
entity.setTxMediaUrl(uploadResult.getUrl()); entity.setTxMediaUrl(uploadResult.getUrl());
entity.setTxMediaId(uploadResult.getMedia_id()); 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); entity.setStatus(status);
finalMaterialList.add(entity); finalMaterialList.add(entity);
continue; continue;
...@@ -252,6 +268,92 @@ public class FollowReplyComponent { ...@@ -252,6 +268,92 @@ public class FollowReplyComponent {
} }
private void handleMp(String dateStr, AuthInfoVO targetAuth, CustomerFollowReply neoEntity, CustomerFollowReply 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);
}
}
/** /**
* 重新排序和保存文本子素材 * 重新排序和保存文本子素材
......
...@@ -14,6 +14,13 @@ import java.util.List; ...@@ -14,6 +14,13 @@ import java.util.List;
*/ */
public class CustomerCommonConstant { public class CustomerCommonConstant {
public final static String GET_BOOK_ITEM = "get_book_item_id";
public final static String LANDING_PAGE = "landing_page";
public final static String FROM_APPID = "from_oa_app_id";
public final static String GET_BOOK_ITEM_VAL = "get_book_item_id=true";
public final static String LANDING_PAGE_VAL = "landing_page=reader";
public final static Integer PERMISSION_OPENING_ROLE_LEVEL = 3; public final static Integer PERMISSION_OPENING_ROLE_LEVEL = 3;
public final static BigDecimal THOUSAND_BIG_DECIMAL = new BigDecimal(1000); public final static BigDecimal THOUSAND_BIG_DECIMAL = new BigDecimal(1000);
...@@ -65,6 +72,10 @@ public class CustomerCommonConstant { ...@@ -65,6 +72,10 @@ public class CustomerCommonConstant {
public final static String CUSTOMER_TYPE_NAME_GRAPHICS = "图文"; public final static String CUSTOMER_TYPE_NAME_GRAPHICS = "图文";
public final static String CUSTOMER_TYPE_VALUE_MINI_PROGRAM = "miniprogram";
public final static String CUSTOMER_TYPE_NAME_MINI_PROGRAM = "小程序";
public final static String CUSTOMER_TYPE_NAME_TEXT = "文本"; public final static String CUSTOMER_TYPE_NAME_TEXT = "文本";
public final static Integer SEND_STATUS_WAITING = 0; public final static Integer SEND_STATUS_WAITING = 0;
......
package com.yaoyaozw.customer.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
* 授权方扩展信息表
*
* @author system
* @since 2025-01-01
*/
@ApiModel(value = "authorizer_expand_info")
@Data
@TableName(value = "authorizer_expand_info")
public class AuthorizerExpandInfo implements Serializable {
private static final long serialVersionUID = 1L;
@TableId(value = "id", type = IdType.AUTO)
@ApiModelProperty(value = "主键ID")
private Long id;
@TableField(value = "authorizer_id")
@ApiModelProperty(value = "authorizer_info 主键Id")
private Long authorizerId;
@TableField(value = "authorizer_appid")
@ApiModelProperty(value = "公众号AppId")
private String authorizerAppid;
@TableField(value = "mp_appid")
@ApiModelProperty(value = "关联小程序appId")
private String mpAppid;
@TableField(value = "mp_name")
@ApiModelProperty(value = "关联小程序名称")
private String mpName;
@TableField(value = "mp_distributor_id")
@ApiModelProperty(value = "小程序分销商Id")
private String mpDistributorId;
@TableField(value = "flag_id")
@ApiModelProperty(value = "公众号在书城的标识Id")
private String flagId;
@TableField(value = "gmt_create")
@ApiModelProperty(value = "创建时间")
private Date gmtCreate;
@TableField(value = "gmt_modified")
@ApiModelProperty(value = "修改时间")
private Date gmtModified;
public static final String COL_ID = "id";
public static final String COL_AUTHORIZER_ID = "authorizer_id";
public static final String COL_AUTHORIZER_APPID = "authorizer_appid";
public static final String COL_MP_APPID = "mp_appid";
public static final String COL_MP_NAME = "mp_name";
public static final String COL_MP_DISTRIBUTOR_ID = "mp_distributor_id";
public static final String COL_FLAG_ID = "flag_id";
public static final String COL_GMT_CREATE = "gmt_create";
public static final String COL_GMT_MODIFIED = "gmt_modified";
}
package com.yaoyaozw.customer.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yaoyaozw.customer.entity.AuthorizerExpandInfo;
import org.apache.ibatis.annotations.Mapper;
/**
* 授权方扩展信息表 Mapper 接口
*
* @author system
* @since 2025-01-01
*/
@Mapper
public interface AuthorizerExpandInfoMapper extends BaseMapper<AuthorizerExpandInfo> {
}
package com.yaoyaozw.customer.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.yaoyaozw.customer.entity.AuthorizerExpandInfo;
/**
* 授权方扩展信息表 服务类
*
* @author system
* @since 2025-01-01
*/
public interface AuthorizerExpandInfoService extends IService<AuthorizerExpandInfo> {
}
package com.yaoyaozw.customer.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yaoyaozw.customer.entity.AuthorizerExpandInfo;
import com.yaoyaozw.customer.mapper.AuthorizerExpandInfoMapper;
import com.yaoyaozw.customer.service.AuthorizerExpandInfoService;
import org.springframework.stereotype.Service;
/**
* 授权方扩展信息表 服务实现类
*
* @author system
* @since 2025-01-01
*/
@Service
public class AuthorizerExpandInfoServiceImpl extends ServiceImpl<AuthorizerExpandInfoMapper, AuthorizerExpandInfo> implements AuthorizerExpandInfoService {
}
...@@ -11,20 +11,16 @@ import com.yaoyaozw.customer.common.BaseResult; ...@@ -11,20 +11,16 @@ import com.yaoyaozw.customer.common.BaseResult;
import com.yaoyaozw.customer.common.GenericsResult; import com.yaoyaozw.customer.common.GenericsResult;
import com.yaoyaozw.customer.components.FollowReplyComponent; import com.yaoyaozw.customer.components.FollowReplyComponent;
import com.yaoyaozw.customer.components.SnowflakeComponent; import com.yaoyaozw.customer.components.SnowflakeComponent;
import com.yaoyaozw.customer.constants.CustomerCommonConstant;
import com.yaoyaozw.customer.constants.CustomerMaterialConstant; import com.yaoyaozw.customer.constants.CustomerMaterialConstant;
import com.yaoyaozw.customer.dto.follow.FollowReplyCopyDTO; import com.yaoyaozw.customer.dto.follow.FollowReplyCopyDTO;
import com.yaoyaozw.customer.dto.follow.FollowReplyMultiNewsCreateDTO; import com.yaoyaozw.customer.dto.follow.FollowReplyMultiNewsCreateDTO;
import com.yaoyaozw.customer.dto.follow.FollowReplyQueryDTO; import com.yaoyaozw.customer.dto.follow.FollowReplyQueryDTO;
import com.yaoyaozw.customer.dto.follow.FollowReplySaveDTO; import com.yaoyaozw.customer.dto.follow.FollowReplySaveDTO;
import com.yaoyaozw.customer.entity.CommonReferralBody; import com.yaoyaozw.customer.entity.*;
import com.yaoyaozw.customer.entity.CustomerFollowReply; import com.yaoyaozw.customer.exception.BaseException;
import com.yaoyaozw.customer.entity.CustomerFollowReplyMultiNews;
import com.yaoyaozw.customer.entity.ReferralEntity;
import com.yaoyaozw.customer.mapper.CustomerFollowReplyMapper; import com.yaoyaozw.customer.mapper.CustomerFollowReplyMapper;
import com.yaoyaozw.customer.service.AuthorizerInfoService; import com.yaoyaozw.customer.service.*;
import com.yaoyaozw.customer.service.CustomerFollowReplyMultiNewsService;
import com.yaoyaozw.customer.service.CustomerFollowReplyService;
import com.yaoyaozw.customer.service.ReferralEntityService;
import com.yaoyaozw.customer.utils.TencentCustomerUtil; import com.yaoyaozw.customer.utils.TencentCustomerUtil;
import com.yaoyaozw.customer.vo.AuthInfoVO; import com.yaoyaozw.customer.vo.AuthInfoVO;
import com.yaoyaozw.customer.vo.TencentMediaResponseVO; import com.yaoyaozw.customer.vo.TencentMediaResponseVO;
...@@ -39,10 +35,13 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -39,10 +35,13 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.*; import java.util.*;
import java.util.function.Function; import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static com.yaoyaozw.customer.constants.CustomerCommonConstant.*;
/** /**
* @author darker * @author darker
* @date 2023/3/14 11:15 * @date 2023/3/14 11:15
...@@ -66,6 +65,8 @@ public class CustomerFollowReplyServiceImpl extends ServiceImpl<CustomerFollowRe ...@@ -66,6 +65,8 @@ public class CustomerFollowReplyServiceImpl extends ServiceImpl<CustomerFollowRe
private RedisTemplate<String, Object> redisTemplate; private RedisTemplate<String, Object> redisTemplate;
@Autowired @Autowired
private CustomerFollowReplyMultiNewsService followReplyMultiNewsService; private CustomerFollowReplyMultiNewsService followReplyMultiNewsService;
@Resource
private AuthorizerExpandInfoService authorizerExpandInfoService;
@Override @Override
...@@ -120,6 +121,7 @@ public class CustomerFollowReplyServiceImpl extends ServiceImpl<CustomerFollowRe ...@@ -120,6 +121,7 @@ public class CustomerFollowReplyServiceImpl extends ServiceImpl<CustomerFollowRe
} }
entity.setTxMediaUrl(uploadResponse.getUrl()); entity.setTxMediaUrl(uploadResponse.getUrl());
entity.setTxMediaId(uploadResponse.getMedia_id()); entity.setTxMediaId(uploadResponse.getMedia_id());
handleMp(saveDto, entity);
} else if (CustomerMaterialConstant.TENCENT_MEDIA_TYPE_MULTI_NEWS.equals(entity.getType())) { } else if (CustomerMaterialConstant.TENCENT_MEDIA_TYPE_MULTI_NEWS.equals(entity.getType())) {
// 多图文 // 多图文
List<FollowReplyMultiNewsCreateDTO> multiNewsList = saveDto.getMultiNewsList(); List<FollowReplyMultiNewsCreateDTO> multiNewsList = saveDto.getMultiNewsList();
...@@ -153,6 +155,80 @@ public class CustomerFollowReplyServiceImpl extends ServiceImpl<CustomerFollowRe ...@@ -153,6 +155,80 @@ public class CustomerFollowReplyServiceImpl extends ServiceImpl<CustomerFollowRe
return new GenericsResult<>(String.valueOf(entity.getId())); return new GenericsResult<>(String.valueOf(entity.getId()));
} }
private void handleMp(FollowReplySaveDTO saveDto, CustomerFollowReply 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
String storeType;
if (saveDto.getAccountEntity() != null && StringUtils.isNotBlank(saveDto.getAccountEntity().getStoreType())) {
storeType = saveDto.getAccountEntity().getStoreType();
} else {
AuthorizerInfo authorizerInfo = authorizerInfoService.lambdaQuery().eq(AuthorizerInfo::getAppid, entity.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, 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 = followReplyComponent.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 @Override
public GenericsResult<List<CommonReferralBody>> createTextItem(CommonReferralBody referralBody) { public GenericsResult<List<CommonReferralBody>> createTextItem(CommonReferralBody referralBody) {
CustomerFollowReply entity = this.getById(referralBody.getMaterialGraphicsId()); CustomerFollowReply entity = this.getById(referralBody.getMaterialGraphicsId());
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论