From 0a7e88ddda2d1ff897bbda93a699a93b75d2e9bf Mon Sep 17 00:00:00 2001 From: x ronger Date: Mon, 9 Nov 2020 22:00:25 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=20=E7=94=A8=E6=88=B7=E6=89=A9?= =?UTF-8?q?=E5=B1=95-=E7=AB=99=E7=82=B9=E9=93=BE=E6=8E=A5=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/rymcu/vertical/entity/UserExtend.java | 28 ++++++++++++++++++ .../vertical/mapper/UserExtendMapper.java | 17 +++++++++++ .../rymcu/vertical/service/UserService.java | 15 ++++++++++ .../service/impl/UserServiceImpl.java | 29 +++++++++++++++++++ .../vertical/web/api/user/UserController.java | 7 +++++ .../web/api/user/UserInfoController.java | 7 +++++ src/main/java/mapper/UserExtendMapper.xml | 16 ++++++++++ 7 files changed, 119 insertions(+) create mode 100644 src/main/java/com/rymcu/vertical/entity/UserExtend.java create mode 100644 src/main/java/com/rymcu/vertical/mapper/UserExtendMapper.java create mode 100644 src/main/java/mapper/UserExtendMapper.xml diff --git a/src/main/java/com/rymcu/vertical/entity/UserExtend.java b/src/main/java/com/rymcu/vertical/entity/UserExtend.java new file mode 100644 index 0000000..a945dac --- /dev/null +++ b/src/main/java/com/rymcu/vertical/entity/UserExtend.java @@ -0,0 +1,28 @@ +package com.rymcu.vertical.entity; + +import lombok.Data; + +import javax.persistence.Id; +import javax.persistence.Table; + +/** + * @author ronger + */ +@Data +@Table(name = "vertical_user_extend") +public class UserExtend { + + @Id + private Integer idUser; + + private String github; + + private String weibo; + + private String weixin; + + private String qq; + + private String blog; + +} diff --git a/src/main/java/com/rymcu/vertical/mapper/UserExtendMapper.java b/src/main/java/com/rymcu/vertical/mapper/UserExtendMapper.java new file mode 100644 index 0000000..e8ec1a3 --- /dev/null +++ b/src/main/java/com/rymcu/vertical/mapper/UserExtendMapper.java @@ -0,0 +1,17 @@ +package com.rymcu.vertical.mapper; + +import com.rymcu.vertical.core.mapper.Mapper; +import com.rymcu.vertical.entity.UserExtend; +import org.apache.ibatis.annotations.Param; + +/** + * @author ronger + */ +public interface UserExtendMapper extends Mapper { + /** + * 获取用户扩展信息 + * @param nickname + * @return + */ + UserExtend selectUserExtendByNickname(@Param("nickname") String nickname); +} diff --git a/src/main/java/com/rymcu/vertical/service/UserService.java b/src/main/java/com/rymcu/vertical/service/UserService.java index f2fb61b..aabaa32 100644 --- a/src/main/java/com/rymcu/vertical/service/UserService.java +++ b/src/main/java/com/rymcu/vertical/service/UserService.java @@ -5,6 +5,7 @@ import com.rymcu.vertical.dto.Author; import com.rymcu.vertical.dto.UserDTO; import com.rymcu.vertical.dto.UserInfoDTO; import com.rymcu.vertical.entity.User; +import com.rymcu.vertical.entity.UserExtend; import org.apache.ibatis.exceptions.TooManyResultsException; import java.util.Map; @@ -108,4 +109,18 @@ public interface UserService extends Service { * @return */ Author selectAuthor(Integer idUser); + + /** + * 更新用户扩展信息 + * @param userExtend + * @return + */ + Map updateUserExtend(UserExtend userExtend); + + /** + * 获取用户扩展信息 + * @param nickname + * @return + */ + UserExtend selectUserExtendByNickname(String nickname); } diff --git a/src/main/java/com/rymcu/vertical/service/impl/UserServiceImpl.java b/src/main/java/com/rymcu/vertical/service/impl/UserServiceImpl.java index 136c58a..80b47dc 100644 --- a/src/main/java/com/rymcu/vertical/service/impl/UserServiceImpl.java +++ b/src/main/java/com/rymcu/vertical/service/impl/UserServiceImpl.java @@ -8,8 +8,10 @@ import com.rymcu.vertical.dto.UserDTO; import com.rymcu.vertical.dto.UserInfoDTO; import com.rymcu.vertical.entity.Role; import com.rymcu.vertical.entity.User; +import com.rymcu.vertical.entity.UserExtend; import com.rymcu.vertical.jwt.service.TokenManager; import com.rymcu.vertical.mapper.RoleMapper; +import com.rymcu.vertical.mapper.UserExtendMapper; import com.rymcu.vertical.mapper.UserMapper; import com.rymcu.vertical.service.UserService; import com.rymcu.vertical.util.BeanCopierUtil; @@ -24,6 +26,7 @@ import javax.annotation.Resource; import java.util.Date; import java.util.HashMap; import java.util.Map; +import java.util.Objects; /** @@ -41,6 +44,8 @@ public class UserServiceImpl extends AbstractService implements UserServic private RedisService redisService; @Resource private TokenManager tokenManager; + @Resource + private UserExtendMapper userExtendMapper; private final static String avatarSvgType = "1"; @@ -165,7 +170,14 @@ public class UserServiceImpl extends AbstractService implements UserServic if (user == null) { map.put("message", "用户不存在!"); } else { + UserExtend userExtend = userExtendMapper.selectByPrimaryKey(user.getIdUser()); + if (Objects.isNull(userExtend)) { + userExtend = new UserExtend(); + userExtend.setIdUser(user.getIdUser()); + userExtendMapper.insertSelective(userExtend); + } map.put("user", user); + map.put("userExtend", userExtend); } return map; } @@ -213,4 +225,21 @@ public class UserServiceImpl extends AbstractService implements UserServic public Author selectAuthor(Integer idUser) { return userMapper.selectAuthor(idUser); } + + @Override + public Map updateUserExtend(UserExtend userExtend) { + Map map = new HashMap(1); + int result = userExtendMapper.updateByPrimaryKeySelective(userExtend); + if (result == 0) { + map.put("message", "操作失败!"); + return map; + } + map.put("userExtend", userExtend); + return map; + } + + @Override + public UserExtend selectUserExtendByNickname(String nickname) { + return userExtendMapper.selectUserExtendByNickname(nickname); + } } diff --git a/src/main/java/com/rymcu/vertical/web/api/user/UserController.java b/src/main/java/com/rymcu/vertical/web/api/user/UserController.java index a8ecea8..5317747 100644 --- a/src/main/java/com/rymcu/vertical/web/api/user/UserController.java +++ b/src/main/java/com/rymcu/vertical/web/api/user/UserController.java @@ -8,6 +8,7 @@ import com.rymcu.vertical.core.service.log.annotation.VisitLogger; import com.rymcu.vertical.dto.ArticleDTO; import com.rymcu.vertical.dto.PortfolioDTO; import com.rymcu.vertical.dto.UserDTO; +import com.rymcu.vertical.entity.UserExtend; import com.rymcu.vertical.service.ArticleService; import com.rymcu.vertical.service.FollowService; import com.rymcu.vertical.service.PortfolioService; @@ -104,4 +105,10 @@ public class UserController { return GlobalResultGenerator.genSuccessResult(map); } + @GetMapping("/{nickname}/user-extend") + public GlobalResult userExtend(@PathVariable String nickname) { + UserExtend userExtend = userService.selectUserExtendByNickname(nickname); + return GlobalResultGenerator.genSuccessResult(userExtend); + } + } diff --git a/src/main/java/com/rymcu/vertical/web/api/user/UserInfoController.java b/src/main/java/com/rymcu/vertical/web/api/user/UserInfoController.java index 559b512..0aeb21b 100644 --- a/src/main/java/com/rymcu/vertical/web/api/user/UserInfoController.java +++ b/src/main/java/com/rymcu/vertical/web/api/user/UserInfoController.java @@ -3,6 +3,7 @@ package com.rymcu.vertical.web.api.user; import com.rymcu.vertical.core.result.GlobalResult; import com.rymcu.vertical.core.result.GlobalResultGenerator; import com.rymcu.vertical.dto.UserInfoDTO; +import com.rymcu.vertical.entity.UserExtend; import com.rymcu.vertical.service.UserService; import org.springframework.web.bind.annotation.*; @@ -37,4 +38,10 @@ public class UserInfoController { return GlobalResultGenerator.genSuccessResult(map); } + @PatchMapping("/update-extend") + public GlobalResult updateUserExtend(@RequestBody UserExtend userExtend) { + Map map = userService.updateUserExtend(userExtend); + return GlobalResultGenerator.genSuccessResult(map); + } + } diff --git a/src/main/java/mapper/UserExtendMapper.xml b/src/main/java/mapper/UserExtendMapper.xml new file mode 100644 index 0000000..a1ec9e5 --- /dev/null +++ b/src/main/java/mapper/UserExtendMapper.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + \ No newline at end of file