Commit 2e43830c by stylefeng

优化代码

parent 1f484cfb
package com.stylefeng.guns.common.annotion; package com.stylefeng.guns.common.annotion;
import java.lang.annotation.ElementType; import java.lang.annotation.*;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/** /**
* 权限注解 用于检查权限 规定访问权限 * 权限注解 用于检查权限 规定访问权限
* *
* @example @Permission({roleID1,roleID2}) * @example @Permission({role1,role2})
* @example @Permission * @example @Permission
*/ */
@Inherited @Inherited
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD}) @Target({ElementType.METHOD})
public @interface Permission { public @interface Permission {
/**
* <p>角色英文名称</p>
* <p>使用注解时加上这个值表示限制只有某个角色的才可以访问对应的资源</p>
* <p>常用在某些资源限制只有超级管理员角色才可访问</p>
*/
String[] value() default {}; String[] value() default {};
} }
package com.stylefeng.guns.common.constant.cache; package com.stylefeng.guns.common.constant.cache;
/** /**
* 缓存的key集合 * 缓存标识前缀集合,常用在ConstantFactory类中
* *
* @author fengshuonan * @author fengshuonan
* @date 2017-04-25 9:37 * @date 2017-04-25 9:37
...@@ -9,15 +9,23 @@ package com.stylefeng.guns.common.constant.cache; ...@@ -9,15 +9,23 @@ package com.stylefeng.guns.common.constant.cache;
public interface CacheKey { public interface CacheKey {
/** /**
* ConstantFactory中的缓存 * 角色名称(多个)
*/ */
String ROLES_NAME = "roles_name_"; String ROLES_NAME = "roles_name_";
/**
* 角色名称(单个)
*/
String SINGLE_ROLE_NAME = "single_role_name_"; String SINGLE_ROLE_NAME = "single_role_name_";
/**
* 角色英文名称
*/
String SINGLE_ROLE_TIP = "single_role_tip_"; String SINGLE_ROLE_TIP = "single_role_tip_";
/**
* 部门名称
*/
String DEPT_NAME = "dept_name_"; String DEPT_NAME = "dept_name_";
} }
...@@ -8,24 +8,22 @@ import com.stylefeng.guns.core.exception.GunsException; ...@@ -8,24 +8,22 @@ import com.stylefeng.guns.core.exception.GunsException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
/** /**
* 字段的包装创建工厂 * 字典字段的包装器(从ConstantFactory中获取包装值)
* *
* @author fengshuonan * @author fengshuonan
* @date 2017-05-06 15:12 * @date 2017-05-06 15:12
*/ */
public class DictFieldWarpperFactory { public class DictFieldWarpperFactory {
public static Object createFieldWarpper(Object field, String methodName) { public static Object createFieldWarpper(Object parameter, String methodName) {
IConstantFactory me = ConstantFactory.me(); IConstantFactory constantFactory = ConstantFactory.me();
try { try {
Method method = IConstantFactory.class.getMethod(methodName, field.getClass()); Method method = IConstantFactory.class.getMethod(methodName, parameter.getClass());
Object result = method.invoke(me, field); return method.invoke(constantFactory, parameter);
return result;
} catch (Exception e) { } catch (Exception e) {
try { try {
Method method = IConstantFactory.class.getMethod(methodName, Integer.class); Method method = IConstantFactory.class.getMethod(methodName, Integer.class);
Object result = method.invoke(me, Integer.parseInt(field.toString())); return method.invoke(constantFactory, Integer.parseInt(parameter.toString()));
return result;
} catch (Exception e1) { } catch (Exception e1) {
throw new GunsException(BizExceptionEnum.ERROR_WRAPPER_FIELD); throw new GunsException(BizExceptionEnum.ERROR_WRAPPER_FIELD);
} }
......
...@@ -16,7 +16,6 @@ public enum BizExceptionEnum implements ServiceExceptionEnum{ ...@@ -16,7 +16,6 @@ public enum BizExceptionEnum implements ServiceExceptionEnum{
ERROR_CREATE_DICT(500,"创建字典失败"), ERROR_CREATE_DICT(500,"创建字典失败"),
ERROR_WRAPPER_FIELD(500,"包装字典属性失败"), ERROR_WRAPPER_FIELD(500,"包装字典属性失败"),
/** /**
* 文件上传 * 文件上传
*/ */
......
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