|
@@ -47,60 +47,50 @@ import java.util.*;
|
|
|
@Log4j2
|
|
|
@Api(tags = "共用接口")
|
|
|
@RestController
|
|
|
-//@RequestMapping("manage/common")
|
|
|
-@RequestMapping("/common")
|
|
|
+@RequestMapping("manage/common")
|
|
|
+//@RequestMapping("/common")
|
|
|
//@Transactional
|
|
|
public class CommonController extends BaseController {
|
|
|
|
|
|
-// @ApiImplicitParams({
|
|
|
-// @ApiImplicitParam(name = "type", value = "模型类型, roam:自由漫游,part:部件欣赏,building: 建筑物,ico时不用传", required = false),
|
|
|
-// @ApiImplicitParam(name = "files", value = "可以接收多个文件", required = true),
|
|
|
-// })
|
|
|
+
|
|
|
@ApiOperation("上传, 可以接收多个文件")
|
|
|
@PostMapping(value = "upload", consumes = {"multipart/form-data"})
|
|
|
- public Result upload(MultipartFile [] files ) throws IOException {
|
|
|
+ public Result upload(MultipartFile [] file ) throws IOException {
|
|
|
|
|
|
- if (files == null) {
|
|
|
+ if (file.length <= 0) {
|
|
|
log.error("文件不能为空");
|
|
|
return Result.failure("文件不能为空");
|
|
|
}
|
|
|
|
|
|
// 写入本地服务器
|
|
|
- List<Map<String, String>> uploads = FileUtils.upload(files, OUT_PATH);
|
|
|
+ List<Map<String, String>> uploads = FileUtils.upload(file, OUT_PATH);
|
|
|
|
|
|
- HashMap<Long, String> resultMap = new HashMap<>();
|
|
|
+ HashMap<String, String> resultMap = new HashMap<>();
|
|
|
String dir = null;
|
|
|
- int a = 0;
|
|
|
for (Map<String, String> map: uploads) {
|
|
|
String fileName = map.get("name");
|
|
|
String newName = map.get("newName");
|
|
|
- String ossPath = OSS_PATH+"/image/" + newName;
|
|
|
+ String ossPath = OSS_PATH+"image/" + newName;
|
|
|
log.info("local {}, ", map.get("path"));
|
|
|
// 上传到oss
|
|
|
AliyunOssUtil.upload(map.get("path"), ossPath);
|
|
|
|
|
|
// 保存db
|
|
|
FileEntity entity = new FileEntity();
|
|
|
-
|
|
|
entity.setFileName(fileName);
|
|
|
-
|
|
|
String ossUrl = OSS_DOMAIN+ossPath;
|
|
|
entity.setFilePath(ossUrl);
|
|
|
|
|
|
fileService.save(entity);
|
|
|
|
|
|
// 返回前端数据
|
|
|
- resultMap.put(entity.getId(), ossUrl);
|
|
|
+ resultMap.put(entity.getId().toString(), ossUrl);
|
|
|
dir = map.get("dir");
|
|
|
- ++ a;
|
|
|
}
|
|
|
|
|
|
// 删除本地服务器物理文件,用删除目录的方式
|
|
|
FileUtil.del(OUT_PATH + dir);
|
|
|
|
|
|
-// log.info("resultMap {}, ", resultMap);
|
|
|
-
|
|
|
- // 用swagger测试有bug, 不显示返回值;使用postman可以
|
|
|
return Result.success(resultMap);
|
|
|
|
|
|
}
|
|
@@ -108,18 +98,7 @@ public class CommonController extends BaseController {
|
|
|
@ApiOperation("删除文件")
|
|
|
@GetMapping("removes/{ids}")
|
|
|
public Result removes(@PathVariable String ids) throws IOException {
|
|
|
-
|
|
|
-// // 删除oss物理文件
|
|
|
-// List<FileEntity> files = fileService.findByIds(ids);
|
|
|
-// for (FileEntity entity: files) {
|
|
|
-// String filePath = entity.getFilePath();
|
|
|
-// filePath = OSS_PATH + StringUtils.substringAfterLast(filePath, "/");
|
|
|
-// log.info("remove oss file: {}", filePath);
|
|
|
-// AliyunOssUtil.delete(filePath);
|
|
|
-// }
|
|
|
-//
|
|
|
-// // 删除db记录
|
|
|
-// fileService.deleteByIds(ids);
|
|
|
+ // 删除oss物理文件
|
|
|
removeFile(ids);
|
|
|
|
|
|
return Result.success();
|