Compare commits

...

2 Commits

Author SHA1 Message Date
cuizhibin 695a32f5ce 1.增加手动上传图片到项目下的接口 2025-07-24 19:58:33 +08:00
cuizhibin c7bec730b4 1.调整图片信息预处理保存路径 2025-07-24 19:58:33 +08:00
4 changed files with 70 additions and 14 deletions

View File

@ -49,7 +49,9 @@ public class Schedule {
PartResp partResp = partRespMap.get(image.getPartId());
FilePathEnum pathEnum = image.getImagePath().contains("temp") ? FilePathEnum.IMAGE_TEMP : FilePathEnum.IMAGE;
String inputFile = pathEnum.getFileAbsolutePath(image.getImagePath());
String outputDir = FilePathEnum.IMAGE.getFileAbsolutePathPrefix().concat(partResp.getProjectName())
String outputDir = FilePathEnum.IMAGE.getFileAbsolutePathPrefix()
.concat("已调整")
.concat(FileUtil.FILE_SEPARATOR).concat(partResp.getProjectName())
.concat(FileUtil.FILE_SEPARATOR).concat(partResp.getTurbineName())
.concat(FileUtil.FILE_SEPARATOR).concat(partResp.getPartName());
extUtilConfig.imagePreTreatment(inputFile, outputDir);

View File

@ -25,6 +25,8 @@ public interface ImageService extends IService<ImageEntity> {
List<ImageReq> batchUploadDefectImage(String partId, String imageSource, ImageCollectReq collectReq, MultipartFile[] files);
List<ImageReq> uploadProjectBatch(String projectId, String imageSource, MultipartFile[] files);
List<String> batchUploadCommonImage(String imageSource, ImageWorkReq imageWorkReq, MultipartFile[] file) throws IOException;
void delete(String imageId);

View File

@ -1,5 +1,6 @@
package com.dite.znpt.service.impl;
import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.ListUtil;
@ -19,12 +20,10 @@ import com.dite.znpt.domain.vo.*;
import com.dite.znpt.enums.*;
import com.dite.znpt.exception.ServiceException;
import com.dite.znpt.mapper.ImageMapper;
import com.dite.znpt.service.AudioFileInfoService;
import com.dite.znpt.service.ImageCollectService;
import com.dite.znpt.service.ImageService;
import com.dite.znpt.service.PartService;
import com.dite.znpt.service.*;
import com.dite.znpt.util.EXIFUtil;
import com.dite.znpt.util.PageUtil;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -65,6 +64,9 @@ public class ImageServiceImpl extends ServiceImpl<ImageMapper, ImageEntity> impl
private PartService partService;
@Autowired
private AudioFileInfoService audioFileInfoService;
private ProjectService projectService;
@Autowired
private UserService userService;
@Override
public List<ImageListResp> list(ImageListReq req) {
@ -159,11 +161,11 @@ public class ImageServiceImpl extends ServiceImpl<ImageMapper, ImageEntity> impl
try {
String path = temPathPrefix + file.getOriginalFilename();
FileUtil.writeBytes(file.getBytes(),path);
ImageReq imageReq = imageRespBuilder(path);
String fileDownPath = FilePathEnum.IMAGE_TEMP.getFileDownPath(path);
ImageReq imageReq = imageRespBuilder(path, fileDownPath);
imageReq.setImageId(IdUtil.simpleUUID());
BeanUtil.copyProperties(imageReq, imageEntity);
list.add(imageReq);
imageEntity.setImagePath(FilePathEnum.IMAGE_TEMP.getFileDownPath(path));
imageEntity.setPartId(partId);
imageEntity.setProjectId(partResp.getProjectId());
imageEntity.setCollectId(imageCollect.getCollectId());
@ -180,6 +182,50 @@ public class ImageServiceImpl extends ServiceImpl<ImageMapper, ImageEntity> impl
return list;
}
@SneakyThrows
@Override
public List<ImageReq> uploadProjectBatch(String projectId, String imageSource, MultipartFile[] files) {
if (Objects.isNull(projectService.getById(projectId))) {
throw new ServiceException(Message.PROJECT_ID_IS_NOT_EXIST);
}
if(null == files || files.length == 0){
throw new ServiceException(Message.IMAGE_IS_EMPTY);
}
String dateStr = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
String path_prefix = FilePathEnum.IMAGE.getFileAbsolutePathPrefix().concat(imageSource).concat(FileUtil.FILE_SEPARATOR)
.concat(projectId).concat(FileUtil.FILE_SEPARATOR)
.concat(dateStr).concat(FileUtil.FILE_SEPARATOR);
if (!FileUtil.exist(path_prefix)) {
FileUtil.mkdir(path_prefix);
}
List<ImageReq> list = new ArrayList<>(files.length);
List<ImageEntity> imageList = new ArrayList<>();
ImageCollectEntity imageCollect = new ImageCollectEntity();
imageCollect.setCollectId(IdUtil.simpleUUID());
imageCollect.setCollectorId(StpUtil.getLoginIdAsString());
imageCollect.setCollectorName(userService.getById(StpUtil.getLoginIdAsString()).getName());
for (MultipartFile multipartFile : files) {
String absolutePath = path_prefix + multipartFile.getOriginalFilename();
FileUtil.writeBytes(multipartFile.getBytes(),absolutePath);
String fileDownPath = FilePathEnum.IMAGE.getFileDownPath(absolutePath);
ImageEntity imageEntity = new ImageEntity();
try {
ImageReq imageReq = imageRespBuilder(absolutePath, fileDownPath);
BeanUtil.copyProperties(imageReq, imageEntity);
list.add(imageReq);
imageEntity.setProjectId(projectId);
imageEntity.setCollectId(imageCollect.getCollectId());
imageList.add(imageEntity);
} catch (Exception e) {
e.printStackTrace();
}
}
imageCollectService.save(imageCollect);
baseMapper.insert(imageList);
return list;
}
@Override
@Transactional(rollbackFor = Exception.class)
public List<String> batchUploadCommonImage(String imageSource, ImageWorkReq imageWorkReq, MultipartFile[] files) throws IOException {
@ -213,9 +259,9 @@ public class ImageServiceImpl extends ServiceImpl<ImageMapper, ImageEntity> impl
List<ImageEntity> imageList = new ArrayList<>();
result.forEach(path -> {
ImageEntity imageEntity = new ImageEntity();
String absolutePath = FilePathEnum.IMAGE.getFileAbsolutePathPrefix() + StrUtil.removePrefix(path, FilePathEnum.IMAGE.getUrlPath());
String absolutePath = FilePathEnum.IMAGE.getFileAbsolutePath(path);
try {
ImageReq imageReq = imageRespBuilder(absolutePath);
ImageReq imageReq = imageRespBuilder(absolutePath, path);
BeanUtil.copyProperties(imageReq, imageEntity);
} catch (Exception e) {
log.debug("读取文件信息失败:{}", path);
@ -255,14 +301,14 @@ public class ImageServiceImpl extends ServiceImpl<ImageMapper, ImageEntity> impl
FileUtil.del(FilePathEnum.IMAGE.getFileAbsolutePath(image.getPreImagePath()));
}
private ImageReq imageRespBuilder(String path) throws Exception {
private ImageReq imageRespBuilder(String absolutePath, String downloadPath) throws Exception {
ImageReq req = new ImageReq();
File file = new File(path);
File file = new File(absolutePath);
JSONObject obj = EXIFUtil.printImageTags(file);
req.setCameraManufacturer(obj.getStr("Make"));
req.setCameraModel(obj.getStr("Model"));
req.setImageName(obj.getStr("File Name"));
req.setImagePath(FilePathEnum.IMAGE_TEMP.getFileDownPath(path));
req.setImagePath(downloadPath);
BigDecimal imageSize = new BigDecimal(extractDigit(obj.getStr("File Size"))).divide(new BigDecimal(1024*1024), 4, RoundingMode.HALF_UP);
req.setImageSize(imageSize.toString().concat("M"));
req.setImageWidth(extractDigit(obj.getStr("Image Width")));
@ -416,9 +462,9 @@ public class ImageServiceImpl extends ServiceImpl<ImageMapper, ImageEntity> impl
List<ImageEntity> newImageList = new ArrayList<>();
partReq.getImagePaths().forEach(path -> {
ImageEntity imageEntity = new ImageEntity();
String absolutePath = FilePathEnum.IMAGE.getFileAbsolutePathPrefix() + StrUtil.removePrefix(path, FilePathEnum.IMAGE.getUrlPath());
String absolutePath = FilePathEnum.IMAGE.getFileAbsolutePath(path);
try {
ImageReq imageReq = imageRespBuilder(absolutePath);
ImageReq imageReq = imageRespBuilder(absolutePath, path);
BeanUtil.copyProperties(imageReq, imageEntity);
} catch (Exception e) {
log.debug("读取文件信息失败:{}", path);

View File

@ -55,6 +55,12 @@ public class ImageController {
return Result.ok(imageService.batchUploadDefectImage(partId, imageSource, collectReq, files));
}
@ApiOperation(value = "手动批量上传文件夹图像到项目", httpMethod = "POST")
@PostMapping("/{projectId}/{imageSource}/upload-batch")
public Result<List<ImageReq>> uploadProjectBatch(@PathVariable String projectId, @PathVariable String imageSource, @RequestParam("files") MultipartFile[] files) {
return Result.ok(imageService.uploadProjectBatch(projectId, imageSource, files));
}
@ApiOperation(value = "上传图像", httpMethod = "POST")
@PostMapping("/{imageSource}/upload/{partId}")
public Result<ImageReq> uploadOutWork(@PathVariable String imageSource, @PathVariable String partId, ImageCollectReq collectReq, @RequestParam("file") MultipartFile file) {