|
@@ -0,0 +1,93 @@
|
|
|
|
+package com.jpsoft.smart;
|
|
|
|
+
|
|
|
|
+import com.jpsoft.smart.config.OSSConfig;
|
|
|
|
+import com.jpsoft.smart.modules.base.entity.EmployeeInfo;
|
|
|
|
+import com.jpsoft.smart.modules.base.service.EmployeeInfoService;
|
|
|
|
+import com.jpsoft.smart.modules.common.utils.OSSUtil;
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
|
+import org.junit.jupiter.api.Test;
|
|
|
|
+import org.junit.runner.RunWith;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.boot.test.context.SpringBootTest;
|
|
|
|
+import org.springframework.test.context.junit4.SpringRunner;
|
|
|
|
+
|
|
|
|
+import java.io.FileOutputStream;
|
|
|
|
+import java.io.InputStream;
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.HashMap;
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.Map;
|
|
|
|
+
|
|
|
|
+@RunWith(SpringRunner.class)
|
|
|
|
+@SpringBootTest
|
|
|
|
+public class EmployeeTest {
|
|
|
|
+ @Autowired
|
|
|
|
+ private OSSConfig ossConfig;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private EmployeeInfoService employeeInfoService;
|
|
|
|
+
|
|
|
|
+ @Test
|
|
|
|
+ public void testZip(){
|
|
|
|
+ try {
|
|
|
|
+ String localPath = "D:\\";
|
|
|
|
+
|
|
|
|
+ //打包文件
|
|
|
|
+ List<Map<String, Object>> fileList = new ArrayList<>();
|
|
|
|
+
|
|
|
|
+ //读取模板
|
|
|
|
+ InputStream inputStream = this.getClass().getResourceAsStream("/static/模板.csv");
|
|
|
|
+ byte[] bytes = new byte[inputStream.available()];
|
|
|
|
+ inputStream.read(bytes);
|
|
|
|
+
|
|
|
|
+ StringBuilder csvBuilder = new StringBuilder();
|
|
|
|
+ csvBuilder.append(new String(bytes, "UTF-8"));
|
|
|
|
+
|
|
|
|
+ String ids = "1";
|
|
|
|
+
|
|
|
|
+ List<EmployeeInfo> employeeInfos = employeeInfoService.findByArray(ids.split(","));
|
|
|
|
+
|
|
|
|
+ if (employeeInfos.size() > 0) {
|
|
|
|
+ for (EmployeeInfo employeeInfo : employeeInfos) {
|
|
|
|
+ csvBuilder.append(employeeInfo.getId() + ",");
|
|
|
|
+ csvBuilder.append(employeeInfo.getName() + ",");
|
|
|
|
+
|
|
|
|
+ String photoExt = employeeInfo.getPhoto().substring(employeeInfo.getPhoto().lastIndexOf("."));
|
|
|
|
+
|
|
|
|
+ csvBuilder.append(localPath + "\\照片\\" + employeeInfo.getId() + photoExt + "\r\n");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Map<String, Object> fileMap = new HashMap<>();
|
|
|
|
+ fileMap.put("fileData", csvBuilder.toString().getBytes("UTF-8"));
|
|
|
|
+ fileMap.put("fileName", "人员名单.csv");
|
|
|
|
+
|
|
|
|
+ fileList.add(fileMap);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //身份证
|
|
|
|
+ for (EmployeeInfo employeeInfo : employeeInfos) {
|
|
|
|
+ if (StringUtils.isNotEmpty(employeeInfo.getPhoto())) {
|
|
|
|
+ String url = employeeInfo.getPhoto();
|
|
|
|
+
|
|
|
|
+ String ext = url.substring(url.lastIndexOf("."));
|
|
|
|
+
|
|
|
|
+ Map<String, Object> fileMap = new HashMap<>();
|
|
|
|
+ fileMap.put("fileUrl", url + "?x-oss-process=image/resize,l_800,limit_1");
|
|
|
|
+ fileMap.put("filePath", "照片/");
|
|
|
|
+ fileMap.put("fileName", employeeInfo.getId() + ext);
|
|
|
|
+
|
|
|
|
+ fileList.add(fileMap);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ FileOutputStream output = new FileOutputStream("H:\\压缩测试\\test.zip");
|
|
|
|
+
|
|
|
|
+ OSSUtil.batchDownload(fileList, output);
|
|
|
|
+
|
|
|
|
+ output.close();
|
|
|
|
+ }
|
|
|
|
+ catch(Exception ex){
|
|
|
|
+ ex.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|