Bladeren bron

客服调整

yuanliang 1 jaar geleden
bovenliggende
commit
5e8c66ca2f
17 gewijzigde bestanden met toevoegingen van 211 en 56 verwijderingen
  1. 25 0
      cooleshow-app/src/main/java/com/yonge/cooleshow/teacher/controller/StudentController.java
  2. 28 0
      cooleshow-app/src/main/java/com/yonge/cooleshow/teacher/controller/TeacherController.java
  3. 2 2
      cooleshow-auth/auth-api/src/main/java/com/yonge/cooleshow/auth/config/CustomerServiceConfig.java
  4. 3 0
      cooleshow-auth/auth-server/src/main/java/com/yonge/cooleshow/auth/dal/dao/SysUserDao.java
  5. 5 13
      cooleshow-auth/auth-server/src/main/java/com/yonge/cooleshow/auth/service/impl/SysUserServiceImpl.java
  6. 17 0
      cooleshow-auth/auth-server/src/main/resources/config/mybatis/SysUserMapper.xml
  7. 2 0
      cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/dao/TeacherDao.java
  8. 3 0
      cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/dto/req/TeacherSubmitReq.java
  9. 3 0
      cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/dto/search/TeacherSearch.java
  10. 4 0
      cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/entity/Teacher.java
  11. 2 0
      cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/TeacherService.java
  12. 9 1
      cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/CustomerServiceBatchSendingServiceImpl.java
  13. 5 11
      cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/StudentServiceImpl.java
  14. 57 29
      cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/TeacherServiceImpl.java
  15. 2 0
      cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/vo/TeacherVo.java
  16. 9 0
      cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/wrapper/teacher/TeacherWrapper.java
  17. 35 0
      cooleshow-user/user-biz/src/main/resources/config/mybatis/TeacherMapper.xml

+ 25 - 0
cooleshow-app/src/main/java/com/yonge/cooleshow/teacher/controller/StudentController.java

@@ -5,10 +5,12 @@ import com.yonge.cooleshow.auth.api.client.SysUserFeignService;
 import com.yonge.cooleshow.auth.api.entity.SysUser;
 import com.yonge.cooleshow.biz.dal.dto.search.StudentSearch;
 import com.yonge.cooleshow.biz.dal.entity.Student;
+import com.yonge.cooleshow.biz.dal.entity.Teacher;
 import com.yonge.cooleshow.biz.dal.entity.TenantGroup;
 import com.yonge.cooleshow.biz.dal.enums.ClientEnum;
 import com.yonge.cooleshow.biz.dal.service.ImGroupService;
 import com.yonge.cooleshow.biz.dal.service.StudentService;
+import com.yonge.cooleshow.biz.dal.service.TeacherService;
 import com.yonge.cooleshow.biz.dal.service.TenantGroupService;
 import com.yonge.cooleshow.biz.dal.vo.StudentVo;
 import com.yonge.cooleshow.common.controller.BaseController;
@@ -16,15 +18,20 @@ import com.yonge.cooleshow.common.entity.HttpResponseResult;
 import com.yonge.cooleshow.common.enums.UserLockFlag;
 import com.yonge.cooleshow.common.enums.UserStatusEnum;
 import com.yonge.cooleshow.common.enums.YesOrNoEnum;
+import com.yonge.toolset.base.exception.BizException;
 import com.yonge.toolset.base.page.PageInfo;
 import com.yonge.toolset.base.util.StringUtil;
 import com.yonge.toolset.mybatis.support.PageUtil;
 import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiImplicitParam;
+import io.swagger.annotations.ApiImplicitParams;
 import io.swagger.annotations.ApiOperation;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.HttpStatus;
