no message
parent
21bb4ae3d7
commit
069a118de0
@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
|
||||
<classpathentry kind="src" path="src/main/java"/>
|
||||
<classpathentry kind="lib" path="lib/jsch-0.1.55.jar"/>
|
||||
<classpathentry kind="lib" path="lib/log4j-1.2.17.jar"/>
|
||||
<classpathentry kind="lib" path="lib/ojdbc6-12.1.0.1.jar"/>
|
||||
<classpathentry kind="lib" path="lib/tibero6-jdbc.jar"/>
|
||||
<classpathentry kind="output" path="build/classes"/>
|
||||
</classpath>
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,443 @@
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
public class BasicInfoDB2File {
|
||||
private static String[] strParam = {"RF_ID Insert", "발생사 Insert", "면제PL", "사전등록결제", "미닙내역PL_inser", "경차PL_insert"};
|
||||
private static String[] g_strDB = new String[4];
|
||||
|
||||
private final Logger logger = Logger.getLogger(BasicInfoDB2File .class);
|
||||
|
||||
public static void main(String[] args) {
|
||||
try{
|
||||
|
||||
// 프로퍼티 파일 위치
|
||||
String propFile = "/gpta/source-app/cfs/relay_jar/config.properties";
|
||||
//String propFile = "./config.properties";
|
||||
|
||||
// 프로퍼티 객체 생성
|
||||
Properties props = new Properties();
|
||||
|
||||
// 프로퍼티 파일 스트림에 담기
|
||||
FileInputStream fis = new FileInputStream(propFile);
|
||||
|
||||
// 프로퍼티 파일 로딩
|
||||
props.load(new java.io.BufferedInputStream(fis));
|
||||
|
||||
// 항목 읽기
|
||||
g_strDB[0] = props.getProperty("db_driver") ;
|
||||
g_strDB[1] = props.getProperty("db_connect") ;
|
||||
g_strDB[2] = props.getProperty("db_id") ;
|
||||
g_strDB[3] = props.getProperty("db_pw") ;
|
||||
|
||||
// 콘솔 출력
|
||||
System.out.println(String.format("=== DB접속정보 : %s, %s, %s", g_strDB[1], g_strDB[2], g_strDB[3])) ;
|
||||
}catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
for(int i = 0; i < strParam.length; i++)
|
||||
System.out.println(String.format("=== 실행 구분 : [%d] - %s", i, strParam[i]));
|
||||
|
||||
String runGubun = args[0];
|
||||
System.out.println("=== 실행 구분 : " + runGubun);
|
||||
try {
|
||||
BasicInfoDB2File obj = new BasicInfoDB2File();
|
||||
if(runGubun.equals("0") == true)
|
||||
obj.runInsertTbRfid();
|
||||
else if(runGubun.equals("1") == true) {
|
||||
obj.runInsertTbIssue("T_PREFIX_INFO_A");
|
||||
obj.runInsertTbIssue("T_PREFIX_INFO_B");
|
||||
}
|
||||
else if(runGubun.equals("2") == true)
|
||||
obj.runMakeExemptCsv();
|
||||
else
|
||||
System.out.println("=== 잘못된 파라미터 입력 ");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
public BasicInfoDB2File() {
|
||||
|
||||
}
|
||||
|
||||
private int getFtpData(String fileNm) {
|
||||
|
||||
FTPUtil sftp = new FTPUtil();
|
||||
|
||||
this.logger.debug("======== 다운로드 시작 : " + fileNm);
|
||||
|
||||
sftp.init("175.193.201.56", "tmax","tmax1234");
|
||||
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
map.put("return", "0");
|
||||
sftp.download2("/gpta/source-web/cfs/relay/data/", fileNm, "/gpta/source-app/cfs/relay_jar/" + fileNm, map);
|
||||
this.logger.debug("======== : " + map.get("return"));
|
||||
|
||||
int nReturn = Integer.parseInt(map.get("return"));
|
||||
if(nReturn > 0) {
|
||||
sftp.fileDelete("/gpta/source-web/cfs/relay/data/" + fileNm);
|
||||
}
|
||||
|
||||
sftp.disconnect();
|
||||
|
||||
this.logger.debug("======== 다운로드 끝 : " + nReturn);
|
||||
|
||||
return nReturn;
|
||||
}
|
||||
|
||||
//
|
||||
private Connection getOrclConn( ) throws Exception{
|
||||
Class.forName(g_strDB[0]);
|
||||
return DriverManager.getConnection(g_strDB[1], g_strDB[2], g_strDB[3]);
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("resource")
|
||||
public double runInsertTbRfid() {
|
||||
long start = System.currentTimeMillis(); // 작동 시간 측정용
|
||||
|
||||
Date time = new Date();
|
||||
SimpleDateFormat sdf = new SimpleDateFormat ("yyyyMMdd");
|
||||
|
||||
String strFile = String.format("/gpta/source-app/cfs/relay_jar/RFID_CARS_INFO_%s.CSV", sdf.format(time));
|
||||
|
||||
if(getFtpData(String.format("RFID_CARS_INFO_%s.CSV", sdf.format(time))) < 0) {
|
||||
this.logger.debug("===== 다운로드 대상 파일 없음");
|
||||
long end = System.currentTimeMillis(); // 작동시간 측정용
|
||||
|
||||
return (end - start) / 1000.0; // insertBatchFileToDB 실행에 걸린 시간
|
||||
}
|
||||
|
||||
String sql = "";
|
||||
BufferedReader br = null;
|
||||
|
||||
Connection conn = null; // 통상 Connection으로 선언
|
||||
PreparedStatement ps = null; // 통상 PreparedStatement로 선언
|
||||
try {
|
||||
this.logger.debug("======== runInsertTbRfid start");
|
||||
|
||||
conn = getOrclConn();
|
||||
conn.setAutoCommit(false); // 자동 commit 끔
|
||||
|
||||
this.logger.debug("======== runInsertTbRfid 1");
|
||||
ps = conn.prepareStatement("delete from RFID_INFO");
|
||||
ps.execute();
|
||||
|
||||
this.logger.debug("======== runInsertTbRfid 2");
|
||||
int n = 0;
|
||||
|
||||
sql = "Insert into RFID_INFO (RFID_TAG, CAR_NO, CAR_TYPE_KBN, DAMAGE_NO, WEEK_WRONG_NO, CAR_NO_HEX) ";
|
||||
sql = sql + " values (?, ?, ?, ?,?, ?) ";
|
||||
|
||||
this.logger.debug("======== runInsertTbRfid 3");
|
||||
|
||||
this.logger.debug("======== runInsertTbRfid " + sdf.format(time));
|
||||
String str1 = "";
|
||||
String str2 = "";
|
||||
String str3 = "";
|
||||
String str4 = "";
|
||||
String str5 = "";
|
||||
String str6 = "";
|
||||
|
||||
this.logger.debug("======== runInsertTbRfid 4");
|
||||
br = Files.newBufferedReader(Paths.get(strFile));
|
||||
Charset.forName("UTF-8");
|
||||
String line = "";
|
||||
|
||||
ps = (PreparedStatement) conn.prepareStatement(sql);
|
||||
while ((line = br.readLine()) != null) {
|
||||
this.logger.debug("===== " + n);
|
||||
n++;
|
||||
|
||||
if (n == 1) {
|
||||
continue;
|
||||
}
|
||||
String array[] = line.split(",", -1);
|
||||
|
||||
str1 = array[0].replaceAll("\"", "");
|
||||
str2 = array[1].replaceAll("\"", "");
|
||||
str3 = array[2].replaceAll("\"", "");
|
||||
str4 = array[3].replaceAll("\"", "");
|
||||
str5 = array[4].replaceAll("\"", "");
|
||||
str6 = PLUploader.runCarNo2Code(str2);
|
||||
|
||||
ps.setString(1, str1);
|
||||
ps.setString(2, str2);
|
||||
ps.setString(3, str3);
|
||||
ps.setInt(4 ,Integer.parseInt(str4));
|
||||
ps.setInt(5,Integer.parseInt(str5.trim()));
|
||||
ps.setString(6, str6);
|
||||
// this.logger.debug(String.format("'%s', '%s', '%s', '%s'",
|
||||
// String.format("to_date('%s','YYYYMMDDHH24MISS'", str1), str2,
|
||||
// str3, str4));
|
||||
ps.addBatch(); // OraclePreparedStatement에 batch로 완성된 SQL 추가
|
||||
ps.clearParameters(); // OraclePreparedStatement에 지정된 Parameter값 초기화
|
||||
|
||||
if (n % 100 == 0) {
|
||||
ps.executeBatch(); // 누적된 batch 실행
|
||||
ps.clearBatch(); // 누적된 batch 초기화
|
||||
conn.commit(); // Commit하여 적용
|
||||
|
||||
this.logger.debug("===== commit ok");
|
||||
} else if (n % 10 == 0) {
|
||||
this.logger.debug("===== : " + n);
|
||||
}
|
||||
} // end while
|
||||
|
||||
// 최종적으로 누적된 채 남은 batch 작업(위의 if문) 실행
|
||||
ps.executeBatch();
|
||||
ps.clearBatch();
|
||||
conn.commit();
|
||||
|
||||
|
||||
File file = new File(strFile);
|
||||
File file2 = new File(String.format("/gpta/source-app/cfs/relay_jar/data/RFID_CARS_INFO_%s.CSV", sdf.format(time)));
|
||||
if (file.exists()) {
|
||||
file.renameTo(file2);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
if(ps != null)
|
||||
ps.close();
|
||||
if(conn != null)
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
this.logger.debug("===== insert ok");
|
||||
long end = System.currentTimeMillis(); // 작동시간 측정용
|
||||
|
||||
this.logger.debug("======== runInsertTbRfid end");
|
||||
return (end - start) / 1000.0; // insertBatchFileToDB 실행에 걸린 시간
|
||||
}
|
||||
|
||||
public double runInsertTbIssue(String strFileName) {
|
||||
long start = System.currentTimeMillis(); // 작동 시간 측정용
|
||||
|
||||
Date time = new Date();
|
||||
SimpleDateFormat sdf = new SimpleDateFormat ("yyyyMMdd");
|
||||
|
||||
String strFile = String.format("/gpta/source-app/cfs/relay_jar/%s.CSV", strFileName);
|
||||
|
||||
if(getFtpData(String.format("%s.CSV", strFileName)) < 0) {
|
||||
this.logger.debug("===== 다운로드 대상 파일 없음");
|
||||
long end = System.currentTimeMillis(); // 작동시간 측정용
|
||||
|
||||
return (end - start) / 1000.0; // insertBatchFileToDB 실행에 걸린 시간
|
||||
}
|
||||
|
||||
BufferedReader br = null;
|
||||
|
||||
Connection conn = null; // 통상 Connection으로 선언
|
||||
PreparedStatement ps = null; // 통상 PreparedStatement로 선언
|
||||
try {
|
||||
this.logger.debug("======== runInsertTbIssue start");
|
||||
|
||||
conn = getOrclConn();
|
||||
conn.setAutoCommit(false); // 자동 commit 끔
|
||||
|
||||
this.logger.debug("======== runInsertTbRfid 2");
|
||||
int n = 0;
|
||||
|
||||
|
||||
StringBuffer strSQL = new StringBuffer();
|
||||
strSQL.append(" insert INTO T_PREFIX_INFO (CARD_COMP, COMP_CODE, BIN_CODE, ISS_CODE) ") ;
|
||||
strSQL.append(" VALUES (?, ?, ?, ?)") ;
|
||||
|
||||
|
||||
|
||||
this.logger.debug("======== runInsertTbRfid 3");
|
||||
|
||||
this.logger.debug("======== runInsertTbRfid " + sdf.format(time));
|
||||
String str1 = "";
|
||||
String str2 = "";
|
||||
String str3 = "";
|
||||
String str4 = "";
|
||||
|
||||
this.logger.debug("======== runInsertTbRfid 4");
|
||||
br = Files.newBufferedReader(Paths.get(strFile));
|
||||
Charset.forName("UTF-8");
|
||||
String line = "";
|
||||
|
||||
ps = (PreparedStatement) conn.prepareStatement(strSQL.toString());
|
||||
while ((line = br.readLine()) != null) {
|
||||
this.logger.debug("===== " + n);
|
||||
n++;
|
||||
|
||||
String array[] = line.split(",", -1);
|
||||
|
||||
str1 = array[0].replaceAll("\"", "");
|
||||
str2 = array[1].replaceAll("\"", "");
|
||||
str3 = array[2].replaceAll("\"", "");
|
||||
str4 = array[3].replaceAll("\"", "");
|
||||
|
||||
ps.setString(1, str1);
|
||||
ps.setString(2, str2);
|
||||
ps.setString(3, str3);
|
||||
ps.setString(4, str4);
|
||||
|
||||
try {
|
||||
this.logger.debug("======== runInsertTbRfid 5");
|
||||
ps.executeUpdate();
|
||||
}
|
||||
catch(SQLException ex) {
|
||||
this.logger.debug("======== runInsertTbRfid 6");
|
||||
}
|
||||
this.logger.debug("======== runInsertTbRfid 9");
|
||||
/*
|
||||
ps.addBatch(); // OraclePreparedStatement에 batch로 완성된 SQL 추가
|
||||
ps.clearParameters(); // OraclePreparedStatement에 지정된 Parameter값 초기화
|
||||
|
||||
if (n % 100 == 0) {
|
||||
ps.executeBatch(); // 누적된 batch 실행
|
||||
ps.clearBatch(); // 누적된 batch 초기화
|
||||
conn.commit(); // Commit하여 적용
|
||||
|
||||
this.logger.debug("===== commit ok");
|
||||
} else if (n % 10 == 0) {
|
||||
this.logger.debug("===== : " + n);
|
||||
}*/
|
||||
} // end while
|
||||
/*
|
||||
// 최종적으로 누적된 채 남은 batch 작업(위의 if문) 실행
|
||||
ps.executeBatch();
|
||||
ps.clearBatch();
|
||||
*/
|
||||
conn.commit();
|
||||
|
||||
|
||||
File file = new File(strFile);
|
||||
File file2 = new File(String.format("/gpta/source-app/cfs/relay_jar/data/%s.CSV", strFileName));
|
||||
if (file.exists()) {
|
||||
file.renameTo(file2);
|
||||
}
|
||||
|
||||
strSQL = new StringBuffer();
|
||||
strSQL.append(" UPDATE TB_CFS_TABLENOM ") ;
|
||||
strSQL.append(" set TCRD_BIN_RVS_NO = DECODE(TCRD_BIN_RVS_NO, '99', '0', TCRD_BIN_RVS_NO)+ 1, ") ;
|
||||
strSQL.append(" TCRD_BIN_UPDATE_DATE = SYSDATE, ") ;
|
||||
strSQL.append(" TCRD_BIN_APPLY_DATE = SYSDATE") ;
|
||||
|
||||
ps = conn.prepareStatement(strSQL.toString());
|
||||
ps.execute();
|
||||
conn.commit(); // Commit하여 적용
|
||||
this.logger.debug("===== update ok");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
if(ps != null)
|
||||
ps.close();
|
||||
if(conn != null)
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
this.logger.debug("===== insert ok");
|
||||
long end = System.currentTimeMillis(); // 작동시간 측정용
|
||||
|
||||
this.logger.debug("======== runInsertTbUssue end");
|
||||
return (end - start) / 1000.0; // insertBatchFileToDB 실행에 걸린 시간
|
||||
}
|
||||
|
||||
|
||||
|
||||
@SuppressWarnings("resource")
|
||||
public double runMakeExemptCsv() throws Exception {
|
||||
long start = System.currentTimeMillis(); // 작동 시간 측정용
|
||||
|
||||
String sql = "";
|
||||
|
||||
Connection conn = null; // 통상 Connection으로 선언
|
||||
PreparedStatement ps = null; // 통상 PreparedStatement로 선언
|
||||
ResultSet rs = null;
|
||||
|
||||
try {
|
||||
conn = (Connection) getOrclConn(); // Connection 생성 시 Connection으로 형변환
|
||||
|
||||
// prepareStatement를 PreparedStatement으로 형변환
|
||||
|
||||
sql= "select to_char(ENFORCE_DATE, 'YYYYMMDDHH24MISS'), CAR_NO, CARS_TYPE_ID, FILE_KIND_ID, DATA_SEQNO, YEAR, MONTH, DAY, DOCUMENT_NO, CAR_TYPE_NAME, OWNER";
|
||||
sql+= " , to_char(END_DATE, 'YYYYMMDDHH24MISS'), to_char(DOCUMENT_DATE, 'YYYYMMDDHH24MISS'), POSITION_BODY, to_char(ACCEPT_DATE, 'YYYYMMDDHH24MISS')";
|
||||
sql+= " , REPLACE_KBN, REPLACE_CAR_NO, END_KBN, REMARKS, TRANS_FILE_CREATE_YN, to_char(CREATE_DATE, 'YYYYMMDDHH24MISS')";
|
||||
sql+= ", CREATER, to_char(UPDATE_DATE, 'YYYYMMDDHH24MISS'), UPDATER, EXEMPT_KBN, COMPANY_KBN, USE_REMARK";
|
||||
sql+= " from exempt_cars_info";
|
||||
|
||||
|
||||
ps = (PreparedStatement) conn.prepareStatement(sql);
|
||||
rs = ps.executeQuery( sql );
|
||||
rs.setFetchSize(10000);
|
||||
|
||||
Statement stmt = conn.createStatement(java.sql.ResultSet.TYPE_FORWARD_ONLY,java.sql.ResultSet.CONCUR_READ_ONLY);
|
||||
stmt.setFetchSize(10000);
|
||||
rs = stmt.executeQuery( sql );
|
||||
|
||||
String str = "";
|
||||
int n = 0;
|
||||
File file = new File("./vo co9n .csv");
|
||||
FileOutputStream fos = new FileOutputStream(file);
|
||||
while (rs.next()) {
|
||||
n++;
|
||||
|
||||
str = String.format("%s,%s,%s,%s,%s,", rs.getString(1), rs.getString(2), rs.getString(3), rs.getString(4), rs.getString(5));
|
||||
str += String.format("%s,%s,%s,%s,%s,", rs.getString(6), rs.getString(7), rs.getString(8), rs.getString(9), rs.getString(10));
|
||||
str += String.format("%s,%s,%s,%s,%s,", rs.getString(11), rs.getString(12), rs.getString(13), rs.getString(14), rs.getString(15));
|
||||
str += String.format("%s,%s,%s,%s,%s,", rs.getString(16), rs.getString(17), rs.getString(18), rs.getString(19), rs.getString(20));
|
||||
str += String.format("%s,%s,%s,%s,%s,", rs.getString(21), rs.getString(22), rs.getString(23), rs.getString(24), rs.getString(25));
|
||||
str += String.format("%s,%s\r\n", rs.getString(26), rs.getString(27));
|
||||
fos.write(str.getBytes());
|
||||
|
||||
|
||||
if(n % 100 == 0) {
|
||||
System.out.println("===== : " + str);
|
||||
}
|
||||
|
||||
} // end while
|
||||
|
||||
fos.close();
|
||||
}catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}finally{
|
||||
if(rs != null)
|
||||
rs.close();
|
||||
if(ps != null)
|
||||
ps.close();
|
||||
|
||||
conn.close();
|
||||
}
|
||||
|
||||
System.out.println("===== insert ok");
|
||||
long end = System.currentTimeMillis(); // 작동시간 측정용
|
||||
return (end - start) / 1000.0; // insertBatchFileToDB 실행에 걸린 시간
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,263 @@
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
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;
|
||||
|
||||
public class FTPUtil {
|
||||
|
||||
private Session session = null;
|
||||
private Channel channel = null;
|
||||
private ChannelSftp channelSftp = null;
|
||||
|
||||
private final Logger logger = Logger.getLogger(FTPUtil.class);
|
||||
|
||||
public String mkdir(String path) throws SftpException {
|
||||
String[] pathArray = path.split("/");
|
||||
|
||||
String currentDirectory = channelSftp.pwd() + "/";
|
||||
String totPathArray = "";
|
||||
|
||||
for (int i = 0; i < pathArray.length; i++) {
|
||||
if (pathArray[i].length() == 0)
|
||||
continue;
|
||||
|
||||
totPathArray += pathArray[i] + "/";
|
||||
String currentPath = currentDirectory + totPathArray;
|
||||
|
||||
try {
|
||||
channelSftp.mkdir(currentPath);
|
||||
channelSftp.cd(currentPath);
|
||||
} catch (Exception e) {
|
||||
channelSftp.cd(currentPath);
|
||||
}
|
||||
}
|
||||
|
||||
return currentDirectory + "/" + totPathArray;
|
||||
}
|
||||
|
||||
public String mkdir2(String path) throws SftpException {
|
||||
String[] pathArray = path.split("/");
|
||||
|
||||
String currentDirectory = "/";
|
||||
String totPathArray = "";
|
||||
|
||||
for (int i = 0; i < pathArray.length; i++) {
|
||||
if (pathArray[i].length() == 0)
|
||||
continue;
|
||||
|
||||
totPathArray += pathArray[i] + "/";
|
||||
String currentPath = currentDirectory + totPathArray;
|
||||
|
||||
try {
|
||||
channelSftp.mkdir(currentPath);
|
||||
channelSftp.cd(currentPath);
|
||||
channelSftp.chmod(511, currentPath);
|
||||
} catch (Exception e) {
|
||||
channelSftp.cd(currentPath);
|
||||
}
|
||||
}
|
||||
|
||||
return currentDirectory + "/" + totPathArray;
|
||||
}
|
||||
|
||||
public void init(String host, String user, String password) {
|
||||
System.out.println(host);
|
||||
System.setProperty("java.net.preferIPv4Stack", "true");
|
||||
|
||||
System.out.println("==> Connecting to " + host);
|
||||
|
||||
// 1. JSch 객체를 생성한다.
|
||||
JSch jsch = new JSch();
|
||||
try {
|
||||
// 2. 세션 객체를 생성한다(사용자 이름, 접속할 호스트, 포트를 인자로 전달한다.)
|
||||
session = jsch.getSession(user, host, 10040);
|
||||
|
||||
// 3. 패스워드를 설정한다.
|
||||
session.setPassword(password);
|
||||
|
||||
// 4. 세션과 관련된 정보를 설정한다.
|
||||
java.util.Properties config = new java.util.Properties();
|
||||
// 4-1. 호스트 정보를 검사하지 않는다.
|
||||
config.put("StrictHostKeyChecking", "no");
|
||||
session.setConfig(config);
|
||||
|
||||
System.out.println("======== 1: ");
|
||||
// 5. 접속한다.
|
||||
session.connect();
|
||||
System.out.println("======== 2: ");
|
||||
|
||||
// 6. sftp 채널을 연다.
|
||||
channel = session.openChannel("sftp");
|
||||
|
||||
// 7. 채널에 연결한다.
|
||||
channel.connect();
|
||||
} catch (JSchException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// 8. 채널을 FTP용 채널 객체로 캐스팅한다.
|
||||
channelSftp = (ChannelSftp) channel;
|
||||
System.out.println("==> Connected to " + host);
|
||||
}
|
||||
|
||||
public void upload(String dir, File file, boolean isChmod) throws SftpException, IOException {
|
||||
FileInputStream in = null;
|
||||
|
||||
in = new FileInputStream(file);
|
||||
channelSftp.cd(dir);
|
||||
channelSftp.put(in, file.getName());
|
||||
in.close();
|
||||
|
||||
if(isChmod == true) {
|
||||
channelSftp.chmod(511, dir); // Integer.parseInt("777", 8)
|
||||
channelSftp.chmod(511, file.getName());
|
||||
}
|
||||
}
|
||||
|
||||
public void upload(String dir, File file, String old, String neo) throws SftpException, IOException {
|
||||
FileInputStream in = null;
|
||||
|
||||
in = new FileInputStream(file);
|
||||
channelSftp.cd(dir);
|
||||
channelSftp.put(in, file.getName());
|
||||
in.close();
|
||||
|
||||
channelSftp.chmod(511, dir); // Integer.parseInt("777", 8)
|
||||
channelSftp.chmod(511, old);
|
||||
channelSftp.rename(old, neo);
|
||||
}
|
||||
|
||||
public void upload2(String dir, File file, String old, String neo) throws SftpException, IOException {
|
||||
System.out.println("==> Uploading: " + file.getPath() );
|
||||
FileInputStream in = null;
|
||||
try {
|
||||
// 입력 파일을 가져온다.
|
||||
in = new FileInputStream(file);
|
||||
|
||||
// 업로드하려는 위치르 디렉토리를 변경한다.
|
||||
channelSftp.cd(dir);
|
||||
|
||||
// 파일을 업로드한다.
|
||||
channelSftp.put(in, file.getName());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
// 업로드된 파일을 닫는다.
|
||||
in.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
System.out.println("==> Uploaded: " + file.getPath());
|
||||
}
|
||||
|
||||
public void upload3(String dir, File file, String old, String neo, Map<String, String> map) throws SftpException, IOException {
|
||||
System.out.println("==> Uploading: " + file.getPath() );
|
||||
FileInputStream in = null;
|
||||
try {
|
||||
// 입력 파일을 가져온다.
|
||||
in = new FileInputStream(file);
|
||||
|
||||
System.out.println("============= 1");
|
||||
System.out.println("============= dir : " + dir);
|
||||
// 업로드하려는 위치르 디렉토리를 변경한다.
|
||||
channelSftp.cd(dir);
|
||||
|
||||
System.out.println("============= 2");
|
||||
// 파일을 업로드한다.
|
||||
channelSftp.put(in, file.getName());
|
||||
System.out.println("============= 3");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
map.put("return", "-1");
|
||||
return;
|
||||
} finally {
|
||||
try {
|
||||
// 업로드된 파일을 닫는다.
|
||||
in.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
map.put("return", "1");
|
||||
System.out.println("==> Uploaded: " + file.getPath());
|
||||
}
|
||||
|
||||
public void download2(String dir, String downloadFileName, String path, Map<String, String> map) {
|
||||
|
||||
InputStream in = null;
|
||||
FileOutputStream out = null;
|
||||
try {
|
||||
channelSftp.cd(dir);
|
||||
in = channelSftp.get(downloadFileName);
|
||||
} catch (SftpException e) {
|
||||
e.printStackTrace();
|
||||
map.put("return", "-1");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
out = new FileOutputStream(new File(path));
|
||||
|
||||
int i;
|
||||
while ((i = in.read()) != -1) {
|
||||
out.write(i);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
map.put("return", "-1");
|
||||
} finally {
|
||||
try {
|
||||
out.close();
|
||||
in.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
map.put("return", "-1");
|
||||
}
|
||||
}
|
||||
|
||||
map.put("return", "1");
|
||||
}
|
||||
|
||||
public void fileDelete(String fileName){
|
||||
try {
|
||||
channelSftp.rm(fileName);
|
||||
} catch (SftpException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public InputStream download(String dir, String fileNm) {
|
||||
InputStream in = null;
|
||||
String path = "";
|
||||
|
||||
System.out.println(path + dir);
|
||||
try {
|
||||
channelSftp.cd(path + dir);
|
||||
in = channelSftp.get(fileNm);
|
||||
|
||||
} catch (SftpException se) {
|
||||
this.logger.debug("Exception : " + se);
|
||||
}
|
||||
|
||||
return in;
|
||||
}
|
||||
|
||||
public void disconnect() {
|
||||
channelSftp.quit();
|
||||
session.disconnect();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,214 @@
|
||||
|
||||
|
||||
import java.io.File;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
||||
public class FileMove {
|
||||
|
||||
public static void main(String[] args) {
|
||||
/*
|
||||
FileMove.makeDir();
|
||||
|
||||
FileMove.makeDirSub();
|
||||
*/
|
||||
|
||||
FileMove.copyData();
|
||||
}
|
||||
|
||||
public static void copyData() {
|
||||
try {
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd"); //년월일 표시
|
||||
SimpleDateFormat sdf_4 = new SimpleDateFormat("yyyy");
|
||||
//dateFormat = new SimpleDateFormat("yyyyMM"); //년월 표시
|
||||
|
||||
Calendar cal = Calendar.getInstance();
|
||||
|
||||
cal.set ( 2019, 12-1, 31 ); //종료 날짜 셋팅
|
||||
String endDate = dateFormat.format(cal.getTime());
|
||||
|
||||
cal.set ( 2016, 1-1, 1 ); //시작 날짜 셋팅
|
||||
String startDate = dateFormat.format(cal.getTime());
|
||||
|
||||
int i = 0;
|
||||
|
||||
String pathOrg = "E:\\혼잡_센터_이미지 백업\\DOTR"; //폴더 경로
|
||||
String path = "E:\\혼잡_센터_이미지 백업\\New"; //폴더 경로
|
||||
while(!startDate.equals(endDate)){ //다르다면 실행, 동일 하다면 빠져나감
|
||||
if(i==0) { //최초 실행 출력
|
||||
System.out.println(dateFormat.format(cal.getTime()));
|
||||
}
|
||||
|
||||
startDate = dateFormat.format(cal.getTime()); //비교를 위한 값 셋팅
|
||||
// 1호터널
|
||||
copyFile(String.format("%s\\\\%s\\\\01\\\\IMAGE", pathOrg, startDate)
|
||||
, String.format("%s\\\\%s\\\\01\\\\%s", path, sdf_4.format(cal.getTime()), startDate));
|
||||
|
||||
// 3호터널
|
||||
copyFile(String.format("%s\\\\%s\\\\03\\\\IMAGE", pathOrg, startDate)
|
||||
, String.format("%s\\\\%s\\\\03\\\\%s", path, sdf_4.format(cal.getTime()), startDate));
|
||||
|
||||
//cal.add(Calendar.MONTH, 1); //1달 더해줌
|
||||
cal.add(Calendar.DATE, 1); //1일 더해줌
|
||||
i++;
|
||||
|
||||
}
|
||||
}
|
||||
catch(Exception e ) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void copyFile(String pathOrg, String path) {
|
||||
// 폴더 참조
|
||||
File original_dir = new File(pathOrg); // 절대경로
|
||||
File move_dir = new File(path);
|
||||
|
||||
if (original_dir.exists()) {
|
||||
// 폴더의 내용물 확인 -> 폴더 & 파일..
|
||||
File[] fileNames = original_dir.listFiles(); // 내용 목록 반환
|
||||
|
||||
System.out.println("--------------파일 읽기-----------------");
|
||||
|
||||
for (int i = 0; i < fileNames.length; i++) {
|
||||
if (fileNames[i].isFile()) {
|
||||
if (fileNames[i].exists()) {
|
||||
if (original_dir.exists()) {
|
||||
}
|
||||
File MoveFile = new File(move_dir, fileNames[i].getName());
|
||||
fileNames[i].renameTo(MoveFile); // 변경(이동)
|
||||
System.out.println(fileNames[i].getName()); // 폴더내에 있는 파일 리스트
|
||||
}
|
||||
}
|
||||
} // end for
|
||||
}
|
||||
|
||||
System.out.println(pathOrg); // 폴더내에 있는 파일 리스트
|
||||
System.out.println(path); // 폴더내에 있는 파일 리스트
|
||||
}
|
||||
|
||||
public static void makeDirSub() {
|
||||
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd"); //년월일 표시
|
||||
SimpleDateFormat sdf_4 = new SimpleDateFormat("yyyy");
|
||||
//dateFormat = new SimpleDateFormat("yyyyMM"); //년월 표시
|
||||
|
||||
Calendar cal = Calendar.getInstance();
|
||||
|
||||
cal.set ( 2019, 12-1, 31 ); //종료 날짜 셋팅
|
||||
String endDate = dateFormat.format(cal.getTime());
|
||||
|
||||
cal.set ( 2016, 1-1, 1 ); //시작 날짜 셋팅
|
||||
String startDate = dateFormat.format(cal.getTime());
|
||||
|
||||
int i = 0;
|
||||
|
||||
String path = "E:\\혼잡_센터_이미지 백업\\New"; //폴더 경로
|
||||
File Folder = null;
|
||||
while(!startDate.equals(endDate)){ //다르다면 실행, 동일 하다면 빠져나감
|
||||
if(i==0) { //최초 실행 출력
|
||||
System.out.println(dateFormat.format(cal.getTime()));
|
||||
}
|
||||
|
||||
startDate = dateFormat.format(cal.getTime()); //비교를 위한 값 셋팅
|
||||
|
||||
|
||||
Folder = new File(String.format("%s\\\\%s\\\\01\\\\%s", path, sdf_4.format(cal.getTime()), startDate));
|
||||
if (!Folder.exists()) {
|
||||
try{
|
||||
Folder.mkdir(); //폴더 생성합니다.
|
||||
System.out.println("폴더가 생성되었습니다.");
|
||||
}
|
||||
catch(Exception e){
|
||||
e.getStackTrace();
|
||||
}
|
||||
}else {
|
||||
System.out.println("이미 폴더가 생성되어 있습니다.");
|
||||
}
|
||||
Folder = new File(String.format("%s\\\\%s\\\\03\\\\%s", path, sdf_4.format(cal.getTime()), startDate));
|
||||
if (!Folder.exists()) {
|
||||
try{
|
||||
Folder.mkdir(); //폴더 생성합니다.
|
||||
System.out.println("폴더가 생성되었습니다.");
|
||||
}
|
||||
catch(Exception e){
|
||||
e.getStackTrace();
|
||||
}
|
||||
}else {
|
||||
System.out.println("이미 폴더가 생성되어 있습니다.");
|
||||
}
|
||||
|
||||
//cal.add(Calendar.MONTH, 1); //1달 더해줌
|
||||
cal.add(Calendar.DATE, 1); //1일 더해줌
|
||||
i++;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static void makeDir() {
|
||||
|
||||
SimpleDateFormat sdf_4 = new SimpleDateFormat ("yyyy");
|
||||
|
||||
Date dtStart = FileMove.getDate(2007, 1, 1, 0, 0, 0);
|
||||
Date dtEnd = FileMove.getDate(2015, 12, 31, 23, 59, 59);
|
||||
|
||||
long lStartYear = Long.parseLong(sdf_4.format(dtStart));
|
||||
long lEndYear = Long.parseLong(sdf_4.format(dtEnd));
|
||||
|
||||
File Folder = null;
|
||||
for(long index = lStartYear; index <= lEndYear; index++) {
|
||||
String path = "E:\\혼잡_센터_이미지 백업\\New"; //폴더 경로
|
||||
Folder = new File(String.format("%s\\\\%d", path, index));
|
||||
if (!Folder.exists()) {
|
||||
try{
|
||||
Folder.mkdir(); //폴더 생성합니다.
|
||||
System.out.println("폴더가 생성되었습니다.");
|
||||
}
|
||||
catch(Exception e){
|
||||
e.getStackTrace();
|
||||
}
|
||||
}else {
|
||||
System.out.println("이미 폴더가 생성되어 있습니다.");
|
||||
}
|
||||
|
||||
Folder = new File(String.format("%s\\\\%d\\\\01", path, index));
|
||||
if (!Folder.exists()) {
|
||||
try{
|
||||
Folder.mkdir(); //폴더 생성합니다.
|
||||
System.out.println("폴더가 생성되었습니다.");
|
||||
}
|
||||
catch(Exception e){
|
||||
e.getStackTrace();
|
||||
}
|
||||
}else {
|
||||
System.out.println("이미 폴더가 생성되어 있습니다.");
|
||||
}
|
||||
Folder = new File(String.format("%s\\\\%d\\\\03", path, index));
|
||||
if (!Folder.exists()) {
|
||||
try{
|
||||
Folder.mkdir(); //폴더 생성합니다.
|
||||
System.out.println("폴더가 생성되었습니다.");
|
||||
}
|
||||
catch(Exception e){
|
||||
e.getStackTrace();
|
||||
}
|
||||
}else {
|
||||
System.out.println("이미 폴더가 생성되어 있습니다.");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static Date getDate(int year, int month, int date, int hour, int minute, int second) {
|
||||
|
||||
Calendar cal = Calendar.getInstance();
|
||||
|
||||
cal.set(year, month-1, date, hour, minute, second);
|
||||
cal.set(Calendar.MILLISECOND, 0);
|
||||
|
||||
return cal.getTime();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,240 @@
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Statement;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
public class MakeExemptInfo {
|
||||
private static String[] g_strDB = new String[4];
|
||||
|
||||
private final Logger logger = Logger.getLogger(MakeExemptInfo .class);
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
|
||||
// 프로퍼티 파일 위치
|
||||
String propFile = "/gpta/source-app/cfs/relay_jar/config.properties";
|
||||
|
||||
// 프로퍼티 객체 생성
|
||||
Properties props = new Properties();
|
||||
|
||||
// 프로퍼티 파일 스트림에 담기
|
||||
FileInputStream fis = new FileInputStream(propFile);
|
||||
|
||||
// 프로퍼티 파일 로딩
|
||||
props.load(new java.io.BufferedInputStream(fis));
|
||||
|
||||
// 항목 읽기
|
||||
g_strDB[0] = props.getProperty("db_driver");
|
||||
g_strDB[1] = props.getProperty("db_connect");
|
||||
g_strDB[2] = props.getProperty("db_id");
|
||||
g_strDB[3] = props.getProperty("db_pw");
|
||||
|
||||
// 콘솔 출력
|
||||
System.out.println(String.format("=== DB접속정보 : %s, %s, %s", g_strDB[1], g_strDB[2], g_strDB[3]));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
MakeExemptInfo obj = new MakeExemptInfo();
|
||||
try {
|
||||
|
||||
if(args.length != 2) {
|
||||
System.err.println("총 2개의 args를 입력하지 않았습니다.");
|
||||
System.err.println("파라미터 의미 없음");
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
double d = 0.0;
|
||||
d = obj.runMakeExemptMstBin(Long.parseLong(args[0]), Long.parseLong(args[1]));
|
||||
MakeScarInfo.logger.info("=== 파일 생성 소요시간 : " + d);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
//
|
||||
private Connection getOrclConn( ) throws Exception{
|
||||
Class.forName(g_strDB[0]);
|
||||
return DriverManager.getConnection(g_strDB[1], g_strDB[2], g_strDB[3]);
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "resource", "unused" })
|
||||
private double runMakeExemptBin() throws Exception {
|
||||
long start = System.currentTimeMillis(); // 작동 시간 측정용
|
||||
|
||||
String sql = "";
|
||||
|
||||
Connection conn = null; // 통상 Connection으로 선언
|
||||
PreparedStatement ps = null; // 통상 PreparedStatement로 선언
|
||||
ResultSet rs = null;
|
||||
|
||||
try {
|
||||
conn = (Connection) getOrclConn(); // Connection 생성 시 Connection으로 형변환
|
||||
|
||||
// prepareStatement를 PreparedStatement으로 형변환
|
||||
|
||||
sql= "select * from (";
|
||||
sql= sql + "select car_no, decode(EXEMPT_KBN, '0', '01', '2', '02', '3', '03', '4', '04', '5', '05', '6', '06') as exempt_cd, car_no_hex, document_no, enforce_date, end_date from exempt_cars_info";
|
||||
sql= sql + " where to_char(enforce_date,'yyyymmdd') <= to_char(sysdate, 'yyyymmdd')";
|
||||
sql= sql + " and to_char(end_date, 'yyyymmdd') >= to_char(sysdate, 'yyyymmdd')";
|
||||
sql= sql + " and car_no_hex != '0000000000'";
|
||||
sql= sql + " order by car_no_hex";
|
||||
|
||||
ps = (PreparedStatement) conn.prepareStatement(sql);
|
||||
rs = ps.executeQuery( sql );
|
||||
rs.setFetchSize(10000);
|
||||
|
||||
Statement stmt = conn.createStatement(java.sql.ResultSet.TYPE_FORWARD_ONLY,java.sql.ResultSet.CONCUR_READ_ONLY);
|
||||
stmt.setFetchSize(10000);
|
||||
rs = stmt.executeQuery( sql );
|
||||
|
||||
String str = "";
|
||||
int n = 0;
|
||||
File file = new File("./ExemptPL.bin");
|
||||
FileOutputStream fos = new FileOutputStream(file);
|
||||
while (rs.next()) {
|
||||
n++;
|
||||
if(n % 100 == 0) {
|
||||
System.out.println("===== : " + n);
|
||||
}
|
||||
|
||||
str = String.format("%010d%s%02d%s", n, "00", Integer.parseInt(rs.getString(2)), rs.getString(3));
|
||||
fos.write(str.getBytes());
|
||||
} // end while
|
||||
|
||||
fos.close();
|
||||
}catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}finally{
|
||||
if(rs != null)
|
||||
rs.close();
|
||||
if(ps != null)
|
||||
ps.close();
|
||||
|
||||
conn.close();
|
||||
}
|
||||
|
||||
System.out.println("===== insert ok");
|
||||
long end = System.currentTimeMillis(); // 작동시간 측정용
|
||||
return (end - start) / 1000.0; // insertBatchFileToDB 실행에 걸린 시간
|
||||
}
|
||||
|
||||
private double runMakeExemptMstBin(long nStart, long nEnd) throws Exception {
|
||||
long start = System.currentTimeMillis(); // 작동 시간 측정용
|
||||
|
||||
Connection conn = null; // 통상 Connection으로 선언
|
||||
PreparedStatement ps = null; // 통상 PreparedStatement로 선언
|
||||
ResultSet rs = null;
|
||||
|
||||
try {
|
||||
conn = (Connection) getOrclConn(); // Connection 생성 시 Connection으로 형변환
|
||||
|
||||
// prepareStatement를 PreparedStatement으로 형변환
|
||||
|
||||
StringBuffer strSQL = new StringBuffer();
|
||||
strSQL.append(" SELECT LPAD(ROWNUM, 10, '0') AS SEQ, '00' AS REG, NVL(DIV, '01') AS DIV, LPAD(DECODE(FUN_CAR_CODE(NVL(CAR_NO,'0')),'없음','0', '숫자오류2', '0', '숫자오류3', '0', FUN_CAR_CODE(NVL(CAR_NO,'0'))), 10, '0') AS CARCODE");
|
||||
strSQL.append(" FROM");
|
||||
strSQL.append(" (") ;
|
||||
strSQL.append(" SELECT CAR_NO, decode(EXEMPT_KBN, '0', '01', '2', '02', '3', '03', '4', '04', '5', '05', '6', '06') AS DIV");
|
||||
strSQL.append(" FROM EXEMPT_CARS_INFO A");
|
||||
strSQL.append(" WHERE ENFORCE_DATE <= SYSDATE");
|
||||
strSQL.append(" AND END_DATE >= SYSDATE");
|
||||
strSQL.append(" ORDER BY CAR_NO");
|
||||
strSQL.append(" )") ;
|
||||
|
||||
|
||||
logger.info(strSQL.toString());
|
||||
|
||||
Statement stmt = conn.createStatement(java.sql.ResultSet.TYPE_FORWARD_ONLY,java.sql.ResultSet.CONCUR_READ_ONLY);
|
||||
stmt.setFetchSize(10000);
|
||||
rs = stmt.executeQuery( strSQL.toString() );
|
||||
|
||||
String str = "";
|
||||
int n = 0;
|
||||
File file = new File("/gpta/source-app/cfs/relay_jar/data/IMMCARNO");
|
||||
FileOutputStream fos = new FileOutputStream(file);
|
||||
while (rs.next()) {
|
||||
n++;
|
||||
if(n % 10000 == 0) {
|
||||
logger.info("===== : " + n);
|
||||
}
|
||||
|
||||
str = String.format("%s%s%s%s", rs.getString(1), rs.getString(2), rs.getString(3), rs.getString(4));
|
||||
fos.write(str.getBytes());
|
||||
} // end while
|
||||
|
||||
fos.close();
|
||||
|
||||
logger.info( strSQL.toString());
|
||||
|
||||
if(setFtpData(file, "IMMCARNO") < 0) {
|
||||
this.logger.debug("===== 업로드 대상 파일 없음(IMMCARNO)");
|
||||
long end = System.currentTimeMillis(); // 작동시간 측정용
|
||||
|
||||
return (end - start) / 1000.0; // insertBatchFileToDB 실행에 걸린 시간
|
||||
}
|
||||
|
||||
String sql = "update TB_CFS_MST_FLAG set EXEMPT_FLAG = '1', EXEMPT_SENDTIME = SYSDATE ";
|
||||
ps = (PreparedStatement) conn.prepareStatement(sql);
|
||||
ps.executeUpdate();
|
||||
conn.commit();
|
||||
|
||||
}catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}finally{
|
||||
if(rs != null)
|
||||
rs.close();
|
||||
if(ps != null)
|
||||
ps.close();
|
||||
|
||||
conn.close();
|
||||
}
|
||||
|
||||
logger.info("===== make ok");
|
||||
long end = System.currentTimeMillis(); // 작동시간 측정용
|
||||
return (end - start) / 1000.0; // insertBatchFileToDB 실행에 걸린 시간
|
||||
}
|
||||
|
||||
private int setFtpData(File file, String fileNm) {
|
||||
|
||||
FTPUtil sftp = new FTPUtil();
|
||||
|
||||
this.logger.debug("======== 업로드 시작 : " + fileNm);
|
||||
|
||||
sftp.init("175.193.201.56", "tmax","tmax1234");
|
||||
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
map.put("return", "0");
|
||||
|
||||
try {
|
||||
sftp.upload3("/gpta/source-web/cfs/relay/data/", file, fileNm, fileNm, map);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
this.logger.debug("======== : " + map.get("return"));
|
||||
|
||||
int nReturn = Integer.parseInt(map.get("return"));
|
||||
|
||||
sftp.disconnect();
|
||||
|
||||
this.logger.debug("======== 업로드 끝 : " + nReturn);
|
||||
|
||||
return nReturn;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,201 @@
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.sql.CallableStatement;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Statement;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.tmax.tibero.TbTypes;
|
||||
|
||||
public class MakePreregistrInfo {
|
||||
private static String[] g_strDB = new String[4];
|
||||
|
||||
public static final Logger logger = Logger.getLogger(MakePreregistrInfo .class);
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
|
||||
// 프로퍼티 파일 위치
|
||||
String propFile = "/gpta/source-app/cfs/relay_jar/config.properties";
|
||||
|
||||
// 프로퍼티 객체 생성
|
||||
Properties props = new Properties();
|
||||
|
||||
// 프로퍼티 파일 스트림에 담기
|
||||
FileInputStream fis = new FileInputStream(propFile);
|
||||
|
||||
// 프로퍼티 파일 로딩
|
||||
props.load(new java.io.BufferedInputStream(fis));
|
||||
|
||||
// 항목 읽기
|
||||
g_strDB[0] = props.getProperty("db_driver");
|
||||
g_strDB[1] = props.getProperty("db_connect");
|
||||
g_strDB[2] = props.getProperty("db_id");
|
||||
g_strDB[3] = props.getProperty("db_pw");
|
||||
|
||||
// 콘솔 출력
|
||||
MakePreregistrInfo.logger.info(String.format("=== DB접속정보 : %s, %s, %s", g_strDB[1], g_strDB[2], g_strDB[3]));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
MakePreregistrInfo obj = new MakePreregistrInfo();
|
||||
try {
|
||||
|
||||
if(args.length != 3) {
|
||||
System.err.println("총 3개의 args를 입력하지 않았습니다.");
|
||||
System.err.println("sFileDir, sFileName");
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
double d = 0.0;
|
||||
d = obj.runMakeScarMstBin(Long.parseLong(args[0]), Long.parseLong(args[1]), args[2]);
|
||||
MakePreregistrInfo.logger.info("=== 파일 생성 소요시간 : " + d);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
//
|
||||
private Connection getOrclConn( ) throws Exception{
|
||||
Class.forName(g_strDB[0]);
|
||||
return DriverManager.getConnection(g_strDB[1], g_strDB[2], g_strDB[3]);
|
||||
}
|
||||
|
||||
private double runMakeScarMstBin(long nStart, long nEnd, String strWorkDate) throws Exception {
|
||||
long start = System.currentTimeMillis(); // 작동 시간 측정용
|
||||
|
||||
|
||||
Connection conn = null; // 통상 Connection으로 선언
|
||||
PreparedStatement ps = null; // 통상 PreparedStatement로 선언
|
||||
ResultSet rs = null;
|
||||
|
||||
try {
|
||||
conn = (Connection) getOrclConn(); // Connection 생성 시 Connection으로 형변환
|
||||
|
||||
|
||||
CallableStatement cs = conn.prepareCall("call SP_ADVREDUCE_CHK(?,?)");
|
||||
// 입력 파라메터
|
||||
cs.setString(1, strWorkDate);
|
||||
// 출력 파라메터
|
||||
cs.registerOutParameter(2, TbTypes.NUMERIC);
|
||||
// 실행
|
||||
cs.execute();
|
||||
|
||||
int out_ret = cs.getInt(2);
|
||||
System.out.println("======== " + out_ret);
|
||||
cs.close();
|
||||
|
||||
if(out_ret != 1 ) {
|
||||
logger.debug("===== SP_ADVREDUCE_CHK 오류 : " + out_ret);
|
||||
long end = System.currentTimeMillis(); // 작동시간 측정용
|
||||
|
||||
|
||||
String sql = "update TB_CFS_MST_FLAG set PRP_FLAG = '1', PRP_SENDTIME = SYSDATE ";
|
||||
ps = (PreparedStatement) conn.prepareStatement(sql);
|
||||
ps.executeUpdate();
|
||||
ps.close();
|
||||
|
||||
return (end - start) / 1000.0; // insertBatchFileToDB 실행에 걸린 시간
|
||||
}
|
||||
|
||||
// prepareStatement를 PreparedStatement으로 형변환
|
||||
StringBuffer strSQL = new StringBuffer();
|
||||
strSQL.append(" SELECT /*+ index_desc(A IDX_SRCH_PRP_MST) */") ;
|
||||
strSQL.append(" LPAD(PRP_INFO_SEQ, 10, '0') AS SEQ, '00' AS REG, NVL(EXMP_CD,'01') AS DIV, LPAD(DECODE(FUN_CAR_CODE(NVL(CAR_NO,'0')),'없음','0', '숫자오류2', '0', '숫자오류3', '0', FUN_CAR_CODE(NVL(CAR_NO,'0'))), 10, '0') AS CARCODE") ;
|
||||
strSQL.append(" FROM TB_CFS_PRP_INFO_MST A") ;
|
||||
strSQL.append(" WHERE SECSN_YN ='N'") ;
|
||||
strSQL.append(" ORDER BY PRP_INFO_SEQ") ;
|
||||
|
||||
logger.info(strSQL.toString());
|
||||
|
||||
Statement stmt = conn.createStatement(java.sql.ResultSet.TYPE_FORWARD_ONLY,java.sql.ResultSet.CONCUR_READ_ONLY);
|
||||
stmt.setFetchSize(10000);
|
||||
rs = stmt.executeQuery( strSQL.toString() );
|
||||
|
||||
String str = "";
|
||||
int n = 0;
|
||||
File file = new File("/gpta/source-app/cfs/relay_jar/data/ADVMST");
|
||||
FileOutputStream fos = new FileOutputStream(file);
|
||||
while (rs.next()) {
|
||||
n++;
|
||||
if(n % 10000 == 0) {
|
||||
logger.info("===== : " + n);
|
||||
}
|
||||
|
||||
str = String.format("%s%s%s%s", rs.getString(1), rs.getString(2), rs.getString(3), rs.getString(4));
|
||||
fos.write(str.getBytes());
|
||||
} // end while
|
||||
|
||||
fos.close();
|
||||
|
||||
logger.info(strSQL.toString());
|
||||
|
||||
if(setFtpData(file, "ADVMST") < 0) {
|
||||
logger.debug("===== 업로드 대상 파일 없음(ADVMST)");
|
||||
long end = System.currentTimeMillis(); // 작동시간 측정용
|
||||
|
||||
return (end - start) / 1000.0; // insertBatchFileToDB 실행에 걸린 시간
|
||||
}
|
||||
|
||||
String sql = "update TB_CFS_MST_FLAG set PRP_FLAG = '1', PRP_SENDTIME = SYSDATE, PRP_CHG_TIME = SYSDATE ";
|
||||
ps = (PreparedStatement) conn.prepareStatement(sql);
|
||||
ps.executeUpdate();
|
||||
conn.commit();
|
||||
|
||||
}catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}finally{
|
||||
if(rs != null)
|
||||
rs.close();
|
||||
if(ps != null)
|
||||
ps.close();
|
||||
|
||||
conn.close();
|
||||
}
|
||||
|
||||
logger.info("===== make ok");
|
||||
long end = System.currentTimeMillis(); // 작동시간 측정용
|
||||
return (end - start) / 1000.0; // insertBatchFileToDB 실행에 걸린 시간
|
||||
}
|
||||
|
||||
private int setFtpData(File file, String fileNm) {
|
||||
|
||||
FTPUtil sftp = new FTPUtil();
|
||||
|
||||
logger.debug("======== 업로드 시작 : " + fileNm);
|
||||
|
||||
sftp.init("175.193.201.56", "tmax","tmax1234");
|
||||
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
map.put("return", "0");
|
||||
|
||||
try {
|
||||
sftp.upload3("/gpta/source-web/cfs/relay/data/", file, fileNm, fileNm, map);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
logger.debug("======== : " + map.get("return"));
|
||||
|
||||
int nReturn = Integer.parseInt(map.get("return"));
|
||||
|
||||
sftp.disconnect();
|
||||
|
||||
logger.debug("======== 업로드 끝 : " + nReturn);
|
||||
|
||||
return nReturn;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,182 @@
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Statement;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
public class MakeRfidnfo {
|
||||
private static String[] g_strDB = new String[4];
|
||||
|
||||
public static final Logger logger = Logger.getLogger(MakeRfidnfo .class);
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
|
||||
// 프로퍼티 파일 위치
|
||||
String propFile = "/gpta/source-app/cfs/relay_jar/config.properties";
|
||||
|
||||
// 프로퍼티 객체 생성
|
||||
Properties props = new Properties();
|
||||
|
||||
// 프로퍼티 파일 스트림에 담기
|
||||
FileInputStream fis = new FileInputStream(propFile);
|
||||
|
||||
// 프로퍼티 파일 로딩
|
||||
props.load(new java.io.BufferedInputStream(fis));
|
||||
|
||||
// 항목 읽기
|
||||
g_strDB[0] = props.getProperty("db_driver");
|
||||
g_strDB[1] = props.getProperty("db_connect");
|
||||
g_strDB[2] = props.getProperty("db_id");
|
||||
g_strDB[3] = props.getProperty("db_pw");
|
||||
|
||||
// 콘솔 출력
|
||||
MakeRfidnfo.logger.info(String.format("=== DB접속정보 : %s, %s, %s", g_strDB[1], g_strDB[2], g_strDB[3]));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
MakeRfidnfo obj = new MakeRfidnfo();
|
||||
try {
|
||||
|
||||
if(args.length != 2) {
|
||||
System.err.println("총 2개의 args를 입력하지 않았습니다.");
|
||||
System.err.println("sFileDir, sFileName");
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
double d = 0.0;
|
||||
d = obj.runMakeRfidMstBin(Long.parseLong(args[0]), Long.parseLong(args[1]));
|
||||
MakeRfidnfo.logger.info("=== 파일 생성 소요시간 : " + d);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
//
|
||||
private Connection getOrclConn( ) throws Exception{
|
||||
Class.forName(g_strDB[0]);
|
||||
return DriverManager.getConnection(g_strDB[1], g_strDB[2], g_strDB[3]);
|
||||
}
|
||||
|
||||
private double runMakeRfidMstBin(long nStart, long nEnd) throws Exception {
|
||||
long start = System.currentTimeMillis(); // 작동 시간 측정용
|
||||
|
||||
|
||||
Connection conn = null; // 통상 Connection으로 선언
|
||||
PreparedStatement ps = null; // 통상 PreparedStatement로 선언
|
||||
ResultSet rs = null;
|
||||
|
||||
try {
|
||||
conn = (Connection) getOrclConn(); // Connection 생성 시 Connection으로 형변환
|
||||
|
||||
// prepareStatement를 PreparedStatement으로 형변환
|
||||
StringBuffer strSQL = new StringBuffer();
|
||||
strSQL.append(" SELECT ") ;
|
||||
strSQL.append(" LPAD(ROWNUM, 10, '0') AS SEQ, '00' AS REG, SUBSTR(CAR_TYPE_KBN, 4, 1) AS DIV, LPAD(RFID_TAG, 24, '0') AS TAG, ") ;
|
||||
strSQL.append(" LPAD(DECODE(FUN_CAR_CODE(NVL(CAR_NO,'0')),'없음','0', FUN_CAR_CODE(NVL(CAR_NO,'0'))), 10, '0') AS CAR, ") ;
|
||||
strSQL.append(" NVL(DAMAGE_NO,'0') AS NON, NVL(WEEK_WRONG_NO,'0') AS VIO ") ;
|
||||
strSQL.append(" FROM") ;
|
||||
strSQL.append("(") ;
|
||||
strSQL.append(" SELECT /*+ INDEX_ASC(A IDX01_RFID_INFO) */ A.* ") ;
|
||||
strSQL.append(" FROM RFID_INFO A") ;
|
||||
strSQL.append(" WHERE A.CAR_NO NOT IN ('00x0000', '01괘0006')") ;
|
||||
strSQL.append(" and car_type_kbn in ('000E', '000F')") ;
|
||||
strSQL.append(")") ;
|
||||
|
||||
|
||||
logger.info(strSQL.toString());
|
||||
|
||||
Statement stmt = conn.createStatement(java.sql.ResultSet.TYPE_FORWARD_ONLY,java.sql.ResultSet.CONCUR_READ_ONLY);
|
||||
stmt.setFetchSize(10000);
|
||||
rs = stmt.executeQuery( strSQL.toString() );
|
||||
|
||||
String str = "";
|
||||
int n = 0;
|
||||
File file = new File("/gpta/source-app/cfs/relay_jar/data/IMMRFID");
|
||||
FileOutputStream fos = new FileOutputStream(file);
|
||||
while (rs.next()) {
|
||||
n++;
|
||||
if(n % 10000 == 0) {
|
||||
logger.info("===== : " + n);
|
||||
}
|
||||
|
||||
str = String.format("%s%s%s%s%s%s%s", rs.getString(1), rs.getString(2), rs.getString(3), rs.getString(4), rs.getString(5), rs.getString(6), rs.getString(7));
|
||||
fos.write(str.getBytes());
|
||||
} // end while
|
||||
|
||||
fos.close();
|
||||
|
||||
logger.info(strSQL.toString());
|
||||
|
||||
if(setFtpData(file, "IMMRFID") < 0) {
|
||||
logger.debug("===== 업로드 대상 파일 없음(REDCARNO)");
|
||||
long end = System.currentTimeMillis(); // 작동시간 측정용
|
||||
|
||||
return (end - start) / 1000.0; // insertBatchFileToDB 실행에 걸린 시간
|
||||
}
|
||||
|
||||
String sql = "update TB_CFS_MST_FLAG set RFID_FLAG = '1', RFID_SENDTIME = SYSDATE ";
|
||||
ps = (PreparedStatement) conn.prepareStatement(sql);
|
||||
ps.executeUpdate();
|
||||
conn.commit();
|
||||
|
||||
}catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}finally{
|
||||
if(rs != null)
|
||||
rs.close();
|
||||
if(ps != null)
|
||||
ps.close();
|
||||
|
||||
conn.close();
|
||||
}
|
||||
|
||||
logger.info("===== make ok");
|
||||
long end = System.currentTimeMillis(); // 작동시간 측정용
|
||||
return (end - start) / 1000.0; // insertBatchFileToDB 실행에 걸린 시간
|
||||
}
|
||||
|
||||
private int setFtpData(File file, String fileNm) {
|
||||
|
||||
FTPUtil sftp = new FTPUtil();
|
||||
|
||||
logger.debug("======== 업로드 시작 : " + fileNm);
|
||||
|
||||
sftp.init("175.193.201.56", "tmax","tmax1234");
|
||||
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
map.put("return", "0");
|
||||
|
||||
try {
|
||||
sftp.upload3("/gpta/source-web/cfs/relay/data/", file, fileNm, fileNm, map);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
logger.debug("======== : " + map.get("return"));
|
||||
|
||||
int nReturn = Integer.parseInt(map.get("return"));
|
||||
|
||||
sftp.disconnect();
|
||||
|
||||
logger.debug("======== 업로드 끝 : " + nReturn);
|
||||
|
||||
return nReturn;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,176 @@
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Statement;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
public class MakeScarInfo {
|
||||
private static String[] g_strDB = new String[4];
|
||||
|
||||
public static final Logger logger = Logger.getLogger(MakeScarInfo .class);
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
|
||||
// 프로퍼티 파일 위치
|
||||
String propFile = "/gpta/source-app/cfs/relay_jar/config.properties";
|
||||
|
||||
// 프로퍼티 객체 생성
|
||||
Properties props = new Properties();
|
||||
|
||||
// 프로퍼티 파일 스트림에 담기
|
||||
FileInputStream fis = new FileInputStream(propFile);
|
||||
|
||||
// 프로퍼티 파일 로딩
|
||||
props.load(new java.io.BufferedInputStream(fis));
|
||||
|
||||
// 항목 읽기
|
||||
g_strDB[0] = props.getProperty("db_driver");
|
||||
g_strDB[1] = props.getProperty("db_connect");
|
||||
g_strDB[2] = props.getProperty("db_id");
|
||||
g_strDB[3] = props.getProperty("db_pw");
|
||||
|
||||
// 콘솔 출력
|
||||
MakeScarInfo.logger.info(String.format("=== DB접속정보 : %s, %s, %s", g_strDB[1], g_strDB[2], g_strDB[3]));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
MakeScarInfo obj = new MakeScarInfo();
|
||||
try {
|
||||
|
||||
if(args.length != 2) {
|
||||
System.err.println("총 2개의 args를 입력하지 않았습니다.");
|
||||
System.err.println("sFileDir, sFileName");
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
double d = 0.0;
|
||||
d = obj.runMakeScarMstBin(Long.parseLong(args[0]), Long.parseLong(args[1]));
|
||||
MakeScarInfo.logger.info("=== 파일 생성 소요시간 : " + d);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
//
|
||||
private Connection getOrclConn( ) throws Exception{
|
||||
Class.forName(g_strDB[0]);
|
||||
return DriverManager.getConnection(g_strDB[1], g_strDB[2], g_strDB[3]);
|
||||
}
|
||||
|
||||
private double runMakeScarMstBin(long nStart, long nEnd) throws Exception {
|
||||
long start = System.currentTimeMillis(); // 작동 시간 측정용
|
||||
|
||||
|
||||
Connection conn = null; // 통상 Connection으로 선언
|
||||
PreparedStatement ps = null; // 통상 PreparedStatement로 선언
|
||||
ResultSet rs = null;
|
||||
|
||||
try {
|
||||
conn = (Connection) getOrclConn(); // Connection 생성 시 Connection으로 형변환
|
||||
|
||||
// prepareStatement를 PreparedStatement으로 형변환
|
||||
|
||||
StringBuffer strSQL = new StringBuffer();
|
||||
strSQL.append(" SELECT LPAD(SCAR_SEQ, 10, '0') AS SEQ, '00' AS REG, DECODE(REDU_CD, '00', '01', '02') AS DIV, LPAD(DECODE(FUN_CAR_CODE(NVL(CAR_NO,'0')),'없음','0', '숫자오류2', '0', '숫자오류3', '0', FUN_CAR_CODE(NVL(CAR_NO,'0'))), 10, '0') AS CARCODE") ;
|
||||
strSQL.append(" FROM TB_CFS_SCAR_PL_MST A") ;
|
||||
strSQL.append(" WHERE REDU_CD IN ('00')") ;
|
||||
strSQL.append(" AND MODI_YN = 'N'") ;
|
||||
strSQL.append(" ORDER BY SCAR_SEQ") ;
|
||||
|
||||
logger.info(strSQL.toString());
|
||||
|
||||
Statement stmt = conn.createStatement(java.sql.ResultSet.TYPE_FORWARD_ONLY,java.sql.ResultSet.CONCUR_READ_ONLY);
|
||||
stmt.setFetchSize(10000);
|
||||
rs = stmt.executeQuery( strSQL.toString() );
|
||||
|
||||
String str = "";
|
||||
int n = 0;
|
||||
File file = new File("/gpta/source-app/cfs/relay_jar/data/REDCARNO");
|
||||
FileOutputStream fos = new FileOutputStream(file);
|
||||
while (rs.next()) {
|
||||
n++;
|
||||
if(n % 10000 == 0) {
|
||||
logger.info("===== : " + n);
|
||||
}
|
||||
|
||||
str = String.format("%s%s%s%s", rs.getString(1), rs.getString(2), rs.getString(3), rs.getString(4));
|
||||
fos.write(str.getBytes());
|
||||
} // end while
|
||||
|
||||
fos.close();
|
||||
|
||||
logger.info(strSQL.toString());
|
||||
|
||||
if(setFtpData(file, "REDCARNO") < 0) {
|
||||
logger.debug("===== 업로드 대상 파일 없음(REDCARNO)");
|
||||
long end = System.currentTimeMillis(); // 작동시간 측정용
|
||||
|
||||
return (end - start) / 1000.0; // insertBatchFileToDB 실행에 걸린 시간
|
||||
}
|
||||
|
||||
String sql = "update TB_CFS_MST_FLAG set RED_FLAG = '1', RED_SENDTIME = SYSDATE ";
|
||||
ps = (PreparedStatement) conn.prepareStatement(sql);
|
||||
ps.executeUpdate();
|
||||
conn.commit();
|
||||
|
||||
}catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}finally{
|
||||
if(rs != null)
|
||||
rs.close();
|
||||
if(ps != null)
|
||||
ps.close();
|
||||
|
||||
conn.close();
|
||||
}
|
||||
|
||||
logger.info("===== make ok");
|
||||
long end = System.currentTimeMillis(); // 작동시간 측정용
|
||||
return (end - start) / 1000.0; // insertBatchFileToDB 실행에 걸린 시간
|
||||
}
|
||||
|
||||
private int setFtpData(File file, String fileNm) {
|
||||
|
||||
FTPUtil sftp = new FTPUtil();
|
||||
|
||||
logger.debug("======== 업로드 시작 : " + fileNm);
|
||||
|
||||
sftp.init("175.193.201.56", "tmax","tmax1234");
|
||||
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
map.put("return", "0");
|
||||
|
||||
try {
|
||||
sftp.upload3("/gpta/source-web/cfs/relay/data/", file, fileNm, fileNm, map);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
logger.debug("======== : " + map.get("return"));
|
||||
|
||||
int nReturn = Integer.parseInt(map.get("return"));
|
||||
|
||||
sftp.disconnect();
|
||||
|
||||
logger.debug("======== 업로드 끝 : " + nReturn);
|
||||
|
||||
return nReturn;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,269 @@
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class PLUploader {
|
||||
public static boolean isNumeric(String s) {
|
||||
return s.matches("-?\\d+(\\.\\d+)?");
|
||||
}
|
||||
|
||||
public static String runCarNo2Code(String strCarNo) {
|
||||
strCarNo = strCarNo.trim();
|
||||
strCarNo = strCarNo.replaceAll(" ", "");
|
||||
|
||||
if (strCarNo.contains("0000"))
|
||||
return "0000000000";
|
||||
|
||||
// System.out.println("====" + strCarNo + "===");
|
||||
// System.out.println("==== " + nCarNoLength);
|
||||
int nCarNoLength = strCarNo.length();
|
||||
|
||||
if (nCarNoLength < 7 || nCarNoLength > 9)
|
||||
return "0000000000";
|
||||
|
||||
if (nCarNoLength == 9 && PLUploader.isNumeric(strCarNo.substring(2, 4)) == false) {
|
||||
return "0000000000";
|
||||
}
|
||||
|
||||
if (PLUploader.isNumeric(strCarNo.substring(strCarNo.length()-4, strCarNo.length())) == false) {
|
||||
return "0000000000";
|
||||
}
|
||||
short b1, b2, b3, b4, b5;
|
||||
// 1. 외교 관련
|
||||
if (strCarNo.indexOf("외교") >= 0 || strCarNo.indexOf("영사") >= 0 || strCarNo.indexOf("국기") >= 0) {
|
||||
String strCarNoF = strCarNo.replaceAll("-", "");
|
||||
|
||||
b1 = getRegion("외교");
|
||||
b2 = Short.parseShort(strCarNoF.substring(2, 4), 16);
|
||||
b3 = getCarClass("외");
|
||||
b4 = Short.parseShort(strCarNoF.substring(4, 6), 16);
|
||||
b5 = Short.parseShort(strCarNoF.substring(6, 8), 16);
|
||||
}
|
||||
// 2. 비사업자용
|
||||
else if (nCarNoLength == 7) { // 35도2345
|
||||
b1 = getRegion("전국");
|
||||
String temp = strCarNo.substring(0, 2);
|
||||
if (PLUploader.isNumeric(temp) == false) {
|
||||
return "0000000000";
|
||||
}
|
||||
b2 = Short.parseShort(strCarNo.substring(0, 2), 16);
|
||||
b3 = getCarClass(strCarNo.substring(2, 3));
|
||||
b4 = Short.parseShort(strCarNo.substring(3, 5), 16);
|
||||
b5 = Short.parseShort(strCarNo.substring(5, 7), 16);
|
||||
|
||||
if (b1 == 256)
|
||||
return "0000000000";
|
||||
|
||||
if (b3 < 0)
|
||||
return "0000000000";
|
||||
} else if (nCarNoLength == 8) { // 135도2345
|
||||
// 예외처리
|
||||
String temp = strCarNo.substring(0, 3);
|
||||
if (PLUploader.isNumeric(temp) == true) {
|
||||
b1 = getRegion(strCarNo.substring(0, 1));
|
||||
b2 = Short.parseShort(strCarNo.substring(1, 3), 16);
|
||||
b3 = getCarClass(strCarNo.substring(3, 4));
|
||||
b4 = Short.parseShort(strCarNo.substring(4, 6), 16);
|
||||
b5 = Short.parseShort(strCarNo.substring(6, 8), 16);
|
||||
|
||||
if (b1 == 256)
|
||||
return "0000000000";
|
||||
|
||||
if (b3 < 0)
|
||||
return "0000000000";
|
||||
} else {
|
||||
temp = strCarNo.substring(0, 2);
|
||||
if (PLUploader.isNumeric(temp) ==true) {
|
||||
return "0000000000";
|
||||
}
|
||||
|
||||
b1 = getRegion(strCarNo.substring(0, 2));
|
||||
if (PLUploader.isNumeric(strCarNo.substring(2, 3)) ==false) {
|
||||
return "0000000000";
|
||||
}
|
||||
b2 = Short.parseShort(strCarNo.substring(2, 3), 16);
|
||||
b3 = getCarClass(strCarNo.substring(3, 4));
|
||||
b4 = Short.parseShort(strCarNo.substring(4, 6), 16);
|
||||
b5 = Short.parseShort(strCarNo.substring(6, 8), 16);
|
||||
|
||||
if (b1 == 256)
|
||||
return "0000000000";
|
||||
|
||||
if (b3 < 0)
|
||||
return "0000000000";
|
||||
}
|
||||
}
|
||||
// 3. 사업자용
|
||||
else {
|
||||
b1 = getRegion(strCarNo.substring(0, 2));
|
||||
b2 = Short.parseShort(strCarNo.substring(2, 4), 16);
|
||||
b3 = getCarClass(strCarNo.substring(4, 5));
|
||||
b4 = Short.parseShort(strCarNo.substring(5, 7), 16);
|
||||
b5 = Short.parseShort(strCarNo.substring(7, 9), 16);
|
||||
|
||||
if (b1 == 256)
|
||||
return "0000000000";
|
||||
|
||||
if (b3 < 0)
|
||||
return "0000000000";
|
||||
}
|
||||
|
||||
return String.format("%02X%02X%02X%02X%02X", b1, b2, b3, b4, b5);
|
||||
}
|
||||
|
||||
private static short getRegion(String str) {
|
||||
|
||||
Map<String, Object> mapRegion = new HashMap<>();
|
||||
|
||||
mapRegion.put("서울", "00");
|
||||
mapRegion.put("부산", "01");
|
||||
mapRegion.put("인천", "02");
|
||||
mapRegion.put("대구", "03");
|
||||
mapRegion.put("광주", "04");
|
||||
mapRegion.put("대전", "05");
|
||||
mapRegion.put("경기", "06");
|
||||
mapRegion.put("강원", "07");
|
||||
mapRegion.put("충북", "08");
|
||||
mapRegion.put("충남", "09");
|
||||
mapRegion.put("전북", "10");
|
||||
mapRegion.put("전남", "11");
|
||||
mapRegion.put("경북", "12");
|
||||
mapRegion.put("경남", "13");
|
||||
mapRegion.put("제주", "14");
|
||||
mapRegion.put("울산", "15");
|
||||
mapRegion.put("세종", "16");
|
||||
|
||||
mapRegion.put("1", "81");
|
||||
mapRegion.put("2", "82");
|
||||
mapRegion.put("3", "83");
|
||||
mapRegion.put("4", "84");
|
||||
mapRegion.put("5", "85");
|
||||
mapRegion.put("6", "86");
|
||||
mapRegion.put("7", "87");
|
||||
mapRegion.put("8", "88");
|
||||
mapRegion.put("9", "89");
|
||||
|
||||
mapRegion.put("외교", "98");
|
||||
|
||||
mapRegion.put("전국", "99");
|
||||
|
||||
if (mapRegion.get(str) == null)
|
||||
return Short.parseShort("100", 16);
|
||||
|
||||
return Short.parseShort((String) mapRegion.get(str), 16);
|
||||
}
|
||||
|
||||
private static short getCarClass(String str) {
|
||||
|
||||
Map<String, Object> mapCarClass = new HashMap<>();
|
||||
mapCarClass.put("가", "00");
|
||||
mapCarClass.put("나", "01");
|
||||
mapCarClass.put("다", "02");
|
||||
mapCarClass.put("라", "03");
|
||||
mapCarClass.put("마", "04");
|
||||
mapCarClass.put("바", "05");
|
||||
mapCarClass.put("사", "06");
|
||||
mapCarClass.put("아", "07");
|
||||
mapCarClass.put("자", "08");
|
||||
mapCarClass.put("차", "09");
|
||||
mapCarClass.put("카", "10");
|
||||
mapCarClass.put("타", "11");
|
||||
mapCarClass.put("파", "12");
|
||||
mapCarClass.put("하", "13");
|
||||
mapCarClass.put("거", "14");
|
||||
mapCarClass.put("너", "15");
|
||||
mapCarClass.put("더", "16");
|
||||
mapCarClass.put("러", "17");
|
||||
mapCarClass.put("머", "18");
|
||||
mapCarClass.put("버", "19");
|
||||
mapCarClass.put("서", "20");
|
||||
mapCarClass.put("어", "21");
|
||||
mapCarClass.put("저", "22");
|
||||
mapCarClass.put("처", "23");
|
||||
mapCarClass.put("커", "24");
|
||||
mapCarClass.put("터", "25");
|
||||
mapCarClass.put("퍼", "26");
|
||||
mapCarClass.put("허", "27");
|
||||
mapCarClass.put("고", "28");
|
||||
mapCarClass.put("노", "29");
|
||||
mapCarClass.put("도", "30");
|
||||
mapCarClass.put("로", "31");
|
||||
mapCarClass.put("모", "32");
|
||||
mapCarClass.put("보", "33");
|
||||
mapCarClass.put("소", "34");
|
||||
mapCarClass.put("오", "35");
|
||||
mapCarClass.put("조", "36");
|
||||
mapCarClass.put("초", "37");
|
||||
mapCarClass.put("코", "38");
|
||||
mapCarClass.put("토", "39");
|
||||
mapCarClass.put("포", "40");
|
||||
mapCarClass.put("호", "41");
|
||||
mapCarClass.put("구", "42");
|
||||
mapCarClass.put("누", "43");
|
||||
mapCarClass.put("두", "44");
|
||||
mapCarClass.put("루", "45");
|
||||
mapCarClass.put("무", "46");
|
||||
mapCarClass.put("부", "47");
|
||||
mapCarClass.put("수", "48");
|
||||
mapCarClass.put("우", "49");
|
||||
mapCarClass.put("주", "50");
|
||||
mapCarClass.put("추", "51");
|
||||
mapCarClass.put("쿠", "52");
|
||||
mapCarClass.put("투", "53");
|
||||
mapCarClass.put("푸", "54");
|
||||
mapCarClass.put("후", "55");
|
||||
mapCarClass.put("그", "56");
|
||||
mapCarClass.put("느", "57");
|
||||
mapCarClass.put("드", "58");
|
||||
mapCarClass.put("르", "59");
|
||||
mapCarClass.put("므", "60");
|
||||
mapCarClass.put("브", "61");
|
||||
mapCarClass.put("스", "62");
|
||||
mapCarClass.put("으", "63");
|
||||
mapCarClass.put("즈", "64");
|
||||
mapCarClass.put("츠", "65");
|
||||
mapCarClass.put("크", "66");
|
||||
mapCarClass.put("트", "67");
|
||||
mapCarClass.put("프", "68");
|
||||
mapCarClass.put("흐", "69");
|
||||
mapCarClass.put("기", "70");
|
||||
mapCarClass.put("니", "71");
|
||||
mapCarClass.put("디", "72");
|
||||
mapCarClass.put("리", "73");
|
||||
mapCarClass.put("미", "74");
|
||||
mapCarClass.put("비", "75");
|
||||
mapCarClass.put("시", "76");
|
||||
mapCarClass.put("이", "77");
|
||||
mapCarClass.put("지", "78");
|
||||
mapCarClass.put("치", "79");
|
||||
mapCarClass.put("키", "80");
|
||||
mapCarClass.put("티", "81");
|
||||
mapCarClass.put("피", "82");
|
||||
mapCarClass.put("히", "83");
|
||||
mapCarClass.put("육", "84");
|
||||
mapCarClass.put("해", "85");
|
||||
mapCarClass.put("공", "86");
|
||||
mapCarClass.put("국", "87");
|
||||
mapCarClass.put("합", "88");
|
||||
mapCarClass.put("_", "89");
|
||||
mapCarClass.put("배", "90");
|
||||
mapCarClass.put("외", "98");
|
||||
|
||||
if (mapCarClass.get(str) == null)
|
||||
return -1;
|
||||
|
||||
return Short.parseShort((String) mapCarClass.get(str), 16);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
//String[] array ={"37너6202", "37너6202", "27어7623", "17러0863", "47어5540", "115조1722", "68부7433", "", ""};
|
||||
String[] array ={"서울4보2416","21러3078", "21러3071", "69오6464", "21러3121", "14두6096", "14두6043" };
|
||||
//{"서울31바3919", "61두6950", "54누5840", "56보1098", "06무3635", "31두7103", "42러2718 ", "41주4712", "24버1549 ", "68라8528 ", "61가3088 ", ""};
|
||||
|
||||
for(int i = 0; i < array.length; i++)
|
||||
System.out.println(PLUploader.runCarNo2Code(array[i]));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,17 @@
|
||||
package util;
|
||||
|
||||
/**
|
||||
* File 처리하는 클래스에서 사용하기 위한 사용자 정의 예외<BR>
|
||||
* @author pantarei
|
||||
* @since JDK 1.4.1
|
||||
* @version 0.1, 2004-11-19 pantarei create
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class IllegalRecordException extends Exception{
|
||||
public IllegalRecordException(){
|
||||
super();
|
||||
}
|
||||
public IllegalRecordException(String msg){
|
||||
super(msg);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,48 @@
|
||||
package util;
|
||||
|
||||
|
||||
/**
|
||||
레코드<BR>
|
||||
@author pantarei
|
||||
@since JDK 1.4.1
|
||||
@version 0.1, 2004-11-17 pantarei create
|
||||
0.2, 2006-06-12 코드 추가
|
||||
*/
|
||||
public class Record{
|
||||
protected String record;
|
||||
/**
|
||||
* 레코드 길이 체크
|
||||
* @param record
|
||||
* @return
|
||||
*/
|
||||
protected boolean checkLength(String record, int length){
|
||||
return record.getBytes().length == length ? true : false;
|
||||
}
|
||||
/**
|
||||
* 레코드를 byte단위로 잘라서 String 로 리턴
|
||||
* @param line
|
||||
* @param start
|
||||
* @param end
|
||||
* @return
|
||||
*/
|
||||
protected String getStringInLine(String line , int start, int end)
|
||||
{
|
||||
byte[] bTmpLine = line.getBytes();
|
||||
|
||||
return new String(bTmpLine, start, end-start);
|
||||
}
|
||||
/**
|
||||
* 레코드 Return
|
||||
* @return String
|
||||
*/
|
||||
public String getRecord() throws IllegalRecordException{
|
||||
return record;
|
||||
}
|
||||
/**
|
||||
* 레코드 Return
|
||||
* @return String
|
||||
*/
|
||||
public String getData(){
|
||||
return record;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,198 @@
|
||||
package util;
|
||||
|
||||
|
||||
/**
|
||||
* 요금단말정보(RF) 데이터 포멧<BR>
|
||||
* @author jckim
|
||||
* @since JDK 1.4.1
|
||||
* @version 0.1, 2007-11-01 초기 작성, 2011-12-12 kde 이비카드 추가 컬럼사이즈 변경.
|
||||
*/
|
||||
public class RfTerminalRecord extends Record {
|
||||
private int RECORD_LEN = 260; // 레코드 길이 2011.12.12 kde 255 -> 260
|
||||
private String worker_id, fare_office_id, booth_id, year, month, day, work_times,
|
||||
seqno, after_kbn, card_no,in_out_kbn, trans_file_create_yn,
|
||||
collect_id, levy_amount, remaind_amount, card_office_id, c_repay_kbn,
|
||||
rfid_kbn, rfid_tag1, rfid_tag2, terminal_id, sam_id, sam_seqno,
|
||||
card_seqno, before_amount, algorithm_id, key_version, e_cash_identifier,
|
||||
sam_tot_seqno, sam_collect_cnt, sam_tot_amount, sign_value, person_code,
|
||||
zipge_id, alias_no, issue_id;
|
||||
/**
|
||||
* Counstructor
|
||||
*/
|
||||
public RfTerminalRecord(String worker_id, String fare_office_id, String booth_id, String year, String month,
|
||||
String day, String work_times, String seqno, String after_kbn, String card_no,
|
||||
String in_out_kbn, String trans_file_create_yn, String collect_id, String levy_amount,
|
||||
String remaind_amount, String card_office_id, String c_repay_kbn, String rfid_kbn,
|
||||
String rfid_tag1, String rfid_tag2, String terminal_id, String sam_id,
|
||||
String sam_seqno, String card_seqno, String before_amount, String algorithm_id,
|
||||
String key_version, String e_cash_identifier, String sam_tot_seqno, String sam_collect_cnt,
|
||||
String sam_tot_amount, String sign_value, String person_code, String zipge_id,
|
||||
String alias_no, String issue_id){
|
||||
this.worker_id = worker_id ;
|
||||
this.fare_office_id = fare_office_id;
|
||||
this.booth_id = booth_id ;
|
||||
this.year = year ;
|
||||
this.month = month ;
|
||||
this.day = day ;
|
||||
this.work_times = work_times ;
|
||||
this.seqno = StringUtil.justify(StringUtil.RIGHT,seqno , "0", 9);
|
||||
this.after_kbn = StringUtil.justify(StringUtil.LEFT ,after_kbn , " ", 1);
|
||||
this.card_no = StringUtil.justify(StringUtil.LEFT ,card_no , " ", 20);
|
||||
this.in_out_kbn = StringUtil.justify(StringUtil.LEFT ,in_out_kbn , " ", 1);
|
||||
this.trans_file_create_yn= StringUtil.justify(StringUtil.LEFT ,trans_file_create_yn, " ", 1);
|
||||
this.collect_id = StringUtil.justify(StringUtil.LEFT ,collect_id , " ", 2);
|
||||
this.levy_amount = StringUtil.justify(StringUtil.RIGHT,levy_amount , "0", 10);
|
||||
this.remaind_amount = StringUtil.justify(StringUtil.RIGHT,remaind_amount , "0", 10);
|
||||
this.card_office_id = StringUtil.justify(StringUtil.LEFT ,card_office_id , " ", 1);
|
||||
this.c_repay_kbn = StringUtil.justify(StringUtil.LEFT ,c_repay_kbn , " ", 1);
|
||||
this.rfid_kbn = StringUtil.justify(StringUtil.LEFT ,rfid_kbn , " ", 2);
|
||||
this.rfid_tag1 = StringUtil.justify(StringUtil.LEFT ,rfid_tag1 , " ", 24);
|
||||
this.rfid_tag2 = StringUtil.justify(StringUtil.LEFT ,rfid_tag2 , " ", 24);
|
||||
this.terminal_id = StringUtil.justify(StringUtil.LEFT ,terminal_id , " ", 9);
|
||||
this.sam_id = StringUtil.justify(StringUtil.LEFT ,sam_id , " ", 16);
|
||||
this.sam_seqno = StringUtil.justify(StringUtil.RIGHT,sam_seqno , "0", 10);
|
||||
this.card_seqno = StringUtil.justify(StringUtil.RIGHT,card_seqno , "0", 10);
|
||||
this.before_amount = StringUtil.justify(StringUtil.RIGHT,before_amount , "0", 10);
|
||||
this.algorithm_id = StringUtil.justify(StringUtil.LEFT ,algorithm_id , " ", 3); // 2011.12.12 kde 2 -> 3
|
||||
this.key_version = StringUtil.justify(StringUtil.LEFT ,key_version , " ", 3); // 2011.12.12 kde 2 -> 3
|
||||
this.e_cash_identifier = StringUtil.justify(StringUtil.LEFT ,e_cash_identifier , " ", 3); // 2011.12.12 kde 2 -> 3
|
||||
this.sam_tot_seqno = StringUtil.justify(StringUtil.RIGHT,sam_tot_seqno , "0", 10);
|
||||
this.sam_collect_cnt = StringUtil.justify(StringUtil.RIGHT,sam_collect_cnt , "0", 5);
|
||||
this.sam_tot_amount = StringUtil.justify(StringUtil.RIGHT,sam_tot_amount , "0", 10);
|
||||
this.sign_value = StringUtil.justify(StringUtil.LEFT ,sign_value , " ", 10); // 2011.12.12 kde 8 -> 10
|
||||
this.person_code = StringUtil.justify(StringUtil.LEFT ,person_code , " ", 2);
|
||||
this.zipge_id = StringUtil.justify(StringUtil.LEFT ,zipge_id , " ", 12);
|
||||
this.alias_no = StringUtil.justify(StringUtil.LEFT ,alias_no , " ", 10);
|
||||
this.issue_id = StringUtil.justify(StringUtil.LEFT ,issue_id , " ", 7);
|
||||
}
|
||||
/**
|
||||
* 레코드 정보를 String으로 return
|
||||
* @return String
|
||||
* @throws IllegalRecordException
|
||||
*/
|
||||
public String getRecord() throws IllegalRecordException{
|
||||
String result
|
||||
= new StringBuffer(worker_id )
|
||||
.append(fare_office_id )
|
||||
.append(booth_id )
|
||||
.append(year )
|
||||
.append(month )
|
||||
.append(day )
|
||||
.append(work_times )
|
||||
.append(seqno )
|
||||
.append(after_kbn )
|
||||
.append(card_no )
|
||||
.append(in_out_kbn )
|
||||
.append(trans_file_create_yn)
|
||||
.append(collect_id )
|
||||
.append(levy_amount )
|
||||
.append(remaind_amount )
|
||||
.append(card_office_id )
|
||||
.append(c_repay_kbn )
|
||||
.append(rfid_kbn )
|
||||
.append(rfid_tag1 )
|
||||
.append(rfid_tag2 )
|
||||
.append(terminal_id )
|
||||
.append(sam_id )
|
||||
.append(sam_seqno )
|
||||
.append(card_seqno )
|
||||
.append(before_amount )
|
||||
.append(algorithm_id )
|
||||
.append(key_version )
|
||||
.append(e_cash_identifier )
|
||||
.append(sam_tot_seqno )
|
||||
.append(sam_collect_cnt )
|
||||
.append(sam_tot_amount )
|
||||
.append(sign_value )
|
||||
.append(person_code )
|
||||
.append(zipge_id )
|
||||
.append(alias_no )
|
||||
.append(issue_id ).toString();
|
||||
|
||||
getRecord2();
|
||||
//System.out.println("=== " + result);
|
||||
if(checkLength(result, RECORD_LEN)){
|
||||
return result;
|
||||
}else{
|
||||
throw new IllegalRecordException(
|
||||
"Cannot create DATA record : [" + result.length() + "] " + result);
|
||||
}
|
||||
}
|
||||
|
||||
public String getRecord2() throws IllegalRecordException{
|
||||
String result
|
||||
= new StringBuffer(worker_id )
|
||||
.append(", " )
|
||||
.append(fare_office_id )
|
||||
.append(", " )
|
||||
.append(booth_id )
|
||||
.append(", " )
|
||||
.append(year )
|
||||
.append(", " )
|
||||
.append(month )
|
||||
.append(", " )
|
||||
.append(day )
|
||||
.append(", " )
|
||||
.append(work_times )
|
||||
.append(", " )
|
||||
.append(seqno )
|
||||
.append(", " )
|
||||
.append(after_kbn )
|
||||
.append(", " )
|
||||
.append(card_no )
|
||||
.append(", " )
|
||||
.append(in_out_kbn )
|
||||
.append(", " )
|
||||
.append(trans_file_create_yn)
|
||||
.append(", " )
|
||||
.append(collect_id )
|
||||
.append(levy_amount )
|
||||
.append(", " )
|
||||
.append(remaind_amount )
|
||||
.append(", " )
|
||||
.append(card_office_id )
|
||||
.append(", " )
|
||||
.append(c_repay_kbn )
|
||||
.append(", " )
|
||||
.append(rfid_kbn )
|
||||
.append(", " )
|
||||
.append(rfid_tag1 )
|
||||
.append(", " )
|
||||
.append(rfid_tag2 )
|
||||
.append(", " )
|
||||
.append(terminal_id )
|
||||
.append(", " )
|
||||
.append(sam_id )
|
||||
.append(", " )
|
||||
.append(sam_seqno )
|
||||
.append(", " )
|
||||
.append(card_seqno )
|
||||
.append(", " )
|
||||
.append(before_amount )
|
||||
.append(", " )
|
||||
.append(algorithm_id )
|
||||
.append(", " )
|
||||
.append(key_version )
|
||||
.append(", " )
|
||||
.append(e_cash_identifier )
|
||||
.append(", " )
|
||||
.append(sam_tot_seqno )
|
||||
.append(", " )
|
||||
.append(sam_collect_cnt )
|
||||
.append(", " )
|
||||
.append(sam_tot_amount )
|
||||
.append(", " )
|
||||
.append(sign_value )
|
||||
.append(", " )
|
||||
.append(person_code )
|
||||
.append(", " )
|
||||
.append(zipge_id )
|
||||
.append(", " )
|
||||
.append(alias_no )
|
||||
.append(", " )
|
||||
.append(issue_id ).toString();
|
||||
System.out.println(result);
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,295 @@
|
||||
package util;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
/**
|
||||
* 문자열 처리 공통 클래스<BR>
|
||||
* @since JDK 1.4.1
|
||||
* @version 0.1, 2006-12-20 초기 작성
|
||||
*/
|
||||
public class StringUtil {
|
||||
|
||||
private static final char[] toHex = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
|
||||
|
||||
public static String toHexString(byte b[]) {
|
||||
return toHexString(b, 0, b.length);
|
||||
}
|
||||
|
||||
public static String toHexString(byte b[], int spos, int epos) {
|
||||
int pos = 0;
|
||||
char[] cbuf = new char[(epos - spos) * 2];
|
||||
|
||||
for (int i = spos; i < epos; i++) {
|
||||
cbuf[pos++] = toHex[(b[i] >> 4) & 0x0F];
|
||||
cbuf[pos++] = toHex[b[i] & 0x0F];
|
||||
}
|
||||
return new String(cbuf);
|
||||
}
|
||||
|
||||
public static byte [] toHexBytes(String str) {
|
||||
String recv_data = str.toUpperCase();
|
||||
byte [] aBuff = null;
|
||||
if( recv_data.length()%2 == 0){
|
||||
aBuff = new byte[recv_data.length()];
|
||||
}else{
|
||||
aBuff = new byte[recv_data.length()+1];
|
||||
aBuff[recv_data.length()] = 0x00;
|
||||
}
|
||||
|
||||
for(int i=0; i< recv_data.length(); i++){
|
||||
char buff = recv_data.charAt(i);
|
||||
if( buff >= '0' && buff <= '9'){
|
||||
aBuff[i] = (byte)(buff-48);
|
||||
}else{
|
||||
aBuff[i] = (byte)(buff-55);
|
||||
}
|
||||
}
|
||||
byte [] bBuff = new byte[aBuff.length/2];
|
||||
|
||||
for(int i=0; i< aBuff.length/2; i++){
|
||||
byte a = (byte)( aBuff[i*2+0] << 4 & 0xF0);
|
||||
byte b = (byte)( aBuff[i*2+1] & 0x0F);
|
||||
bBuff[i] = (byte)( a | b);
|
||||
}
|
||||
return bBuff;
|
||||
}
|
||||
|
||||
public static long toLong(byte b[]) {
|
||||
return toLong(b, 0, b.length);
|
||||
}
|
||||
|
||||
public static long toLong(byte b[], int spos, int epos) {
|
||||
long num = 0;
|
||||
int pos = 0;
|
||||
|
||||
for (int i=epos - 1; i>= spos; i--, pos++) {
|
||||
num |= (b[i] & 0xFF) << (8 * pos);
|
||||
}
|
||||
|
||||
return num;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public static boolean isSupportedEncoding(String charset) {
|
||||
try {
|
||||
byte[] b = charset.getBytes("8859_1");
|
||||
String value = new String(b, charset);
|
||||
}
|
||||
catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static String toEncString(String str, String charset) {
|
||||
try {
|
||||
byte[] b = str.getBytes("8859_1");
|
||||
return new String(b, charset);
|
||||
}
|
||||
catch (UnsupportedEncodingException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static String toWhiteSpace(String str) {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
String whites = " \t\r\n";
|
||||
boolean before = false;
|
||||
|
||||
for (int i = 0; i < str.length(); i++) {
|
||||
char c = str.charAt(i);
|
||||
int p = whites.indexOf(c);
|
||||
|
||||
if (before && p >= 0)
|
||||
continue;
|
||||
|
||||
if (p >= 0) {
|
||||
buffer.append(" ");
|
||||
before = true;
|
||||
}
|
||||
else {
|
||||
buffer.append(c);
|
||||
before = false;
|
||||
}
|
||||
}
|
||||
return new String(buffer.toString().trim());
|
||||
}
|
||||
|
||||
public static String toEncString(byte b[], String charset) {
|
||||
try {
|
||||
return new String(b, charset);
|
||||
}
|
||||
catch (UnsupportedEncodingException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static String MD5(String str) {
|
||||
return MD5(str.getBytes());
|
||||
}
|
||||
|
||||
public static String MD5(byte[] msg) {
|
||||
try {
|
||||
MessageDigest md = MessageDigest.getInstance("MD5");
|
||||
md.update(msg);
|
||||
|
||||
byte[] digest = md.digest();
|
||||
StringBuffer buf = new StringBuffer(digest.length * 2);
|
||||
|
||||
for (int i = 0; i < digest.length; i++) {
|
||||
int intVal = digest[i] & 0xff;
|
||||
|
||||
if (intVal < 0x10) {
|
||||
buf.append("0");
|
||||
}
|
||||
|
||||
buf.append(Integer.toHexString(intVal));
|
||||
}
|
||||
return buf.toString();
|
||||
}
|
||||
catch (NoSuchAlgorithmException ne) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static String ntos(int num, int len) {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append(Integer.toString(num));
|
||||
|
||||
while (buffer.length() < len) {
|
||||
buffer.insert(0, "0");
|
||||
}
|
||||
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
public static String ltos(long num, int len) {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append(Long.toString(num));
|
||||
|
||||
while (buffer.length() < len) {
|
||||
buffer.insert(0, "0");
|
||||
}
|
||||
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
public static String getString(char c, int length) {
|
||||
char[] chars = new char[length];
|
||||
for (int i = 0; i < length; i++) {
|
||||
chars[i] = c;
|
||||
}
|
||||
return new String(chars);
|
||||
}
|
||||
|
||||
public static String getDate(String format) {
|
||||
return new SimpleDateFormat(format, Locale.KOREA).format(new Date());
|
||||
}
|
||||
|
||||
public static String getTomorrow(String format){
|
||||
Date today = new Date();
|
||||
Date tomorrow = new Date();
|
||||
tomorrow.setTime( today.getTime() + (long) ( 1000 * 60 * 60 * 24 ) * 1 );
|
||||
return new SimpleDateFormat(format, Locale.KOREA).format(tomorrow);
|
||||
}
|
||||
|
||||
public static final boolean LEFT = true;
|
||||
public static final boolean RIGHT = false;
|
||||
|
||||
public static String justify(
|
||||
boolean direction, String src, String filler, int length) {
|
||||
if (src == null || filler == null || length < 0) {
|
||||
return "";
|
||||
}
|
||||
int len = src.getBytes().length;
|
||||
if (len > length) {
|
||||
return src.substring(0, length);
|
||||
}
|
||||
if (len == length) {
|
||||
return src;
|
||||
}
|
||||
StringBuffer buf = direction == LEFT ? new StringBuffer(src) : new StringBuffer();
|
||||
int fillLength = length - len;
|
||||
for (int i = 0; i < fillLength; i++) {
|
||||
buf.append(filler);
|
||||
}
|
||||
if (direction == RIGHT) {
|
||||
buf.append(src);
|
||||
}
|
||||
return buf.toString();
|
||||
}
|
||||
/**
|
||||
* 특정구분자로 문자열을 자르는 메소드
|
||||
* @param src
|
||||
* @param filler
|
||||
* @param nArrSize
|
||||
* @return String []
|
||||
* @throws Exception
|
||||
*/
|
||||
public static String [] split( String src, byte filler, int nArrSize) throws Exception {
|
||||
int iArrIndex = 0;
|
||||
int iStartIndex = 0;
|
||||
String [] saReturn = new String[100];
|
||||
byte[] byteOrigin = src.getBytes();
|
||||
byte[] byteArrTemp = null;
|
||||
for(int idx=0; idx<byteOrigin.length;idx++){
|
||||
if(byteOrigin[idx]==filler){
|
||||
if(iStartIndex==idx) saReturn[iArrIndex] = "";
|
||||
else if(iStartIndex==idx-1) {
|
||||
char bTemp = (char)byteOrigin[iStartIndex];
|
||||
saReturn[iArrIndex] = String.valueOf(bTemp);
|
||||
}
|
||||
else {
|
||||
byteArrTemp = getByteArray(byteOrigin, iStartIndex, idx);
|
||||
saReturn[iArrIndex] = new String(byteArrTemp);
|
||||
}
|
||||
iArrIndex++;
|
||||
iStartIndex=idx+1;
|
||||
}
|
||||
}
|
||||
if(iStartIndex==byteOrigin.length) saReturn[iArrIndex] = "";
|
||||
else if(iStartIndex==byteOrigin.length-1) {
|
||||
char bTemp = (char)byteOrigin[iStartIndex];
|
||||
saReturn[iArrIndex] = String.valueOf(bTemp);
|
||||
}
|
||||
else {
|
||||
byteArrTemp = getByteArray(byteOrigin, iStartIndex, byteOrigin.length);
|
||||
saReturn[iArrIndex] = new String(byteArrTemp);
|
||||
}
|
||||
return saReturn;
|
||||
}
|
||||
/**
|
||||
* byte 배열의 일부분을 Return 해주는 메소드
|
||||
* @param bByteData
|
||||
* @param iStart
|
||||
* @param iEnd
|
||||
* @return byte[]
|
||||
*/
|
||||
public static byte[] getByteArray(byte[] bByteData, int iStart, int iEnd)
|
||||
{
|
||||
byte[] b = new byte[iEnd-iStart];
|
||||
for( int i=iStart; i< iEnd; i++) {
|
||||
int c = (bByteData[i] & 0xff) ;
|
||||
b[i-iStart] = (byte) c;
|
||||
}
|
||||
return b;
|
||||
}
|
||||
/*
|
||||
* 라인 문자열에는 한글이 들어가므로 정확한 데이터를
|
||||
* 가져오기 위해서는 바이트로 변환후 바이트 위치로 가져와야 된다
|
||||
*
|
||||
* @param line 문자열, 한라인
|
||||
* @param start 문자열의 시작 인텍스 (0부터 시작으로)
|
||||
* @param end 문자열의 끝 인덱스
|
||||
*/
|
||||
public static String getStringByte(String line , int start, int end)
|
||||
{
|
||||
byte[] bTmpLine = line.getBytes();
|
||||
|
||||
return new String(bTmpLine, start, end-start);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue