diff --git a/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-api/src/main/java/org/hswebframework/web/service/authorization/UserService.java b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-api/src/main/java/org/hswebframework/web/service/authorization/UserService.java index 8ace7c65d..2fc2573dc 100644 --- a/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-api/src/main/java/org/hswebframework/web/service/authorization/UserService.java +++ b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-api/src/main/java/org/hswebframework/web/service/authorization/UserService.java @@ -107,4 +107,12 @@ public interface UserService extends * @return 永远不为null, 如果用户不存在或者用户没有任何角色, 返回空集合. */ List getUserRole(String userId); + + /** + * 根据角色id集合获取对应的全部用户 + * + * @param roleIdList 角色ID集合 + * @return 用户, 不存在时返回空集合,不会返回null + */ + List selectByUserByRole(List roleIdList); } diff --git a/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-local/src/main/java/org/hswebframework/web/dao/authorization/UserRoleDao.java b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-local/src/main/java/org/hswebframework/web/dao/authorization/UserRoleDao.java index 14292a449..66db83f7e 100644 --- a/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-local/src/main/java/org/hswebframework/web/dao/authorization/UserRoleDao.java +++ b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-local/src/main/java/org/hswebframework/web/dao/authorization/UserRoleDao.java @@ -18,4 +18,5 @@ public interface UserRoleDao extends Dao { List selectByUserId(String userId); List selectByRoleId(String roleId); + } diff --git a/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-local/src/main/java/org/hswebframework/web/service/authorization/simple/SimpleUserService.java b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-local/src/main/java/org/hswebframework/web/service/authorization/simple/SimpleUserService.java index 0629afcf7..1efcc841c 100644 --- a/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-local/src/main/java/org/hswebframework/web/service/authorization/simple/SimpleUserService.java +++ b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-local/src/main/java/org/hswebframework/web/service/authorization/simple/SimpleUserService.java @@ -181,9 +181,9 @@ public class SimpleUserService extends AbstractService //不修改的字段 List excludeProperties = new ArrayList<>(Arrays.asList( UserEntity.username - ,UserEntity.password - ,UserEntity.salt - ,UserEntity.status)); + , UserEntity.password + , UserEntity.salt + , UserEntity.status)); //修改密码 if (StringUtils.hasLength(userEntity.getPassword())) { //密码强度验证 @@ -211,7 +211,7 @@ public class SimpleUserService extends AbstractService if (excludeProperties.contains(UserEntity.password)) { publisher.publishEvent(new UserModifiedEvent(userEntity, passwordModified, roleModified)); } - publisher.publishEvent(new ClearUserAuthorizationCacheEvent(userId,false)); + publisher.publishEvent(new ClearUserAuthorizationCacheEvent(userId, false)); } @@ -285,4 +285,14 @@ public class SimpleUserService extends AbstractService settingInfo.add(new SettingInfo(SETTING_TYPE_USER, userId)); return settingInfo; } + + @Override + public List selectByUserByRole(List roleIdList) { + if (CollectionUtils.isEmpty(roleIdList)) { + return Collections.emptyList(); + } + return createQuery() + .where("id", "user-in-role", roleIdList) + .listNoPaging(); + } } diff --git a/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-local/src/main/java/org/hswebframework/web/service/authorization/simple/terms/CustomUserSqlTermAutoConfiguration.java b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-local/src/main/java/org/hswebframework/web/service/authorization/simple/terms/CustomUserSqlTermAutoConfiguration.java new file mode 100644 index 000000000..b0209841e --- /dev/null +++ b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-local/src/main/java/org/hswebframework/web/service/authorization/simple/terms/CustomUserSqlTermAutoConfiguration.java @@ -0,0 +1,22 @@ +package org.hswebframework.web.service.authorization.simple.terms; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * @author zhouhao + * @since 3.0.0-RC + */ +@Configuration +public class CustomUserSqlTermAutoConfiguration { + + @Bean + public UserInRoleSqlTerm userInRoleSqlTerm() { + return new UserInRoleSqlTerm(false); + } + + @Bean + public UserInRoleSqlTerm userNotInRoleSqlTerm() { + return new UserInRoleSqlTerm(true); + } +} diff --git a/hsweb-system/hsweb-system-organizational/hsweb-system-organizational-local/src/main/java/org/hswebframework/web/service/organizational/simple/terms/PersonInPositionSqlTerm.java b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-local/src/main/java/org/hswebframework/web/service/authorization/simple/terms/UserInRoleSqlTerm.java similarity index 66% rename from hsweb-system/hsweb-system-organizational/hsweb-system-organizational-local/src/main/java/org/hswebframework/web/service/organizational/simple/terms/PersonInPositionSqlTerm.java rename to hsweb-system/hsweb-system-authorization/hsweb-system-authorization-local/src/main/java/org/hswebframework/web/service/authorization/simple/terms/UserInRoleSqlTerm.java index ec5952075..d52fa743c 100644 --- a/hsweb-system/hsweb-system-organizational/hsweb-system-organizational-local/src/main/java/org/hswebframework/web/service/organizational/simple/terms/PersonInPositionSqlTerm.java +++ b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-local/src/main/java/org/hswebframework/web/service/authorization/simple/terms/UserInRoleSqlTerm.java @@ -1,4 +1,4 @@ -package org.hswebframework.web.service.organizational.simple.terms; +package org.hswebframework.web.service.authorization.simple.terms; import org.hswebframework.ezorm.core.param.Term; import org.hswebframework.ezorm.rdb.meta.RDBColumnMetaData; @@ -9,36 +9,31 @@ import org.hswebframework.web.dao.mybatis.mapper.ChangedTermValue; import java.util.List; - /** - * 查询岗位中的人员 - * * @author zhouhao - * @since 3.0.0-RC + * @since 3.0 */ -public class PersonInPositionSqlTerm extends AbstractSqlTermCustomer { +public class UserInRoleSqlTerm extends AbstractSqlTermCustomer { private boolean not; - public PersonInPositionSqlTerm(boolean not) { - super("person-" + (not ? "not-" : "") + "in-position"); + public UserInRoleSqlTerm(boolean not) { + super("user" + (not ? "-not-in" : "-in") + "-role"); this.not = not; } @Override public SqlAppender accept(String wherePrefix, Term term, RDBColumnMetaData column, String tableAlias) { ChangedTermValue termValue = createChangedTermValue(term); - SqlAppender appender = new SqlAppender(); - //exists(select 1 from s_person_position tmp where tmp.person_id = t.owner_id and position_id =?) - appender.add(not ? "not " : "", "exists(select 1 from s_person_position tmp where tmp.person_id =", createColumnName(column, tableAlias)); + appender.add(not ? "not " : "", "exists(select 1 from s_user_role tmp where tmp.user_id =", + createColumnName(column, tableAlias)); List positionIdList = BoostTermTypeMapper.convertList(column, termValue.getOld()); if (!positionIdList.isEmpty()) { - appender.add(" and tmp.position_id"); + appender.add(" and tmp.role_id"); termValue.setValue(appendCondition(positionIdList, wherePrefix, appender)); } - appender.add(")"); return appender;