전기차,장애인 과태료시스템 FTP접속 추가

main
이범준 2 months ago
parent d0e4b346f5
commit 8f58dcc607

@ -89,6 +89,11 @@
<version>1.0.0-SNAPSHOT</version> <version>1.0.0-SNAPSHOT</version>
</dependency> </dependency>
<dependency>
<groupId>com.github.mwiede</groupId>
<artifactId>jsch</artifactId>
<version>0.2.20</version>
</dependency>
</dependencies> </dependencies>
<build> <build>

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

@ -1,5 +1,7 @@
package cokr.xit.fims.rent.service.bean; package cokr.xit.fims.rent.service.bean;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -7,15 +9,26 @@ import javax.annotation.Resource;
import org.springframework.stereotype.Component; 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.crypto.bean.XitAria;
import cokr.xit.base.file.FileInfo; 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.service.bean.FileBean;
import cokr.xit.base.file.web.FileInfoFactory;
import cokr.xit.fims.crdn.Crdn; import cokr.xit.fims.crdn.Crdn;
import cokr.xit.fims.crdn.service.bean.CrdnBean; import cokr.xit.fims.crdn.service.bean.CrdnBean;
import cokr.xit.fims.payer.Payer; import cokr.xit.fims.payer.Payer;
import cokr.xit.fims.payer.service.bean.PayerBean; import cokr.xit.fims.payer.service.bean.PayerBean;
import cokr.xit.fims.rent.Lsct; import cokr.xit.fims.rent.Lsct;
import cokr.xit.fims.rent.RentQuery; import cokr.xit.fims.rent.RentQuery;
import cokr.xit.fims.rent.dao.FinSysFtpMapper;
import cokr.xit.fims.rent.dao.LsctMapper; import cokr.xit.fims.rent.dao.LsctMapper;
import cokr.xit.foundation.component.AbstractBean; import cokr.xit.foundation.component.AbstractBean;
import cokr.xit.foundation.data.DataObject; import cokr.xit.foundation.data.DataObject;
@ -49,12 +62,19 @@ public class LsctBean extends AbstractBean {
@Resource(name = "payerBean") @Resource(name = "payerBean")
private PayerBean payerBean; private PayerBean payerBean;
@Resource(name = "finSysFtpMapper")
private FinSysFtpMapper finSysFtpMapper;
/** . /** .
* TB_CRDN, TB_PAYER . * TB_CRDN, TB_PAYER .
* @param req * @param req
* @return * @return
* @throws IOException
* @throws JSchException
* @throws NumberFormatException
* @throws SftpException
*/ */
public List<DataObject> getCrdnLsctList(RentQuery req) { public List<DataObject> getCrdnLsctList(RentQuery req) throws Exception {
// 기존 과태료 시스템에서 사용하던 암/복호화 함수 사용을 위해서.. // 기존 과태료 시스템에서 사용하던 암/복호화 함수 사용을 위해서..
XitAria crypto = new XitAria("xit-aria"); XitAria crypto = new XitAria("xit-aria");
@ -218,16 +238,108 @@ public class LsctBean extends AbstractBean {
throw new RuntimeException("[F] 단속 부가 대장 등록 작업에 실패하였습니다."); // 예외를 발생시켜서 DB Rollback 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<FileInfo> fileInfoList = new FileInfoFactory().createFileInfos(List.of(dataHolder));
fileBean.create(fileInfoList);
i++;
if(i >= 5) {
fileSearchEnd = true;
}
}
// 단속 파일 등록 /////////////////////////////
List<FileInfo> fileInfoList = new ArrayList<FileInfo>(); //sftp연결종료
session.disconnect();
//
} else { // 단속 정보가 존재한다면 update?? } else {
// 단속 정보가 존재한다면 update??
//사진?
} }
//등록 또는 수정 완료
//////////////////////////
//...
} }
} }

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cokr.xit.fims.rent.dao.FinSysFtpMapper">
<select id="selectFtpInfo" parameterType="map" resultType="dataObject">
/* 과태료 시스템 FTP서버 정보 조회(finSysFtpMapper.selectFtpInfo) */
SELECT SGG_CD
, TASK_SE_CD
, REMOTE_IP
, REMOTE_PORT
, REMOTE_ID
, REMOTE_PASSWORD
, REMOTE_OS
, REMOTE_WORK_PATH
FROM TB_FIN_SYS_FTP
WHERE SGG_CD = #{sggCd}
AND TASK_SE_CD = #{taskSeCd}
</select>
</mapper>
Loading…
Cancel
Save