guarantee-lsq 2 anni fa
parent
commit
6a558e1b1e

+ 38 - 2
platform-common/src/main/java/com/platform/common/util/FileUtils.java

@@ -1,7 +1,10 @@
 package com.platform.common.util;
 
-import java.io.File;
-import java.io.FileOutputStream;
+import com.platform.common.exception.DeniedException;
+import lombok.extern.slf4j.Slf4j;
+
+import javax.servlet.http.HttpServletResponse;
+import java.io.*;
 
 /**
  * @Description 获取spring的bean对象
@@ -9,6 +12,7 @@ import java.io.FileOutputStream;
  * @Date 2019-08-18
  * @Version Copyright (c) 2019,北京乾元坤和科技有限公司 All rights reserved.
  */
+@Slf4j
 public class FileUtils {
 
     /**
@@ -48,4 +52,36 @@ public class FileUtils {
         out.flush();
         out.close();
     }
+
+    public static HttpServletResponse downloadFile(String path, HttpServletResponse response){
+        try {
+            log.info("下载类型: " + path);
+            if(StringUtils.isEmpty(path)){
+                throw new DeniedException("下载地址为空。。。。。");
+            }
+            // path是指欲下载的文件的路径。
+            File file = new File(path);
+            // 取得文件名。
+            String filename = file.getName();
+            // 以流的形式下载文件。
+            InputStream fis = new BufferedInputStream(new FileInputStream(path));
+            byte[] buffer = new byte[fis.available()];
+            fis.read(buffer);
+            fis.close();
+            // 清空response
+            response.reset();
+            // 设置response的Header
+            response.addHeader("Content-Disposition", "attachment;filename=" + new String(filename.getBytes()));
+            response.addHeader("Content-Length", "" + file.length());
+            OutputStream toClient = new BufferedOutputStream(response.getOutputStream());
+            response.setContentType("application/octet-stream");
+            toClient.write(buffer);
+            toClient.flush();
+            toClient.close();
+            log.info("下载模板成功: " + path);
+        } catch (IOException ex) {
+            ex.printStackTrace();
+        }
+        return response;
+    }
 }

+ 2 - 0
platform-dao/src/main/java/com/platform/dao/vo/query/sparepartmanage/SparePartInfoVO.java

@@ -323,4 +323,6 @@ public class SparePartInfoVO extends BaseVO implements Serializable {
      * 备件下一次更换日期
      */
     private LocalDate changeDate;
+
+    private String producerName;
 }

+ 26 - 6
platform-rest/src/main/java/com/platform/rest/controller/excel/ExcelImportController.java

@@ -1,19 +1,20 @@
 package com.platform.rest.controller.excel;
 
-import cn.hutool.core.collection.CollectionUtil;
+import com.platform.common.util.FileUtils;
 import com.platform.common.util.R;
-import com.platform.dao.util.ExcelUtil;
-import com.platform.dao.vo.export.sb.ExportSbTypeVO;
 import com.platform.rest.log.annotation.SysLog;
-import com.platform.service.activiti.ActivitiAssignStrategy;
 import com.platform.service.excel.ExcelImportStrategy;
-import com.platform.service.sb.SbInfoService;
-import com.platform.service.sb.impl.SbInfoServiceImpl;
 import lombok.AllArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
+import org.springframework.util.ResourceUtils;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 
+import javax.servlet.http.HttpServletResponse;
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
 import java.util.List;
 import java.util.stream.Collectors;
 
@@ -52,4 +53,23 @@ public class ExcelImportController {
             return new R("导入失败");
         }
     }
+
+    /**
+     * 文件下载
+     */
+    @GetMapping("/download")
+    public void downloadExcel(@RequestParam("downloadType") Integer downloadType, HttpServletResponse response) {
+        File file1 = new File("./");
+        String filePath = file1.getAbsolutePath();
+        filePath = filePath.substring(0,filePath.length()-1);
+        switch (downloadType){
+            case 1 :
+                filePath += "/db/sparePartInfo.xls";
+                break;
+            case 2:
+                filePath += "/db/checkstandard.xls";
+                break;
+        }
+        FileUtils.downloadFile(filePath,response);
+    }
 }

+ 4 - 0
platform-service/src/main/java/com/platform/service/sqarepartmanage/impl/SparePartInfoServiceImpl.java

@@ -405,6 +405,10 @@ public class SparePartInfoServiceImpl extends BaseServiceImpl<SparePartInfoMappe
                         vo.setChildNo(type.getNo());
                     }
                 }
+                // 给供应商赋值
+                if(StringUtils.isNotBlank(vo.getProducerId())){
+                    vo.setProducerName(firmProducerMapper.selectNameById(vo.getProducerId()));
+                }
             }
             AbstractPageResultBean<SparePartInfo> pageInfo = new MyPage(list);
             return pageInfo;