From bd999ecc09fcacf4016edcba85caf9b9696d2140 Mon Sep 17 00:00:00 2001 From: lrj <owen.stl@gmail.com> Date: 星期六, 04 十月 2025 18:40:31 +0800 Subject: [PATCH] feat: 同步本地改动(认证/评审/用户/选手模块更新;新增/调整 GraphQL schema;小程序个人信息与评审相关页面、配置与资源等) --- backend/src/main/java/com/rongyichuang/user/service/UserService.java | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 44 insertions(+), 0 deletions(-) diff --git a/backend/src/main/java/com/rongyichuang/user/service/UserService.java b/backend/src/main/java/com/rongyichuang/user/service/UserService.java index 8ee3be7..a4c4913 100644 --- a/backend/src/main/java/com/rongyichuang/user/service/UserService.java +++ b/backend/src/main/java/com/rongyichuang/user/service/UserService.java @@ -5,6 +5,7 @@ import com.rongyichuang.employee.repository.EmployeeRepository; import com.rongyichuang.judge.repository.JudgeRepository; import com.rongyichuang.player.repository.PlayerRepository; +import com.rongyichuang.common.util.UserContextUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.stereotype.Service; @@ -20,6 +21,9 @@ @Service @Transactional public class UserService { + + @Autowired + private UserContextUtil userContextUtil; private static final Logger logger = LoggerFactory.getLogger(UserService.class); @@ -57,6 +61,39 @@ if (password != null && !password.trim().isEmpty()) { user.setPassword(passwordEncoder.encode(password)); } + + // 瑕嗙洊 wxOpenid / wxUnionid锛氬鏋滃綋鍓嶇櫥褰曠敤鎴锋湁openid/unionid锛屽苟涓庡簱涓笉鍚岋紝鍒欎互褰撳墠鐧诲綍瑕嗙洊 + try { + Long currentUserId = userContextUtil != null ? userContextUtil.getCurrentUserId() : null; + if (currentUserId != null) { + Optional<User> currentUserOpt = userRepository.findById(currentUserId); + if (currentUserOpt.isPresent()) { + User currentUser = currentUserOpt.get(); + String currentWxOpenid = currentUser.getWxOpenid(); + String currentWxUnionid = currentUser.getWxUnionid(); + + boolean needUpdateWx = false; + if (currentWxOpenid != null && !currentWxOpenid.trim().isEmpty()) { + if (user.getWxOpenid() == null || !currentWxOpenid.equals(user.getWxOpenid())) { + user.setWxOpenid(currentWxOpenid); + needUpdateWx = true; + } + } + if (currentWxUnionid != null && !currentWxUnionid.trim().isEmpty()) { + if (user.getWxUnionid() == null || !currentWxUnionid.equals(user.getWxUnionid())) { + user.setWxUnionid(currentWxUnionid); + needUpdateWx = true; + } + } + if (needUpdateWx) { + logger.info("瑕嗙洊鐢ㄦ埛(wx)鏍囪瘑锛歱hone鍖归厤鐨勭敤鎴稩D={}, 浣跨敤褰撳墠鐧诲綍鐢ㄦ埛ID={} 鐨� openid/unionid 瑕嗙洊", user.getId(), currentUserId); + } + } + } + } catch (Exception ex) { + logger.warn("瑕嗙洊wxOpenid/unionid鏃跺彂鐢熷紓甯革紙蹇界暐锛屼笉闃绘柇鎶ュ悕娴佺▼锛夛細{}", ex.getMessage()); + } + return userRepository.save(user); } else { // 鐢ㄦ埛涓嶅瓨鍦紝鍒涘缓鏂扮敤鎴� @@ -95,6 +132,13 @@ } /** + * 鑾峰彇瀵嗙爜缂栫爜鍣� + */ + public BCryptPasswordEncoder getPasswordEncoder() { + return passwordEncoder; + } + + /** * 淇濆瓨鐢ㄦ埛鎵嬫満鍙风爜 * 鏍稿績閫昏緫锛� * 1. 鏌ヨ褰撳墠t_user閲岄潰鏄惁瀛樺湪鐩稿悓鐨勭數璇濆彿鐮侊紝濡傛灉娌℃湁锛屽氨鏇存柊鍒板綋鍓島ser閲岄潰 -- Gitblit v1.8.0