|  | @@ -11,7 +11,6 @@ import com.google.common.collect.Lists;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.auth.api.client.SysUserFeignService;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.auth.api.dto.RealnameAuthReq;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.auth.api.entity.SysUser;
 | 
	
		
			
				|  |  | -import com.yonge.cooleshow.auth.config.CustomerServiceConfig;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.biz.dal.dao.EmployeeDao;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.biz.dal.dao.StudentStarDao;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.biz.dal.dao.TeacherDao;
 | 
	
	
		
			
				|  | @@ -184,9 +183,6 @@ public class TeacherServiceImpl extends ServiceImpl<TeacherDao, Teacher> impleme
 | 
	
		
			
				|  |  |      private RealnameAuthenticationPlugin realnameAuthenticationPlugin;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @Autowired
 | 
	
		
			
				|  |  | -    private CustomerServiceConfig customerServiceConfig;
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -    @Autowired
 | 
	
		
			
				|  |  |      private SysUserMapper sysUserMapper;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @Autowired
 | 
	
	
		
			
				|  | @@ -251,6 +247,10 @@ public class TeacherServiceImpl extends ServiceImpl<TeacherDao, Teacher> impleme
 | 
	
		
			
				|  |  |                  detail.setUserStatus(UserStatusEnum.NORMAL);
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        // 系统客服数量
 | 
	
		
			
				|  |  | +        detail.setCustomerServiceNum(baseMapper.selectCustomerServiceV2().size());
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |          return detail;
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -654,14 +654,18 @@ public class TeacherServiceImpl extends ServiceImpl<TeacherDao, Teacher> impleme
 | 
	
		
			
				|  |  |          } else {
 | 
	
		
			
				|  |  |              // 客服状态变更,移交好友信息
 | 
	
		
			
				|  |  |              Boolean customerService = teacher.getCustomerService();
 | 
	
		
			
				|  |  | -            List<TeacherWrapper.CustomerServiceSendMsg2User> customerServiceSendMsg2User = new ArrayList<>();
 | 
	
		
			
				|  |  | +            //List<TeacherWrapper.CustomerServiceSendMsg2User> customerServiceSendMsg2User = new ArrayList<>();
 | 
	
		
			
				|  |  |              if (Boolean.TRUE.equals(customerService) && Boolean.FALSE.equals(teacherSubmitReq.getCustomerService())) {
 | 
	
		
			
				|  |  | -                customerServiceSendMsg2User.addAll(transferFriendV2(teacher.getUserId(), true));
 | 
	
		
			
				|  |  | +                //customerServiceSendMsg2User.addAll(transferFriendV2(teacher.getUserId(), true));
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                // 清除客服绑定关系
 | 
	
		
			
				|  |  |                  clearUserCustomerRelation(teacherSubmitReq.getUserId());
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                // 重置客服关系
 | 
	
		
			
				|  |  |                  this.update(null, new UpdateWrapper<Teacher>().lambda()
 | 
	
		
			
				|  |  |                          .set(Teacher::getCustomerId, null)
 | 
	
		
			
				|  |  | +                        .set(Teacher::getImCustomerId, "")
 | 
	
		
			
				|  |  |                          .eq(Teacher::getUserId, teacherSubmitReq.getUserId()));
 | 
	
		
			
				|  |  | -                teacher.setCustomerId(null);
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |              // 如果机构解绑,更新机构ID为-1
 | 
	
		
			
				|  |  |              if (Boolean.TRUE.equals(teacherSubmitReq.getBindTenant())) {
 | 
	
	
		
			
				|  | @@ -698,7 +702,7 @@ public class TeacherServiceImpl extends ServiceImpl<TeacherDao, Teacher> impleme
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |              // 交接后的客服发送消息
 | 
	
		
			
				|  |  | -            if (Boolean.TRUE.equals(customerService) && Boolean.FALSE.equals(teacherSubmitReq.getCustomerService())) {
 | 
	
		
			
				|  |  | +            /*if (Boolean.TRUE.equals(customerService) && Boolean.FALSE.equals(teacherSubmitReq.getCustomerService())) {
 | 
	
		
			
				|  |  |                  String customerMessage = sysConfigService.findConfigValue(SysConfigConstant.CUSTOMER_SERVICE_ADD_MSG);
 | 
	
		
			
				|  |  |                  String customerTitle = sysConfigService.findConfigValue(SysConfigConstant.CUSTOMER_SERVICE_ADD_MSG_TITLE);
 | 
	
		
			
				|  |  |                  for (TeacherWrapper.CustomerServiceSendMsg2User serviceSendMsg2User : customerServiceSendMsg2User) {
 | 
	
	
		
			
				|  | @@ -707,7 +711,7 @@ public class TeacherServiceImpl extends ServiceImpl<TeacherDao, Teacher> impleme
 | 
	
		
			
				|  |  |                      imUserFriendService.sendCustomerServiceAddFriendMessage(serviceSendMsg2User.getCustomerId(), customerTitle, customerMessage, serviceSendMsg2User.getStudentIds(),
 | 
	
		
			
				|  |  |                              ClientEnum.STUDENT);
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  | -            }
 | 
	
		
			
				|  |  | +            }*/
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -716,11 +720,19 @@ public class TeacherServiceImpl extends ServiceImpl<TeacherDao, Teacher> impleme
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      // 清除专属客服信息
 | 
	
		
			
				|  |  |      private void clearUserCustomerRelation(Long userId) {
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        String imCustomerServiceId = imGroupCoreService.getImUserId(String.valueOf(userId), ClientEnum.TEACHER.getCode());
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        // 重置老师关联客服绑定
 | 
	
		
			
				|  |  |          this.update(null, new UpdateWrapper<Teacher>().lambda()
 | 
	
		
			
				|  |  | -                .eq(Teacher::getCustomerId, userId)
 | 
	
		
			
				|  |  | +                .eq(Teacher::getImCustomerId, imCustomerServiceId)
 | 
	
		
			
				|  |  | +                .set(Teacher::getImCustomerId, "")
 | 
	
		
			
				|  |  |                  .set(Teacher::getCustomerId, null));
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        // 重置学生关联客服绑定
 | 
	
		
			
				|  |  |          studentService.update(null, new UpdateWrapper<Student>().lambda()
 | 
	
		
			
				|  |  | -                .eq(Student::getCustomerId, userId)
 | 
	
		
			
				|  |  | +                .eq(Student::getImCustomerId, imCustomerServiceId)
 | 
	
		
			
				|  |  | +                .set(Student::getImCustomerId, imCustomerServiceId)
 | 
	
		
			
				|  |  |                  .set(Student::getCustomerId, null));
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -1522,22 +1534,83 @@ public class TeacherServiceImpl extends ServiceImpl<TeacherDao, Teacher> impleme
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          // 冻结客服,移交好友给其他客服
 | 
	
		
			
				|  |  |          if (UserLockFlag.NORMAL.equals(teacher.getLockFlag()) && Boolean.TRUE.equals(customerService)) {
 | 
	
		
			
				|  |  | -            List<TeacherWrapper.CustomerServiceSendMsg2User> customerServiceSendMsg2User = transferFriendV2(teacherId, false);
 | 
	
		
			
				|  |  | +            // List<TeacherWrapper.CustomerServiceSendMsg2User> customerServiceSendMsg2User = transferFriendV2(teacherId, false);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            // 清除客服绑定关系
 | 
	
		
			
				|  |  |              clearUserCustomerRelation(teacherId);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            // 重置数据
 | 
	
		
			
				|  |  |              this.update(null, new UpdateWrapper<Teacher>().lambda()
 | 
	
		
			
				|  |  |                      .set(Teacher::getCustomerId, null)
 | 
	
		
			
				|  |  | +                    .set(Teacher::getImCustomerId, "")
 | 
	
		
			
				|  |  |                      .eq(Teacher::getUserId, teacherId));
 | 
	
		
			
				|  |  | -            teacher.setCustomerId(null);
 | 
	
		
			
				|  |  | -            for (TeacherWrapper.CustomerServiceSendMsg2User serviceSendMsg2User : customerServiceSendMsg2User) {
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            /*for (TeacherWrapper.CustomerServiceSendMsg2User serviceSendMsg2User : customerServiceSendMsg2User) {
 | 
	
		
			
				|  |  |                  String customerMessage = sysConfigService.findConfigValue(SysConfigConstant.CUSTOMER_SERVICE_ADD_MSG);
 | 
	
		
			
				|  |  |                  String customerTitle = sysConfigService.findConfigValue(SysConfigConstant.CUSTOMER_SERVICE_ADD_MSG_TITLE);
 | 
	
		
			
				|  |  |                  imUserFriendService.sendCustomerServiceAddFriendMessage(serviceSendMsg2User.getCustomerId(), customerTitle, customerMessage, serviceSendMsg2User.getTeacherIds(),
 | 
	
		
			
				|  |  |                          ClientEnum.TEACHER);
 | 
	
		
			
				|  |  |                  imUserFriendService.sendCustomerServiceAddFriendMessage(serviceSendMsg2User.getCustomerId(), customerTitle, customerMessage, serviceSendMsg2User.getStudentIds(),
 | 
	
		
			
				|  |  |                          ClientEnum.STUDENT);
 | 
	
		
			
				|  |  | -            }
 | 
	
		
			
				|  |  | +            }*/
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          teacher.setLockFlag(UserLockFlag.NORMAL.equals(teacher.getLockFlag()) ? UserLockFlag.LOCKED : UserLockFlag.NORMAL);
 | 
	
		
			
				|  |  |          this.updateById(teacher);
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    /**
 | 
	
		
			
				|  |  | +     * 系统默认客服用户
 | 
	
		
			
				|  |  | +     *
 | 
	
		
			
				|  |  | +     * @return List<Teacher>
 | 
	
		
			
				|  |  | +     */
 | 
	
		
			
				|  |  | +    @Override
 | 
	
		
			
				|  |  | +    public List<Teacher> getCustomerServiceV2() {
 | 
	
		
			
				|  |  | +        return baseMapper.selectCustomerServiceV2();
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    /**
 | 
	
		
			
				|  |  | +     * 查询客服好友数量
 | 
	
		
			
				|  |  | +     *
 | 
	
		
			
				|  |  | +     * @return List<StatGroupWrapper>
 | 
	
		
			
				|  |  | +     */
 | 
	
		
			
				|  |  | +    @Override
 | 
	
		
			
				|  |  | +    public List<StatGroupWrapper> getCustomerServiceMemberNums() {
 | 
	
		
			
				|  |  | +        return baseMapper.countCustomerServiceMemberNum();
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    /**
 | 
	
		
			
				|  |  | +     * 更新用户客服
 | 
	
		
			
				|  |  | +     *
 | 
	
		
			
				|  |  | +     * @param userId 用户ID
 | 
	
		
			
				|  |  | +     * @return String
 | 
	
		
			
				|  |  | +     */
 | 
	
		
			
				|  |  | +    @Override
 | 
	
		
			
				|  |  | +    public String updateUserCustomerService(Long userId) {
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        TeacherVo teacher = detail(userId);
 | 
	
		
			
				|  |  | +        if (Objects.isNull(teacher)) {
 | 
	
		
			
				|  |  | +            throw new BizException("老师不存在");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        // 学生已绑定客服,直接近回
 | 
	
		
			
				|  |  | +        if (StringUtils.isNotBlank(teacher.getImCustomerId())) {
 | 
	
		
			
				|  |  | +            return teacher.getImCustomerId();
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        // 随机分配系统客服
 | 
	
		
			
				|  |  | +        String imCustomerServiceId = imGroupCoreService.getSysRandomCustomerService();
 | 
	
		
			
				|  |  | +        if (StringUtils.isBlank(imCustomerServiceId)) {
 | 
	
		
			
				|  |  | +            throw new BizException("系统客服不存在");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        String customerServiceId = imGroupCoreService.analysisImUserId(imCustomerServiceId);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        // 更新用户绑定客服
 | 
	
		
			
				|  |  | +        lambdaUpdate()
 | 
	
		
			
				|  |  | +            .eq(Teacher::getUserId, userId)
 | 
	
		
			
				|  |  | +            .set(Teacher::getCustomerId, customerServiceId)
 | 
	
		
			
				|  |  | +            .set(Teacher::getImCustomerId, imCustomerServiceId)
 | 
	
		
			
				|  |  | +            .update();
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        return imCustomerServiceId;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  |  }
 |