调整代码结构,完善了文件v2相关操作
This commit is contained in:
parent
0e5855cbfa
commit
91e8ca193d
@ -0,0 +1,246 @@
|
||||
package ink.wgink.module.file.components;
|
||||
|
||||
import ink.wgink.exceptions.FileException;
|
||||
import ink.wgink.exceptions.SearchException;
|
||||
import ink.wgink.exceptions.base.SystemException;
|
||||
import ink.wgink.module.file.enums.UploadTypeEnum;
|
||||
import ink.wgink.module.file.service.IFileService;
|
||||
import ink.wgink.properties.FileProperties;
|
||||
import ink.wgink.util.date.DateUtil;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
/**
|
||||
* @ClassName: FileUtil
|
||||
* @Description: 文件工具
|
||||
* @Author: wanggeng
|
||||
* @Date: 2022/7/25 17:00
|
||||
* @Version: 1.0
|
||||
*/
|
||||
@Component
|
||||
public class FileComponent {
|
||||
|
||||
protected static final Logger LOG = LoggerFactory.getLogger(FileComponent.class);
|
||||
private static final char[] HEX_CODE = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
|
||||
private String[] imageTypes;
|
||||
private String[] videoTypes;
|
||||
private String[] audioTypes;
|
||||
private String[] fileTypes;
|
||||
@Autowired
|
||||
private FileProperties fileProperties;
|
||||
|
||||
/**
|
||||
* 保存文件
|
||||
*
|
||||
* @param fileInputStream
|
||||
* @param fileName
|
||||
* @param filePath
|
||||
* @return
|
||||
*/
|
||||
public long saveFile(InputStream fileInputStream, String fileName, String filePath) {
|
||||
File uploadFolder = new File(filePath);
|
||||
if (!uploadFolder.exists()) {
|
||||
uploadFolder.mkdirs();
|
||||
}
|
||||
FileOutputStream uploadFileOutputStream = null;
|
||||
long fileSize = 0;
|
||||
try {
|
||||
uploadFileOutputStream = new FileOutputStream(uploadFolder + File.separator + fileName);
|
||||
int readLength;
|
||||
for (byte[] buf = new byte[IFileService.INPUT_STREAM_SIZE]; (readLength = fileInputStream.read(buf)) > -1; ) {
|
||||
uploadFileOutputStream.write(buf, 0, readLength);
|
||||
fileSize += readLength;
|
||||
}
|
||||
uploadFileOutputStream.flush();
|
||||
} catch (Exception e) {
|
||||
LOG.error(e.getMessage(), e);
|
||||
throw new FileException("文件上传失败");
|
||||
} finally {
|
||||
try {
|
||||
if (null != uploadFileOutputStream) {
|
||||
uploadFileOutputStream.close();
|
||||
}
|
||||
if (null != fileInputStream) {
|
||||
fileInputStream.close();
|
||||
}
|
||||
} catch (Exception e1) {
|
||||
LOG.error(e1.getMessage());
|
||||
throw new FileException("文件上传失败");
|
||||
}
|
||||
}
|
||||
return fileSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除源文件
|
||||
*
|
||||
* @param sourceFilePath
|
||||
*/
|
||||
public static void deleteSourceFile(String sourceFilePath) {
|
||||
File file = new File(sourceFilePath);
|
||||
if (file.exists()) {
|
||||
boolean isDelete = file.delete();
|
||||
if (isDelete) {
|
||||
LOG.debug("文件删除成功");
|
||||
} else {
|
||||
LOG.debug("文件删除失败");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件的MD5
|
||||
*
|
||||
* @param file
|
||||
* @return
|
||||
*/
|
||||
public String getFileMD5(File file) {
|
||||
if (file == null) {
|
||||
throw new SearchException("文件不存在");
|
||||
}
|
||||
if (!file.exists()) {
|
||||
throw new SearchException("文件不存在");
|
||||
}
|
||||
String fileMd5;
|
||||
try (InputStream inputStream = Files.newInputStream(file.toPath())) {
|
||||
MessageDigest messageDigest = MessageDigest.getInstance("MD5");
|
||||
int readLength;
|
||||
for (byte[] buf = new byte[IFileService.INPUT_STREAM_SIZE]; (readLength = inputStream.read(buf)) > -1; ) {
|
||||
messageDigest.update(buf, 0, readLength);
|
||||
}
|
||||
// 计算文件的MD5
|
||||
byte[] data = messageDigest.digest();
|
||||
StringBuilder fileMd5SB = new StringBuilder(data.length * 2);
|
||||
for (byte b : data) {
|
||||
fileMd5SB.append(HEX_CODE[(b >> 4) & 0xF]);
|
||||
fileMd5SB.append(HEX_CODE[(b & 0xF)]);
|
||||
}
|
||||
fileMd5 = fileMd5SB.toString();
|
||||
} catch (IOException | NoSuchAlgorithmException e) {
|
||||
throw new SystemException(e);
|
||||
}
|
||||
return fileMd5;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取上传绝对文件
|
||||
*
|
||||
* @param uploadTypeEnum
|
||||
* @param fileType
|
||||
* @return
|
||||
* @throws FileException
|
||||
*/
|
||||
public String getUploadPath(UploadTypeEnum uploadTypeEnum, String fileType) throws FileException {
|
||||
String baseUploadPath = fileProperties.getUploadPath();
|
||||
if (StringUtils.isBlank(baseUploadPath)) {
|
||||
throw new SystemException("上传路径未配置");
|
||||
}
|
||||
StringBuilder filePath = new StringBuilder();
|
||||
if (!baseUploadPath.endsWith(File.separator)) {
|
||||
filePath.append(baseUploadPath).append(File.separator);
|
||||
} else {
|
||||
filePath.append(baseUploadPath);
|
||||
}
|
||||
boolean hasFileType = !StringUtils.isBlank(fileType);
|
||||
if (uploadTypeEnum.getValue() == UploadTypeEnum.IMAGE.getValue()) {
|
||||
if (hasFileType && !isTypeCorrect(getImageTypes(), fileType)) {
|
||||
throw new FileException("图片格式不支持上传");
|
||||
}
|
||||
filePath.append("images");
|
||||
} else if (uploadTypeEnum.getValue() == UploadTypeEnum.VIDEO.getValue()) {
|
||||
if (hasFileType && !isTypeCorrect(getVideoTypes(), fileType)) {
|
||||
throw new FileException("视频格式不支持上传");
|
||||
}
|
||||
filePath.append("videos");
|
||||
} else if (uploadTypeEnum.getValue() == UploadTypeEnum.AUDIO.getValue()) {
|
||||
if (hasFileType && !isTypeCorrect(getAudioTypes(), fileType)) {
|
||||
throw new FileException("音频格式不支持上传");
|
||||
}
|
||||
filePath.append("audios");
|
||||
} else if (uploadTypeEnum.getValue() == UploadTypeEnum.ERROR_EXCEL.getValue()) {
|
||||
filePath.append("errorexcels");
|
||||
} else {
|
||||
if (hasFileType && !isTypeCorrect(getFileTypes(), fileType)) {
|
||||
throw new FileException("文件格式不支持上传");
|
||||
}
|
||||
filePath.append("files");
|
||||
}
|
||||
filePath.append(File.separator).append(DateUtil.getDays());
|
||||
return filePath.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件url
|
||||
*
|
||||
* @param uploadPath
|
||||
* @return
|
||||
*/
|
||||
public String getFileUrl(String uploadPath) {
|
||||
String fileUrl = uploadPath.replace(fileProperties.getUploadPath(), "");
|
||||
if ("\\".equals(File.separator)) {
|
||||
fileUrl = fileUrl.replace("\\", "/");
|
||||
}
|
||||
if (fileUrl.startsWith("/")) {
|
||||
fileUrl = fileUrl.substring(1, fileUrl.length() - 1);
|
||||
}
|
||||
return fileUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件类型
|
||||
*
|
||||
* @param fileName
|
||||
* @return
|
||||
*/
|
||||
public String getFileType(String fileName) {
|
||||
String[] names = fileName.split("\\.");
|
||||
if (names != null) {
|
||||
return names[names.length - 1].toLowerCase();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验类型
|
||||
*
|
||||
* @param types
|
||||
* @param fileType
|
||||
* @return
|
||||
*/
|
||||
public boolean isTypeCorrect(String[] types, String fileType) {
|
||||
for (String type : types) {
|
||||
if (StringUtils.equalsIgnoreCase(fileType, type)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public String[] getImageTypes() {
|
||||
return imageTypes == null ? fileProperties.getImageTypes().split(",") : imageTypes;
|
||||
}
|
||||
|
||||
public String[] getVideoTypes() {
|
||||
return videoTypes == null ? fileProperties.getVideoTypes().split(",") : videoTypes;
|
||||
}
|
||||
|
||||
public String[] getAudioTypes() {
|
||||
return audioTypes == null ? fileProperties.getAudioTypes().split(",") : audioTypes;
|
||||
}
|
||||
|
||||
public String[] getFileTypes() {
|
||||
return fileTypes == null ? fileProperties.getFileTypes().split(",") : fileTypes;
|
||||
}
|
||||
|
||||
}
|
@ -1,10 +1,10 @@
|
||||
package ink.wgink.module.file.controller.api;
|
||||
package ink.wgink.module.file.controller.api.v2;
|
||||
|
||||
import ink.wgink.common.base.DefaultBaseController;
|
||||
import ink.wgink.interfaces.consts.ISystemConstant;
|
||||
import ink.wgink.module.file.enums.UploadTypeEnum;
|
||||
import ink.wgink.module.file.pojo.dtos.FileUploadSuccessDTO;
|
||||
import ink.wgink.module.file.service.v2.IFileV2Service;
|
||||
import ink.wgink.module.file.pojo.dtos.v2.FileUploadSuccessDTO;
|
||||
import ink.wgink.module.file.service.v2.IFileService;
|
||||
import ink.wgink.pojo.result.ErrorResult;
|
||||
import ink.wgink.pojo.result.SuccessResultData;
|
||||
import io.swagger.annotations.*;
|
||||
@ -15,8 +15,6 @@ import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @ClassName: FileController
|
||||
* @Description: 文件处理
|
||||
@ -25,12 +23,12 @@ import java.util.Map;
|
||||
* @Version: 1.0
|
||||
**/
|
||||
@Api(tags = ISystemConstant.API_TAGS_SYSTEM_PREFIX + "文件接口")
|
||||
@RestController
|
||||
@RestController("fileControllerV2")
|
||||
@RequestMapping(ISystemConstant.API_PREFIX + "/file/v2")
|
||||
public class FileV2Controller extends DefaultBaseController {
|
||||
public class FileController extends DefaultBaseController {
|
||||
|
||||
@Autowired
|
||||
private IFileV2Service fileV2Service;
|
||||
private IFileService fileService;
|
||||
|
||||
@ApiOperation(value = "上传文件", notes = "上传文件接口")
|
||||
@ApiImplicitParams({
|
||||
@ -39,8 +37,7 @@ public class FileV2Controller extends DefaultBaseController {
|
||||
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
|
||||
@PostMapping("upload-file")
|
||||
public SuccessResultData<FileUploadSuccessDTO> uploadFile(@RequestParam("file") MultipartFile file) {
|
||||
Map<String, Object> params = requestParams();
|
||||
return uploadSingle(file, UploadTypeEnum.FILE, params);
|
||||
return uploadSingle(file, UploadTypeEnum.FILE);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "上传图片", notes = "上传图片接口")
|
||||
@ -50,8 +47,7 @@ public class FileV2Controller extends DefaultBaseController {
|
||||
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
|
||||
@PostMapping("upload-image")
|
||||
public SuccessResultData<FileUploadSuccessDTO> uploadImage(@RequestParam("image") MultipartFile image) {
|
||||
Map<String, Object> params = requestParams();
|
||||
return uploadSingle(image, UploadTypeEnum.IMAGE, params);
|
||||
return uploadSingle(image, UploadTypeEnum.IMAGE);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "上传视频", notes = "上传视频接口")
|
||||
@ -61,8 +57,7 @@ public class FileV2Controller extends DefaultBaseController {
|
||||
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
|
||||
@PostMapping("upload-video")
|
||||
public SuccessResultData<FileUploadSuccessDTO> uploadVideo(@RequestParam("video") MultipartFile video) {
|
||||
Map<String, Object> params = requestParams();
|
||||
return uploadSingle(video, UploadTypeEnum.VIDEO, params);
|
||||
return uploadSingle(video, UploadTypeEnum.VIDEO);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "上传音频", notes = "上传音频接口")
|
||||
@ -72,8 +67,7 @@ public class FileV2Controller extends DefaultBaseController {
|
||||
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
|
||||
@PostMapping("upload-audio")
|
||||
public SuccessResultData<FileUploadSuccessDTO> uploadAudio(@RequestParam("audio") MultipartFile audio) {
|
||||
Map<String, Object> params = requestParams();
|
||||
return uploadSingle(audio, UploadTypeEnum.AUDIO, params);
|
||||
return uploadSingle(audio, UploadTypeEnum.AUDIO);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -83,8 +77,8 @@ public class FileV2Controller extends DefaultBaseController {
|
||||
* @param params
|
||||
* @return
|
||||
*/
|
||||
private SuccessResultData<FileUploadSuccessDTO> uploadSingle(MultipartFile uploadFile, UploadTypeEnum uploadTypeEnum, Map<String, Object> params) {
|
||||
return new SuccessResultData<>(fileV2Service.uploadSingle(uploadFile, uploadTypeEnum, params));
|
||||
private SuccessResultData<FileUploadSuccessDTO> uploadSingle(MultipartFile uploadFile, UploadTypeEnum uploadTypeEnum) {
|
||||
return new SuccessResultData<>(fileService.uploadSingle(uploadFile, uploadTypeEnum));
|
||||
}
|
||||
|
||||
}
|
@ -1,10 +1,10 @@
|
||||
package ink.wgink.module.file.controller.app.api;
|
||||
package ink.wgink.module.file.controller.app.api.v2;
|
||||
|
||||
import ink.wgink.common.base.DefaultBaseController;
|
||||
import ink.wgink.interfaces.consts.ISystemConstant;
|
||||
import ink.wgink.module.file.enums.UploadTypeEnum;
|
||||
import ink.wgink.module.file.pojo.dtos.FileUploadSuccessDTO;
|
||||
import ink.wgink.module.file.service.v2.IFileV2Service;
|
||||
import ink.wgink.module.file.pojo.dtos.v2.FileUploadSuccessDTO;
|
||||
import ink.wgink.module.file.service.v2.IFileService;
|
||||
import ink.wgink.pojo.result.ErrorResult;
|
||||
import ink.wgink.pojo.result.SuccessResultData;
|
||||
import io.swagger.annotations.*;
|
||||
@ -12,8 +12,6 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* When you feel like quitting. Think about why you started
|
||||
* 当你想要放弃的时候,想想当初你为何开始
|
||||
@ -25,12 +23,12 @@ import java.util.Map;
|
||||
* @Version: 1.0
|
||||
**/
|
||||
@Api(tags = ISystemConstant.API_TAGS_APP_PREFIX + "文件管理接口")
|
||||
@RestController
|
||||
@RestController("fileAppControllerV2")
|
||||
@RequestMapping(ISystemConstant.APP_PREFIX + "/file/v2")
|
||||
public class FileV2AppController extends DefaultBaseController {
|
||||
public class FileAppController extends DefaultBaseController {
|
||||
|
||||
@Autowired
|
||||
private IFileV2Service fileV2Service;
|
||||
private IFileService fileV2Service;
|
||||
|
||||
@ApiOperation(value = "上传文件", notes = "上传文件接口")
|
||||
@ApiImplicitParams({
|
||||
@ -40,8 +38,7 @@ public class FileV2AppController extends DefaultBaseController {
|
||||
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
|
||||
@PostMapping("upload-file")
|
||||
public SuccessResultData<FileUploadSuccessDTO> uploadFile(@RequestHeader("token") String token, @RequestParam("file") MultipartFile file) {
|
||||
Map<String, Object> params = requestParams();
|
||||
return new SuccessResultData<>(fileV2Service.uploadSingleByToken(token, file, UploadTypeEnum.FILE, params));
|
||||
return new SuccessResultData<>(fileV2Service.uploadSingleByToken(token, file, UploadTypeEnum.FILE));
|
||||
}
|
||||
|
||||
@ApiOperation(value = "上传文件", notes = "上传文件接口")
|
||||
@ -52,8 +49,7 @@ public class FileV2AppController extends DefaultBaseController {
|
||||
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
|
||||
@PostMapping("upload-file-release")
|
||||
public SuccessResultData<FileUploadSuccessDTO> uploadFileByUserId(@RequestHeader("userId") String userId, @RequestParam("file") MultipartFile file) {
|
||||
Map<String, Object> params = requestParams();
|
||||
return new SuccessResultData<>(fileV2Service.uploadSingleByUserId(userId, file, UploadTypeEnum.FILE, params));
|
||||
return new SuccessResultData<>(fileV2Service.uploadSingleByUserId(userId, file, UploadTypeEnum.FILE));
|
||||
}
|
||||
|
||||
@ApiOperation(value = "上传图片", notes = "上传图片接口")
|
||||
@ -64,8 +60,7 @@ public class FileV2AppController extends DefaultBaseController {
|
||||
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
|
||||
@PostMapping("upload-image")
|
||||
public SuccessResultData<FileUploadSuccessDTO> uploadImage(@RequestHeader("token") String token, @RequestParam("image") MultipartFile image) {
|
||||
Map<String, Object> params = requestParams();
|
||||
return new SuccessResultData<>(fileV2Service.uploadSingleByToken(token, image, UploadTypeEnum.IMAGE, params));
|
||||
return new SuccessResultData<>(fileV2Service.uploadSingleByToken(token, image, UploadTypeEnum.IMAGE));
|
||||
}
|
||||
|
||||
@ApiOperation(value = "上传图片", notes = "上传图片接口")
|
||||
@ -76,8 +71,7 @@ public class FileV2AppController extends DefaultBaseController {
|
||||
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
|
||||
@PostMapping("upload-image-release")
|
||||
public SuccessResultData<FileUploadSuccessDTO> uploadImageByUserId(@RequestHeader("userId") String userId, @RequestParam("image") MultipartFile image) {
|
||||
Map<String, Object> params = requestParams();
|
||||
return new SuccessResultData<>(fileV2Service.uploadSingleByUserId(userId, image, UploadTypeEnum.IMAGE, params));
|
||||
return new SuccessResultData<>(fileV2Service.uploadSingleByUserId(userId, image, UploadTypeEnum.IMAGE));
|
||||
}
|
||||
|
||||
@ApiOperation(value = "上传视频", notes = "上传视频接口")
|
||||
@ -88,8 +82,7 @@ public class FileV2AppController extends DefaultBaseController {
|
||||
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
|
||||
@PostMapping("upload-video")
|
||||
public SuccessResultData<FileUploadSuccessDTO> uploadVideo(@RequestHeader("token") String token, @RequestParam("video") MultipartFile video) {
|
||||
Map<String, Object> params = requestParams();
|
||||
return new SuccessResultData<>(fileV2Service.uploadSingleByToken(token, video, UploadTypeEnum.VIDEO, params));
|
||||
return new SuccessResultData<>(fileV2Service.uploadSingleByToken(token, video, UploadTypeEnum.VIDEO));
|
||||
}
|
||||
|
||||
@ApiOperation(value = "上传视频", notes = "上传视频接口")
|
||||
@ -100,8 +93,7 @@ public class FileV2AppController extends DefaultBaseController {
|
||||
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
|
||||
@PostMapping("upload-video-release")
|
||||
public SuccessResultData<FileUploadSuccessDTO> uploadVideoByUserId(@RequestHeader("userId") String userId, @RequestParam("video") MultipartFile video) {
|
||||
Map<String, Object> params = requestParams();
|
||||
return new SuccessResultData<>(fileV2Service.uploadSingleByUserId(userId, video, UploadTypeEnum.VIDEO, params));
|
||||
return new SuccessResultData<>(fileV2Service.uploadSingleByUserId(userId, video, UploadTypeEnum.VIDEO));
|
||||
}
|
||||
|
||||
@ApiOperation(value = "上传音频", notes = "上传音频接口")
|
||||
@ -112,8 +104,7 @@ public class FileV2AppController extends DefaultBaseController {
|
||||
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
|
||||
@PostMapping("upload-audio")
|
||||
public SuccessResultData<FileUploadSuccessDTO> uploadAudio(@RequestHeader("token") String token, @RequestParam("audio") MultipartFile audio) {
|
||||
Map<String, Object> params = requestParams();
|
||||
return new SuccessResultData<>(fileV2Service.uploadSingleByToken(token, audio, UploadTypeEnum.AUDIO, params));
|
||||
return new SuccessResultData<>(fileV2Service.uploadSingleByToken(token, audio, UploadTypeEnum.AUDIO));
|
||||
}
|
||||
|
||||
@ApiOperation(value = "上传音频", notes = "上传音频接口")
|
||||
@ -124,8 +115,7 @@ public class FileV2AppController extends DefaultBaseController {
|
||||
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
|
||||
@PostMapping("upload-audio-release")
|
||||
public SuccessResultData<FileUploadSuccessDTO> uploadAudioByUserId(@RequestHeader("userId") String userId, @RequestParam("audio") MultipartFile audio) {
|
||||
Map<String, Object> params = requestParams();
|
||||
return new SuccessResultData<>(fileV2Service.uploadSingleByUserId(userId, audio, UploadTypeEnum.AUDIO, params));
|
||||
return new SuccessResultData<>(fileV2Service.uploadSingleByUserId(userId, audio, UploadTypeEnum.AUDIO));
|
||||
}
|
||||
|
||||
}
|
@ -4,6 +4,7 @@ package ink.wgink.module.file.dao;
|
||||
import ink.wgink.exceptions.RemoveException;
|
||||
import ink.wgink.exceptions.SaveException;
|
||||
import ink.wgink.exceptions.SearchException;
|
||||
import ink.wgink.exceptions.UpdateException;
|
||||
import ink.wgink.interfaces.init.IInitBaseTable;
|
||||
import ink.wgink.module.file.pojo.dtos.FileDTO;
|
||||
import ink.wgink.module.file.pojo.dtos.FileInfoDTO;
|
||||
@ -31,6 +32,7 @@ public interface IFileDao extends IInitBaseTable {
|
||||
*/
|
||||
void save(Map<String, Object> params) throws SaveException;
|
||||
|
||||
|
||||
/**
|
||||
* 删除文件
|
||||
*
|
||||
@ -47,6 +49,14 @@ public interface IFileDao extends IInitBaseTable {
|
||||
*/
|
||||
void delete(Map<String, Object> params) throws RemoveException;
|
||||
|
||||
/**
|
||||
* 修改文件
|
||||
*
|
||||
* @param params
|
||||
* @throws UpdateException
|
||||
*/
|
||||
void update(Map<String, Object> params) throws UpdateException;
|
||||
|
||||
/**
|
||||
* 更新文件描述
|
||||
*
|
||||
@ -99,4 +109,5 @@ public interface IFileDao extends IInitBaseTable {
|
||||
* @throws SearchException
|
||||
*/
|
||||
List<FilePO> listPO(Map<String, Object> params) throws SearchException;
|
||||
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
package ink.wgink.module.file.pojo.dtos;
|
||||
package ink.wgink.module.file.pojo.dtos.v2;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
@ -24,6 +24,15 @@ public class FileUploadSuccessDTO implements Serializable {
|
||||
@ApiModelProperty(name = "fileSize", value = "文件大小")
|
||||
private Long fileSize;
|
||||
|
||||
public FileUploadSuccessDTO() {
|
||||
}
|
||||
|
||||
public FileUploadSuccessDTO(String fileId, String fileName, Long fileSize) {
|
||||
this.fileId = fileId;
|
||||
this.fileName = fileName;
|
||||
this.fileSize = fileSize;
|
||||
}
|
||||
|
||||
public String getFileId() {
|
||||
return fileId == null ? "" : fileId.trim();
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
package ink.wgink.module.file.pojo.vos.v2;
|
||||
|
||||
/**
|
||||
* @ClassName: FileSaveVO
|
||||
* @Description: 文件保存
|
||||
* @Author: wanggeng
|
||||
* @Date: 2022/7/25 17:58
|
||||
* @Version: 1.0
|
||||
*/
|
||||
public class FileSaveVO {
|
||||
|
||||
private String fileName;
|
||||
private String fileType;
|
||||
private String uploadPath;
|
||||
private long fileSize;
|
||||
private String creator;
|
||||
|
||||
public String getFileName() {
|
||||
return fileName == null ? "" : fileName.trim();
|
||||
}
|
||||
|
||||
public void setFileName(String fileName) {
|
||||
this.fileName = fileName;
|
||||
}
|
||||
|
||||
public String getFileType() {
|
||||
return fileType == null ? "" : fileType.trim();
|
||||
}
|
||||
|
||||
public void setFileType(String fileType) {
|
||||
this.fileType = fileType;
|
||||
}
|
||||
|
||||
public String getUploadPath() {
|
||||
return uploadPath == null ? "" : uploadPath.trim();
|
||||
}
|
||||
|
||||
public void setUploadPath(String uploadPath) {
|
||||
this.uploadPath = uploadPath;
|
||||
}
|
||||
|
||||
public long getFileSize() {
|
||||
return fileSize;
|
||||
}
|
||||
|
||||
public void setFileSize(long fileSize) {
|
||||
this.fileSize = fileSize;
|
||||
}
|
||||
|
||||
public String getCreator() {
|
||||
return creator == null ? "" : creator.trim();
|
||||
}
|
||||
|
||||
public void setCreator(String creator) {
|
||||
this.creator = creator;
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package ink.wgink.module.file.pojo.vos.v2;
|
||||
|
||||
/**
|
||||
* @ClassName: FileUpdateVO
|
||||
* @Description: 文件修改
|
||||
* @Author: wanggeng
|
||||
* @Date: 2022/7/25 22:06
|
||||
* @Version: 1.0
|
||||
*/
|
||||
public class FileUpdateVO extends FileSaveVO {
|
||||
private String fileId;
|
||||
|
||||
public String getFileId() {
|
||||
return fileId == null ? "" : fileId.trim();
|
||||
}
|
||||
|
||||
public void setFileId(String fileId) {
|
||||
this.fileId = fileId;
|
||||
}
|
||||
}
|
@ -628,9 +628,10 @@ public class DefaultFileServiceImpl extends DefaultBaseService implements IDefau
|
||||
uploadFileInputStream = uploadFile.getInputStream();
|
||||
uploadFileOutputStream = new FileOutputStream(new File(uploadFolder + "/" + uploadFileName));
|
||||
MessageDigest messageDigest = MessageDigest.getInstance("MD5");
|
||||
for (byte[] buf = new byte[IFileService.INPUT_STREAM_SIZE]; uploadFileInputStream.read(buf) > -1; ) {
|
||||
uploadFileOutputStream.write(buf, 0, buf.length);
|
||||
messageDigest.update(buf, 0, buf.length);
|
||||
int readLength;
|
||||
for (byte[] buf = new byte[IFileService.INPUT_STREAM_SIZE]; (readLength = uploadFileInputStream.read(buf)) > -1; ) {
|
||||
uploadFileOutputStream.write(buf, 0, readLength);
|
||||
messageDigest.update(buf, 0, readLength);
|
||||
}
|
||||
uploadFileOutputStream.flush();
|
||||
// 计算文件的MD5
|
||||
|
@ -233,8 +233,9 @@ public class MinIoFileServiceImpl extends DefaultBaseService implements IMinIoFi
|
||||
}
|
||||
outputStream.flush();
|
||||
inputStream.close();
|
||||
} catch (ServerException | IOException | ErrorResponseException | InsufficientDataException | InternalException | InvalidKeyException | InvalidResponseException | NoSuchAlgorithmException |
|
||||
XmlParserException e) {
|
||||
} catch (ServerException | IOException | ErrorResponseException | InsufficientDataException |
|
||||
InternalException | InvalidKeyException | InvalidResponseException | NoSuchAlgorithmException |
|
||||
XmlParserException e) {
|
||||
throw new FileException("文件输出异常", e);
|
||||
} finally {
|
||||
if (inputStream != null) {
|
||||
|
@ -0,0 +1,115 @@
|
||||
package ink.wgink.module.file.service.v2;
|
||||
|
||||
import ink.wgink.module.file.enums.UploadTypeEnum;
|
||||
import ink.wgink.module.file.pojo.dtos.v2.FileUploadSuccessDTO;
|
||||
import ink.wgink.module.file.pojo.vos.v2.FileSaveVO;
|
||||
import ink.wgink.module.file.pojo.vos.v2.FileUpdateVO;
|
||||
import ink.wgink.pojo.pos.FilePO;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @ClassName: IFileV2Service
|
||||
* @Description: 文件V2
|
||||
* @Author: wanggeng
|
||||
* @Date: 2022/4/13 16:15
|
||||
* @Version: 1.0
|
||||
*/
|
||||
public interface IFileService {
|
||||
|
||||
/**
|
||||
* 单文件上传
|
||||
*
|
||||
* @param uploadFile 上传文件
|
||||
* @param uploadTypeEnum 上传类型
|
||||
* @return
|
||||
*/
|
||||
FileUploadSuccessDTO uploadSingle(MultipartFile uploadFile, UploadTypeEnum uploadTypeEnum);
|
||||
|
||||
/**
|
||||
* 单文件上传
|
||||
*
|
||||
* @param inputStream 文件流
|
||||
* @param uploadTypeEnum 上传类型
|
||||
* @param fileName 带后缀的文件名
|
||||
* @return
|
||||
*/
|
||||
FileUploadSuccessDTO uploadSingle(InputStream inputStream, UploadTypeEnum uploadTypeEnum, String fileName);
|
||||
|
||||
/**
|
||||
* 单文件上传
|
||||
*
|
||||
* @param token token
|
||||
* @param uploadFile 上传文件
|
||||
* @param uploadTypeEnum 上传类型
|
||||
* @return
|
||||
*/
|
||||
FileUploadSuccessDTO uploadSingleByToken(String token, MultipartFile uploadFile, UploadTypeEnum uploadTypeEnum);
|
||||
|
||||
/**
|
||||
* 单文件上传
|
||||
*
|
||||
* @param token
|
||||
* @param inputStream
|
||||
* @param uploadTypeEnum
|
||||
* @param fileName
|
||||
* @return
|
||||
*/
|
||||
FileUploadSuccessDTO uploadSingleByToken(String token, InputStream inputStream, UploadTypeEnum uploadTypeEnum, String fileName);
|
||||
|
||||
/**
|
||||
* 单文件上传
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @param uploadFile 上传文件
|
||||
* @param uploadTypeEnum 上传类型
|
||||
* @return
|
||||
*/
|
||||
FileUploadSuccessDTO uploadSingleByUserId(String userId, MultipartFile uploadFile, UploadTypeEnum uploadTypeEnum);
|
||||
|
||||
|
||||
/**
|
||||
* 单文件上传
|
||||
*
|
||||
* @param userId
|
||||
* @param inputStream
|
||||
* @param uploadTypeEnum
|
||||
* @param fileName
|
||||
* @return
|
||||
*/
|
||||
FileUploadSuccessDTO uploadSingleByUserId(String userId, InputStream inputStream, UploadTypeEnum uploadTypeEnum, String fileName);
|
||||
|
||||
/**
|
||||
* 保存文件
|
||||
*
|
||||
* @param fileSaveVO
|
||||
* @return
|
||||
*/
|
||||
FileUploadSuccessDTO saveFile(FileSaveVO fileSaveVO);
|
||||
|
||||
/**
|
||||
* 修改文件VO
|
||||
*
|
||||
* @param fileUpdateVO
|
||||
*/
|
||||
void update(FileUpdateVO fileUpdateVO);
|
||||
|
||||
/**
|
||||
* 获取文件
|
||||
*
|
||||
* @param params
|
||||
* @return
|
||||
*/
|
||||
FilePO getPO(Map<String, Object> params);
|
||||
|
||||
/**
|
||||
* 获取文件
|
||||
*
|
||||
* @param fileId
|
||||
* @return
|
||||
*/
|
||||
FilePO getPO(String fileId);
|
||||
|
||||
}
|
@ -1,66 +0,0 @@
|
||||
package ink.wgink.module.file.service.v2;
|
||||
|
||||
import ink.wgink.module.file.enums.UploadTypeEnum;
|
||||
import ink.wgink.module.file.pojo.dtos.FileUploadSuccessDTO;
|
||||
import ink.wgink.pojo.pos.FilePO;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @ClassName: IFileV2Service
|
||||
* @Description: 文件V2
|
||||
* @Author: wanggeng
|
||||
* @Date: 2022/4/13 16:15
|
||||
* @Version: 1.0
|
||||
*/
|
||||
public interface IFileV2Service {
|
||||
|
||||
/**
|
||||
* 单文件上传
|
||||
*
|
||||
* @param uploadFile 上传文件
|
||||
* @param uploadTypeEnum 上传类型
|
||||
* @param requestParams 请求参数
|
||||
* @return
|
||||
*/
|
||||
FileUploadSuccessDTO uploadSingle(MultipartFile uploadFile, UploadTypeEnum uploadTypeEnum, Map<String, Object> requestParams);
|
||||
|
||||
/**
|
||||
* 单文件上传
|
||||
*
|
||||
* @param token token
|
||||
* @param uploadFile 上传文件
|
||||
* @param uploadTypeEnum 上传类型
|
||||
* @param requestParams 请求参数
|
||||
* @return
|
||||
*/
|
||||
FileUploadSuccessDTO uploadSingleByToken(String token, MultipartFile uploadFile, UploadTypeEnum uploadTypeEnum, Map<String, Object> requestParams);
|
||||
|
||||
/**
|
||||
* 单文件上传
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @param uploadFile 上传文件
|
||||
* @param uploadTypeEnum 上传类型
|
||||
* @param requestParams 请求参数
|
||||
* @return
|
||||
*/
|
||||
FileUploadSuccessDTO uploadSingleByUserId(String userId, MultipartFile uploadFile, UploadTypeEnum uploadTypeEnum, Map<String, Object> requestParams);
|
||||
|
||||
/**
|
||||
* 获取文件
|
||||
*
|
||||
* @param params
|
||||
* @return
|
||||
*/
|
||||
FilePO getPO(Map<String, Object> params);
|
||||
|
||||
/**
|
||||
* 获取文件
|
||||
*
|
||||
* @param fileId
|
||||
* @return
|
||||
*/
|
||||
FilePO getPO(String fileId);
|
||||
}
|
@ -0,0 +1,171 @@
|
||||
package ink.wgink.module.file.service.v2.impl;
|
||||
|
||||
import ink.wgink.common.base.DefaultBaseService;
|
||||
import ink.wgink.exceptions.SearchException;
|
||||
import ink.wgink.module.file.components.FileComponent;
|
||||
import ink.wgink.module.file.dao.IFileDao;
|
||||
import ink.wgink.module.file.enums.UploadTypeEnum;
|
||||
import ink.wgink.module.file.pojo.dtos.v2.FileUploadSuccessDTO;
|
||||
import ink.wgink.module.file.pojo.vos.v2.FileSaveVO;
|
||||
import ink.wgink.module.file.pojo.vos.v2.FileUpdateVO;
|
||||
import ink.wgink.module.file.service.v2.IFileService;
|
||||
import ink.wgink.pojo.pos.FilePO;
|
||||
import ink.wgink.util.UUIDUtil;
|
||||
import ink.wgink.util.date.DateUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @ClassName: FileV2ServiceImpl
|
||||
* @Description: 文件V2
|
||||
* @Author: wanggeng
|
||||
* @Date: 2022/4/13 16:15
|
||||
* @Version: 1.0
|
||||
*/
|
||||
@Service("fileServiceV2")
|
||||
public class FileServiceImpl extends DefaultBaseService implements IFileService {
|
||||
|
||||
@Autowired
|
||||
private FileComponent fileComponent;
|
||||
@Autowired
|
||||
private IFileDao fileDao;
|
||||
|
||||
@Override
|
||||
public FileUploadSuccessDTO uploadSingle(MultipartFile uploadFile, UploadTypeEnum uploadTypeEnum) {
|
||||
FileSaveVO fileSaveVO = getFileSaveVO(uploadFile, uploadTypeEnum);
|
||||
fileSaveVO.setCreator(securityComponent.getCurrentUser().getUserId());
|
||||
return saveFile(fileSaveVO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileUploadSuccessDTO uploadSingle(InputStream inputStream, UploadTypeEnum uploadTypeEnum, String fileName) {
|
||||
FileSaveVO fileSaveVO = getFileSaveVO(inputStream, uploadTypeEnum, fileName);
|
||||
fileSaveVO.setCreator(securityComponent.getCurrentUser().getUserId());
|
||||
return saveFile(fileSaveVO);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public FileUploadSuccessDTO uploadSingleByToken(String token, MultipartFile uploadFile, UploadTypeEnum uploadTypeEnum) {
|
||||
FileSaveVO fileSaveVO = getFileSaveVO(uploadFile, uploadTypeEnum);
|
||||
fileSaveVO.setCreator(getAppTokenUser(token).getId());
|
||||
return saveFile(fileSaveVO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileUploadSuccessDTO uploadSingleByToken(String token, InputStream inputStream, UploadTypeEnum uploadTypeEnum, String fileName) {
|
||||
FileSaveVO fileSaveVO = getFileSaveVO(inputStream, uploadTypeEnum, fileName);
|
||||
fileSaveVO.setCreator(getAppTokenUser(token).getId());
|
||||
return saveFile(fileSaveVO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileUploadSuccessDTO uploadSingleByUserId(String userId, MultipartFile uploadFile, UploadTypeEnum uploadTypeEnum) {
|
||||
FileSaveVO fileSaveVO = getFileSaveVO(uploadFile, uploadTypeEnum);
|
||||
fileSaveVO.setCreator(userId);
|
||||
return saveFile(fileSaveVO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileUploadSuccessDTO uploadSingleByUserId(String userId, InputStream inputStream, UploadTypeEnum uploadTypeEnum, String fileName) {
|
||||
FileSaveVO fileSaveVO = getFileSaveVO(inputStream, uploadTypeEnum, fileName);
|
||||
fileSaveVO.setCreator(userId);
|
||||
return saveFile(fileSaveVO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileUploadSuccessDTO saveFile(FileSaveVO fileSaveVO) {
|
||||
String fileId = UUIDUtil.getUUID();
|
||||
Map<String, Object> params = getHashMap(10);
|
||||
params.put("fileId", fileId);
|
||||
params.put("fileName", fileSaveVO.getFileName());
|
||||
params.put("filePath", fileSaveVO.getUploadPath());
|
||||
params.put("fileUrl", fileComponent.getFileUrl(fileSaveVO.getUploadPath()));
|
||||
params.put("fileType", fileSaveVO.getFileType());
|
||||
params.put("fileSize", fileSaveVO.getFileSize());
|
||||
params.put("isBack", 0);
|
||||
|
||||
String time = DateUtil.getTime();
|
||||
params.put("creator", fileSaveVO.getCreator());
|
||||
params.put("modifier", fileSaveVO.getCreator());
|
||||
params.put("gmtCreate", time);
|
||||
params.put("gmtModified", time);
|
||||
params.put("isDelete", 0);
|
||||
fileDao.save(params);
|
||||
|
||||
return new FileUploadSuccessDTO(fileId, fileSaveVO.getFileName(), fileSaveVO.getFileSize());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(FileUpdateVO fileUpdateVO) {
|
||||
Map<String, Object> params = getHashMap(10);
|
||||
params.put("fileId", fileUpdateVO.getFileId());
|
||||
params.put("fileName", fileUpdateVO.getFileName());
|
||||
params.put("filePath", fileUpdateVO.getUploadPath());
|
||||
params.put("fileUrl", fileComponent.getFileUrl(fileUpdateVO.getUploadPath()));
|
||||
params.put("fileType", fileUpdateVO.getFileType());
|
||||
params.put("fileSize", fileUpdateVO.getFileSize());
|
||||
params.put("modifier", fileUpdateVO.getCreator());
|
||||
params.put("gmtModified", DateUtil.getTime());
|
||||
fileDao.update(params);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FilePO getPO(Map<String, Object> params) {
|
||||
return fileDao.getPO(params);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FilePO getPO(String fileId) {
|
||||
Map<String, Object> params = getHashMap(2);
|
||||
params.put("fileId", fileId);
|
||||
return getPO(params);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件保存VO
|
||||
*
|
||||
* @param uploadFile
|
||||
* @param uploadTypeEnum
|
||||
* @return
|
||||
*/
|
||||
private FileSaveVO getFileSaveVO(MultipartFile uploadFile, UploadTypeEnum uploadTypeEnum) {
|
||||
String fileName = uploadFile.getOriginalFilename();
|
||||
InputStream inputStream;
|
||||
try {
|
||||
inputStream = uploadFile.getInputStream();
|
||||
} catch (IOException e) {
|
||||
throw new SearchException(e);
|
||||
}
|
||||
return getFileSaveVO(inputStream, uploadTypeEnum, fileName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件保存VO
|
||||
*
|
||||
* @param inputStream
|
||||
* @param uploadTypeEnum
|
||||
* @param fileName
|
||||
* @return
|
||||
*/
|
||||
private FileSaveVO getFileSaveVO(InputStream inputStream, UploadTypeEnum uploadTypeEnum, String fileName) {
|
||||
String fileType = fileComponent.getFileType(fileName);
|
||||
String uploadPath = fileComponent.getUploadPath(uploadTypeEnum, fileType);
|
||||
String uuidFileName = UUIDUtil.get32UUID() + "." + fileType;
|
||||
long fileSize = fileComponent.saveFile(inputStream, uuidFileName, uploadPath);
|
||||
// 保存文件
|
||||
FileSaveVO fileSaveVO = new FileSaveVO();
|
||||
fileSaveVO.setFileName(fileName);
|
||||
fileSaveVO.setFileType(fileType);
|
||||
fileSaveVO.setUploadPath(uploadPath + File.separator + uuidFileName);
|
||||
fileSaveVO.setFileSize(fileSize);
|
||||
return fileSaveVO;
|
||||
}
|
||||
|
||||
}
|
@ -1,73 +0,0 @@
|
||||
package ink.wgink.module.file.service.v2.impl;
|
||||
|
||||
import ink.wgink.common.base.DefaultBaseService;
|
||||
import ink.wgink.module.file.dao.IFileDao;
|
||||
import ink.wgink.module.file.enums.UploadTypeEnum;
|
||||
import ink.wgink.module.file.pojo.dtos.FileUploadSuccessDTO;
|
||||
import ink.wgink.module.file.service.IFileService;
|
||||
import ink.wgink.module.file.service.v2.IFileV2Service;
|
||||
import ink.wgink.pojo.pos.FilePO;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @ClassName: FileV2ServiceImpl
|
||||
* @Description: 文件V2
|
||||
* @Author: wanggeng
|
||||
* @Date: 2022/4/13 16:15
|
||||
* @Version: 1.0
|
||||
*/
|
||||
@Service
|
||||
public class FileV2ServiceImpl extends DefaultBaseService implements IFileV2Service {
|
||||
|
||||
@Autowired
|
||||
private IFileService fileService;
|
||||
@Autowired
|
||||
private IFileDao fileDao;
|
||||
|
||||
@Override
|
||||
public FileUploadSuccessDTO uploadSingle(MultipartFile uploadFile, UploadTypeEnum uploadTypeEnum, Map<String, Object> requestParams) {
|
||||
fileService.uploadSingle(uploadFile, uploadTypeEnum, requestParams);
|
||||
FileUploadSuccessDTO fileUploadSuccessDTO = new FileUploadSuccessDTO();
|
||||
fileUploadSuccessDTO.setFileId(requestParams.get("fileId").toString());
|
||||
fileUploadSuccessDTO.setFileName(requestParams.get("fileName").toString());
|
||||
fileUploadSuccessDTO.setFileSize(Long.valueOf(requestParams.get("fileSize").toString()));
|
||||
return fileUploadSuccessDTO;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileUploadSuccessDTO uploadSingleByToken(String token, MultipartFile uploadFile, UploadTypeEnum uploadTypeEnum, Map<String, Object> requestParams) {
|
||||
fileService.uploadSingle(token, uploadFile, uploadTypeEnum, requestParams);
|
||||
FileUploadSuccessDTO fileUploadSuccessDTO = new FileUploadSuccessDTO();
|
||||
fileUploadSuccessDTO.setFileId(requestParams.get("fileId").toString());
|
||||
fileUploadSuccessDTO.setFileName(requestParams.get("fileName").toString());
|
||||
fileUploadSuccessDTO.setFileSize(Long.valueOf(requestParams.get("fileSize").toString()));
|
||||
return fileUploadSuccessDTO;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileUploadSuccessDTO uploadSingleByUserId(String userId, MultipartFile uploadFile, UploadTypeEnum uploadTypeEnum, Map<String, Object> requestParams) {
|
||||
fileService.uploadSingleByUserId(userId, uploadFile, uploadTypeEnum, requestParams);
|
||||
FileUploadSuccessDTO fileUploadSuccessDTO = new FileUploadSuccessDTO();
|
||||
fileUploadSuccessDTO.setFileId(requestParams.get("fileId").toString());
|
||||
fileUploadSuccessDTO.setFileName(requestParams.get("fileName").toString());
|
||||
fileUploadSuccessDTO.setFileSize(Long.valueOf(requestParams.get("fileSize").toString()));
|
||||
return fileUploadSuccessDTO;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FilePO getPO(Map<String, Object> params) {
|
||||
return fileDao.getPO(params);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FilePO getPO(String fileId) {
|
||||
Map<String, Object> params = getHashMap(2);
|
||||
params.put("fileId", fileId);
|
||||
return getPO(params);
|
||||
}
|
||||
|
||||
}
|
@ -2,8 +2,6 @@
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="ink.wgink.module.file.dao.IFileDao">
|
||||
|
||||
<cache/>
|
||||
|
||||
<resultMap id="filePO" type="ink.wgink.pojo.pos.FilePO">
|
||||
<id property="fileId" column="file_id"/>
|
||||
<result property="fileName" column="file_name"/>
|
||||
@ -63,7 +61,7 @@
|
||||
</update>
|
||||
|
||||
<!-- 保存文件 -->
|
||||
<insert id="save" parameterType="map" flushCache="true">
|
||||
<insert id="save" parameterType="map">
|
||||
INSERT INTO sys_file(
|
||||
file_id,
|
||||
file_name,
|
||||
@ -96,7 +94,7 @@
|
||||
</insert>
|
||||
|
||||
<!-- 删除文件 -->
|
||||
<update id="remove" parameterType="map" flushCache="true">
|
||||
<update id="remove" parameterType="map">
|
||||
UPDATE
|
||||
sys_file
|
||||
SET
|
||||
@ -111,7 +109,7 @@
|
||||
</update>
|
||||
|
||||
<!-- 删除文件(物理删除) -->
|
||||
<delete id="delete" parameterType="map" flushCache="true">
|
||||
<delete id="delete" parameterType="map">
|
||||
DELETE FROM
|
||||
sys_file
|
||||
WHERE
|
||||
@ -122,7 +120,41 @@
|
||||
</delete>
|
||||
|
||||
<!-- 更新文件描述 -->
|
||||
<update id="updateSummary" parameterType="map" flushCache="true">
|
||||
<update id="update" parameterType="map">
|
||||
UPDATE
|
||||
sys_file
|
||||
SET
|
||||
<if test="fileName != null and fileName != ''">
|
||||
file_name = #{fileName},
|
||||
</if>
|
||||
<if test="filePath != null">
|
||||
file_path = #{filePath},
|
||||
</if>
|
||||
<if test="fileUrl != null">
|
||||
file_url = #{fileUrl},
|
||||
</if>
|
||||
<if test="fileType != null">
|
||||
file_type = #{fileType},
|
||||
</if>
|
||||
<if test="fileSize != null">
|
||||
file_size = #{fileSize},
|
||||
</if>
|
||||
modifier = #{modifier},
|
||||
gmt_modified = #{gmtModified}
|
||||
WHERE
|
||||
<if test="fileId != null and fileId != ''">
|
||||
file_id = #{fileId}
|
||||
</if>
|
||||
<if test="fileIds != null and fileIds.size > 0">
|
||||
file_id IN
|
||||
<foreach collection="fileIds" index="index" open="(" separator="," close=")">
|
||||
#{fileIds[${index}]}
|
||||
</foreach>
|
||||
</if>
|
||||
</update>
|
||||
|
||||
<!-- 更新文件描述 -->
|
||||
<update id="updateSummary" parameterType="map">
|
||||
UPDATE
|
||||
sys_file
|
||||
SET
|
||||
@ -140,7 +172,7 @@
|
||||
</update>
|
||||
|
||||
<!-- 获取文件 -->
|
||||
<select id="getPO" parameterType="map" resultMap="filePO" useCache="true">
|
||||
<select id="getPO" parameterType="map" resultMap="filePO">
|
||||
SELECT
|
||||
file_id,
|
||||
file_name,
|
||||
@ -213,7 +245,7 @@
|
||||
</select>
|
||||
|
||||
<!-- 文件列表 -->
|
||||
<select id="listInfo" parameterType="map" resultMap="fileInfoDTO" useCache="false">
|
||||
<select id="listInfo" parameterType="map" resultMap="fileInfoDTO">
|
||||
SELECT
|
||||
file_id,
|
||||
file_name,
|
||||
@ -254,7 +286,7 @@
|
||||
</select>
|
||||
|
||||
<!-- 文件列表 -->
|
||||
<select id="listByMd5" parameterType="java.lang.String" resultMap="fileInfoDTO" useCache="false">
|
||||
<select id="listByMd5" parameterType="java.lang.String" resultMap="fileInfoDTO">
|
||||
SELECT
|
||||
file_id,
|
||||
file_name,
|
||||
@ -278,7 +310,7 @@
|
||||
</select>
|
||||
|
||||
<!-- 文件列表 -->
|
||||
<select id="listPO" parameterType="map" resultMap="filePO" useCache="true">
|
||||
<select id="listPO" parameterType="map" resultMap="filePO">
|
||||
SELECT
|
||||
file_id,
|
||||
file_name,
|
||||
|
Loading…
Reference in New Issue
Block a user