|
@@ -19,6 +19,8 @@ import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
+
|
|
|
/**
|
|
|
* @Description: 文件上传服务接口实现
|
|
|
* @author: gaodm
|
|
@@ -80,6 +82,9 @@ public class UploadServiceImpl implements UploadService {
|
|
|
fileDTO.setMd5(fileUploadDTO.getMd5());
|
|
|
fileDTO.setOriginal(file.getOriginalFilename());
|
|
|
fileDTO.setTitle(file.getOriginalFilename());
|
|
|
+ BigDecimal bg = new BigDecimal(file.getSize() / (1.0 * 1024 * 1024));
|
|
|
+ double d = bg.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
|
|
|
+ fileDTO.setSize(d + "M");
|
|
|
return fileDTO;
|
|
|
}
|
|
|
|
|
@@ -126,4 +131,19 @@ public class UploadServiceImpl implements UploadService {
|
|
|
}
|
|
|
return new FileDTO("SUCCESS", "文件删除成功");
|
|
|
}
|
|
|
+
|
|
|
+ public static void main(String[] args) {
|
|
|
+ long size = 1023 * 33;
|
|
|
+
|
|
|
+ BigDecimal bg = new BigDecimal(size/ (1.0 * 1024 * 1024));
|
|
|
+ double d3 = bg.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
|
|
|
+ System.out.println(d3);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (size < 1024 * 1024) {
|
|
|
+ System.out.println(size / (1.0 * 1024) + "KB");
|
|
|
+ }
|
|
|
+ System.out.println(size / (1.0 * 1024 * 1024) + "M");
|
|
|
+ }
|
|
|
}
|