Browse Source

1.修改员工资料打包下载。

tomatozq 5 năm trước cách đây
mục cha
commit
122fffc4e4

+ 1 - 1
src/main/java/com/jpsoft/smart/advice/PermissionAdvice.java

@@ -26,7 +26,7 @@ public class PermissionAdvice {
     @Autowired
     private PermissionService permissionService;
 
-    @Pointcut("(execution(public * com.jpsoft.epay..controller.*.*(..)))")
+    @Pointcut("(execution(public * com.jpsoft.smart..controller.*.*(..)))")
     public void pointcut(){
 
     }

+ 23 - 12
src/main/java/com/jpsoft/smart/modules/common/utils/OSSUtil.java

@@ -12,6 +12,7 @@ import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 
 import java.io.*;
+import java.net.HttpURLConnection;
 import java.net.URL;
 import java.net.URLConnection;
 import java.net.URLEncoder;
@@ -118,27 +119,37 @@ public class OSSUtil {
                         zipFile = filePath + fileName;
                     }
 
-                    ZipEntry zipEntry = new ZipEntry(zipFile);
-                    zos.putNextEntry(zipEntry);
-
                     if(StringUtils.isNotEmpty(fileUrl)) {
+                        ZipEntry zipEntry = new ZipEntry(zipFile);
+                        zos.putNextEntry(zipEntry);
+
                         URL url = new URL(encodeFileName(fileUrl));
 
-                        URLConnection conn = url.openConnection();
-                        InputStream inputStream = conn.getInputStream();
+                        HttpURLConnection conn = (HttpURLConnection)url.openConnection();
+                        // 设置连接主机超时(单位:毫秒)
+                        conn.setConnectTimeout(5000);
+                        // 设置从主机读取数据超时(单位:毫秒)
+                        conn.setReadTimeout(5000);
 
-                        byte[] buffs = new byte[1024 * 10];
+                        if(conn.getResponseCode()==200) {
+                            InputStream inputStream = conn.getInputStream();
 
-                        BufferedInputStream bis = new BufferedInputStream(inputStream, 1024 * 10);
+                            byte[] buffs = new byte[1024 * 10];
 
-                        int read;
-                        while ((read = bis.read(buffs, 0, 1024 * 10)) != -1) {
-                            zos.write(buffs, 0, read);
-                        }
+                            BufferedInputStream bis = new BufferedInputStream(inputStream, 1024 * 10);
 
-                        bis.close();
+                            int read;
+                            while ((read = bis.read(buffs, 0, 1024 * 10)) != -1) {
+                                zos.write(buffs, 0, read);
+                            }
+
+                            bis.close();
+                        }
                     }
                     else if(map.containsKey("fileData")){
+                        ZipEntry zipEntry = new ZipEntry(zipFile);
+                        zos.putNextEntry(zipEntry);
+
                         byte[] fileData = (byte[])map.get("fileData");
                         zos.write(fileData,0,fileData.length);
                     }

+ 7 - 1
src/main/resources/application-dev.yml

@@ -35,4 +35,10 @@ alipay:
   mchId: 2088102170202580
   # appAuthToken: 201906BBbc7d6558596f4bbc9f056c01b8aebX48
   signType: RSA2
-  notifyUrl: http://18891j25i6.iok.la/epay-server/aliPay/payNotify
+  notifyUrl: http://18891j25i6.iok.la/smart-server/aliPay/payNotify
+
+springfox:
+  documentation:
+    swagger:
+      v2:
+        host: kr6zr7.natappfree.cc

+ 2 - 2
src/main/resources/application-production.yml

@@ -21,7 +21,7 @@ spring:
 
 logger:
   level: WARN
-  dir: E:\\epay\\logs
+  dir: E:\\smart\\logs
 
 netty:
   port: 9966    #监听端口
@@ -39,5 +39,5 @@ wx:
     mchId: 1500160622
     subMchId: 1505070291
     mchKey: jpsoft11111111111111111111111111
-    notifyUrl: http://www.wzgh.org/epay-server/wxPay/payNotify
+    notifyUrl: http://www.wzgh.org/smart-server/wxPay/payNotify
     ip: 122.228.31.242

+ 1 - 1
src/main/resources/application.yml

@@ -115,7 +115,7 @@ wx:
     mchId: 1500160622
     subMchId: 1505070291
     mchKey: jpsoft11111111111111111111111111
-    notifyUrl: http://18891j25i6.iok.la:40309/epay-server/wxPay/payNotify
+    notifyUrl: http://18891j25i6.iok.la:40309/smart-server/wxPay/payNotify
     ip: 101.37.31.116
   jpsoft:
     appId: wxe598c699aa68cffe

+ 1 - 1
src/test/java/com/jpsoft/epay/ElectricityPaymentServerApplicationTests.java → src/test/java/com/jpsoft/smart/ElectricityPaymentServerApplicationTests.java

@@ -1,4 +1,4 @@
-package com.jpsoft.epay;
+package com.jpsoft.smart;
 
 import org.junit.jupiter.api.Test;
 import org.springframework.boot.test.context.SpringBootTest;

+ 93 - 0
src/test/java/com/jpsoft/smart/EmployeeTest.java

@@ -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();
+        }
+    }
+}

+ 1 - 3
src/test/java/com/jpsoft/epay/HutoolTest.java → src/test/java/com/jpsoft/smart/HutoolTest.java

@@ -1,9 +1,7 @@
-package com.jpsoft.epay;
+package com.jpsoft.smart;
 
 import cn.hutool.core.date.DatePattern;
 import cn.hutool.core.date.DateTime;
-import cn.hutool.core.lang.Snowflake;
-import cn.hutool.core.util.IdUtil;
 import cn.hutool.core.util.RandomUtil;
 
 public class HutoolTest {