diff --git a/pom.xml b/pom.xml index 5ca49f3d..edb845c5 100644 --- a/pom.xml +++ b/pom.xml @@ -89,6 +89,11 @@ 1.0.0-SNAPSHOT + + com.github.mwiede + jsch + 0.2.20 + diff --git a/src/main/java/cokr/xit/fims/rent/dao/FinSysFtpMapper.java b/src/main/java/cokr/xit/fims/rent/dao/FinSysFtpMapper.java new file mode 100644 index 00000000..04e54236 --- /dev/null +++ b/src/main/java/cokr/xit/fims/rent/dao/FinSysFtpMapper.java @@ -0,0 +1,15 @@ +package cokr.xit.fims.rent.dao; + +import java.util.Map; + +import org.egovframe.rte.psl.dataaccess.mapper.Mapper; + +import cokr.xit.foundation.component.AbstractMapper; +import cokr.xit.foundation.data.DataObject; + +@Mapper("finSysFtpMapper") +public interface FinSysFtpMapper extends AbstractMapper { + + DataObject selectFtpInfo(Map map); + +} diff --git a/src/main/java/cokr/xit/fims/rent/service/bean/LsctBean.java b/src/main/java/cokr/xit/fims/rent/service/bean/LsctBean.java index 5e656883..15e7b567 100644 --- a/src/main/java/cokr/xit/fims/rent/service/bean/LsctBean.java +++ b/src/main/java/cokr/xit/fims/rent/service/bean/LsctBean.java @@ -1,5 +1,7 @@ package cokr.xit.fims.rent.service.bean; +import java.io.IOException; +import java.io.InputStream; import java.util.ArrayList; import java.util.List; @@ -7,15 +9,26 @@ import javax.annotation.Resource; import org.springframework.stereotype.Component; +import com.jcraft.jsch.Channel; +import com.jcraft.jsch.ChannelSftp; +import com.jcraft.jsch.JSch; +import com.jcraft.jsch.JSchException; +import com.jcraft.jsch.Session; +import com.jcraft.jsch.SftpException; + import cokr.xit.base.crypto.bean.XitAria; import cokr.xit.base.file.FileInfo; +import cokr.xit.base.file.FileInfo.DataHolder; +import cokr.xit.base.file.FileInfo.Relation; import cokr.xit.base.file.service.bean.FileBean; +import cokr.xit.base.file.web.FileInfoFactory; import cokr.xit.fims.crdn.Crdn; import cokr.xit.fims.crdn.service.bean.CrdnBean; import cokr.xit.fims.payer.Payer; import cokr.xit.fims.payer.service.bean.PayerBean; import cokr.xit.fims.rent.Lsct; import cokr.xit.fims.rent.RentQuery; +import cokr.xit.fims.rent.dao.FinSysFtpMapper; import cokr.xit.fims.rent.dao.LsctMapper; import cokr.xit.foundation.component.AbstractBean; import cokr.xit.foundation.data.DataObject; @@ -49,12 +62,19 @@ public class LsctBean extends AbstractBean { @Resource(name = "payerBean") private PayerBean payerBean; + @Resource(name = "finSysFtpMapper") + private FinSysFtpMapper finSysFtpMapper; + /**지정한 조건에 따라 단속 대장 목록을 조회하여 반환한다. * 통합플랫폼으로 사용하지 안을 경우 렌트 소스만 사용하기 위해서 TB_CRDN, TB_PAYER에 직접 등록한다. * @param req 임대차계약 대장 조회 조건 * @return 임대차계약 대장 목록 + * @throws IOException + * @throws JSchException + * @throws NumberFormatException + * @throws SftpException */ - public List getCrdnLsctList(RentQuery req) { + public List getCrdnLsctList(RentQuery req) throws Exception { // 기존 과태료 시스템에서 사용하던 암/복호화 함수 사용을 위해서.. XitAria crypto = new XitAria("xit-aria"); @@ -218,16 +238,108 @@ public class LsctBean extends AbstractBean { throw new RuntimeException("[F] 단속 부가 대장 등록 작업에 실패하였습니다."); // 예외를 발생시켜서 DB Rollback } - // 단속ID로 단속 파일 다운로드 + ///////////////////////////////////////////////// + //FTP 서버 정보 조회 + DataObject main = mainList.get(iLoop); + DataObject ftpQuery = new DataObject() + .set("SGG_CD", main.string("MM_SGGCODE")) + .set("TASK_SE_CD", main.string("MM_TASKGB")); + DataObject storageServer = finSysFtpMapper.selectFtpInfo(ftpQuery); + + ///////////////////////////////////////////////// + //SFTP접속 + Session session = null; + JSch jsch = new JSch(); + Channel channel = null; + ChannelSftp channelSftp = null; + //세션객체 생성 + session = jsch.getSession("admin", "127.0.0.1", Integer.parseInt("22")); + session.setPassword("pass"); + + + //세션관련 설정정보 설정 + java.util.Properties config = new java.util.Properties(); + + //호스트 정보 검사하지 않는다. + config.put("StrictHostKeyChecking", "no"); + session.setConfig(config); + session.setTimeout(10000); //타임아웃 설정 + + //log.info("connect.. " + connIp); + System.out.println("connect.. "); + session.connect(); //접속 + channel = session.openChannel("sftp"); //sftp 채널 접속 + channel.connect(); + + channelSftp = (ChannelSftp) channel; + + + String remoteWorkPath = storageServer.string("REMOTE_WORK_PATH"); + channelSftp.cd(remoteWorkPath); + + //접속완료 + /////////////////////////////////////////////////////////////////// + boolean fileSearchEnd = false; + int i = 1; + while(!fileSearchEnd) { + /////////////////////////////////////////////// + // 단속ID로 단속 파일 다운로드 + + String i_char = ""; + + switch (i) { + case 1:i_char="A";break; + case 2:i_char="B";break; + case 3:i_char="C";break; + case 4:i_char="D";break; + } + + String remoteFileName = main.string("MM_CODE")+i_char+".JPG"; + String remoteFilePath = remoteWorkPath+remoteFileName; + InputStream is = channelSftp.get(remoteFilePath); + + if(is == null) { + fileSearchEnd = true; + continue; + } + + byte[] bytesOfFile = is.readAllBytes(); + is.close(); + + ///////////////////////////////////////////// + // 단속 파일 등록 + Relation rel = new FileInfo.Relation().setInfoType(Crdn.INF_TYPE).setInfoKey(crdn.getCrdnId()); + String originalFileName = remoteFileName; + DataHolder dataHolder = new FileInfo.DataHolder(rel, originalFileName, bytesOfFile); + List fileInfoList = new FileInfoFactory().createFileInfos(List.of(dataHolder)); + fileBean.create(fileInfoList); + + i++; + if(i >= 5) { + fileSearchEnd = true; + } + } - // 단속 파일 등록 - List fileInfoList = new ArrayList(); + ///////////////////////////// + //sftp연결종료 + session.disconnect(); - // - } else { // 단속 정보가 존재한다면 update?? + } else { + + // 단속 정보가 존재한다면 update?? + + + //사진? } + //등록 또는 수정 완료 + ////////////////////////// + + + + //... + } } diff --git a/src/main/resources/sql/mapper/fims/rent/finSysFtpMapper.xml b/src/main/resources/sql/mapper/fims/rent/finSysFtpMapper.xml new file mode 100644 index 00000000..a7a47443 --- /dev/null +++ b/src/main/resources/sql/mapper/fims/rent/finSysFtpMapper.xml @@ -0,0 +1,20 @@ + + + + + + + \ No newline at end of file