|
|
|
@ -2,10 +2,10 @@ package cn.iocoder.yudao.framework.datapermission.core.dept.rule;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil; |
|
|
|
|
import cn.hutool.core.util.StrUtil; |
|
|
|
|
import cn.iocoder.yudao.framework.datapermission.core.dept.service.DeptDataPermissionFrameworkService; |
|
|
|
|
import cn.iocoder.yudao.framework.datapermission.core.dept.service.dto.DeptDataPermissionRespDTO; |
|
|
|
|
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; |
|
|
|
|
import cn.iocoder.yudao.framework.common.util.json.JsonUtils; |
|
|
|
|
import cn.iocoder.yudao.framework.datapermission.core.dept.service.DeptDataPermissionFrameworkService; |
|
|
|
|
import cn.iocoder.yudao.framework.datapermission.core.dept.service.dto.DeptDataPermissionRespDTO; |
|
|
|
|
import cn.iocoder.yudao.framework.datapermission.core.rule.DataPermissionRule; |
|
|
|
|
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; |
|
|
|
|
import cn.iocoder.yudao.framework.mybatis.core.util.MyBatisUtils; |
|
|
|
@ -13,7 +13,7 @@ import cn.iocoder.yudao.framework.security.core.LoginUser;
|
|
|
|
|
import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils; |
|
|
|
|
import com.baomidou.mybatisplus.core.metadata.TableInfoHelper; |
|
|
|
|
import lombok.AllArgsConstructor; |
|
|
|
|
import lombok.Getter; |
|
|
|
|
import lombok.SneakyThrows; |
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
import net.sf.jsqlparser.expression.Alias; |
|
|
|
|
import net.sf.jsqlparser.expression.Expression; |
|
|
|
@ -23,6 +23,7 @@ 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.parser.CCJSqlParserUtil; |
|
|
|
|
|
|
|
|
|
import java.util.HashMap; |
|
|
|
|
import java.util.HashSet; |
|
|
|
@ -146,6 +147,7 @@ public class DeptDataPermissionRule implements DataPermissionRule {
|
|
|
|
|
new ExpressionList(CollectionUtils.convertList(deptIds, LongValue::new))); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@SneakyThrows |
|
|
|
|
private Expression buildUserExpression(String tableName, Alias tableAlias, Boolean self, Long userId) { |
|
|
|
|
// 如果不查看自己,则无需作为条件
|
|
|
|
|
if (Boolean.FALSE.equals(self)) { |
|
|
|
@ -155,6 +157,17 @@ public class DeptDataPermissionRule implements DataPermissionRule {
|
|
|
|
|
if (StrUtil.isEmpty(columnName)) { |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Long cpUserId = deptDataPermissionService.getCpUserIdBySystemUserId(userId); |
|
|
|
|
if (tableName.equals("farm_project")){ |
|
|
|
|
Expression projectSql = CCJSqlParserUtil.parseCondExpression("(creator = " + userId + " or JSON_CONTAINS(members, '"+ cpUserId +"'))"); |
|
|
|
|
return projectSql; |
|
|
|
|
} |
|
|
|
|
if (tableName.equals("farm_task")){ |
|
|
|
|
Expression taskSql = CCJSqlParserUtil.parseCondExpression(" (creator = " + userId + " or JSON_CONTAINS(executor_person, '"+ cpUserId +"')" + |
|
|
|
|
" or main_person = " + cpUserId +")"); |
|
|
|
|
return taskSql; |
|
|
|
|
} |
|
|
|
|
// 拼接条件
|
|
|
|
|
return new EqualsTo(MyBatisUtils.buildColumn(tableName, tableAlias, columnName), new LongValue(userId)); |
|
|
|
|
} |
|
|
|
|