Browse Source

Merge branch 'feature/1204-tenant' into online

yuanliang 11 months ago
parent
commit
d5d03c42db

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

@@ -699,10 +699,10 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, Student> impleme
         if (!student.getPhone().equals(studentInfo.getPhone())) {
             updatePhone = true;
             SysUser oldSysUser = sysUserMapper.getByUserId(studentInfo.getId());
-            com.yonge.cooleshow.biz.dal.entity.SysUser sysUser = getOrCreateAccount(studentInfo, oldSysUser.getPassword());
+            com.yonge.cooleshow.biz.dal.entity.SysUser sysUser = updateAccount(studentInfo, oldSysUser);
             this.lambdaUpdate().set(Student::getSubjectId, studentInfo.getSubjectId())
                     .set(Student::getTenantId, studentInfo.getTenantId())
-                    .set(Student::getUserId, sysUser.getId())
+//                    .set(Student::getUserId, sysUser.getId())
                     .set(Student::getUpdateTime, new Date())
                     .set(Student::getTenantGroupId, studentInfo.getTenantGroupId())
                     .set(StringUtils.isNotEmpty(studentInfo.getAvatar()), Student::getAvatar, studentInfo.getAvatar())
@@ -924,6 +924,38 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, Student> impleme
         return sysUser;
     }
 
+    private com.yonge.cooleshow.biz.dal.entity.SysUser updateAccount(StudentWrapper.Student studentInfo,SysUser oldSysUser) {
+        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);
+        if (!sysUsers.isEmpty()) {
+            throw new BizException("手机号已经注册账号");
+        } else {
+            com.yonge.cooleshow.biz.dal.entity.SysUser sysUser = JSON.parseObject(JSON.toJSONString(studentInfo),
+                    com.yonge.cooleshow.biz.dal.entity.SysUser.class);
+            sysUser.setId(oldSysUser.getId());
+            sysUser.setPhone(studentInfo.getPhone());
+            sysUser.setAvatar(studentInfo.getAvatar());
+            if (StringUtils.isEmpty(studentInfo.getAvatar())) {
+                //设置默认头像
+                String avatar = sysConfigService.findConfigValue(SysConfigConstant.STUDENT_AVATAR);
+                sysUser.setAvatar(avatar);
+            }
+            sysUser.setGender(studentInfo.getGender());
+            sysUser.setBirthdate(studentInfo.getBirthdate());
+            sysUser.setUsername(studentInfo.getName());
+            String password = oldSysUser.getPassword();
+            sysUser.setPassword(password);
+
+            if (StringUtils.isEmpty(password)) {
+                String newPassword = MessageFormat.format("klx{0}", studentInfo.getPhone().substring(7));
+                sysUser.setPassword(new BCryptPasswordEncoder().encode(newPassword));
+            }
+            sysUserMapper.updateById(sysUser);
+            return sysUser;
+        }
+    }
+
     /**
      * 更新学生关联帐号
      *