Bläddra i källkod

1.调整新增老师、学生与随机一个客服成为好友

yuanliang 1 år sedan
förälder
incheckning
22b20e4ce6

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

@@ -648,19 +648,17 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, Student> impleme
                     new HashSet<>(ImmutableList.of(sysUser.getId()))));
         }
 
-        //  与客服建立好友
+        //  与随机一个客服建立好友
         String customerService = customerServiceConfig.getCustomerService();
         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) {
+            Random rand = new Random();
+            String mobile = phones.get(rand.nextInt(phones.size()));
+            SysUser friend = sysUserMapper.findUserByPhone(mobile);
+            if (friend != null) {
                 HashSet<Long> studentIds = new HashSet<>();
                 studentIds.add(student.getUserId());
-                imUserFriendService.saveUserFriend(teacherId, studentIds);
+                imUserFriendService.saveUserFriend(friend.getId(), studentIds);
             }
         }
 

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

@@ -66,15 +66,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.Optional;
-import java.util.Set;
+import java.util.*;
 import java.util.concurrent.TimeUnit;
 import java.util.stream.Collectors;
 
@@ -423,13 +415,13 @@ public class TeacherServiceImpl extends ServiceImpl<TeacherDao, Teacher> impleme
         String customerService = customerServiceConfig.getCustomerService();
         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) {
+                HashSet<Long> teacherIds = new HashSet<>();
+                teacherIds.add(teacher.getUserId());
+                imUserFriendService.saveUserFriend(friend.getId(), teacherIds);
             }
         }