wangxuanran 2022-11-23 10:06:11 +08:00
commit b09f13ebc2
7 changed files with 597 additions and 202 deletions

2
.gitignore vendored
View File

@ -16,7 +16,7 @@ log
*.ipa
*.apk
.idea/
.gitignore
#.gitignore
!.gitignore
# Project files, i.e. `.project`, `.actionScriptProperties` and `.flexProperties`
# should NOT be excluded as they contain compiler settings and other important

View File

@ -192,7 +192,7 @@ public abstract class CusBaseAction implements Action {
if (null == propertyArr) {
return Collections.emptyMap();
}
Map<String, String> mainTable = new HashMap<>((int) Math.ceil(propertyArr.length * 0.75));
Map<String, String> 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<String, List<Map<String, String>>> getDetailTableValue() {
DetailTable[] detailTableArr = requestInfo.getDetailTableInfo().getDetailTable();
Map<String, List<Map<String, String>>> detailDataList = new HashMap<>((int) Math.ceil(detailTableArr.length * 0.75));
Map<String, List<Map<String, String>>> detailDataList = new HashMap<>((int) Math.ceil(detailTableArr.length * 1.4));
for (DetailTable detailTable : detailTableArr) {
List<Map<String, String>> detailData = getDetailValue(detailTable);
detailDataList.put(detailTable.getId(), detailData);
@ -242,7 +242,8 @@ public abstract class CusBaseAction implements Action {
List<Map<String, String>> detailData = new ArrayList<>(rowArr.length);
for (Row row : rowArr) {
Cell[] cellArr = row.getCell();
Map<String, String> rowData = new HashMap<>((int) Math.ceil(cellArr.length * 0.75));
Map<String, String> 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();

View File

@ -1,140 +0,0 @@
package aiyh.utils.fileUtil.sftp;
import aiyh.utils.excention.CustomerException;
import com.jcraft.jsch.*;
import lombok.Getter;
import lombok.NoArgsConstructor;
import java.util.Properties;
/**
* <h1>sftp</h1>
*
* <p>create: 2022-11-22 11:00</p>
*
* @author youHong.ai
*/
@Getter
@NoArgsConstructor
public class SftpConnectUtil extends ChannelSftp {
/**
* sftp
*/
private ChannelSftp sftp;
/**
*
*/
private Session session;
/**
*
*/
private String userName;
/**
*
*/
private String password;
/**
*
*/
private String prvKeyFilePath;
/**
*
*/
private boolean success;
/**
* sftp
*/
private String sftpIp;
/**
*
*/
private Integer port;
/**
*
*/
private Integer sftpTimeOut;
public SftpConnectUtil(String userName, String prvKeyFilePath,String password, String sftpIp,
Integer port, Integer sftpTimeOut) {
this.userName = userName;
this.prvKeyFilePath = prvKeyFilePath;
this.sftpIp = sftpIp;
this.port = port;
this.password = password;
this.sftpTimeOut = sftpTimeOut;
this.login();
}
/**
* <h2>sftp</h2>
*
* @author youHong.ai
*/
private void login() {
JSch jSch = new JSch();
try {
if (prvKeyFilePath != null && !"".equals(prvKeyFilePath)) {
if (password != null && !"".equals(password)) {
jSch.addIdentity(prvKeyFilePath, password);
} else {
jSch.addIdentity(prvKeyFilePath);
}
} else {
throw new RuntimeException("从sftp下载需要的ppk文件未找到");
}
if (port != null && port > 0) {
this.session = jSch.getSession(userName, sftpIp, port);
} else {
this.session = jSch.getSession(userName, sftpIp);
}
Properties config = new Properties();
config.put("StrictHostKeyChecking", "no");
this.session.setConfig(config);
this.session.setTimeout(sftpTimeOut);
this.session.connect();
Channel channel = this.session.openChannel("sftp");
channel.connect();
this.sftp = (ChannelSftp) channel;
this.success = true;
} catch (JSchException e) {
throw new CustomerException("SFTP链接失败", e);
}
}
/**
* server
*
* @author youHong.ai
*/
private void logout() {
if (sftp != null) {
if (sftp.isConnected()) {
sftp.disconnect();
}
}
if (session != null) {
if (session.isConnected()) {
session.disconnect();
}
}
}
/**
* <h2></h2>
*/
public void close(){
this.login();
}
}

View File

@ -0,0 +1,571 @@
package ebu7common.youhong.ai.sftp;
import aiyh.utils.excention.CustomerException;
import com.jcraft.jsch.*;
import lombok.Getter;
import lombok.NoArgsConstructor;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Hashtable;
import java.util.Properties;
import java.util.Vector;
/**
* <h1>sftp</h1>
*
* <p>create: 2022-11-22 11:00</p>
*
* @author youHong.ai
*/
@Getter
@NoArgsConstructor
public class SftpConnectUtil extends ChannelSftp {
/**
* sftp
*/
private ChannelSftp sftp;
/**
*
*/
private Session session;
/**
*
*/
private String userName;
/**
*
*/
private String password;
/**
*
*/
private String prvKeyFilePath;
/**
*
*/
private boolean success;
/**
* sftp
*/
private String sftpIp;
/**
*
*/
private Integer port;
/**
*
*/
private Integer sftpTimeOut;
public SftpConnectUtil(String userName, String prvKeyFilePath,String password, String sftpIp,
Integer port, Integer sftpTimeOut) {
this.userName = userName;
this.prvKeyFilePath = prvKeyFilePath;
this.sftpIp = sftpIp;
this.port = port;
this.password = password;
this.sftpTimeOut = sftpTimeOut;
this.login();
}
/**
* <h2>sftp</h2>
*
* @author youHong.ai
*/
private void login() {
JSch jSch = new JSch();
try {
if (prvKeyFilePath != null && !"".equals(prvKeyFilePath)) {
if (password != null && !"".equals(password)) {
jSch.addIdentity(prvKeyFilePath, password);
} else {
jSch.addIdentity(prvKeyFilePath);
}
} else {
throw new RuntimeException("从sftp下载需要的ppk文件未找到");
}
if (port != null && port > 0) {
this.session = jSch.getSession(userName, sftpIp, port);
} else {
this.session = jSch.getSession(userName, sftpIp);
}
Properties config = new Properties();
config.put("StrictHostKeyChecking", "no");
this.session.setConfig(config);
this.session.setTimeout(sftpTimeOut);
this.session.connect();
Channel channel = this.session.openChannel("sftp");
channel.connect();
this.sftp = (ChannelSftp) channel;
this.success = true;
} catch (JSchException e) {
throw new CustomerException("SFTP链接失败", e);
}
}
/**
* server
*
* @author youHong.ai
*/
private void logout() {
if (sftp != null) {
if (sftp.isConnected()) {
sftp.disconnect();
}
}
if (session != null) {
if (session.isConnected()) {
session.disconnect();
}
}
}
/**
* <h2></h2>
*/
public void close(){
this.login();
}
@Override
public boolean isClosed() {
return this.sftp.isClosed();
}
@Override
public void setBulkRequests(int bulk_requests) throws JSchException {
this.sftp.setBulkRequests(bulk_requests);
}
@Override
public int getBulkRequests() {
return this.sftp.getBulkRequests();
}
@Override
public void start() throws JSchException {
this.sftp.start();
}
@Override
public boolean isEOF() {
return this.sftp.isEOF();
}
@Override
public void setInputStream(InputStream in) {
this.sftp.setInputStream(in);
}
@Override
public void setInputStream(InputStream in, boolean dontclose) {
this.sftp.setInputStream(in, dontclose);
}
@Override
public void setOutputStream(OutputStream out) {
this.sftp.setOutputStream(out);
}
@Override
public void setOutputStream(OutputStream out, boolean dontclose) {
this.sftp.setOutputStream(out, dontclose);
}
@Override
public void setExtOutputStream(OutputStream out) {
this.sftp.setExtOutputStream(out);
}
@Override
public void setExtOutputStream(OutputStream out, boolean dontclose) {
this.sftp.setExtOutputStream(out, dontclose);
}
@Override
public InputStream getInputStream() throws IOException {
return this.sftp.getInputStream();
}
@Override
public InputStream getExtInputStream() throws IOException {
return this.sftp.getExtInputStream();
}
@Override
public OutputStream getOutputStream() throws IOException {
return this.sftp.getOutputStream();
}
@Override
public void quit() {
this.sftp.quit();
}
@Override
public void exit() {
this.sftp.exit();
}
@Override
public void lcd(String path) throws SftpException {
this.sftp.lcd(path);
}
@Override
public void cd(String path) throws SftpException {
this.sftp.cd(path);
}
@Override
public void put(String src, String dst) throws SftpException {
this.sftp.put(src, dst);
}
@Override
public void put(String src, String dst, int mode) throws SftpException {
this.sftp.put(src, dst, mode);
}
@Override
public void put(String src, String dst, SftpProgressMonitor monitor) throws SftpException {
this.sftp.put(src, dst, monitor);
}
@Override
public void put(String src, String dst, SftpProgressMonitor monitor, int mode) throws SftpException {
this.sftp.put(src, dst, monitor, mode);
}
@Override
public void put(InputStream src, String dst) throws SftpException {
this.sftp.put(src, dst);
}
@Override
public void put(InputStream src, String dst, int mode) throws SftpException {
this.sftp.put(src, dst, mode);
}
@Override
public void put(InputStream src, String dst, SftpProgressMonitor monitor) throws SftpException {
this.sftp.put(src, dst, monitor);
}
@Override
public void put(InputStream src, String dst, SftpProgressMonitor monitor, int mode) throws SftpException {
this.sftp.put(src, dst, monitor, mode);
}
@Override
public void _put(InputStream src, String dst, SftpProgressMonitor monitor, int mode) throws SftpException {
this.sftp._put(src, dst, monitor, mode);
}
@Override
public OutputStream put(String dst) throws SftpException {
return this.sftp.put(dst);
}
@Override
public OutputStream put(String dst, int mode) throws SftpException {
return this.sftp.put(dst, mode);
}
@Override
public OutputStream put(String dst, SftpProgressMonitor monitor, int mode) throws SftpException {
return this.sftp.put(dst, monitor, mode);
}
@Override
public OutputStream put(String dst, SftpProgressMonitor monitor, int mode, long offset) throws SftpException {
return this.sftp.put(dst, monitor, mode, offset);
}
@Override
public void get(String src, String dst) throws SftpException {
this.sftp.get(src, dst);
}
@Override
public void get(String src, String dst, SftpProgressMonitor monitor) throws SftpException {
this.sftp.get(src, dst, monitor);
}
@Override
public void get(String src, String dst, SftpProgressMonitor monitor, int mode) throws SftpException {
this.sftp.get(src, dst, monitor, mode);
}
@Override
public void get(String src, OutputStream dst) throws SftpException {
this.sftp.get(src, dst);
}
@Override
public void get(String src, OutputStream dst, SftpProgressMonitor monitor) throws SftpException {
this.sftp.get(src, dst, monitor);
}
@Override
public void get(String src, OutputStream dst, SftpProgressMonitor monitor, int mode, long skip) throws SftpException {
this.sftp.get(src, dst, monitor, mode, skip);
}
@Override
public InputStream get(String src) throws SftpException {
return this.sftp.get(src);
}
@Override
public InputStream get(String src, SftpProgressMonitor monitor) throws SftpException {
return this.sftp.get(src, monitor);
}
@Override
public InputStream get(String src, int mode) throws SftpException {
return this.sftp.get(src, mode);
}
@Override
public InputStream get(String src, SftpProgressMonitor monitor, int mode) throws SftpException {
return this.sftp.get(src, monitor, mode);
}
@Override
public InputStream get(String src, SftpProgressMonitor monitor, long skip) throws SftpException {
return this.sftp.get(src, monitor, skip);
}
@Override
public Vector ls(String path) throws SftpException {
return this.sftp.ls(path);
}
@Override
public void ls(String path, LsEntrySelector selector) throws SftpException {
this.sftp.ls(path, selector);
}
@Override
public String readlink(String path) throws SftpException {
return this.sftp.readlink(path);
}
@Override
public void symlink(String oldpath, String newpath) throws SftpException {
this.sftp.symlink(oldpath, newpath);
}
@Override
public void hardlink(String oldpath, String newpath) throws SftpException {
this.sftp.hardlink(oldpath, newpath);
}
@Override
public void rename(String oldpath, String newpath) throws SftpException {
this.sftp.rename(oldpath, newpath);
}
@Override
public void rm(String path) throws SftpException {
this.sftp.rm(path);
}
@Override
public void chgrp(int gid, String path) throws SftpException {
this.sftp.chgrp(gid, path);
}
@Override
public void chown(int uid, String path) throws SftpException {
this.sftp.chown(uid, path);
}
@Override
public void chmod(int permissions, String path) throws SftpException {
this.sftp.chmod(permissions, path);
}
@Override
public void setMtime(String path, int mtime) throws SftpException {
this.sftp.setMtime(path, mtime);
}
@Override
public void rmdir(String path) throws SftpException {
this.sftp.rmdir(path);
}
@Override
public void mkdir(String path) throws SftpException {
this.sftp.mkdir(path);
}
@Override
public SftpATTRS stat(String path) throws SftpException {
return this.sftp.stat(path);
}
@Override
public SftpStatVFS statVFS(String path) throws SftpException {
return this.sftp.statVFS(path);
}
@Override
public SftpATTRS lstat(String path) throws SftpException {
return this.sftp.lstat(path);
}
@Override
public void setStat(String path, SftpATTRS attr) throws SftpException {
this.sftp.setStat(path, attr);
}
@Override
public String pwd() throws SftpException {
return this.sftp.pwd();
}
@Override
public String lpwd() {
return this.sftp.lpwd();
}
@Override
public String version() {
return this.sftp.version();
}
@Override
public String getHome() throws SftpException {
return this.sftp.getHome();
}
@Override
public void disconnect() {
this.sftp.disconnect();
}
@Override
public boolean isConnected() {
return this.sftp.isConnected();
}
@Override
public void sendSignal(String signal) throws Exception {
this.sftp.sendSignal(signal);
}
@Override
public int getExitStatus() {
return this.sftp.getExitStatus();
}
@Override
public int getId() {
return this.sftp.getId();
}
@Override
public int getServerVersion() throws SftpException {
return this.sftp.getServerVersion();
}
@Override
public void setFilenameEncoding(String encoding) throws SftpException {
this.sftp.setFilenameEncoding(encoding);
}
@Override
public String getExtension(String key) {
return this.sftp.getExtension(key);
}
@Override
public String realpath(String path) throws SftpException {
return this.sftp.realpath(path);
}
@Override
public void setAgentForwarding(boolean enable) {
this.sftp.setAgentForwarding(enable);
}
@Override
public void connect() throws JSchException {
this.sftp.connect();
}
@Override
public void connect(int connectTimeout) throws JSchException {
this.sftp.connect(connectTimeout);
}
@Override
public void setXForwarding(boolean enable) {
this.sftp.setXForwarding(enable);
}
@Override
public void setEnv(Hashtable env) {
this.sftp.setEnv(env);
}
@Override
public void setEnv(String name, String value) {
this.sftp.setEnv(name, value);
}
@Override
public void setEnv(byte[] name, byte[] value) {
this.sftp.setEnv(name, value);
}
@Override
public void setPty(boolean enable) {
this.sftp.setPty(enable);
}
@Override
public void setTerminalMode(byte[] terminal_mode) {
this.sftp.setTerminalMode(terminal_mode);
}
@Override
public void setPtySize(int col, int row, int wp, int hp) {
this.sftp.setPtySize(col, row, wp, hp);
}
@Override
public void setPtyType(String ttype) {
this.sftp.setPtyType(ttype);
}
@Override
public void setPtyType(String ttype, int col, int row, int wp, int hp) {
this.sftp.setPtyType(ttype, col, row, wp, hp);
}
@Override
public void run() {
this.sftp.run();
}
}

View File

@ -1,14 +1,10 @@
package weaver.youhong.ai.pcn.hrorganization.sftp;
import aiyh.utils.excention.CustomerException;
import aiyh.utils.fileUtil.sftp.SftpConnectUtil;
import ebu7common.youhong.ai.sftp.SftpConnectUtil;
import com.jcraft.jsch.ChannelSftp;
import com.jcraft.jsch.SftpException;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.util.Vector;
import java.io.*;
/**
* <h1></h1>
@ -33,23 +29,28 @@ public class FetchDataUtil {
public void downloadFile(SftpConnectUtil sftpConnectUtil,String fileName,
String targetFile){
public void downloadFile(SftpConnectUtil sftpConnectUtil,
String fileName, String targetFile){
try {
sftpConnectUtil.cd("/");
Vector<ChannelSftp.LsEntry> ls = sftpConnectUtil.ls("/");
for (ChannelSftp.LsEntry l : ls) {
System.out.println(l.getFilename());
}
// sftpConnectUtil.lcd(".");
// Vector ls = sftpConnectUtil.ls(".");
// for (Object l : ls) {
// System.out.println(l);
// }
//
File file = new File(targetFile);
if (!file.exists()) {
file.getParentFile().mkdirs();
}
sftpConnectUtil.get(fileName + "/", new FileOutputStream(file));
} catch (SftpException | FileNotFoundException e) {
sftpConnectUtil.get(fileName,new FileOutputStream(targetFile));
} catch (SftpException e) {
sftpConnectUtil.close();
e.printStackTrace();
// throw new CustomerException("下载文件出错,down file error!");
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
}
}

View File

@ -1,39 +0,0 @@
package baseTest;
import cn.hutool.core.lang.Console;
import org.junit.Before;
import org.junit.Test;
import weaver.conn.RecordSet;
import weaver.general.GCONST;
/**
* @author EBU7-dev1-ayh
* create 2021/12/13 0013 23:08
*/
public class BaseTest {
@Before
public void before() {
GCONST.setServerName("ecology");
GCONST.setRootPath("F:\\wxr\\e9-project-ebu7-dev1\\src\\main\\resources\\");
GCONST.setSystemFilePath("F:\\wxr\\e9-project-ebu7-dev1\\src\\main\\resources\\file");
// GCONST.setLogPath("/Users/aoey.oct.22/company/Fan_wei/code/idea/ecology9-project/log");
}
@Test
public void with() {
String sql = "select COMPANYNAME,LICENSE,EXPIREDATE,CVERSION from license ";
RecordSet rs = new RecordSet();
rs.executeQuery(sql);
if (rs.next()) {
System.out.println("公司名称:" + rs.getString(1));
System.out.println("LICENSE:" + rs.getString(2));
System.out.println("授权到期日期:" + rs.getString(3));
System.out.println("版本:" + rs.getString(4));
Console.log(sql);
System.out.println(GCONST.getSysFilePath());
// 打印文件位置
}
}
}

View File

@ -1,7 +1,8 @@
package youhong.ai.pcn;
import aiyh.utils.fileUtil.sftp.SftpConnectUtil;
import ebu7common.youhong.ai.sftp.SftpConnectUtil;
import baseTest.BaseTest;
import com.jcraft.jsch.ChannelSftp;
import org.junit.Test;
import weaver.general.GCONST;
import weaver.youhong.ai.pcn.hrorganization.sftp.FetchDataUtil;
@ -22,10 +23,10 @@ public class TestOrganization extends BaseTest {
SftpConnectUtil sftpConnectUtil = new SftpConnectUtil(
"HR Digital_PROD",
"/Users/aoey.oct.22/company/Fan_wei/ssl/pcn/HR_Digital_PROD.pem",null,"222.73.197.242",
null,1000 * 10
null,1000 * 100
);
FetchDataUtil fetchDataUtil = new FetchDataUtil();
fetchDataUtil.downloadFile(sftpConnectUtil,
"HRIS_DepartmentExport20200503", GCONST.getSysFilePath() + "HRIS_DepartmentExport20200503.csv");
"HRIS_PositionExport20221120", GCONST.getSysFilePath() + "HRIS_PositionExport20221120.csv");
}
}