Sfoglia il codice sorgente

获取团队成员优化

黄远 5 anni fa
parent
commit
43fc6fa7cb

+ 1 - 1
lift-system-service/src/main/java/cn/com/ty/lift/system/settings/service/impl/MaintenanceCompanyServiceImpl.java

@@ -75,7 +75,7 @@ public class MaintenanceCompanyServiceImpl extends ServiceImpl<MaintenanceCompan
     @Transactional
     public RestResponse createTeam(MaintenanceCompanyRequest maintenanceCompanyRequest) {
         MaintenanceCompany maintenanceCompany = new MaintenanceCompany();
-        //当前登录用户id
+        //当前登录用户id
         Long userId = maintenanceCompanyRequest.getUserId();
         //设置申请团队信息
         maintenanceCompany.setName(maintenanceCompanyRequest.getCompanyName());

+ 6 - 0
lift-system-service/src/main/java/cn/com/ty/lift/system/user/service/impl/LoginService.java

@@ -20,6 +20,7 @@ import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
+import javax.servlet.http.Cookie;
 import javax.servlet.http.HttpServletRequest;
 import java.util.HashMap;
 import java.util.List;
@@ -198,6 +199,11 @@ public class LoginService implements ILoginService {
         UserResponse userResponse = userService.getLoginUserInfo(userId);
         //将用户登录的手机号放入session中
         request.getSession().setAttribute(ApiConstants.UserConstants.USER_INFO_MOBILE, userResponse.getMobile());
+
+        Cookie[] cookies = request.getCookies();
+        System.out.println("JSESSIONID:" + cookies[0].getValue());
+        System.out.println("test:" + request.getSession().getAttribute("test"));
+        System.out.println("sessionId:" + request.getSession().getId());
         //封装登录用户信息
         Map<String, Object> currentUserInfoMap = getUserInfoMap(userResponse);
         //将手机号对应的用户信息放入redis中,设置过期时间为30分钟

+ 25 - 5
lift-system-service/src/main/java/cn/com/ty/lift/system/user/service/impl/MtCompanyUserService.java

@@ -78,7 +78,7 @@ public class MtCompanyUserService extends ServiceImpl<MtCompanyUserMapper, MtCom
             userRole.setRoleId(roleId);
             userRole.setUserId(userId);
             boolean saveUserRoleFlag = userRoleService.save(userRole);
-            if(!saveUserRoleFlag){
+            if (!saveUserRoleFlag) {
                 //事务强制回滚
                 TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                 return RestResponse.fail(ApiConstants.RESULT_ERROR, "保存角色信息失败");
@@ -111,6 +111,14 @@ public class MtCompanyUserService extends ServiceImpl<MtCompanyUserMapper, MtCom
         );
         //获取角色关联的用户信息
         List<Long> userIdList = ProjectUtils.getAttrList(userRoleList, "userId", null);
+        if(userIdList.size() > 0){
+            List<MtCompanyUser> mtCompanyUserList = this.list(new QueryWrapper<MtCompanyUser>()
+                    .in(userIdList != null && userIdList.size() > 0, "user_id", userIdList)
+                    .eq("mt_company_id", mtCompanyUserRequest.getCompanyId())
+                    .eq("status", ApiConstants.ApplicationConstants.APPLY_PASS)
+            );
+            userIdList = ProjectUtils.getAttrList(mtCompanyUserList, "userId", null);
+        }
         Map<Long, Role> userIdToRole = roleService.getUserIdToRoleByUserIdsAndCompanyId(userIdList, mtCompanyUserRequest.getCompanyId());
         //获取用户信息集合
         if (userIdList != null && userIdList.size() > 0) {
@@ -125,7 +133,7 @@ public class MtCompanyUserService extends ServiceImpl<MtCompanyUserMapper, MtCom
                     //用户id->角色
                     Role role = userIdToRole.get(userId);
                     //设置角色编码
-                    if(role !=  null){
+                    if (role != null) {
                         userResponse.setRoleCode(role.getCode());
                     }
                     if (userInfo != null) {
@@ -151,8 +159,20 @@ public class MtCompanyUserService extends ServiceImpl<MtCompanyUserMapper, MtCom
         }
         //设置用户为踢出团队状态
         mtCompanyUser.setStatus(ApiConstants.ApplicationConstants.APPLY_FAIL);
-        this.updateById(mtCompanyUser);
-        return RestResponse.success(null, ApiConstants.RESULT_SUCCESS, "踢出用户成功");
+        //将用户原来关联的角色信息删除掉
+        boolean deleteUserRoleFlag = userRoleService.remove(new QueryWrapper<UserRole>()
+                .eq("user_id", mtCompanyUser.getUserId())
+                .eq("company_id", mtCompanyUser.getMtCompanyId())
+        );
+        if (deleteUserRoleFlag) {
+            if (this.updateById(mtCompanyUser)) {
+                return RestResponse.success(null, ApiConstants.RESULT_SUCCESS, "踢出用户成功");
+            } else {
+                //如果删除不成功,强制事务回滚
+                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
+            }
+        }
+        return RestResponse.fail(ApiConstants.RESULT_ERROR, "踢出用户失败");
     }
 
     @Override
@@ -292,7 +312,7 @@ public class MtCompanyUserService extends ServiceImpl<MtCompanyUserMapper, MtCom
                 .eq("delete_flag", ApiConstants.DELETE_NO)
         );
         //获取用户信息
-        List<Long> userIdList = ProjectUtils.getAttrList(mtCompanyUserList,"userId", null);
+        List<Long> userIdList = ProjectUtils.getAttrList(mtCompanyUserList, "userId", null);
         Map<Long, UserResponse> userIdToUserResponse = userService.getUserResponseByUserIdList(userIdList);
         return RestResponse.success(userIdToUserResponse.values(), ApiConstants.RESULT_SUCCESS, "获取急修工成功");
     }