Commit 87f4fb0a authored by 冷玲鹏's avatar 冷玲鹏

Merge remote-tracking branch 'origin/master'

parents 8cad4b40 88f7b80b
...@@ -324,15 +324,11 @@ global: ...@@ -324,15 +324,11 @@ global:
sl_location: sl sl_location: sl
freemarker_location: /freemarker freemarker_location: /freemarker
image_location: /upload image_location: /upload
video_location: video
temp_location: temp
file_location: file
ppt_location: ppt ppt_location: ppt
pdf_location: pdf pdf_location: pdf
cut_pdf_location: cutPdf cut_pdf_location: cutPdf
excel_template_location: excel-template/ excel_template_location: excel-template/
cource_logo_location: /course/logo cource_logo_location: /course/logo
images_location: /images
lanch_logo_location: /lanch/logo lanch_logo_location: /lanch/logo
md_file_location: mdFiles md_file_location: mdFiles
che_def_template_location: /WEB-INF/classes/che-def-jsonfile/java-mysql.json che_def_template_location: /WEB-INF/classes/che-def-jsonfile/java-mysql.json
...@@ -348,7 +344,6 @@ global: ...@@ -348,7 +344,6 @@ global:
open_office_home: D:/oppenOffice/openOffice open_office_home: D:/oppenOffice/openOffice
cut_pdf_num: 30 cut_pdf_num: 30
code: code:
admin: ROLE_1001
teacher: ROLE_1002 teacher: ROLE_1002
student: ROLE_1003 student: ROLE_1003
java: '001' java: '001'
......
...@@ -178,6 +178,7 @@ global: ...@@ -178,6 +178,7 @@ global:
temp_location: /temp temp_location: /temp
file_location: /file file_location: /file
images_location: /images images_location: /images
zsp_location: /zsp
code: code:
admin: ROLE_1001 admin: ROLE_1001
resetPassword: 123456 resetPassword: 123456
......
...@@ -163,6 +163,7 @@ global: ...@@ -163,6 +163,7 @@ global:
temp_location: /temp temp_location: /temp
file_location: /file file_location: /file
images_location: /images images_location: /images
zsp_location: /zsp
code: code:
admin: ROLE_1001 admin: ROLE_1001
resetPassword: 123456 resetPassword: 123456
......
...@@ -163,6 +163,7 @@ global: ...@@ -163,6 +163,7 @@ global:
temp_location: /temp temp_location: /temp
file_location: /file file_location: /file
images_location: /images images_location: /images
zsp_location: /zsp
code: code:
admin: ROLE_1001 admin: ROLE_1001
resetPassword: 123456 resetPassword: 123456
......
...@@ -117,18 +117,4 @@ cy: ...@@ -117,18 +117,4 @@ cy:
stringOutputType: base644 stringOutputType: base644
#身份证、邮箱、手机号存储加密 #身份证、邮箱、手机号存储加密
aesSecret: 'PLMOKNIJBU' aesSecret: 'PLMOKNIJBU'
global:
path:
# base_upload_location: C:\software\nginx-1.26.2\html\upload
# base_discovery: 'http://192.168.1.112:8023/upload/'
base_upload_location: D:\Work\nginx-1.24.0\html\upload
base_discovery: 'http://192.168.1.45/upload/'
zsp_location: /zsp
code_generate_location: /code
video_location: /video
temp_location: /tempg
file_location: /file
images_location: /images
code:
admin: ROLE_1001
resetPassword: 123456
...@@ -162,6 +162,7 @@ global: ...@@ -162,6 +162,7 @@ global:
temp_location: /temp temp_location: /temp
file_location: /file file_location: /file
images_location: /images images_location: /images
zsp_location: /zsp
code: code:
admin: ROLE_1001 admin: ROLE_1001
resetPassword: 123456 resetPassword: 123456
......
...@@ -145,6 +145,14 @@ ...@@ -145,6 +145,14 @@
<artifactId>xmlbeans</artifactId> <artifactId>xmlbeans</artifactId>
<version>5.1.1</version> <!-- 请检查最新版本并替换 --> <version>5.1.1</version> <!-- 请检查最新版本并替换 -->
</dependency> </dependency>
<dependency>
<groupId>org.imgscalr</groupId>
<artifactId>imgscalr-lib</artifactId>
<version>4.2</version>
</dependency>
</dependencies> </dependencies>
<build> <build>
......
...@@ -9,6 +9,7 @@ import io.swagger.v3.oas.annotations.Parameter; ...@@ -9,6 +9,7 @@ import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters; import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpServletResponse;
import org.imgscalr.Scalr;
import org.rcisoft.business.memInfo.entity.MemInfo; import org.rcisoft.business.memInfo.entity.MemInfo;
import org.rcisoft.business.memInfo.service.MemInfoService; import org.rcisoft.business.memInfo.service.MemInfoService;
import org.rcisoft.core.anno.CyEncryptSm4Anno; import org.rcisoft.core.anno.CyEncryptSm4Anno;
...@@ -26,12 +27,18 @@ import org.rcisoft.core.service.CyFileStorageService; ...@@ -26,12 +27,18 @@ import org.rcisoft.core.service.CyFileStorageService;
import org.rcisoft.core.util.CyEpExcelUtil; import org.rcisoft.core.util.CyEpExcelUtil;
import org.rcisoft.core.util.CyResultGenUtil; import org.rcisoft.core.util.CyResultGenUtil;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.BindingResult; import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import javax.imageio.ImageIO;
import javax.validation.Valid; import javax.validation.Valid;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
...@@ -110,15 +117,54 @@ public class AppMemInfoController extends CyPaginationController<MemInfo> { ...@@ -110,15 +117,54 @@ public class AppMemInfoController extends CyPaginationController<MemInfo> {
@Parameters({@Parameter(name = "file", description = "文件", required = true)}) @Parameters({@Parameter(name = "file", description = "文件", required = true)})
@PostMapping(value = "/open/fileUpload") @PostMapping(value = "/open/fileUpload")
@ResponseBody @ResponseBody
public CyResult fileUpload(@RequestParam("file") MultipartFile file, @RequestParam("temp") String temp, @RequestParam(name = "bucket", required = false) String bucket) { public CyResult fileUpload(@RequestParam("file") MultipartFile file, @RequestParam("temp") String temp, @RequestParam(name = "bucket", required = false) String bucket,
@RequestParam(name = "isCompacted", required = false,defaultValue = "false") boolean isCompacted) {
//文件上传限制 //文件上传限制
String[] split = cyGlobal.getFileUploadFormatRestrictions().split(","); String[] split = cyGlobal.getFileUploadFormatRestrictions().split(",");
if (file==null || Arrays.stream(split).anyMatch(file.getOriginalFilename()::contains)){ if (file==null || Arrays.stream(split).anyMatch(file.getOriginalFilename()::contains)){
throw new CyServiceException(CyResSysExcEnum.FILE_STORAGE_ERROR); throw new CyServiceException(CyResSysExcEnum.FILE_STORAGE_ERROR);
}; }
//如果上传文件是大于1Mb的图片,判断是否需要压缩
String[] imageExtensions = {".jpg", ".jpeg", ".png", ".gif", ".bmp", ".tiff", ".webp"};
long maxSize = 1024 * 1024; // 1MB
if (Arrays.stream(imageExtensions).anyMatch(file.getOriginalFilename()::contains) && file.getSize() > maxSize && isCompacted) {
file = compressImage(file);
}
return CyResultGenUtil.builder(new CyPersistModel(1), return CyResultGenUtil.builder(new CyPersistModel(1),
CyMessCons.MESSAGE_ALERT_SUCCESS, CyMessCons.MESSAGE_ALERT_SUCCESS,
CyMessCons.MESSAGE_ALERT_ERROR, CyMessCons.MESSAGE_ALERT_ERROR,
cyFileStorageService.filePath(file, temp, bucket)); cyFileStorageService.filePath(file, temp, bucket));
} }
private static MultipartFile compressImage(MultipartFile file) {
BufferedImage image = null;
try {
image = ImageIO.read(file.getInputStream());
// 设置压缩质量
float quality = 1.0f;
// 调整图片尺寸,设置目标宽度和高度
int targetWidth = 800; // 目标宽度(可以根据需求调整)
int targetHeight = 600; // 目标高度(可以根据需求调整)
// 使用Imgscalr进行图像压缩(缩放)
BufferedImage compressedImage = Scalr.resize(image, Scalr.Method.QUALITY, targetWidth, targetHeight);
// 将BufferedImage写入ByteArrayOutputStream
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
String originalFilename = file.getOriginalFilename();
String extension = originalFilename.substring(originalFilename.lastIndexOf('.') + 1).toLowerCase();
ImageIO.write(compressedImage, extension, outputStream); // 假设原始图片格式为jpg
// 将压缩后的图片数据转换为byte数组
byte[] compressedImageData = outputStream.toByteArray();
// 将byte数组转换为MultipartFile
return new MockMultipartFile(file.getName(), originalFilename,
file.getContentType(), compressedImageData);
} catch (IOException e) {
e.printStackTrace();
}
return file;
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment