Commit 4de73800 by stylefeng

修复缓存失效的问题

parent fbbe297b
...@@ -2,6 +2,8 @@ package com.stylefeng.guns.common.constant.factory; ...@@ -2,6 +2,8 @@ package com.stylefeng.guns.common.constant.factory;
import com.baomidou.mybatisplus.mapper.EntityWrapper; import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper; import com.baomidou.mybatisplus.mapper.Wrapper;
import com.stylefeng.guns.common.constant.cache.Cache;
import com.stylefeng.guns.common.constant.cache.CacheKey;
import com.stylefeng.guns.common.constant.state.ManagerStatus; import com.stylefeng.guns.common.constant.state.ManagerStatus;
import com.stylefeng.guns.common.constant.state.MenuStatus; import com.stylefeng.guns.common.constant.state.MenuStatus;
import com.stylefeng.guns.common.persistence.dao.*; import com.stylefeng.guns.common.persistence.dao.*;
...@@ -11,6 +13,7 @@ import com.stylefeng.guns.core.support.StrKit; ...@@ -11,6 +13,7 @@ import com.stylefeng.guns.core.support.StrKit;
import com.stylefeng.guns.core.util.Convert; import com.stylefeng.guns.core.util.Convert;
import com.stylefeng.guns.core.util.SpringContextHolder; import com.stylefeng.guns.core.util.SpringContextHolder;
import com.stylefeng.guns.core.util.ToolUtil; import com.stylefeng.guns.core.util.ToolUtil;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.context.annotation.DependsOn; import org.springframework.context.annotation.DependsOn;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
...@@ -74,6 +77,7 @@ public class ConstantFactory implements IConstantFactory { ...@@ -74,6 +77,7 @@ public class ConstantFactory implements IConstantFactory {
* 通过角色ids获取角色名称 * 通过角色ids获取角色名称
*/ */
@Override @Override
@Cacheable(value = Cache.CONSTANT, key = "'" + CacheKey.ROLES_NAME + "'+#roleIds")
public String getRoleName(String roleIds) { public String getRoleName(String roleIds) {
Integer[] roles = Convert.toIntArray(roleIds); Integer[] roles = Convert.toIntArray(roleIds);
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
...@@ -90,6 +94,7 @@ public class ConstantFactory implements IConstantFactory { ...@@ -90,6 +94,7 @@ public class ConstantFactory implements IConstantFactory {
* 通过角色id获取角色名称 * 通过角色id获取角色名称
*/ */
@Override @Override
@Cacheable(value = Cache.CONSTANT, key = "'" + CacheKey.SINGLE_ROLE_NAME + "'+#roleId")
public String getSingleRoleName(Integer roleId) { public String getSingleRoleName(Integer roleId) {
if (0 == roleId) { if (0 == roleId) {
return "--"; return "--";
...@@ -105,6 +110,7 @@ public class ConstantFactory implements IConstantFactory { ...@@ -105,6 +110,7 @@ public class ConstantFactory implements IConstantFactory {
* 通过角色id获取角色英文名称 * 通过角色id获取角色英文名称
*/ */
@Override @Override
@Cacheable(value = Cache.CONSTANT, key = "'" + CacheKey.SINGLE_ROLE_TIP + "'+#roleId")
public String getSingleRoleTip(Integer roleId) { public String getSingleRoleTip(Integer roleId) {
if (0 == roleId) { if (0 == roleId) {
return "--"; return "--";
...@@ -120,6 +126,7 @@ public class ConstantFactory implements IConstantFactory { ...@@ -120,6 +126,7 @@ public class ConstantFactory implements IConstantFactory {
* 获取部门名称 * 获取部门名称
*/ */
@Override @Override
@Cacheable(value = Cache.CONSTANT, key = "'" + CacheKey.DEPT_NAME + "'+#deptId")
public String getDeptName(Integer deptId) { public String getDeptName(Integer deptId) {
Dept dept = deptMapper.selectById(deptId); Dept dept = deptMapper.selectById(deptId);
if (ToolUtil.isNotEmpty(dept) && ToolUtil.isNotEmpty(dept.getFullname())) { if (ToolUtil.isNotEmpty(dept) && ToolUtil.isNotEmpty(dept.getFullname())) {
......
package com.stylefeng.guns.common.constant.factory; package com.stylefeng.guns.common.constant.factory;
import com.stylefeng.guns.common.constant.cache.Cache;
import com.stylefeng.guns.common.constant.cache.CacheKey;
import com.stylefeng.guns.common.persistence.model.Dict; import com.stylefeng.guns.common.persistence.model.Dict;
import org.springframework.cache.annotation.Cacheable;
import java.util.List; import java.util.List;
...@@ -34,25 +31,21 @@ public interface IConstantFactory { ...@@ -34,25 +31,21 @@ public interface IConstantFactory {
/** /**
* 通过角色ids获取角色名称 * 通过角色ids获取角色名称
*/ */
@Cacheable(value = Cache.CONSTANT, key = "'" + CacheKey.ROLES_NAME + "'+#roleIds")
String getRoleName(String roleIds); String getRoleName(String roleIds);
/** /**
* 通过角色id获取角色名称 * 通过角色id获取角色名称
*/ */
@Cacheable(value = Cache.CONSTANT, key = "'" + CacheKey.SINGLE_ROLE_NAME + "'+#roleId")
String getSingleRoleName(Integer roleId); String getSingleRoleName(Integer roleId);
/** /**
* 通过角色id获取角色英文名称 * 通过角色id获取角色英文名称
*/ */
@Cacheable(value = Cache.CONSTANT, key = "'" + CacheKey.SINGLE_ROLE_TIP + "'+#roleId")
String getSingleRoleTip(Integer roleId); String getSingleRoleTip(Integer roleId);
/** /**
* 获取部门名称 * 获取部门名称
*/ */
@Cacheable(value = Cache.CONSTANT, key = "'" + CacheKey.DEPT_NAME + "'+#deptId")
String getDeptName(Integer deptId); String getDeptName(Integer deptId);
/** /**
......
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