Browse Source

公共组件更新,es和ftp支持最新版

wj 4 years ago
parent
commit
51798b17aa

+ 24 - 4
common-data-es/src/main/java/com/tofly/es/config/ToflyEsRepository.java

@@ -28,6 +28,7 @@ import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
+import java.util.stream.Collectors;
 
 /**
  * @author tuonbed
@@ -115,14 +116,33 @@ public interface ToflyEsRepository<T, ID extends Serializable> extends Elasticse
                 }
             });
             Sort sort;
+
+//            if(asc.size()>0 && desc.size()>0){
+//                sort=new Sort(Sort.Direction.ASC,asc);
+//                Sort sort1=new Sort(Sort.Direction.DESC,desc);
+//                sort.and(sort1);
+//            }else if(asc.size()>0){
+//                sort=new Sort(Sort.Direction.ASC,asc);
+//            }else{
+//                sort=new Sort(Sort.Direction.DESC,desc);
+//            }
+
             if(asc.size()>0 && desc.size()>0){
-                sort=new Sort(Sort.Direction.ASC,asc);
-                Sort sort1=new Sort(Sort.Direction.DESC,desc);
+                sort=Sort.by(asc.stream().map(it->{
+                    return new Sort.Order(Sort.Direction.ASC, it);
+                }).collect(Collectors.toList()));
+                Sort sort1= Sort.by(desc.stream().map(it->{
+                    return new Sort.Order(Sort.Direction.DESC, it);
+                }).collect(Collectors.toList()));
                 sort.and(sort1);
             }else if(asc.size()>0){
-                sort=new Sort(Sort.Direction.ASC,asc);
+                sort=sort=Sort.by(asc.stream().map(it->{
+                    return new Sort.Order(Sort.Direction.ASC, it);
+                }).collect(Collectors.toList()));
             }else{
-                sort=new Sort(Sort.Direction.DESC,desc);
+                sort=Sort.by(desc.stream().map(it->{
+                    return new Sort.Order(Sort.Direction.DESC, it);
+                }).collect(Collectors.toList()));
             }
             pageRequest = PageRequest.of(Long.valueOf(page.getCurrent()).intValue()-1,
                     Long.valueOf(page.getSize()).intValue(),sort);

+ 2 - 2
common-file-ftp/src/main/java/com/tofly/common/ftp/config/FtpConfiguration.java

@@ -44,8 +44,8 @@ public class FtpConfiguration {
         poolConfig.setMinEvictableIdleTimeMillis(60000);
         poolConfig.setSoftMinEvictableIdleTimeMillis(50000);
         poolConfig.setTimeBetweenEvictionRunsMillis(30000);
-        poolConfig.setMaxTotal(50);//最大连接数
-        poolConfig.setMaxIdle(10);//最大空闲连接数
+        poolConfig.setMaxTotal(20);//最大连接数
+        poolConfig.setMaxIdle(20);//最大空闲连接数
         pool = new GenericObjectPool<>(new FtpClientPooledObjectFactory(props), poolConfig);
         preLoadingFtpClient(props.getInitialSize(), poolConfig.getMaxIdle());
         // 初始化ftp工具类中的ftpClientPool

+ 23 - 26
common-file-ftp/src/main/java/com/tofly/common/ftp/config/FtpUtil.java

@@ -80,7 +80,7 @@ public class FtpUtil {
 //                    .withIgnoreSurroundingSpaces().withIgnoreEmptyLines()
 //                    .parse(new InputStreamReader(in, "utf-8")).getRecords();
 //        } finally {
-//            ftpClient.completePendingCommand();
+//            //ftpClient.completePendingCommand();
 //            releaseFtpClient(ftpClient);
 //        }
 //    }
@@ -99,7 +99,7 @@ public class FtpUtil {
             return br.lines().map(line -> StringUtils.trimToEmpty(line))
                     .filter(line -> StringUtils.isNotEmpty(line)).collect(Collectors.toList());
         } finally {
-            ftpClient.completePendingCommand();
+            //ftpClient.completePendingCommand();
             releaseFtpClient(ftpClient);
         }
     }
@@ -234,7 +234,7 @@ public class FtpUtil {
             workbook.close();
             return true;
         } finally {
-            ftpClient.completePendingCommand();
+            //ftpClient.completePendingCommand();
             releaseFtpClient(ftpClient);
         }
     }
@@ -248,7 +248,7 @@ public class FtpUtil {
             out.write(bytes);
             return true;
         } finally {
-            ftpClient.completePendingCommand();
+            //ftpClient.completePendingCommand();
             releaseFtpClient(ftpClient);
         }
     }
@@ -279,7 +279,7 @@ public class FtpUtil {
 
             return true;
         }finally {
-            //ftpClient.completePendingCommand();
+            ////ftpClient.completePendingCommand();
             releaseFtpClient(ftpClient);
         }
     }
@@ -343,7 +343,7 @@ public class FtpUtil {
             log.info("上传文件结果:{}",b);
             return true;
         }finally {
-            //ftpClient.completePendingCommand();
+            ////ftpClient.completePendingCommand();
             releaseFtpClient(ftpClient);
         }
     }
@@ -409,7 +409,7 @@ public class FtpUtil {
                 out.flush();
             }
         } finally {
-            ftpClient.completePendingCommand();
+            //ftpClient.completePendingCommand();
             releaseFtpClient(ftpClient);
         }
     }
@@ -423,7 +423,7 @@ public class FtpUtil {
         try {
              in = ftpClient.retrieveFileStream(encodingPath(remoteFilePath));
         }finally {
-            ftpClient.completePendingCommand();
+            //ftpClient.completePendingCommand();
             releaseFtpClient(ftpClient);
         }
         return in;
@@ -431,34 +431,31 @@ public class FtpUtil {
 
     @SneakyThrows
     public static byte[] getByteDataforFile(String remoteFilePath){
+        byte[] flieByte=null;
         FTPClient ftpClient = getFtpClient();
         if(StringUtil.isNotEmpty(remoteFilePath)){
             try{
                 ftpClient.changeWorkingDirectory(remoteFilePath);
             }catch (Exception e){
                 log.info("e:",e.getMessage());
-                ftpClient.completePendingCommand();
+                //ftpClient.completePendingCommand();
                 releaseFtpClient(ftpClient);
                 return null;
             }
             log.info("file success");
-        }
-
-        String fileName = remoteFilePath.substring(remoteFilePath.lastIndexOf("/") + 1);
-        fileName = new String(fileName.getBytes("utf-8"), "iso-8859-1");
-        byte[] flieByte=null;
-        try (InputStream in = ftpClient.retrieveFileStream(encodingPath(remoteFilePath));
-             ByteArrayOutputStream out = new ByteArrayOutputStream()) {
-            int size = 0;
-            byte[] buf = new byte[10240];
-            while ((size = in.read(buf)) > 0) {
-                out.write(buf, 0, size);
-                out.flush();
+            try (InputStream in = ftpClient.retrieveFileStream(encodingPath(remoteFilePath));
+                 ByteArrayOutputStream out = new ByteArrayOutputStream()) {
+                int size = 0;
+                byte[] buf = new byte[10240];
+                while ((size = in.read(buf)) > 0) {
+                    out.write(buf, 0, size);
+                    out.flush();
+                }
+                flieByte = out.toByteArray();
+            } finally {
+                //ftpClient.completePendingCommand();
+                releaseFtpClient(ftpClient);
             }
-            flieByte = out.toByteArray();
-        } finally {
-            ftpClient.completePendingCommand();
-            releaseFtpClient(ftpClient);
         }
         return flieByte;
     }
@@ -486,7 +483,7 @@ public class FtpUtil {
                 out.flush();
             }
         } finally {
-            ftpClient.completePendingCommand();
+            //ftpClient.completePendingCommand();
             releaseFtpClient(ftpClient);
         }
     }