上传图片接口增加部件id,可直接上传并关联部件
This commit is contained in:
parent
97ac292069
commit
4c7b7b4347
|
@ -32,8 +32,8 @@ public class VideoFileInfoEntity extends AuditableEntity implements Serializable
|
|||
@TableId(value = "id", type = IdType.ASSIGN_ID)
|
||||
private String id;
|
||||
|
||||
@ExcelProperty("机组id")
|
||||
@ApiModelProperty(value = "机组id",required = true)
|
||||
@ExcelProperty("部件id")
|
||||
@ApiModelProperty(value = "部件id",required = true)
|
||||
@TableField("part_id")
|
||||
private String partId;
|
||||
|
||||
|
|
|
@ -29,4 +29,7 @@ public class ImageWorkReq implements Serializable {
|
|||
|
||||
@ApiModelProperty("海拔")
|
||||
private String altitude;
|
||||
|
||||
@ApiModelProperty("部件id")
|
||||
private String partId;
|
||||
}
|
||||
|
|
|
@ -10,18 +10,18 @@ import java.io.Serializable;
|
|||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* @author Bear.G
|
||||
* @date 2025/5/27/周二 15:25
|
||||
* @description
|
||||
* @author cuizhibin
|
||||
* @date 2025/06/23 11:04
|
||||
* @description 视频文件信息要求
|
||||
*/
|
||||
@Data
|
||||
@ApiModel("人员资质请求实体")
|
||||
@ApiModel("视频文件请求实体")
|
||||
public class VideoFileInfoReq implements Serializable {
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1737569842748352413L;
|
||||
|
||||
@NotBlank(message = "机组id不能为空")
|
||||
@ApiModelProperty(value = "机组id",required = true)
|
||||
@NotBlank(message = "部件id不能为空")
|
||||
@ApiModelProperty(value = "部件id",required = true)
|
||||
private String partId;
|
||||
|
||||
@ApiModelProperty("测试点")
|
||||
|
|
|
@ -4,6 +4,7 @@ import cn.hutool.core.collection.CollUtil;
|
|||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.dite.znpt.constant.Constants;
|
||||
import com.dite.znpt.constant.Message;
|
||||
import com.dite.znpt.converts.Converts;
|
||||
import com.dite.znpt.domain.entity.ImageCollectEntity;
|
||||
|
@ -67,7 +68,7 @@ public class ImageCollectServiceImpl extends ServiceImpl<ImageCollectMapper, Ima
|
|||
if (file.exists()) {
|
||||
byte[] bytes = FileUtil.readBytes(file);
|
||||
FileUtil.writeBytes(bytes, path);
|
||||
String url = "/static/image/".concat(StrUtil.removePrefix(path,permPath).replace(FileUtil.FILE_SEPARATOR, StrUtil.SLASH));
|
||||
String url = Constants.PERM_IMAGE_PATH.concat(StrUtil.removePrefix(path,permPath).replace(FileUtil.FILE_SEPARATOR, StrUtil.SLASH));
|
||||
image.setImagePath(url);
|
||||
FileUtil.del(file);
|
||||
}else {
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
package com.dite.znpt.service.impl;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
|
@ -168,10 +169,10 @@ public class ImageServiceImpl extends ServiceImpl<ImageMapper, ImageEntity> impl
|
|||
String dateStr = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
||||
String path_prefix = permPath.concat(imageSource).concat(FileUtil.FILE_SEPARATOR).concat(dateStr).concat(FileUtil.FILE_SEPARATOR);
|
||||
if (Objects.nonNull(imageWorkReq)) {
|
||||
path_prefix = path_prefix.concat(StrUtil.nullToDefault(imageWorkReq.getUploadUser(), "默认用户")).concat(FileUtil.FILE_SEPARATOR)
|
||||
.concat(StrUtil.nullToDefault(imageWorkReq.getLongitude(), "0"))
|
||||
.concat(" ").concat(StrUtil.nullToDefault(imageWorkReq.getLatitude(), "0"))
|
||||
.concat(" ").concat(StrUtil.nullToDefault(imageWorkReq.getAltitude(), "0"))
|
||||
path_prefix = path_prefix.concat(StrUtil.emptyToDefault(imageWorkReq.getUploadUser(), "默认用户")).concat(FileUtil.FILE_SEPARATOR)
|
||||
.concat(StrUtil.emptyToDefault(imageWorkReq.getLongitude(), "0"))
|
||||
.concat(" ").concat(StrUtil.emptyToDefault(imageWorkReq.getLatitude(), "0"))
|
||||
.concat(" ").concat(StrUtil.emptyToDefault(imageWorkReq.getAltitude(), "0"))
|
||||
.concat(FileUtil.FILE_SEPARATOR);
|
||||
}
|
||||
if (!FileUtil.exist(path_prefix)) {
|
||||
|
@ -183,6 +184,39 @@ public class ImageServiceImpl extends ServiceImpl<ImageMapper, ImageEntity> impl
|
|||
FileUtil.writeBytes(multipartFile.getBytes(),path);
|
||||
result.add(getImageDownPath(StrUtil.removePrefix(path, permPath)));
|
||||
}
|
||||
String partId = imageWorkReq.getPartId();
|
||||
if (Objects.nonNull(partId)) {
|
||||
ImageCollectEntity imageCollect = new ImageCollectEntity();
|
||||
imageCollect.setCollectId(IdUtil.simpleUUID());
|
||||
imageCollect.setCollectorName(imageWorkReq.getUploadUser());
|
||||
PartEntity part = partService.getById(partId);
|
||||
if (Objects.isNull(part)) {
|
||||
throw new ServiceException(Message.PART_ID_IS_NOT_EXIST);
|
||||
}
|
||||
List<ImageEntity> imageList = new ArrayList<>();
|
||||
result.forEach(path -> {
|
||||
ImageEntity imageEntity = new ImageEntity();
|
||||
String absolutePath = permPath + StrUtil.removePrefix(path, Constants.PERM_IMAGE_PATH);
|
||||
try {
|
||||
ImageReq imageReq = imageRespBuilder(absolutePath);
|
||||
BeanUtil.copyProperties(imageReq, imageEntity);
|
||||
} catch (Exception e) {
|
||||
log.debug("读取文件信息失败:{}", path);
|
||||
imageEntity.setImageName(FileUtil.getName(absolutePath));
|
||||
BigDecimal imageSize = new BigDecimal(FileUtil.size(FileUtil.file(absolutePath))).divide(new BigDecimal(1024*1024), 4, RoundingMode.HALF_UP);
|
||||
imageEntity.setImageSize(imageSize.toString().concat("M"));
|
||||
}
|
||||
imageEntity.setLongitude(imageWorkReq.getLongitude());
|
||||
imageEntity.setLatitude(imageWorkReq.getLatitude());
|
||||
imageEntity.setAltitude(imageWorkReq.getAltitude());
|
||||
imageEntity.setImagePath(path);
|
||||
imageEntity.setPartId(partId);
|
||||
imageEntity.setCollectId(imageCollect.getCollectId());
|
||||
imageList.add(imageEntity);
|
||||
});
|
||||
imageCollectService.save(imageCollect);
|
||||
baseMapper.insert(imageList);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -392,7 +426,7 @@ public class ImageServiceImpl extends ServiceImpl<ImageMapper, ImageEntity> impl
|
|||
List<ImageEntity> newImageList = new ArrayList<>();
|
||||
partReq.getImagePaths().forEach(path -> {
|
||||
ImageEntity imageEntity = new ImageEntity();
|
||||
String absolutePath = permPath + StrUtil.removePrefix(path, "/static/image/");
|
||||
String absolutePath = permPath + StrUtil.removePrefix(path, Constants.PERM_IMAGE_PATH);
|
||||
try {
|
||||
ImageReq imageReq = imageRespBuilder(absolutePath);
|
||||
BeanUtil.copyProperties(imageReq, imageEntity);
|
||||
|
|
|
@ -2,20 +2,17 @@ package com.dite.znpt.web.controller;
|
|||
|
||||
import com.dite.znpt.constant.Message;
|
||||
import com.dite.znpt.domain.Result;
|
||||
import com.dite.znpt.domain.vo.AppImageResp;
|
||||
import com.dite.znpt.domain.vo.ImageWorkReq;
|
||||
import com.dite.znpt.enums.*;
|
||||
import com.dite.znpt.exception.ServiceException;
|
||||
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;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author: gaoxiong
|
||||
|
@ -110,36 +107,18 @@ public class CommonController {
|
|||
|
||||
@ApiOperation(value = "上传图片", httpMethod = "POST")
|
||||
@PostMapping("/upload-image/{imageSource}")
|
||||
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,
|
||||
public Result uploadImage(@PathVariable String imageSource, ImageWorkReq workReq,
|
||||
MultipartFile file) throws IOException {
|
||||
if(null == file){
|
||||
throw new ServiceException(Message.IMAGE_IS_EMPTY);
|
||||
}
|
||||
ImageWorkReq workReq = new ImageWorkReq();
|
||||
workReq.setUploadUser(uploadUser);
|
||||
workReq.setLongitude(longitude);
|
||||
workReq.setLatitude(latitude);
|
||||
workReq.setAltitude(altitude);
|
||||
return Result.ok(imageService.batchUploadCommonImage(imageSource, workReq, new MultipartFile[]{file}).get(0));
|
||||
}
|
||||
|
||||
@ApiOperation(value = "批量上传图片", httpMethod = "POST")
|
||||
@PostMapping("/batch-upload-image/{imageSource}")
|
||||
public Result batchUploadImage(@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,
|
||||
public Result batchUploadImage(@PathVariable String imageSource, ImageWorkReq workReq,
|
||||
@RequestParam("file") MultipartFile[] files) throws IOException {
|
||||
ImageWorkReq workReq = new ImageWorkReq();
|
||||
workReq.setUploadUser(uploadUser);
|
||||
workReq.setLongitude(longitude);
|
||||
workReq.setLatitude(latitude);
|
||||
workReq.setAltitude(altitude);
|
||||
return Result.ok(imageService.batchUploadCommonImage(imageSource, workReq, files));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue