Skip to content

Commit cbdab1f

Browse files
committed
增加UserInRoleSqlTerm
1 parent 72d0a47 commit cbdab1f

File tree

5 files changed

+53
-17
lines changed

5 files changed

+53
-17
lines changed

hsweb-system/hsweb-system-authorization/hsweb-system-authorization-api/src/main/java/org/hswebframework/web/service/authorization/UserService.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,12 @@ public interface UserService extends
107107
* @return 永远不为null, 如果用户不存在或者用户没有任何角色, 返回空集合.
108108
*/
109109
List<RoleEntity> getUserRole(String userId);
110+
111+
/**
112+
* 根据角色id集合获取对应的全部用户
113+
*
114+
* @param roleIdList 角色ID集合
115+
* @return 用户, 不存在时返回空集合,不会返回null
116+
*/
117+
List<UserEntity> selectByUserByRole(List<String> roleIdList);
110118
}

hsweb-system/hsweb-system-authorization/hsweb-system-authorization-local/src/main/java/org/hswebframework/web/dao/authorization/UserRoleDao.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ public interface UserRoleDao extends Dao {
1818
List<UserRoleEntity> selectByUserId(String userId);
1919

2020
List<UserRoleEntity> selectByRoleId(String roleId);
21+
2122
}

hsweb-system/hsweb-system-authorization/hsweb-system-authorization-local/src/main/java/org/hswebframework/web/service/authorization/simple/SimpleUserService.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,9 @@ public void update(String userId, UserEntity userEntity) {
181181
//不修改的字段
182182
List<String> excludeProperties = new ArrayList<>(Arrays.asList(
183183
UserEntity.username
184-
,UserEntity.password
185-
,UserEntity.salt
186-
,UserEntity.status));
184+
, UserEntity.password
185+
, UserEntity.salt
186+
, UserEntity.status));
187187
//修改密码
188188
if (StringUtils.hasLength(userEntity.getPassword())) {
189189
//密码强度验证
@@ -211,7 +211,7 @@ public void update(String userId, UserEntity userEntity) {
211211
if (excludeProperties.contains(UserEntity.password)) {
212212
publisher.publishEvent(new UserModifiedEvent(userEntity, passwordModified, roleModified));
213213
}
214-
publisher.publishEvent(new ClearUserAuthorizationCacheEvent(userId,false));
214+
publisher.publishEvent(new ClearUserAuthorizationCacheEvent(userId, false));
215215

216216
}
217217

@@ -285,4 +285,14 @@ public Set<SettingInfo> get(String userId) {
285285
settingInfo.add(new SettingInfo(SETTING_TYPE_USER, userId));
286286
return settingInfo;
287287
}
288+
289+
@Override
290+
public List<UserEntity> selectByUserByRole(List<String> roleIdList) {
291+
if (CollectionUtils.isEmpty(roleIdList)) {
292+
return Collections.emptyList();
293+
}
294+
return createQuery()
295+
.where("id", "user-in-role", roleIdList)
296+
.listNoPaging();
297+
}
288298
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package org.hswebframework.web.service.authorization.simple.terms;
2+
3+
import org.springframework.context.annotation.Bean;
4+
import org.springframework.context.annotation.Configuration;
5+
6+
/**
7+
* @author zhouhao
8+
* @since 3.0.0-RC
9+
*/
10+
@Configuration
11+
public class CustomUserSqlTermAutoConfiguration {
12+
13+
@Bean
14+
public UserInRoleSqlTerm userInRoleSqlTerm() {
15+
return new UserInRoleSqlTerm(false);
16+
}
17+
18+
@Bean
19+
public UserInRoleSqlTerm userNotInRoleSqlTerm() {
20+
return new UserInRoleSqlTerm(true);
21+
}
22+
}
Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.hswebframework.web.service.organizational.simple.terms;
1+
package org.hswebframework.web.service.authorization.simple.terms;
22

33
import org.hswebframework.ezorm.core.param.Term;
44
import org.hswebframework.ezorm.rdb.meta.RDBColumnMetaData;
@@ -9,36 +9,31 @@
99

1010
import java.util.List;
1111

12-
1312
/**
14-
* 查询岗位中的人员
15-
*
1613
* @author zhouhao
17-
* @since 3.0.0-RC
14+
* @since 3.0
1815
*/
19-
public class PersonInPositionSqlTerm extends AbstractSqlTermCustomer {
16+
public class UserInRoleSqlTerm extends AbstractSqlTermCustomer {
2017

2118
private boolean not;
2219

23-
public PersonInPositionSqlTerm(boolean not) {
24-
super("person-" + (not ? "not-" : "") + "in-position");
20+
public UserInRoleSqlTerm(boolean not) {
21+
super("user" + (not ? "-not-in" : "-in") + "-role");
2522
this.not = not;
2623
}
2724

2825
@Override
2926
public SqlAppender accept(String wherePrefix, Term term, RDBColumnMetaData column, String tableAlias) {
3027
ChangedTermValue termValue = createChangedTermValue(term);
31-
3228
SqlAppender appender = new SqlAppender();
33-
//exists(select 1 from s_person_position tmp where tmp.person_id = t.owner_id and position_id =?)
34-
appender.add(not ? "not " : "", "exists(select 1 from s_person_position tmp where tmp.person_id =", createColumnName(column, tableAlias));
29+
appender.add(not ? "not " : "", "exists(select 1 from s_user_role tmp where tmp.user_id =",
30+
createColumnName(column, tableAlias));
3531

3632
List<Object> positionIdList = BoostTermTypeMapper.convertList(column, termValue.getOld());
3733
if (!positionIdList.isEmpty()) {
38-
appender.add(" and tmp.position_id");
34+
appender.add(" and tmp.role_id");
3935
termValue.setValue(appendCondition(positionIdList, wherePrefix, appender));
4036
}
41-
4237
appender.add(")");
4338

4439
return appender;

0 commit comments

Comments
 (0)