Compare commits
2 Commits
d1603d5b14
...
695a32f5ce
Author | SHA1 | Date |
---|---|---|
|
695a32f5ce | |
|
c7bec730b4 |
|
@ -49,7 +49,9 @@ public class Schedule {
|
||||||
PartResp partResp = partRespMap.get(image.getPartId());
|
PartResp partResp = partRespMap.get(image.getPartId());
|
||||||
FilePathEnum pathEnum = image.getImagePath().contains("temp") ? FilePathEnum.IMAGE_TEMP : FilePathEnum.IMAGE;
|
FilePathEnum pathEnum = image.getImagePath().contains("temp") ? FilePathEnum.IMAGE_TEMP : FilePathEnum.IMAGE;
|
||||||
String inputFile = pathEnum.getFileAbsolutePath(image.getImagePath());
|
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.getTurbineName())
|
||||||
.concat(FileUtil.FILE_SEPARATOR).concat(partResp.getPartName());
|
.concat(FileUtil.FILE_SEPARATOR).concat(partResp.getPartName());
|
||||||
extUtilConfig.imagePreTreatment(inputFile, outputDir);
|
extUtilConfig.imagePreTreatment(inputFile, outputDir);
|
||||||
|
|
|
@ -25,6 +25,8 @@ public interface ImageService extends IService<ImageEntity> {
|
||||||
|
|
||||||
List<ImageReq> batchUploadDefectImage(String partId, String imageSource, ImageCollectReq collectReq, MultipartFile[] files);
|
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;
|
List<String> batchUploadCommonImage(String imageSource, ImageWorkReq imageWorkReq, MultipartFile[] file) throws IOException;
|
||||||
|
|
||||||
void delete(String imageId);
|
void delete(String imageId);
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package com.dite.znpt.service.impl;
|
package com.dite.znpt.service.impl;
|
||||||
|
|
||||||
|
import cn.dev33.satoken.stp.StpUtil;
|
||||||
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.hutool.core.collection.ListUtil;
|
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.enums.*;
|
||||||
import com.dite.znpt.exception.ServiceException;
|
import com.dite.znpt.exception.ServiceException;
|
||||||
import com.dite.znpt.mapper.ImageMapper;
|
import com.dite.znpt.mapper.ImageMapper;
|
||||||
import com.dite.znpt.service.AudioFileInfoService;
|
import com.dite.znpt.service.*;
|
||||||
import com.dite.znpt.service.ImageCollectService;
|
|
||||||
import com.dite.znpt.service.ImageService;
|
|
||||||
import com.dite.znpt.service.PartService;
|
|
||||||
import com.dite.znpt.util.EXIFUtil;
|
import com.dite.znpt.util.EXIFUtil;
|
||||||
import com.dite.znpt.util.PageUtil;
|
import com.dite.znpt.util.PageUtil;
|
||||||
|
import lombok.SneakyThrows;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
@ -65,6 +64,9 @@ public class ImageServiceImpl extends ServiceImpl<ImageMapper, ImageEntity> impl
|
||||||
private PartService partService;
|
private PartService partService;
|
||||||
@Autowired
|
@Autowired
|
||||||
private AudioFileInfoService audioFileInfoService;
|
private AudioFileInfoService audioFileInfoService;
|
||||||
|
private ProjectService projectService;
|
||||||
|
@Autowired
|
||||||
|
private UserService userService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<ImageListResp> list(ImageListReq req) {
|
public List<ImageListResp> list(ImageListReq req) {
|
||||||
|
@ -159,11 +161,11 @@ public class ImageServiceImpl extends ServiceImpl<ImageMapper, ImageEntity> impl
|
||||||
try {
|
try {
|
||||||
String path = temPathPrefix + file.getOriginalFilename();
|
String path = temPathPrefix + file.getOriginalFilename();
|
||||||
FileUtil.writeBytes(file.getBytes(),path);
|
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());
|
imageReq.setImageId(IdUtil.simpleUUID());
|
||||||
BeanUtil.copyProperties(imageReq, imageEntity);
|
BeanUtil.copyProperties(imageReq, imageEntity);
|
||||||
list.add(imageReq);
|
list.add(imageReq);
|
||||||
imageEntity.setImagePath(FilePathEnum.IMAGE_TEMP.getFileDownPath(path));
|
|
||||||
imageEntity.setPartId(partId);
|
imageEntity.setPartId(partId);
|
||||||
imageEntity.setProjectId(partResp.getProjectId());
|
imageEntity.setProjectId(partResp.getProjectId());
|
||||||
imageEntity.setCollectId(imageCollect.getCollectId());
|
imageEntity.setCollectId(imageCollect.getCollectId());
|
||||||
|
@ -180,6 +182,50 @@ public class ImageServiceImpl extends ServiceImpl<ImageMapper, ImageEntity> impl
|
||||||
return list;
|
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
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public List<String> batchUploadCommonImage(String imageSource, ImageWorkReq imageWorkReq, MultipartFile[] files) throws IOException {
|
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<>();
|
List<ImageEntity> imageList = new ArrayList<>();
|
||||||
result.forEach(path -> {
|
result.forEach(path -> {
|
||||||
ImageEntity imageEntity = new ImageEntity();
|
ImageEntity imageEntity = new ImageEntity();
|
||||||
String absolutePath = FilePathEnum.IMAGE.getFileAbsolutePathPrefix() + StrUtil.removePrefix(path, FilePathEnum.IMAGE.getUrlPath());
|
String absolutePath = FilePathEnum.IMAGE.getFileAbsolutePath(path);
|
||||||
try {
|
try {
|
||||||
ImageReq imageReq = imageRespBuilder(absolutePath);
|
ImageReq imageReq = imageRespBuilder(absolutePath, path);
|
||||||
BeanUtil.copyProperties(imageReq, imageEntity);
|
BeanUtil.copyProperties(imageReq, imageEntity);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.debug("读取文件信息失败:{}", path);
|
log.debug("读取文件信息失败:{}", path);
|
||||||
|
@ -255,14 +301,14 @@ public class ImageServiceImpl extends ServiceImpl<ImageMapper, ImageEntity> impl
|
||||||
FileUtil.del(FilePathEnum.IMAGE.getFileAbsolutePath(image.getPreImagePath()));
|
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();
|
ImageReq req = new ImageReq();
|
||||||
File file = new File(path);
|
File file = new File(absolutePath);
|
||||||
JSONObject obj = EXIFUtil.printImageTags(file);
|
JSONObject obj = EXIFUtil.printImageTags(file);
|
||||||
req.setCameraManufacturer(obj.getStr("Make"));
|
req.setCameraManufacturer(obj.getStr("Make"));
|
||||||
req.setCameraModel(obj.getStr("Model"));
|
req.setCameraModel(obj.getStr("Model"));
|
||||||
req.setImageName(obj.getStr("File Name"));
|
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);
|
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.setImageSize(imageSize.toString().concat("M"));
|
||||||
req.setImageWidth(extractDigit(obj.getStr("Image Width")));
|
req.setImageWidth(extractDigit(obj.getStr("Image Width")));
|
||||||
|
@ -416,9 +462,9 @@ public class ImageServiceImpl extends ServiceImpl<ImageMapper, ImageEntity> impl
|
||||||
List<ImageEntity> newImageList = new ArrayList<>();
|
List<ImageEntity> newImageList = new ArrayList<>();
|
||||||
partReq.getImagePaths().forEach(path -> {
|
partReq.getImagePaths().forEach(path -> {
|
||||||
ImageEntity imageEntity = new ImageEntity();
|
ImageEntity imageEntity = new ImageEntity();
|
||||||
String absolutePath = FilePathEnum.IMAGE.getFileAbsolutePathPrefix() + StrUtil.removePrefix(path, FilePathEnum.IMAGE.getUrlPath());
|
String absolutePath = FilePathEnum.IMAGE.getFileAbsolutePath(path);
|
||||||
try {
|
try {
|
||||||
ImageReq imageReq = imageRespBuilder(absolutePath);
|
ImageReq imageReq = imageRespBuilder(absolutePath, path);
|
||||||
BeanUtil.copyProperties(imageReq, imageEntity);
|
BeanUtil.copyProperties(imageReq, imageEntity);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.debug("读取文件信息失败:{}", path);
|
log.debug("读取文件信息失败:{}", path);
|
||||||
|
|
|
@ -55,6 +55,12 @@ public class ImageController {
|
||||||
return Result.ok(imageService.batchUploadDefectImage(partId, imageSource, collectReq, files));
|
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")
|
@ApiOperation(value = "上传图像", httpMethod = "POST")
|
||||||
@PostMapping("/{imageSource}/upload/{partId}")
|
@PostMapping("/{imageSource}/upload/{partId}")
|
||||||
public Result<ImageReq> uploadOutWork(@PathVariable String imageSource, @PathVariable String partId, ImageCollectReq collectReq, @RequestParam("file") MultipartFile file) {
|
public Result<ImageReq> uploadOutWork(@PathVariable String imageSource, @PathVariable String partId, ImageCollectReq collectReq, @RequestParam("file") MultipartFile file) {
|
||||||
|
|
Loading…
Reference in New Issue