From 2c0300f8d46098cc84d94774524d499216327ee7 Mon Sep 17 00:00:00 2001 From: "youHong.ai" <774495953@qq.com> Date: Tue, 22 Nov 2022 18:21:50 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DCusBaseAction=E4=B8=AD?= =?UTF-8?q?=E6=B2=A1=E6=9C=89=E8=8E=B7=E5=8F=96=E6=98=8E=E7=BB=86id?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/aiyh/utils/action/CusBaseAction.java | 7 ++++--- .../java/aiyh/utils/fileUtil/sftp/SftpConnectUtil.java | 5 +++-- .../youhong/ai/pcn/hrorganization/sftp/FetchDataUtil.java | 8 ++++---- src/test/java/youhong/ai/pcn/TestOrganization.java | 7 ++++--- 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/main/java/aiyh/utils/action/CusBaseAction.java b/src/main/java/aiyh/utils/action/CusBaseAction.java index 6dc2c26..0eea3d6 100644 --- a/src/main/java/aiyh/utils/action/CusBaseAction.java +++ b/src/main/java/aiyh/utils/action/CusBaseAction.java @@ -192,7 +192,7 @@ public abstract class CusBaseAction implements Action { if (null == propertyArr) { return Collections.emptyMap(); } - Map mainTable = new HashMap<>((int) Math.ceil(propertyArr.length * 0.75)); + Map mainTable = new HashMap<>((int) Math.ceil(propertyArr.length * 1.4)); for (Property property : propertyArr) { String fieldName = property.getName(); String value = property.getValue(); @@ -209,7 +209,7 @@ public abstract class CusBaseAction implements Action { */ protected Map>> getDetailTableValue() { DetailTable[] detailTableArr = requestInfo.getDetailTableInfo().getDetailTable(); - Map>> detailDataList = new HashMap<>((int) Math.ceil(detailTableArr.length * 0.75)); + Map>> detailDataList = new HashMap<>((int) Math.ceil(detailTableArr.length * 1.4)); for (DetailTable detailTable : detailTableArr) { List> detailData = getDetailValue(detailTable); detailDataList.put(detailTable.getId(), detailData); @@ -242,7 +242,8 @@ public abstract class CusBaseAction implements Action { List> detailData = new ArrayList<>(rowArr.length); for (Row row : rowArr) { Cell[] cellArr = row.getCell(); - Map rowData = new HashMap<>((int) Math.ceil(cellArr.length * 0.75)); + Map rowData = new HashMap<>((int) Math.ceil(cellArr.length * (1 + 0.4))); + rowData.put("id",row.getId()); for (Cell cell : cellArr) { String fieldName = cell.getName(); String value = cell.getValue(); diff --git a/src/main/java/aiyh/utils/fileUtil/sftp/SftpConnectUtil.java b/src/main/java/aiyh/utils/fileUtil/sftp/SftpConnectUtil.java index 61c5d3b..7af9199 100644 --- a/src/main/java/aiyh/utils/fileUtil/sftp/SftpConnectUtil.java +++ b/src/main/java/aiyh/utils/fileUtil/sftp/SftpConnectUtil.java @@ -71,7 +71,7 @@ public class SftpConnectUtil extends ChannelSftp { this.port = port; this.password = password; this.sftpTimeOut = sftpTimeOut; - this.login(); + // this.login(); } @@ -81,7 +81,7 @@ public class SftpConnectUtil extends ChannelSftp { * @author youHong.ai */ - private void login() { + public ChannelSftp login() { JSch jSch = new JSch(); try { @@ -108,6 +108,7 @@ public class SftpConnectUtil extends ChannelSftp { channel.connect(); this.sftp = (ChannelSftp) channel; this.success = true; + return sftp; } catch (JSchException e) { throw new CustomerException("SFTP链接失败!", e); } diff --git a/src/main/java/weaver/youhong/ai/pcn/hrorganization/sftp/FetchDataUtil.java b/src/main/java/weaver/youhong/ai/pcn/hrorganization/sftp/FetchDataUtil.java index 5b4ee07..b7a9e48 100644 --- a/src/main/java/weaver/youhong/ai/pcn/hrorganization/sftp/FetchDataUtil.java +++ b/src/main/java/weaver/youhong/ai/pcn/hrorganization/sftp/FetchDataUtil.java @@ -32,10 +32,10 @@ public class FetchDataUtil { - public void downloadFile(SftpConnectUtil sftpConnectUtil,String fileName, - String targetFile){ + public void downloadFile(ChannelSftp sftp,SftpConnectUtil sftpConnectUtil, + String fileName, String targetFile){ try { - sftpConnectUtil.lcd("."); + // sftpConnectUtil.lcd("."); // Vector ls = sftpConnectUtil.ls("."); // for (Object l : ls) { // System.out.println(l); @@ -45,7 +45,7 @@ public class FetchDataUtil { if (!file.exists()) { file.getParentFile().mkdirs(); } - sftpConnectUtil.get(fileName,new FileOutputStream(targetFile)); + sftp.get(fileName,new FileOutputStream(targetFile)); } catch (SftpException e) { diff --git a/src/test/java/youhong/ai/pcn/TestOrganization.java b/src/test/java/youhong/ai/pcn/TestOrganization.java index 68246c2..48ff058 100644 --- a/src/test/java/youhong/ai/pcn/TestOrganization.java +++ b/src/test/java/youhong/ai/pcn/TestOrganization.java @@ -3,6 +3,7 @@ package youhong.ai.pcn; import aiyh.utils.fileUtil.sftp.SftpConnectUtil; import baseTest.BaseTest; import com.api.doc.detail.util.SFTPUtils; +import com.jcraft.jsch.ChannelSftp; import org.junit.Test; import weaver.general.GCONST; import weaver.youhong.ai.pcn.hrorganization.sftp.FetchDataUtil; @@ -25,9 +26,9 @@ public class TestOrganization extends BaseTest { "/Users/aoey.oct.22/company/Fan_wei/ssl/pcn/HR_Digital_PROD.pem",null,"222.73.197.242", null,1000 * 100 ); - SFTPUtils sftpUtils = new SFTPUtils(); + ChannelSftp login = sftpConnectUtil.login(); FetchDataUtil fetchDataUtil = new FetchDataUtil(); - fetchDataUtil.downloadFile(sftpConnectUtil, - "HRIS_DepartmentExport20200503", GCONST.getSysFilePath() + "HRIS_DepartmentExport20200503.csv"); + fetchDataUtil.downloadFile(login, sftpConnectUtil, + "HRIS_PositionExport20221120", GCONST.getSysFilePath() + "HRIS_PositionExport20221120.csv"); } }