提交 b9723371 作者: 沈振路

关回多图文配置(不入库,进缓存)

上级 5d3b35dc
...@@ -18,6 +18,7 @@ public class CustomerMaterialConstant { ...@@ -18,6 +18,7 @@ public class CustomerMaterialConstant {
public final static String TENCENT_MEDIA_TYPE_VOICE = "voice"; public final static String TENCENT_MEDIA_TYPE_VOICE = "voice";
public final static String TENCENT_MEDIA_TYPE_NEWS = "news"; public final static String TENCENT_MEDIA_TYPE_NEWS = "news";
public final static String TENCENT_MEDIA_TYPE_TEXT = "text"; public final static String TENCENT_MEDIA_TYPE_TEXT = "text";
public final static String TENCENT_MEDIA_TYPE_MULTI_NEWS = "multi_news";
public static Boolean needUpload(String type) { public static Boolean needUpload(String type) {
......
package com.yaoyaozw.customer.controller;
import com.yaoyaozw.customer.common.R;
import com.yaoyaozw.customer.dto.follow.FollowReplyMultiNewsCreateDTO;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @author darker
* @date 2023/10/26 16:11
*/
@RestController
@RequestMapping("/follow-reply/multi-news")
public class FollowReplyMultiNewsController {
@PostMapping("/createMultiNews")
public R createMultiNews(@RequestBody FollowReplyMultiNewsCreateDTO createDto) {
return null;
}
}
package com.yaoyaozw.customer.dto.follow;
import com.yaoyaozw.customer.entity.CommonReferralBody;
import com.yaoyaozw.customer.entity.CustomerFollowReplyMultiNews;
import com.yaoyaozw.customer.entity.ReferralEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.io.Serializable;
/**
* @author darker
* @date 2023/10/26 16:14
*/
@EqualsAndHashCode(callSuper = true)
@Data
public class FollowReplyMultiNewsCreateDTO extends CustomerFollowReplyMultiNews implements Serializable {
/**
* 链接参数
*/
private CommonReferralBody referralBody;
}
...@@ -8,6 +8,7 @@ import lombok.Data; ...@@ -8,6 +8,7 @@ import lombok.Data;
import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import java.io.Serializable; import java.io.Serializable;
import java.util.List;
/** /**
* @author darker * @author darker
...@@ -37,4 +38,9 @@ public class FollowReplySaveDTO implements Serializable { ...@@ -37,4 +38,9 @@ public class FollowReplySaveDTO implements Serializable {
private Integer sort; private Integer sort;
private CommonReferralBody referralBody; private CommonReferralBody referralBody;
/**
* 多图文的图文列表
*/
private List<FollowReplyMultiNewsCreateDTO> multiNewsList;
} }
package com.yaoyaozw.customer.dto.follow;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
/**
* @author darker
* @date 2023/10/26 10:49
*/
@Data
@NoArgsConstructor
public class NewsMessageReplyEntity implements Serializable {
private String title;
private String picUrl;
private String linkUrl;
public NewsMessageReplyEntity(String title, String picUrl, String linkUrl) {
this.title = title;
this.picUrl = picUrl;
this.linkUrl = linkUrl;
}
}
package com.yaoyaozw.customer.entity;
import java.io.Serializable;
import java.util.Date;
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 lombok.Data;
/**
* @author darker
* @date 2023/10/26
*/
@Data
@TableName("customer_follow_reply_multi_news")
public class CustomerFollowReplyMultiNews implements Serializable {
/**
* 主键Id
*/
@TableId(value = "id", type = IdType.ID_WORKER)
private Long id;
/**
* customer_follow_reply 表主键Id
*/
@TableField("reply_id")
private Long replyId;
/**
* 标题
*/
@TableField("title")
private String title;
/**
* 图片地址
*/
@TableField("pic_url")
private String picUrl;
/**
* 链接地址
*/
@TableField("link_url")
private String linkUrl;
/**
* 逻辑删除
*/
@TableField("is_deleted")
private Integer isDeleted;
/**
* 创建时间
*/
@TableField("gmt_create")
private Date gmtCreate;
/**
* 创建人
*/
@TableField("create_user")
private Long createUser;
/**
* 修改时间
*/
@TableField("gmt_modified")
private Date gmtModified;
/**
* 修改人
*/
@TableField("modified_user")
private Long modifiedUser;
private static final long serialVersionUID = 1L;
}
package com.yaoyaozw.customer.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yaoyaozw.customer.entity.CustomerFollowReplyMultiNews;
import org.apache.ibatis.annotations.Mapper;
/**
* @author darker
* @date 2023/11/1 14:28
*/
@Mapper
public interface CustomerFollowReplyMultiNewsMapper extends BaseMapper<CustomerFollowReplyMultiNews> {
}
package com.yaoyaozw.customer.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.yaoyaozw.customer.dto.follow.FollowReplyMultiNewsCreateDTO;
import com.yaoyaozw.customer.entity.CustomerFollowReplyMultiNews;
import java.util.List;
/**
* @author darker
* @date 2023/11/1 14:28
*/
public interface CustomerFollowReplyMultiNewsService extends IService<CustomerFollowReplyMultiNews> {
/**
* 保存关回多图文的图文列表
* @param replyId 关回配置的主键Id
* @param appId 公众号 appId
* @param multiNewsList 图文列表
*/
void saveFollowReplyMultiNews(Long replyId, String appId, List<FollowReplyMultiNewsCreateDTO> multiNewsList);
}
package com.yaoyaozw.customer.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yaoyaozw.customer.components.FollowReplyComponent;
import com.yaoyaozw.customer.components.SnowflakeComponent;
import com.yaoyaozw.customer.dto.follow.FollowReplyMultiNewsCreateDTO;
import com.yaoyaozw.customer.dto.follow.NewsMessageReplyEntity;
import com.yaoyaozw.customer.entity.CommonReferralBody;
import com.yaoyaozw.customer.entity.CustomerFollowReply;
import com.yaoyaozw.customer.entity.CustomerFollowReplyMultiNews;
import com.yaoyaozw.customer.entity.ReferralEntity;
import com.yaoyaozw.customer.mapper.CustomerFollowReplyMultiNewsMapper;
import com.yaoyaozw.customer.service.CustomerFollowReplyMultiNewsService;
import com.yaoyaozw.customer.service.ReferralEntityService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
/**
* @author darker
* @date 2023/11/1 14:29
*/
@Service
public class CustomerFollowReplyMultiNewsServiceImpl extends ServiceImpl<CustomerFollowReplyMultiNewsMapper, CustomerFollowReplyMultiNews> implements CustomerFollowReplyMultiNewsService {
private final static Logger localLog = LoggerFactory.getLogger(CustomerFollowReplyMultiNewsServiceImpl.class);
private final static String FOLLOW_REPLY_MULTI_NEWS_CACHE_KEY = "followReplyMultiNews";
@Autowired
private ReferralEntityService referralEntityService;
@Autowired
private FollowReplyComponent followReplyComponent;
@Autowired
private RedisTemplate<String, Object> redisTemplate;
@Autowired
private SnowflakeComponent snowflakeComponent;
@Override
public void saveFollowReplyMultiNews(Long replyId, String appId, List<FollowReplyMultiNewsCreateDTO> multiNewsList) {
if (CollectionUtil.isEmpty(multiNewsList)) {
return;
}
localLog.info("reply id {} save multi news size {}", replyId, multiNewsList.size());
// 删除这个replyId当前的所有的多图文配置
List<CustomerFollowReplyMultiNews> currentMultiNewsList = this.list(new QueryWrapper<CustomerFollowReplyMultiNews>().eq("reply_id", replyId));
if (CollectionUtil.isNotEmpty(currentMultiNewsList)) {
// 删除这些多图文配置对应的referral_entity 数据
List<Long> multiNewsIdList = currentMultiNewsList.stream().map(CustomerFollowReplyMultiNews::getId).collect(Collectors.toList());
referralEntityService.remove(new QueryWrapper<ReferralEntity>().in(ReferralEntity.COL_MATERIAL_GRAPHICS_ID, multiNewsIdList));
this.removeByIds(multiNewsIdList);
redisTemplate.opsForHash().delete(FOLLOW_REPLY_MULTI_NEWS_CACHE_KEY, appId);
}
List<ReferralEntity> referralEntityList = new ArrayList<>(multiNewsList.size());
List<CustomerFollowReplyMultiNews> entityList = new ArrayList<>(multiNewsList.size());
// 处理链接
for (FollowReplyMultiNewsCreateDTO multiNewsEntity : multiNewsList) {
CommonReferralBody referralBody = multiNewsEntity.getReferralBody();
// 调用通用方法生成referralEntity
ReferralEntity referralEntity = followReplyComponent.getCreateReferralEntity(referralBody);
referralEntityList.add(referralEntity);
// 将生成的链接设置到多图文表中
multiNewsEntity.setLinkUrl(referralEntity.getReferral());
CustomerFollowReplyMultiNews entity = new CustomerFollowReplyMultiNews();
BeanUtil.copyProperties(multiNewsEntity, entity);
entityList.add(entity);
}
localLog.info("generate multi news size {}, referral entity size {}", entityList.size(), referralEntityList.size());
// 将这些多图文信息转换到缓存
List<NewsMessageReplyEntity> cacheEntityList = JSONUtil.toList(JSONUtil.parseArray(multiNewsList), NewsMessageReplyEntity.class);
redisTemplate.opsForHash().put(FOLLOW_REPLY_MULTI_NEWS_CACHE_KEY, appId, JSONUtil.toJsonStr(cacheEntityList));
// this.saveBatch(entityList);
// referralEntityService.saveBatch(referralEntityList);
}
}
...@@ -13,6 +13,7 @@ import com.yaoyaozw.customer.components.FollowReplyComponent; ...@@ -13,6 +13,7 @@ import com.yaoyaozw.customer.components.FollowReplyComponent;
import com.yaoyaozw.customer.components.SnowflakeComponent; import com.yaoyaozw.customer.components.SnowflakeComponent;
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.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.CommonReferralBody;
...@@ -20,6 +21,7 @@ import com.yaoyaozw.customer.entity.CustomerFollowReply; ...@@ -20,6 +21,7 @@ import com.yaoyaozw.customer.entity.CustomerFollowReply;
import com.yaoyaozw.customer.entity.ReferralEntity; 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.AuthorizerInfoService;
import com.yaoyaozw.customer.service.CustomerFollowReplyMultiNewsService;
import com.yaoyaozw.customer.service.CustomerFollowReplyService; import com.yaoyaozw.customer.service.CustomerFollowReplyService;
import com.yaoyaozw.customer.service.ReferralEntityService; import com.yaoyaozw.customer.service.ReferralEntityService;
import com.yaoyaozw.customer.utils.TencentCustomerUtil; import com.yaoyaozw.customer.utils.TencentCustomerUtil;
...@@ -62,6 +64,8 @@ public class CustomerFollowReplyServiceImpl extends ServiceImpl<CustomerFollowRe ...@@ -62,6 +64,8 @@ public class CustomerFollowReplyServiceImpl extends ServiceImpl<CustomerFollowRe
private AuthorizerInfoService authorizerInfoService; private AuthorizerInfoService authorizerInfoService;
@Autowired @Autowired
private RedisTemplate<String, Object> redisTemplate; private RedisTemplate<String, Object> redisTemplate;
@Autowired
private CustomerFollowReplyMultiNewsService followReplyMultiNewsService;
@Override @Override
...@@ -116,6 +120,12 @@ public class CustomerFollowReplyServiceImpl extends ServiceImpl<CustomerFollowRe ...@@ -116,6 +120,12 @@ public class CustomerFollowReplyServiceImpl extends ServiceImpl<CustomerFollowRe
} }
entity.setTxMediaUrl(uploadResponse.getUrl()); entity.setTxMediaUrl(uploadResponse.getUrl());
entity.setTxMediaId(uploadResponse.getMedia_id()); entity.setTxMediaId(uploadResponse.getMedia_id());
} else if (CustomerMaterialConstant.TENCENT_MEDIA_TYPE_MULTI_NEWS.equals(entity.getType())) {
// 多图文
List<FollowReplyMultiNewsCreateDTO> multiNewsList = saveDto.getMultiNewsList();
localLog.info("appId {} follow reply has multi news size {}", saveDto.getAppid(), multiNewsList.size());
followReplyMultiNewsService.saveFollowReplyMultiNews(entity.getId(), saveDto.getAppid(), saveDto.getMultiNewsList());
return new GenericsResult<>(true, "【测试】多图文关回设置成功");
} else if (!CustomerMaterialConstant.TENCENT_MEDIA_TYPE_TEXT.equals(entity.getType())){ } else if (!CustomerMaterialConstant.TENCENT_MEDIA_TYPE_TEXT.equals(entity.getType())){
// 获取书城公众号链接(图文) // 获取书城公众号链接(图文)
ReferralEntity referralEntity; ReferralEntity referralEntity;
...@@ -355,8 +365,8 @@ public class CustomerFollowReplyServiceImpl extends ServiceImpl<CustomerFollowRe ...@@ -355,8 +365,8 @@ public class CustomerFollowReplyServiceImpl extends ServiceImpl<CustomerFollowRe
} }
private String checkNecessary(FollowReplySaveDTO saveDto) { private String checkNecessary(FollowReplySaveDTO saveDto) {
if (!CustomerMaterialConstant.TENCENT_MEDIA_TYPE_TEXT.equals(saveDto.getType())) { if (!CustomerMaterialConstant.TENCENT_MEDIA_TYPE_TEXT.equals(saveDto.getType()) && !CustomerMaterialConstant.TENCENT_MEDIA_TYPE_MULTI_NEWS.equals(saveDto.getType())) {
// 非文本类型的都需要文件 // 文本类型和多图文类型的都不需要文件
if (StringUtils.isEmpty(saveDto.getOriginMediaUrl())) { if (StringUtils.isEmpty(saveDto.getOriginMediaUrl())) {
return "请选择素材文件"; return "请选择素材文件";
} }
......
...@@ -237,6 +237,10 @@ public class CustomerGraphicsServiceImpl extends ServiceImpl<CustomerGraphicsMap ...@@ -237,6 +237,10 @@ public class CustomerGraphicsServiceImpl extends ServiceImpl<CustomerGraphicsMap
Long packId = customerGraphics.getPackId(); Long packId = customerGraphics.getPackId();
CrowdPackage crowdPackage = crowdPackageMap.get(packId); CrowdPackage crowdPackage = crowdPackageMap.get(packId);
if (crowdPackage == null) {
LOCAL_LOG.warn("crowd package id {} not exist", packId);
continue;
}
//活跃时间限制窗口 //活跃时间限制窗口
Long activeTimeMax = crowdPackage.getActiveTimeMax(); Long activeTimeMax = crowdPackage.getActiveTimeMax();
Long activeTimeMin = crowdPackage.getActiveTimeMin(); Long activeTimeMin = crowdPackage.getActiveTimeMin();
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论