|
@@ -13,10 +13,8 @@ import cn.hutool.extra.spring.SpringUtil;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.StringPool;
|
|
|
import com.xjrsoft.common.constant.GlobalConstant;
|
|
|
-import com.xjrsoft.common.enums.DataAuthFieldTypeEnum;
|
|
|
-import com.xjrsoft.common.enums.DataAuthMethodEnum;
|
|
|
-import com.xjrsoft.common.enums.DataAuthScopeEnum;
|
|
|
-import com.xjrsoft.common.enums.DataAuthTypeEnum;
|
|
|
+import com.xjrsoft.common.enums.*;
|
|
|
+import com.xjrsoft.common.exception.MyException;
|
|
|
import com.xjrsoft.common.utils.RedisUtil;
|
|
|
import com.xjrsoft.module.authority.entity.DataAuth;
|
|
|
import com.xjrsoft.module.authority.entity.DataAuthConfig;
|
|
@@ -26,12 +24,12 @@ import com.xjrsoft.module.organization.entity.*;
|
|
|
import lombok.SneakyThrows;
|
|
|
import net.sf.jsqlparser.expression.Expression;
|
|
|
import net.sf.jsqlparser.expression.LongValue;
|
|
|
+import net.sf.jsqlparser.expression.Parenthesis;
|
|
|
import net.sf.jsqlparser.expression.StringValue;
|
|
|
+import net.sf.jsqlparser.expression.operators.arithmetic.Modulo;
|
|
|
import net.sf.jsqlparser.expression.operators.conditional.AndExpression;
|
|
|
import net.sf.jsqlparser.expression.operators.conditional.OrExpression;
|
|
|
-import net.sf.jsqlparser.expression.operators.relational.EqualsTo;
|
|
|
-import net.sf.jsqlparser.expression.operators.relational.ExpressionList;
|
|
|
-import net.sf.jsqlparser.expression.operators.relational.InExpression;
|
|
|
+import net.sf.jsqlparser.expression.operators.relational.*;
|
|
|
import net.sf.jsqlparser.parser.CCJSqlParserUtil;
|
|
|
import net.sf.jsqlparser.schema.Column;
|
|
|
|
|
@@ -134,7 +132,7 @@ public class AuthorityUtil {
|
|
|
if (dataAuthExpression == null) {
|
|
|
dataAuthExpression = expression;
|
|
|
} else {
|
|
|
- dataAuthExpression = new OrExpression(dataAuthExpression, expression);
|
|
|
+ dataAuthExpression = new OrExpression(dataAuthExpression, new Parenthesis(expression));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -158,7 +156,7 @@ public class AuthorityUtil {
|
|
|
|
|
|
for (String str : split) {
|
|
|
//如果是数字 并且 包含当前
|
|
|
- if(StrUtil.isNumeric(str)){
|
|
|
+ if (StrUtil.isNumeric(str)) {
|
|
|
Integer order = Convert.toInt(str);
|
|
|
|
|
|
Optional<DataAuthConfig> configOptional = configs.stream().filter(x -> ObjectUtil.equals(x.getOrderNumber(), order)).findFirst();
|
|
@@ -167,8 +165,7 @@ public class AuthorityUtil {
|
|
|
}
|
|
|
Expression expression = getExpression(tableAlias, configOptional.get());
|
|
|
resultExpresionString.append(expression);
|
|
|
- }
|
|
|
- else {
|
|
|
+ } else {
|
|
|
resultExpresionString.append(str);
|
|
|
}
|
|
|
}
|
|
@@ -248,60 +245,52 @@ public class AuthorityUtil {
|
|
|
|
|
|
/**
|
|
|
* 拼接所有的权限表达式
|
|
|
+ *
|
|
|
* @param tableAlias
|
|
|
* @param dataAuthExpression
|
|
|
* @param config
|
|
|
* @return
|
|
|
*/
|
|
|
private static Expression getExpression(String tableAlias, Expression dataAuthExpression, DataAuthConfig config) {
|
|
|
+ Integer conditionType = config.getConditionType();
|
|
|
if (config.getFieldType() == DataAuthFieldTypeEnum.STRING.getCode()) {
|
|
|
- EqualsTo equalsTo = new EqualsTo();
|
|
|
- equalsTo.setLeftExpression(buildColumn(tableAlias, config.getFieldName()));
|
|
|
- equalsTo.setRightExpression(new StringValue(config.getFieldValue()));
|
|
|
-
|
|
|
//如果是第一个条件 直接赋值
|
|
|
if (ObjectUtil.isNull(dataAuthExpression)) {
|
|
|
- dataAuthExpression = equalsTo;
|
|
|
+ dataAuthExpression = getConditionType(conditionType, tableAlias, config.getFieldName(), config.getFieldValue());
|
|
|
} else {
|
|
|
- dataAuthExpression = new AndExpression(dataAuthExpression, equalsTo);
|
|
|
+ dataAuthExpression = new AndExpression(dataAuthExpression, getConditionType(conditionType, tableAlias, config.getFieldName(), config.getFieldValue()));
|
|
|
}
|
|
|
} else if (config.getFieldType() == DataAuthFieldTypeEnum.INT.getCode()) {
|
|
|
- EqualsTo equalsTo = new EqualsTo();
|
|
|
- equalsTo.setLeftExpression(buildColumn(tableAlias, config.getFieldName()));
|
|
|
- equalsTo.setRightExpression(new LongValue(config.getFieldValue()));
|
|
|
//如果是第一个条件 直接赋值
|
|
|
if (ObjectUtil.isNull(dataAuthExpression)) {
|
|
|
- dataAuthExpression = equalsTo;
|
|
|
+ dataAuthExpression = getConditionTypeLong(conditionType, tableAlias, config.getFieldName(), config.getFieldValue());
|
|
|
} else {
|
|
|
- dataAuthExpression = new AndExpression(dataAuthExpression, equalsTo);
|
|
|
+ dataAuthExpression = new AndExpression(dataAuthExpression, getConditionTypeLong(conditionType, tableAlias, config.getFieldName(), config.getFieldValue()));
|
|
|
}
|
|
|
- } else if (config.getFieldType() == DataAuthFieldTypeEnum.LOGIN_USER_ID.getCode()) {
|
|
|
- EqualsTo equalsTo = new EqualsTo();
|
|
|
- equalsTo.setLeftExpression(buildColumn(tableAlias, config.getFieldName()));
|
|
|
- equalsTo.setRightExpression(new LongValue(StpUtil.getLoginIdAsLong()));
|
|
|
+ } else if (config.getFieldType() == DataAuthFieldTypeEnum.LOGIN_USER_ID.getCode()) {//存在包含、不包含几种情况
|
|
|
+ User user = StpUtil.getTokenSession().get(GlobalConstant.LOGIN_USER_INFO_KEY, new User());
|
|
|
//如果是第一个条件 直接赋值
|
|
|
if (ObjectUtil.isNull(dataAuthExpression)) {
|
|
|
- dataAuthExpression = equalsTo;
|
|
|
+ dataAuthExpression = getConditionType(conditionType, tableAlias, config.getFieldName(), user.getId().toString());
|
|
|
} else {
|
|
|
- dataAuthExpression = new AndExpression(dataAuthExpression, equalsTo);
|
|
|
+ dataAuthExpression = new AndExpression(dataAuthExpression, getConditionType(conditionType, tableAlias, config.getFieldName(), user.getId().toString()));
|
|
|
}
|
|
|
- } else if (config.getFieldType() == DataAuthFieldTypeEnum.LOGIN_DEP_ID.getCode()) {
|
|
|
+ } else if (config.getFieldType() == DataAuthFieldTypeEnum.LOGIN_DEP_ID.getCode()) {//只存在包含于,不包含于这两种,其它全部按包含于处理
|
|
|
InExpression inExpression = new InExpression();
|
|
|
- inExpression.setLeftExpression(buildColumn(tableAlias, config.getFieldName()));
|
|
|
List<Department> departmentList = StpUtil.getTokenSession().get(GlobalConstant.LOGIN_USER_DEPT_LIST_KEY, new ArrayList<>(0));
|
|
|
List<Expression> list = new ArrayList<>();
|
|
|
+ inExpression.setLeftExpression(buildColumn(tableAlias, config.getFieldName()));
|
|
|
for (Department department : departmentList) {
|
|
|
- list.add(new LongValue(department.getId()));
|
|
|
+ list.add(new StringValue(department.getId().toString()));
|
|
|
}
|
|
|
-
|
|
|
- inExpression.setRightItemsList(new ExpressionList(list));
|
|
|
- //如果是第一个条件 直接赋值
|
|
|
+ String Message = "该登陆人没有所属部门";
|
|
|
+ inExpression = getConditionTypeList(inExpression,conditionType,list,Message);
|
|
|
if (ObjectUtil.isNull(dataAuthExpression)) {
|
|
|
dataAuthExpression = inExpression;
|
|
|
} else {
|
|
|
dataAuthExpression = new AndExpression(dataAuthExpression, inExpression);
|
|
|
}
|
|
|
- } else if (config.getFieldType() == DataAuthFieldTypeEnum.LOGIN_DEP_CHILD_ID.getCode()) {
|
|
|
+ } else if (config.getFieldType() == DataAuthFieldTypeEnum.LOGIN_DEP_CHILD_ID.getCode()) {//只存在包含于,不包含于这两种,其它全部按包含于处理
|
|
|
InExpression inExpression = new InExpression();
|
|
|
inExpression.setLeftExpression(buildColumn(tableAlias, config.getFieldName()));
|
|
|
List<Department> departmentList = redisUtil.get(GlobalConstant.DEP_CACHE_KEY, new TypeReference<List<Department>>() {
|
|
@@ -313,43 +302,39 @@ public class AuthorityUtil {
|
|
|
myAndOrgAndChildOrgUserId.addAll(currentDepartmentIdList);
|
|
|
List<Expression> list = new ArrayList<>();
|
|
|
for (Long id : myAndOrgAndChildOrgUserId) {
|
|
|
- list.add(new LongValue(id));
|
|
|
+ list.add(new StringValue(id.toString()));
|
|
|
}
|
|
|
-
|
|
|
- inExpression.setRightItemsList(new ExpressionList(list));
|
|
|
- //如果是第一个条件 直接赋值
|
|
|
+ String Message = "该登陆人没有所属部门";
|
|
|
+ inExpression = getConditionTypeList(inExpression,conditionType,list,Message);
|
|
|
if (ObjectUtil.isNull(dataAuthExpression)) {
|
|
|
dataAuthExpression = inExpression;
|
|
|
} else {
|
|
|
dataAuthExpression = new AndExpression(dataAuthExpression, inExpression);
|
|
|
}
|
|
|
} else if (config.getFieldType() == DataAuthFieldTypeEnum.LOGIN_USER_NAME.getCode()) {
|
|
|
- EqualsTo equalsTo = new EqualsTo();
|
|
|
- equalsTo.setLeftExpression(buildColumn(tableAlias, config.getFieldName()));
|
|
|
User user = StpUtil.getTokenSession().get(GlobalConstant.LOGIN_USER_INFO_KEY, new User());
|
|
|
- equalsTo.setRightExpression(new StringValue(user.getUserName()));
|
|
|
//如果是第一个条件 直接赋值
|
|
|
if (ObjectUtil.isNull(dataAuthExpression)) {
|
|
|
- dataAuthExpression = equalsTo;
|
|
|
+ dataAuthExpression = getConditionType(conditionType, tableAlias, config.getFieldName(), user.getUserName());
|
|
|
} else {
|
|
|
- dataAuthExpression = new AndExpression(dataAuthExpression, equalsTo);
|
|
|
+ dataAuthExpression = new AndExpression(dataAuthExpression, getConditionType(conditionType, tableAlias, config.getFieldName(), user.getUserName()));
|
|
|
}
|
|
|
- } else if (config.getFieldType() == DataAuthFieldTypeEnum.LOGIN_POST_ID.getCode()) {
|
|
|
+ } else if (config.getFieldType() == DataAuthFieldTypeEnum.LOGIN_POST_ID.getCode()) {//只存在包含于,不包含于这两种,其它全部按包含于处理
|
|
|
InExpression inExpression = new InExpression();
|
|
|
inExpression.setLeftExpression(buildColumn(tableAlias, config.getFieldName()));
|
|
|
List<Post> postList = StpUtil.getTokenSession().get(GlobalConstant.LOGIN_USER_POST_LIST_KEY, new ArrayList<>());
|
|
|
List<Expression> list = new ArrayList<>();
|
|
|
for (Post post : postList) {
|
|
|
- list.add(new LongValue(post.getId()));
|
|
|
+ list.add(new StringValue(post.getId().toString()));
|
|
|
}
|
|
|
- inExpression.setRightItemsList(new ExpressionList(list));
|
|
|
- //如果是第一个条件 直接赋值
|
|
|
+ String Message = "该登陆人没有所属岗位";
|
|
|
+ inExpression = getConditionTypeList(inExpression,conditionType,list,Message);
|
|
|
if (ObjectUtil.isNull(dataAuthExpression)) {
|
|
|
dataAuthExpression = inExpression;
|
|
|
} else {
|
|
|
dataAuthExpression = new AndExpression(dataAuthExpression, inExpression);
|
|
|
}
|
|
|
- } else {
|
|
|
+ } else {//只存在包含于,不包含于这两种,其它全部按包含于处理
|
|
|
InExpression inExpression = new InExpression();
|
|
|
inExpression.setLeftExpression(buildColumn(tableAlias, config.getFieldName()));
|
|
|
List<Long> roleIdList = StpUtil.getTokenSession().get(GlobalConstant.LOGIN_USER_ROLE_ID_KEY, new ArrayList<>());
|
|
@@ -357,8 +342,8 @@ public class AuthorityUtil {
|
|
|
for (Long id : roleIdList) {
|
|
|
list.add(new LongValue(id));
|
|
|
}
|
|
|
- inExpression.setRightItemsList(new ExpressionList(list));
|
|
|
- //如果是第一个条件 直接赋值
|
|
|
+ String Message = "该登陆人没有所属角色";
|
|
|
+ inExpression = getConditionTypeList(inExpression,conditionType,list,Message);
|
|
|
if (ObjectUtil.isNull(dataAuthExpression)) {
|
|
|
dataAuthExpression = inExpression;
|
|
|
} else {
|
|
@@ -370,37 +355,30 @@ public class AuthorityUtil {
|
|
|
|
|
|
/**
|
|
|
* 只返回一个权限表达式
|
|
|
+ *
|
|
|
* @param tableAlias
|
|
|
* @param config
|
|
|
* @return
|
|
|
*/
|
|
|
private static Expression getExpression(String tableAlias, DataAuthConfig config) {
|
|
|
+ Integer conditionType = config.getConditionType();
|
|
|
if (config.getFieldType() == DataAuthFieldTypeEnum.STRING.getCode()) {
|
|
|
- EqualsTo equalsTo = new EqualsTo();
|
|
|
- equalsTo.setLeftExpression(buildColumn(tableAlias, config.getFieldName()));
|
|
|
- equalsTo.setRightExpression(new StringValue(config.getFieldValue()));
|
|
|
- return equalsTo;
|
|
|
+ return getConditionType(conditionType, tableAlias, config.getFieldName(), config.getFieldValue());
|
|
|
} else if (config.getFieldType() == DataAuthFieldTypeEnum.INT.getCode()) {
|
|
|
- EqualsTo equalsTo = new EqualsTo();
|
|
|
- equalsTo.setLeftExpression(buildColumn(tableAlias, config.getFieldName()));
|
|
|
- equalsTo.setRightExpression(new LongValue(config.getFieldValue()));
|
|
|
- return equalsTo;
|
|
|
- } else if (config.getFieldType() == DataAuthFieldTypeEnum.LOGIN_USER_ID.getCode()) {
|
|
|
- EqualsTo equalsTo = new EqualsTo();
|
|
|
- equalsTo.setLeftExpression(buildColumn(tableAlias, config.getFieldName()));
|
|
|
- equalsTo.setRightExpression(new LongValue(StpUtil.getLoginIdAsLong()));
|
|
|
- return equalsTo;
|
|
|
+ return getConditionTypeLong(conditionType, tableAlias, config.getFieldName(), config.getFieldValue());
|
|
|
+ } else if (config.getFieldType() == DataAuthFieldTypeEnum.LOGIN_USER_ID.getCode()) {//存在包含、不包含两种情况
|
|
|
+ User user = StpUtil.getTokenSession().get(GlobalConstant.LOGIN_USER_INFO_KEY, new User());
|
|
|
+ return getConditionType(conditionType, tableAlias, config.getFieldName(), user.getId().toString());
|
|
|
} else if (config.getFieldType() == DataAuthFieldTypeEnum.LOGIN_DEP_ID.getCode()) {
|
|
|
InExpression inExpression = new InExpression();
|
|
|
inExpression.setLeftExpression(buildColumn(tableAlias, config.getFieldName()));
|
|
|
List<Department> departmentList = StpUtil.getTokenSession().get(GlobalConstant.LOGIN_USER_DEPT_LIST_KEY, new ArrayList<>(0));
|
|
|
List<Expression> list = new ArrayList<>();
|
|
|
for (Department department : departmentList) {
|
|
|
- list.add(new LongValue(department.getId()));
|
|
|
+ list.add(new StringValue(department.getId().toString()));
|
|
|
}
|
|
|
-
|
|
|
- inExpression.setRightItemsList(new ExpressionList(list));
|
|
|
- return inExpression;
|
|
|
+ String Message = "该登陆人没有所属部门";
|
|
|
+ return getConditionTypeList(inExpression,conditionType,list,Message);
|
|
|
} else if (config.getFieldType() == DataAuthFieldTypeEnum.LOGIN_DEP_CHILD_ID.getCode()) {
|
|
|
InExpression inExpression = new InExpression();
|
|
|
inExpression.setLeftExpression(buildColumn(tableAlias, config.getFieldName()));
|
|
@@ -413,41 +391,185 @@ public class AuthorityUtil {
|
|
|
myAndOrgAndChildOrgUserId.addAll(currentDepartmentIdList);
|
|
|
List<Expression> list = new ArrayList<>();
|
|
|
for (Long id : myAndOrgAndChildOrgUserId) {
|
|
|
- list.add(new LongValue(id));
|
|
|
+ list.add(new StringValue(id.toString()));
|
|
|
}
|
|
|
-
|
|
|
- inExpression.setRightItemsList(new ExpressionList(list));
|
|
|
- //如果是第一个条件 直接赋值
|
|
|
- return inExpression;
|
|
|
+ String Message = "该登陆人没有所属部门";
|
|
|
+ return getConditionTypeList(inExpression,conditionType,list,Message);
|
|
|
} else if (config.getFieldType() == DataAuthFieldTypeEnum.LOGIN_USER_NAME.getCode()) {
|
|
|
- EqualsTo equalsTo = new EqualsTo();
|
|
|
- equalsTo.setLeftExpression(buildColumn(tableAlias, config.getFieldName()));
|
|
|
User user = StpUtil.getTokenSession().get(GlobalConstant.LOGIN_USER_INFO_KEY, new User());
|
|
|
- equalsTo.setRightExpression(new StringValue(user.getUserName()));
|
|
|
- return equalsTo;
|
|
|
+ return getConditionType(conditionType, tableAlias, config.getFieldName(), user.getUserName());
|
|
|
} else if (config.getFieldType() == DataAuthFieldTypeEnum.LOGIN_POST_ID.getCode()) {
|
|
|
InExpression inExpression = new InExpression();
|
|
|
inExpression.setLeftExpression(buildColumn(tableAlias, config.getFieldName()));
|
|
|
List<Post> postList = StpUtil.getTokenSession().get(GlobalConstant.LOGIN_USER_POST_LIST_KEY, new ArrayList<>());
|
|
|
List<Expression> list = new ArrayList<>();
|
|
|
for (Post post : postList) {
|
|
|
- list.add(new LongValue(post.getId()));
|
|
|
+ list.add(new StringValue(post.getId().toString()));
|
|
|
}
|
|
|
- inExpression.setRightItemsList(new ExpressionList(list));
|
|
|
- return inExpression;
|
|
|
+ String Message = "该登陆人没有所属岗位";
|
|
|
+ return getConditionTypeList(inExpression,conditionType,list,Message);
|
|
|
} else {
|
|
|
InExpression inExpression = new InExpression();
|
|
|
inExpression.setLeftExpression(buildColumn(tableAlias, config.getFieldName()));
|
|
|
List<Long> roleIdList = StpUtil.getTokenSession().get(GlobalConstant.LOGIN_USER_ROLE_ID_KEY, new ArrayList<>());
|
|
|
List<Expression> list = new ArrayList<>();
|
|
|
for (Long id : roleIdList) {
|
|
|
- list.add(new LongValue(id));
|
|
|
+ list.add(new StringValue(id.toString()));
|
|
|
}
|
|
|
+ String Message = "该登陆人没有所属角色";
|
|
|
+ return getConditionTypeList(inExpression,conditionType,list,Message);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static InExpression getConditionTypeList(InExpression inExpression, Integer conditionType, List<Expression> list,String Message) {
|
|
|
+ if (conditionType == DataAuthConditionTypeEnum.NO_CONTAINED_IN.getCode()) {//包含于,其它全部按包含于处理
|
|
|
+ inExpression.setRightItemsList(new ExpressionList(list));
|
|
|
+ inExpression.setNot(true);
|
|
|
+ } else if (conditionType == DataAuthConditionTypeEnum.EQUAL_TO.getCode()) {//等于,获取第一个部门id
|
|
|
+ if (list.size() > 0) {
|
|
|
+ inExpression.setRightItemsList(new ExpressionList(list.get(0)));
|
|
|
+ } else {
|
|
|
+ throw new MyException(Message);
|
|
|
+ }
|
|
|
+ } else if (conditionType == DataAuthConditionTypeEnum.NO_EQUAL_TO.getCode()) {//不等于,获取第一个部门id
|
|
|
+ if (list.size() > 0) {
|
|
|
+ inExpression.setRightItemsList(new ExpressionList(list.get(0)));
|
|
|
+ inExpression.setNot(true);
|
|
|
+ } else {
|
|
|
+ throw new MyException(Message);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
inExpression.setRightItemsList(new ExpressionList(list));
|
|
|
- return inExpression;
|
|
|
}
|
|
|
+ return inExpression;
|
|
|
}
|
|
|
|
|
|
+ public static Expression getConditionType(Integer conditionType, String tableAlias, String fieldName, String fieldValue) {
|
|
|
+ if (conditionType == DataAuthConditionTypeEnum.EQUAL_TO.getCode()) {
|
|
|
+ EqualsTo equalsTo = new EqualsTo(); //等于
|
|
|
+ equalsTo.setLeftExpression(buildColumn(tableAlias, fieldName));
|
|
|
+ equalsTo.setRightExpression(new StringValue(fieldValue));
|
|
|
+ return equalsTo;
|
|
|
+ } else if (conditionType == DataAuthConditionTypeEnum.GREATER_THAN.getCode()) {
|
|
|
+ GreaterThan greaterThan = new GreaterThan(); //大于
|
|
|
+ greaterThan.setLeftExpression(buildColumn(tableAlias, fieldName));
|
|
|
+ greaterThan.setRightExpression(new StringValue(fieldValue));
|
|
|
+ return greaterThan;
|
|
|
+ } else if (conditionType == DataAuthConditionTypeEnum.GREATER_THAN_EQUAL.getCode()) {
|
|
|
+ GreaterThanEquals greaterThanEquals = new GreaterThanEquals();//大于等于
|
|
|
+ greaterThanEquals.setLeftExpression(buildColumn(tableAlias, fieldName));
|
|
|
+ greaterThanEquals.setRightExpression(new StringValue(fieldValue));
|
|
|
+ return greaterThanEquals;
|
|
|
+ } else if (conditionType == DataAuthConditionTypeEnum.MINOR_THAN.getCode()) {
|
|
|
+ MinorThan minorThan = new MinorThan();//小于
|
|
|
+ minorThan.setLeftExpression(buildColumn(tableAlias, fieldName));
|
|
|
+ minorThan.setRightExpression(new StringValue(fieldValue));
|
|
|
+ return minorThan;
|
|
|
+ } else if (conditionType == DataAuthConditionTypeEnum.MINOR_THAN_EQUAL.getCode()) {
|
|
|
+ MinorThanEquals minorThanEquals = new MinorThanEquals();//小于等于
|
|
|
+ minorThanEquals.setLeftExpression(buildColumn(tableAlias, fieldName));
|
|
|
+ minorThanEquals.setRightExpression(new StringValue(fieldValue));
|
|
|
+ return minorThanEquals;
|
|
|
+ } else if (conditionType == DataAuthConditionTypeEnum.CONTAIN.getCode()) {//包含
|
|
|
+ LikeExpression likeExpression = new LikeExpression();
|
|
|
+ likeExpression.setLeftExpression(buildColumn(tableAlias, fieldName));
|
|
|
+ likeExpression.setRightExpression(new StringValue("%" + fieldValue + "%"));
|
|
|
+ return likeExpression;
|
|
|
+ } else if (conditionType == DataAuthConditionTypeEnum.CONTAINED_IN.getCode()) {//包含于
|
|
|
+ LikeExpression likeExpression = new LikeExpression();
|
|
|
+ likeExpression.setLeftExpression(new StringValue(fieldValue));
|
|
|
+ likeExpression.setRightExpression(buildColumn(tableAlias, fieldName));
|
|
|
+ return likeExpression;
|
|
|
+ } else if (conditionType == DataAuthConditionTypeEnum.NO_EQUAL_TO.getCode()) {//不等于
|
|
|
+ NotEqualsTo notEqualsTo = new NotEqualsTo();
|
|
|
+ notEqualsTo.setLeftExpression(buildColumn(tableAlias, fieldName));
|
|
|
+ notEqualsTo.setRightExpression(new StringValue(fieldValue));
|
|
|
+ return notEqualsTo;
|
|
|
+ } else if (conditionType == DataAuthConditionTypeEnum.NO_CONTAIN.getCode()) {//不包含
|
|
|
+ LikeExpression likeExpression = new LikeExpression();
|
|
|
+ likeExpression.setLeftExpression(buildColumn(tableAlias, fieldName));
|
|
|
+ likeExpression.setNot(true);
|
|
|
+ likeExpression.setRightExpression(new StringValue("%" + fieldValue + "%"));
|
|
|
+ return likeExpression;
|
|
|
+ } else if (conditionType == DataAuthConditionTypeEnum.NO_CONTAINED_IN.getCode()) {//不包含于
|
|
|
+ LikeExpression likeExpression = new LikeExpression();
|
|
|
+ likeExpression.setNot(true);
|
|
|
+ likeExpression.setLeftExpression(new StringValue(fieldValue));
|
|
|
+ likeExpression.setRightExpression(buildColumn(tableAlias, fieldName));
|
|
|
+ return likeExpression;
|
|
|
+ } else {
|
|
|
+ throw new MyException("条件不成立");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Expression getConditionTypeLong(Integer conditionType, String tableAlias, String fieldName, String fieldValue) {
|
|
|
+ if (conditionType == DataAuthConditionTypeEnum.EQUAL_TO.getCode()) {
|
|
|
+ EqualsTo equalsTo = new EqualsTo(); //等于
|
|
|
+ equalsTo.setLeftExpression(buildColumn(tableAlias, fieldName));
|
|
|
+ equalsTo.setRightExpression(new LongValue(fieldValue));
|
|
|
+ return equalsTo;
|
|
|
+ } else if (conditionType == DataAuthConditionTypeEnum.GREATER_THAN.getCode()) {
|
|
|
+ GreaterThan greaterThan = new GreaterThan(); //大于
|
|
|
+ greaterThan.setLeftExpression(buildColumn(tableAlias, fieldName));
|
|
|
+ greaterThan.setRightExpression(new LongValue(fieldValue));
|
|
|
+ return greaterThan;
|
|
|
+ } else if (conditionType == DataAuthConditionTypeEnum.GREATER_THAN_EQUAL.getCode()) {
|
|
|
+ GreaterThanEquals greaterThanEquals = new GreaterThanEquals();//大于等于
|
|
|
+ greaterThanEquals.setLeftExpression(buildColumn(tableAlias, fieldName));
|
|
|
+ greaterThanEquals.setRightExpression(new LongValue(fieldValue));
|
|
|
+ return greaterThanEquals;
|
|
|
+ } else if (conditionType == DataAuthConditionTypeEnum.MINOR_THAN.getCode()) {
|
|
|
+ MinorThan minorThan = new MinorThan();//小于
|
|
|
+ minorThan.setLeftExpression(buildColumn(tableAlias, fieldName));
|
|
|
+ minorThan.setRightExpression(new LongValue(fieldValue));
|
|
|
+ return minorThan;
|
|
|
+ } else if (conditionType == DataAuthConditionTypeEnum.MINOR_THAN_EQUAL.getCode()) {
|
|
|
+ MinorThanEquals minorThanEquals = new MinorThanEquals();//小于等于
|
|
|
+ minorThanEquals.setLeftExpression(buildColumn(tableAlias, fieldName));
|
|
|
+ minorThanEquals.setRightExpression(new LongValue(fieldValue));
|
|
|
+ return minorThanEquals;
|
|
|
+ } else if (conditionType == DataAuthConditionTypeEnum.CONTAIN.getCode()) {//包含
|
|
|
+ InExpression inExpression = new InExpression();
|
|
|
+ inExpression.setLeftExpression(buildColumn(tableAlias, fieldName));
|
|
|
+ List<Expression> list = new ArrayList<>();
|
|
|
+ list.add(new LongValue(fieldValue));
|
|
|
+ inExpression.setRightItemsList(new ExpressionList(list));
|
|
|
+// LikeExpression likeExpression = new LikeExpression();
|
|
|
+// likeExpression.setLeftExpression(buildColumn(tableAlias, fieldName));
|
|
|
+// likeExpression.setRightExpression(new StringValue("%" + fieldValue + "%"));
|
|
|
+ return inExpression;
|
|
|
+ } else if (conditionType == DataAuthConditionTypeEnum.CONTAINED_IN.getCode()) {//包含于
|
|
|
+ InExpression inExpression = new InExpression();
|
|
|
+ inExpression.setLeftExpression(new LongValue(fieldValue));
|
|
|
+ List<Expression> list = new ArrayList<>();
|
|
|
+ list.add(buildColumn(tableAlias, fieldName));
|
|
|
+ inExpression.setRightItemsList(new ExpressionList(list));
|
|
|
+ return inExpression;
|
|
|
+ } else if (conditionType == DataAuthConditionTypeEnum.NO_EQUAL_TO.getCode()) {//不等于
|
|
|
+ NotEqualsTo notEqualsTo = new NotEqualsTo();
|
|
|
+ notEqualsTo.setLeftExpression(buildColumn(tableAlias, fieldName));
|
|
|
+ notEqualsTo.setRightExpression(new LongValue(fieldValue));
|
|
|
+ return notEqualsTo;
|
|
|
+ } else if (conditionType == DataAuthConditionTypeEnum.NO_CONTAIN.getCode()) {//不包含
|
|
|
+ InExpression inExpression = new InExpression();
|
|
|
+ inExpression.setLeftExpression(buildColumn(tableAlias, fieldName));
|
|
|
+ List<Expression> list = new ArrayList<>();
|
|
|
+ list.add(new LongValue(fieldValue));
|
|
|
+ inExpression.setRightItemsList(new ExpressionList(list));
|
|
|
+ inExpression.setNot(true);
|
|
|
+ return inExpression;
|
|
|
+ } else if (conditionType == DataAuthConditionTypeEnum.NO_CONTAINED_IN.getCode()) {//不包含于
|
|
|
+ InExpression inExpression = new InExpression();
|
|
|
+ inExpression.setLeftExpression(new LongValue(fieldValue));
|
|
|
+ List<Expression> list = new ArrayList<>();
|
|
|
+ list.add(buildColumn(tableAlias, fieldName));
|
|
|
+ inExpression.setRightItemsList(new ExpressionList(list));
|
|
|
+ inExpression.setNot(true);
|
|
|
+ return inExpression;
|
|
|
+ } else {
|
|
|
+ throw new MyException("条件不成立");
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* 构建Column
|