Search in sources :

Example 6 with SysPermissionDataRuleModel

use of org.jeecg.common.system.vo.SysPermissionDataRuleModel in project kms by mahonelau.

the class JeecgDataAutorUtils method installDataSearchConditon.

/**
 * 往链接请求里面,传入数据查询条件
 *
 * @param request
 * @param dataRules
 */
public static synchronized void installDataSearchConditon(HttpServletRequest request, List<SysPermissionDataRuleModel> dataRules) {
    @SuppressWarnings("unchecked") List<SysPermissionDataRuleModel> // 1.先从request获取MENU_DATA_AUTHOR_RULES,如果存则获取到LIST
    list = (List<SysPermissionDataRuleModel>) loadDataSearchConditon();
    if (list == null) {
        // 2.如果不存在,则new一个list
        list = new ArrayList<SysPermissionDataRuleModel>();
    }
    for (SysPermissionDataRuleModel tsDataRule : dataRules) {
        list.add(tsDataRule);
    }
    // 3.往list里面增量存指
    request.setAttribute(MENU_DATA_AUTHOR_RULES, list);
}
Also used : SysPermissionDataRuleModel(org.jeecg.common.system.vo.SysPermissionDataRuleModel) List(java.util.List) ArrayList(java.util.ArrayList)

Example 7 with SysPermissionDataRuleModel

use of org.jeecg.common.system.vo.SysPermissionDataRuleModel in project kykms by mahonelau.

the class QueryGenerator method getRuleMap.

/**
 * 获取请求对应的数据权限规则
 * @return
 */
public static Map<String, SysPermissionDataRuleModel> getRuleMap() {
    Map<String, SysPermissionDataRuleModel> ruleMap = new HashMap<String, SysPermissionDataRuleModel>();
    List<SysPermissionDataRuleModel> list = JeecgDataAutorUtils.loadDataSearchConditon();
    if (list != null && list.size() > 0) {
        if (list.get(0) == null) {
            return ruleMap;
        }
        for (SysPermissionDataRuleModel rule : list) {
            String column = rule.getRuleColumn();
            if (QueryRuleEnum.SQL_RULES.getValue().equals(rule.getRuleConditions())) {
                column = SQL_RULES_COLUMN + rule.getId();
            }
            ruleMap.put(column, rule);
        }
    }
    return ruleMap;
}
Also used : SysPermissionDataRuleModel(org.jeecg.common.system.vo.SysPermissionDataRuleModel)

Example 8 with SysPermissionDataRuleModel

use of org.jeecg.common.system.vo.SysPermissionDataRuleModel in project kykms by mahonelau.

the class QueryGenerator method installAuthJdbc.

/**
 *   根据权限相关配置生成相关的SQL 语句
 * @param clazz
 * @return
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
public static String installAuthJdbc(Class<?> clazz) {
    StringBuffer sb = new StringBuffer();
    // 权限查询
    Map<String, SysPermissionDataRuleModel> ruleMap = getRuleMap();
    PropertyDescriptor[] origDescriptors = PropertyUtils.getPropertyDescriptors(clazz);
    String sql_and = " and ";
    for (String c : ruleMap.keySet()) {
        if (oConvertUtils.isNotEmpty(c) && c.startsWith(SQL_RULES_COLUMN)) {
            sb.append(sql_and + getSqlRuleValue(ruleMap.get(c).getRuleValue()));
        }
    }
    String name, column;
    for (int i = 0; i < origDescriptors.length; i++) {
        name = origDescriptors[i].getName();
        if (judgedIsUselessField(name)) {
            continue;
        }
        if (ruleMap.containsKey(name)) {
            column = getTableFieldName(clazz, name);
            if (column == null) {
                continue;
            }
            SysPermissionDataRuleModel dataRule = ruleMap.get(name);
            QueryRuleEnum rule = QueryRuleEnum.getByValue(dataRule.getRuleConditions());
            Class propType = origDescriptors[i].getPropertyType();
            boolean isString = propType.equals(String.class);
            Object value;
            if (isString) {
                value = converRuleValue(dataRule.getRuleValue());
            } else {
                value = NumberUtils.parseNumber(dataRule.getRuleValue(), propType);
            }
            String filedSql = getSingleSqlByRule(rule, oConvertUtils.camelToUnderline(column), value, isString);
            sb.append(sql_and + filedSql);
        }
    }
    log.debug("query auth sql is:" + sb.toString());
    return sb.toString();
}
Also used : SysPermissionDataRuleModel(org.jeecg.common.system.vo.SysPermissionDataRuleModel) PropertyDescriptor(java.beans.PropertyDescriptor)

Example 9 with SysPermissionDataRuleModel

use of org.jeecg.common.system.vo.SysPermissionDataRuleModel in project kykms by mahonelau.

the class QueryGenerator method getRuleMap.

/**
 * 获取请求对应的数据权限规则
 * @return
 */
