zhs hace 2 años
padre
commit
65a1ce8dfb

+ 63 - 0
src/main/java/com/tld/controller/UploadController.java

@@ -0,0 +1,63 @@
+package com.tld.controller;
+
+import com.tld.util.PassToken;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.*;
+
+@RestController
+@RequestMapping("upload")
+public class UploadController {
+
+    @GetMapping("downloadFile")
+    @PassToken
+    public String downloadFile(HttpServletRequest request, HttpServletResponse response) {
+        String fileName = "tld-consumer-9560.jar";// 设置文件名,根据业务需要替换成要下载的文件名
+        if (fileName != null) {
+            //设置文件路径
+            String realPath = "D:\\project\\tld-consumer-9560\\build\\libs";
+            File file = new File(realPath , fileName);
+            if (file.exists()) {
+                response.setContentType("application/octet-stream");//
+                response.setHeader("content-type", "application/octet-stream");
+                response.setHeader("Content-Disposition", "attachment;fileName=" + fileName);// 设置文件名
+                byte[] buffer = new byte[1024];
+                FileInputStream fis = null;
+                BufferedInputStream bis = null;
+                try {
+                    fis = new FileInputStream(file);
+                    bis = new BufferedInputStream(fis);
+                    OutputStream os = response.getOutputStream();
+                    int i = bis.read(buffer);
+                    while (i != -1) {
+                        os.write(buffer, 0, i);
+                        i = bis.read(buffer);
+                    }
+                    System.out.println("success");
+                } catch (Exception e) {
+                    e.printStackTrace();
+                } finally {
+                    if (bis != null) {
+                        try {
+                            bis.close();
+                        } catch (IOException e) {
+                            e.printStackTrace();
+                        }
+                    }
+                    if (fis != null) {
+                        try {
+                            fis.close();
+                        } catch (IOException e) {
+                            e.printStackTrace();
+                        }
+                    }
+                }
+            }
+        }
+        return null;
+    }
+}

+ 15 - 0
src/main/java/com/tld/util/LinuxUtil.java

@@ -0,0 +1,15 @@
+package com.tld.util;
+
+public class LinuxUtil {
+    /**
+     * linux将磁盘转换成本地路径
+     * @param path
+     * @return
+     */
+    public static String isLinux(String path) {
+        if(System.getProperty("os.name").toLowerCase().indexOf("linux") >= 0) {
+            path = path.replaceAll("D:", "/usr/local").replaceAll("//","/").replaceAll("\\\\\\\\", "/").replaceAll("\\\\", "/");
+        }
+        return path;
+    }
+}

+ 3 - 0
src/main/resources/mapper/QueryListMappeer.xml

@@ -56,6 +56,9 @@
             a.storage_location_code as storageLocationCode,
             a.material_id as materialId,
             sum( a.amount ) AS sum,
+            a.serial,
+            a.produc_batch as producBatch,
+            a.supplier_id as supplierId,
             b.storage_location_name as storageLocationName ,
             b.warehouse_where as warehouseWhere,
             b.storage_location_type as storageLocationType,