修改通用上传,增加字段
This commit is contained in:
parent
9d2cf4c916
commit
b57e6cc4c5
|
@ -0,0 +1,32 @@
|
|||
package com.dite.znpt.domain.vo;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @Author: gaoxiong
|
||||
* @Date: 2025/5/11 22:29
|
||||
* @Description:
|
||||
*/
|
||||
@Data
|
||||
@ApiModel("内部、外部、防雷图像简易请求实体")
|
||||
public class ImageWorkReq implements Serializable {
|
||||
@Serial
|
||||
private static final long serialVersionUID = 4813411833253078204L;
|
||||
|
||||
@ApiModelProperty("上传人")
|
||||
private String uploadUser;
|
||||
|
||||
@ApiModelProperty("经度")
|
||||
private String longitude;
|
||||
|
||||
@ApiModelProperty("纬度")
|
||||
private String latitude;
|
||||
|
||||
@ApiModelProperty("海拔")
|
||||
private String altitude;
|
||||
}
|
|
@ -15,6 +15,7 @@ import java.util.List;
|
|||
public enum ImageSourceEnum {
|
||||
COLLECT("collect", "图像采集", Boolean.TRUE),
|
||||
OUT_WORK("out-work", "外部工作", Boolean.TRUE),
|
||||
IN_WORK("in-work", "外部工作", Boolean.TRUE),
|
||||
LIGHTNING_PROTECTING_WORK("lightning-protection-work", "防雷工作", Boolean.FALSE);
|
||||
|
||||
private final String code;
|
||||
|
|
|
@ -25,7 +25,7 @@ public interface ImageService extends IService<ImageEntity> {
|
|||
|
||||
List<ImageReq> batchUploadDefectImage(String partId, String imageSource, MultipartFile[] files);
|
||||
|
||||
String uploadCommonImage(String imageSource, MultipartFile file) throws IOException;
|
||||
String uploadCommonImage(String imageSource, ImageWorkReq imageWorkReq, MultipartFile file) throws IOException;
|
||||
|
||||
void delete(String imageId);
|
||||
}
|
||||
|
|
|
@ -34,6 +34,7 @@ import java.time.format.DateTimeFormatter;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Function;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
@ -138,16 +139,26 @@ public class ImageServiceImpl extends ServiceImpl<ImageMapper, ImageEntity> impl
|
|||
}
|
||||
|
||||
@Override
|
||||
public String uploadCommonImage(String imageSource, MultipartFile file) throws IOException {
|
||||
public String uploadCommonImage(String imageSource, ImageWorkReq imageWorkReq, MultipartFile file) throws IOException {
|
||||
if(null == file){
|
||||
throw new ServiceException(Message.IMAGE_IS_EMPTY);
|
||||
}
|
||||
ImageSourceEnum imageSourceEnum = ImageSourceEnum.getByCode(imageSource);
|
||||
if(null == imageSourceEnum || imageSourceEnum.isDefectImage()){
|
||||
throw new ServiceException(Message.IMAGE_SOURCE_ID_NOT_EXIST_OR_ILLEGAL);
|
||||
}
|
||||
String dateStr = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
||||
String path_prefix = permPath.concat(FileUtil.FILE_SEPARATOR).concat(dateStr).concat(FileUtil.FILE_SEPARATOR).concat(imageSource).concat(FileUtil.FILE_SEPARATOR);
|
||||
if (Objects.nonNull(imageWorkReq)) {
|
||||
if (StrUtil.isNotBlank(imageWorkReq.getUploadUser())) {
|
||||
path_prefix = path_prefix.concat(imageWorkReq.getUploadUser()).concat(FileUtil.FILE_SEPARATOR);
|
||||
}
|
||||
if (StrUtil.isNotBlank(imageWorkReq.getLongitude())) {
|
||||
path_prefix = path_prefix.concat(imageWorkReq.getLongitude())
|
||||
.concat(" ").concat(StrUtil.nullToDefault(imageWorkReq.getLatitude(), "0"))
|
||||
.concat(" ").concat(StrUtil.nullToDefault(imageWorkReq.getAltitude(), "0"))
|
||||
.concat(FileUtil.FILE_SEPARATOR);
|
||||
}
|
||||
}
|
||||
if (!FileUtil.exist(path_prefix)) {
|
||||
FileUtil.mkdir(path_prefix);
|
||||
}
|
||||
String path = path_prefix + file.getOriginalFilename();
|
||||
FileUtil.writeBytes(file.getBytes(),path);
|
||||
return path;
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
package com.dite.znpt.web.controller;
|
||||
|
||||
import com.dite.znpt.domain.Result;
|
||||
import com.dite.znpt.domain.vo.ImageWorkReq;
|
||||
import com.dite.znpt.enums.*;
|
||||
import com.dite.znpt.service.ImageService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
|
@ -101,8 +103,18 @@ public class CommonController {
|
|||
|
||||
@ApiOperation(value = "上传图片", httpMethod = "POST")
|
||||
@PostMapping("/upload-image/{imageSource}")
|
||||
public Result uploadImage(@PathVariable String imageSource, MultipartFile file) throws IOException {
|
||||
return Result.ok(imageService.uploadCommonImage(imageSource, file));
|
||||
public Result uploadImage(@PathVariable String imageSource,
|
||||
@Parameter(description = "上传用户")@RequestParam(required = false) String uploadUser,
|
||||
@Parameter(description = "经度")@RequestParam(required = false) String longitude,
|
||||
@Parameter(description = "纬度")@RequestParam(required = false) String latitude,
|
||||
@Parameter(description = "海拔")@RequestParam(required = false) String altitude,
|
||||
MultipartFile file) throws IOException {
|
||||
ImageWorkReq workReq = new ImageWorkReq();
|
||||
workReq.setUploadUser(uploadUser);
|
||||
workReq.setLongitude(longitude);
|
||||
workReq.setLatitude(latitude);
|
||||
workReq.setAltitude(altitude);
|
||||
return Result.ok(imageService.uploadCommonImage(imageSource, workReq, file));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -117,6 +117,6 @@ zlm-config:
|
|||
dynamicPortEnd: 30185
|
||||
|
||||
upload:
|
||||
temp-path: F:\Upload\Image\Temp
|
||||
perm-path: F:\Upload\Image
|
||||
temp-path: d:\Upload\Image\Temp
|
||||
perm-path: d:\Upload\Image
|
||||
|
||||
|
|
Loading…
Reference in New Issue