no message

main
이범준 7 months ago
parent 9be5b67777
commit b62c70cf9e

@ -1,4 +1,4 @@
import java.io.BufferedInputStream;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.File;
@ -24,289 +24,223 @@ import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.PersistJobDataAfterExecution;
@PersistJobDataAfterExecution
@DisallowConcurrentExecution
public class DumbJob
implements Job
{
private final Logger logger = Logger.getLogger(getClass());
private ArrayList<String> state;
private static String[] g_strDB = new String[4];
private static String[] g_strFTP = new String[7];
private String g_strTenel = "";
public static void main(String[] args) {
String str = "";
if (args.length > 0) {
str = args[0];
}
if (str.length() != 8) {
return;
}
DumbJob obj = new DumbJob();
try {
obj.runAPI(str);
}
catch (Exception e) {
e.printStackTrace();
}
}
public DumbJob() {
try {
String propFile = "./config.properties";
Properties props = new Properties();
FileInputStream fis = new FileInputStream(propFile);
props.load(new 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("=== " + g_strDB[0]);
System.out.println("=== " + g_strDB[1]);
System.out.println("=== " + g_strDB[2]);
System.out.println("=== " + g_strDB[3]);
g_strFTP[0] = props.getProperty("path_org");
g_strFTP[1] = props.getProperty("ftp_ip");
g_strFTP[2] = props.getProperty("ftp_id");
g_strFTP[3] = props.getProperty("ftp_pw");
g_strFTP[4] = props.getProperty("api_url");
g_strFTP[5] = props.getProperty("api_id");
g_strFTP[6] = props.getProperty("api_pw");
this.g_strTenel = props.getProperty("tennel_no");
props.clear();
props = null;
} catch (Exception e) {
e.printStackTrace();
}
}
public void setState(ArrayList<String> state) {
this.state = state;
}
@Override
public void execute(JobExecutionContext arg0) throws JobExecutionException {
System.out.println("Job Executed [" + new Date(System.currentTimeMillis()) + "]");
try {
runAPI(this.state.get(0).toString());
}
catch (Exception e) {
e.printStackTrace();
}
}
public void runAPI(String strPassDate) {
Map<String, String> map = new HashMap<>();
map.put("0101", "01");
map.put("0102", "02");
map.put("0103", "03");
map.put("0104", "04");
map.put("0105", "05");
map.put("0106", "06");
map.put("0107", "07");
map.put("0108", "08");
map.put("0301", "01");
map.put("0302", "02");
map.put("0303", "03");
map.put("0304", "04");
map.put("0307", "05");
map.put("0308", "06");
map.put("0309", "07");
map.put("0310", "08");
JSONObject jsonParam = new JSONObject();
jsonParam.put("fareOfficeId", String.format("0%s", new Object[] { this.g_strTenel.trim() }));
jsonParam.put("start_dt", strPassDate);
jsonParam.put("end_dt", strPassDate);
StringBuffer strbuf = new StringBuffer();
int nReuslt = callAnprCarnoSend(jsonParam.toJSONString(), strbuf);
if (nReuslt < 0) {
System.out.println("================== API 조회 오류 ");
return;
}
try {
int nBoothId = 0;
File Folder = new File("./download/" + strPassDate);
if (!Folder.exists()) {
try {
Folder.mkdir();
this.logger.debug("폴더가 생성되었습니다.");
} catch (Exception e) {
e.getStackTrace();
}
} else {
this.logger.debug("이미 폴더가 생성되어 있습니다.");
}
JSONParser parser = new JSONParser();
JSONObject jsonObj = (JSONObject)parser.parse(strbuf.toString());
JSONArray jsonArray1 = (JSONArray)jsonObj.get("data");
String strUrl = "";
String strFileNme = "";
SmtURLDownloadFunc obj = new SmtURLDownloadFunc();
for (int i = 0; i < jsonArray1.size(); i++) {
JSONObject objectInArray = (JSONObject)jsonArray1.get(i);
System.out.println(objectInArray);
nBoothId = Integer.parseInt(map.get(String.valueOf(objectInArray.get("FARE_OFFICE_ID").toString()) + objectInArray.get("BOOTH_ID").toString()));
String uri = String.format("%s/download/video%d.mp4", new Object[] {
g_strFTP[4],
Integer.valueOf(nBoothId)
});
String param_id_pw = String.format("user=%s&password=%s", new Object[] {
g_strFTP[5],
g_strFTP[6]
});
String param_start_end = String.format("start=%s&end=%s", new Object[] {
objectInArray.get("PASS_START_DATE").toString().replace(" ", "T"),
objectInArray.get("PASS_END_DATE").toString().replace(" ", "T")
});
strUrl = uri+"?"+param_id_pw+"&"+param_start_end;
strFileNme = objectInArray.get("CARS_MOVE_PICTURE_FILE").toString();
System.out.println(String.format("=== %s,", new Object[] { strFileNme }));
System.out.println(String.format("=== %s\n,", new Object[] { strUrl }));
try {
Thread.sleep(100L);
obj.fileUrlDownload(strUrl, "./download/" + objectInArray.get("PASS_DATE").toString() + "/", strFileNme);
} catch (Exception e) {
e.printStackTrace();
}
}
} catch (ParseException e) {
e.printStackTrace();
}
}
private int callAnprCarnoSend(String strJson, StringBuffer strbuf) {
int nResult = 0;
HttpURLConnection connection = null;
InputStream is = null;
InputStreamReader isr = null;
BufferedReader br = null;
try {
URL url = new URL(g_strDB[1]);
this.logger.info("==== 수집서버 주소 : " + g_strDB[1]);
connection = (HttpURLConnection)url.openConnection();
connection.setDoInput(true);
connection.setDoOutput(true);
connection.setUseCaches(false);
connection.setRequestMethod("POST");
connection.setConnectTimeout(30000);
connection.setReadTimeout(30000);
connection.setRequestProperty("Accept", "application/json");
connection.setRequestProperty("Content-Type", "application/json");
BufferedOutputStream bos = new BufferedOutputStream(connection.getOutputStream());
bos.write(strJson.getBytes("UTF-8"));
bos.flush();
bos.close();
int resCode = connection.getResponseCode();
StringBuffer sb = new StringBuffer();
String inputLine = null;
this.logger.info("==== : " + resCode);
if (resCode == 200) {
is = connection.getInputStream();
isr = new InputStreamReader(is, "UTF-8");
br = new BufferedReader(isr);
while ((inputLine = br.readLine()) != null) {
sb.append(inputLine);
}
strbuf.append(sb.toString());
this.logger.info("==== " + sb.toString());
}
else if (connection.getErrorStream() != null) {
br = new BufferedReader(new InputStreamReader(connection.getErrorStream(), "UTF-8"));
while ((inputLine = br.readLine()) != null) {
sb.append(inputLine);
}
this.logger.info("==== Http Error Resopnse : " + sb.toString());
nResult = -1;
} else {
this.logger.info("==== Http Error Resopnse : " + sb.toString());
nResult = -1;
}
} catch (Exception e) {
this.logger.info("Exception : " + e);
this.logger.info("==== Http Error Resopnse : ");
nResult = -1;
} finally {
try {
if (is != null)
is.close();
if (isr != null)
isr.close();
if (br != null)
br.close();
} catch (Exception exception) {}
}
return nResult;
}
}
@PersistJobDataAfterExecution
@DisallowConcurrentExecution
public class DumbJob implements Job {
private final Logger logger = Logger.getLogger(getClass());
private ArrayList<String> state;
private static String[] g_strDB = new String[4];
private static String[] g_strFTP = new String[7];
private String g_strTenel = "";
public static void main(String[] args) {
String str = "";
if (args.length > 0)
str = args[0];
if (str.length() != 8)
return;
DumbJob obj = new DumbJob();
try {
obj.runAPI(str);
} catch (Exception e) {
e.printStackTrace();
}
}
public DumbJob() {
try {
String propFile = "./config.properties";
Properties props = new Properties();
FileInputStream fis = new FileInputStream(propFile);
props.load(new 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("=== " + g_strDB[0]);
System.out.println("=== " + g_strDB[1]);
System.out.println("=== " + g_strDB[2]);
System.out.println("=== " + g_strDB[3]);
g_strFTP[0] = props.getProperty("path_org");
g_strFTP[1] = props.getProperty("ftp_ip");
g_strFTP[2] = props.getProperty("ftp_id");
g_strFTP[3] = props.getProperty("ftp_pw");
g_strFTP[4] = props.getProperty("api_url");
g_strFTP[5] = props.getProperty("api_id");
g_strFTP[6] = props.getProperty("api_pw");
this.g_strTenel = props.getProperty("tennel_no");
props.clear();
props = null;
} catch (Exception e) {
e.printStackTrace();
}
}
public void setState(ArrayList<String> state) {
this.state = state;
}
@Override
public void execute(JobExecutionContext arg0) throws JobExecutionException {
System.out.println("Job Executed [" + new Date(System.currentTimeMillis()) + "]");
try {
runAPI(this.state.get(0).toString());
} catch (Exception e) {
e.printStackTrace();
}
}
public void runAPI(String strPassDate) {
Map<String, String> map = new HashMap<>();
map.put("0101", "01");
map.put("0102", "02");
map.put("0103", "03");
map.put("0104", "04");
map.put("0105", "05");
map.put("0106", "06");
map.put("0107", "07");
map.put("0108", "08");
map.put("0301", "01");
map.put("0302", "02");
map.put("0303", "03");
map.put("0304", "04");
map.put("0307", "05");
map.put("0308", "06");
map.put("0309", "07");
map.put("0310", "08");
JSONObject jsonParam = new JSONObject();
jsonParam.put("fareOfficeId", String.format("0%s", new Object[] { this.g_strTenel.trim() }));
jsonParam.put("start_dt", strPassDate);
jsonParam.put("end_dt", strPassDate);
StringBuffer strbuf = new StringBuffer();
int nReuslt = callAnprCarnoSend(jsonParam.toJSONString(), strbuf);
if (nReuslt < 0) {
System.out.println("================== API ");
return;
}
try {
int nBoothId = 0;
File Folder = new File("./download/" + strPassDate);
if (!Folder.exists()) {
try {
Folder.mkdir();
this.logger.debug("폴더가 생성되었습니다.");
} catch (Exception e) {
e.getStackTrace();
}
} else {
this.logger.debug("이미 폴더가 생성되어 있습니다.");
}
JSONParser parser = new JSONParser();
JSONObject jsonObj = (JSONObject)parser.parse(strbuf.toString());
JSONArray jsonArray1 = (JSONArray)jsonObj.get("data");
String strUrl = "";
String strFileNme = "";
SmtURLDownloadFunc obj = new SmtURLDownloadFunc();
for (int i = 0; i < jsonArray1.size(); i++) {
JSONObject objectInArray = (JSONObject)jsonArray1.get(i);
System.out.println(objectInArray);
nBoothId = Integer.parseInt(map.get(String.valueOf(objectInArray.get("FARE_OFFICE_ID").toString()) + objectInArray.get("BOOTH_ID").toString()));
String uri = String.format("%s/download/video%d.mp4", new Object[] {
g_strFTP[4],
Integer.valueOf(nBoothId)
});
String param_id_pw = String.format("user=%s&password=%s", new Object[] {
g_strFTP[5],
g_strFTP[6]
});
String param_start_end = String.format("start=%s&end=%s", new Object[] {
objectInArray.get("PASS_START_DATE").toString().replace(" ", "T"),
objectInArray.get("PASS_END_DATE").toString().replace(" ", "T")
});
strUrl = uri+"?"+param_id_pw+"&"+param_start_end;
strFileNme = objectInArray.get("CARS_MOVE_PICTURE_FILE").toString();
System.out.println(String.format("=== %s,", new Object[] { strFileNme }));
System.out.println(String.format("=== %s\n,", new Object[] { strUrl }));
try {
Thread.sleep(100L);
obj.fileUrlDownload(strUrl, "./download/" + objectInArray.get("PASS_DATE").toString() + "/", strFileNme);
} catch (Exception e) {
e.printStackTrace();
}
}
} catch (ParseException e) {
e.printStackTrace();
}
}
private int callAnprCarnoSend(String strJson, StringBuffer strbuf) {
int nResult = 0;
HttpURLConnection connection = null;
InputStream is = null;
InputStreamReader isr = null;
BufferedReader br = null;
try {
URL url = new URL(g_strDB[1]);
this.logger.info("==== : " + g_strDB[1]);
connection = (HttpURLConnection)url.openConnection();
connection.setDoInput(true);
connection.setDoOutput(true);
connection.setUseCaches(false);
connection.setRequestMethod("POST");
connection.setConnectTimeout(30000);
connection.setReadTimeout(30000);
connection.setRequestProperty("Accept", "application/json");
connection.setRequestProperty("Content-Type", "application/json");
BufferedOutputStream bos = new BufferedOutputStream(connection.getOutputStream());
bos.write(strJson.getBytes("UTF-8"));
bos.flush();
bos.close();
int resCode = connection.getResponseCode();
StringBuffer sb = new StringBuffer();
String inputLine = null;
this.logger.info("==== : " + resCode);
if (resCode == 200) {
is = connection.getInputStream();
isr = new InputStreamReader(is, "UTF-8");
br = new BufferedReader(isr);
while ((inputLine = br.readLine()) != null)
sb.append(inputLine);
strbuf.append(sb.toString());
this.logger.info("==== " + sb.toString());
} else if (connection.getErrorStream() != null) {
br = new BufferedReader(new InputStreamReader(connection.getErrorStream(), "UTF-8"));
while ((inputLine = br.readLine()) != null)
sb.append(inputLine);
this.logger.info("==== Http Error Resopnse : " + sb.toString());
nResult = -1;
} else {
this.logger.info("==== Http Error Resopnse : " + sb.toString());
nResult = -1;
}
} catch (Exception e) {
this.logger.info("Exception : " + e);
this.logger.info("==== Http Error Resopnse : ");
nResult = -1;
} finally {
try {
if (is != null)
is.close();
if (isr != null)
isr.close();
if (br != null)
br.close();
} catch (Exception exception) {}
}
return nResult;
}
}

@ -9,15 +9,14 @@ import java.net.URLConnection;
import org.apache.log4j.Logger;
public class SmtURLDownloadFunc {
private static final Logger logger = Logger.getLogger(SmtURLDownloadFunc.class);
private static final Logger logger = Logger.getLogger(SmtURLDownloadFunc.class);
static final int size = 4096;
static final int size = 4096;
public static void fileUrlReadAndDownload(String fileAddress, String localFileName, String downloadDir) {
public static void fileUrlReadAndDownload(String fileAddress, String localFileName, String downloadDir) {
OutputStream outStream = null;
URLConnection uCon = null;

Loading…
Cancel
Save