| 
					
				 | 
			
			
				@@ -1,13 +1,22 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 package com.yonge.cooleshow.tenant.controller.open; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.alibaba.fastjson.JSON; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.google.common.collect.ImmutableList; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.yonge.cooleshow.auth.api.client.SysUserFeignService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.yonge.cooleshow.auth.api.entity.SysUser; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.yonge.cooleshow.biz.dal.entity.ImGroupMember; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.yonge.cooleshow.biz.dal.entity.Student; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.yonge.cooleshow.biz.dal.entity.Teacher; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.yonge.cooleshow.biz.dal.entity.TenantInfo; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.yonge.cooleshow.biz.dal.enums.ClientEnum; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.yonge.cooleshow.biz.dal.enums.ImGroupMemberRoleType; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.yonge.cooleshow.biz.dal.enums.MessageTypeEnum; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.yonge.cooleshow.biz.dal.service.ImGroupMemberService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.yonge.cooleshow.biz.dal.service.ImGroupService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.yonge.cooleshow.biz.dal.service.ImUserFriendService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.yonge.cooleshow.biz.dal.service.SmsCodeService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.yonge.cooleshow.biz.dal.service.StudentService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.yonge.cooleshow.biz.dal.service.TeacherService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.yonge.cooleshow.biz.dal.service.TenantInfoService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.yonge.cooleshow.biz.dal.wrapper.StudentWrapper; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.yonge.cooleshow.common.controller.BaseController; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -16,6 +25,7 @@ import com.yonge.cooleshow.tenant.vo.StudentVo; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.yonge.toolset.base.exception.BizException; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import io.swagger.annotations.Api; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import io.swagger.annotations.ApiOperation; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import lombok.extern.slf4j.Slf4j; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.apache.commons.lang3.StringUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.springframework.beans.factory.annotation.Autowired; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.springframework.validation.annotation.Validated; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -25,7 +35,11 @@ import org.springframework.web.bind.annotation.RequestMapping; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.springframework.web.bind.annotation.RestController; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import javax.annotation.Resource; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import java.util.HashSet; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import java.util.List; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import java.util.stream.Collectors; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+@Slf4j 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 @RestController 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 @RequestMapping("/open/student") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 @Api(value = "学生表", tags = "学生表") 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -34,6 +48,9 @@ public class OpenStudentController extends BaseController { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private StudentService studentService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private TeacherService teacherService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private TenantInfoService tenantInfoService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @Resource 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -42,6 +59,15 @@ public class OpenStudentController extends BaseController { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private SmsCodeService smsCodeService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private ImUserFriendService imUserFriendService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private ImGroupService imGroupService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private ImGroupMemberService imGroupMemberService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @PostMapping("/save") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @ApiOperation(value = "新增/修改", notes = "传入Student,换绑时按照返回错误码5004判断,是否需要换绑,updateTenant=true表示换绑") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     public HttpResponseResult<Boolean> save(@Validated @RequestBody StudentVo.Student student) { 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -78,10 +104,30 @@ public class OpenStudentController extends BaseController { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             if (one != null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 if (one.getTenantId().equals(-1L)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     throw new BizException("该手机号已经注册为平台学生"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                } else if (!one.getTenantId().equals(tenantId) && (student.getUpdateTenant() == null || 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if (one.getTenantId().equals(tenantId)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    throw new BizException("已经注册当前机构,请勿重复注册"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                // 转到其他机构 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if ((student.getUpdateTenant() == null || 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                         !student.getUpdateTenant())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     throw new BizException(5004, "该手机号已经注册为其他平台学生"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                // 退群 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                List<ImGroupMember> groupMembers = imGroupMemberService.lambdaQuery() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        .eq(ImGroupMember::getRoleType, ImGroupMemberRoleType.STUDENT) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        .eq(ImGroupMember::getIsAdmin, false) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        .eq(ImGroupMember::getUserId, one.getUserId()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        .list(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                List<String> groupIdList = groupMembers.stream().map(ImGroupMember::getGroupId) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        .distinct().collect(Collectors.toList()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                groupIdList.forEach(groupId -> { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        imGroupService.quit(groupId, one.getUserId(), ClientEnum.STUDENT); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    } catch (Exception e) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        log.error("学生注册,切换机构退群失败:{}", e.getMessage()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             student.setId(studentId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -90,6 +136,16 @@ public class OpenStudentController extends BaseController { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         StudentWrapper.Student studentInfo = JSON.parseObject(JSON.toJSONString(student), StudentWrapper.Student.class); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         studentInfo.setTenantId(tenantInfo.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         studentService.save(studentInfo); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        // 加好友 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (student.getId() == null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            SysUser sysUser = sysUserFeignService.queryUserByMobile(student.getPhone()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            // 自动与机构老师成为好友 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            List<Teacher> teacherList = teacherService.lambdaQuery() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    .eq(Teacher::getTenantId, tenantId).list(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            teacherList.forEach(next -> imUserFriendService.saveUserFriend(next.getUserId(), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    new HashSet<>(ImmutableList.of(sysUser.getId())))); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         return succeed(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 } 
			 |