ソースを参照

物业用户通过用户名和手机号搜索用户信息

黄远 5 年 前
コミット
e04cebfb81

+ 4 - 4
lift-system-service/src/main/java/cn/com/ty/lift/system/user/service/impl/PropertyUserService.java

@@ -16,6 +16,7 @@ import javax.annotation.Resource;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
+import java.util.stream.Collectors;
 
 /**
  * @author huangyuan
@@ -47,11 +48,10 @@ public class PropertyUserService implements IPropertyUserService {
         IPage propertyUserPage = new Page(propertyUserRequest.getPageNum(), propertyUserRequest.getPageSize());
         if (projectUserList != null && projectUserList.size() > 0) {
             //获取用户信息
-            List<Long> userIdList = ProjectUtils.getAttrList(projectUserList, "userId", null);
+            List<Long> userIdList = projectUserList.stream().map(ProjectUser::getUserId).collect(Collectors.toList());
             Map<Long, UserResponse> userIdToUserResponse = userService.getUserResponseByUserIdList(userIdList);
             //获取项目信息
-            List<Long> projectIdList = ProjectUtils.getAttrList(projectUserList,
-                    "projectId", null);
+            List<Long> projectIdList = projectUserList.stream().map(ProjectUser::getProjectId).collect(Collectors.toList());
             Map<Long, ProjectInfo> projectIdToProjectInfo = projectService.getProjectIdToProjectByProjectIdList(projectIdList);
             List<PropertyUserResponse> propertyUserResponseList = new ArrayList<>();
             for (ProjectUser projectUser : projectUserList) {
@@ -84,7 +84,7 @@ public class PropertyUserService implements IPropertyUserService {
     @Override
     public RestResponse cancelPermission(PropertyUserRequest propertyUserRequest) {
         Long deleteCount = projectService.deleteProjectUser(propertyUserRequest);
-        if(deleteCount == 0){
+        if (deleteCount == 0) {
             return RestResponse.fail(ApiConstants.RESULT_ERROR, "操作失败");
         }
         return RestResponse.success(ApiConstants.RESULT_SUCCESS, "操作成功");

+ 20 - 16
lift-system-service/src/main/java/cn/com/ty/lift/system/user/service/impl/UserService.java

@@ -293,23 +293,27 @@ public class UserService implements IUserService {
 
     @Override
     public List<Long> getIdListByQueryCondition(String queryCondition) {
-        List<UserAccount> userAccountList = userAccountService.list(new QueryWrapper<UserAccount>()
-                .select("user_id")
-                //通过手机号模糊查找
-                .like("mobile", queryCondition));
-        List<UserInfo> userInfoList = userInfoService.list(new QueryWrapper<UserInfo>()
-                .select("user_id")
-                //通过用户名模糊查找
-                .like("name", queryCondition)
+        //通过手机号模糊查找
+        List<UserAccount> userAccountList = userAccountService.list(new QueryWrapper<UserAccount>().
+                select("user_id").like("mobile", queryCondition)
         );
-        //获取通过手机号模糊查询出来的用户id
-        List<Long> accountUserIdList = ProjectUtils.getAttrList(userAccountList, "userId", null);
-        //获取通过用户名模糊查询出来的用户id
-        List<Long> infoUserIdList = ProjectUtils.getAttrList(userInfoList, "userId", null);
-        //合并去重
-        accountUserIdList.addAll(infoUserIdList);
-        ProjectUtils.removeDuplicateWithOrder(accountUserIdList);
-        return accountUserIdList;
+        //通过用户名称模糊查找用户信息
+        List<UserInfo> userInfoList = userInfoService.list(new QueryWrapper<UserInfo>().
+                select("user_id").like("name", queryCondition)
+        );
+        List<Long> userIdList = new ArrayList<>();
+        //将用户id封装到集合中
+        if (userAccountList != null && userAccountList.size() > 0) {
+            userIdList.addAll(userAccountList.stream().map(UserAccount::getUserId)
+                    .collect(Collectors.toList()));
+        }
+        if (userInfoList != null && userInfoList.size() > 0) {
+            userIdList.addAll(userInfoList.stream().map(UserInfo::getUserId)
+                    .collect(Collectors.toList()));
+        }
+        //列表去重
+        ProjectUtils.removeDuplicateWithOrder(userIdList);
+        return userIdList;
     }
 
     @Override