本地图片上传
This commit is contained in:
parent
136e7afb7a
commit
246c1509dd
@ -1,10 +1,15 @@
|
|||||||
package com.aircraft.modules.aircraft.domain;
|
package com.aircraft.modules.aircraft.domain;
|
||||||
|
|
||||||
|
import com.aircraft.base.SysBaseEntity;
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
import com.aircraft.base.BaseEntity;
|
import com.aircraft.base.BaseEntity;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotBlank;
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
* 飞行器设备表
|
* 飞行器设备表
|
||||||
@ -23,46 +28,63 @@ public class AircraftDevice extends BaseEntity {
|
|||||||
/**
|
/**
|
||||||
* 主键id
|
* 主键id
|
||||||
*/
|
*/
|
||||||
|
@NotNull(groups = SysBaseEntity.Update.class)
|
||||||
|
@ApiModelProperty(value = "主键id")
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 飞行器名称
|
* 飞行器名称
|
||||||
*/
|
*/
|
||||||
|
@NotBlank
|
||||||
|
@ApiModelProperty(value = "飞行器名称")
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设备型号
|
* 设备型号
|
||||||
*/
|
*/
|
||||||
|
@NotBlank
|
||||||
|
@ApiModelProperty(value = "设备型号")
|
||||||
private String model;
|
private String model;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 品牌(DJI,SF)
|
* 品牌(DJI,SF)
|
||||||
*/
|
*/
|
||||||
|
@NotBlank
|
||||||
|
@ApiModelProperty(value = "品牌(DJI,SF)")
|
||||||
private String brand;
|
private String brand;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 类型:0-载物飞行,1-载人飞行,2-其他
|
* 类型:0-载物飞行,1-载人飞行,2-其他
|
||||||
*/
|
*/
|
||||||
|
@NotNull
|
||||||
|
@ApiModelProperty(value = "类型:0-载物飞行,1-载人飞行,2-其他")
|
||||||
private Integer useType;
|
private Integer useType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 区域id
|
* 区域id
|
||||||
*/
|
*/
|
||||||
|
@NotNull
|
||||||
|
@ApiModelProperty(value = "区域id")
|
||||||
private Long areaId;
|
private Long areaId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 景区id
|
* 景区id
|
||||||
*/
|
*/
|
||||||
|
@NotNull
|
||||||
|
@ApiModelProperty(value = "景区id")
|
||||||
private Long scenicId;
|
private Long scenicId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 飞行员(负责人)id
|
* 飞行员(负责人)id
|
||||||
*/
|
*/
|
||||||
|
@NotNull
|
||||||
|
@ApiModelProperty(value = "飞行员(负责人)id")
|
||||||
private Long employeesId;
|
private Long employeesId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 备注
|
* 备注
|
||||||
*/
|
*/
|
||||||
|
@ApiModelProperty(value = "备注")
|
||||||
private String remark;
|
private String remark;
|
||||||
|
|
||||||
|
|
||||||
|
@ -0,0 +1,52 @@
|
|||||||
|
package com.aircraft.modules.system.domain.dto;
|
||||||
|
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 本地附件材料DTO
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class LocalAttachmentMaterialDTO {
|
||||||
|
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "id")
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文件类型(jpg,png)
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "文件类型(jpg,png)")
|
||||||
|
private String fileType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 源文件名称
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "源文件名称")
|
||||||
|
private String sourceFileName;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新文件名称
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "新文件名称")
|
||||||
|
private String newFileName;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文件大小(字节)
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "文件大小(字节)")
|
||||||
|
private Long fileSize;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文件的全路径
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "文件的全路径")
|
||||||
|
private String fileFullPath;
|
||||||
|
}
|
@ -65,6 +65,10 @@ public class S3Storage extends SysBaseEntity implements Serializable {
|
|||||||
@ApiModelProperty(value = "文件路径")
|
@ApiModelProperty(value = "文件路径")
|
||||||
private String filePath;
|
private String filePath;
|
||||||
|
|
||||||
|
@NotBlank
|
||||||
|
@ApiModelProperty(value = "文件全路径")
|
||||||
|
private String fileFullPath;
|
||||||
|
|
||||||
public void copy(S3Storage source){
|
public void copy(S3Storage source){
|
||||||
BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
|
BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,50 @@
|
|||||||
|
package com.aircraft.domain.dto;
|
||||||
|
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 本地附件材料DTO
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class LocalAttachmentMaterialDTO {
|
||||||
|
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "id")
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文件类型(jpg,png)
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "文件类型(jpg,png)")
|
||||||
|
private String fileType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 源文件名称
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "源文件名称")
|
||||||
|
private String sourceFileName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新文件名称
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "新文件名称")
|
||||||
|
private String newFileName;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文件大小(字节)
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "文件大小(字节)")
|
||||||
|
private Long fileSize;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文件的全路径
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "文件的全路径")
|
||||||
|
private String fileFullPath;
|
||||||
|
}
|
@ -15,6 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.aircraft.rest;
|
package com.aircraft.rest;
|
||||||
|
|
||||||
|
import com.aircraft.domain.dto.LocalAttachmentMaterialDTO;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import com.aircraft.annotation.Log;
|
import com.aircraft.annotation.Log;
|
||||||
@ -63,37 +64,43 @@ public class LocalStorageController {
|
|||||||
|
|
||||||
@PostMapping
|
@PostMapping
|
||||||
@ApiOperation("上传文件")
|
@ApiOperation("上传文件")
|
||||||
public ResponseEntity<Object> createFile(@RequestParam String name, @RequestParam("file") MultipartFile file){
|
public ResponseEntity<Object> createFile(@RequestParam String name, @RequestPart("file") MultipartFile file){
|
||||||
localStorageService.create(name, file);
|
localStorageService.create(name, file);
|
||||||
return new ResponseEntity<>(HttpStatus.CREATED);
|
return new ResponseEntity<>(HttpStatus.CREATED);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation("上传图片")
|
@ApiOperation("上传图片")
|
||||||
@PostMapping("/pictures")
|
@PostMapping("/pictures")
|
||||||
public ResponseEntity<LocalStorage> uploadPicture(@RequestParam MultipartFile file){
|
public ResponseEntity<LocalAttachmentMaterialDTO> uploadPicture(@RequestPart("file") MultipartFile file){
|
||||||
// 判断文件是否为图片
|
// 判断文件是否为图片
|
||||||
String suffix = FileUtil.getExtensionName(file.getOriginalFilename());
|
String suffix = FileUtil.getExtensionName(file.getOriginalFilename());
|
||||||
if(!FileUtil.IMAGE.equals(FileUtil.getFileType(suffix))){
|
if(!FileUtil.IMAGE.equals(FileUtil.getFileType(suffix))){
|
||||||
throw new BadRequestException("只能上传图片");
|
throw new BadRequestException("只能上传图片");
|
||||||
}
|
}
|
||||||
LocalStorage localStorage = localStorageService.create(null, file);
|
LocalStorage localStorage = localStorageService.create(file.getName(), file);
|
||||||
return new ResponseEntity<>(localStorage, HttpStatus.OK);
|
LocalAttachmentMaterialDTO localAttachmentMaterialDTO = new LocalAttachmentMaterialDTO();
|
||||||
|
localAttachmentMaterialDTO.setFileType(localStorage.getSuffix());
|
||||||
|
localAttachmentMaterialDTO.setFileSize(file.getSize());
|
||||||
|
localAttachmentMaterialDTO.setNewFileName(localStorage.getRealName());
|
||||||
|
localAttachmentMaterialDTO.setSourceFileName(localStorage.getName());
|
||||||
|
localAttachmentMaterialDTO.setFileFullPath(localStorage.getPath());
|
||||||
|
return new ResponseEntity<>(localAttachmentMaterialDTO, HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PutMapping
|
// @PutMapping
|
||||||
@Log("修改文件")
|
// @Log("修改文件")
|
||||||
@ApiOperation("修改文件")
|
// @ApiOperation("修改文件")
|
||||||
public ResponseEntity<Object> updateFile(@Validated @RequestBody LocalStorage resources){
|
// public ResponseEntity<Object> updateFile(@Validated @RequestBody LocalStorage resources){
|
||||||
localStorageService.update(resources);
|
// localStorageService.update(resources);
|
||||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
// return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@Log("删除文件")
|
// @Log("删除文件")
|
||||||
@DeleteMapping
|
// @DeleteMapping
|
||||||
@ApiOperation("多选删除")
|
// @ApiOperation("多选删除")
|
||||||
@PreAuthorize("@el.check('storage:del')")
|
// @PreAuthorize("@el.check('storage:del')")
|
||||||
public ResponseEntity<Object> deleteFile(@RequestBody Long[] ids) {
|
// public ResponseEntity<Object> deleteFile(@RequestBody Long[] ids) {
|
||||||
localStorageService.deleteAll(ids);
|
// localStorageService.deleteAll(ids);
|
||||||
return new ResponseEntity<>(HttpStatus.OK);
|
// return new ResponseEntity<>(HttpStatus.OK);
|
||||||
}
|
// }
|
||||||
}
|
}
|
@ -69,7 +69,7 @@ public class S3StorageController {
|
|||||||
|
|
||||||
@PostMapping
|
@PostMapping
|
||||||
@ApiOperation("上传文件")
|
@ApiOperation("上传文件")
|
||||||
public ResponseEntity<Object> uploadS3Storage(@RequestParam MultipartFile file){
|
public ResponseEntity<Object> uploadS3Storage(@RequestPart("file") MultipartFile file){
|
||||||
S3Storage storage = s3StorageService.upload(file);
|
S3Storage storage = s3StorageService.upload(file);
|
||||||
Map<String,Object> map = new HashMap<>(3);
|
Map<String,Object> map = new HashMap<>(3);
|
||||||
map.put("id",storage.getId());
|
map.put("id",storage.getId());
|
||||||
|
@ -139,6 +139,7 @@ public class S3StorageServiceImpl extends ServiceImpl<S3StorageMapper, S3Storage
|
|||||||
s3Storage.setFileSize(FileUtil.getSize(file.getSize()));
|
s3Storage.setFileSize(FileUtil.getSize(file.getSize()));
|
||||||
s3Storage.setFileType(FileUtil.getExtensionName(originalName));
|
s3Storage.setFileType(FileUtil.getExtensionName(originalName));
|
||||||
s3Storage.setFilePath(filePath);
|
s3Storage.setFilePath(filePath);
|
||||||
|
s3Storage.setFileFullPath(amzS3Config.getDomain() + "/" + s3Storage.getFilePath());
|
||||||
// 保存入库
|
// 保存入库
|
||||||
s3StorageMapper.insert(s3Storage);
|
s3StorageMapper.insert(s3Storage);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
Loading…
Reference in New Issue
Block a user