diff --git a/src/main/java/com/rymcu/forest/mapper/ForestFileMapper.java b/src/main/java/com/rymcu/forest/mapper/ForestFileMapper.java index 339fdaf..327f217 100644 --- a/src/main/java/com/rymcu/forest/mapper/ForestFileMapper.java +++ b/src/main/java/com/rymcu/forest/mapper/ForestFileMapper.java @@ -13,10 +13,11 @@ public interface ForestFileMapper extends Mapper { /** * 通过md5获取文件访问链接 * - * @param md5Value md5值 + * @param md5Value md5值 + * @param createdBy 创建人 * @return */ - String getFileUrlByMd5(@Param("md5Value") String md5Value); + String getFileUrlByMd5(@Param("md5Value") String md5Value, @Param("createdBy") long createdBy); /** * 插入文件对象 diff --git a/src/main/java/com/rymcu/forest/service/ForestFileService.java b/src/main/java/com/rymcu/forest/service/ForestFileService.java index 78f7bac..5459d86 100644 --- a/src/main/java/com/rymcu/forest/service/ForestFileService.java +++ b/src/main/java/com/rymcu/forest/service/ForestFileService.java @@ -15,10 +15,11 @@ public interface ForestFileService extends Service { /** * 通过md5获取文件访问链接 * - * @param md5Value md5值 + * @param md5Value md5值 + * @param createdBy 用户id * @return */ - String getFileUrlByMd5(String md5Value); + String getFileUrlByMd5(String md5Value, long createdBy); /** * 插入文件对象 diff --git a/src/main/java/com/rymcu/forest/service/impl/ForestFileServiceImpl.java b/src/main/java/com/rymcu/forest/service/impl/ForestFileServiceImpl.java index 65b1a2a..4f178f9 100644 --- a/src/main/java/com/rymcu/forest/service/impl/ForestFileServiceImpl.java +++ b/src/main/java/com/rymcu/forest/service/impl/ForestFileServiceImpl.java @@ -22,12 +22,13 @@ public class ForestFileServiceImpl extends AbstractService implement /** * 通过md5获取文件访问链接 * - * @param md5Value md5值 + * @param md5Value md5值 + * @param createdBy 用户id * @return */ @Override - public String getFileUrlByMd5(String md5Value) { - return forestFileMapper.getFileUrlByMd5(md5Value); + public String getFileUrlByMd5(String md5Value, long createdBy) { + return forestFileMapper.getFileUrlByMd5(md5Value, createdBy); } /** diff --git a/src/main/java/com/rymcu/forest/web/api/common/UploadController.java b/src/main/java/com/rymcu/forest/web/api/common/UploadController.java index 5ea38c9..2495184 100644 --- a/src/main/java/com/rymcu/forest/web/api/common/UploadController.java +++ b/src/main/java/com/rymcu/forest/web/api/common/UploadController.java @@ -121,7 +121,7 @@ public class UploadController { TokenUser tokenUser = getTokenUser(request); Map data = new HashMap(2); String md5 = DigestUtils.md5DigestAsHex(multipartFile.getInputStream()); - String fileUrl = forestFileService.getFileUrlByMd5(md5); + String fileUrl = forestFileService.getFileUrlByMd5(md5, tokenUser.getIdUser()); if (StringUtils.isNotEmpty(fileUrl)) { data.put("url", fileUrl); return GlobalResultGenerator.genSuccessResult(data); @@ -180,7 +180,7 @@ public class UploadController { try (InputStream in = multipartFiles[i].getInputStream(); OutputStream out = Files.newOutputStream(saveFile.toPath())) { String md5 = DigestUtils.md5DigestAsHex(in); - String fileUrl = forestFileService.getFileUrlByMd5(md5); + String fileUrl = forestFileService.getFileUrlByMd5(md5, tokenUser.getIdUser()); if (StringUtils.isNotEmpty(fileUrl)) { successMap.put(orgName, fileUrl); continue; @@ -235,12 +235,9 @@ public class UploadController { @PostMapping("/file/link") @Transactional(rollbackFor = Exception.class) - public GlobalResult linkToImageUrl(@RequestBody LinkToImageUrlDTO linkToImageUrlDTO) throws IOException, BaseApiException { - //todo 无法获取当前登录用户 -// User user = UserUtils.getCurrentUserByToken(); -// if (Objects.isNull(user)) { -// throw new BaseApiException(ErrorCode.INVALID_TOKEN); -// } + public GlobalResult linkToImageUrl(@RequestBody LinkToImageUrlDTO linkToImageUrlDTO, HttpServletRequest request) throws IOException, BaseApiException { + + TokenUser tokenUser = getTokenUser(request); String url = linkToImageUrlDTO.getUrl(); URL link = new URL(url); HttpURLConnection conn = (HttpURLConnection) link.openConnection(); @@ -255,7 +252,7 @@ public class UploadController { // 获取文件md5值 String md5 = DigestUtils.md5DigestAsHex(inputStream); - String fileUrl = forestFileService.getFileUrlByMd5(md5); + String fileUrl = forestFileService.getFileUrlByMd5(md5, tokenUser.getIdUser()); Map data = new HashMap(2); data.put("originalURL", url); @@ -289,7 +286,7 @@ public class UploadController { //获取自己数组 byte[] getData = readInputStream(inputStream); FileCopyUtils.copy(getData, saveFile); - forestFileService.insertForestFile(fileUrl, savePath, md5, 1); + forestFileService.insertForestFile(fileUrl, savePath, md5, tokenUser.getIdUser()); data.put("originalURL", url); data.put("url", fileUrl); } catch (IOException e) { diff --git a/src/main/java/mapper/ForestFileMapper.xml b/src/main/java/mapper/ForestFileMapper.xml index 8b37b3c..d9dcd7a 100644 --- a/src/main/java/mapper/ForestFileMapper.xml +++ b/src/main/java/mapper/ForestFileMapper.xml @@ -20,6 +20,7 @@ select file_url from forest_file where md5_value = #{md5Value} + and created_by = #{createdBy} \ No newline at end of file