mirror of
				https://gitee.com/hhyykk/ipms-sjy.git
				synced 2025-10-31 10:18:42 +08:00 
			
		
		
		
	文件表建加原文件名称字段original_name,相关代码修改
This commit is contained in:
		| @@ -97,11 +97,12 @@ public class UserProfileController { | ||||
|  | ||||
|     @PutMapping("/update-avatar") | ||||
|     @ApiOperation("上传用户个人头像") | ||||
|     public CommonResult<String> updateUserAvatar(@RequestParam("avatarFile") MultipartFile file) throws Exception { | ||||
|     public CommonResult<String> updateUserAvatar(@RequestParam("avatarFile") MultipartFile file, | ||||
|                                                  @RequestParam(value = "originalName", required = false) String originalName) throws Exception { | ||||
|         if (file.isEmpty()) { | ||||
|             throw ServiceExceptionUtil.exception(FILE_IS_EMPTY); | ||||
|         } | ||||
|         String avatar = userService.updateUserAvatar(getLoginUserId(), file.getInputStream()); | ||||
|         String avatar = userService.updateUserAvatar(getLoginUserId(), originalName, file.getInputStream()); | ||||
|         return success(avatar); | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -62,9 +62,10 @@ public interface AdminUserService { | ||||
|      * 更新用户头像 | ||||
|      * | ||||
|      * @param id         用户 id | ||||
|      * @param originalName 原文件名称 | ||||
|      * @param avatarFile 头像文件 | ||||
|      */ | ||||
|     String updateUserAvatar(Long id, InputStream avatarFile) throws Exception; | ||||
|     String updateUserAvatar(Long id, String originalName, InputStream avatarFile) throws Exception; | ||||
|  | ||||
|     /** | ||||
|      * 修改密码 | ||||
|   | ||||
| @@ -153,10 +153,10 @@ public class AdminUserServiceImpl implements AdminUserService { | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public String updateUserAvatar(Long id, InputStream avatarFile) throws Exception { | ||||
|     public String updateUserAvatar(Long id, String originalName, InputStream avatarFile) throws Exception { | ||||
|         checkUserExists(id); | ||||
|         // 存储文件 | ||||
|         String avatar = fileApi.createFile(IoUtil.readBytes(avatarFile)); | ||||
|         String avatar = fileApi.createFile(originalName,IoUtil.readBytes(avatarFile)); | ||||
|         // 更新路径 | ||||
|         AdminUserDO sysUserDO = new AdminUserDO(); | ||||
|         sysUserDO.setId(id); | ||||
|   | ||||
| @@ -225,10 +225,11 @@ public class AdminUserServiceImplTest extends BaseDbUnitTest { | ||||
|         ByteArrayInputStream avatarFile = new ByteArrayInputStream(avatarFileBytes); | ||||
|         // mock 方法 | ||||
|         String avatar = randomString(); | ||||
|         when(fileApi.createFile(eq(avatarFileBytes))).thenReturn(avatar); | ||||
|         String originalName = "单测文件名"; | ||||
|         when(fileApi.createFile(originalName, eq( avatarFileBytes))).thenReturn(avatar); | ||||
|  | ||||
|         // 调用 | ||||
|         userService.updateUserAvatar(userId, avatarFile); | ||||
|         userService.updateUserAvatar(userId, originalName, avatarFile); | ||||
|         // 断言 | ||||
|         AdminUserDO user = userMapper.selectById(userId); | ||||
|         assertEquals(avatar, user.getAvatar()); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 谢华宁
					谢华宁