文件保存路径修改为:仅在配置文件配置总路径,子路径在FilePathEnum处理及转换
This commit is contained in:
parent
4c7b7b4347
commit
fe75768d05
|
@ -1,11 +1,14 @@
|
||||||
package com.dite.znpt.config;
|
package com.dite.znpt.config;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.ListUtil;
|
||||||
import com.dite.znpt.constant.Constants;
|
import com.dite.znpt.constant.Constants;
|
||||||
|
import com.dite.znpt.enums.FilePathEnum;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -18,23 +21,14 @@ import java.util.List;
|
||||||
@Configuration
|
@Configuration
|
||||||
public class WebMvcConfig implements WebMvcConfigurer {
|
public class WebMvcConfig implements WebMvcConfigurer {
|
||||||
|
|
||||||
@Value(value = "${upload.temp-path.image}")
|
|
||||||
private String uploadTempPath;
|
|
||||||
|
|
||||||
@Value(value = "${upload.perm-path.image}")
|
|
||||||
private String uploadPermPath;
|
|
||||||
|
|
||||||
@Value(value = "${upload.perm-path.video}")
|
|
||||||
private String uploadPermVideoPath;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||||
registry.addResourceHandler("doc.html").addResourceLocations("classpath:/META-INF/resources/");
|
registry.addResourceHandler("doc.html").addResourceLocations("classpath:/META-INF/resources/");
|
||||||
registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
|
registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
|
||||||
registry.addResourceHandler("/swagger-ui/**").addResourceLocations("classpath:/META-INF/resources/webjars/springfox-swagger-ui/");
|
registry.addResourceHandler("/swagger-ui/**").addResourceLocations("classpath:/META-INF/resources/webjars/springfox-swagger-ui/");
|
||||||
registry.addResourceHandler(Constants.PERM_IMAGE_PATH + "**").addResourceLocations("file:" + uploadPermPath);
|
for (FilePathEnum pathEnum : FilePathEnum.values()) {
|
||||||
registry.addResourceHandler(Constants.PERM_VIDEO_PATH + "**").addResourceLocations("file:" + uploadPermVideoPath);
|
registry.addResourceHandler(pathEnum.getUrlPath() + "**").addResourceLocations("file:" + pathEnum.getFileAbsolutePath());
|
||||||
registry.addResourceHandler(Constants.TEMP_IMAGE_PATH + "**").addResourceLocations("file:" + uploadTempPath);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Override
|
// @Override
|
||||||
|
@ -51,7 +45,11 @@ public class WebMvcConfig implements WebMvcConfigurer {
|
||||||
// 动态获取哪些 path 可以忽略鉴权
|
// 动态获取哪些 path 可以忽略鉴权
|
||||||
public List<String> excludePaths() {
|
public List<String> excludePaths() {
|
||||||
// 此处仅为示例,实际项目你可以写任意代码来查询这些path
|
// 此处仅为示例,实际项目你可以写任意代码来查询这些path
|
||||||
return Arrays.asList("/auth/login", "/favicon.ico", "/favicon.ico", "/doc.html", "/swagger-ui/**", "/swagger-resources","/webjars/**", "/v3/api-docs/**", "/**/v3/api-docs", "/static/image/**","/static/image/temp/**");
|
ArrayList<String> list = ListUtil.toList("/auth/login", "/favicon.ico", "/favicon.ico", "/doc.html", "/swagger-ui/**", "/swagger-resources", "/webjars/**", "/v3/api-docs/**", "/**/v3/api-docs");
|
||||||
|
for (FilePathEnum pathEnum : FilePathEnum.values()) {
|
||||||
|
list.add(pathEnum.getUrlPath() + "**");
|
||||||
|
}
|
||||||
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,11 +86,4 @@ public class Constants {
|
||||||
* 1:代表隐藏
|
* 1:代表隐藏
|
||||||
*/
|
*/
|
||||||
public static final String VISIBLE_1 = "1";
|
public static final String VISIBLE_1 = "1";
|
||||||
|
|
||||||
// 持久化图片路径请求前缀
|
|
||||||
public static final String TEMP_IMAGE_PATH = "/static/image/temp/";
|
|
||||||
// 临时图片路径请求前缀
|
|
||||||
public static final String PERM_IMAGE_PATH = "/static/image/";
|
|
||||||
// 持久化视频文件路径请求前缀
|
|
||||||
public static final String PERM_VIDEO_PATH = "/static/video/";
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package com.dite.znpt.domain;
|
package com.dite.znpt.domain;
|
||||||
|
|
||||||
import com.alibaba.excel.annotation.ExcelIgnore;
|
import com.alibaba.excel.annotation.ExcelIgnore;
|
||||||
|
import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||||
import com.baomidou.mybatisplus.annotation.TableField;
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
@ -10,6 +11,7 @@ import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
import lombok.experimental.SuperBuilder;
|
import lombok.experimental.SuperBuilder;
|
||||||
|
|
||||||
|
import java.io.Serial;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -22,20 +24,21 @@ import java.util.List;
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@Data
|
@Data
|
||||||
public class AuditableEntity implements Serializable {
|
public class AuditableEntity implements Serializable {
|
||||||
|
@Serial
|
||||||
private static final long serialVersionUID = 141481953116476081L;
|
private static final long serialVersionUID = 141481953116476081L;
|
||||||
|
|
||||||
@ApiParam(hidden = true)
|
@ApiModelProperty(value = "创建人id", hidden = true)
|
||||||
private String createBy;
|
private String createBy;
|
||||||
|
|
||||||
@ApiParam(hidden = true)
|
@ApiModelProperty(value = "更新时间", hidden = true)
|
||||||
private String updateBy;
|
private String updateBy;
|
||||||
|
|
||||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
@ApiModelProperty(value = "创建时间", example = "2022-01-22", notes = "创建时间", hidden = true)
|
@ApiModelProperty(value = "创建时间", hidden = true)
|
||||||
private LocalDateTime createTime;
|
private LocalDateTime createTime;
|
||||||
|
|
||||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
@ApiModelProperty(hidden = true)
|
@ApiModelProperty(value = "修改人id", hidden = true)
|
||||||
private LocalDateTime updateTime;
|
private LocalDateTime updateTime;
|
||||||
|
|
||||||
@ExcelIgnore
|
@ExcelIgnore
|
||||||
|
|
|
@ -0,0 +1,47 @@
|
||||||
|
package com.dite.znpt.enums;
|
||||||
|
|
||||||
|
import cn.hutool.core.io.FileUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import cn.hutool.extra.spring.SpringUtil;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
import org.springframework.core.env.Environment;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@AllArgsConstructor
|
||||||
|
public enum FilePathEnum {
|
||||||
|
|
||||||
|
IMAGE("/static/image/", "/image/"),
|
||||||
|
IMAGE_TEMP("/static/image/temp/", "/image/temp/"),
|
||||||
|
VIDEO("/static/video/", "/video/"),
|
||||||
|
AUDIO("/static/audio/", "/audio/"),
|
||||||
|
;
|
||||||
|
|
||||||
|
private final String urlPath;
|
||||||
|
private final String fileRelativePath;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 功能描述:获取文件绝对路径
|
||||||
|
*
|
||||||
|
* @return {@link String }
|
||||||
|
* @author cuizhibin
|
||||||
|
* @date 2025/06/23 14:46
|
||||||
|
**/
|
||||||
|
public String getFileAbsolutePath() {
|
||||||
|
return SpringUtil.getBean(Environment.class).getProperty("upload.save-path") + fileRelativePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 功能描述:获取图像下载路径
|
||||||
|
*
|
||||||
|
* @param absolutePath
|
||||||
|
* @return {@link String }
|
||||||
|
* @author cuizhibin
|
||||||
|
* @date 2025/06/06 09:07
|
||||||
|
**/
|
||||||
|
public String getImageDownPath(String absolutePath) {
|
||||||
|
String relativePath = StrUtil.removePrefix(absolutePath, getFileAbsolutePath());
|
||||||
|
return StrUtil.replace(urlPath.concat(relativePath), FileUtil.FILE_SEPARATOR, StrUtil.SLASH);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -10,6 +10,7 @@ import com.dite.znpt.converts.Converts;
|
||||||
import com.dite.znpt.domain.entity.ImageCollectEntity;
|
import com.dite.znpt.domain.entity.ImageCollectEntity;
|
||||||
import com.dite.znpt.domain.entity.ImageEntity;
|
import com.dite.znpt.domain.entity.ImageEntity;
|
||||||
import com.dite.znpt.domain.vo.ImageCollectReq;
|
import com.dite.znpt.domain.vo.ImageCollectReq;
|
||||||
|
import com.dite.znpt.enums.FilePathEnum;
|
||||||
import com.dite.znpt.enums.ImageSourceEnum;
|
import com.dite.znpt.enums.ImageSourceEnum;
|
||||||
import com.dite.znpt.exception.ServiceException;
|
import com.dite.znpt.exception.ServiceException;
|
||||||
import com.dite.znpt.mapper.ImageCollectMapper;
|
import com.dite.znpt.mapper.ImageCollectMapper;
|
||||||
|
@ -34,11 +35,6 @@ import java.util.List;
|
||||||
@Service
|
@Service
|
||||||
public class ImageCollectServiceImpl extends ServiceImpl<ImageCollectMapper, ImageCollectEntity> implements ImageCollectService {
|
public class ImageCollectServiceImpl extends ServiceImpl<ImageCollectMapper, ImageCollectEntity> implements ImageCollectService {
|
||||||
|
|
||||||
@Value("${upload.perm-path.image}")
|
|
||||||
private String permPath;
|
|
||||||
@Value("${upload.temp-path.image}")
|
|
||||||
private String tempPath;
|
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private ImageService imageService;
|
private ImageService imageService;
|
||||||
|
|
||||||
|
@ -58,8 +54,8 @@ public class ImageCollectServiceImpl extends ServiceImpl<ImageCollectMapper, Ima
|
||||||
this.save(imageCollect);
|
this.save(imageCollect);
|
||||||
String dateStr = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
String dateStr = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
||||||
List<ImageEntity> imageList = Converts.INSTANCE.toImageEntity(req.getImageList());
|
List<ImageEntity> imageList = Converts.INSTANCE.toImageEntity(req.getImageList());
|
||||||
String permPathPrefix = permPath.concat(ImageSourceEnum.COLLECT.getCode()).concat(FileUtil.FILE_SEPARATOR).concat(partId).concat(FileUtil.FILE_SEPARATOR).concat(dateStr).concat(FileUtil.FILE_SEPARATOR);
|
String permPathPrefix = FilePathEnum.IMAGE.getFileAbsolutePath().concat(ImageSourceEnum.COLLECT.getCode()).concat(FileUtil.FILE_SEPARATOR).concat(partId).concat(FileUtil.FILE_SEPARATOR).concat(dateStr).concat(FileUtil.FILE_SEPARATOR);
|
||||||
String temPathPrefix = tempPath.concat(ImageSourceEnum.COLLECT.getCode()).concat(FileUtil.FILE_SEPARATOR).concat(partId).concat(FileUtil.FILE_SEPARATOR);
|
String temPathPrefix = FilePathEnum.IMAGE_TEMP.getFileAbsolutePath().concat(ImageSourceEnum.COLLECT.getCode()).concat(FileUtil.FILE_SEPARATOR).concat(partId).concat(FileUtil.FILE_SEPARATOR);
|
||||||
imageList.forEach(image -> {
|
imageList.forEach(image -> {
|
||||||
image.setPartId(partId);
|
image.setPartId(partId);
|
||||||
image.setCollectId(imageCollect.getCollectId());
|
image.setCollectId(imageCollect.getCollectId());
|
||||||
|
@ -68,7 +64,7 @@ public class ImageCollectServiceImpl extends ServiceImpl<ImageCollectMapper, Ima
|
||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
byte[] bytes = FileUtil.readBytes(file);
|
byte[] bytes = FileUtil.readBytes(file);
|
||||||
FileUtil.writeBytes(bytes, path);
|
FileUtil.writeBytes(bytes, path);
|
||||||
String url = Constants.PERM_IMAGE_PATH.concat(StrUtil.removePrefix(path,permPath).replace(FileUtil.FILE_SEPARATOR, StrUtil.SLASH));
|
String url = FilePathEnum.IMAGE.getUrlPath().concat(StrUtil.removePrefix(path,FilePathEnum.IMAGE.getFileAbsolutePath()).replace(FileUtil.FILE_SEPARATOR, StrUtil.SLASH));
|
||||||
image.setImagePath(url);
|
image.setImagePath(url);
|
||||||
FileUtil.del(file);
|
FileUtil.del(file);
|
||||||
}else {
|
}else {
|
||||||
|
|
|
@ -19,10 +19,7 @@ import com.dite.znpt.domain.entity.ImageEntity;
|
||||||
import com.dite.znpt.domain.entity.PartEntity;
|
import com.dite.znpt.domain.entity.PartEntity;
|
||||||
import com.dite.znpt.domain.page.PageDomain;
|
import com.dite.znpt.domain.page.PageDomain;
|
||||||
import com.dite.znpt.domain.vo.*;
|
import com.dite.znpt.domain.vo.*;
|
||||||
import com.dite.znpt.enums.ImageSourceEnum;
|
import com.dite.znpt.enums.*;
|
||||||
import com.dite.znpt.enums.ImageTypeEnum;
|
|
||||||
import com.dite.znpt.enums.ShootingMethodEnum;
|
|
||||||
import com.dite.znpt.enums.WeatherEnum;
|
|
||||||
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.ImageCollectService;
|
import com.dite.znpt.service.ImageCollectService;
|
||||||
|
@ -71,11 +68,6 @@ public class ImageServiceImpl extends ServiceImpl<ImageMapper, ImageEntity> impl
|
||||||
@Resource
|
@Resource
|
||||||
private PartService partService;
|
private PartService partService;
|
||||||
|
|
||||||
@Value("${upload.temp-path.image}")
|
|
||||||
private String tempPath;
|
|
||||||
|
|
||||||
@Value("${upload.perm-path.image}")
|
|
||||||
private String permPath;
|
|
||||||
@Override
|
@Override
|
||||||
public List<ImageListResp> list(ImageListReq req) {
|
public List<ImageListResp> list(ImageListReq req) {
|
||||||
List<ImageListResp> partList= this.baseMapper.queryImageList(req);
|
List<ImageListResp> partList= this.baseMapper.queryImageList(req);
|
||||||
|
@ -100,8 +92,8 @@ public class ImageServiceImpl extends ServiceImpl<ImageMapper, ImageEntity> impl
|
||||||
Map<String, PartEntity> partIdMap= partService.listByIds(partIds).stream().collect(Collectors.toMap(PartEntity::getPartId, Function.identity()));
|
Map<String, PartEntity> partIdMap= partService.listByIds(partIds).stream().collect(Collectors.toMap(PartEntity::getPartId, Function.identity()));
|
||||||
list.forEach(req -> {
|
list.forEach(req -> {
|
||||||
if(partIdMap.containsKey(req.getPartId())){
|
if(partIdMap.containsKey(req.getPartId())){
|
||||||
String path_prefix = permPath.concat(StrUtil.BACKSLASH).concat(req.getImageSource()).concat(StrUtil.BACKSLASH).concat(req.getPartId()).concat(StrUtil.BACKSLASH);
|
String path_prefix = FilePathEnum.IMAGE.getFileAbsolutePath().concat(StrUtil.BACKSLASH).concat(req.getImageSource()).concat(StrUtil.BACKSLASH).concat(req.getPartId()).concat(StrUtil.BACKSLASH);
|
||||||
String temp_path_prefix = tempPath.concat(StrUtil.BACKSLASH).concat(req.getImageSource()).concat(StrUtil.BACKSLASH).concat(req.getPartId()).concat(StrUtil.BACKSLASH);
|
String temp_path_prefix = FilePathEnum.IMAGE_TEMP.getFileAbsolutePath().concat(StrUtil.BACKSLASH).concat(req.getImageSource()).concat(StrUtil.BACKSLASH).concat(req.getPartId()).concat(StrUtil.BACKSLASH);
|
||||||
File file = new File(req.getImagePath());
|
File file = new File(req.getImagePath());
|
||||||
if(file.exists() && req.getImagePath().contains(temp_path_prefix)){
|
if(file.exists() && req.getImagePath().contains(temp_path_prefix)){
|
||||||
ImageEntity entity = new ImageEntity();
|
ImageEntity entity = new ImageEntity();
|
||||||
|
@ -140,12 +132,12 @@ public class ImageServiceImpl extends ServiceImpl<ImageMapper, ImageEntity> impl
|
||||||
throw new ServiceException(Message.IMAGE_IS_EMPTY);
|
throw new ServiceException(Message.IMAGE_IS_EMPTY);
|
||||||
}
|
}
|
||||||
List<ImageReq> list = new ArrayList<>(files.length);
|
List<ImageReq> list = new ArrayList<>(files.length);
|
||||||
File temCategory = new File(tempPath);
|
File temCategory = new File(FilePathEnum.IMAGE_TEMP.getFileAbsolutePath());
|
||||||
if (!temCategory.exists()) {
|
if (!temCategory.exists()) {
|
||||||
// 创建完整的目录
|
// 创建完整的目录
|
||||||
temCategory.mkdirs();
|
temCategory.mkdirs();
|
||||||
}
|
}
|
||||||
String temPathPrefix = tempPath.concat(imageSource).concat(FileUtil.FILE_SEPARATOR).concat(partId).concat(FileUtil.FILE_SEPARATOR);
|
String temPathPrefix = FilePathEnum.IMAGE_TEMP.getFileAbsolutePath().concat(imageSource).concat(FileUtil.FILE_SEPARATOR).concat(partId).concat(FileUtil.FILE_SEPARATOR);
|
||||||
for (MultipartFile file : files) {
|
for (MultipartFile file : files) {
|
||||||
if (!file.isEmpty()) {
|
if (!file.isEmpty()) {
|
||||||
try {
|
try {
|
||||||
|
@ -167,7 +159,7 @@ public class ImageServiceImpl extends ServiceImpl<ImageMapper, ImageEntity> impl
|
||||||
throw new ServiceException(Message.IMAGE_IS_EMPTY);
|
throw new ServiceException(Message.IMAGE_IS_EMPTY);
|
||||||
}
|
}
|
||||||
String dateStr = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
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);
|
String path_prefix = FilePathEnum.IMAGE.getFileAbsolutePath().concat(imageSource).concat(FileUtil.FILE_SEPARATOR).concat(dateStr).concat(FileUtil.FILE_SEPARATOR);
|
||||||
if (Objects.nonNull(imageWorkReq)) {
|
if (Objects.nonNull(imageWorkReq)) {
|
||||||
path_prefix = path_prefix.concat(StrUtil.emptyToDefault(imageWorkReq.getUploadUser(), "默认用户")).concat(FileUtil.FILE_SEPARATOR)
|
path_prefix = path_prefix.concat(StrUtil.emptyToDefault(imageWorkReq.getUploadUser(), "默认用户")).concat(FileUtil.FILE_SEPARATOR)
|
||||||
.concat(StrUtil.emptyToDefault(imageWorkReq.getLongitude(), "0"))
|
.concat(StrUtil.emptyToDefault(imageWorkReq.getLongitude(), "0"))
|
||||||
|
@ -182,7 +174,7 @@ public class ImageServiceImpl extends ServiceImpl<ImageMapper, ImageEntity> impl
|
||||||
for (MultipartFile multipartFile : files) {
|
for (MultipartFile multipartFile : files) {
|
||||||
String path = path_prefix + multipartFile.getOriginalFilename();
|
String path = path_prefix + multipartFile.getOriginalFilename();
|
||||||
FileUtil.writeBytes(multipartFile.getBytes(),path);
|
FileUtil.writeBytes(multipartFile.getBytes(),path);
|
||||||
result.add(getImageDownPath(StrUtil.removePrefix(path, permPath)));
|
result.add(FilePathEnum.IMAGE.getImageDownPath(path));
|
||||||
}
|
}
|
||||||
String partId = imageWorkReq.getPartId();
|
String partId = imageWorkReq.getPartId();
|
||||||
if (Objects.nonNull(partId)) {
|
if (Objects.nonNull(partId)) {
|
||||||
|
@ -196,7 +188,7 @@ 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 = permPath + StrUtil.removePrefix(path, Constants.PERM_IMAGE_PATH);
|
String absolutePath = FilePathEnum.IMAGE.getFileAbsolutePath() + StrUtil.removePrefix(path, FilePathEnum.IMAGE.getUrlPath());
|
||||||
try {
|
try {
|
||||||
ImageReq imageReq = imageRespBuilder(absolutePath);
|
ImageReq imageReq = imageRespBuilder(absolutePath);
|
||||||
BeanUtil.copyProperties(imageReq, imageEntity);
|
BeanUtil.copyProperties(imageReq, imageEntity);
|
||||||
|
@ -245,7 +237,7 @@ public class ImageServiceImpl extends ServiceImpl<ImageMapper, ImageEntity> impl
|
||||||
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(getTmpImageDownPath(StrUtil.removePrefix(path, tempPath)));
|
req.setImagePath(FilePathEnum.IMAGE_TEMP.getImageDownPath(path));
|
||||||
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")));
|
||||||
|
@ -299,41 +291,14 @@ public class ImageServiceImpl extends ServiceImpl<ImageMapper, ImageEntity> impl
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 功能描述:获取图像下载路径
|
|
||||||
*
|
|
||||||
* @param relativePath
|
|
||||||
* @return {@link String }
|
|
||||||
* @author cuizhibin
|
|
||||||
* @date 2025/06/06 09:07
|
|
||||||
**/
|
|
||||||
public static String getImageDownPath(String relativePath) {
|
|
||||||
String url = Constants.PERM_IMAGE_PATH.concat(relativePath);
|
|
||||||
return StrUtil.replace(url, FileUtil.FILE_SEPARATOR, StrUtil.SLASH);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 功能描述:获取tmp图像下载路径
|
|
||||||
*
|
|
||||||
* @param relativePath
|
|
||||||
* @return {@link String }
|
|
||||||
* @author cuizhibin
|
|
||||||
* @date 2025/06/06 09:07
|
|
||||||
**/
|
|
||||||
public static String getTmpImageDownPath(String relativePath) {
|
|
||||||
String url = Constants.TEMP_IMAGE_PATH.concat(StrUtil.SLASH).concat(relativePath);
|
|
||||||
return StrUtil.replace(url, FileUtil.FILE_SEPARATOR, StrUtil.SLASH);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<AppImageResp> listAppUploadImages() {
|
public List<AppImageResp> listAppUploadImages() {
|
||||||
List<String> filePaths = new ArrayList<>();
|
List<String> filePaths = new ArrayList<>();
|
||||||
PathUtil.walkFiles(Path.of(permPath), new SimpleFileVisitor<>() {
|
PathUtil.walkFiles(Path.of(FilePathEnum.IMAGE.getFileAbsolutePath()), new SimpleFileVisitor<>() {
|
||||||
@Override
|
@Override
|
||||||
public FileVisitResult visitFile(Path path, BasicFileAttributes attrs) {
|
public FileVisitResult visitFile(Path path, BasicFileAttributes attrs) {
|
||||||
if (path.toFile().isFile()) {
|
if (path.toFile().isFile()) {
|
||||||
String relativePath = StrUtil.removePrefix(path.toFile().getAbsolutePath(), permPath);
|
String imageDownPath = FilePathEnum.IMAGE.getImageDownPath(path.toFile().getAbsolutePath());
|
||||||
String imageDownPath = getImageDownPath(relativePath);
|
|
||||||
List<String> split = StrUtil.split(imageDownPath, StrUtil.SLASH, true, true);
|
List<String> split = StrUtil.split(imageDownPath, StrUtil.SLASH, true, true);
|
||||||
// /static/image/source/date
|
// /static/image/source/date
|
||||||
try {
|
try {
|
||||||
|
@ -426,7 +391,7 @@ 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 = permPath + StrUtil.removePrefix(path, Constants.PERM_IMAGE_PATH);
|
String absolutePath = FilePathEnum.IMAGE.getFileAbsolutePath() + StrUtil.removePrefix(path, FilePathEnum.IMAGE.getUrlPath());
|
||||||
try {
|
try {
|
||||||
ImageReq imageReq = imageRespBuilder(absolutePath);
|
ImageReq imageReq = imageRespBuilder(absolutePath);
|
||||||
BeanUtil.copyProperties(imageReq, imageEntity);
|
BeanUtil.copyProperties(imageReq, imageEntity);
|
||||||
|
|
|
@ -10,6 +10,7 @@ import com.dite.znpt.domain.entity.VideoFileInfoEntity;
|
||||||
import com.dite.znpt.domain.vo.VideoFileInfoListReq;
|
import com.dite.znpt.domain.vo.VideoFileInfoListReq;
|
||||||
import com.dite.znpt.domain.vo.VideoFileInfoReq;
|
import com.dite.znpt.domain.vo.VideoFileInfoReq;
|
||||||
import com.dite.znpt.domain.vo.VideoFileInfoResp;
|
import com.dite.znpt.domain.vo.VideoFileInfoResp;
|
||||||
|
import com.dite.znpt.enums.FilePathEnum;
|
||||||
import com.dite.znpt.exception.ServiceException;
|
import com.dite.znpt.exception.ServiceException;
|
||||||
import com.dite.znpt.service.PartService;
|
import com.dite.znpt.service.PartService;
|
||||||
import com.dite.znpt.service.VideoFileInfoService;
|
import com.dite.znpt.service.VideoFileInfoService;
|
||||||
|
@ -39,8 +40,6 @@ import java.util.stream.Collectors;
|
||||||
public class VideoFileInfoServiceImpl extends ServiceImpl<VideoFileInfoMapper, VideoFileInfoEntity> implements VideoFileInfoService {
|
public class VideoFileInfoServiceImpl extends ServiceImpl<VideoFileInfoMapper, VideoFileInfoEntity> implements VideoFileInfoService {
|
||||||
|
|
||||||
private final PartService partService;
|
private final PartService partService;
|
||||||
@Value(value = "${upload.perm-path.video}")
|
|
||||||
private String uploadPermVideoPath;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 功能描述:查询视频文件信息列表
|
* 功能描述:查询视频文件信息列表
|
||||||
|
@ -121,7 +120,7 @@ public class VideoFileInfoServiceImpl extends ServiceImpl<VideoFileInfoMapper, V
|
||||||
throw new ServiceException(Message.IMAGE_IS_EMPTY);
|
throw new ServiceException(Message.IMAGE_IS_EMPTY);
|
||||||
}
|
}
|
||||||
String dateStr = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
String dateStr = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
||||||
String path_prefix = uploadPermVideoPath.concat(dateStr).concat(FileUtil.FILE_SEPARATOR);
|
String path_prefix = FilePathEnum.VIDEO.getFileAbsolutePath().concat(dateStr).concat(FileUtil.FILE_SEPARATOR);
|
||||||
if (!FileUtil.exist(path_prefix)) {
|
if (!FileUtil.exist(path_prefix)) {
|
||||||
FileUtil.mkdir(path_prefix);
|
FileUtil.mkdir(path_prefix);
|
||||||
}
|
}
|
||||||
|
@ -130,7 +129,7 @@ public class VideoFileInfoServiceImpl extends ServiceImpl<VideoFileInfoMapper, V
|
||||||
VideoFileInfoEntity info = BeanUtil.copyProperties(infoReq, VideoFileInfoEntity.class);
|
VideoFileInfoEntity info = BeanUtil.copyProperties(infoReq, VideoFileInfoEntity.class);
|
||||||
String path = path_prefix + multipartFile.getOriginalFilename();
|
String path = path_prefix + multipartFile.getOriginalFilename();
|
||||||
FileUtil.writeBytes(multipartFile.getBytes(), path);
|
FileUtil.writeBytes(multipartFile.getBytes(), path);
|
||||||
info.setFilePath(Constants.PERM_VIDEO_PATH + StrUtil.removePrefix(path, uploadPermVideoPath).replace(FileUtil.FILE_SEPARATOR, StrUtil.SLASH));
|
info.setFilePath(FilePathEnum.VIDEO.getUrlPath() + StrUtil.removePrefix(path, FilePathEnum.VIDEO.getFileAbsolutePath()).replace(FileUtil.FILE_SEPARATOR, StrUtil.SLASH));
|
||||||
result.add(info);
|
result.add(info);
|
||||||
}
|
}
|
||||||
baseMapper.insert(result);
|
baseMapper.insert(result);
|
||||||
|
|
|
@ -134,9 +134,6 @@ zlm-config:
|
||||||
dynamicPortEnd: 30185
|
dynamicPortEnd: 30185
|
||||||
|
|
||||||
upload:
|
upload:
|
||||||
temp-path:
|
# 此处仅定义总的父路径,细节定义到 FilePathEnum
|
||||||
image: D:\Upload\Image\Temp\
|
save-path: D:\Upload\
|
||||||
perm-path:
|
|
||||||
image: D:\Upload\Image\
|
|
||||||
video: D:\Upload\Video\
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue