Commit d03ad9e6 authored by 赵啸非's avatar 赵啸非

添加查询缓存

parent 6b1e125a
...@@ -38,8 +38,7 @@ import java.util.stream.Collectors; ...@@ -38,8 +38,7 @@ import java.util.stream.Collectors;
import static com.mortals.framework.util.HttpUtil.HEADER_CONTENT_TYPE; import static com.mortals.framework.util.HttpUtil.HEADER_CONTENT_TYPE;
import static com.mortals.xhx.common.key.Constant.PARAM_SERVER_PHP_HTTP_URL; import static com.mortals.xhx.common.key.Constant.PARAM_SERVER_PHP_HTTP_URL;
import static com.mortals.xhx.common.key.RedisKey.KEY_SEARCH_SITEBUSINESSID_CACHE; import static com.mortals.xhx.common.key.RedisKey.*;
import static com.mortals.xhx.common.key.RedisKey.KEY_SEARCH_TIMEOUTT_CACHE;
/** /**
* WindowBusinessService * WindowBusinessService
...@@ -68,43 +67,60 @@ public class WindowBusinessServiceImpl extends AbstractCRUDServiceImpl<WindowBus ...@@ -68,43 +67,60 @@ public class WindowBusinessServiceImpl extends AbstractCRUDServiceImpl<WindowBus
*/ */
@Override @Override
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() == YesNoEnum.YES.getValue())) { if (!ObjectUtils.isEmpty(query) && !ObjectUtils.isEmpty(query.getSearchCache() == YesNoEnum.YES.getValue())) {
//根据查询条件 获取缓存,如果缓存有则直接取缓存,否则读数据库后 再写入缓存 //根据查询条件 获取缓存,如果缓存有则直接取缓存,否则读数据库后 再写入缓存
return getWindowBusinessEntityCacheResult(entity, pageInfo, context, query);
} else {
Result<WindowBusinessEntity> result = this.dao.getList(query, pageInfo);
this.findAfter(entity, pageInfo, context, result.getList());
return result;
}
}
private Result<WindowBusinessEntity> getWindowBusinessEntityCacheResult(WindowBusinessEntity entity, PageInfo pageInfo, Context context, WindowBusinessEntity query) {
Result<WindowBusinessEntity> result = null;
if (!ObjectUtils.isEmpty(query.getSiteBusinessId())) { if (!ObjectUtils.isEmpty(query.getSiteBusinessId())) {
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<WindowBusinessEntity> result = JSON.parseObject(cacheResult, new TypeReference<Result<WindowBusinessEntity>>() { result = JSON.parseObject(cacheResult, new TypeReference<Result<WindowBusinessEntity>>() {});
});
return result;
} else { } else {
//查询数据库 //查询数据库
Result<WindowBusinessEntity> 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());
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);
return result;
} }
} else if (!ObjectUtils.isEmpty(query.getWindowId())) { } else if (!ObjectUtils.isEmpty(query.getWindowId())) {
//todo Long windowId = query.getWindowId();
return null; String cacheResult = cacheService.get(KEY_SEARCH_WINDOWID_CACHE + windowId, String.class);
if (!ObjectUtils.isEmpty(cacheResult)) {
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_WINDOWID_CACHE + windowId, JSON.toJSONString(result), KEY_SEARCH_TIMEOUTT_CACHE);
}
} else if (!ObjectUtils.isEmpty(query.getWindowIdList())) { } else if (!ObjectUtils.isEmpty(query.getWindowIdList())) {
//todo String windowIdlist = query.getWindowIdList().stream().map(String::valueOf).collect(Collectors.joining("#"));
return null; String cacheResult = cacheService.get(KEY_SEARCH_WINDOWID_LIST_CACHE + windowIdlist, String.class);
if (!ObjectUtils.isEmpty(cacheResult)) {
result = JSON.parseObject(cacheResult, new TypeReference<Result<WindowBusinessEntity>>() {
});
} else { } else {
Result<WindowBusinessEntity> 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());
return result; cacheService.set(KEY_SEARCH_WINDOWID_LIST_CACHE + windowIdlist, JSON.toJSONString(result), KEY_SEARCH_TIMEOUTT_CACHE);
} }
} else { } else {
Result<WindowBusinessEntity> 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());
return result;
} }
return result;
} }
@Override @Override
......
...@@ -11,7 +11,7 @@ Content-Type: application/json ...@@ -11,7 +11,7 @@ Content-Type: application/json
POST {{baseUrl}}/window/business/interlist POST {{baseUrl}}/window/business/interlist
Content-Type: application/json Content-Type: application/json
{"siteBusinessId":1,"size":-1,"searchCache": 1} {"siteBusinessId":2,"size":-1,"searchCache": 1}
###窗口业务列表缓存2 ###窗口业务列表缓存2
POST {{baseUrl}}/window/business/interlist POST {{baseUrl}}/window/business/interlist
......
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