Commit ea1a9ddd by naan1993

解决cache不能用的bug

parent a2163795
package com.stylefeng.guns.common.constant.dictmap.factory; package com.stylefeng.guns.common.constant.dictmap.factory;
import com.stylefeng.guns.common.constant.factory.ConstantFactory; import com.stylefeng.guns.common.constant.factory.ConstantFactory;
import com.stylefeng.guns.common.constant.factory.IConstantFactory;
import com.stylefeng.guns.common.exception.BizExceptionEnum; import com.stylefeng.guns.common.exception.BizExceptionEnum;
import com.stylefeng.guns.common.exception.BussinessException; import com.stylefeng.guns.common.exception.BussinessException;
...@@ -15,14 +16,14 @@ import java.lang.reflect.Method; ...@@ -15,14 +16,14 @@ import java.lang.reflect.Method;
public class DictFieldWarpperFactory { public class DictFieldWarpperFactory {
public static Object createFieldWarpper(Object field, String methodName) { public static Object createFieldWarpper(Object field, String methodName) {
ConstantFactory me = ConstantFactory.me(); IConstantFactory me = ConstantFactory.me();
try { try {
Method method = ConstantFactory.class.getMethod(methodName, field.getClass()); Method method = IConstantFactory.class.getMethod(methodName, field.getClass());
Object result = method.invoke(me, field); Object result = method.invoke(me, field);
return result; return result;
} catch (Exception e) { } catch (Exception e) {
try { try {
Method method = ConstantFactory.class.getMethod(methodName, Integer.class); Method method = IConstantFactory.class.getMethod(methodName, Integer.class);
Object result = method.invoke(me, Integer.parseInt(field.toString())); Object result = method.invoke(me, Integer.parseInt(field.toString()));
return result; return result;
} catch (Exception e1) { } catch (Exception e1) {
......
package com.stylefeng.guns.common.constant.factory; package com.stylefeng.guns.common.constant.factory;
import com.baomidou.mybatisplus.mapper.EntityWrapper; import com.baomidou.mybatisplus.mapper.EntityWrapper;
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.constant.state.Sex; import com.stylefeng.guns.common.constant.state.Sex;
...@@ -13,7 +11,6 @@ import com.stylefeng.guns.core.support.StrKit; ...@@ -13,7 +11,6 @@ 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;
...@@ -27,7 +24,7 @@ import java.util.List; ...@@ -27,7 +24,7 @@ import java.util.List;
*/ */
@Component @Component
@DependsOn("springContextHolder") @DependsOn("springContextHolder")
public class ConstantFactory { public class ConstantFactory implements IConstantFactory {
private RoleMapper roleMapper = SpringContextHolder.getBean(RoleMapper.class); private RoleMapper roleMapper = SpringContextHolder.getBean(RoleMapper.class);
private DeptMapper deptMapper = SpringContextHolder.getBean(DeptMapper.class); private DeptMapper deptMapper = SpringContextHolder.getBean(DeptMapper.class);
...@@ -36,7 +33,7 @@ public class ConstantFactory { ...@@ -36,7 +33,7 @@ public class ConstantFactory {
private MenuMapper menuMapper = SpringContextHolder.getBean(MenuMapper.class); private MenuMapper menuMapper = SpringContextHolder.getBean(MenuMapper.class);
private NoticeMapper noticeMapper = SpringContextHolder.getBean(NoticeMapper.class); private NoticeMapper noticeMapper = SpringContextHolder.getBean(NoticeMapper.class);
public static ConstantFactory me() { public static IConstantFactory me() {
return SpringContextHolder.getBean("constantFactory"); return SpringContextHolder.getBean("constantFactory");
} }
...@@ -46,6 +43,7 @@ public class ConstantFactory { ...@@ -46,6 +43,7 @@ public class ConstantFactory {
* @author stylefeng * @author stylefeng
* @Date 2017/5/9 23:41 * @Date 2017/5/9 23:41
*/ */
@Override
public String getUserNameById(Integer userId) { public String getUserNameById(Integer userId) {
User user = userMapper.selectById(userId); User user = userMapper.selectById(userId);
if (user != null) { if (user != null) {
...@@ -61,6 +59,7 @@ public class ConstantFactory { ...@@ -61,6 +59,7 @@ public class ConstantFactory {
* @author stylefeng * @author stylefeng
* @date 2017年5月16日21:55:371 * @date 2017年5月16日21:55:371
*/ */
@Override
public String getUserAccountById(Integer userId) { public String getUserAccountById(Integer userId) {
User user = userMapper.selectById(userId); User user = userMapper.selectById(userId);
if (user != null) { if (user != null) {
...@@ -73,7 +72,7 @@ public class ConstantFactory { ...@@ -73,7 +72,7 @@ public class ConstantFactory {
/** /**
* 通过角色ids获取角色名称 * 通过角色ids获取角色名称
*/ */
@Cacheable(value = Cache.CONSTANT, key = "'" + CacheKey.ROLES_NAME + "'+#roleIds") @Override
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();
...@@ -89,7 +88,7 @@ public class ConstantFactory { ...@@ -89,7 +88,7 @@ public class ConstantFactory {
/** /**
* 通过角色id获取角色名称 * 通过角色id获取角色名称
*/ */
@Cacheable(value = Cache.CONSTANT, key = "'" + CacheKey.SINGLE_ROLE_NAME + "'+#roleId") @Override
public String getSingleRoleName(Integer roleId) { public String getSingleRoleName(Integer roleId) {
if (0 == roleId) { if (0 == roleId) {
return "--"; return "--";
...@@ -104,7 +103,7 @@ public class ConstantFactory { ...@@ -104,7 +103,7 @@ public class ConstantFactory {
/** /**
* 通过角色id获取角色英文名称 * 通过角色id获取角色英文名称
*/ */
@Cacheable(value = Cache.CONSTANT, key = "'" + CacheKey.SINGLE_ROLE_TIP + "'+#roleId") @Override
public String getSingleRoleTip(Integer roleId) { public String getSingleRoleTip(Integer roleId) {
if (0 == roleId) { if (0 == roleId) {
return "--"; return "--";
...@@ -119,7 +118,7 @@ public class ConstantFactory { ...@@ -119,7 +118,7 @@ public class ConstantFactory {
/** /**
* 获取部门名称 * 获取部门名称
*/ */
@Cacheable(value = Cache.CONSTANT, key = "'" + CacheKey.DEPT_NAME + "'+#deptId") @Override
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())) {
...@@ -131,6 +130,7 @@ public class ConstantFactory { ...@@ -131,6 +130,7 @@ public class ConstantFactory {
/** /**
* 获取菜单的名称们(多个) * 获取菜单的名称们(多个)
*/ */
@Override
public String getMenuNames(String menuIds) { public String getMenuNames(String menuIds) {
Integer[] menus = Convert.toIntArray(menuIds); Integer[] menus = Convert.toIntArray(menuIds);
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
...@@ -146,6 +146,7 @@ public class ConstantFactory { ...@@ -146,6 +146,7 @@ public class ConstantFactory {
/** /**
* 获取菜单名称 * 获取菜单名称
*/ */
@Override
public String getMenuName(Integer menuId) { public String getMenuName(Integer menuId) {
if (ToolUtil.isEmpty(menuId)) { if (ToolUtil.isEmpty(menuId)) {
return ""; return "";
...@@ -162,6 +163,7 @@ public class ConstantFactory { ...@@ -162,6 +163,7 @@ public class ConstantFactory {
/** /**
* 获取菜单名称通过编号 * 获取菜单名称通过编号
*/ */
@Override
public String getMenuNameByCode(String code) { public String getMenuNameByCode(String code) {
if (ToolUtil.isEmpty(code)) { if (ToolUtil.isEmpty(code)) {
return ""; return "";
...@@ -180,7 +182,8 @@ public class ConstantFactory { ...@@ -180,7 +182,8 @@ public class ConstantFactory {
/** /**
* 获取字典名称 * 获取字典名称
*/ */
public String getDictName(Integer dictId){ @Override
public String getDictName(Integer dictId) {
if (ToolUtil.isEmpty(dictId)) { if (ToolUtil.isEmpty(dictId)) {
return ""; return "";
} else { } else {
...@@ -196,7 +199,8 @@ public class ConstantFactory { ...@@ -196,7 +199,8 @@ public class ConstantFactory {
/** /**
* 获取通知标题 * 获取通知标题
*/ */
public String getNoticeTitle(Integer dictId){ @Override
public String getNoticeTitle(Integer dictId) {
if (ToolUtil.isEmpty(dictId)) { if (ToolUtil.isEmpty(dictId)) {
return ""; return "";
} else { } else {
...@@ -212,6 +216,7 @@ public class ConstantFactory { ...@@ -212,6 +216,7 @@ public class ConstantFactory {
/** /**
* 获取性别名称 * 获取性别名称
*/ */
@Override
public String getSexName(Integer sex) { public String getSexName(Integer sex) {
return Sex.valueOf(sex); return Sex.valueOf(sex);
} }
...@@ -219,6 +224,7 @@ public class ConstantFactory { ...@@ -219,6 +224,7 @@ public class ConstantFactory {
/** /**
* 获取用户登录状态 * 获取用户登录状态
*/ */
@Override
public String getStatusName(Integer status) { public String getStatusName(Integer status) {
return ManagerStatus.valueOf(status); return ManagerStatus.valueOf(status);
} }
...@@ -226,6 +232,7 @@ public class ConstantFactory { ...@@ -226,6 +232,7 @@ public class ConstantFactory {
/** /**
* 获取菜单状态 * 获取菜单状态
*/ */
@Override
public String getMenuStatusName(Integer status) { public String getMenuStatusName(Integer status) {
return MenuStatus.valueOf(status); return MenuStatus.valueOf(status);
} }
...@@ -233,6 +240,7 @@ public class ConstantFactory { ...@@ -233,6 +240,7 @@ public class ConstantFactory {
/** /**
* 查询字典 * 查询字典
*/ */
@Override
public List<Dict> findInDict(Integer id) { public List<Dict> findInDict(Integer id) {
if (ToolUtil.isEmpty(id)) { if (ToolUtil.isEmpty(id)) {
return null; return null;
...@@ -250,6 +258,7 @@ public class ConstantFactory { ...@@ -250,6 +258,7 @@ public class ConstantFactory {
/** /**
* 获取被缓存的对象(用户删除业务) * 获取被缓存的对象(用户删除业务)
*/ */
@Override
public String getCacheObject(String para) { public String getCacheObject(String para) {
return LogObjectHolder.me().get().toString(); return LogObjectHolder.me().get().toString();
} }
......
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 org.springframework.cache.annotation.Cacheable;
import java.util.List;
/**
* 常量生产工厂的接口
*
* @author fengshuonan
* @date 2017-06-14 21:12
*/
public interface IConstantFactory {
/**
* 根据用户id获取用户名称
*
* @author stylefeng
* @Date 2017/5/9 23:41
*/
String getUserNameById(Integer userId);
/**
* 根据用户id获取用户账号
*
* @author stylefeng
* @date 2017年5月16日21:55:371
*/
String getUserAccountById(Integer userId);
/**
* 通过角色ids获取角色名称
*/
@Cacheable(value = Cache.CONSTANT, key = "'" + CacheKey.ROLES_NAME + "'+#roleIds")
String getRoleName(String roleIds);
/**
* 通过角色id获取角色名称
*/
@Cacheable(value = Cache.CONSTANT, key = "'" + CacheKey.SINGLE_ROLE_NAME + "'+#roleId")
String getSingleRoleName(Integer roleId);
/**
* 通过角色id获取角色英文名称
*/
@Cacheable(value = Cache.CONSTANT, key = "'" + CacheKey.SINGLE_ROLE_TIP + "'+#roleId")
String getSingleRoleTip(Integer roleId);
/**
* 获取部门名称
*/
@Cacheable(value = Cache.CONSTANT, key = "'" + CacheKey.DEPT_NAME + "'+#deptId")
String getDeptName(Integer deptId);
/**
* 获取菜单的名称们(多个)
*/
String getMenuNames(String menuIds);
/**
* 获取菜单名称
*/
String getMenuName(Integer menuId);
/**
* 获取菜单名称通过编号
*/
String getMenuNameByCode(String code);
/**
* 获取字典名称
*/
String getDictName(Integer dictId);
/**
* 获取通知标题
*/
String getNoticeTitle(Integer dictId);
/**
* 获取性别名称
*/
String getSexName(Integer sex);
/**
* 获取用户登录状态
*/
String getStatusName(Integer status);
/**
* 获取菜单状态
*/
String getMenuStatusName(Integer status);
/**
* 查询字典
*/
List<Dict> findInDict(Integer id);
/**
* 获取被缓存的对象(用户删除业务)
*/
String getCacheObject(String para);
}
package com.stylefeng.guns.config; package com.stylefeng.guns.config;
import net.sf.ehcache.CacheManager; import net.sf.ehcache.CacheManager;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cache.ehcache.EhCacheCacheManager; import org.springframework.cache.ehcache.EhCacheCacheManager;
import org.springframework.cache.ehcache.EhCacheManagerFactoryBean; import org.springframework.cache.ehcache.EhCacheManagerFactoryBean;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
...@@ -14,6 +15,7 @@ import org.springframework.core.io.ClassPathResource; ...@@ -14,6 +15,7 @@ import org.springframework.core.io.ClassPathResource;
* @date 2017-05-20 23:11 * @date 2017-05-20 23:11
*/ */
@Configuration @Configuration
@EnableCaching
public class EhCacheConfig { public class EhCacheConfig {
/** /**
......
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