licailing %!s(int64=5) %!d(string=hai) anos
pai
achega
43f1cfb5b1

+ 29 - 9
src/main/java/com/izouma/imt/service/InformationService.java

@@ -4,6 +4,7 @@ import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.util.ObjectUtil;
 import cn.hutool.core.util.StrUtil;
+import com.github.kevinsawicki.http.HttpRequest;
 import com.izouma.imt.domain.Email;
 import com.izouma.imt.domain.Information;
 import com.izouma.imt.domain.SearchRecord;
@@ -31,6 +32,7 @@ import org.springframework.data.domain.PageRequest;
 import org.springframework.stereotype.Service;
 
 import javax.persistence.criteria.Predicate;
+import java.io.File;
 import java.io.IOException;
 import java.time.LocalDateTime;
 import java.util.*;
@@ -158,25 +160,43 @@ public class InformationService {
             dto.setStatus(information.getStatus().getDesc());
             dto.setType(information.getType().getDesc());
             dto.setSession(information.getSession().toString());
-            String file = "/platform/news";
+
+            dtos.add(dto);
+
+            String file = "news/platform";
             if (ObjectUtil.isNotEmpty(information.getVendorInfoId())) {
                 VendorInfo vendorInfo = vendorMap.get(information.getVendorInfoId());
-                if (ObjectUtil.isNotNull(vendorInfo)){
+                if (ObjectUtil.isNotNull(vendorInfo)) {
                     dto.setVendorName(vendorInfo.getChCompanyName());
-                    file = "/vendor/" + vendorInfo.getEnCompanyName() + "/news";
+                    file = "news/" + vendorInfo.getEnCompanyName();
                 }
             }
-            dtos.add(dto);
-            // 下载封面
-            try {
-                FileUtils.download(information.getImg(), file, information.getTitle());
-            } catch (IOException e) {
-                e.printStackTrace();
+
+            File dirfile = new File(file);
+            if (!dirfile.exists()) {
+                dirfile.mkdirs();
+            }
+            if (StrUtil.isNotBlank(information.getImg())) {
+                String title = information.getTitle();
+                if (title.contains("/")) {
+                    title = title.replaceAll("/", "-");
+                }
+                HttpRequest.get(information.getImg())
+                        .receive(new File(dirfile + "/" + title + this.getSuffix(information.getImg())));
             }
         });
         return dtos;
     }
 
+
+    /*
+    后缀
+    */
+    public String getSuffix(String name) {
+        int i = name.lastIndexOf(".");
+        return name.substring(i);
+    }
+
     public InformationDTO toDto(Information information) {
         InformationDTO dto = new InformationDTO();
         BeanUtil.copyProperties(information, dto);

+ 31 - 21
src/main/java/com/izouma/imt/service/vendor/ProductService.java

@@ -4,6 +4,7 @@ import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.util.ObjectUtil;
 import cn.hutool.core.util.StrUtil;
+import com.github.kevinsawicki.http.HttpRequest;
 import com.izouma.imt.converter.LongArrayConverter;
 import com.izouma.imt.converter.StringArrayConverter;
 import com.izouma.imt.domain.*;
@@ -45,6 +46,7 @@ import javax.persistence.criteria.CriteriaBuilder;
 import javax.persistence.criteria.Expression;
 import javax.persistence.criteria.Predicate;
 import javax.persistence.criteria.Root;
+import java.io.File;
 import java.io.IOException;
 import java.time.LocalDateTime;
 import java.util.*;
@@ -358,36 +360,44 @@ public class ProductService {
             }
             vos.add(vo);
 
-            /*if (download) {
-                String file = "product/" + product.getEnBrand() + "-" + product.getEnName();
-                if (CollUtil.isNotEmpty(product.getPdf1())){
-                    product.getPdf1().forEach(pdf -> {
-                        try {
-                            FileUtils.download(pdf.getUrl(), file, pdf.getName());
-                        } catch (IOException e) {
-                            e.printStackTrace();
-                        }
-                    });
+            if (download) {
+                String enName = product.getEnName();
+                if (enName.contains("/")) {
+                    enName = enName.replaceAll("/", "-");
+                }
+                String file = "product/" + product.getEnBrand() + "-" + enName;
+                File dirfile = new File(file);
+                if (!dirfile.exists()) {
+                    dirfile.mkdirs();
+                }
+                if (CollUtil.isNotEmpty(product.getPdf1())) {
+                    product.getPdf1().forEach(pdf -> HttpRequest.get(pdf.getUrl())
+                            .receive(new File(dirfile + "/" + pdf.getName())));
                 }
                 String[] split = product.getImg().split(",");
                 for (int i = 1; i <= split.length; i++) {
-                    try {
-                        FileUtils.download(split[i - 1], file, "img" + i);
-                    } catch (IOException e) {
-                        e.printStackTrace();
-                    }
-                }
-                try {
-                    FileUtils.download(product.getVideo(), file, "video");
-                } catch (IOException e) {
-                    e.printStackTrace();
+                    HttpRequest.get(split[i - 1])
+                            .receive(new File(dirfile + "/img" + i + this.getSuffix(split[i - 1])));
                 }
 
-            }*/
+//                if (StrUtil.isNotBlank(product.getVideo())) {
+//                    HttpRequest.get(product.getVideo())
+//                            .receive(new File(dirfile + "/video" + this.getSuffix(product.getVideo())));
+//                }
+
+            }
         });
         return vos;
     }
 
