Commit 1bd06e97 by 吴博

feat: [1007550]【优化】指定图书(斗罗大陆第五部重生唐三15)资源优化

parent cfec5133
...@@ -316,4 +316,10 @@ public interface BookGroupService { ...@@ -316,4 +316,10 @@ public interface BookGroupService {
@GetMapping("getQrcodeOneServe") @GetMapping("getQrcodeOneServe")
public ResponseEntity<ResponseDto<String>> getQrcodeOneServe(@RequestParam(value = "bookGroupId", required = false) Long bookGroupId, public ResponseEntity<ResponseDto<String>> getQrcodeOneServe(@RequestParam(value = "bookGroupId", required = false) Long bookGroupId,
@RequestParam(value = "sceneId", required = false) Long sceneId); @RequestParam(value = "sceneId", required = false) Long sceneId);
@ApiOperation("删除斗罗首页缓存")
@PostMapping("deleteDouluoCache")
void deleteDouluoCache(@RequestParam("sceneId") Long sceneId,
@RequestParam("wechatUserId") Long wechatUserId,
@RequestBody List<Long> mapSceneIds);
} }
...@@ -575,9 +575,10 @@ public interface ResourcePageBiz { ...@@ -575,9 +575,10 @@ public interface ResourcePageBiz {
* 客户端-斗罗大陆获取配置资源 * 客户端-斗罗大陆获取配置资源
* @param wechatUserId * @param wechatUserId
* @param sceneId * @param sceneId
* @param mapSceneId
* @return * @return
*/ */
List<ResourcePageItemVO> getServerList4Wechat(Long wechatUserId, Long sceneId); List<ResourcePageItemVO> getServerList4Wechat(Long wechatUserId, Long sceneId, Long mapSceneId);
/** /**
* @Description 一码一资源,素材列表 * @Description 一码一资源,素材列表
* @Author zhuyajie * @Author zhuyajie
...@@ -598,4 +599,12 @@ public interface ResourcePageBiz { ...@@ -598,4 +599,12 @@ public interface ResourcePageBiz {
* 根据rays码id查资源页菜单栏数量 * 根据rays码id查资源页菜单栏数量
*/ */
Integer getNavigationCount(Long bookGroupId, Long wechatUserId, Long sceneId); Integer getNavigationCount(Long bookGroupId, Long wechatUserId, Long sceneId);
/**
* 删除斗罗首页缓存
* @param sceneId
* @param mapSceneIds
* @param wechatUserId
*/
void deleteDouluoCache(Long sceneId, List<Long> mapSceneIds, Long wechatUserId);
} }
...@@ -4,6 +4,7 @@ import cn.hutool.core.bean.BeanUtil; ...@@ -4,6 +4,7 @@ import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.io.FileUtil; import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.ReUtil; import cn.hutool.core.util.ReUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
...@@ -11,6 +12,7 @@ import cn.hutool.extra.qrcode.QrCodeException; ...@@ -11,6 +12,7 @@ import cn.hutool.extra.qrcode.QrCodeException;
import cn.hutool.extra.qrcode.QrCodeUtil; import cn.hutool.extra.qrcode.QrCodeUtil;
import cn.hutool.http.HttpUtil; import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.pcloud.advertising.advertising.dto.AdvertisingSpaceDTO; import com.pcloud.advertising.advertising.dto.AdvertisingSpaceDTO;
import com.pcloud.advertising.advertising.dto.AdvertisingSpaceItemDTO; import com.pcloud.advertising.advertising.dto.AdvertisingSpaceItemDTO;
...@@ -4536,14 +4538,22 @@ public class ResourcePageBizImpl implements ResourcePageBiz { ...@@ -4536,14 +4538,22 @@ public class ResourcePageBizImpl implements ResourcePageBiz {
} }
@Override @Override
public List<ResourcePageItemVO> getServerList4Wechat(Long wechatUserId, Long sceneId) { public List<ResourcePageItemVO> getServerList4Wechat(Long wechatUserId, Long sceneId, Long mapSceneId) {
List<ResourcePageItemVO> itemVOList = JedisClusterUtils.getJsonList(StrUtil.join(":",DL_BOOK_SERVES_CACHE,sceneId, wechatUserId), ResourcePageItemVO.class); String redisKey = StrUtil.join(":", DL_BOOK_SERVES_CACHE, sceneId);
if (CollUtil.isEmpty(itemVOList)) { String redisField = StrUtil.join(":", wechatUserId, mapSceneId);
List<ResourcePageItemVO> itemVOList = JedisClusterUtils.hgetJson2List(redisKey, redisField, ResourcePageItemVO.class);
if (CollUtil.isEmpty(itemVOList)) {
ResourcePage bySceneId = resourcePageDao.getBySceneId(sceneId); ResourcePage bySceneId = resourcePageDao.getBySceneId(sceneId);
if (null == bySceneId) { if (null == bySceneId) {
return new ArrayList<>(); return new ArrayList<>();
} }
itemVOList = resourcePageItemDao.getResourcePageItemByPageId(bySceneId.getId(), true); itemVOList = resourcePageItemDao.getResourcePageItemByPageId(bySceneId.getId(), true);
//如果mapSceneId 不为null 则直接替换其中的精品文章
try {
replaceArticle(itemVOList, mapSceneId);
} catch (Exception e) {
log.warn("斗罗更换精品文章失败sceneId:{}", sceneId);
}
if(CollUtil.isEmpty(itemVOList)) { if(CollUtil.isEmpty(itemVOList)) {
return new ArrayList<>(); return new ArrayList<>();
} }
...@@ -4572,14 +4582,59 @@ public class ResourcePageBizImpl implements ResourcePageBiz { ...@@ -4572,14 +4582,59 @@ public class ResourcePageBizImpl implements ResourcePageBiz {
} }
setChannel(itemVOList); setChannel(itemVOList);
fillTaskType(itemVOList,wechatUserId); fillTaskType(itemVOList,wechatUserId);
fillPageType(sceneId,itemVOList,mapSceneId,bySceneId.getBookId());
} }
if (CollUtil.isNotEmpty(itemVOList)) { if (CollUtil.isNotEmpty(itemVOList)) {
JedisClusterUtils.setJsonList(StrUtil.join(":",DL_BOOK_SERVES_CACHE,sceneId, wechatUserId), itemVOList, 3600 * 24); JedisClusterUtils.hset2Json(redisKey, redisField, itemVOList);
JedisClusterUtils.expire(redisKey, 3600 * 14);
} }
return itemVOList; return itemVOList;
} }
private void fillPageType(Long sceneId, List<ResourcePageItemVO> itemVOList, Long mapSceneId, Long bookId) {
// 处理斗罗系列书二维码映射
//添加页面版本
String pageType = JedisClusterUtils.hget("FUNCTION:DOULUO_BOOK_MAP", bookId.toString());
itemVOList.forEach(e -> {
if (null != e.getResultUrl() && null != mapSceneId) {
e.setResultUrl(e.getResultUrl() + "&mapSceneId=" + mapSceneId);
}
if (null != e.getResultUrl() && StrUtil.isNotBlank(pageType)) {
e.setResultUrl(e.getResultUrl() + "&pageType=" + pageType);
}
});
}
private void replaceArticle(List<ResourcePageItemVO> itemVOList, Long mapSceneId) {
if (CollUtil.isEmpty(itemVOList) || null == mapSceneId) {
return;
}
ResourcePage bySceneId = resourcePageDao.getBySceneId(mapSceneId);
if (null == bySceneId) {
return;
}
List<ResourcePageItemVO> itemVOList4Map = resourcePageItemDao.getResourcePageItemByPageId(bySceneId.getId(), true);
if (CollUtil.isEmpty(itemVOList4Map)) {
return;
}
Optional<ResourcePageItemVO> first = itemVOList4Map.stream().filter(e -> AppTypeEnum.ARTICLE.value.equals(e.getTypeCode())).findFirst();
if (!first.isPresent()) {
return;
}
itemVOList.forEach(e -> {
if (AppTypeEnum.ARTICLE.value.equals(e.getTypeCode())) {
BeanUtil.copyProperties(first.get(), e);
}
});
}
private void setChannel(List<ResourcePageItemVO> itemVOList) { private void setChannel(List<ResourcePageItemVO> itemVOList) {
String key = "BOOK:DOULUO:SET:CHANNEL:STATE";
if(JedisClusterUtils.exists(key)) {
return;
}
if (CollUtil.isEmpty(itemVOList)) { if (CollUtil.isEmpty(itemVOList)) {
return; return;
} }
...@@ -4711,4 +4766,19 @@ public class ResourcePageBizImpl implements ResourcePageBiz { ...@@ -4711,4 +4766,19 @@ public class ResourcePageBizImpl implements ResourcePageBiz {
} }
return count; return count;
} }
@Override
public void deleteDouluoCache(Long sceneId, List<Long> mapSceneIds, Long wechatUserId) {
if (null == sceneId) {
return;
}
String redisKey = StrUtil.join(":", DL_BOOK_SERVES_CACHE, sceneId);
if (CollUtil.isEmpty(mapSceneIds)) {
JedisClusterUtils.del(redisKey);
} else {
String[] fields = mapSceneIds.stream().map(e -> StrUtil.join(":",wechatUserId, e.toString())).collect(Collectors.toList()).stream().toArray(String[]::new);
JedisClusterUtils.hdel(redisKey, fields);
}
}
} }
...@@ -479,9 +479,10 @@ public class ResourcePageFacade { ...@@ -479,9 +479,10 @@ public class ResourcePageFacade {
@ApiOperation("客户端-斗罗大陆获取配置资源") @ApiOperation("客户端-斗罗大陆获取配置资源")
@GetMapping("getServerList4Wechat") @GetMapping("getServerList4Wechat")
public ResponseDto<?> getServerList4Wechat(@CookieValue("userInfo") String userInfo, public ResponseDto<?> getServerList4Wechat(@CookieValue("userInfo") String userInfo,
@RequestParam(value = "sceneId") Long sceneId){ @RequestParam(value = "sceneId") Long sceneId,
@RequestParam(value = "mapSceneId",required = false) Long mapSceneId){
Long wechatUserId = Cookie.getId(userInfo,Cookie._WECHAT_USER_ID); Long wechatUserId = Cookie.getId(userInfo,Cookie._WECHAT_USER_ID);
return new ResponseDto<>(resourcePageBiz.getServerList4Wechat(wechatUserId, sceneId)); return new ResponseDto<>(resourcePageBiz.getServerList4Wechat(wechatUserId, sceneId, mapSceneId));
} }
......
...@@ -535,4 +535,13 @@ public class BookGroupServiceImpl implements BookGroupService { ...@@ -535,4 +535,13 @@ public class BookGroupServiceImpl implements BookGroupService {
@RequestParam(value = "sceneId", required = false) Long sceneId) { @RequestParam(value = "sceneId", required = false) Long sceneId) {
return ResponseHandleUtil.toResponse(resourcePageBiz.getQrcodeOneServe(bookGroupId,sceneId,null)); return ResponseHandleUtil.toResponse(resourcePageBiz.getQrcodeOneServe(bookGroupId,sceneId,null));
} }
@ApiOperation("删除斗罗首页缓存")
@PostMapping("deleteDouluoCache")
@Override
public void deleteDouluoCache(@RequestParam("sceneId") Long sceneId,
@RequestParam("wechatUserId") Long wechatUserId,
@RequestBody List<Long> mapSceneIds){
resourcePageBiz.deleteDouluoCache(sceneId, mapSceneIds,wechatUserId);
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment