Browse Source

增加UserInRoleSqlTerm

zhouhao 6 years ago
parent
commit
cbdab1f0df

+ 8 - 0
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<RoleEntity> getUserRole(String userId);
+
+    /**
+     * 根据角色id集合获取对应的全部用户
+     *
+     * @param roleIdList 角色ID集合
+     * @return 用户, 不存在时返回空集合,不会返回null
+     */
+    List<UserEntity> selectByUserByRole(List<String> roleIdList);
 }

+ 1 - 0
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<UserRoleEntity> selectByUserId(String userId);
 
     List<UserRoleEntity> selectByRoleId(String roleId);
+
 }

+ 14 - 4
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<UserEntity, String>
         //不修改的字段
         List<String> 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<UserEntity, String>
         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<UserEntity, String>
         settingInfo.add(new SettingInfo(SETTING_TYPE_USER, userId));
         return settingInfo;
     }
+
+    @Override
+    public List<UserEntity> selectByUserByRole(List<String> roleIdList) {
+        if (CollectionUtils.isEmpty(roleIdList)) {
+            return Collections.emptyList();
+        }
+        return createQuery()
+                .where("id", "user-in-role", roleIdList)
+                .listNoPaging();
+    }
 }

+ 22 - 0
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);
+    }
+}

+ 8 - 13
hsweb-system/hsweb-system-organizational/hsweb-system-organizational-local/src/main/java/org/hswebframework/web/service/organizational/simple/terms/PersonInPositionSqlTerm.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<Object> 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;