|
@@ -2,11 +2,13 @@ package com.sckw.file.service;
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.aliyun.oss.model.OSSObject;
|
|
import com.aliyun.oss.model.OSSObject;
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.sckw.core.common.enums.NumberConstant;
|
|
import com.sckw.core.common.enums.NumberConstant;
|
|
|
import com.sckw.core.common.enums.StringConstant;
|
|
import com.sckw.core.common.enums.StringConstant;
|
|
|
import com.sckw.core.common.enums.enums.FileDisposeLayoutEnum;
|
|
import com.sckw.core.common.enums.enums.FileDisposeLayoutEnum;
|
|
|
import com.sckw.core.common.enums.enums.FileEnum;
|
|
import com.sckw.core.common.enums.enums.FileEnum;
|
|
|
import com.sckw.core.model.file.FileInfo;
|
|
import com.sckw.core.model.file.FileInfo;
|
|
|
|
|
+import com.sckw.core.model.vo.FileInfoEncryptVO;
|
|
|
import com.sckw.core.model.vo.FileInfoVO;
|
|
import com.sckw.core.model.vo.FileInfoVO;
|
|
|
import com.sckw.core.utils.FileUtils;
|
|
import com.sckw.core.utils.FileUtils;
|
|
|
import com.sckw.core.utils.IdWorker;
|
|
import com.sckw.core.utils.IdWorker;
|
|
@@ -21,6 +23,7 @@ import com.sckw.file.dao.KwsFileEncryptDao;
|
|
|
import com.sckw.file.dao.KwsFileInfoDao;
|
|
import com.sckw.file.dao.KwsFileInfoDao;
|
|
|
import com.sckw.file.model.kwfFileEncrypt;
|
|
import com.sckw.file.model.kwfFileEncrypt;
|
|
|
import com.sckw.file.model.kwfFileInfo;
|
|
import com.sckw.file.model.kwfFileInfo;
|
|
|
|
|
+import com.sckw.file.model.param.FileImageParam;
|
|
|
import jakarta.servlet.http.HttpServletRequest;
|
|
import jakarta.servlet.http.HttpServletRequest;
|
|
|
import jakarta.servlet.http.HttpServletResponse;
|
|
import jakarta.servlet.http.HttpServletResponse;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
@@ -57,6 +60,8 @@ import java.util.zip.ZipOutputStream;
|
|
|
@Service
|
|
@Service
|
|
|
public class FileService {
|
|
public class FileService {
|
|
|
|
|
|
|
|
|
|
+ final static String IMG_FORMAT = "png_jpg_bmp_gif_tif_jpeg_PNG_JPG_BMP_GIF_TIF_JPEG_HEIC_heic";
|
|
|
|
|
+
|
|
|
@Autowired
|
|
@Autowired
|
|
|
KwsFileInfoDao fileInfoDao;
|
|
KwsFileInfoDao fileInfoDao;
|
|
|
|
|
|
|
@@ -254,7 +259,7 @@ public class FileService {
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public HttpResult uploadFileInfo(MultipartFile file){
|
|
|
|
|
|
|
+ public HttpResult uploadFileInfo(MultipartFile file) {
|
|
|
boolean flag = checkFileFormat(file);
|
|
boolean flag = checkFileFormat(file);
|
|
|
if (!flag) {
|
|
if (!flag) {
|
|
|
throw new RuntimeException("上传文件格式错误!");
|
|
throw new RuntimeException("上传文件格式错误!");
|
|
@@ -349,10 +354,10 @@ public class FileService {
|
|
|
insertFile(returnFileInfo, isImage);
|
|
insertFile(returnFileInfo, isImage);
|
|
|
/**存储到加密属性文件信息*/
|
|
/**存储到加密属性文件信息*/
|
|
|
String fileMd5 = returnFileInfo.getFileMd5();
|
|
String fileMd5 = returnFileInfo.getFileMd5();
|
|
|
- String filePath = returnFileInfo.getFilePath();
|
|
|
|
|
- FileInfoVO vo = new FileInfoVO();
|
|
|
|
|
|
|
+// String filePath = returnFileInfo.getFilePath();
|
|
|
|
|
+ FileInfoEncryptVO vo = new FileInfoEncryptVO();
|
|
|
vo.setFileMd5(fileMd5);
|
|
vo.setFileMd5(fileMd5);
|
|
|
- vo.setFilePath(filePath);
|
|
|
|
|
|
|
+// vo.setFilePath(filePath);
|
|
|
// insertFileEncrypt(fileMd5, filePath, FileEnum.FILE_STORE_TYPE_OSS, isImage);
|
|
// insertFileEncrypt(fileMd5, filePath, FileEnum.FILE_STORE_TYPE_OSS, isImage);
|
|
|
return HttpResult.ok(vo);
|
|
return HttpResult.ok(vo);
|
|
|
}
|
|
}
|
|
@@ -403,11 +408,51 @@ public class FileService {
|
|
|
insertFile(returnFileInfo, isImage);
|
|
insertFile(returnFileInfo, isImage);
|
|
|
/**存储到加密属性文件信息*/
|
|
/**存储到加密属性文件信息*/
|
|
|
String fileMd5 = returnFileInfo.getFileMd5();
|
|
String fileMd5 = returnFileInfo.getFileMd5();
|
|
|
- String filePath = returnFileInfo.getFilePath();
|
|
|
|
|
|
|
+// String filePath = returnFileInfo.getFilePath();
|
|
|
// insertFileEncrypt(fileMd5, filePath, FileEnum.FILE_STORE_TYPE_OSS, isImage);
|
|
// insertFileEncrypt(fileMd5, filePath, FileEnum.FILE_STORE_TYPE_OSS, isImage);
|
|
|
- FileInfoVO vo = new FileInfoVO();
|
|
|
|
|
|
|
+ FileInfoEncryptVO vo = new FileInfoEncryptVO();
|
|
|
vo.setFileMd5(fileMd5);
|
|
vo.setFileMd5(fileMd5);
|
|
|
- vo.setFilePath(filePath);
|
|
|
|
|
|
|
+// vo.setFilePath(filePath);
|
|
|
return HttpResult.ok(Status.SUCCESS.getCode(), "", vo);
|
|
return HttpResult.ok(Status.SUCCESS.getCode(), "", vo);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ public HttpResult getImage(FileImageParam fileImageParam) {
|
|
|
|
|
+ String lessenRatio = fileImageParam.getLessenRatio();
|
|
|
|
|
+ String fileHeight = fileImageParam.getFileHeight();
|
|
|
|
|
+ String fileWidth = fileImageParam.getFileWidth();
|
|
|
|
|
+ boolean flag = true;
|
|
|
|
|
+ if (fileImageParam.isLessen()) {
|
|
|
|
|
+ if (org.apache.commons.lang3.StringUtils.isBlank(lessenRatio)) {
|
|
|
|
|
+ lessenRatio = String.valueOf(NumberConstant.TWELVE);
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ flag = false;
|
|
|
|
|
+ if (org.apache.commons.lang3.StringUtils.isBlank(fileHeight)) {
|
|
|
|
|
+ fileHeight = String.valueOf(NumberConstant.TWO_HUNDRED);
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ if (org.apache.commons.lang3.StringUtils.isBlank(fileWidth)) {
|
|
|
|
|
+ fileWidth = String.valueOf(NumberConstant.TWO_HUNDRED);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ String returnImageAddress = FileUtils.getOSSAddressPrefix();
|
|
|
|
|
+ LambdaQueryWrapper<kwfFileInfo> wrapper = new LambdaQueryWrapper<>();
|
|
|
|
|
+ wrapper.eq(com.sckw.file.model.kwfFileInfo::getMd5, fileImageParam.getFileKey())
|
|
|
|
|
+ .orderByDesc(kwfFileInfo::getCreateTime);
|
|
|
|
|
+ kwfFileInfo kwfFileInfo = fileInfoDao.selectList(
|
|
|
|
|
+ wrapper).get(0);
|
|
|
|
|
+ if (IMG_FORMAT.indexOf(kwfFileInfo.getFileSuffix()) == -1) {
|
|
|
|
|
+ returnImageAddress = returnImageAddress + kwfFileInfo.getFilePath();
|
|
|
|
|
+ } else {
|
|
|
|
|
+ if (flag) {
|
|
|
|
|
+ returnImageAddress = returnImageAddress + kwfFileInfo.getFilePath()
|
|
|
|
|
+ + FileDisposeLayoutEnum.OSS_LESSEN.getParameter() + lessenRatio;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ returnImageAddress = returnImageAddress + kwfFileInfo.getFilePath()
|
|
|
|
|
+ + FileDisposeLayoutEnum.OSS_ABBREVIATE_LEFT.getParameter() + fileHeight
|
|
|
|
|
+ + FileDisposeLayoutEnum.OSS_ABBREVIATE_RIGHT.getParameter() + fileWidth;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return HttpResult.ok("",returnImageAddress);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|