Commit ea1a9ddd by naan1993

解决cache不能用的bug

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