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

添加查询缓存

parent 666748b4
...@@ -12,4 +12,24 @@ public class RedisKey { ...@@ -12,4 +12,24 @@ public class RedisKey {
public static final String KEY_USER_MENU_CACHE = "user:menu"; public static final String KEY_USER_MENU_CACHE = "user:menu";
/**
* 站点业务id缓存
*/
public static final String KEY_SEARCH_SITEBUSINESSID_CACHE = "base:search:sitebusinessid:";
/**
* 窗口id缓存
*/
public static final String KEY_SEARCH_WINDOWID_CACHE = "base:search:windowId:";
/**
* 窗口id列表缓存
*/
public static final String KEY_SEARCH_WINDOWID_LIST_CACHE = "base:search:windowId:list:";
/**
* 缓存过期时间(秒)
*/
public static final Long KEY_SEARCH_TIMEOUTT_CACHE = 3600L;
} }
...@@ -54,5 +54,10 @@ public class WindowBusinessVo extends BaseEntityLong { ...@@ -54,5 +54,10 @@ public class WindowBusinessVo extends BaseEntityLong {
@JSONField(serialize = true) @JSONField(serialize = true)
private String hallName; private String hallName;
/**
* 查询缓存是否开启
*/
private Integer searchCache;
} }
\ No newline at end of file
...@@ -2,12 +2,16 @@ package com.mortals.xhx.module.window.service.impl; ...@@ -2,12 +2,16 @@ package com.mortals.xhx.module.window.service.impl;
import cn.hutool.core.collection.ListUtil; import cn.hutool.core.collection.ListUtil;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.alibaba.fastjson.serializer.SerializerFeature; import com.alibaba.fastjson.serializer.SerializerFeature;
import com.mortals.framework.ap.GlobalSysInfo; import com.mortals.framework.ap.GlobalSysInfo;
import com.mortals.framework.exception.AppException; import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.Context; import com.mortals.framework.model.Context;
import com.mortals.framework.model.PageInfo; import com.mortals.framework.model.PageInfo;
import com.mortals.framework.model.Result;
import com.mortals.framework.service.ICacheService;
import com.mortals.framework.util.HttpUtil; import com.mortals.framework.util.HttpUtil;
import com.mortals.xhx.common.code.YesNoEnum;
import com.mortals.xhx.common.utils.BeanUtil; import com.mortals.xhx.common.utils.BeanUtil;
import com.mortals.xhx.module.business.model.BusinessEntity; import com.mortals.xhx.module.business.model.BusinessEntity;
import com.mortals.xhx.module.business.model.BusinessQuery; import com.mortals.xhx.module.business.model.BusinessQuery;
...@@ -18,6 +22,7 @@ import com.mortals.xhx.module.window.model.*; ...@@ -18,6 +22,7 @@ import com.mortals.xhx.module.window.model.*;
import com.mortals.xhx.module.window.service.WindowHallService; import com.mortals.xhx.module.window.service.WindowHallService;
import com.mortals.xhx.module.window.service.WindowService; import com.mortals.xhx.module.window.service.WindowService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.formula.functions.T;
import org.checkerframework.checker.units.qual.A; import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -33,6 +38,8 @@ import java.util.stream.Collectors; ...@@ -33,6 +38,8 @@ 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.KEY_SEARCH_TIMEOUTT_CACHE;
/** /**
* WindowBusinessService * WindowBusinessService
...@@ -48,7 +55,57 @@ public class WindowBusinessServiceImpl extends AbstractCRUDServiceImpl<WindowBus ...@@ -48,7 +55,57 @@ public class WindowBusinessServiceImpl extends AbstractCRUDServiceImpl<WindowBus
private WindowService windowService; private WindowService windowService;
@Autowired @Autowired
private WindowHallService windowHallService; private WindowHallService windowHallService;
@Autowired
private ICacheService cacheService;
/**
* @param entity
* @param pageInfo
* @param context
* @return
* @throws AppException
*/
@Override
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() == YesNoEnum.YES.getValue())) {
//根据查询条件 获取缓存,如果缓存有则直接取缓存,否则读数据库后 再写入缓存
if (ObjectUtils.isEmpty(query.getSiteBusinessId())) {
Long siteBusinessId = query.getSiteBusinessId();
String cacheResult = cacheService.get(KEY_SEARCH_SITEBUSINESSID_CACHE + siteBusinessId, String.class);
if (!ObjectUtils.isEmpty(cacheResult)) {
Result<WindowBusinessEntity> result = JSON.parseObject(cacheResult, new TypeReference<Result<WindowBusinessEntity>>() {
});
return result;
} else {
//查询数据库
Result<WindowBusinessEntity> 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);
return result;
}
} else if (ObjectUtils.isEmpty(query.getWindowId())) {
//todo
return null;
} else if (ObjectUtils.isEmpty(query.getWindowIdList())) {
//todo
return null;
} else {
Result<WindowBusinessEntity> result = this.dao.getList(query, pageInfo);
this.findAfter(entity, pageInfo, context, result.getList());
return result;
}
} else {
Result<WindowBusinessEntity> result = this.dao.getList(query, pageInfo);
this.findAfter(entity, pageInfo, context, result.getList());
return result;
}
}
@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 {
......
...@@ -3,6 +3,8 @@ package com.mortals.xhx.module.window.web; ...@@ -3,6 +3,8 @@ package com.mortals.xhx.module.window.web;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.mortals.framework.annotation.UnAuth; import com.mortals.framework.annotation.UnAuth;
import com.mortals.framework.common.Rest; import com.mortals.framework.common.Rest;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.Context;
import com.mortals.framework.util.DataUtil; import com.mortals.framework.util.DataUtil;
import com.mortals.framework.web.BaseCRUDJsonBodyMappingController; import com.mortals.framework.web.BaseCRUDJsonBodyMappingController;
import com.mortals.framework.web.BasePhpCRUDJsonMappingController; import com.mortals.framework.web.BasePhpCRUDJsonMappingController;
...@@ -32,7 +34,6 @@ public class WindowBusinessController extends BaseCRUDJsonBodyMappingController< ...@@ -32,7 +34,6 @@ public class WindowBusinessController extends BaseCRUDJsonBodyMappingController<
private ParamService paramService; private ParamService paramService;
public WindowBusinessController() { public WindowBusinessController() {
super.setFormClass(WindowBusinessForm.class);
super.setModuleDesc("窗口业务"); super.setModuleDesc("窗口业务");
} }
......
package com.mortals.xhx.module.window.web;
import com.mortals.framework.web.BaseCRUDFormLong;
import com.mortals.xhx.module.window.model.WindowBusinessEntity;
import com.mortals.xhx.module.window.model.WindowBusinessQuery;
/**
* WindowBusiness
*
* 窗口业务 Form
*
* @author zxfei
* @date 2022-01-12
*/
public class WindowBusinessForm extends BaseCRUDFormLong<WindowBusinessEntity> {
private WindowBusinessEntity entity = new WindowBusinessEntity();
private WindowBusinessQuery query = new WindowBusinessQuery();
public WindowBusinessForm(){
}
@Override
public WindowBusinessEntity getEntity() {
return entity;
}
public void setWindowBusiness(WindowBusinessEntity entity) {
this.entity = entity;
}
@Override
public WindowBusinessQuery getQuery() {
return query;
}
public void setQuery(WindowBusinessQuery query) {
this.query = query;
}
}
\ No newline at end of file
...@@ -57,7 +57,6 @@ public class WindowController extends BaseCRUDJsonBodyMappingController<WindowSe ...@@ -57,7 +57,6 @@ public class WindowController extends BaseCRUDJsonBodyMappingController<WindowSe
public WindowController() { public WindowController() {
super.setFormClass(WindowForm.class);
super.setModuleDesc("站点部门窗口"); super.setModuleDesc("站点部门窗口");
} }
......
package com.mortals.xhx.module.window.web;
import com.mortals.framework.web.BaseCRUDFormLong;
import com.mortals.xhx.module.window.model.WindowEntity;
import com.mortals.xhx.module.window.model.WindowQuery;
/**
* Window
*
* 站点部门窗口 Form
*
* @author zxfei
* @date 2022-01-12
*/
public class WindowForm extends BaseCRUDFormLong<WindowEntity> {
private WindowEntity entity = new WindowEntity();
private WindowQuery query = new WindowQuery();
public WindowForm(){
}
@Override
public WindowEntity getEntity() {
return entity;
}
public void setWindow(WindowEntity entity) {
this.entity = entity;
}
@Override
public WindowQuery getQuery() {
return query;
}
public void setQuery(WindowQuery query) {
this.query = query;
}
}
\ No newline at end of file
...@@ -43,7 +43,6 @@ public class WindowMatterController extends BaseCRUDJsonBodyMappingController<Wi ...@@ -43,7 +43,6 @@ public class WindowMatterController extends BaseCRUDJsonBodyMappingController<Wi
private ParamService paramService; private ParamService paramService;
public WindowMatterController() { public WindowMatterController() {
super.setFormClass(WindowMatterForm.class);
super.setModuleDesc("窗口事项"); super.setModuleDesc("窗口事项");
} }
......
package com.mortals.xhx.module.window.web;
import com.mortals.framework.web.BaseCRUDFormLong;
import com.mortals.xhx.module.window.model.WindowMatterEntity;
import com.mortals.xhx.module.window.model.WindowMatterQuery;
/**
* WindowMatter
*
* 窗口事项 Form
*
* @author zxfei
* @date 2022-01-12
*/
public class WindowMatterForm extends BaseCRUDFormLong<WindowMatterEntity> {
private WindowMatterEntity entity = new WindowMatterEntity();
private WindowMatterQuery query = new WindowMatterQuery();
public WindowMatterForm(){
}
@Override
public WindowMatterEntity getEntity() {
return entity;
}
public void setWindowMatter(WindowMatterEntity entity) {
this.entity = entity;
}
@Override
public WindowMatterQuery getQuery() {
return query;
}
public void setQuery(WindowMatterQuery query) {
this.query = query;
}
}
\ No newline at end of file
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