Browse Source

Merge branch 'feature/0721-tenant'

yuanliang 1 year ago
parent
commit
c4e0c179c4

+ 6 - 6
cooleshow-auth/auth-server/src/main/java/com/yonge/cooleshow/auth/core/provider/PhoneAuthenticationProvider.java

@@ -180,12 +180,6 @@ public class PhoneAuthenticationProvider extends AbstractAuthenticationProvider
                     throw new LockedException("用户已锁定");
                     throw new LockedException("用户已锁定");
                 }
                 }
 
 
-                // 同账号,用户信息存在的情况
-                if (!user.getUserType().contains(clientId.toUpperCase())) {
-                    // 自动添加系统默认IM帐号为好友,并自动发送通知消息
-                    sysUserService.sendSysCustomerServiceFriendMessage(userInfo.getSysUser(), clientId.toUpperCase());
-                }
-
                 if (StringUtils.isNotBlank(deviceNum)) {
                 if (StringUtils.isNotBlank(deviceNum)) {
                     sysUserDeviceService.bindDevice(clientId, user.getId(), deviceNum);
                     sysUserDeviceService.bindDevice(clientId, user.getId(), deviceNum);
                 }
                 }
@@ -211,6 +205,12 @@ public class PhoneAuthenticationProvider extends AbstractAuthenticationProvider
                     throw new LockedException("用户不存在");
                     throw new LockedException("用户不存在");
                 }
                 }
 
 
+                // 同账号,用户信息存在的情况
+                if (!user.getUserType().contains(clientId.toUpperCase())) {
+                    // 自动添加系统默认IM帐号为好友,并自动发送通知消息
+                    sysUserService.sendSysCustomerServiceFriendMessage(userInfo.getSysUser(), clientId.toUpperCase());
+                }
+
                 user.setUpdateTime(new Date());
                 user.setUpdateTime(new Date());
                 if(StringUtils.isNotEmpty(loginUserType)){
                 if(StringUtils.isNotEmpty(loginUserType)){
                     if (StringUtils.equalsIgnoreCase(loginUserType, "TEACHER")) {
                     if (StringUtils.equalsIgnoreCase(loginUserType, "TEACHER")) {

+ 7 - 10
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/StudentServiceImpl.java

@@ -675,19 +675,16 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, Student> impleme
                     new HashSet<>(ImmutableList.of(sysUser.getId()))));
                     new HashSet<>(ImmutableList.of(sysUser.getId()))));
         }
         }
 
 
-        //  与客服建立好友
+        //  与随机一个客服建立好友
         String customerService = customerServiceConfig.getCustomerService();
         String customerService = customerServiceConfig.getCustomerService();
         if(StringUtils.isNotBlank(customerService)){
         if(StringUtils.isNotBlank(customerService)){
             List<String> phones = Arrays.stream(customerService.split(",")).collect(Collectors.toList());
             List<String> phones = Arrays.stream(customerService.split(",")).collect(Collectors.toList());
-            // 通过手机号获取用户ID
-            QueryWrapper<com.yonge.cooleshow.biz.dal.entity.SysUser> queryWrapper = new QueryWrapper<>();
-            queryWrapper.lambda().in(com.yonge.cooleshow.biz.dal.entity.SysUser::getPhone,phones);
-            List<com.yonge.cooleshow.biz.dal.entity.SysUser> sysUsers = sysUserMapper.selectList(queryWrapper);
-            Set<Long> userIds = sysUsers.stream().map(com.yonge.cooleshow.biz.dal.entity.SysUser::getId).collect(Collectors.toSet());
-            for (Long teacherId : userIds) {
-                HashSet<Long> studentIds = new HashSet<>();
-                studentIds.add(student.getUserId());
-                imUserFriendService.saveUserFriend(teacherId, studentIds);
+            Random rand = new Random();
+            String mobile = phones.get(rand.nextInt(phones.size()));
+            SysUser friend = sysUserMapper.findUserByPhone(mobile);
+            if (friend != null) {
+                imUserFriendService.registerUserBindCustomerService(student.getUserId(),
+                        Collections.singletonList(friend.getId()), ClientEnum.STUDENT);
             }
             }
         }
         }
 
 

+ 7 - 16
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/TeacherServiceImpl.java

@@ -68,15 +68,7 @@ import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.transaction.annotation.Transactional;
 
 
 import javax.annotation.Resource;
 import javax.annotation.Resource;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Optional;
-import java.util.Set;
+import java.util.*;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.TimeUnit;
 import java.util.stream.Collectors;
 import java.util.stream.Collectors;
 
 
@@ -438,13 +430,12 @@ public class TeacherServiceImpl extends ServiceImpl<TeacherDao, Teacher> impleme
         String customerService = customerServiceConfig.getCustomerService();
         String customerService = customerServiceConfig.getCustomerService();
         if(StringUtils.isNotBlank(customerService)){
         if(StringUtils.isNotBlank(customerService)){
             List<String> phones = Arrays.stream(customerService.split(",")).collect(Collectors.toList());
             List<String> phones = Arrays.stream(customerService.split(",")).collect(Collectors.toList());
-            // 通过手机号获取用户ID
-            QueryWrapper<com.yonge.cooleshow.biz.dal.entity.SysUser> queryWrapper = new QueryWrapper<>();
-            queryWrapper.lambda().in(com.yonge.cooleshow.biz.dal.entity.SysUser::getPhone,phones);
-            List<com.yonge.cooleshow.biz.dal.entity.SysUser> sysUsers = sysUserMapper.selectList(queryWrapper);
-            Set<Long> userIds = sysUsers.stream().map(com.yonge.cooleshow.biz.dal.entity.SysUser::getId).collect(Collectors.toSet());
-            if (!userIds.isEmpty()) {
-                imUserFriendService.saveUserTeacherFriend(teacher.getUserId(), userIds);
+            Random rand = new Random();
+            String mobile = phones.get(rand.nextInt(phones.size()));
+            SysUser friend = sysUserMapper.findUserByPhone(mobile);
+            if (friend != null) {
+                imUserFriendService.registerUserBindCustomerService(teacher.getUserId(),
+                        Collections.singletonList(friend.getId()), ClientEnum.TEACHER);
             }
             }
         }
         }