From 4f3a98f19143865cdc1de4791e8a95d96bd40c65 Mon Sep 17 00:00:00 2001
From: maven <2163098428@qq.com>
Date: 星期五, 01 八月 2025 13:27:59 +0800
Subject: [PATCH] yys 密码已重置

---
 inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsUnqualifiedHandlerFileServiceImpl.java |  111 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 111 insertions(+), 0 deletions(-)

diff --git a/inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsUnqualifiedHandlerFileServiceImpl.java b/inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsUnqualifiedHandlerFileServiceImpl.java
new file mode 100644
index 0000000..28236fa
--- /dev/null
+++ b/inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsUnqualifiedHandlerFileServiceImpl.java
@@ -0,0 +1,111 @@
+package com.ruoyi.inspect.service.impl;
+
+import cn.hutool.core.io.IoUtil;
+import cn.hutool.core.lang.UUID;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ruoyi.framework.exception.ErrorException;
+import com.ruoyi.inspect.mapper.InsUnqualifiedHandlerFileMapper;
+import com.ruoyi.inspect.pojo.InsUnqualifiedHandlerFile;
+import com.ruoyi.inspect.service.InsUnqualifiedHandlerFileService;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Service;
+import org.springframework.web.multipart.MultipartFile;
+
+import javax.servlet.http.HttpServletResponse;
+import java.io.File;
+import java.io.IOException;
+import java.net.URLEncoder;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+
+/**
+* @author 27233
+* @description 閽堝琛ㄣ�恑ns_unqualified_handler_file(涓嶅悎鏍煎鐞嗛檮浠惰褰曡〃)銆戠殑鏁版嵁搴撴搷浣淪ervice瀹炵幇
+* @createDate 2024-07-31 13:38:38
+*/
+@Service
+@Slf4j
+public class InsUnqualifiedHandlerFileServiceImpl extends ServiceImpl<InsUnqualifiedHandlerFileMapper, InsUnqualifiedHandlerFile>
+    implements InsUnqualifiedHandlerFileService {
+
+    @Value("${wordUrl}")
+    private String wordUrl;
+
+    @Value("${file.path}")
+    private String imgUrl;
+
+    @Override
+    public InsUnqualifiedHandlerFile uploadFile(Long handlerId, MultipartFile file) {
+        String urlString;
+        String pathName;
+        String path;
+        String prefix;
+        String filename = file.getOriginalFilename();
+        String contentType = file.getContentType();
+        InsUnqualifiedHandlerFile unqualifiedHandlerFile = new InsUnqualifiedHandlerFile();
+//        unqualifiedHandlerFile.setUnqualifiedId(handlerId);
+        unqualifiedHandlerFile.setFileName(filename);
+        if (contentType != null && contentType.startsWith("image/")) {
+            // 鏄浘鐗�
+            path = imgUrl;
+            prefix = "/image/";
+            unqualifiedHandlerFile.setType(1);
+        } else {
+            // 鏄枃浠�
+            path = wordUrl;
+            prefix = "/word/";
+            unqualifiedHandlerFile.setType(2);
+        }
+        try {
+            File realpath = new File(path);
+            if (!realpath.exists()) {
+                realpath.mkdirs();
+            }
+            pathName = UUID.randomUUID() + "_" + file.getOriginalFilename();
+            urlString = realpath + "/" + pathName;
+            file.transferTo(new File(urlString));
+            unqualifiedHandlerFile.setFileUrl(pathName);
+            baseMapper.insert(unqualifiedHandlerFile);
+            return unqualifiedHandlerFile;
+        } catch (Exception e) {
+            e.printStackTrace();
+            log.error("闄勪欢涓婁紶閿欒");
+            throw new ErrorException(e.getMessage());
+        }
+    }
+
+    @Override
+    public void downloadOAFile(Long handlerFileId, HttpServletResponse response) {
+        response.reset();
+        String fileName;
+        try {
+            //鏌ヨ涓婁紶闄勪欢璁板綍
+            InsUnqualifiedHandlerFile file = baseMapper.selectById(handlerFileId);
+            if (file != null){
+                fileName = file.getFileName();
+                fileName =  URLEncoder.encode(fileName, StandardCharsets.UTF_8.toString());
+                response.setContentType("application/vnd.ms-excel");
+                response.setHeader("Cache-Control", "no-cache");
+                response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
+                response.setHeader("Access-Control-Expose-Headers", "Content-Disposition");
+                //鑾峰彇鏂囦欢澶硅矾寰�
+                String path = file.getType()==1?imgUrl:wordUrl;
+                //鏂囦欢瀹屾暣璺緞
+                String fullPath = path + file.getFileUrl();
+                //鍒ゆ柇鏂囦欢鏄惁瀛樺湪
+                File fullFile = new File(fullPath);
+                if(fullFile.exists()){
+                    IoUtil.copy(Files.newInputStream(fullFile.toPath()),response.getOutputStream());
+                }
+            }
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+}
+
+
+
+

--
Gitblit v1.9.3