최초커밋

main
이범준 2 months ago
parent 2d7683a8b7
commit bd7408c473

3
.gitignore vendored

@ -10,6 +10,9 @@ local.properties
.settings/
.loadpath
.recommenders
.classpath
.project
build/
# External tool builders
.externalToolBuilders/

@ -0,0 +1,7 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>cokr.xit</groupId>
<artifactId>dummyNxrpEsb</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
</project>

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

@ -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<Contract> 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<String> 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<String> makeResp(List<Contract> contractDatas) {
List<String> 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<Contract> results) {
FilenameFilter zipFilter = new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
return (name.toUpperCase().endsWith(".ZIP"));
}
};
switch(pathType) {
case DOWNLOAD_DIR:
List<String> 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<String> 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<String> 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;
}
}
}

@ -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<String> 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
* <ul><li>key - </li>
* <li>value - InputStream</li>
* </ul>
*/
public File compress(String zipPath, Map<String, InputStream> 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;
}
}
Loading…
Cancel
Save