| | |
| | | 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) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * 根据微信openid查找用户 |
| | | */ |
| | | public Optional<User> findByWxOpenid(String wxOpenid) { |
| | | return userRepository.findByWxOpenid(wxOpenid); |
| | | } |
| | | |
| | | /** |
| | | * 保存用户 |
| | | */ |
| | | public User save(User user) { |