提交 1880b4a1 作者: 沈振路

关回多图文复用处理

上级 61ba3207
...@@ -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.json.JSONUtil;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference; import com.alibaba.fastjson.TypeReference;
...@@ -9,6 +10,7 @@ import com.yaoyaozw.customer.common.R; ...@@ -9,6 +10,7 @@ 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.NewsMessageReplyEntity;
import com.yaoyaozw.customer.entity.CommonReferralBody; import com.yaoyaozw.customer.entity.CommonReferralBody;
import com.yaoyaozw.customer.entity.CustomerFollowReply; import com.yaoyaozw.customer.entity.CustomerFollowReply;
import com.yaoyaozw.customer.entity.CustomerFollowReplyMultiNews; import com.yaoyaozw.customer.entity.CustomerFollowReplyMultiNews;
...@@ -24,6 +26,7 @@ import org.apache.commons.lang3.StringUtils; ...@@ -24,6 +26,7 @@ import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
...@@ -48,6 +51,8 @@ public class FollowReplyComponent { ...@@ -48,6 +51,8 @@ public class FollowReplyComponent {
private ReferralFeignClient referralFeignClient; private ReferralFeignClient referralFeignClient;
@Autowired @Autowired
private SnowflakeComponent snowflakeComponent; private SnowflakeComponent snowflakeComponent;
@Autowired
private RedisTemplate<String, Object> redisTemplate;
/** /**
* 获取链接实体 * 获取链接实体
...@@ -206,6 +211,7 @@ public class FollowReplyComponent { ...@@ -206,6 +211,7 @@ public class FollowReplyComponent {
finalMaterialList.add(entity); finalMaterialList.add(entity);
} else { } else {
// 多图文 // 多图文
redisTemplate.opsForHash().delete(CustomerMaterialConstant.FOLLOW_REPLY_MULTI_NEWS_CACHE_KEY, targetAuth.getAppId());
List<CustomerFollowReplyMultiNews> sourceMultiNewsList = sourceMaterial.getMultiNewsList(); List<CustomerFollowReplyMultiNews> sourceMultiNewsList = sourceMaterial.getMultiNewsList();
for (CustomerFollowReplyMultiNews sourceMultiNews : sourceMultiNewsList) { for (CustomerFollowReplyMultiNews sourceMultiNews : sourceMultiNewsList) {
ReferralEntity sourceReferralEntity = sourceMultiNews.getReferralEntity(); ReferralEntity sourceReferralEntity = sourceMultiNews.getReferralEntity();
...@@ -229,7 +235,10 @@ public class FollowReplyComponent { ...@@ -229,7 +235,10 @@ public class FollowReplyComponent {
result.setMaterialList(finalMaterialList); result.setMaterialList(finalMaterialList);
result.setReferralEntityList(finalReferralList); result.setReferralEntityList(finalReferralList);
result.setMultiNewsList(finalMultiNewsList); result.setMultiNewsList(finalMultiNewsList);
if (CollectionUtil.isNotEmpty(finalMultiNewsList)) {
List<NewsMessageReplyEntity> cacheEntityList = JSONUtil.toList(JSONUtil.parseArray(finalMultiNewsList), NewsMessageReplyEntity.class);
redisTemplate.opsForHash().put(CustomerMaterialConstant.FOLLOW_REPLY_MULTI_NEWS_CACHE_KEY, targetAuth.getAppId(), JSONUtil.toJsonStr(cacheEntityList));
}
return result; return result;
} }
......
...@@ -14,6 +14,8 @@ public class CustomerMaterialConstant { ...@@ -14,6 +14,8 @@ public class CustomerMaterialConstant {
public final static String FOLLOW_REPLY_REDIS_KEY = "followReplyMap"; public final static String FOLLOW_REPLY_REDIS_KEY = "followReplyMap";
public final static String CUSTOMER_KEYWORD_REDIS_KEY = "customerKeywordMap"; public final static String CUSTOMER_KEYWORD_REDIS_KEY = "customerKeywordMap";
public final static String FOLLOW_REPLY_MULTI_NEWS_CACHE_KEY = "followReplyMultiNews";
public final static String TENCENT_MEDIA_TYPE_PIC = "image"; public final static String TENCENT_MEDIA_TYPE_PIC = "image";
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";
......
...@@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; ...@@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
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.CustomerMaterialConstant;
import com.yaoyaozw.customer.dto.follow.FollowReplyMultiNewsCreateDTO; import com.yaoyaozw.customer.dto.follow.FollowReplyMultiNewsCreateDTO;
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.CommonReferralBody;
...@@ -35,7 +36,6 @@ import java.util.stream.Collectors; ...@@ -35,7 +36,6 @@ import java.util.stream.Collectors;
public class CustomerFollowReplyMultiNewsServiceImpl extends ServiceImpl<CustomerFollowReplyMultiNewsMapper, CustomerFollowReplyMultiNews> implements CustomerFollowReplyMultiNewsService { public class CustomerFollowReplyMultiNewsServiceImpl extends ServiceImpl<CustomerFollowReplyMultiNewsMapper, CustomerFollowReplyMultiNews> implements CustomerFollowReplyMultiNewsService {
private final static Logger localLog = LoggerFactory.getLogger(CustomerFollowReplyMultiNewsServiceImpl.class); private final static Logger localLog = LoggerFactory.getLogger(CustomerFollowReplyMultiNewsServiceImpl.class);
private final static String FOLLOW_REPLY_MULTI_NEWS_CACHE_KEY = "followReplyMultiNews";
@Autowired @Autowired
private ReferralEntityService referralEntityService; private ReferralEntityService referralEntityService;
...@@ -59,7 +59,7 @@ public class CustomerFollowReplyMultiNewsServiceImpl extends ServiceImpl<Custome ...@@ -59,7 +59,7 @@ public class CustomerFollowReplyMultiNewsServiceImpl extends ServiceImpl<Custome
List<Long> multiNewsIdList = currentMultiNewsList.stream().map(CustomerFollowReplyMultiNews::getId).collect(Collectors.toList()); List<Long> multiNewsIdList = currentMultiNewsList.stream().map(CustomerFollowReplyMultiNews::getId).collect(Collectors.toList());
referralEntityService.remove(new QueryWrapper<ReferralEntity>().in(ReferralEntity.COL_MATERIAL_GRAPHICS_ID, multiNewsIdList)); referralEntityService.remove(new QueryWrapper<ReferralEntity>().in(ReferralEntity.COL_MATERIAL_GRAPHICS_ID, multiNewsIdList));
this.removeByIds(multiNewsIdList); this.removeByIds(multiNewsIdList);
redisTemplate.opsForHash().delete(FOLLOW_REPLY_MULTI_NEWS_CACHE_KEY, accountEntity.getAppId()); redisTemplate.opsForHash().delete(CustomerMaterialConstant.FOLLOW_REPLY_MULTI_NEWS_CACHE_KEY, accountEntity.getAppId());
} }
List<ReferralEntity> referralEntityList = new ArrayList<>(multiNewsList.size()); List<ReferralEntity> referralEntityList = new ArrayList<>(multiNewsList.size());
List<CustomerFollowReplyMultiNews> entityList = new ArrayList<>(multiNewsList.size()); List<CustomerFollowReplyMultiNews> entityList = new ArrayList<>(multiNewsList.size());
...@@ -89,7 +89,7 @@ public class CustomerFollowReplyMultiNewsServiceImpl extends ServiceImpl<Custome ...@@ -89,7 +89,7 @@ public class CustomerFollowReplyMultiNewsServiceImpl extends ServiceImpl<Custome
localLog.info("generate multi news size {}, referral entity size {}", entityList.size(), referralEntityList.size()); localLog.info("generate multi news size {}, referral entity size {}", entityList.size(), referralEntityList.size());
// 将这些多图文信息转换到缓存 // 将这些多图文信息转换到缓存
List<NewsMessageReplyEntity> cacheEntityList = JSONUtil.toList(JSONUtil.parseArray(multiNewsList), NewsMessageReplyEntity.class); List<NewsMessageReplyEntity> cacheEntityList = JSONUtil.toList(JSONUtil.parseArray(multiNewsList), NewsMessageReplyEntity.class);
redisTemplate.opsForHash().put(FOLLOW_REPLY_MULTI_NEWS_CACHE_KEY, accountEntity.getAppId(), JSONUtil.toJsonStr(cacheEntityList)); redisTemplate.opsForHash().put(CustomerMaterialConstant.FOLLOW_REPLY_MULTI_NEWS_CACHE_KEY, accountEntity.getAppId(), JSONUtil.toJsonStr(cacheEntityList));
this.saveBatch(entityList); this.saveBatch(entityList);
referralEntityService.saveBatch(referralEntityList); referralEntityService.saveBatch(referralEntityList);
} }
......
...@@ -125,7 +125,6 @@ public class CustomerFollowReplyServiceImpl extends ServiceImpl<CustomerFollowRe ...@@ -125,7 +125,6 @@ public class CustomerFollowReplyServiceImpl extends ServiceImpl<CustomerFollowRe
List<FollowReplyMultiNewsCreateDTO> multiNewsList = saveDto.getMultiNewsList(); List<FollowReplyMultiNewsCreateDTO> multiNewsList = saveDto.getMultiNewsList();
localLog.info("appId {} follow reply has multi news size {}", saveDto.getAppid(), multiNewsList.size()); localLog.info("appId {} follow reply has multi news size {}", saveDto.getAppid(), multiNewsList.size());
followReplyMultiNewsService.saveFollowReplyMultiNews(entity.getId(), saveDto.getAccountEntity(), saveDto.getMultiNewsList()); followReplyMultiNewsService.saveFollowReplyMultiNews(entity.getId(), saveDto.getAccountEntity(), 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;
...@@ -196,6 +195,13 @@ public class CustomerFollowReplyServiceImpl extends ServiceImpl<CustomerFollowRe ...@@ -196,6 +195,13 @@ public class CustomerFollowReplyServiceImpl extends ServiceImpl<CustomerFollowRe
// 删除本体 // 删除本体
this.removeById(id); this.removeById(id);
// 查看是否有多图文素材
List<CustomerFollowReplyMultiNews> followReplyMultiNewsList = followReplyMultiNewsService.list(new QueryWrapper<CustomerFollowReplyMultiNews>().eq("reply_id", id));
if (CollectionUtil.isNotEmpty(followReplyMultiNewsList)) {
List<Long> newsIdList = followReplyMultiNewsList.stream().map(CustomerFollowReplyMultiNews::getId).collect(Collectors.toList());
followReplyMultiNewsService.removeByIds(newsIdList);
referralEntityService.remove(new QueryWrapper<ReferralEntity>().in(ReferralEntity.COL_MATERIAL_GRAPHICS_ID, newsIdList));
}
// 删除相关链接 // 删除相关链接
referralEntityService.remove(new QueryWrapper<ReferralEntity>().eq(ReferralEntity.COL_MATERIAL_GRAPHICS_ID, id)); referralEntityService.remove(new QueryWrapper<ReferralEntity>().eq(ReferralEntity.COL_MATERIAL_GRAPHICS_ID, id));
// 重置redis中的素材 // 重置redis中的素材
...@@ -394,6 +400,14 @@ public class CustomerFollowReplyServiceImpl extends ServiceImpl<CustomerFollowRe ...@@ -394,6 +400,14 @@ public class CustomerFollowReplyServiceImpl extends ServiceImpl<CustomerFollowRe
// 删除主体 // 删除主体
this.removeByIds(sourceMaterialIdList); this.removeByIds(sourceMaterialIdList);
QueryWrapper<CustomerFollowReplyMultiNews> multiNewsQueryWrapper = new QueryWrapper<CustomerFollowReplyMultiNews>().in("reply_id", sourceMaterialIdList);
List<CustomerFollowReplyMultiNews> multiNewsList = followReplyMultiNewsService.list(multiNewsQueryWrapper);
if (CollectionUtil.isNotEmpty(multiNewsList)) {
followReplyMultiNewsService.remove(multiNewsQueryWrapper);
List<Long> newsIdList = multiNewsList.stream().map(CustomerFollowReplyMultiNews::getId).collect(Collectors.toList());
// 把多图文的id添加到素材id列表中,一起删除referralEntity数据
sourceMaterialIdList.addAll(newsIdList);
}
// 删除链接 // 删除链接
referralEntityService.remove(new QueryWrapper<ReferralEntity>().in(ReferralEntity.COL_MATERIAL_GRAPHICS_ID, sourceMaterialIdList)); referralEntityService.remove(new QueryWrapper<ReferralEntity>().in(ReferralEntity.COL_MATERIAL_GRAPHICS_ID, sourceMaterialIdList));
...@@ -422,6 +436,11 @@ public class CustomerFollowReplyServiceImpl extends ServiceImpl<CustomerFollowRe ...@@ -422,6 +436,11 @@ public class CustomerFollowReplyServiceImpl extends ServiceImpl<CustomerFollowRe
} else { } else {
redisTemplate.opsForHash().delete(CustomerMaterialConstant.FOLLOW_REPLY_REDIS_KEY, appid); redisTemplate.opsForHash().delete(CustomerMaterialConstant.FOLLOW_REPLY_REDIS_KEY, appid);
} }
long multiNewsCount = entityList.stream().filter(item -> CustomerMaterialConstant.TENCENT_MEDIA_TYPE_MULTI_NEWS.equals(item.getType())).count();
if (multiNewsCount == 0) {
redisTemplate.opsForHash().delete(CustomerMaterialConstant.FOLLOW_REPLY_MULTI_NEWS_CACHE_KEY, appid);
}
} }
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论