mirror of
				https://gitee.com/hhyykk/ipms-sjy.git
				synced 2025-10-31 18:28:43 +08:00 
			
		
		
		
	Merge branch 'master' of https://gitee.com/zhijiantianya/ruoyi-vue-pro into feature/user-social
Conflicts: yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/enums/SysErrorCodeConstants.java
This commit is contained in:
		| @@ -1,3 +1,11 @@ | ||||
| ### 请求 /system/user/profile/get 接口 => 没有权限 | ||||
| GET {{userServerUrl}}/system/user/profile/get | ||||
| Authorization: Bearer test245 | ||||
|  | ||||
| ### 请求 /system/user/profile/revise-nickname 接口 成功 | ||||
| PUT {{userServerUrl}}/system/user/profile/update-nickname?nickName=yunai222 | ||||
| Authorization: Bearer test245 | ||||
|  | ||||
| ### 请求 /system/user/profile/get-user-info 接口 成功 | ||||
| GET {{userServerUrl}}/system/user/profile/get-user-info?id=245 | ||||
| Authorization: Bearer test245 | ||||
| @@ -1,14 +1,24 @@ | ||||
| package cn.iocoder.yudao.userserver.modules.member.controller.user; | ||||
|  | ||||
| import cn.iocoder.yudao.userserver.modules.member.controller.user.vo.MbrUserInfoRespVO; | ||||
| import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil; | ||||
| import cn.iocoder.yudao.framework.common.pojo.CommonResult; | ||||
| import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated; | ||||
| import cn.iocoder.yudao.userserver.modules.member.service.user.MbrUserService; | ||||
| import io.swagger.annotations.Api; | ||||
| import io.swagger.annotations.ApiOperation; | ||||
| import lombok.extern.slf4j.Slf4j; | ||||
| import org.springframework.validation.annotation.Validated; | ||||
| import org.springframework.web.bind.annotation.GetMapping; | ||||
| import org.springframework.web.bind.annotation.RequestMapping; | ||||
| import org.springframework.web.bind.annotation.RestController; | ||||
| import org.springframework.web.bind.annotation.*; | ||||
| import org.springframework.web.multipart.MultipartFile; | ||||
|  | ||||
| import javax.annotation.Resource; | ||||
|  | ||||
| import java.io.IOException; | ||||
|  | ||||
| import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | ||||
| import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; | ||||
| import static cn.iocoder.yudao.userserver.modules.member.enums.MbrErrorCodeConstants.FILE_IS_EMPTY; | ||||
|  | ||||
| @Api(tags = "用户个人中心") | ||||
| @RestController | ||||
| @@ -17,11 +27,34 @@ import org.springframework.web.bind.annotation.RestController; | ||||
| @Slf4j | ||||
| public class SysUserProfileController { | ||||
|  | ||||
|     @GetMapping("/get") | ||||
|     @ApiOperation("获得登录用户信息") | ||||
|     @Resource | ||||
|     private MbrUserService userService; | ||||
|  | ||||
|     @PutMapping("/update-nickname") | ||||
|     @ApiOperation("修改用户昵称") | ||||
|     @PreAuthenticated | ||||
|     public CommonResult<Boolean> profile() { | ||||
|         return null; | ||||
|     public CommonResult<Boolean> updateNickname(@RequestParam("nickName") String nickName) { | ||||
|         userService.updateNickname(getLoginUserId(), nickName); | ||||
|         return success(true); | ||||
|     } | ||||
|  | ||||
|     @PutMapping("/update-avatar") | ||||
|     @ApiOperation("修改用户头像") | ||||
|     @PreAuthenticated | ||||
|     public CommonResult<String> updateAvatar(@RequestParam("avatarFile") MultipartFile file) throws IOException { | ||||
|         if (file.isEmpty()) { | ||||
|             throw ServiceExceptionUtil.exception(FILE_IS_EMPTY); | ||||
|         } | ||||
|         String avatar = userService.updateAvatar(getLoginUserId(), file.getInputStream()); | ||||
|         return success(avatar); | ||||
|     } | ||||
|  | ||||
|     @GetMapping("/get-user-info") | ||||
|     @ApiOperation("获取用户头像与昵称") | ||||
|     @PreAuthenticated | ||||
|     public CommonResult<MbrUserInfoRespVO> getUserInfo() { | ||||
|         return success(userService.getUserInfo(getLoginUserId())); | ||||
|     } | ||||
|  | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -0,0 +1,20 @@ | ||||
| package cn.iocoder.yudao.userserver.modules.member.controller.user.vo; | ||||
|  | ||||
| import io.swagger.annotations.ApiModel; | ||||
| import io.swagger.annotations.ApiModelProperty; | ||||
| import lombok.AllArgsConstructor; | ||||
| import lombok.Data; | ||||
| import lombok.NoArgsConstructor; | ||||
|  | ||||
| @ApiModel("用户个人信息 Response VO") | ||||
| @Data | ||||
| @NoArgsConstructor | ||||
| @AllArgsConstructor | ||||
| public class MbrUserInfoRespVO { | ||||
|  | ||||
|     @ApiModelProperty(value = "用户昵称", required = true, example = "芋艿") | ||||
|     private String nickName; | ||||
|  | ||||
|     @ApiModelProperty(value = "用户头像", required = true, example = "/infra/file/get/35a12e57-4297-4faa-bf7d-7ed2f211c952") | ||||
|     private String avatar; | ||||
| } | ||||
| @@ -9,4 +9,9 @@ import cn.iocoder.yudao.framework.common.exception.ErrorCode; | ||||
|  */ | ||||
| public interface MbrErrorCodeConstants { | ||||
|  | ||||
|     // ==========用户相关  1004001000============ | ||||
|     ErrorCode USER_NOT_EXISTS = new ErrorCode(1004001000, "用户不存在"); | ||||
|  | ||||
|     // ==========文件相关 1004002000 =========== | ||||
|     ErrorCode FILE_IS_EMPTY = new ErrorCode(1004002000, "文件为空"); | ||||
| } | ||||
|   | ||||
| @@ -1,8 +1,11 @@ | ||||
| package cn.iocoder.yudao.userserver.modules.member.service.user; | ||||
|  | ||||
| import cn.iocoder.yudao.coreservice.modules.member.dal.dataobject.user.MbrUserDO; | ||||
| import cn.iocoder.yudao.userserver.modules.member.controller.user.vo.MbrUserInfoRespVO; | ||||
| import cn.iocoder.yudao.framework.common.validation.Mobile; | ||||
|  | ||||
| import java.io.InputStream; | ||||
|  | ||||
| /** | ||||
|  * 前台用户 Service 接口 | ||||
|  * | ||||
| @@ -44,4 +47,26 @@ public interface MbrUserService { | ||||
|      */ | ||||
|     MbrUserDO getUser(Long id); | ||||
|  | ||||
|     /** | ||||
|      * 修改用户昵称 | ||||
|      * @param userId 用户id | ||||
|      * @param nickName 用户新昵称 | ||||
|      */ | ||||
|     void updateNickname(Long userId, String nickName); | ||||
|  | ||||
|     /** | ||||
|      * 修改用户头像 | ||||
|      * @param userId 用户id | ||||
|      * @param inputStream 头像文件 | ||||
|      * @return 头像url | ||||
|      */ | ||||
|     String updateAvatar(Long userId, InputStream inputStream); | ||||
|  | ||||
|     /** | ||||
|      * 根据用户id,获取用户头像与昵称 | ||||
|      * @param userId 用户id | ||||
|      * @return 用户响应实体类 | ||||
|      */ | ||||
|     MbrUserInfoRespVO getUserInfo(Long userId); | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -1,18 +1,26 @@ | ||||
| package cn.iocoder.yudao.userserver.modules.member.service.user.impl; | ||||
|  | ||||
| import cn.hutool.core.io.IoUtil; | ||||
| import cn.hutool.core.util.IdUtil; | ||||
| import cn.iocoder.yudao.coreservice.modules.infra.service.file.InfFileCoreService; | ||||
| import cn.iocoder.yudao.coreservice.modules.member.dal.dataobject.user.MbrUserDO; | ||||
| import cn.iocoder.yudao.userserver.modules.member.controller.user.vo.MbrUserInfoRespVO; | ||||
| import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | ||||
| import cn.iocoder.yudao.userserver.modules.member.dal.mysql.user.MbrUserMapper; | ||||
| import cn.iocoder.yudao.userserver.modules.member.service.user.MbrUserService; | ||||
| import com.google.common.annotations.VisibleForTesting; | ||||
| import lombok.extern.slf4j.Slf4j; | ||||
| import org.springframework.security.crypto.password.PasswordEncoder; | ||||
| import org.springframework.stereotype.Service; | ||||
|  | ||||
| import javax.annotation.Resource; | ||||
| import javax.validation.Valid; | ||||
| import java.io.InputStream; | ||||
| import java.util.Date; | ||||
|  | ||||
| import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | ||||
| import static cn.iocoder.yudao.userserver.modules.member.enums.MbrErrorCodeConstants.USER_NOT_EXISTS; | ||||
|  | ||||
| /** | ||||
|  * User Service 实现类 | ||||
|  * | ||||
| @@ -26,6 +34,9 @@ public class MbrUserServiceImpl implements MbrUserService { | ||||
|     @Resource | ||||
|     private MbrUserMapper userMapper; | ||||
|  | ||||
|     @Resource | ||||
|     private InfFileCoreService fileCoreService; | ||||
|  | ||||
|     @Resource | ||||
|     private PasswordEncoder passwordEncoder; | ||||
|  | ||||
| @@ -68,4 +79,53 @@ public class MbrUserServiceImpl implements MbrUserService { | ||||
|         return userMapper.selectById(id); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void updateNickname(Long userId, String nickName) { | ||||
|         MbrUserDO user = this.checkUserExists(userId); | ||||
|         // 仅当新昵称不等于旧昵称时进行修改 | ||||
|         if (nickName.equals(user.getNickname())){ | ||||
|             return; | ||||
|         } | ||||
|         MbrUserDO userDO = new MbrUserDO(); | ||||
|         userDO.setId(user.getId()); | ||||
|         userDO.setNickname(nickName); | ||||
|         userMapper.updateById(userDO); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public String updateAvatar(Long userId, InputStream avatarFile) { | ||||
|         this.checkUserExists(userId); | ||||
|         // 创建文件 | ||||
|         String avatar = fileCoreService.createFile(IdUtil.fastUUID(), IoUtil.readBytes(avatarFile)); | ||||
|         // 更新头像路径 | ||||
|         MbrUserDO userDO = MbrUserDO.builder() | ||||
|                 .id(userId) | ||||
|                 .avatar(avatar) | ||||
|                 .build(); | ||||
|         userMapper.updateById(userDO); | ||||
|         return avatar; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public MbrUserInfoRespVO getUserInfo(Long userId) { | ||||
|         MbrUserDO user = this.checkUserExists(userId); | ||||
|         // 拼接返回结果 | ||||
|         MbrUserInfoRespVO userResp = new MbrUserInfoRespVO(); | ||||
|         userResp.setNickName(user.getNickname()); | ||||
|         userResp.setAvatar(user.getAvatar()); | ||||
|         return userResp; | ||||
|     } | ||||
|  | ||||
|     @VisibleForTesting | ||||
|     public MbrUserDO checkUserExists(Long id) { | ||||
|         if (id == null) { | ||||
|             return null; | ||||
|         } | ||||
|         MbrUserDO user = userMapper.selectById(id); | ||||
|         if (user == null) { | ||||
|             throw exception(USER_NOT_EXISTS); | ||||
|         }else{ | ||||
|             return user; | ||||
|         } | ||||
|     } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 YunaiV
					YunaiV