Browse Source

1.代码合并遗漏

yuanliang 1 year ago
parent
commit
c5695f7eb4

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

@@ -781,19 +781,16 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, Student> impleme
                     new HashSet<>(ImmutableList.of(sysUser.getId()))));
         }
 
-        //  与客服建立好友
+        //  与随机一个客服建立好友
         String customerService = customerServiceConfig.getCustomerService();
-        if(StringUtils.isNotBlank(customerService)){
+        if (StringUtils.isNotBlank(customerService)) {
             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);
             }
         }
 

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

@@ -85,13 +85,7 @@ import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 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.*;
 import java.util.concurrent.TimeUnit;
 import java.util.stream.Collectors;
 
@@ -115,8 +109,6 @@ 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.concurrent.TimeUnit;
 import java.util.stream.Collectors;
 
@@ -487,15 +479,14 @@ public class TeacherServiceImpl extends ServiceImpl<TeacherDao, Teacher> impleme
         }
         //  与客服建立好友
         String customerService = customerServiceConfig.getCustomerService();
-        if(StringUtils.isNotBlank(customerService)){
+        if (StringUtils.isNotBlank(customerService)) {
             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);
             }
         }