diff --git a/.gitignore b/.gitignore
index 4c8fd93..dbf74fa 100644
--- a/.gitignore
+++ b/.gitignore
@@ -10,6 +10,9 @@ local.properties
.settings/
.loadpath
.recommenders
+.classpath
+.project
+build/
# External tool builders
.externalToolBuilders/
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..e3e1336
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,7 @@
+
+ 4.0.0
+ cokr.xit
+ dummyNxrpEsb
+ 0.0.1-SNAPSHOT
+ jar
+
\ No newline at end of file
diff --git a/src/main/java/cokr/xit/Contract.java b/src/main/java/cokr/xit/Contract.java
new file mode 100644
index 0000000..f829b76
--- /dev/null
+++ b/src/main/java/cokr/xit/Contract.java
@@ -0,0 +1,79 @@
+package cokr.xit;
+
+public class Contract {
+
+ private String srcSstKey;
+
+ private String deptCd;
+ private String entNm;
+ private String entNo;
+ private String vhrno;
+ private String contractNo;
+ private String contractStartYmd;
+ private String contractEndYmd;
+ private String pyrNm;
+ private String lcnsNo;
+
+ public String getSrcSstKey() {
+ return srcSstKey;
+ }
+ public void setSrcSstKey(String srcSstKey) {
+ this.srcSstKey = srcSstKey;
+ }
+
+ public String getDeptCd() {
+ return deptCd;
+ }
+ public void setDeptCd(String deptCd) {
+ this.deptCd = deptCd;
+ }
+ public String getEntNm() {
+ return entNm;
+ }
+ public void setEntNm(String entNm) {
+ this.entNm = entNm;
+ }
+ public String getEntNo() {
+ return entNo;
+ }
+ public void setEntNo(String entNo) {
+ this.entNo = entNo;
+ }
+ public String getVhrno() {
+ return vhrno;
+ }
+ public void setVhrno(String vhrno) {
+ this.vhrno = vhrno;
+ }
+ public String getContractNo() {
+ return contractNo;
+ }
+ public void setContractNo(String contractNo) {
+ this.contractNo = contractNo;
+ }
+ public String getContractStartYmd() {
+ return contractStartYmd;
+ }
+ public void setContractStartYmd(String contractStartYmd) {
+ this.contractStartYmd = contractStartYmd;
+ }
+ public String getContractEndYmd() {
+ return contractEndYmd;
+ }
+ public void setContractEndYmd(String contractEndYmd) {
+ this.contractEndYmd = contractEndYmd;
+ }
+ public String getPyrNm() {
+ return pyrNm;
+ }
+ public void setPyrNm(String pyrNm) {
+ this.pyrNm = pyrNm;
+ }
+ public String getLcnsNo() {
+ return lcnsNo;
+ }
+ public void setLcnsNo(String lcnsNo) {
+ this.lcnsNo = lcnsNo;
+ }
+
+}
diff --git a/src/main/java/cokr/xit/MainClass.java b/src/main/java/cokr/xit/MainClass.java
new file mode 100644
index 0000000..12b94a7
--- /dev/null
+++ b/src/main/java/cokr/xit/MainClass.java
@@ -0,0 +1,301 @@
+package cokr.xit;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.FilenameFilter;
+import java.io.IOException;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+import cokr.xit.base.file.ZIP;
+
+public class MainClass {
+
+ public enum WORKING_UNIT {
+ DOWNLOAD_DIR, ZIP_PATH, TXT_PATH, TXT_LINE
+ }
+
+
+ public static void main(String[] args) throws IOException {
+
+ String curJarPath = ClassLoader.getSystemClassLoader().getResource(".").getPath();
+ if(curJarPath.startsWith("/C:/") || curJarPath.startsWith("/D:/") || curJarPath.startsWith("/E:/")) {
+ curJarPath = curJarPath.substring(1);
+ }
+
+ String receiveFilesPath = curJarPath + "files/RCV/1741000NIS";
+
+ String sendFilesPath = curJarPath + "files/SND/1741000NIS";
+
+ List contractDatas = new ArrayList<>();
+
+ getContractInfoFromWorkingUnit(WORKING_UNIT.DOWNLOAD_DIR, sendFilesPath, contractDatas);
+
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
+ String curYmdhms = sdf.format(new Date());
+ String receiveFileName = "EBF_1741000NIS_Z000001LGE_2001_"+curYmdhms+"000"+"@6510000ECA";
+ String txtFilePath = receiveFilesPath + "/" + receiveFileName + ".txt";
+ String zipFilePath = receiveFilesPath + "/" + receiveFileName + ".zip";
+ File txtFile = new File(txtFilePath);
+ txtFile.createNewFile();
+ FileWriter fileWriter = new FileWriter(txtFile);
+
+ List respLines = makeResp(contractDatas);
+
+ for(String respLine : respLines) {
+ fileWriter.write(respLine);
+ fileWriter.write("\r\n");
+ }
+ fileWriter.close();
+ new ZIP().compress(zipFilePath, txtFilePath);
+ txtFile.delete();
+
+ System.out.println("종료");
+ }
+
+
+ private static List makeResp(List contractDatas) {
+ List lines = new ArrayList<>();
+
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
+ String curYmd = sdf.format(new Date());
+
+ for(Contract contractData : contractDatas) {
+
+ String lcnsNo = contractData.getLcnsNo();
+ String npaRespNm = "";
+ String npaPyrNm = "";
+ String npaPyrNo = "";
+ String pyrSeCd = "";
+ String jibeonRoadSeCd = "";
+ String roadCd = "";
+ String underYn = "";
+ String buildMain = "";
+ String buildSub = "";
+ String postNo = "";
+ String addr = "";
+ String daddr = "";
+ String stdgCd = "";
+ String dongCd = "";
+
+ switch (lcnsNo) {
+ case "111111111111":
+ npaRespNm = "정상";
+ npaPyrNm = "홍길동";
+ npaPyrNo = "1111111111111";
+ pyrSeCd = "01";
+ jibeonRoadSeCd = "";
+ roadCd = "";
+ underYn = "";
+ buildMain = "";
+ buildSub = "";
+ postNo = "";
+ addr = "";
+ daddr = "";
+ stdgCd = "";
+ dongCd = "";
+ break;
+ case "170200214712":
+ npaRespNm = "정상";
+ npaPyrNm = "박성영";
+ npaPyrNo = "1111112222222";
+ pyrSeCd = "01";
+ jibeonRoadSeCd = "";
+ roadCd = "";
+ underYn = "N";
+ buildMain = "5";
+ buildSub = "6";
+ postNo = "11222";
+ addr = "서울특별시 서서구 cc길";
+ daddr = "n층";
+ stdgCd = "";
+ dongCd = "";
+ break;
+ case "160561804720":
+ npaRespNm = "정상";
+ npaPyrNm = "김지호";
+ npaPyrNo = "1111113333333";
+ pyrSeCd = "01";
+ jibeonRoadSeCd = "";
+ roadCd = "";
+ underYn = "N";
+ buildMain = "3";
+ buildSub = "4";
+ postNo = "12345";
+ addr = "서울특별시 동동구 bb로";
+ daddr = "m층";
+ stdgCd = "";
+ dongCd = "";
+ break;
+ case "119363847024":
+ npaRespNm = "정상";
+ npaPyrNm = "신영균";
+ npaPyrNo = "1111114444444";
+ pyrSeCd = "01";
+ jibeonRoadSeCd = "";
+ roadCd = "";
+ underYn = "N";
+ buildMain = "1";
+ buildSub = "2";
+ postNo = "01234";
+ addr = "서울특별시 남남구 aa대로";
+ daddr = "o층";
+ stdgCd = "";
+ dongCd = "";
+ break;
+ default:
+ npaRespNm = "없음";
+ npaPyrNm = "";
+ npaPyrNo = "";
+ pyrSeCd = "";
+ jibeonRoadSeCd = "";
+ roadCd = "";
+ underYn = "";
+ buildMain = "";
+ buildSub = "";
+ postNo = "";
+ addr = "";
+ daddr = "";
+ stdgCd = "";
+ dongCd = "";
+ break;
+ }
+
+ String line = "";
+ line += curYmd;
+ line += "|";
+ line += contractData.getSrcSstKey();
+ line += "|";
+ line += contractData.getDeptCd();
+ line += "|";
+ line += npaRespNm;//경찰응답명
+ line += "|";
+ line += npaPyrNm;//경찰납부자명
+ line += "|";
+ line += npaPyrNo;//경찰납부자번호
+ line += "|";
+ line += pyrSeCd;//납부자구분코드
+ line += "|";
+ line += jibeonRoadSeCd;//지번인가도로명인가
+ line += "|";
+ line += roadCd;//도로명코드
+ line += "|";
+ line += underYn;//지하여부yn
+ line += "|";
+ line += buildMain;//건물본
+ line += "|";
+ line += buildSub;//건물부
+ line += "|";
+ line += postNo;//우편번호
+ line += "|";
+ line += addr;//기본주소
+ line += "|";
+ line += daddr;//상세주소
+ line += "|";
+ line += stdgCd;//법정동코드
+ line += "|";
+ line += dongCd;//행정동코드
+
+ lines.add(line);
+ }
+ return lines;
+ }
+
+
+ public static void getContractInfoFromWorkingUnit(WORKING_UNIT pathType, String workingUnitString, List results) {
+ FilenameFilter zipFilter = new FilenameFilter() {
+ @Override
+ public boolean accept(File dir, String name) {
+ return (name.toUpperCase().endsWith(".ZIP"));
+ }
+ };
+
+ switch(pathType) {
+ case DOWNLOAD_DIR:
+
+ List zips = new ArrayList<>();
+ for(File file : new File(workingUnitString).listFiles(zipFilter)) {
+
+ zips.add(file.getPath());
+ }
+
+ for(String zip : zips) {
+ getContractInfoFromWorkingUnit(WORKING_UNIT.ZIP_PATH,zip,results);
+ }
+ break;
+ case ZIP_PATH:
+
+ String zip = workingUnitString;
+ String unzip = workingUnitString.substring(0,zip.length()-4);
+ new ZIP().decompress(zip, unzip);
+
+ List txts = new ArrayList<>();
+ for(File file : new File(unzip).listFiles()) {
+ txts.add(file.getPath());
+ }
+
+ for(String txt : txts) {
+ getContractInfoFromWorkingUnit(WORKING_UNIT.TXT_PATH,txt,results);
+ }
+
+ new File(zip).delete();
+ new File(unzip).delete();
+
+ break;
+ case TXT_PATH:
+
+ File txtFile = new File(workingUnitString);
+
+ List lines = new ArrayList<>();
+
+ try (BufferedReader reader = new BufferedReader(new FileReader(txtFile))) {
+ String line;
+ // 파일의 각 줄을 읽어와 화면에 출력합니다.
+ while ((line = reader.readLine()) != null) {
+ lines.add(line);
+ }
+ } catch (IOException e) {
+ // 파일이 존재하지 않거나 읽기 오류가 발생하면 예외를 처리합니다.
+ System.err.println("파일을 읽는 중 오류가 발생했습니다: " + e.getMessage());
+ e.printStackTrace();
+ return;
+ }
+
+ for(String line : lines) {
+ if(line != null && !line.equals("")) {
+ getContractInfoFromWorkingUnit(WORKING_UNIT.TXT_LINE,line,results);
+ }
+ }
+
+ txtFile.delete();
+ break;
+ case TXT_LINE:
+
+ String[] items = workingUnitString.split("\\|",-1);
+
+ Contract contractVO = new Contract();
+ String srcSstKey = items[1-1];
+
+ contractVO.setSrcSstKey(srcSstKey);
+ contractVO.setDeptCd(items[2-1]);
+ contractVO.setEntNm(items[3-1]);
+ contractVO.setEntNo(items[4-1]);
+ contractVO.setVhrno(items[5-1]);
+ contractVO.setContractNo(items[6-1]);
+ contractVO.setContractStartYmd(items[7-1]);
+ contractVO.setContractEndYmd(items[8-1]);
+ contractVO.setPyrNm(items[9-1]);
+ contractVO.setLcnsNo(items[10-1]);
+
+
+ results.add(contractVO);
+
+ break;
+ }
+ }
+
+}
diff --git a/src/main/java/cokr/xit/base/file/ZIP.java b/src/main/java/cokr/xit/base/file/ZIP.java
new file mode 100644
index 0000000..8676e61
--- /dev/null
+++ b/src/main/java/cokr/xit/base/file/ZIP.java
@@ -0,0 +1,163 @@
+package cokr.xit.base.file;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.InputStream;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
+import java.util.zip.ZipOutputStream;
+
+public class ZIP {
+ /**zip 파일(*.zip)의 mime type */
+ public static final String MIME_TYPE = "application/zip";
+
+ /**지정한 파일들을 지정한 경로의 zip 파일로 압축한다.
+ * @param zipPath zip 파일 경로
+ * @param targets 압축할 파일들의 경로
+ * @return 압축한 zip 파일
+ */
+ public File compress(String zipPath, String... targets) {
+ return compress(zipPath, Arrays.asList(targets));
+ }
+
+ /**지정한 파일들을 지정한 경로의 zip 파일로 압축한다.
+ * @param zipPath zip 파일 경로
+ * @param targets 압축할 파일들의 경로
+ * @return 압축한 zip 파일
+ */
+ public File compress(String zipPath, List targets) {
+ File zip = zipFile(zipPath);
+ try (
+ FileOutputStream fout = new FileOutputStream(zip);
+ ZipOutputStream zout = new ZipOutputStream(fout);
+ ) {
+ for (String path: targets) {
+ File file = new File(path);
+ compress(zout, file, file.getName());
+ }
+
+ return zip;
+ } catch(Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ private File zipFile(String zipPath) {
+ File zip = new File(zipPath);
+ File dir = zip.getParentFile();
+ if (dir != null && !dir.exists())
+ dir.mkdirs();
+ return zip;
+ }
+
+ /**지정한 파일들을 지정한 경로의 zip 파일로 압축한다.
+ * @param zipPath zip 파일 경로
+ * @param inputs 압축할 파일의 InputStream 맵
+ * - key - 압축할 파일이름
+ * - value - 압축할 파일의 InputStream
+ *
+ */
+ public File compress(String zipPath, Map inputs) {
+ File zip = zipFile(zipPath);
+ try (
+ FileOutputStream fout = new FileOutputStream(zip);
+ ZipOutputStream zout = new ZipOutputStream(fout );
+ ) {
+ inputs.forEach((filename, input) -> {
+ try {
+ compress(zout, filename, input);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ });
+ return zip;
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+
+ private void compress(ZipOutputStream zout, File file, String filename) throws Exception {
+ if (file.isHidden()) return;
+
+ if (file.isDirectory()) {
+ zout.putNextEntry(new ZipEntry(filename.endsWith("/") ? filename : filename + "/"));
+ zout.closeEntry();
+
+ File[] children = file.listFiles();
+ for (File child: children) {
+ compress(zout, child, filename + "/" + child.getName());
+ }
+ } else
+ compress(zout, filename, new FileInputStream(file));
+ }
+
+ private void compress(ZipOutputStream zout, String filename, InputStream input) throws Exception {
+ try (InputStream stream = input) {
+ zout.putNextEntry(new ZipEntry(filename));
+ byte[] bytes = new byte[1024];
+ int length;
+ while((length = stream.read(bytes)) >= 0) {
+ zout.write(bytes, 0, length);
+ }
+ }
+ }
+
+ /**지정한 zip 파일을 지정한 경로의 디렉토리에 압축을 해제한다.
+ * @param zipPath zip 파일 경로
+ * @param destDir 압축을 해제한 파일들을 저장할 디렉토리 경로
+ */
+ public void decompress(String zipPath, String destDir) {
+ try (
+ FileInputStream fis = new FileInputStream(zipPath);
+ ZipInputStream zis = new ZipInputStream(fis);
+ ) {
+ decompress(zis, destDir);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ private void decompress(ZipInputStream zis, String destDir) throws Exception {
+ byte[] buff = new byte[1024];
+ File dir = new File(destDir);
+
+ ZipEntry zipEntry = zis.getNextEntry();
+ while (zipEntry != null) {
+ File newFile = newFile(dir, zipEntry);
+
+ if (zipEntry.isDirectory()) {
+ if (!newFile.isDirectory() && !newFile.mkdirs())
+ throw new Exception("Failed to create directory " + newFile);
+ } else {
+ File parent = newFile.getParentFile();
+ if (!parent.isDirectory() && !parent.mkdirs())
+ throw new Exception("Failed to create directory " + parent);
+
+ try (
+ FileOutputStream fos = new FileOutputStream(newFile);
+ ) {
+ int len;
+ while ((len = zis.read(buff)) > 0) {
+ fos.write(buff, 0, len);
+ }
+ }
+ }
+ zipEntry = zis.getNextEntry();
+ }
+ }
+
+ private File newFile(File destDir, ZipEntry zipEntry) throws Exception {
+ File destFile = new File(destDir, zipEntry.getName());
+
+ String destDirPath = destDir.getCanonicalPath();
+ if (!destFile.getCanonicalPath().startsWith(destDirPath + File.separator))
+ throw new Exception(String.format("%s is outside of the %s", zipEntry.getName(), destDirPath));
+
+ return destFile;
+ }
+}