feat: 开发中...
This commit is contained in:
@@ -48,15 +48,21 @@ public class AttachService implements IAttachService {
|
||||
if (checked != null) {
|
||||
return checked;
|
||||
}
|
||||
log.info("prepare to save file: {}({} bytes)", file.getOriginalFilename(), file.getSize());
|
||||
log.info("prepare to save file: {}({} kb)", file.getOriginalFilename(), file.getSize() / 1024.0);
|
||||
long time1 = System.currentTimeMillis();
|
||||
AttachEntity attachEntity = new AttachEntity();
|
||||
attachEntity.setFilename(file.getOriginalFilename());
|
||||
attachEntity.setContentType(file.getContentType());
|
||||
attachEntity.setData(file.getBytes());
|
||||
attachEntity = attachRepo.save(attachEntity);
|
||||
long time2 = System.currentTimeMillis();
|
||||
log.info("file upload finished, took {} ms", time2 - time1);
|
||||
|
||||
File localCacheFile = new File(ATTACH_FOLDER, String.valueOf(attachEntity.getId()));
|
||||
Files.copy(file.getInputStream(), localCacheFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
|
||||
log.info("written attach data to local cache file: {}. took {} ms",
|
||||
localCacheFile.getName(),
|
||||
System.currentTimeMillis() - time2);
|
||||
|
||||
return ResponseVO.success(attachEntity.getId());
|
||||
}
|
||||
@@ -113,16 +119,23 @@ public class AttachService implements IAttachService {
|
||||
if (!attachRepo.existsById(attachID)) {
|
||||
return ResponseVO.notFound();
|
||||
}
|
||||
log.info("update attach {}, save file {} to database. ({} kb)", attachID,
|
||||
file.getOriginalFilename(), file.getSize() / 1024.0);
|
||||
long time1 = System.currentTimeMillis();
|
||||
attachRepo.updateFilenameAndContentTypeAndDataById(
|
||||
file.getOriginalFilename(),
|
||||
file.getContentType(),
|
||||
file.getBytes(),
|
||||
attachID
|
||||
);
|
||||
long time2 = System.currentTimeMillis();
|
||||
log.info("file upload finished, took {} ms", time2 - time1);
|
||||
|
||||
File localCacheFile = new File(ATTACH_FOLDER, String.valueOf(attachID));
|
||||
Files.copy(file.getInputStream(), localCacheFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
|
||||
log.info("written attach data to local cache file: {}", localCacheFile.getName());
|
||||
log.info("written attach data to local cache file: {}. took {} ms",
|
||||
localCacheFile.getName(),
|
||||
System.currentTimeMillis() - time2);
|
||||
|
||||
return ResponseVO.success();
|
||||
}
|
||||
|
Reference in New Issue
Block a user