|
|
|
@ -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);
|
|
|
|
|