Codex Assistant
昨天 afeeed281e60466b576fbe74d339634cc5d07b82
backend/src/main/java/com/rongyichuang/user/service/UserService.java
@@ -75,14 +75,22 @@
                        boolean needUpdateWx = false;
                        if (currentWxOpenid != null && !currentWxOpenid.trim().isEmpty()) {
                            if (user.getWxOpenid() == null || !currentWxOpenid.equals(user.getWxOpenid())) {
                                user.setWxOpenid(currentWxOpenid);
                                needUpdateWx = true;
                                // 检查这个openid是否已经被其他用户使用
                                Optional<User> existingUserWithOpenid = userRepository.findByWxOpenid(currentWxOpenid);
                                if (existingUserWithOpenid.isEmpty() || existingUserWithOpenid.get().getId().equals(user.getId())) {
                                    user.setWxOpenid(currentWxOpenid);
                                    needUpdateWx = true;
                                }
                            }
                        }
                        if (currentWxUnionid != null && !currentWxUnionid.trim().isEmpty()) {
                            if (user.getWxUnionid() == null || !currentWxUnionid.equals(user.getWxUnionid())) {
                                user.setWxUnionid(currentWxUnionid);
                                needUpdateWx = true;
                                // 检查这个unionid是否已经被其他用户使用
                                Optional<User> existingUserWithUnionid = userRepository.findByWxUnionid(currentWxUnionid);
                                if (existingUserWithUnionid.isEmpty() || existingUserWithUnionid.get().getId().equals(user.getId())) {
                                    user.setWxUnionid(currentWxUnionid);
                                    needUpdateWx = true;
                                }
                            }
                        }
                        if (needUpdateWx) {