+    /*
+    后缀
+    */
+    public String getSuffix(String name) {
+        int i = name.lastIndexOf(".");
+        return name.substring(i);
+    }
+
     /*
     筛选
      */

+ 29 - 2
src/main/java/com/izouma/imt/web/InformationController.java

@@ -1,6 +1,7 @@
 package com.izouma.imt.web;
 
 import cn.hutool.core.util.ObjectUtil;
+import cn.hutool.core.util.ZipUtil;
 import com.izouma.imt.domain.Information;
 import com.izouma.imt.domain.vendor.Operating;
 import com.izouma.imt.dto.InformationDTO;
@@ -22,7 +23,10 @@ import org.springframework.web.bind.annotation.*;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
+import java.io.File;
+import java.io.FileInputStream;
 import java.io.IOException;
+import java.io.OutputStream;
 import java.time.LocalDateTime;
 import java.util.List;
 import java.util.Map;
@@ -111,11 +115,34 @@ public class InformationController extends BaseController {
         informationRepo.softDelete(id);
     }
 
-    @GetMapping("/excel")
+    @GetMapping(value = "/excel", produces = "application/zip;charset=utf-8")
     @ResponseBody
     public void excel(HttpServletResponse response, PageQuery pageQuery) throws IOException {
         List<InformationDTO> data = informationService.toDtoList(all(pageQuery).getContent());
-        ExcelUtils.export(response, data);
+//        ExcelUtils.export(response, data);
+        ExcelUtils.export1(data, "news/");
+        File news = ZipUtil.zip(new File("news"));
+
+        //响应头的设置
+        response.setCharacterEncoding("utf-8");
+        response.setContentType("application/zip");
+
+        //设置压缩包的名字
+        //解决不同浏览器压缩包名字含有中文时乱码的问题
+        String downloadName = "news.zip";
+        response.setHeader("Content-Disposition", "attachment;fileName=\"" + downloadName + "\"");
+
+        FileInputStream fis = new FileInputStream(news);
+        OutputStream os = response.getOutputStream();
+        int readBytes;
+        while ((readBytes = fis.read()) != -1) {
+            os.write(readBytes);
+        }
+
+        os.flush();
+        os.close();
+        fis.close();
+
     }
 
     @GetMapping("/home")

+ 31 - 2
src/main/java/com/izouma/imt/web/vendor/ProductController.java

@@ -1,6 +1,7 @@
 package com.izouma.imt.web.vendor;
 
 import cn.hutool.core.util.StrUtil;
+import cn.hutool.core.util.ZipUtil;
 import com.izouma.imt.converter.StringArrayConverter;
 import com.izouma.imt.domain.ProductCategory;
 import com.izouma.imt.domain.vendor.Operating;
@@ -30,7 +31,10 @@ import org.springframework.web.bind.annotation.*;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
+import java.io.File;
+import java.io.FileInputStream;
 import java.io.IOException;
+import java.io.OutputStream;
 import java.time.LocalDateTime;
 import java.util.List;
 import java.util.Map;
@@ -160,11 +164,36 @@ public class ProductController extends BaseController {
         vendorInfoRepo.subQuantity(product.getVendorInfoId());
     }
 
-    @GetMapping("/excel")
+    @GetMapping(value = "/excel", produces = "application/octet-stream;charset=utf-8")
     @ResponseBody
     public void excel(HttpServletResponse response, PageQuery pageQuery) throws IOException {
         List<ProductVO> data = productService.backAll(pageQuery, null, null, null, true).getContent();
-        ExcelUtils.export(response, data);
+//        ExcelUtils.export(response, data);
+        ExcelUtils.export1(data,"product/");
+        File product = ZipUtil.zip(new File("product"));
+
+        //响应头的设置
+        response.setCharacterEncoding("utf-8");
+        response.setContentType("application/octet-stream");
+
+
+        //设置压缩包的名字
+        //解决不同浏览器压缩包名字含有中文时乱码的问题
+        String downloadName = "product.zip";
+        response.addHeader("Content-Disposition", "attachment;fileName=\"" + downloadName + "\"");
+        response.addHeader("Content-Length", "" + product.length());
+        FileInputStream fis = new FileInputStream(product);
+        OutputStream os = response.getOutputStream();
+        byte[] buffer = new byte[1024];
+        int i;
+        while ((i = fis.read(buffer)) != -1) {
+            os.write(buffer, 0, i);
+
+        }
+
+        os.flush();
+        os.close();
+        fis.close();
     }
 
     @GetMapping("/hotProducts")

+ 0 - 1
src/main/java/com/izouma/imt/web/vendor/VendorInfoController.java

@@ -86,7 +86,6 @@ public class VendorInfoController extends BaseController {
         File vendor = ZipUtil.zip(new File("vendor"));
 
         //响应头的设置
-//        response.reset();
         response.setCharacterEncoding("utf-8");
         response.setContentType("application/zip");
 

+ 2 - 1
src/main/vue/src/views/InformationList.vue

@@ -246,7 +246,8 @@ export default {
                     const downloadUrl = window.URL.createObjectURL(new Blob([res.data]));
                     const link = document.createElement('a');
                     link.href = downloadUrl;
-                    link.setAttribute('download', res.headers['content-disposition'].split('filename=')[1]);
+                    link.setAttribute('download', 'news.zip');
+                    // link.setAttribute('download', res.headers['content-disposition'].split('filename=')[1]);
                     document.body.appendChild(link);
                     link.click();
                     link.remove();

+ 2 - 1
src/main/vue/src/views/InformationList2.vue

@@ -224,7 +224,8 @@ export default {
                     const downloadUrl = window.URL.createObjectURL(new Blob([res.data]));
                     const link = document.createElement('a');
                     link.href = downloadUrl;
-                    link.setAttribute('download', res.headers['content-disposition'].split('filename=')[1]);
+                    link.setAttribute('download', 'news.zip');
+                    // link.setAttribute('download', res.headers['content-disposition'].split('filename=')[1]);
                     document.body.appendChild(link);
                     link.click();
                     link.remove();

+ 2 - 1
src/main/vue/src/views/InformationList3.vue

@@ -197,7 +197,8 @@ export default {
                     const downloadUrl = window.URL.createObjectURL(new Blob([res.data]));
                     const link = document.createElement('a');
                     link.href = downloadUrl;
-                    link.setAttribute('download', res.headers['content-disposition'].split('filename=')[1]);
+                    link.setAttribute('download', 'news.zip');
+                    // link.setAttribute('download', res.headers['content-disposition'].split('filename=')[1]);
                     document.body.appendChild(link);
                     link.click();
                     link.remove();

+ 2 - 1
src/main/vue/src/views/product/ProductList.vue

@@ -270,7 +270,8 @@ export default {
                     const downloadUrl = window.URL.createObjectURL(new Blob([res.data]));
                     const link = document.createElement('a');
                     link.href = downloadUrl;
-                    link.setAttribute('download', res.headers['content-disposition'].split('filename=')[1]);
+                    // link.setAttribute('download', res.headers['content-disposition'].split('filename=')[1]);
+                    link.setAttribute('download', 'product.zip');
                     document.body.appendChild(link);
                     link.click();
                     link.remove();

+ 2 - 1
src/main/vue/src/views/product/ProductList2.vue

@@ -244,7 +244,8 @@ export default {
                     const downloadUrl = window.URL.createObjectURL(new Blob([res.data]));
                     const link = document.createElement('a');
                     link.href = downloadUrl;
-                    link.setAttribute('download', res.headers['content-disposition'].split('filename=')[1]);
+                    // link.setAttribute('download', res.headers['content-disposition'].split('filename=')[1]);
+                    link.setAttribute('download', 'product.zip');
                     document.body.appendChild(link);
                     link.click();
                     link.remove();

+ 2 - 1
src/main/vue/src/views/product/ProductList3.vue

@@ -236,7 +236,8 @@ export default {
                     const downloadUrl = window.URL.createObjectURL(new Blob([res.data]));
                     const link = document.createElement('a');
                     link.href = downloadUrl;
-                    link.setAttribute('download', res.headers['content-disposition'].split('filename=')[1]);
+                    link.setAttribute('download', 'product.zip');
+                    // link.setAttribute('download', res.headers['content-disposition'].split('filename=')[1]);
                     document.body.appendChild(link);
                     link.click();
                     link.remove();