+import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
@@ -53,6 +60,9 @@ public class StudentController extends BaseController {
     @Autowired
     private TenantGroupService tenantGroupService;
 
+    @Autowired
+    private TeacherService teacherService;
+
 
     @ApiOperation(value = "查询指定学员信息-融云token")
     @GetMapping("/queryUserById")
@@ -75,6 +85,21 @@ public class StudentController extends BaseController {
         return succeed(studentService.detail(userId));
     }
 
+    @GetMapping("/detail/{id}")
+    public HttpResponseResult<StudentVo> detail(@PathVariable("id") Long id) {
+        SysUser user = sysUserFeignService.queryUserInfo();
+        Teacher teacher = teacherService.getById(user.getId());
+        if (Boolean.FALSE.equals(teacher.getCustomerService())) {
+            throw new BizException("权限不足");
+        }
+        StudentVo detail = studentService.detail(id);
+        if (detail != null && detail.getTenantGroupId() != null) {
+            TenantGroup group = tenantGroupService.getById(detail.getTenantGroupId());
+            detail.setTenantGroupName(group == null ? "" : group.getName());
+        }
+        return succeed(detail);
+    }
+
     /**
      * 查询老师所属机构下所有的学生
      *

+ 28 - 0
cooleshow-app/src/main/java/com/yonge/cooleshow/teacher/controller/TeacherController.java

@@ -7,8 +7,10 @@ import com.yonge.cooleshow.auth.api.entity.SysUser;
 import com.yonge.cooleshow.biz.dal.dto.TeacherDto;
 import com.yonge.cooleshow.biz.dal.entity.Subject;
 import com.yonge.cooleshow.biz.dal.entity.Teacher;
+import com.yonge.cooleshow.biz.dal.entity.TeacherStyleVideo;
 import com.yonge.cooleshow.biz.dal.entity.TenantInfo;
 import com.yonge.cooleshow.biz.dal.entity.TenantUnbindRecord;
+import com.yonge.cooleshow.biz.dal.enums.AuthStatusEnum;
 import com.yonge.cooleshow.biz.dal.enums.ClientEnum;
 import com.yonge.cooleshow.biz.dal.service.SmsCodeService;
 import com.yonge.cooleshow.biz.dal.service.SubjectService;
@@ -30,13 +32,18 @@ import com.yonge.toolset.base.util.StringUtil;
 import com.yonge.toolset.mybatis.support.PageUtil;
 import com.yonge.toolset.utils.idcard.IdcardInfoExtractor;
 import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiImplicitParam;
+import io.swagger.annotations.ApiImplicitParams;
 import io.swagger.annotations.ApiOperation;
 import io.swagger.annotations.ApiParam;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.HttpStatus;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.util.CollectionUtils;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
@@ -83,6 +90,27 @@ public class TeacherController extends BaseController {
         return teacherService.queryUserInfo(user.getId());
     }
 
+
+    /**
+     * 查询单条
+     */
+    @GetMapping("/detail/{id}")
+    public HttpResponseResult<TeacherVo> detail(@PathVariable("id") Long userId) {
+        SysUser user = sysUserFeignService.queryUserInfo();
+        Teacher teacher = teacherService.getById(user.getId());
+        if (Boolean.FALSE.equals(teacher.getCustomerService())) {
+            throw new BizException("权限不足");
+        }
+
+        TeacherVo detail = teacherService.findTeacherDetailInfo(userId);
+        if (null != detail && !CollectionUtils.isEmpty(detail.getStyleVideo())) {
+            List<TeacherStyleVideo> styleVideo = detail.getStyleVideo();
+            List<TeacherStyleVideo> collect = styleVideo.stream().filter(o -> AuthStatusEnum.PASS.equals(o.getAuthStatus())).collect(Collectors.toList());
+            detail.setStyleVideo(collect);
+        }
+        return succeed(detail);
+    }
+
     @ApiOperation(value = "开通直播")
     @GetMapping("/openLive")
     public HttpResponseResult<Boolean> openLive() {

+ 2 - 2
cooleshow-auth/auth-api/src/main/java/com/yonge/cooleshow/auth/config/CustomerServiceConfig.java

@@ -16,8 +16,8 @@ import java.io.Serializable;
 @Component
 public class CustomerServiceConfig implements Serializable {
 
-    @Value("${app.customer.service:17740683946}")
-    private String customerService;
+//    @Value("${app.customer.service:17740683946}")
+//    private String customerService;
     @Value("${app.customer.message:}")
     private String customerMessage;
     @Value("${app.customer.title:}")

+ 3 - 0
cooleshow-auth/auth-server/src/main/java/com/yonge/cooleshow/auth/dal/dao/SysUserDao.java

@@ -185,4 +185,7 @@ public interface SysUserDao extends BaseDAO<Long, SysUser> {
     void updateStudentHideFlag(@Param("userId") Long userId, @Param("hideFlag") int hideFlag);
 
     void updateAvatar(@Param("clientId") String clientId, @Param("avatar") String avatar,@Param("id") Long id);
+
+    SysUser getCustomerServiceByFriendLeast();
+
 }

+ 5 - 13
cooleshow-auth/auth-server/src/main/java/com/yonge/cooleshow/auth/service/impl/SysUserServiceImpl.java

@@ -3,6 +3,7 @@ package com.yonge.cooleshow.auth.service.impl;
 import com.alibaba.fastjson.JSON;
 import com.google.common.collect.Lists;
 import com.yonge.cooleshow.api.feign.AdminFeignService;
+import com.yonge.cooleshow.api.feign.TeacherFeignService;
 import com.yonge.cooleshow.api.feign.dto.UserFriendInfoVO;
 import com.yonge.cooleshow.auth.api.dto.QRLoginDto;
 import com.yonge.cooleshow.auth.api.dto.RealnameAuthReq;
@@ -218,24 +219,15 @@ public class SysUserServiceImpl extends BaseServiceImpl<Long, SysUser> implement
 
             ThreadPool.getExecutor().submit(() -> {
 
-                String customerService = customerServiceConfig.getCustomerService();
-                if (StringUtils.isNotEmpty(customerService)) {
-
-                    List<String> collect = Arrays.stream(customerService.split(",")).collect(Collectors.toList());
-
-                    Random rand = new Random();
-                    String mobile = collect.get(rand.nextInt(collect.size()));
-
-                    // 系统客服好友
-                    SysUser friend = sysUserDao.queryByPhone(mobile);
-
+                SysUser customerService = sysUserDao.getCustomerServiceByFriendLeast();
+                if (customerService != null) {
                     // 发送添加系统客服好友消息
                     HttpResponseResult<Boolean> result = adminFeignService.customerService(UserFriendInfoVO.builder()
                             .userId(sysUser.getId())
                             .clientType(clientType)
-                            .friendIds(Lists.newArrayList(friend.getId()))
+                            .friendIds(Lists.newArrayList(customerService.getId()))
                             .build());
-                    log.info("sendSysCustomerServiceFriendMessage mobile={}, ret={}", mobile, JSON.toJSONString(result));
+                    log.info("sendSysCustomerServiceFriendMessage mobile={}, ret={}", customerService.getPhone(), JSON.toJSONString(result));
                 }
 
             });

+ 17 - 0
cooleshow-auth/auth-server/src/main/resources/config/mybatis/SysUserMapper.xml

@@ -382,4 +382,21 @@
             update sys_user set avatar_ = #{avatar} where id_ = #{id}
         </if>
     </update>
+
+    <select id="getCustomerServiceByFriendLeast" resultMap="SysUser">
+        select t.*
+        from (SELECT te.user_id_,
+                     count(distinct iuf.friend_id_) friends
+              from teacher te
+                       left join sys_user su on te.user_id_ = su.id_
+                       left join im_user_friend iuf on te.user_id_ = iuf.user_id_
+              where te.lock_flag_ = 0
+                and te.customer_service_ = 1
+                and su.del_flag_ = 0
+                and su.lock_flag_ = 0
+              group by te.user_id_
+              order by friends
+              limit 1) t
+                 left join sys_user m on m.id_ = t.user_id_
+    </select>
 </mapper>

+ 2 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/dao/TeacherDao.java

@@ -115,4 +115,6 @@ public interface TeacherDao extends BaseMapper<Teacher> {
     List<TenantInfoWrapper.UserCount> countTeacherByTenantIds(@Param("tenantIdList") List<Long> tenantIdList);
 
     Integer queryTeacherCounts(@Param("id") Long id);
+
+    Teacher getCustomerServiceByFriendLeast();
 }

+ 3 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/dto/req/TeacherSubmitReq.java

@@ -65,6 +65,9 @@ public class TeacherSubmitReq implements Serializable {
     @ApiModelProperty(value = "后台修改人",hidden = true)
     private Long updateBy;
 
+    @ApiModelProperty("是否客服")
+    private Boolean customerService;
+
     public Long getUserId() {
         return userId;
     }

+ 3 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/dto/search/TeacherSearch.java

@@ -78,6 +78,9 @@ public class TeacherSearch extends QueryInfo{
 	@ApiModelProperty("老师ID")
 	private Long userId;
 
+	@ApiModelProperty("是否客服")
+	private Boolean customerService;
+
 	@ApiModelProperty(value = "排序方式, 默认 create_time_ desc", hidden = true)
 	private String orderBy;
 	public YesOrNoEnum getTrainFlag() {

+ 4 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/entity/Teacher.java

@@ -251,6 +251,10 @@ public class Teacher implements Serializable {
     @TableField(value = "im_device_id_")
     private String imDeviceId;
 
+    @ApiModelProperty("是否是客服")
+    @TableField(value = "customer_service_")
+    private Boolean customerService;
+
     public ESettlementFrom getSettlementFrom() {
         return settlementFrom;
     }

+ 2 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/TeacherService.java

@@ -186,4 +186,6 @@ public interface TeacherService extends IService<Teacher> {
     UserPaymentOrderWrapper.AccountTenantTo teacherSettlementFrom(Long teacherId,Long recomUserId);
 
     Map<Long, Teacher> getMapByIds(List<Long> teacherIds);
+
+    List<Teacher> getCustomerService();
 }

+ 9 - 1
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/CustomerServiceBatchSendingServiceImpl.java

@@ -1,6 +1,7 @@
 package com.yonge.cooleshow.biz.dal.service.impl;
 
 import com.alibaba.fastjson.JSON;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -211,7 +212,14 @@ public class CustomerServiceBatchSendingServiceImpl extends ServiceImpl<Customer
         // 发送客服ID
         String customerService = info.getMobile();
         if (StringUtils.isBlank(customerService)) {
-            customerService = customerServiceConfig.getCustomerService();
+            List<Long> teacherIds = teacherService.getCustomerService().stream().map(Teacher::getUserId).collect(Collectors.toList());
+            if (!teacherIds.isEmpty()) {
+                customerService = sysUserMapper.selectList(new QueryWrapper<SysUser>().lambda()
+                                .in(SysUser::getId, teacherIds))
+                        .stream()
+                        .map(SysUser::getPhone)
+                        .collect(Collectors.joining(","));
+            }
         }
         if (StringUtils.isNotEmpty(customerService)) {
 

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

@@ -853,17 +853,11 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, Student> impleme
             addBindUnBindRecord(student.getUserId(), student.getTenantId(), true);
         }
 
-        //  与随机一个客服建立好友
-        String customerService = customerServiceConfig.getCustomerService();
-        if (StringUtils.isNotBlank(customerService)) {
-            List<String> phones = Arrays.stream(customerService.split(",")).collect(Collectors.toList());
-            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);
-            }
+        //  与好友数量最少的客服建立好友关系
+        Teacher customerService = teacherDao.getCustomerServiceByFriendLeast();
+        if (customerService != null) {
+            imUserFriendService.registerUserBindCustomerService(student.getUserId(),
+                    Collections.singletonList(customerService.getUserId()), ClientEnum.STUDENT);
         }
 
         // 加入机构小组群

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

@@ -7,7 +7,6 @@ import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.google.common.collect.Lists;
-import com.microsvc.toolkit.middleware.rtc.enums.EDeviceMessageType;
 import com.yonge.cooleshow.auth.api.client.SysUserFeignService;
 import com.yonge.cooleshow.auth.api.dto.RealnameAuthReq;
 import com.yonge.cooleshow.auth.api.entity.SysUser;
@@ -48,10 +47,8 @@ import com.yonge.cooleshow.biz.dal.mapper.TenantAlbumMapper;
 import com.yonge.cooleshow.biz.dal.mapper.TenantAlbumRefMapper;
 import com.yonge.cooleshow.biz.dal.mapper.TenantUnbindHistoryMapper;
 import com.yonge.cooleshow.biz.dal.mapper.TenantUnbindRecordMapper;
-import com.yonge.cooleshow.biz.dal.queryInfo.TeacherQueryInfo;
 import com.yonge.cooleshow.biz.dal.service.*;
 import com.yonge.cooleshow.biz.dal.vo.HotTeacherVo;
-import com.yonge.cooleshow.biz.dal.vo.MusicSheetUploadCountVo;
 import com.yonge.cooleshow.biz.dal.vo.MyFens;
 import com.yonge.cooleshow.biz.dal.vo.TeacherAuthEntryRecordVo;
 import com.yonge.cooleshow.biz.dal.vo.TeacherHomeVo;
@@ -61,8 +58,6 @@ import com.yonge.cooleshow.biz.dal.wrapper.StatGroupWrapper;
 import com.yonge.cooleshow.biz.dal.wrapper.UserPaymentOrderWrapper;
 import com.yonge.cooleshow.biz.dal.wrapper.im.ImGroupWrapper;
 import com.yonge.cooleshow.biz.dal.wrapper.teacher.TeacherWrapper;
-import com.yonge.cooleshow.biz.dal.wrapper.StatGroupWrapper;
-import com.yonge.cooleshow.biz.dal.wrapper.teacher.TeacherWrapper;
 import com.yonge.cooleshow.common.constant.SysConfigConstant;
 import com.yonge.cooleshow.common.entity.HttpResponseResult;
 import com.yonge.cooleshow.common.enums.CacheNameEnum;
@@ -94,17 +89,7 @@ import java.util.stream.Collectors;
 
 import static com.yonge.cooleshow.biz.dal.constant.LiveRoomConstant.TEACHER_TEMP_LIVE_ROOM;
 import org.apache.commons.lang3.StringUtils;
-import org.redisson.api.RMap;
-import org.redisson.api.RedissonClient;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.BeanUtils;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
-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;
@@ -112,11 +97,6 @@ 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;
-
-import static com.yonge.cooleshow.biz.dal.constant.LiveRoomConstant.TEACHER_TEMP_LIVE_ROOM;
 
 @Service
 public class TeacherServiceImpl extends ServiceImpl<TeacherDao, Teacher> implements TeacherService {
@@ -599,15 +579,11 @@ public class TeacherServiceImpl extends ServiceImpl<TeacherDao, Teacher> impleme
             sendBindUnBindSMS(teacher.getUserId(), teacherSubmitReq.getPhone(), MessageTypeEnum.TEACHER_BIND_TENANT, teacher.getTenantId());
 
             //  与客服建立好友
-            String customerService = customerServiceConfig.getCustomerService();
-            if (StringUtils.isNotBlank(customerService)) {
-                List<String> phones = Arrays.stream(customerService.split(",")).collect(Collectors.toList());
-                Random rand = new Random();
-                String mobile = phones.get(rand.nextInt(phones.size()));
-                SysUser friend = sysUserMapper.findUserByPhone(mobile);
-                if (friend != null) {
+            if (!Boolean.TRUE.equals(teacher.getCustomerService())) {
+                Teacher customerServiceTeacher = getCustomerServiceByFriendLeast();
+                if (customerServiceTeacher != null) {
                     imUserFriendService.registerUserBindCustomerService(teacher.getUserId(),
-                            Collections.singletonList(friend.getId()), ClientEnum.TEACHER);
+                            Collections.singletonList(customerServiceTeacher.getUserId()), ClientEnum.TEACHER);
                 }
             }
         } else {
@@ -631,6 +607,11 @@ public class TeacherServiceImpl extends ServiceImpl<TeacherDao, Teacher> impleme
                 updateTenant(updateTenant, teacherSubmitReq.getUpdateBy());
             }
 
+            // 客服状态变更,移交好友信息
+            if (Boolean.TRUE.equals(teacher.getCustomerService()) && Boolean.FALSE.equals(teacherSubmitReq.getCustomerService())) {
+                transferFriend(teacher.getUserId());
+            }
+
             teacher.setUpdateTime(new Date());
             teacher = getTeacherDetil(teacher, teacherSubmitReq);
             if (null == teacher.getEntryAuthDate() || null == teacher.getMusicianDate()) {
@@ -648,6 +629,33 @@ public class TeacherServiceImpl extends ServiceImpl<TeacherDao, Teacher> impleme
         return teacher;
     }
 
+    // 客服好友移交给其他客服
+    private void transferFriend(Long userId) {
+        List<ImUserFriend> friendList = imUserFriendService.lambdaQuery()
+                .eq(ImUserFriend::getUserId, userId)
+                .eq(ImUserFriend::getClientType, ClientEnum.TEACHER)
+                .list();
+        if (friendList.isEmpty()) { // 没有好友
+            return;
+        }
+        List<Teacher> customerService = getCustomerService();
+        List<Long> teacherIdList = customerService.stream().map(Teacher::getUserId).collect(Collectors.toList());
+        teacherIdList.removeIf(n->n.equals(userId));
+        if (teacherIdList.isEmpty()) { // 没有客服
+            return;
+        }
+        List<Long> friendIdList = friendList.stream().map(ImUserFriend::getFriendId).collect(Collectors.toList());
+        friendIdList.removeIf(teacherIdList::contains);
+        if (friendIdList.isEmpty()) { // 有一个客服好友
+            return;
+        }
+
+        //todo
+
+
+
+    }
+
     /***
      * 封装用户信息
      * @author liweifan
@@ -700,6 +708,7 @@ public class TeacherServiceImpl extends ServiceImpl<TeacherDao, Teacher> impleme
         teacher.setSettlementFrom(teacherSubmitReq.getSettlementFrom());
         teacher.setTenantId(teacherSubmitReq.getTenantId() == null ? -1L : teacherSubmitReq.getTenantId());
         teacher.setAvatar(Optional.ofNullable(teacherSubmitReq.getAvatar()).orElse(teacher.getAvatar()));
+        teacher.setCustomerService(teacherSubmitReq.getCustomerService());
         if (StringUtil.isEmpty(teacherSubmitReq.getTeacherType())) {
             return teacher;
         }
@@ -1117,7 +1126,10 @@ public class TeacherServiceImpl extends ServiceImpl<TeacherDao, Teacher> impleme
                 });
             }
             // 删除好友关系
-            imUserFriendService.delStudentFriendByTenantId(teacher.getTenantId(), teacher.getUserId(), ClientEnum.TEACHER.getCode());
+            Boolean customerService = teacher.getCustomerService();
+            if (Boolean.FALSE.equals(customerService)) {
+                imUserFriendService.delStudentFriendByTenantId(teacher.getTenantId(), teacher.getUserId(), ClientEnum.TEACHER.getCode());
+            }
             addBindUnBindRecord(teacher.getUserId(), teacher.getTenantId(), false);
             SysUser sysUser = sysUserMapper.getByUserId(teacher.getUserId());
             sendBindUnBindSMS(teacher.getUserId(), sysUser.getPhone(), MessageTypeEnum.TEACHER_UNBIND_TENANT, teacher.getTenantId());
@@ -1250,4 +1262,20 @@ public class TeacherServiceImpl extends ServiceImpl<TeacherDao, Teacher> impleme
         sysMessageService.batchSendMessage(MessageSenderPluginContext.MessageSender.AWSMS, messageType,
                 receivers, null, 0, null, ClientEnum.SYSTEM.getCode(), tenantInfo.getName());
     }
+
+    /**
+     * 获取学生好友最少的一个客服
+     * @return 客服
+     */
+    private Teacher getCustomerServiceByFriendLeast() {
+        return this.getBaseMapper().getCustomerServiceByFriendLeast();
+    }
+
+    @Override
+    public List<Teacher> getCustomerService() {
+        return this.lambdaQuery()
+                .eq(Teacher::getCustomerService, true)
+                .eq(Teacher::getLockFlag, false)
+                .list();
+    }
 }

+ 2 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/vo/TeacherVo.java

@@ -102,6 +102,8 @@ public class TeacherVo extends Teacher {
     @ApiModelProperty("机构小组名称")
     private String tenantGroupName;
 
+    @ApiModelProperty("是否客服")
+    private Boolean customerService;
 
     public YesOrNoEnum getDelFlag() {
         return delFlag;

+ 9 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/wrapper/teacher/TeacherWrapper.java

@@ -158,4 +158,13 @@ public class TeacherWrapper {
         @ApiModelProperty("下载地址")
         private String downloadPath;
     }
+
+
+    @Data
+    public static class TeacherFriend {
+
+        private Long teacherId;
+
+        private Integer friendNums;
+    }
 }

+ 35 - 0
cooleshow-user/user-biz/src/main/resources/config/mybatis/TeacherMapper.xml

@@ -40,6 +40,7 @@
         <result column="create_time_" property="createTime"/>
         <result column="update_time_" property="updateTime"/>
         <result column="im_device_id_" property="imDeviceId"/>
+        <result column="customer_service_" property="customerService"/>
     </resultMap>
 
     <resultMap id="HotTeacherVoMap" type="com.yonge.cooleshow.biz.dal.vo.HotTeacherVo">
@@ -91,6 +92,7 @@
         , t.tenant_id_ as tenantId
         , t.settlement_from_ as settlementFrom
         , t.im_device_id_ as imDeviceId
+        , t.customer_service_ as customerService
     </sql>
 
     <!-- 分页查询 -->
@@ -192,6 +194,9 @@
             <if test="param.tenantName != null and param.tenantName.trim() != ''">
                 and ti.name_ like concat('%',#{param.tenantName},'%')
             </if>
+            <if test="param.customerService != null">
+                AND t.customer_service_ = #{param.customerService}
+            </if>
         </where>
         <choose>
             <when test="param.orderBy != null and param.orderBy.trim() != ''">
@@ -402,4 +407,34 @@
         </where>
     </select>
     <!--老师学生人数统计-->
+
+    <select id="getCustomerServiceByFriendLeast" resultMap="BaseResultMap">
+        select
+        t.*
+        from
+        ( SELECT
+        te.user_id_,
+        count(distinct iuf.friend_id_) friends
+        from teacher te
+        left join sys_user su on te.user_id_ = su.id_
+        left join im_user_friend iuf on te.user_id_ = iuf.user_id_
+        where te.lock_flag_ = 0 and te.customer_service_ = 1 and su.del_flag_ = 0 and su.lock_flag_ = 0
+        group by te.user_id_
+        order by friends
+        limit 1) m
+        left join teacher t on m.user_id_ = t.user_id_
+    </select>
+
+    <select id="getCustomerServiceFriendNums" resultType="com.yonge.cooleshow.biz.dal.wrapper.teacher.TeacherWrapper$TeacherFriend">
+        SELECT te.user_id_                    teacherId,
+               count(distinct iuf.friend_id_) friendNums
+        from teacher te
+                 left join sys_user su on te.user_id_ = su.id_
+                 left join im_user_friend iuf on te.user_id_ = iuf.user_id_
+        where te.lock_flag_ = 0
+          and te.customer_service_ = 1
+          and su.del_flag_ = 0
+          and su.lock_flag_ = 0
+        group by te.user_id_
+    </select>
 </mapper>