From 8d58208e6480d0d5a9e49e1fde4b9e81fa1d26fb Mon Sep 17 00:00:00 2001 From: "DESKTOP-G8BCEP0\\HP" <2037158277@qq.com> Date: Thu, 9 Sep 2021 16:07:07 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=86=E5=BE=AE=E4=BF=A1?= =?UTF-8?q?=E5=B0=8F=E7=A8=8B=E5=BA=8F=E7=BB=91=E5=AE=9A=E7=BD=91=E7=AB=99?= =?UTF-8?q?=E8=B4=A6=E5=8F=B7=E7=9A=84=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/xkrs/controller/SysUserController.java | 16 ++++++++++++++++ src/main/java/com/xkrs/dao/SysUserDao.java | 9 +++++++++ 2 files changed, 25 insertions(+) diff --git a/src/main/java/com/xkrs/controller/SysUserController.java b/src/main/java/com/xkrs/controller/SysUserController.java index 8bc0534..f563bee 100644 --- a/src/main/java/com/xkrs/controller/SysUserController.java +++ b/src/main/java/com/xkrs/controller/SysUserController.java @@ -11,6 +11,7 @@ import com.xkrs.model.vo.SysUserVo; import com.xkrs.service.SysUserService; import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.BindingResult; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; @@ -251,4 +252,19 @@ public class SysUserController { return sysUserService.findUserByOpenId(openId); } + /** + * 绑定网站账号 + * @param map + * @return + */ + @Transactional(rollbackFor=Exception.class) + @PostMapping("/updateOpenIdByPhone") + public String updateOpenIdByPhone(@RequestBody Map map){ + Locale locale = LocaleContextHolder.getLocale(); + String openId = (String) map.get("openId"); + String phone = (String) map.get("phone"); + sysUserDao.updateOpenIdByPhone(phone,openId); + return outputEncapsulationObject(PromptMessageEnum.SUCCESS,"绑定成功!",locale); + } + } diff --git a/src/main/java/com/xkrs/dao/SysUserDao.java b/src/main/java/com/xkrs/dao/SysUserDao.java index 673b6d1..c13a953 100644 --- a/src/main/java/com/xkrs/dao/SysUserDao.java +++ b/src/main/java/com/xkrs/dao/SysUserDao.java @@ -134,4 +134,13 @@ public interface SysUserDao extends JpaRepository { * @return */ SysUserEntity findByOpenId(String openId); + + /** + * 根据用户名(手机号),修改openid + * @param userName + * @param openId + */ + @Query(value = "update sys_user set open_id = ?2 where user_name = ?1",nativeQuery = true) + @Modifying(clearAutomatically=true) + void updateOpenIdByPhone(String userName,String openId); }