From 13edb5a063f4e66e83c50b5965fecf51c412b955 Mon Sep 17 00:00:00 2001 From: ronger Date: Fri, 26 Mar 2021 10:46:21 +0800 Subject: [PATCH] =?UTF-8?q?:recycle:=20=E4=B8=AA=E4=BA=BA=E4=B8=AD?= =?UTF-8?q?=E5=BF=83=E8=B7=AF=E5=BE=84=20/user/nickname=20->=20/user/accou?= =?UTF-8?q?nt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- .../forest/config/MybatisConfigurer.java | 2 +- .../java/com/rymcu/forest/dto/Author.java | 2 ++ .../com/rymcu/forest/mapper/UserMapper.java | 4 +-- .../com/rymcu/forest/service/UserService.java | 10 +++--- .../service/impl/ArticleServiceImpl.java | 2 ++ .../service/impl/PortfolioServiceImpl.java | 5 +-- .../forest/service/impl/UserServiceImpl.java | 6 ++-- .../forest/web/api/user/UserController.java | 36 +++++++++---------- .../wx/mp/controller/WxoAuthController.java | 6 ++-- src/main/java/mapper/UserMapper.xml | 5 +-- src/main/resources/wxMpMenus.json | 5 +++ 12 files changed, 46 insertions(+), 39 deletions(-) diff --git a/pom.xml b/pom.xml index bff52cb..8edbd3b 100644 --- a/pom.xml +++ b/pom.xml @@ -191,7 +191,7 @@ com.thoughtworks.xstream xstream - 1.4.15 + 1.4.16 com.github.jedis-lock diff --git a/src/main/java/com/rymcu/forest/config/MybatisConfigurer.java b/src/main/java/com/rymcu/forest/config/MybatisConfigurer.java index 594882c..9aa708d 100644 --- a/src/main/java/com/rymcu/forest/config/MybatisConfigurer.java +++ b/src/main/java/com/rymcu/forest/config/MybatisConfigurer.java @@ -45,7 +45,7 @@ public class MybatisConfigurer { //添加XML目录 ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); factory.setMapperLocations(resolver.getResources("classpath:mapper/**/*.xml")); - factory.setTypeHandlersPackage("com.rymcu.forest.util.handlers"); +// factory.setTypeHandlersPackage("com.rymcu.forest.util.handlers"); return factory.getObject(); } diff --git a/src/main/java/com/rymcu/forest/dto/Author.java b/src/main/java/com/rymcu/forest/dto/Author.java index 5dca54e..3782f01 100644 --- a/src/main/java/com/rymcu/forest/dto/Author.java +++ b/src/main/java/com/rymcu/forest/dto/Author.java @@ -12,6 +12,8 @@ public class Author { private String userNickname; + private String userAccount; + private String userAvatarURL; private String userArticleCount; diff --git a/src/main/java/com/rymcu/forest/mapper/UserMapper.java b/src/main/java/com/rymcu/forest/mapper/UserMapper.java index 2d61a58..f23b726 100644 --- a/src/main/java/com/rymcu/forest/mapper/UserMapper.java +++ b/src/main/java/com/rymcu/forest/mapper/UserMapper.java @@ -39,10 +39,10 @@ public interface UserMapper extends Mapper { /** * 根据用户昵称获取用户信息 - * @param nickname + * @param account * @return */ - UserDTO selectUserDTOByNickname(@Param("nickname") String nickname); + UserDTO selectUserDTOByAccount(@Param("account") String account); /** * 修改用户密码 diff --git a/src/main/java/com/rymcu/forest/service/UserService.java b/src/main/java/com/rymcu/forest/service/UserService.java index 7fcca8f..31ad8c3 100644 --- a/src/main/java/com/rymcu/forest/service/UserService.java +++ b/src/main/java/com/rymcu/forest/service/UserService.java @@ -43,11 +43,11 @@ public interface UserService extends Service { Map login(String account, String password); /** - * 通过 nickname 获取用户信息接口 - * @param nickname 昵称 + * 通过 account 获取用户信息接口 + * @param account 昵称 * @return UserDTO * */ - UserDTO findUserDTOByNickname(String nickname); + UserDTO findUserDTOByAccount(String account); /** * 找回密码接口 @@ -118,10 +118,10 @@ public interface UserService extends Service { /** * 获取用户扩展信息 - * @param nickname + * @param account * @return */ - UserExtend selectUserExtendByNickname(String nickname); + UserExtend selectUserExtendByAccount(String account); /** * 更换邮箱 diff --git a/src/main/java/com/rymcu/forest/service/impl/ArticleServiceImpl.java b/src/main/java/com/rymcu/forest/service/impl/ArticleServiceImpl.java index 9bbbb54..af287d1 100644 --- a/src/main/java/com/rymcu/forest/service/impl/ArticleServiceImpl.java +++ b/src/main/java/com/rymcu/forest/service/impl/ArticleServiceImpl.java @@ -388,9 +388,11 @@ public class ArticleServiceImpl extends AbstractService
implements Arti private Author genAuthor(ArticleDTO article) { Author author = new Author(); + User user = userService.findById(String.valueOf(article.getArticleAuthorId())); author.setUserNickname(article.getArticleAuthorName()); author.setUserAvatarURL(article.getArticleAuthorAvatarUrl()); author.setIdUser(article.getArticleAuthorId()); + author.setUserAccount(user.getAccount()); return author; } } diff --git a/src/main/java/com/rymcu/forest/service/impl/PortfolioServiceImpl.java b/src/main/java/com/rymcu/forest/service/impl/PortfolioServiceImpl.java index af9a0fc..b843722 100644 --- a/src/main/java/com/rymcu/forest/service/impl/PortfolioServiceImpl.java +++ b/src/main/java/com/rymcu/forest/service/impl/PortfolioServiceImpl.java @@ -39,10 +39,7 @@ public class PortfolioServiceImpl extends AbstractService implements @Override public List findUserPortfoliosByUser(UserDTO userDTO) { List list = portfolioMapper.selectUserPortfoliosByIdUser(userDTO.getIdUser()); - Author author = new Author(); - author.setIdUser(userDTO.getIdUser()); - author.setUserAvatarURL(userDTO.getAvatarUrl()); - author.setUserNickname(userDTO.getNickname()); + Author author = userService.selectAuthor(userDTO.getIdUser()); list.forEach(portfolioDTO -> { genPortfolioAuthor(portfolioDTO,author); }); diff --git a/src/main/java/com/rymcu/forest/service/impl/UserServiceImpl.java b/src/main/java/com/rymcu/forest/service/impl/UserServiceImpl.java index 2ae4446..891cf7c 100644 --- a/src/main/java/com/rymcu/forest/service/impl/UserServiceImpl.java +++ b/src/main/java/com/rymcu/forest/service/impl/UserServiceImpl.java @@ -116,8 +116,8 @@ public class UserServiceImpl extends AbstractService implements UserServic } @Override - public UserDTO findUserDTOByNickname(String nickname) { - UserDTO user = userMapper.selectUserDTOByNickname(nickname); + public UserDTO findUserDTOByAccount(String account) { + UserDTO user = userMapper.selectUserDTOByAccount(account); return user; } @@ -239,7 +239,7 @@ public class UserServiceImpl extends AbstractService implements UserServic } @Override - public UserExtend selectUserExtendByNickname(String nickname) { + public UserExtend selectUserExtendByAccount(String nickname) { return userExtendMapper.selectUserExtendByNickname(nickname); } diff --git a/src/main/java/com/rymcu/forest/web/api/user/UserController.java b/src/main/java/com/rymcu/forest/web/api/user/UserController.java index f7e154e..9976387 100644 --- a/src/main/java/com/rymcu/forest/web/api/user/UserController.java +++ b/src/main/java/com/rymcu/forest/web/api/user/UserController.java @@ -37,16 +37,16 @@ public class UserController { @Resource private FollowService followService; - @GetMapping("/{nickname}") + @GetMapping("/{account}") @VisitLogger - public GlobalResult detail(@PathVariable String nickname){ - UserDTO userDTO = userService.findUserDTOByNickname(nickname); + public GlobalResult detail(@PathVariable String account){ + UserDTO userDTO = userService.findUserDTOByAccount(account); return GlobalResultGenerator.genSuccessResult(userDTO); } - @GetMapping("/{nickname}/articles") - public GlobalResult userArticles(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "12") Integer rows, @PathVariable String nickname){ - UserDTO userDTO = userService.findUserDTOByNickname(nickname); + @GetMapping("/{account}/articles") + public GlobalResult userArticles(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "12") Integer rows, @PathVariable String account){ + UserDTO userDTO = userService.findUserDTOByAccount(account); if (userDTO == null){ return GlobalResultGenerator.genErrorResult("用户不存在!"); } @@ -57,9 +57,9 @@ public class UserController { return GlobalResultGenerator.genSuccessResult(map); } - @GetMapping("/{nickname}/portfolios") - public GlobalResult userPortfolios(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "12") Integer rows, @PathVariable String nickname){ - UserDTO userDTO = userService.findUserDTOByNickname(nickname); + @GetMapping("/{account}/portfolios") + public GlobalResult userPortfolios(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "12") Integer rows, @PathVariable String account){ + UserDTO userDTO = userService.findUserDTOByAccount(account); if (userDTO == null){ return GlobalResultGenerator.genErrorResult("用户不存在!"); } @@ -73,9 +73,9 @@ public class UserController { return GlobalResultGenerator.genSuccessResult(map); } - @GetMapping("/{nickname}/followers") - public GlobalResult userFollowers(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "12") Integer rows, @PathVariable String nickname){ - UserDTO userDTO = userService.findUserDTOByNickname(nickname); + @GetMapping("/{account}/followers") + public GlobalResult userFollowers(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "12") Integer rows, @PathVariable String account){ + UserDTO userDTO = userService.findUserDTOByAccount(account); if (userDTO == null){ return GlobalResultGenerator.genErrorResult("用户不存在!"); } @@ -89,9 +89,9 @@ public class UserController { return GlobalResultGenerator.genSuccessResult(map); } - @GetMapping("/{nickname}/followings") - public GlobalResult userFollowings(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "12") Integer rows, @PathVariable String nickname){ - UserDTO userDTO = userService.findUserDTOByNickname(nickname); + @GetMapping("/{account}/followings") + public GlobalResult userFollowings(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "12") Integer rows, @PathVariable String account){ + UserDTO userDTO = userService.findUserDTOByAccount(account); if (userDTO == null){ return GlobalResultGenerator.genErrorResult("用户不存在!"); } @@ -105,9 +105,9 @@ public class UserController { return GlobalResultGenerator.genSuccessResult(map); } - @GetMapping("/{nickname}/user-extend") - public GlobalResult userExtend(@PathVariable String nickname) { - UserExtend userExtend = userService.selectUserExtendByNickname(nickname); + @GetMapping("/{account}/user-extend") + public GlobalResult userExtend(@PathVariable String account) { + UserExtend userExtend = userService.selectUserExtendByAccount(account); return GlobalResultGenerator.genSuccessResult(userExtend); } diff --git a/src/main/java/com/rymcu/forest/wx/mp/controller/WxoAuthController.java b/src/main/java/com/rymcu/forest/wx/mp/controller/WxoAuthController.java index 7e0ba87..8638bf5 100644 --- a/src/main/java/com/rymcu/forest/wx/mp/controller/WxoAuthController.java +++ b/src/main/java/com/rymcu/forest/wx/mp/controller/WxoAuthController.java @@ -44,7 +44,7 @@ public class WxoAuthController { baseUrl = new StringBuilder(domain).append(contextPath); } StringBuilder accessTokenUrl = baseUrl.append("/wx/oauth/" + appId + "/getAccessToken?redirectUrl=").append(URIUtil.encodeURIComponent(redirectUrl)); - String oauth2Url = wxMpService.getOAuth2Service().buildAuthorizationUrl(accessTokenUrl.toString(), WxConsts.OAuth2Scope.SNSAPI_BASE, null); + String oauth2Url = wxMpService.getOAuth2Service().buildAuthorizationUrl(accessTokenUrl.toString(), WxConsts.OAuth2Scope.SNSAPI_USERINFO, null); return "redirect:" + oauth2Url; } @@ -58,8 +58,8 @@ public class WxoAuthController { throw new Exception("无权限"); } - WxMpUser wxMpUser =wxMpService.getUserService().userInfo(oAuth2AccessToken.getOpenId()); - wxUserService.saveUser(wxMpUser,appId); + WxMpUser wxMpUser = wxMpService.getUserService().userInfo(oAuth2AccessToken.getOpenId()); + wxUserService.saveUser(wxMpUser, appId); ContextHolderUtils.getSession2().setAttribute("wxUser", wxMpUser); return "redirect:" + redirectUrl; } diff --git a/src/main/java/mapper/UserMapper.xml b/src/main/java/mapper/UserMapper.xml index adaf741..d7e0615 100644 --- a/src/main/java/mapper/UserMapper.xml +++ b/src/main/java/mapper/UserMapper.xml @@ -45,6 +45,7 @@ + insert into forest_user_role (id_user,id_role,created_time) values (#{idUser},#{idRole},sysdate()) @@ -81,8 +82,8 @@ - + select id, nickname, avatar_type, avatar_url, account, signature from forest_user where account = #{account} and status = 0