From 34981c30a78e8bbd7791131059a9210f9928b62c Mon Sep 17 00:00:00 2001
From: 刘光辉 <347230014@qq.com>
Date: 星期四, 17 九月 2026 09:24:09 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master' into master
---
jnpf-file/jnpf-file-storage/src/main/java/jnpf/controller/UtilsController.java | 352 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 352 insertions(+), 0 deletions(-)
diff --git a/jnpf-file/jnpf-file-storage/src/main/java/jnpf/controller/UtilsController.java b/jnpf-file/jnpf-file-storage/src/main/java/jnpf/controller/UtilsController.java
new file mode 100644
index 0000000..233fb60
--- /dev/null
+++ b/jnpf-file/jnpf-file-storage/src/main/java/jnpf/controller/UtilsController.java
@@ -0,0 +1,352 @@
+package jnpf.controller;
+
+import com.alibaba.fastjson.JSONObject;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.Operation;
+import jnpf.base.ActionResult;
+import jnpf.base.DictionaryDataApi;
+import jnpf.model.UploaderVO;
+import jnpf.base.vo.DownloadVO;
+import jnpf.config.ConfigValueUtil;
+import jnpf.constant.FileTypeConstant;
+import jnpf.constant.MsgCode;
+import jnpf.entity.FileParameter;
+import jnpf.service.FileService;
+import jnpf.util.FileExport;
+import jnpf.exception.DataException;
+import jnpf.file.FileApi;
+import jnpf.file.FileUploadApi;
+import jnpf.model.*;
+import jnpf.util.*;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.io.FileUtils;
+import org.dromara.x.file.storage.core.FileInfo;
+import org.springframework.http.MediaType;
+import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.io.*;
+import java.nio.file.Files;
+import java.util.*;
+
+/**
+ * 閫氱敤鎺у埗鍣�
+ *
+ * @author JNPF寮�鍙戝钩鍙扮粍
+ * @version V3.1.0
+ * @copyright 寮曡繄淇℃伅鎶�鏈湁闄愬叕鍙革紙https://www.jnpfsoft.com锛�
+ * @date 2021-03-23
+ */
+@Slf4j
+@Tag(name = "鍏叡", description = "file")
+@RestController
+@RequiredArgsConstructor
+public class UtilsController implements FileApi {
+
+
+ private final ConfigValueUtil configValueUtil;
+
+ private final RedisUtil redisUtil;
+
+ private final DictionaryDataApi dictionaryDataApi;
+
+ private final FileUploadApi fileUploadApi;
+
+ private final FileApi fileApi;
+
+ private final FileExport fileExport;
+
+ private final FileService fileService;
+
+
+
+ /**
+ * 鍥惧舰楠岃瘉鐮�
+ *
+ * @return
+ */
+ @NoDataSourceBind
+ @Operation(summary = "鍥惧舰楠岃瘉鐮�")
+ @GetMapping("/ImageCode/{timestamp}")
+ @Parameter(name = "timestamp", description = "鏃堕棿鎴�",required = true)
+ public void imageCode(@PathVariable("timestamp") String timestamp) {
+ DownUtil.downCode(null);
+ redisUtil.insert(timestamp, ServletUtil.getSession().getAttribute(CodeUtil.RANDOMCODEKEY), 120);
+ }
+
+ /**
+ * 涓婁紶鏂囦欢/鍥剧墖
+ *
+ * @return
+ */
+ @NoDataSourceBind
+ @Operation(summary = "涓婁紶鏂囦欢/鍥剧墖")
+ @PostMapping(value = "/Uploader/{type}", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
+ @Parameter(name = "type", description = "绫诲瀷",required = true)
+ public ActionResult<UploaderVO> uploader(@PathVariable("type") String type, MergeChunkDto mergeChunkDto, MultipartFile file) {
+ mergeChunkDto.setType(type);
+ return ActionResult.success(fileService.uploadFile(mergeChunkDto, file));
+ }
+
+ /**
+ * 鍥剧墖杞垚base64
+ *
+ * @return
+ */
+ @NoDataSourceBind()
+ @Operation(summary = "鍥剧墖杞垚base64")
+ @PostMapping(value = "/Uploader/imgToBase64", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
+ public ActionResult<Object> imgToBase64(@RequestParam("file") MultipartFile file) throws IOException {
+ String encode = cn.hutool.core.codec.Base64.encode(file.getBytes());
+ Object base64Name = "";
+ if (StringUtil.isNotEmpty(encode)) {
+ base64Name = "data:image/jpeg;base64,"+encode;
+ }
+ return ActionResult.success(base64Name);
+ }
+
+ /**
+ * 鑾峰彇涓嬭浇鏂囦欢閾炬帴
+ *
+ * @return
+ */
+ @NoDataSourceBind
+ @Operation(summary = "鑾峰彇涓嬭浇鏂囦欢閾炬帴")
+ @GetMapping("/Download/{type}/{fileName}")
+ @Parameter(name = "type", description = "绫诲瀷",required = true)
+ @Parameter(name = "fileName", description = "鏂囦欢鍚嶇О",required = true)
+ public ActionResult<Object> downloadUrl(@PathVariable("type") String type, @PathVariable("fileName") String fileName) {
+ boolean exists = FileUploadUtils.exists(new FileParameter(type, fileName));
+ if (exists) {
+ jnpf.base.vo.DownloadVO vo = DownloadVO.builder().name(fileName).url(UploaderUtil.uploaderFile(fileName + "#" + type)).build();
+ return ActionResult.success(vo);
+ }
+ return ActionResult.fail(MsgCode.FA018.get());
+ }
+
+ /**
+ * 鑾峰彇鍏ㄩ儴涓嬭浇鏂囦欢閾炬帴锛堟墦鍖呬笅杞斤級
+ *
+ * @return
+ */
+ @NoDataSourceBind
+ @Operation(summary = "鑾峰彇鍏ㄩ儴涓嬭浇鏂囦欢閾炬帴锛堟墦鍖呬笅杞斤級")
+ @PostMapping("/PackDownload/{type}")
+ @Parameter(name = "type", description = "绫诲瀷",required = true)
+ public ActionResult packDownloadUrl(@PathVariable("type") String type, @RequestBody List<Map<String, String>> fileInfoList) throws Exception {
+ if (fileInfoList == null || fileInfoList.isEmpty()) {
+ return ActionResult.fail(MsgCode.FA047.get());
+ }
+
+ StringBuilder zipTempFilePath = null;
+ String zipFileId = RandomUtil.uuId() + ".zip";
+ List<String> repeatName = new ArrayList<>();
+ for (Map<String, String> fileInfoMap : fileInfoList) {
+ String fileId = XSSEscape.escape( fileInfoMap.get("fileId")).trim();
+ String fileName = XSSEscape.escape( fileInfoMap.get("fileName")).trim();
+ if (repeatName.contains(fileName)) {
+ fileName = fileName.substring(0, fileName.lastIndexOf(".")) + "鍓湰" + UUID.randomUUID().toString().substring(0, 5) + fileName.substring(fileName.lastIndexOf("."));
+ } else {
+ repeatName.add(fileName);
+ }
+ if (StringUtil.isEmpty(fileId) || StringUtil.isEmpty(fileName)) {
+ continue;
+ }
+ FileParameter fileParameter = new FileParameter(type, fileId);
+ if (FileUploadUtils.exists(fileParameter)) {
+ if (zipTempFilePath == null) {
+ zipTempFilePath = new StringBuilder(FileUploadUtils.getLocalBasePath() + FilePathUtil.getFilePath(FileTypeConstant.FILEZIPDOWNTEMPPATH));
+ if (!new File(zipTempFilePath.toString()).exists()) {
+ new File(zipTempFilePath.toString()).mkdirs();
+ }
+ zipTempFilePath.append(zipFileId);
+ }
+ String finalZipTempFilePath = String.valueOf(zipTempFilePath);
+ String finalFileName = fileName;
+ FileUploadUtils.downloadFile(fileParameter, inputStream -> {
+ try {
+ ZipUtil.fileAddToZip(finalZipTempFilePath, inputStream, finalFileName);
+ } catch (Exception e) {
+ throw new IllegalArgumentException(e);
+ }
+ });
+ }
+ }
+ //灏嗘枃浠朵笂浼犲埌榛樿鏂囦欢鏈嶅姟鍣�
+ String newFileId = zipFileId;
+ if (!"local".equals(FileUploadUtils.getDefaultPlatform())) { //涓嶆槸鏈湴锛岃鏄庢槸鍏朵粬鏂囦欢鏈嶅姟鍣紝灏唞ip鏂囦欢涓婁紶鍒板叾浠栨湇鍔″櫒閲岋紝鏂逛究涓嬭浇
+ File zipFile = new File(String.valueOf(zipTempFilePath));
+ FileInfo fileInfo = FileUploadUtils.uploadFile(new FileParameter(FilePathUtil.getFilePath(FileTypeConstant.FILEZIPDOWNTEMPPATH), zipFileId), zipFile);
+ Files.delete(zipFile.toPath());
+ FileUtils.deleteQuietly(zipFile);
+ newFileId = fileInfo.getFilename();
+ }
+ jnpf.base.vo.DownloadVO vo = DownloadVO.builder().name(zipFileId).url(UploaderUtil.uploaderFile(newFileId + "#" + FileTypeConstant.FILEZIPDOWNTEMPPATH)).build();
+ Map<String, Object> map = new HashMap<>();
+ map.put("downloadVo", vo);
+ map.put("downloadName", "鏂囦欢" + zipFileId);
+ return ActionResult.success(map);
+ }
+
+ /**
+ * 涓嬭浇鏂囦欢閾炬帴
+ *
+ * @return
+ */
+ @NoDataSourceBind
+ @Operation(summary = "涓嬭浇鏂囦欢閾炬帴")
+ @GetMapping("/Download")
+ public void downloadFile(@RequestParam("encryption") String encryption, @RequestParam("name") String downName) throws DataException {
+ fileService.downloadFile(encryption, downName);
+ }
+
+
+
+
+ /**
+ * 鑾峰彇鍥剧墖
+ *
+ * @param fileName
+ * @param type
+ * @return
+ */
+ @NoDataSourceBind
+ @Operation(summary = "鑾峰彇鍥剧墖")
+ @GetMapping("/Image/{type}/{fileName}")
+ @Parameter(name = "type", description = "绫诲瀷",required = true)
+ @Parameter(name = "fileName", description = "鍚嶇О",required = true)
+ public void downLoadImg(@PathVariable("type") String type, @PathVariable("fileName") String fileName, @RequestParam(name = "s", required = false) String securityKey, @RequestParam(name = "t", required = false) String t) throws DataException {
+ fileService.flushFile(type, fileName, securityKey, StringUtil.isEmpty(t));
+ }
+
+
+
+
+ /**
+ * app鍚姩鑾峰彇淇℃伅
+ *
+ * @param appName
+ * @return
+ */
+ @NoDataSourceBind
+ @Operation(summary = "app鍚姩鑾峰彇淇℃伅")
+ @GetMapping("/AppStartInfo/{appName}")
+ @Parameter(name = "appName", description = "鍚嶇О",required = true)
+ public ActionResult<Object> getAppStartInfo(@PathVariable("appName") String appName) {
+ JSONObject object = new JSONObject();
+ object.put("AppVersion", configValueUtil.getAppVersion());
+ object.put("AppUpdateContent", configValueUtil.getAppUpdateContent());
+ return ActionResult.success(object);
+ }
+
+ /**
+ * 澶у睆鍥剧墖涓嬭浇
+ *
+ * @param type
+ * @param fileName
+ */
+ @NoDataSourceBind
+ @Operation(summary = "鑾峰彇鍥剧墖")
+ @GetMapping("/VisusalImg/{bivisualpath}/{type}/{fileName}")
+ @Parameter(name = "type", description = "绫诲瀷",required = true)
+ @Parameter(name = "bivisualpath", description = "璺緞",required = true)
+ @Parameter(name = "fileName", description = "鍚嶇О",required = true)
+ public void downVisusalImg(@PathVariable("type") String type,@PathVariable("bivisualpath") String bivisualpath, @PathVariable("fileName") String fileName) {
+ fileName = XSSEscape.escapePath(fileName);
+ type = XSSEscape.escapePath(type);
+ String filePath = getPath(FileTypeConstant.BIVISUALPATH);
+ String finalFileName = fileName;
+ FileUploadUtils.downloadFile(new FileParameter(filePath + type + File.separator, fileName), inputStream ->
+ FileDownloadUtil.flushFile(inputStream, finalFileName)
+ );
+ }
+
+ @Operation(summary = "鍒嗙墖涓婁紶鑾峰彇")
+ @GetMapping("/chunk")
+ public ActionResult<ChunkRes> checkChunk(Chunk chunk) {
+ return ActionResult.success(fileService.checkChunk(chunk));
+ }
+
+
+ @Operation(summary = "鍒嗙墖涓婁紶闄勪欢")
+ @PostMapping("/chunk")
+ public ActionResult<ChunkRes> upload(Chunk chunk, MultipartFile file) {
+ return ActionResult.success(fileService.uploadChunk(chunk, file));
+ }
+
+ @Operation(summary = "鍒嗙墖缁勮")
+ @PostMapping("/merge")
+ public ActionResult<UploaderVO> merge(MergeChunkDto mergeChunkDto) {
+ return ActionResult.success(fileService.mergeChunk(mergeChunkDto));
+ }
+
+ //----------------------
+
+ /**
+ * 閫氳繃type鑾峰彇璺緞
+ *
+ * @param type 绫诲瀷
+ * @return
+ */
+ @Override
+ @NoDataSourceBind()
+ @GetMapping("/getPath/{type}")
+ public String getPath(@PathVariable("type") String type) {
+ return fileService.getPath(type);
+ }
+
+ /**
+ * 瀵煎嚭
+ *
+ * @param exportModel
+ * @return
+ */
+ @Override
+ @NoDataSourceBind
+ @PostMapping("/export")
+ public jnpf.base.vo.DownloadVO exportFile(@RequestBody ExportModel exportModel) {
+ return fileExport.exportFile(exportModel.getClazz(), exportModel.getFilePath(), exportModel.getFileName(), exportModel.getTableName());
+ }
+
+ /**
+ * 鑾峰彇浠g爜鐢熸垚鍣ㄩ粯璁や繚瀛樿矾寰�
+ *
+ * @return
+ */
+ @Override
+ @NoDataSourceBind()
+ @GetMapping("/getLocalBasePath")
+ public String getLocalBasePath() {
+ return fileService.getLocalBasePath();
+ }
+
+
+
+ /**
+ * 鑾峰彇鍏佽鏂囦欢棰勮绫诲瀷
+ *
+ * @return
+ */
+ @Override
+ @NoDataSourceBind()
+ @GetMapping("/getAllowPreviewFileType")
+ public String getAllowPreviewFileType() {
+ return configValueUtil.getAllowPreviewFileType();
+ }
+
+ @Override
+ @NoDataSourceBind()
+ @GetMapping("/fileExists")
+ public Boolean fileExists(@RequestParam("type") String path, @RequestParam("fileName") String fileName) {
+ return fileService.fileExists(path, fileName);
+ }
+
+ @Operation(summary = "棰勮鏂囦欢")
+ @GetMapping("/Uploader/Preview")
+ public ActionResult<Object> preview(PreviewParams previewParams) {
+ return ActionResult.success(MsgCode.SU000.get(), fileService.previewFile(previewParams));
+ }
+
+}
--
Gitblit v1.8.0