| 
					
				 | 
			
			
				@@ -1,9 +1,12 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 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.CollectionUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.baomidou.mybatisplus.core.toolkit.Wrappers; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.microsvc.toolkit.common.webportal.exception.BizException; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.yonge.cooleshow.auth.api.entity.SysUser; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.yonge.cooleshow.biz.dal.dao.StudentDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.yonge.cooleshow.biz.dal.dao.SubjectDao; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -11,15 +14,27 @@ import com.yonge.cooleshow.biz.dal.dao.TeacherDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.yonge.cooleshow.biz.dal.dao.UserBindingTeacherDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.yonge.cooleshow.biz.dal.dto.search.QueryMyFollowSearch; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.yonge.cooleshow.biz.dal.dto.search.StudentSearch; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import com.yonge.cooleshow.biz.dal.entity.*; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.yonge.cooleshow.biz.dal.entity.Student; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.yonge.cooleshow.biz.dal.entity.StudentTotal; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.yonge.cooleshow.biz.dal.entity.Subject; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.yonge.cooleshow.biz.dal.entity.TenantInfo; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.yonge.cooleshow.biz.dal.entity.UserBindingTeacher; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.yonge.cooleshow.biz.dal.entity.UserTenantAlbumRecord; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.yonge.cooleshow.biz.dal.enums.ClientEnum; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.yonge.cooleshow.biz.dal.mapper.SysUserMapper; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import com.yonge.cooleshow.biz.dal.service.*; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.yonge.cooleshow.biz.dal.service.ImGroupService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.yonge.cooleshow.biz.dal.service.ImUserFriendService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.yonge.cooleshow.biz.dal.service.StudentService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.yonge.cooleshow.biz.dal.service.StudentTotalService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.yonge.cooleshow.biz.dal.service.SysConfigService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.yonge.cooleshow.biz.dal.service.TenantInfoService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.yonge.cooleshow.biz.dal.service.UserTenantAlbumRecordService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.yonge.cooleshow.biz.dal.vo.MyFollow; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.yonge.cooleshow.biz.dal.vo.StudentHomeVo; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.yonge.cooleshow.biz.dal.vo.StudentVo; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.yonge.cooleshow.biz.dal.vo.TeacherVo; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.yonge.cooleshow.biz.dal.wrapper.StudentWrapper; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.yonge.cooleshow.common.constant.SysConfigConstant; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.yonge.cooleshow.common.entity.HttpResponseResult; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.yonge.cooleshow.common.enums.CacheNameEnum; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.yonge.cooleshow.common.enums.UserLockFlag; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -72,6 +87,12 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, Student> impleme 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private UserTenantAlbumRecordService userTenantAlbumRecordService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private SysConfigService sysConfigService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private ImGroupService imGroupService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @Override 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     public StudentVo detail(Long userId) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         return baseMapper.detail(userId); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -257,8 +278,9 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, Student> impleme 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         StudentVo studentVo = detailByPhone(info.getMobile()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        com.yonge.cooleshow.biz.dal.entity.SysUser sysUser = sysUserMapper.selectOne(Wrappers.<com.yonge.cooleshow.biz.dal.entity.SysUser>lambdaQuery() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                                                                                             .eq(com.yonge.cooleshow.biz.dal.entity.SysUser::getPhone, info.getMobile())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        com.yonge.cooleshow.biz.dal.entity.SysUser sysUser = 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                sysUserMapper.selectOne(Wrappers.<com.yonge.cooleshow.biz.dal.entity.SysUser>lambdaQuery() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        .eq(com.yonge.cooleshow.biz.dal.entity.SysUser::getPhone, info.getMobile())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         studentResp.setSysUser(sysUser); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if (Objects.isNull(studentVo)) { 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -281,7 +303,8 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, Student> impleme 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 studentResp.setUpdateFlag(true); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                com.yonge.cooleshow.biz.dal.entity.SysUser updateEntity = new com.yonge.cooleshow.biz.dal.entity.SysUser(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                com.yonge.cooleshow.biz.dal.entity.SysUser updateEntity = 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        new com.yonge.cooleshow.biz.dal.entity.SysUser(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 updateEntity.setId(sysUser.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 updateEntity.setUpdateTime(LocalDateTime.now()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 //updateEntity.setDelFlag(Optional.ofNullable(info.getLockFlag()).orElse(0)); // 激活帐号 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -337,11 +360,98 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, Student> impleme 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         return studentResp; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @Transactional(rollbackFor = Exception.class) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @Override 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public Boolean save(StudentWrapper.Student studentInfo) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (studentInfo.getId() != null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return createStudent(studentInfo); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return updateStudent(studentInfo); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private Boolean updateStudent(StudentWrapper.Student studentInfo) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        StudentVo student = detail(studentInfo.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (student == null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            throw new BizException("学生信息不存在"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        // 解绑 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (!studentInfo.getBindTenant()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            studentInfo.setTenantId(-1L); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            // 退群,删除好友 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            imUserFriendService.delFriendByTenantId(student.getTenantId(), student.getUserId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        // 手机号码修改 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (!student.getPhone().equals(studentInfo.getPhone())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            com.yonge.cooleshow.biz.dal.entity.SysUser sysUser = getOrCreateAccount(studentInfo); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            this.lambdaUpdate().set(Student::getSubjectId, studentInfo.getSubjectId()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    .set(Student::getTenantId, studentInfo.getTenantId()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    .set(Student::getUserId, sysUser.getId()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    .set(Student::getUpdateTime, new Date()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    .eq(Student::getUserId, studentInfo.getId()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    .update(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            Student newStudent = new Student(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            newStudent.setUserId(studentInfo.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            newStudent.setSubjectId(studentInfo.getSubjectId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            newStudent.setUpdateTime(new Date()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            newStudent.setTenantId(studentInfo.getTenantId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            this.getBaseMapper().updateById(newStudent); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return true; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private Boolean createStudent(StudentWrapper.Student studentInfo) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        com.yonge.cooleshow.biz.dal.entity.SysUser sysUser = getOrCreateAccount(studentInfo); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Student student = new Student(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        student.setUserId(sysUser.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        student.setTenantId(studentInfo.getTenantId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        student.setSubjectId(studentInfo.getSubjectId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        student.setCreateTime(new Date()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        student.setLockFlag(UserLockFlag.NORMAL); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        save(student); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return true; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private com.yonge.cooleshow.biz.dal.entity.SysUser getOrCreateAccount(StudentWrapper.Student studentInfo) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        QueryWrapper<com.yonge.cooleshow.biz.dal.entity.SysUser> sysUserQueryWrapper = new QueryWrapper<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        sysUserQueryWrapper.lambda().eq(com.yonge.cooleshow.biz.dal.entity.SysUser::getPhone, studentInfo.getPhone()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        List<com.yonge.cooleshow.biz.dal.entity.SysUser> sysUsers = sysUserMapper.selectList(sysUserQueryWrapper); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        com.yonge.cooleshow.biz.dal.entity.SysUser sysUser; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (!sysUsers.isEmpty()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            sysUser = sysUsers.get(0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (this.getBaseMapper().selectById(sysUser.getId()) != null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                throw new BizException("手机号已经注册学生账号"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            sysUser.setGender(studentInfo.getGender()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            sysUser.setBirthdate(studentInfo.getBirthdate()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            String userType = sysUser.getUserType(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            String studentUserType = "STUDENT"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (StringUtils.isEmpty(userType)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                sysUser.setUserType(studentUserType); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } else if (!userType.contains(studentUserType)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                sysUser.setUserType(userType + "," + studentUserType); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            sysUserMapper.updateById(sysUser); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            sysUser = JSON.parseObject(JSON.toJSONString(studentInfo), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    com.yonge.cooleshow.biz.dal.entity.SysUser.class); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            sysUser.setPhone(studentInfo.getPhone()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            sysUser.setAvatar(sysConfigService.findConfigValue(SysConfigConstant.DEFAULT_HEARD)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            sysUser.setGender(studentInfo.getGender()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            sysUser.setUserType("STUDENT"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            sysUser.setBirthdate(studentInfo.getBirthdate()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            sysUserMapper.insert(sysUser); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return sysUser; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      * 更新学生关联帐号 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-     * @param info StudentWrapper.UnionStudent 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * @param info        StudentWrapper.UnionStudent 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      * @param studentResp StudentWrapper.UnionStudentResp 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-     * @param student Student 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * @param student     Student 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private void updateStudentUnionStatus(StudentWrapper.UnionStudent info, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                           StudentWrapper.UnionStudentResp studentResp, Student student) { 
			 |