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

添加查询缓存

parent 6839b90a
......@@ -69,7 +69,7 @@ public class WindowBusinessServiceImpl extends AbstractCRUDServiceImpl<WindowBus
public Result<WindowBusinessEntity> find(WindowBusinessEntity entity, PageInfo pageInfo, Context context) throws AppException {
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);
} else {
......@@ -85,12 +85,16 @@ public class WindowBusinessServiceImpl extends AbstractCRUDServiceImpl<WindowBus
Long siteBusinessId = query.getSiteBusinessId();
String cacheResult = cacheService.get(KEY_SEARCH_SITEBUSINESSID_CACHE + siteBusinessId, String.class);
if (!ObjectUtils.isEmpty(cacheResult)) {
result = JSON.parseObject(cacheResult, new TypeReference<Result<WindowBusinessEntity>>() {});
result = JSON.parseObject(cacheResult, new TypeReference<Result<WindowBusinessEntity>>() {
});
} else {
//查询数据库
result = this.dao.getList(query, pageInfo);
this.findAfter(entity, pageInfo, context, result.getList());
cacheService.set(KEY_SEARCH_SITEBUSINESSID_CACHE + siteBusinessId, JSON.toJSONString(result), KEY_SEARCH_TIMEOUTT_CACHE);
if (!ObjectUtils.isEmpty(result.getList())) {
cacheService.set(KEY_SEARCH_SITEBUSINESSID_CACHE + siteBusinessId, JSON.toJSONString(result), KEY_SEARCH_TIMEOUTT_CACHE);
}
}
} else if (!ObjectUtils.isEmpty(query.getWindowId())) {
Long windowId = query.getWindowId();
......@@ -102,7 +106,10 @@ public class WindowBusinessServiceImpl extends AbstractCRUDServiceImpl<WindowBus
//查询数据库
result = this.dao.getList(query, pageInfo);
this.findAfter(entity, pageInfo, context, result.getList());
cacheService.set(KEY_SEARCH_WINDOWID_CACHE + windowId, JSON.toJSONString(result), KEY_SEARCH_TIMEOUTT_CACHE);
//无查询结果的不做保存
if (!ObjectUtils.isEmpty(result.getList())) {
cacheService.set(KEY_SEARCH_WINDOWID_CACHE + windowId, JSON.toJSONString(result), KEY_SEARCH_TIMEOUTT_CACHE);
}
}
} else if (!ObjectUtils.isEmpty(query.getWindowIdList())) {
String windowIdlist = query.getWindowIdList().stream().map(String::valueOf).collect(Collectors.joining("#"));
......@@ -114,7 +121,9 @@ public class WindowBusinessServiceImpl extends AbstractCRUDServiceImpl<WindowBus
//查询数据库
result = this.dao.getList(query, pageInfo);
this.findAfter(entity, pageInfo, context, result.getList());
cacheService.set(KEY_SEARCH_WINDOWID_LIST_CACHE + windowIdlist, JSON.toJSONString(result), KEY_SEARCH_TIMEOUTT_CACHE);
if (!ObjectUtils.isEmpty(result.getList())) {
cacheService.set(KEY_SEARCH_WINDOWID_LIST_CACHE + windowIdlist, JSON.toJSONString(result), KEY_SEARCH_TIMEOUTT_CACHE);
}
}
} else {
result = this.dao.getList(query, pageInfo);
......@@ -125,11 +134,9 @@ public class WindowBusinessServiceImpl extends AbstractCRUDServiceImpl<WindowBus
@Override
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.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.find(new WindowHallQuery(), context).parallelStream().collect(Collectors.toMap(x -> x.getWindowId(), Function.identity()));
Iterator iterator = list.iterator();
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