Commit 4c2a0563 authored by 赵啸非's avatar 赵啸非

添加查询缓存

parent 6839b90a
...@@ -69,7 +69,7 @@ public class WindowBusinessServiceImpl extends AbstractCRUDServiceImpl<WindowBus ...@@ -69,7 +69,7 @@ public class WindowBusinessServiceImpl extends AbstractCRUDServiceImpl<WindowBus
public Result<WindowBusinessEntity> find(WindowBusinessEntity entity, PageInfo pageInfo, Context context) throws AppException { public Result<WindowBusinessEntity> find(WindowBusinessEntity entity, PageInfo pageInfo, Context context) throws AppException {
WindowBusinessEntity query = this.findBefore(entity, pageInfo, context); WindowBusinessEntity query = this.findBefore(entity, pageInfo, context);
//判断查询结果是否用缓存 //判断查询结果是否用缓存
if (!ObjectUtils.isEmpty(query) &&!ObjectUtils.isEmpty(query.getSearchCache()) && !ObjectUtils.isEmpty(query.getSearchCache() == YesNoEnum.YES.getValue())) { if (!ObjectUtils.isEmpty(query) && !ObjectUtils.isEmpty(query.getSearchCache()) && !ObjectUtils.isEmpty(query.getSearchCache() == YesNoEnum.YES.getValue())) {
//根据查询条件 获取缓存,如果缓存有则直接取缓存,否则读数据库后 再写入缓存 //根据查询条件 获取缓存,如果缓存有则直接取缓存,否则读数据库后 再写入缓存
return getWindowBusinessEntityCacheResult(entity, pageInfo, context, query); return getWindowBusinessEntityCacheResult(entity, pageInfo, context, query);
} else { } else {
...@@ -85,12 +85,16 @@ public class WindowBusinessServiceImpl extends AbstractCRUDServiceImpl<WindowBus ...@@ -85,12 +85,16 @@ public class WindowBusinessServiceImpl extends AbstractCRUDServiceImpl<WindowBus
Long siteBusinessId = query.getSiteBusinessId(); Long siteBusinessId = query.getSiteBusinessId();
String cacheResult = cacheService.get(KEY_SEARCH_SITEBUSINESSID_CACHE + siteBusinessId, String.class); String cacheResult = cacheService.get(KEY_SEARCH_SITEBUSINESSID_CACHE + siteBusinessId, String.class);
if (!ObjectUtils.isEmpty(cacheResult)) { if (!ObjectUtils.isEmpty(cacheResult)) {
result = JSON.parseObject(cacheResult, new TypeReference<Result<WindowBusinessEntity>>() {}); result = JSON.parseObject(cacheResult, new TypeReference<Result<WindowBusinessEntity>>() {
});
} else { } else {
//查询数据库 //查询数据库
result = this.dao.getList(query, pageInfo); result = this.dao.getList(query, pageInfo);
this.findAfter(entity, pageInfo, context, result.getList()); this.findAfter(entity, pageInfo, context, result.getList());
if (!ObjectUtils.isEmpty(result.getList())) {
cacheService.set(KEY_SEARCH_SITEBUSINESSID_CACHE + siteBusinessId, JSON.toJSONString(result), KEY_SEARCH_TIMEOUTT_CACHE); cacheService.set(KEY_SEARCH_SITEBUSINESSID_CACHE + siteBusinessId, JSON.toJSONString(result), KEY_SEARCH_TIMEOUTT_CACHE);
}
} }
} else if (!ObjectUtils.isEmpty(query.getWindowId())) { } else if (!ObjectUtils.isEmpty(query.getWindowId())) {
Long windowId = query.getWindowId(); Long windowId = query.getWindowId();
...@@ -102,8 +106,11 @@ public class WindowBusinessServiceImpl extends AbstractCRUDServiceImpl<WindowBus ...@@ -102,8 +106,11 @@ public class WindowBusinessServiceImpl extends AbstractCRUDServiceImpl<WindowBus
//查询数据库 //查询数据库
result = this.dao.getList(query, pageInfo); result = this.dao.getList(query, pageInfo);
this.findAfter(entity, pageInfo, context, result.getList()); this.findAfter(entity, pageInfo, context, result.getList());
//无查询结果的不做保存
if (!ObjectUtils.isEmpty(result.getList())) {
cacheService.set(KEY_SEARCH_WINDOWID_CACHE + windowId, JSON.toJSONString(result), KEY_SEARCH_TIMEOUTT_CACHE); cacheService.set(KEY_SEARCH_WINDOWID_CACHE + windowId, JSON.toJSONString(result), KEY_SEARCH_TIMEOUTT_CACHE);
} }
}
} else if (!ObjectUtils.isEmpty(query.getWindowIdList())) { } else if (!ObjectUtils.isEmpty(query.getWindowIdList())) {
String windowIdlist = query.getWindowIdList().stream().map(String::valueOf).collect(Collectors.joining("#")); String windowIdlist = query.getWindowIdList().stream().map(String::valueOf).collect(Collectors.joining("#"));
String cacheResult = cacheService.get(KEY_SEARCH_WINDOWID_LIST_CACHE + windowIdlist, String.class); String cacheResult = cacheService.get(KEY_SEARCH_WINDOWID_LIST_CACHE + windowIdlist, String.class);
...@@ -114,8 +121,10 @@ public class WindowBusinessServiceImpl extends AbstractCRUDServiceImpl<WindowBus ...@@ -114,8 +121,10 @@ public class WindowBusinessServiceImpl extends AbstractCRUDServiceImpl<WindowBus
//查询数据库 //查询数据库
result = this.dao.getList(query, pageInfo); result = this.dao.getList(query, pageInfo);
this.findAfter(entity, pageInfo, context, result.getList()); this.findAfter(entity, pageInfo, context, result.getList());
if (!ObjectUtils.isEmpty(result.getList())) {
cacheService.set(KEY_SEARCH_WINDOWID_LIST_CACHE + windowIdlist, JSON.toJSONString(result), KEY_SEARCH_TIMEOUTT_CACHE); cacheService.set(KEY_SEARCH_WINDOWID_LIST_CACHE + windowIdlist, JSON.toJSONString(result), KEY_SEARCH_TIMEOUTT_CACHE);
} }
}
} else { } else {
result = this.dao.getList(query, pageInfo); result = this.dao.getList(query, pageInfo);
this.findAfter(entity, pageInfo, context, result.getList()); this.findAfter(entity, pageInfo, context, result.getList());
...@@ -125,11 +134,9 @@ public class WindowBusinessServiceImpl extends AbstractCRUDServiceImpl<WindowBus ...@@ -125,11 +134,9 @@ public class WindowBusinessServiceImpl extends AbstractCRUDServiceImpl<WindowBus
@Override @Override
protected void findAfter(WindowBusinessEntity entity, PageInfo pageInfo, Context context, List<WindowBusinessEntity> list) throws AppException { protected void findAfter(WindowBusinessEntity entity, PageInfo pageInfo, Context context, List<WindowBusinessEntity> list) throws AppException {
Map<Long, WindowEntity> collect = windowService.getCacheList().stream().collect(Collectors.toMap(x -> x.getId(), y -> y, (o, n) -> n)); Map<Long, WindowEntity> collect = windowService.getCacheList().stream().collect(Collectors.toMap(x -> x.getId(), y -> y, (o, n) -> n));
//Map<Long, WindowEntity> collect = windowService.findToMap(new WindowQuery(), context); //Map<Long, WindowEntity> collect = windowService.findToMap(new WindowQuery(), context);
Map<Long, WindowHallEntity> windowHallEntityMap = windowHallService.getCacheList().stream().collect(Collectors.toMap(x -> x.getId(), y -> y, (o, n) -> n)); Map<Long, WindowHallEntity> windowHallEntityMap = windowHallService.getCacheList().stream().collect(Collectors.toMap(x -> x.getId(), y -> y, (o, n) -> n));
//Map<Long, WindowHallEntity> windowHallEntityMap = windowHallService.find(new WindowHallQuery(), context).parallelStream().collect(Collectors.toMap(x -> x.getWindowId(), Function.identity())); //Map<Long, WindowHallEntity> windowHallEntityMap = windowHallService.find(new WindowHallQuery(), context).parallelStream().collect(Collectors.toMap(x -> x.getWindowId(), Function.identity()));
Iterator iterator = list.iterator(); Iterator iterator = list.iterator();
while (iterator.hasNext()) { while (iterator.hasNext()) {
......
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