소스 정리

main
이범준 4 months ago
parent a58d8178b2
commit 3484080be3

@ -22,29 +22,7 @@ public class FTPUtil {
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("/");
@ -76,16 +54,16 @@ public class FTPUtil {
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. 호스트 정보를 검사하지 않는다.
@ -96,80 +74,32 @@ public class FTPUtil {
// 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 {
public void upload3(String dir, File file, Map<String, String> map) 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);
// 업로드하려는 위치르 디렉토리를 변경한다.
@ -191,13 +121,13 @@ public class FTPUtil {
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 {
@ -239,11 +169,11 @@ public class FTPUtil {
e.printStackTrace();
}
}
public InputStream download(String dir, String fileNm) {
InputStream in = null;
String path = "";
System.out.println(path + dir);
try {
channelSftp.cd(path + dir);

@ -8,11 +8,7 @@ import java.util.Date;
public class FileMove {
public static void main(String[] args) {
/*
FileMove.makeDir();
FileMove.makeDirSub();
*/
FileMove.copyData();
}
@ -20,26 +16,25 @@ public class FileMove {
public static void copyData() {
try {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd"); //년월일 표시
SimpleDateFormat sdf_4 = new SimpleDateFormat("yyyy");
//dateFormat = new SimpleDateFormat("yyyyMM"); //년월 표시
SimpleDateFormat sdf_4 = new SimpleDateFormat("yyyy");
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 startDate = dateFormat.format(cal.getTime());
int i = 0;
String pathOrg = "E:\\혼잡_센터_이미지 백업\\DOTR"; //폴더 경로
String path = "E:\\혼잡_센터_이미지 백업\\New"; //폴더 경로
while(!startDate.equals(endDate)){ //다르다면 실행, 동일 하다면 빠져나감
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)
@ -48,11 +43,11 @@ public class FileMove {
// 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 ) {
@ -76,53 +71,52 @@ public class FileMove {
if (fileNames[i].exists()) {
if (original_dir.exists()) {
}
File MoveFile = new File(move_dir, fileNames[i].getName());
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); // 폴더내에 있는 파일 리스트
System.out.println(path); // 폴더내에 있는 파일 리스트
}
public static void makeDirSub() {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd"); //년월일 표시
SimpleDateFormat sdf_4 = new SimpleDateFormat("yyyy");
//dateFormat = new SimpleDateFormat("yyyyMM"); //년월 표시
SimpleDateFormat sdf_4 = new SimpleDateFormat("yyyy");
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 startDate = dateFormat.format(cal.getTime());
int i = 0;
String path = "E:\\혼잡_센터_이미지 백업\\New"; //폴더 경로
File Folder = null;
while(!startDate.equals(endDate)){ //다르다면 실행, 동일 하다면 빠져나감
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("이미 폴더가 생성되어 있습니다.");
}
@ -131,31 +125,31 @@ public class FileMove {
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"; //폴더 경로
@ -164,10 +158,10 @@ public class FileMove {
try{
Folder.mkdir(); //폴더 생성합니다.
System.out.println("폴더가 생성되었습니다.");
}
}
catch(Exception e){
e.getStackTrace();
}
}
}else {
System.out.println("이미 폴더가 생성되어 있습니다.");
}
@ -177,29 +171,29 @@ public class FileMove {
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();

@ -165,7 +165,7 @@ public class MakeExemptInfo {
map.put("return", "0");
try {
sftp.upload3("/gpta/source-web/cfs/relay/data/", file, fileNm, fileNm, map);
sftp.upload3("/gpta/source-web/cfs/relay/data/", file, map);
} catch (Exception e) {
e.printStackTrace();
}

@ -185,7 +185,7 @@ public class MakePreregistrInfo {
map.put("return", "0");
try {
sftp.upload3("/gpta/source-web/cfs/relay/data/", file, fileNm, fileNm, map);
sftp.upload3("/gpta/source-web/cfs/relay/data/", file, map);
} catch (Exception e) {
e.printStackTrace();
}

@ -165,7 +165,7 @@ public class MakeRfidnfo {
map.put("return", "0");
try {
sftp.upload3("/gpta/source-web/cfs/relay/data/", file, fileNm, fileNm, map);
sftp.upload3("/gpta/source-web/cfs/relay/data/", file, map);
} catch (Exception e) {
e.printStackTrace();
}

@ -161,7 +161,7 @@ public class MakeScarInfo {
map.put("return", "0");
try {
sftp.upload3("/gpta/source-web/cfs/relay/data/", file, fileNm, fileNm, map);
sftp.upload3("/gpta/source-web/cfs/relay/data/", file, map);
} catch (Exception e) {
e.printStackTrace();
}

@ -11,11 +11,10 @@ public class PLUploader {
strCarNo = strCarNo.trim();
strCarNo = strCarNo.replaceAll(" ", "");
if (strCarNo.contains("0000"))
if (strCarNo.contains("0000")) {
return "0000000000";
}
// System.out.println("====" + strCarNo + "===");
// System.out.println("==== " + nCarNoLength);
int nCarNoLength = strCarNo.length();
if (nCarNoLength < 7 || nCarNoLength > 9)
@ -76,11 +75,11 @@ public class PLUploader {
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);
@ -255,15 +254,5 @@ public class PLUploader {
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]));
}
}

@ -1,71 +0,0 @@
package util;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class TiberoDBConnection {
Connection con;
PreparedStatement pstmt;
ResultSet rs;
String IP = "192.168.0.40"; // 접속 IP ex) 192.168.0.0
String PORT = "8629"; // 접속 PORT * Tibero 에서 기본 포트는 8629 이다.
String DB_NAME = "gtpadevdb"; // sid * create database "" 에 썼던 이름
String userid = "dbuser_cfs"; // tbsql 접속시 #tbsql userid/pwd
String pwd = "dbuser_cfs"; // tbsql 접속시 #tbsql userid/pwd
public TiberoDBConnection() {
}
private void connect() throws SQLException, ClassNotFoundException {
Class.forName("com.tmax.tibero.jdbc.TbDriver");
con = DriverManager.getConnection("jdbc:tibero:thin:@" + IP + ":" + PORT + ":" + DB_NAME, userid, pwd);
if (con == null) {
System.out.println("Tibero DBConnection Fail");
System.exit(-1);
}
System.out.println("Tibero DBConnection Success");
}
// DB 접속 성공 후 테스트 쿼리
private void select() throws SQLException {
String sql = "SELECT count(*) as aa FROM TB_CFS_PRP_REQ";
pstmt = con.prepareStatement(sql);
rs = pstmt.executeQuery();
while (rs.next()) {
System.out.println("userinfo: " + rs.getString(1));
}
}
private void close() throws Exception {
try {
if (pstmt != null)
pstmt.close();
if (rs != null)
rs.close();
if (con != null)
con.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) throws Exception {
TiberoDBConnection dbcon = new TiberoDBConnection();
dbcon.connect();
dbcon.select();
dbcon.close();
}
}
Loading…
Cancel
Save