|
@@ -1,14 +1,19 @@
|
|
|
package com.izouma.imt.service.vendor;
|
|
package com.izouma.imt.service.vendor;
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
|
|
+import cn.hutool.core.util.ZipUtil;
|
|
|
|
|
+import com.github.kevinsawicki.http.HttpRequest;
|
|
|
import com.izouma.imt.domain.vendor.VendorInfo;
|
|
import com.izouma.imt.domain.vendor.VendorInfo;
|
|
|
import com.izouma.imt.dto.InfoVO;
|
|
import com.izouma.imt.dto.InfoVO;
|
|
|
import com.izouma.imt.dto.PageQuery;
|
|
import com.izouma.imt.dto.PageQuery;
|
|
|
import com.izouma.imt.dto.VendorDTO;
|
|
import com.izouma.imt.dto.VendorDTO;
|
|
|
|
|
+import com.izouma.imt.dto.excel.VendorInfoVO;
|
|
|
import com.izouma.imt.enums.VendorSort;
|
|
import com.izouma.imt.enums.VendorSort;
|
|
|
|
|
+import com.izouma.imt.exception.BusinessException;
|
|
|
import com.izouma.imt.repo.vendor.VendorInfoRepo;
|
|
import com.izouma.imt.repo.vendor.VendorInfoRepo;
|
|
|
import com.izouma.imt.service.ProductCategoryService;
|
|
import com.izouma.imt.service.ProductCategoryService;
|
|
|
import com.izouma.imt.service.buyers.BuyersInfoService;
|
|
import com.izouma.imt.service.buyers.BuyersInfoService;
|
|
|
|
|
+import com.izouma.imt.utils.excel.ExcelUtils;
|
|
|
import org.apache.commons.io.FileUtils;
|
|
import org.apache.commons.io.FileUtils;
|
|
|
import org.junit.Test;
|
|
import org.junit.Test;
|
|
|
import org.junit.runner.RunWith;
|
|
import org.junit.runner.RunWith;
|
|
@@ -17,12 +22,16 @@ import org.springframework.boot.test.context.SpringBootTest;
|
|
|
import org.springframework.data.domain.Page;
|
|
import org.springframework.data.domain.Page;
|
|
|
import org.springframework.test.context.junit4.SpringRunner;
|
|
import org.springframework.test.context.junit4.SpringRunner;
|
|
|
|
|
|
|
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
import java.io.*;
|
|
import java.io.*;
|
|
|
import java.net.HttpURLConnection;
|
|
import java.net.HttpURLConnection;
|
|
|
import java.net.MalformedURLException;
|
|
import java.net.MalformedURLException;
|
|
|
import java.net.URL;
|
|
import java.net.URL;
|
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
|
+import java.util.zip.ZipEntry;
|
|
|
|
|
+import java.util.zip.ZipOutputStream;
|
|
|
|
|
|
|
|
@SpringBootTest
|
|
@SpringBootTest
|
|
|
@RunWith(SpringRunner.class)
|
|
@RunWith(SpringRunner.class)
|
|
@@ -153,13 +162,102 @@ public class VendorInfoServiceTest {
|
|
|
String urlStr = "https://imttech.oss-cn-hangzhou.aliyuncs.com/image/avatar/2021-01-20-22-59-11wMmjdDcp.jpg";
|
|
String urlStr = "https://imttech.oss-cn-hangzhou.aliyuncs.com/image/avatar/2021-01-20-22-59-11wMmjdDcp.jpg";
|
|
|
try {
|
|
try {
|
|
|
URL httpurl = new URL(urlStr);
|
|
URL httpurl = new URL(urlStr);
|
|
|
- File dirfile = new File("vendor");
|
|
|
|
|
- if (!dirfile.exists()) {
|
|
|
|
|
- dirfile.mkdirs();
|
|
|
|
|
|
|
+// File dirfile = new File("vendor");
|
|
|
|
|
+// if (!dirfile.exists()) {
|
|
|
|
|
+// dirfile.mkdirs();
|
|
|
|
|
+// }
|
|
|
|
|
+ FileUtils.copyURLToFile(httpurl, new File("/Users/qiufangchao/Desktop/123" + com.izouma.imt.utils.FileUtils.getFileNameFromUrl(urlStr)));
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Test
|
|
|
|
|
+ public void test12() {
|
|
|
|
|
+ VendorInfo vendorInfo = vendorInfoRepo.findById(27804L).orElseThrow(new BusinessException("wu"));
|
|
|
|
|
+ String logo = vendorInfo.getLogo();
|
|
|
|
|
+ int i = logo.lastIndexOf(".");
|
|
|
|
|
+ String suffer = logo.substring(i);
|
|
|
|
|
+ System.out.println(suffer);
|
|
|
|
|
+ HttpRequest.get("https://imttech.oss-cn-hangzhou.aliyuncs.com/image/avatar/2021-01-20-22-59-11wMmjdDcp.jpg")
|
|
|
|
|
+ .receive(new File("/Users/qiufangchao/Desktop/vendor/logo.jpg"));
|
|
|
|
|
+ HttpRequest.get(vendorInfo.getLogo())
|
|
|
|
|
+ .receive(new File("/Users/qiufangchao/Desktop/vendor/logo/logo1" + suffer));
|
|
|
|
|
+
|
|
|
|
|
+ ZipUtil.zip(new File("/Users/qiufangchao/Desktop/vendor"));
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /* @Test
|
|
|
|
|
+ public void test13(HttpServletResponse response, HttpServletRequest request){
|
|
|
|
|
+ //响应头的设置
|
|
|
|
|
+ response.reset();
|
|
|
|
|
+ response.setCharacterEncoding("utf-8");
|
|
|
|
|
+ response.setContentType("multipart/form-data");
|
|
|
|
|
+
|
|
|
|
|
+ //设置压缩包的名字
|
|
|
|
|
+ //解决不同浏览器压缩包名字含有中文时乱码的问题
|
|
|
|
|
+ String downloadName = "我是压缩包的名字.zip";
|
|
|
|
|
+ String agent = request.getHeader("USER-AGENT");
|
|
|
|
|
+ try {
|
|
|
|
|
+ if (agent.contains("MSIE")||agent.contains("Trident")) {
|
|
|
|
|
+ downloadName = java.net.URLEncoder.encode(downloadName, "UTF-8");
|
|
|
|
|
+ } else {
|
|
|
|
|
+ downloadName = new String(downloadName.getBytes("UTF-8"),"ISO-8859-1");
|
|
|
}
|
|
}
|
|
|
- FileUtils.copyURLToFile(httpurl, new File("vendor/123" + com.izouma.imt.utils.FileUtils.getFileNameFromUrl(urlStr)));
|
|
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
|
}
|
|
}
|
|
|
|
|
+ response.setHeader("Content-Disposition", "attachment;fileName=\"" + downloadName + "\"");
|
|
|
|
|
+
|
|
|
|
|
+ //设置压缩流:直接写入response,实现边压缩边下载
|
|
|
|
|
+ ZipOutputStream zipos = null;
|
|
|
|
|
+ try {
|
|
|
|
|
+ zipos = new ZipOutputStream(new BufferedOutputStream(response.getOutputStream()));
|
|
|
|
|
+ zipos.setMethod(ZipOutputStream.DEFLATED); //设置压缩方法
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //循环将文件写入压缩流
|
|
|
|
|
+ DataOutputStream os = null;
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ for(int i = 0; i < 10; i++ ){
|
|
|
|
|
+
|
|
|
|
|
+ File file = new File("要下载的某个文件的路径");
|
|
|
|
|
+ try {
|
|
|
|
|
+ //添加ZipEntry,并ZipEntry中写入文件流
|
|
|
|
|
+ //这里,加上i是防止要下载的文件有重名的导致下载失败
|
|
|
|
|
+ zipos.putNextEntry(new ZipEntry(i + "文件名字"));
|
|
|
|
|
+ os = new DataOutputStream(zipos);
|
|
|
|
|
+ InputStream is = new FileInputStream(file);
|
|
|
|
|
+ byte[] b = new byte[100];
|
|
|
|
|
+ int length = 0;
|
|
|
|
|
+ while((length = is.read(b))!= -1){
|
|
|
|
|
+ os.write(b, 0, length);
|
|
|
|
|
+ }
|
|
|
|
|
+ is.close();
|
|
|
|
|
+ zipos.closeEntry();
|
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //关闭流
|
|
|
|
|
+ try {
|
|
|
|
|
+ os.flush();
|
|
|
|
|
+ os.close();
|
|
|
|
|
+ zipos.close();
|
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+ }*/
|
|
|
|
|
+
|
|
|
|
|
+ @Test
|
|
|
|
|
+ public void test14() throws IOException {
|
|
|
|
|
+ List<VendorInfoVO> data = vendorInfoService.export();
|
|
|
|
|
+ ExcelUtils.export1(data,"vendor/");
|
|
|
|
|
+ ZipUtil.zip(new File("vendor"));
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|