mirror of
				https://gitee.com/hhyykk/ipms-sjy.git
				synced 2025-10-31 18:28:43 +08:00 
			
		
		
		
	[update]更新代码规范
This commit is contained in:
		| @@ -3,7 +3,7 @@ GET {{userServerUrl}}/system/user/profile/get | ||||
| Authorization: Bearer test245 | ||||
|  | ||||
| ### 请求 /system/user/profile/revise-nickname 接口 成功 | ||||
| PUT http://localhost:28080/api/system/user/profile/revise-nickname?nickName=yunai111 | ||||
| PUT http://localhost:28080/api/system/user/profile/update-nickname?nickName=yunai222 | ||||
| Authorization: Bearer test245 | ||||
|  | ||||
| ### 请求 /system/user/profile/get-user-info 接口 成功 | ||||
|   | ||||
| @@ -1,6 +1,6 @@ | ||||
| package cn.iocoder.yudao.userserver.modules.member.controller.user; | ||||
|  | ||||
| import cn.iocoder.yudao.coreservice.modules.system.controller.user.vo.SysUserCoreProfileRespVo; | ||||
| import cn.iocoder.yudao.userserver.modules.member.controller.user.vo.SysUserInfoRespVO; | ||||
| 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; | ||||
| @@ -37,15 +37,17 @@ public class SysUserProfileController { | ||||
|         return null; | ||||
|     } | ||||
|  | ||||
|     @PutMapping("/revise-nickname") | ||||
|     @PutMapping("/update-nickname") | ||||
|     @ApiOperation("修改用户昵称") | ||||
|     public CommonResult<Boolean> reviseNickname(@RequestParam("nickName") String nickName) { | ||||
|         userService.reviseNickname(getLoginUserId(), nickName); | ||||
|     @PreAuthenticated | ||||
|     public CommonResult<Boolean> updateNickname(@RequestParam("nickName") String nickName) { | ||||
|         userService.updateNickname(getLoginUserId(), nickName); | ||||
|         return success(true); | ||||
|     } | ||||
|  | ||||
|     @PutMapping("/revise-avatar") | ||||
|     @ApiOperation("修改用户头像") | ||||
|     @PreAuthenticated | ||||
|     public CommonResult<String> reviseAvatar(@RequestParam("avatarFile") MultipartFile file) throws IOException { | ||||
|         if (file.isEmpty()) { | ||||
|             throw ServiceExceptionUtil.exception(FILE_IS_EMPTY); | ||||
| @@ -56,8 +58,9 @@ public class SysUserProfileController { | ||||
|  | ||||
|     @GetMapping("/get-user-info") | ||||
|     @ApiOperation("获取用户头像与昵称") | ||||
|     public CommonResult<SysUserCoreProfileRespVo> getUserInfo(@RequestParam("id") Long id) { | ||||
|         return success(userService.getUserInfo(id)); | ||||
|     @PreAuthenticated | ||||
|     public CommonResult<SysUserInfoRespVO> 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 SysUserInfoRespVO { | ||||
|  | ||||
|     @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,9 +9,9 @@ import cn.iocoder.yudao.framework.common.exception.ErrorCode; | ||||
|  */ | ||||
| public interface MbrErrorCodeConstants { | ||||
|  | ||||
|     // 用户相关 | ||||
|     ErrorCode USER_NOT_EXISTS = new ErrorCode(1004000000, "用户不存在"); | ||||
|     // ==========用户相关============ | ||||
|     ErrorCode USER_NOT_EXISTS = new ErrorCode(1004001000, "用户不存在"); | ||||
|  | ||||
|     // 文件相关 | ||||
|     ErrorCode FILE_IS_EMPTY = new ErrorCode(1004000000, "用户不存在"); | ||||
|     // ==========文件相关 =========== | ||||
|     ErrorCode FILE_IS_EMPTY = new ErrorCode(1004002000, "文件不存在"); | ||||
| } | ||||
|   | ||||
| @@ -1,7 +1,7 @@ | ||||
| package cn.iocoder.yudao.userserver.modules.member.service.user; | ||||
|  | ||||
| import cn.iocoder.yudao.coreservice.modules.member.dal.dataobject.user.MbrUserDO; | ||||
| import cn.iocoder.yudao.coreservice.modules.system.controller.user.vo.SysUserCoreProfileRespVo; | ||||
| import cn.iocoder.yudao.userserver.modules.member.controller.user.vo.SysUserInfoRespVO; | ||||
| import cn.iocoder.yudao.framework.common.validation.Mobile; | ||||
|  | ||||
| import java.io.InputStream; | ||||
| @@ -49,24 +49,24 @@ public interface MbrUserService { | ||||
|  | ||||
|     /** | ||||
|      * 修改用户昵称 | ||||
|      * @param loginUserId 登录用户id | ||||
|      * @param userId 用户id | ||||
|      * @param nickName 用户新昵称 | ||||
|      */ | ||||
|     void reviseNickname(Long loginUserId, String nickName); | ||||
|     void updateNickname(Long userId, String nickName); | ||||
|  | ||||
|     /** | ||||
|      * 修改用户头像 | ||||
|      * @param loginUserId 登录用户id | ||||
|      * @param userId 用户id | ||||
|      * @param inputStream 头像文件 | ||||
|      * @return 头像url | ||||
|      */ | ||||
|     String reviseAvatar(Long loginUserId, InputStream inputStream); | ||||
|     String reviseAvatar(Long userId, InputStream inputStream); | ||||
|  | ||||
|     /** | ||||
|      * 根据用户id,获取用户头像与昵称 | ||||
|      * @param loginUserId 登录用户id | ||||
|      * @param userId 用户id | ||||
|      * @return 用户响应实体类 | ||||
|      */ | ||||
|     SysUserCoreProfileRespVo getUserInfo(Long loginUserId); | ||||
|     SysUserInfoRespVO getUserInfo(Long userId); | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -4,8 +4,7 @@ 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.coreservice.modules.system.controller.user.vo.SysUserCoreProfileRespVo; | ||||
| import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.user.SysUserDO; | ||||
| import cn.iocoder.yudao.userserver.modules.member.controller.user.vo.SysUserInfoRespVO; | ||||
| 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; | ||||
| @@ -81,52 +80,51 @@ public class MbrUserServiceImpl implements MbrUserService { | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void reviseNickname(Long loginUserId, String nickName) { | ||||
|         MbrUserDO mbrUserDO = userMapper.selectById(loginUserId); | ||||
|     public void updateNickname(Long userId, String nickName) { | ||||
|         MbrUserDO user = this.checkUserExists(userId); | ||||
|         // 仅当新昵称不等于旧昵称时进行修改 | ||||
|         if (!nickName.equals(mbrUserDO.getNickname())){ | ||||
|             MbrUserDO user = new MbrUserDO(); | ||||
|             user.setId(mbrUserDO.getId()); | ||||
|             user.setNickname(nickName); | ||||
|             userMapper.updateById(user); | ||||
|         if (nickName.equals(user.getNickname())){ | ||||
|             return; | ||||
|         } | ||||
|         MbrUserDO userDO = new MbrUserDO(); | ||||
|         userDO.setId(user.getId()); | ||||
|         userDO.setNickname(nickName); | ||||
|         userMapper.updateById(userDO); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public String reviseAvatar(Long loginUserId, InputStream avatarFile) { | ||||
|         this.checkUserExists(loginUserId); | ||||
|     public String reviseAvatar(Long userId, InputStream avatarFile) { | ||||
|         this.checkUserExists(userId); | ||||
|         // 创建文件 | ||||
|         String avatar = fileCoreService.createFile(IdUtil.fastUUID(), IoUtil.readBytes(avatarFile)); | ||||
|         // 更新头像路径 | ||||
|         MbrUserDO userDO = new MbrUserDO(); | ||||
|         userDO.setId(loginUserId); | ||||
|         userDO.setAvatar(avatar); | ||||
|         MbrUserDO userDO = MbrUserDO.builder() | ||||
|                 .id(userId) | ||||
|                 .avatar(avatar) | ||||
|                 .build(); | ||||
|         userMapper.updateById(userDO); | ||||
|         return avatar; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public SysUserCoreProfileRespVo getUserInfo(Long loginUserId) { | ||||
|         MbrUserDO mbrUserDO = userMapper.selectById(loginUserId); | ||||
|         if (mbrUserDO == null){ | ||||
|             log.error("用户不存在:{}",loginUserId); | ||||
|             throw exception(USER_NOT_EXISTS); | ||||
|         } | ||||
|  | ||||
|         SysUserCoreProfileRespVo userRes = new SysUserCoreProfileRespVo(); | ||||
|         userRes.setNickName(mbrUserDO.getNickname()); | ||||
|         userRes.setAvatar(mbrUserDO.getAvatar()); | ||||
|         return userRes; | ||||
|     public SysUserInfoRespVO getUserInfo(Long userId) { | ||||
|         MbrUserDO user = this.checkUserExists(userId); | ||||
|         SysUserInfoRespVO userResp = new SysUserInfoRespVO(); | ||||
|         userResp.setNickName(user.getNickname()); | ||||
|         userResp.setAvatar(user.getAvatar()); | ||||
|         return userResp; | ||||
|     } | ||||
|  | ||||
|     @VisibleForTesting | ||||
|     public void checkUserExists(Long id) { | ||||
|     public MbrUserDO checkUserExists(Long id) { | ||||
|         if (id == null) { | ||||
|             return; | ||||
|             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
	 宋天
					宋天