public static Map<String, SysPermissionDataRuleModel> getRuleMap(List<SysPermissionDataRuleModel> list) {
    Map<String, SysPermissionDataRuleModel> ruleMap = new HashMap<String, SysPermissionDataRuleModel>();
    if (list == null) {
        list = JeecgDataAutorUtils.loadDataSearchConditon();
    }
    if (list != null && list.size() > 0) {
        if (list.get(0) == null) {
            return ruleMap;
        }
        for (SysPermissionDataRuleModel rule : list) {
            String column = rule.getRuleColumn();
            if (QueryRuleEnum.SQL_RULES.getValue().equals(rule.getRuleConditions())) {
                column = SQL_RULES_COLUMN + rule.getId();
            }
            ruleMap.put(column, rule);
        }
    }
    return ruleMap;
}
Also used : SysPermissionDataRuleModel(org.jeecg.common.system.vo.SysPermissionDataRuleModel)

Example 10 with SysPermissionDataRuleModel

use of org.jeecg.common.system.vo.SysPermissionDataRuleModel in project kms by mahonelau.

the class QueryGenerator method installAuthJdbc.

/**
 *   根据权限相关配置生成相关的SQL 语句
 * @param clazz
 * @return
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
public static String installAuthJdbc(Class<?> clazz) {
    StringBuffer sb = new StringBuffer();
    // 权限查询
    Map<String, SysPermissionDataRuleModel> ruleMap = getRuleMap();
    PropertyDescriptor[] origDescriptors = PropertyUtils.getPropertyDescriptors(clazz);
    String sql_and = " and ";
    for (String c : ruleMap.keySet()) {
        if (oConvertUtils.isNotEmpty(c) && c.startsWith(SQL_RULES_COLUMN)) {
            sb.append(sql_and + getSqlRuleValue(ruleMap.get(c).getRuleValue()));
        }
    }
    String name, column;
    for (int i = 0; i < origDescriptors.length; i++) {
        name = origDescriptors[i].getName();
        if (judgedIsUselessField(name)) {
            continue;
        }
        if (ruleMap.containsKey(name)) {
            column = getTableFieldName(clazz, name);
            if (column == null) {
                continue;
            }
            SysPermissionDataRuleModel dataRule = ruleMap.get(name);
            QueryRuleEnum rule = QueryRuleEnum.getByValue(dataRule.getRuleConditions());
            Class propType = origDescriptors[i].getPropertyType();
            boolean isString = propType.equals(String.class);
            Object value;
            if (isString) {
                value = converRuleValue(dataRule.getRuleValue());
            } else {
                value = NumberUtils.parseNumber(dataRule.getRuleValue(), propType);
            }
            String filedSql = getSingleSqlByRule(rule, oConvertUtils.camelToUnderline(column), value, isString);
            sb.append(sql_and + filedSql);
        }
    }
    log.debug("query auth sql is:" + sb.toString());
    return sb.toString();
}
Also used : SysPermissionDataRuleModel(org.jeecg.common.system.vo.SysPermissionDataRuleModel) PropertyDescriptor(java.beans.PropertyDescriptor)

Aggregations

SysPermissionDataRuleModel (org.jeecg.common.system.vo.SysPermissionDataRuleModel)17 PropertyDescriptor (java.beans.PropertyDescriptor)3 Method (java.lang.reflect.Method)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 Around (org.aspectj.lang.annotation.Around)3 MethodSignature (org.aspectj.lang.reflect.MethodSignature)3 PermissionData (org.jeecg.common.aspect.annotation.PermissionData)3 SysUserCacheInfo (org.jeecg.common.system.vo.SysUserCacheInfo)3