@ -491,6 +491,183 @@ public class AuthorizeServiceImpl extends ServiceImpl<AuthorizeMapper, Authorize
return queryWhere ;
}
/ * *
* 获 取 条 件 过 滤
*
* @param userInfo 用 户 信 息
* @param moduleId 功 能 模 块 Id
* @param tableName 表 名
* @return
* /
@Override
public QueryWrapper < T > getCondition2 ( AuthorizeConditionModel conditionModel ) {
Object obj = conditionModel . getObj ( ) ;
String moduleId = conditionModel . getModuleId ( ) ;
String tableName = conditionModel . getTableName ( ) ;
UserInfo userInfo = userProvider . get ( ) ;
QueryWrapper < T > queryWhere = ( QueryWrapper < T > ) obj ;
AuthorizeVO model = this . getAuthorize ( true ) ;
List < ResourceModel > resourceList = model . getResourceList ( ) . stream ( ) . filter ( m - > m . getModuleId ( ) . equals ( moduleId ) ) . collect ( Collectors . toList ( ) ) ;
if ( resourceList . size ( ) = = 0 ) {
return null ;
}
List < ResourceModel > resourceList1 = new ArrayList < > ( ) ;
//拼接计数
int t = 0 ;
for ( ResourceModel item : resourceList ) {
if ( "linkage_alldata" . equals ( item . getEnCode ( ) ) ) {
t = 0 ;
break ;
}
List < ConditionModel > conditionModelList = JsonUtil . getJsonToList ( item . getConditionJson ( ) , ConditionModel . class ) ;
for ( int i = 0 ; i < conditionModelList . size ( ) ; i + + ) {
ConditionModel conditionItem = conditionModelList . get ( i ) ;
for ( int k = 0 ; k < conditionItem . getGroups ( ) . size ( ) ; k + + ) {
ConditionModel . ConditionItemModel fieldItem = conditionItem . getGroups ( ) . get ( k ) ;
String itemValue = fieldItem . getValue ( ) ;
String itemMethod = fieldItem . getOp ( ) ;
String itemTable = fieldItem . getBindTable ( ) ;
if ( StringUtil . isNotEmpty ( itemTable ) & & itemTable . equalsIgnoreCase ( tableName ) ) {
resourceList1 . add ( item ) ;
}
if ( AuthorizeConditionEnum . USER . getCondition ( ) . equals ( itemValue )
| | AuthorizeConditionEnum . ORGANIZE . getCondition ( ) . equals ( itemValue )
| | AuthorizeConditionEnum . USERANDUNDER . getCondition ( ) . equals ( itemValue )
| | AuthorizeConditionEnum . ORGANIZEANDUNDER . getCondition ( ) . equals ( itemValue )
| | itemMethod . equals ( SearchMethodEnum . Equal . getMessage ( ) )
| | itemMethod . equals ( SearchMethodEnum . NotEqual . getMessage ( ) )
| | itemMethod . equals ( SearchMethodEnum . LessThan . getMessage ( ) )
| | itemMethod . equals ( SearchMethodEnum . LessThanOrEqual . getMessage ( ) )
| | itemMethod . equals ( SearchMethodEnum . GreaterThan . getMessage ( ) )
| | itemMethod . equals ( SearchMethodEnum . GreaterThanOrEqual . getMessage ( ) )
) { //当前用户Id
t = 1 ;
}
}
}
}
if ( t = = 1 ) {
if ( resourceList1 . size ( ) > 0 ) {
queryWhere . and ( tw - > {
for ( ResourceModel item : resourceList1 ) {
List < ConditionModel > conditionModelList = JsonUtil . getJsonToList ( item . getConditionJson ( ) , ConditionModel . class ) ;
for ( int i = 0 ; i < conditionModelList . size ( ) ; i + + ) {
ConditionModel conditionItem = conditionModelList . get ( i ) ;
for ( int k = 0 ; k < conditionItem . getGroups ( ) . size ( ) ; k + + ) {
ConditionModel . ConditionItemModel fieldItem = conditionItem . getGroups ( ) . get ( k ) ;
String itemField = "a." + fieldItem . getField ( ) ;
String itemValue = fieldItem . getValue ( ) ;
String itemMethod = fieldItem . getOp ( ) ;
if ( "and" . equalsIgnoreCase ( conditionItem . getLogic ( ) ) ) {
if ( AuthorizeConditionEnum . USER . getCondition ( ) . equals ( itemValue ) ) { //当前用户
tw . eq ( itemField , userInfo . getUserId ( ) ) ;
} else if ( AuthorizeConditionEnum . ORGANIZE . getCondition ( ) . equals ( itemValue ) ) { //当前组织
String orgId = userInfo . getOrganizeId ( ) ;
if ( StringUtil . isNotEmpty ( userInfo . getDepartmentId ( ) ) ) {
orgId = userInfo . getDepartmentId ( ) ;
}
tw . eq ( itemField , orgId ) ;
} else if ( AuthorizeConditionEnum . ORGANIZEANDUNDER . getCondition ( ) . equals ( itemValue ) ) { //组织及子组织
String orgId = userInfo . getOrganizeId ( ) ;
if ( StringUtil . isNotEmpty ( userInfo . getDepartmentId ( ) ) ) {
orgId = userInfo . getDepartmentId ( ) ;
}
List < String > underOrganizations = organizeService . getUnderOrganizations ( orgId ) ;
underOrganizations . add ( orgId ) ;
tw . in ( itemField , underOrganizations ) ;
} else if ( AuthorizeConditionEnum . USERANDUNDER . getCondition ( ) . equals ( itemValue ) ) { //用户及用户下属
List < String > idsList = new ArrayList < > ( ) ;
if ( userInfo . getSubordinateIds ( ) . size ( ) > 0 ) {
idsList = userInfo . getSubordinateIds ( ) ;
}
idsList . add ( userInfo . getUserId ( ) ) ;
tw . in ( itemField , idsList ) ;
} else { //任意文本
if ( itemMethod . equals ( SearchMethodEnum . Equal . getMessage ( ) ) ) {
tw . eq ( itemField , itemValue ) ;
} else if ( itemMethod . equals ( SearchMethodEnum . NotEqual . getMessage ( ) ) ) {
tw . ne ( itemField , itemValue ) ;
} else if ( itemMethod . equals ( SearchMethodEnum . LessThan . getMessage ( ) ) ) {
tw . lt ( itemField , itemValue ) ;
} else if ( itemMethod . equals ( SearchMethodEnum . LessThanOrEqual . getMessage ( ) ) ) {
tw . le ( itemField , itemValue ) ;
} else if ( itemMethod . equals ( SearchMethodEnum . GreaterThan . getMessage ( ) ) ) {
tw . gt ( itemField , itemValue ) ;
} else if ( itemMethod . equals ( SearchMethodEnum . GreaterThanOrEqual . getMessage ( ) ) ) {
tw . ge ( itemField , itemValue ) ;
}
}
} else {
if ( AuthorizeConditionEnum . USER . getCondition ( ) . equals ( itemValue ) ) { //当前用户
tw . or (
qw - > qw . eq ( itemField , userInfo . getUserId ( ) )
) ;
} else if ( AuthorizeConditionEnum . ORGANIZE . getCondition ( ) . equals ( itemValue ) ) { //当前组织
String orgId = userInfo . getOrganizeId ( ) ;
if ( StringUtil . isNotEmpty ( userInfo . getDepartmentId ( ) ) ) {
orgId = userInfo . getDepartmentId ( ) ;
}
String finalOrgId = orgId ;
tw . or (
qw - > qw . eq ( itemField , finalOrgId )
) ;
} else if ( AuthorizeConditionEnum . ORGANIZEANDUNDER . getCondition ( ) . equals ( itemValue ) ) { //组织及子组织
String orgId = userInfo . getOrganizeId ( ) ;
if ( StringUtil . isNotEmpty ( userInfo . getDepartmentId ( ) ) ) {
orgId = userInfo . getDepartmentId ( ) ;
}
List < String > underOrganizations = organizeService . getUnderOrganizations ( orgId ) ;
underOrganizations . add ( orgId ) ;
tw . or (
qw - > qw . in ( itemField , underOrganizations )
) ;
} else if ( AuthorizeConditionEnum . USERANDUNDER . getCondition ( ) . equals ( itemValue ) ) { //用户及用户下属
List < String > idsList = new ArrayList < > ( ) ;
if ( userInfo . getSubordinateIds ( ) . size ( ) > 0 ) {
idsList = userInfo . getSubordinateIds ( ) ;
}
idsList . add ( userInfo . getUserId ( ) ) ;
List < String > finalIdsList = idsList ;
tw . or (
qw - > qw . in ( itemField , finalIdsList )
) ;
} else { //任意文本
if ( itemMethod . equals ( SearchMethodEnum . Equal . getMessage ( ) ) ) {
tw . or (
qw - > qw . eq ( itemField , itemValue )
) ;
} else if ( itemMethod . equals ( SearchMethodEnum . NotEqual . getMessage ( ) ) ) {
tw . or (
qw - > qw . ne ( itemField , itemValue )
) ;
} else if ( itemMethod . equals ( SearchMethodEnum . LessThan . getMessage ( ) ) ) {
tw . or (
qw - > qw . lt ( itemField , itemValue )
) ;
} else if ( itemMethod . equals ( SearchMethodEnum . LessThanOrEqual . getMessage ( ) ) ) {
tw . or (
qw - > qw . le ( itemField , itemValue )
) ;
} else if ( itemMethod . equals ( SearchMethodEnum . GreaterThan . getMessage ( ) ) ) {
tw . or (
qw - > qw . gt ( itemField , itemValue )
) ;
} else if ( itemMethod . equals ( SearchMethodEnum . GreaterThanOrEqual . getMessage ( ) ) ) {
tw . or (
qw - > qw . ge ( itemField , itemValue )
) ;
}
}
}
}
}
}
} ) ;
}
}
return queryWhere ;
}
/ * *
* 获 取 条 件 过 滤