파일 다운로드 수정

master
mjkhan21 2 weeks ago
parent 93ea2ffdf9
commit 1a01c2887f

@ -51,6 +51,11 @@
<artifactId>xit-file</artifactId> <artifactId>xit-file</artifactId>
<version>23.04.01-SNAPSHOT</version> <version>23.04.01-SNAPSHOT</version>
</dependency> </dependency>
<dependency>
<groupId>cokr.xit.base</groupId>
<artifactId>xit-crypto</artifactId>
<version>23.04.01-SNAPSHOT</version>
</dependency>
<dependency> <dependency>
<groupId>cokr.xit.interfaces</groupId> <groupId>cokr.xit.interfaces</groupId>

@ -15,6 +15,7 @@ import lombok.Setter;
public class SOHNN00011 extends SaeolMessage { public class SOHNN00011 extends SaeolMessage {
public static final String INF_TYPE = "011"; public static final String INF_TYPE = "011";
private ArrayList<FileInfo> fileInfos; private ArrayList<FileInfo> fileInfos;
private ArrayList<File> converted; private ArrayList<File> converted;
@ -110,6 +111,13 @@ public class SOHNN00011 extends SaeolMessage {
public List<FileItem> getFileinfo_p() { public List<FileItem> getFileinfo_p() {
return ifEmpty(fileinfo_p, Collections::emptyList); return ifEmpty(fileinfo_p, Collections::emptyList);
} }
public List<FileItem> getAllFileinfo() {
ArrayList<FileItem> fileinfo = new ArrayList<>();
fileinfo.addAll(getFileinfo_m());
fileinfo.addAll(getFileinfo_p());
return fileinfo;
}
} }
@Getter @Getter
@ -256,7 +264,7 @@ public class SOHNN00011 extends SaeolMessage {
private String pre_minwon_yn; private String pre_minwon_yn;
public String infoKey() { public String infoKey() {
return getCnsl_qna_no() + "-" + getMsg_key(); return getCnsl_qna_no(); // + "-" + getMsg_key();
} }
} }

@ -30,7 +30,12 @@ public class Configuration extends AbstractComponent {
sido, sido,
sigungu, sigungu,
logXml, logXml,
attachmentDir; attachmentDir,
k_anc_code,
k_anc_id,
k_anc_passwd;
private List<String> deptCodes; private List<String> deptCodes;
private boolean logToDatabase; private boolean logToDatabase;
@ -66,6 +71,18 @@ public class Configuration extends AbstractComponent {
return conf.attachmentDir; return conf.attachmentDir;
} }
public static String k_anc_code() {
return conf.k_anc_code;
}
public static String k_anc_id() {
return conf.k_anc_id;
}
public static String k_anc_passwd() {
return conf.k_anc_passwd;
}
public static List<String> sources() { public static List<String> sources() {
return ifEmpty(conf.sources, Collections::emptyList); return ifEmpty(conf.sources, Collections::emptyList);
} }

@ -14,28 +14,33 @@ import java.net.URI;
import java.net.URLConnection; import java.net.URLConnection;
import java.net.http.HttpClient; import java.net.http.HttpClient;
import java.net.http.HttpResponse; import java.net.http.HttpResponse;
import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Optional; import java.util.Optional;
import java.util.function.Function;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
import cokr.xit.base.crypto.Cryptography;
import cokr.xit.base.crypto.bean.XitAria;
import cokr.xit.base.file.FileInfo; import cokr.xit.base.file.FileInfo;
import cokr.xit.foundation.AbstractComponent; import cokr.xit.foundation.AbstractComponent;
import cokr.xit.foundation.data.DataObject;
import cokr.xit.foundation.util.DateFormats; import cokr.xit.foundation.util.DateFormats;
import cokr.xit.foundation.web.WebClient; import cokr.xit.foundation.web.WebClient;
import cokr.xit.interfaces.saeol.SOHNN00011;
public class EPeople extends AbstractComponent { public class EPeople extends AbstractComponent {
private static String HOST = "https://www.epeople.go.kr"; protected static String HOST = "https://www.epeople.go.kr";
private static XitAria crypto = ((XitAria)Cryptography.get("xit-aria"))
public static boolean supports(String url) { .setKey(new String(new byte[] {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F}));
return url.contains(HOST);
}
private WebClient webClient; private WebClient webClient;
private CookieHandler cookies; private CookieHandler cookies;
private WebClient hclient() throws Exception { protected WebClient hclient() throws Exception {
if (webClient == null) { if (webClient == null) {
CookieManager cm = new CookieManager(); CookieManager cm = new CookieManager();
cm.setCookiePolicy(CookiePolicy.ACCEPT_ALL); cm.setCookiePolicy(CookiePolicy.ACCEPT_ALL);
@ -50,21 +55,39 @@ public class EPeople extends AbstractComponent {
return webClient; return webClient;
} }
public FileInfo download(String filepath, String phoneNo) { public List<FileInfo> download(SOHNN00011.Resp00011 resp) {
SOHNN00011.Item item = resp.getResult();
List<SOHNN00011.FileItem> fileItems = resp.getAllFileinfo();
List<FileInfo> files = download(item.getMw_org_code(), item.getInet_qna_no());
files.forEach(fileInfo -> {
String filename = fileInfo.getName();
Optional<SOHNN00011.FileItem> match = fileItems.stream()
.filter(fileItem -> filename.equals(fileItem.getSys_file_nm())).findFirst();
match.ifPresent(fileItem -> {
String file_type = fileItem.getFile_type();
fileInfo
.setSubType(file_type)
.setSubCode("M".equals(file_type) ? fileItem.getFile_id_m() : fileItem.getFile_id_p());
});
});
return files;
}
public List<FileInfo> download(String mw_org_code, String inet_qna_no) {
try { try {
Info info = getInfo(filepath); Info info = getInfo(mw_org_code, inet_qna_no);
addCookie("fileDownloadToken", "TRUE");
addCookie("XSRF-TOKEN", info.csrf); addCookie("XSRF-TOKEN", info.csrf);
// compare(info, phoneNo);
return download(info); return download(info);
} catch (Exception e) { } catch (Exception e) {
throw runtimeException(e); throw runtimeException(e);
} }
} }
private void addCookie(String name, String value) throws Exception { protected void addCookie(String name, String value) throws Exception {
HttpCookie cookie = new HttpCookie(name, value); HttpCookie cookie = new HttpCookie(name, value);
cookie.setPath("/"); cookie.setPath("/");
cookie.setVersion(1); cookie.setVersion(1);
@ -72,76 +95,83 @@ public class EPeople extends AbstractComponent {
((CookieManager)cookies).getCookieStore().add(new URI(HOST), cookie); ((CookieManager)cookies).getCookieStore().add(new URI(HOST), cookie);
} }
private Info getInfo(String url) throws Exception { private static Map<String, Object> commonParams = Map.of(
"k_anc_code", crypto.encrypt(Configuration.k_anc_code()),
"k_anc_id", crypto.encrypt(Configuration.k_anc_id()),
"k_anc_passwd", crypto.encrypt(Configuration.k_anc_passwd())
);
private Info getInfo(String mw_org_code, String inet_qna_no) throws Exception {
String url = HOST + ":8055/jsp/other/ic/local/AIcDecryptExtPetiFileList.jsp";
HttpResponse<String> hresp = hclient().get(req -> HttpResponse<String> hresp = hclient().get(req ->
req.uri(url.replace("http://www.epeople.go.kr", HOST)) req.uri(url.replace("http://www.epeople.go.kr", HOST))
.noCache() .noCache()
); .data(commonParams)
Info info = Info.parse(hresp.body()); .data("k_local_anc_code_v", crypto.encrypt(mw_org_code.trim()))
log().debug("EPeople.Info:\n{}", info.toString().replace(", ", "\n")); .data("k_local_peti_no_c", crypto.encrypt(inet_qna_no.trim()))
return info;
}
private void compare(Info info, String phoneNo) throws Exception {
HttpResponse<String> hresp = hclient().post(req ->
req.uri(HOST + "/paid/syscmmn/fileDwldCompare.npaid")
.noCache()
.contentType(WebClient.Request.ContentType.FORM)
.header("Accept", "application/json, text/javascript, */*; q=0.01")
.header("X-Requested-With", "XMLHttpRequest")
.header("AJAX", "true")
.header("X-CSRF-TOKEN", info.csrf)
.data(info.asParams())
.data("encryptValue", phoneNo)
); );
System.out.println(hresp.body()); return Info.parse(hresp.body());
} }
private FileInfo download(Info info) throws Exception { private ArrayList<FileInfo> download(Info info) throws Exception {
HttpResponse<InputStream> hresp = hclient().post(req -> String url = HOST + ":8055/paid/syscmmn/fileDwldForCntc.npaid";
req.uri(HOST + "/paid/syscmmn/fileDwld.npaid") Function<Download, FileInfo> getFileInfo = download -> {
.noCache() try {
.contentType(WebClient.Request.ContentType.FORM) HttpResponse<InputStream> hresp = hclient().post(req ->
.header("X-CSRF-TOKEN", info.csrf) req.uri(url)
.noCache()
.contentType(WebClient.Request.ContentType.FORM)
.data(info.asParams()) .data(info.common)
.data(download.asParams().set("_csrf", info.csrf))
.download(true) .download(true)
); );
InputStream downloaded = hresp.body(); InputStream downloaded = hresp.body();
if (WebClient.Request.SUCCESS != hresp.statusCode()) { if (WebClient.Request.SUCCESS != hresp.statusCode()) {
if (info.retry()) { log().debug(hclient().toString(downloaded).trim());
log().debug("Retrying to download the attachment"); return null;
return download(info); }
}
log().debug(hclient().toString(downloaded).trim());
return null;
}
String filename = info.filename; String filename = download.filename;
Optional<String> header = hresp.headers().firstValue("content-length"); Optional<String> header = hresp.headers().firstValue("content-length");
long length = header.isPresent() ? Long.parseLong(header.get()) : 0; long length = header.isPresent() ? Long.parseLong(header.get()) : 0;
FileInfo fileInfo = new FileInfo(); FileInfo fileInfo = new FileInfo();
fileInfo.setName(filename); fileInfo.setName(filename);
fileInfo.setInputStream(downloaded); fileInfo.setInputStream(downloaded);
String mimeType = URLConnection.guessContentTypeFromName(filename); String mimeType = URLConnection.guessContentTypeFromName(filename);
if (isEmpty(mimeType)) if (isEmpty(mimeType))
mimeType = URLConnection.guessContentTypeFromStream(downloaded); mimeType = URLConnection.guessContentTypeFromStream(downloaded);
fileInfo.setMimeType(mimeType); fileInfo.setMimeType(mimeType);
if (length > 0) if (length > 0)
fileInfo.setSize(length); fileInfo.setSize(length);
log().debug("{} downloaded", filename); log().debug("{} downloaded", filename);
return fileInfo; return fileInfo;
} catch (Exception e) {
throw runtimeException(e);
}
};
ArrayList<FileInfo> result = new ArrayList<>();
for (Download download: info.downloads) {
FileInfo fileInfo = getFileInfo.apply(download);
if (fileInfo == null && download.retry())
fileInfo = getFileInfo.apply(download);
if (fileInfo != null) {
fileInfo.setSortOrder(result.size() + 1);
result.add(fileInfo);
}
}
return result;
} }
private static String parseValue(String body, String head, String tail) { protected static String parseValue(String body, String head, String tail) {
int start = body.indexOf(head); int start = body.indexOf(head);
if (start < 0) return ""; if (start < 0) return "";
@ -204,51 +234,92 @@ public class EPeople extends AbstractComponent {
} }
} }
public static class Info { private static class Download {
private String static Download parse(int start, String str) {
csrf, String token = "doSubmit('";
atchFileGrpId, int pos = str.indexOf(token, start);
atchFileId, if (pos < 0) return null;
oldAtchFileId,
doc_id,
filename;
private int attempt = 1;
public static Info parse(String str) { pos += token.length();
Info info = new Info();
info.csrf = parseValue(str, "\"_csrf\" content=\"", "\"").trim(); token = ",";
info.atchFileGrpId = parseValue(str, "atchFileGrpId\" value=\"", "\"").trim(); int end = str.indexOf(token, pos);
info.atchFileId = parseValue(str, "atchFileId\" value=\"", "\"").trim(); if (end < 0) return null;
info.oldAtchFileId = parseValue(str, "oldAtchFileId\" value=\"", "\"").trim();
info.doc_id = parseValue(str, "doc_id\" value=\"", "\"").trim();
info.filename = parseValue(str, "filename\" value=\"", "\"").trim();
return info; Download download = new Download();
download.fileId = str.substring(pos, end);
token = ",'";
pos = str.indexOf(token, end);
if (pos > -1) {
pos += token.length();
token = "')";
end = str.indexOf(token, pos);
download.fileGrpId = str.substring(pos, end);
}
token = "<b class=\"td_u blue\">";
pos = str.indexOf(token, end);
if (pos > -1) {
pos += token.length();
token = "</b>";
end = str.indexOf(token, pos);
download.filename = str.substring(pos, end);
}
download.next = ++end;
return download;
} }
public Map<String, String> asParams() { private String
return Map.of( fileGrpId,
"atchFileGrpId", atchFileGrpId, fileId,
"atchFileId", atchFileId, filename;
"oldAtchFileId", "oldAtchFileId", private int
"doc_id", doc_id, next,
"filename", filename, attempt = 1;
"_csrf", csrf
); DataObject asParams() {
return new DataObject()
.set("atchFileGrpId", fileGrpId)
.set("atchFileId", fileId);
} }
public boolean retry() { boolean retry() {
++attempt; return ++attempt < 6;
return attempt < 6;
} }
}
@Override private static class Info {
public String toString() { private DataObject common = new DataObject();
return String.format( private String csrf;
"csrf: %s, atchFileGrpId: %s, atchFileId: %s, oldAtchFileId: %s, doc_id: %s, filename: %s", private ArrayList<Download> downloads = new ArrayList<>();
csrf, atchFileGrpId, atchFileId, oldAtchFileId, doc_id, filename
); static Info parse(String body) {
log(EPeople2.class).debug(body);
Info info = new Info();
info.csrf = parseValue(body, "\"_csrf\" content=\"", "\"").trim();
info.common
.set("k_local_anc_code_v", parseValue(body, "k_local_anc_code_v : \"", "\","))
.set("k_local_peti_no_c", parseValue(body, "k_local_peti_no_c :\"", "\","))
.set("k_anc_code", parseValue(body, "k_anc_code : \"", "\","))
.set("k_anc_id", parseValue(body, "k_anc_id : \"", "\","))
.set("k_anc_passwd", parseValue(body, "k_anc_passwd : \"", "\","));
int start = 0;
while (start > -1) {
Download download = Download.parse(start, body);
if (download == null) {
start = -1;
break;
}
info.downloads.add(download);
start = download.next;
}
return info;
} }
} }
} }

@ -0,0 +1,164 @@
package cokr.xit.interfaces.saeol.service.bean;
import java.io.InputStream;
import java.net.URLConnection;
import java.net.http.HttpResponse;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import cokr.xit.base.file.FileInfo;
import cokr.xit.foundation.web.WebClient;
import cokr.xit.interfaces.saeol.SOHNN00011;
public class EPeople2 extends EPeople {
@Override
public List<FileInfo> download(SOHNN00011.Resp00011 resp) {
SOHNN00011.Item item = resp.getResult();
String phoneNo = ifEmpty(item.getTelno_m(), item::getHpno_m);
return resp.getAllFileinfo().stream()
.map(file -> {
FileInfo fileInfo = downloadFrom(file.getFile_path(), phoneNo);
if (fileInfo != null) {
String file_type = file.getFile_type();
fileInfo.setSubType(file_type);
fileInfo.setSubCode("M".equals(file_type) ? file.getFile_id_m() : file.getFile_id_p());
}
return fileInfo;
})
.filter(fileInfo -> fileInfo != null)
.toList();
}
public FileInfo downloadFrom(String filepath, String phoneNo) {
try {
Info info = getInfo(filepath);
addCookie("fileDownloadToken", "TRUE");
addCookie("XSRF-TOKEN", info.csrf);
// compare(info, phoneNo);
return download(info);
} catch (Exception e) {
throw runtimeException(e);
}
}
private Info getInfo(String url) throws Exception {
HttpResponse<String> hresp = hclient().get(req ->
req.uri(url.replace("http://www.epeople.go.kr", HOST))
.noCache()
);
Info info = Info.parse(hresp.body());
log().debug("EPeople.Info:\n{}", info.toString().replace(", ", "\n"));
return info;
}
private void compare(Info info, String phoneNo) throws Exception {
HttpResponse<String> hresp = hclient().post(req ->
req.uri(HOST + "/paid/syscmmn/fileDwldCompare.npaid")
.noCache()
.contentType(WebClient.Request.ContentType.FORM)
.header("Accept", "application/json, text/javascript, */*; q=0.01")
.header("X-Requested-With", "XMLHttpRequest")
.header("AJAX", "true")
.header("X-CSRF-TOKEN", info.csrf)
.data(info.asParams())
.data("encryptValue", phoneNo)
);
log().debug(hresp.body());
}
private FileInfo download(Info info) throws Exception {
HttpResponse<InputStream> hresp = hclient().post(req ->
req.uri(HOST + "/paid/syscmmn/fileDwld.npaid")
.noCache()
.contentType(WebClient.Request.ContentType.FORM)
.header("X-CSRF-TOKEN", info.csrf)
.data(info.asParams())
.download(true)
);
InputStream downloaded = hresp.body();
if (WebClient.Request.SUCCESS != hresp.statusCode()) {
if (info.retry()) {
log().debug("Retrying to download the attachment");
return download(info);
}
log().debug(hclient().toString(downloaded).trim());
return null;
}
String filename = info.filename;
Optional<String> header = hresp.headers().firstValue("content-length");
long length = header.isPresent() ? Long.parseLong(header.get()) : 0;
FileInfo fileInfo = new FileInfo();
fileInfo.setName(filename);
fileInfo.setInputStream(downloaded);
String mimeType = URLConnection.guessContentTypeFromName(filename);
if (isEmpty(mimeType))
mimeType = URLConnection.guessContentTypeFromStream(downloaded);
fileInfo.setMimeType(mimeType);
if (length > 0)
fileInfo.setSize(length);
log().debug("{} downloaded", filename);
return fileInfo;
}
public static class Info {
private String
csrf,
atchFileGrpId,
atchFileId,
oldAtchFileId,
doc_id,
filename;
private int attempt = 1;
public static Info parse(String str) {
Info info = new Info();
info.csrf = parseValue(str, "\"_csrf\" content=\"", "\"").trim();
info.atchFileGrpId = parseValue(str, "atchFileGrpId\" value=\"", "\"").trim();
info.atchFileId = parseValue(str, "atchFileId\" value=\"", "\"").trim();
info.oldAtchFileId = parseValue(str, "oldAtchFileId\" value=\"", "\"").trim();
info.doc_id = parseValue(str, "doc_id\" value=\"", "\"").trim();
info.filename = parseValue(str, "filename\" value=\"", "\"").trim();
return info;
}
public Map<String, String> asParams() {
return Map.of(
"atchFileGrpId", atchFileGrpId,
"atchFileId", atchFileId,
"oldAtchFileId", "oldAtchFileId",
"doc_id", doc_id,
"filename", filename,
"_csrf", csrf
);
}
public boolean retry() {
++attempt;
return attempt < 6;
}
@Override
public String toString() {
return String.format(
"csrf: %s, atchFileGrpId: %s, atchFileId: %s, oldAtchFileId: %s, doc_id: %s, filename: %s",
csrf, atchFileGrpId, atchFileId, oldAtchFileId, doc_id, filename
);
}
}
}

@ -2,7 +2,6 @@ package cokr.xit.interfaces.saeol.service.bean;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -13,15 +12,17 @@ import org.springframework.stereotype.Component;
import cokr.xit.base.file.FileInfo; import cokr.xit.base.file.FileInfo;
import cokr.xit.base.file.service.bean.FileBean; import cokr.xit.base.file.service.bean.FileBean;
import cokr.xit.foundation.data.DataObject;
import cokr.xit.interfaces.saeol.SOHNN00004; import cokr.xit.interfaces.saeol.SOHNN00004;
import cokr.xit.interfaces.saeol.SOHNN00011; import cokr.xit.interfaces.saeol.SOHNN00011;
@Component("minwonBean") @Component("minwonBean")
@Scope("prototype") @Scope("prototype")
public class MinwonBean extends SaeolBean { public class MinwonBean extends SaeolBean {
private EPeople epeople = new EPeople();
@Resource(name = "fileBean") @Resource(name = "fileBean")
private FileBean fileBean; private FileBean fileBean;
private EPeople epeople = new EPeople();
private EPeople2 epeople2 = new EPeople2();
public MinwonBean() { public MinwonBean() {
log().debug("MinwonBean created"); log().debug("MinwonBean created");
@ -37,9 +38,9 @@ public class MinwonBean extends SaeolBean {
if (resp00004.error()) if (resp00004.error())
return resp00004.getFault().toMap(); return resp00004.getFault().toMap();
LinkedHashMap<String, Object> result = new LinkedHashMap<>(); DataObject result = new DataObject()
result.put("success", true); .set("success", true)
result.put("minwonsReceived", resp00004.getResult().size()); .set("minwonsReceived", resp00004.getResult().size());
resp00004.getResult().stream() resp00004.getResult().stream()
.map(item -> { .map(item -> {
@ -57,23 +58,7 @@ public class MinwonBean extends SaeolBean {
sohnn00011.getConverted().forEach(File::delete); sohnn00011.getConverted().forEach(File::delete);
}); });
/*
.forEach(sohnn00011 -> {
List<FileInfo> files = sohnn00011.getFileInfos();
if (Configuration.logToDatabase())
fileBean.create(files);
else
epeople.write(files);
sohnn00011.getConverted().forEach(File::delete);
});
for (SOHNN00004.Item item: resp00004.getResult()) {
String cnsl_qna_no = item.getCnsl_qna_no();
SOHNN00011 sohnn00011 = getSOHNN00011(cnsl_qna_no, item.getDetail());
result.put(cnsl_qna_no, !sohnn00011.getResponse().error() ? "success" : "fail");
}
*/
return result; return result;
} }
@ -123,79 +108,32 @@ public class MinwonBean extends SaeolBean {
if (affected > 0) if (affected > 0)
log(msg); log(msg);
if (SOHNN00004.Item.GET.equals(detail)) { if (SOHNN00004.Item.GET.equals(detail))
String phoneNo = ifEmpty(result.getTelno_m(), result::getHpno_m); downloadFiles(msg);
FileInfo.Relation relation = new FileInfo.Relation()
.setInfoType(SOHNN00011.INF_TYPE)
.setInfoKey(result.infoKey());
create(msg, relation, phoneNo, resp.getFileinfo_m());
create(msg, relation, phoneNo, resp.getFileinfo_p());
// create(relation, phoneNo, resp.getFileinfo_m());
// create(relation, phoneNo, resp.getFileinfo_p());
}
return resp; return resp;
} }
private void create(SOHNN00011 msg, FileInfo.Relation relation, String phoneNo, List<SOHNN00011.FileItem> fileItems) { private void downloadFiles(SOHNN00011 msg) {
ArrayList<File> converted = new ArrayList<>(); SOHNN00011.Resp00011 resp = msg.getResponse();
SOHNN00011.Item result = resp.getResult();
List<FileInfo> files = fileItems.stream() FileInfo.Relation relation = new FileInfo.Relation()
.map(fileItem -> { .setInfoType(SOHNN00011.INF_TYPE)
FileInfo fileInfo = epeople.download(fileItem.getFile_path(), phoneNo); .setInfoKey(result.infoKey());
if (fileInfo == null) return null;
relation.setInfo(fileInfo);
String file_type = fileItem.getFile_type();
fileInfo.setSubType(file_type);
fileInfo.setSubCode("M".equals(file_type) ? fileItem.getFile_id_m() : fileItem.getFile_id_p());
fileInfo.setSortOrder(fileItem.getFile_seq());
File jpg = epeople.pngToJpg(fileInfo);
if (jpg != null)
converted.add(jpg);
return fileInfo; ArrayList<File> converted = new ArrayList<>();
}) List<FileInfo> files = ifEmpty(epeople.download(resp), () -> epeople2.download(resp));
.filter(fileInfo -> fileInfo != null) files.forEach(fileInfo -> {
.toList(); relation.setInfo(fileInfo);
File jpg = epeople.pngToJpg(fileInfo);
if (jpg != null)
converted.add(jpg);
});
msg.addFileInfos(files); msg.addFileInfos(files);
msg.addConverted(converted); msg.addConverted(converted);
} }
private void create(FileInfo.Relation relation, String phoneNo, List<SOHNN00011.FileItem> fileItems) {
ArrayList<File> converted = new ArrayList<>();
List<FileInfo> files = fileItems.stream()
.map(fileItem -> {
FileInfo fileInfo = epeople.download(fileItem.getFile_path(), phoneNo);
if (fileInfo == null) return null;
relation.setInfo(fileInfo);
String file_type = fileItem.getFile_type();
fileInfo.setSubType(file_type);
fileInfo.setSubCode("M".equals(file_type) ? fileItem.getFile_id_m() : fileItem.getFile_id_p());
fileInfo.setSortOrder(fileItem.getFile_seq());
File jpg = epeople.pngToJpg(fileInfo);
if (jpg != null)
converted.add(jpg);
return fileInfo;
})
.filter(fileInfo -> fileInfo != null)
.toList();
if (Configuration.logToDatabase())
fileBean.create(files);
else
epeople.write(files);
converted.forEach(File::delete);
}
public int updateSOHNN00011(String[] cnsl_qna_nos, String[] msg_keys) { public int updateSOHNN00011(String[] cnsl_qna_nos, String[] msg_keys) {
return saeolMapper.updateSOHNN00011(cnsl_qna_nos, msg_keys); return saeolMapper.updateSOHNN00011(cnsl_qna_nos, msg_keys);
} }

@ -5,6 +5,10 @@
"sigungu": "", /* 시군구 코드 */ "sigungu": "", /* 시군구 코드 */
"deptCodes": ["부서코드"], /* 부서코드 */ "deptCodes": ["부서코드"], /* 부서코드 */
"k_anc_code": "3150000", /* 기관코드 */
"k_anc_id": "SU44526786720", /* 연계 ID */
"k_anc_passwd": "ZUDDN1129404", /* 연계 비밀번호 */
"logXml": "files/xml/{date}/{interfaceID}/{msgKey}.xml", /* xml 로그파일 이름 패턴, 로그파일을 남기지 않으려면 제거할 것 */ "logXml": "files/xml/{date}/{interfaceID}/{msgKey}.xml", /* xml 로그파일 이름 패턴, 로그파일을 남기지 않으려면 제거할 것 */
"logToDatabase": true, /* 전문 데이터베이스 사용 여부 */ "logToDatabase": true, /* 전문 데이터베이스 사용 여부 */
"attachmentDir": "files/attachment/{date}", /* 첨부파일 디렉토리 경로 패턴, 전문 데이터베이스를 사용하지 않을 경우에만 유효 */ "attachmentDir": "files/attachment/{date}", /* 첨부파일 디렉토리 경로 패턴, 전문 데이터베이스를 사용하지 않을 경우에만 유효 */

@ -0,0 +1,13 @@
{ "enabled": true,
"cryptoDefs": [
{ "name": "xit-aria",
"class": "cokr.xit.base.crypto.bean.XitAria",
"settings": {
"version": 1,
"charset": "EUC-KR",
"key": "3AsrGqpYYnkHIu3D",
"keySize": 128
}
}
]
}

@ -16,6 +16,7 @@ import cokr.xit.foundation.test.TestSupport;
import cokr.xit.interfaces.saeol.dao.SaeolMapper; import cokr.xit.interfaces.saeol.dao.SaeolMapper;
import cokr.xit.interfaces.saeol.service.bean.Configuration; import cokr.xit.interfaces.saeol.service.bean.Configuration;
import cokr.xit.interfaces.saeol.service.bean.EPeople; import cokr.xit.interfaces.saeol.service.bean.EPeople;
import cokr.xit.interfaces.saeol.service.bean.EPeople2;
import cokr.xit.interfaces.saeol.service.bean.SaeolMessenger; import cokr.xit.interfaces.saeol.service.bean.SaeolMessenger;
import cokr.xit.interfaces.saeol.service.bean.XmlSupport; import cokr.xit.interfaces.saeol.service.bean.XmlSupport;
@ -149,6 +150,13 @@ public class SaeolMessageTest extends TestSupport {
@Test @Test
void download() { void download() {
EPeople epeople = new EPeople(); EPeople epeople = new EPeople();
List<FileInfo> files = epeople.download("1741000", "SPP-2410-2802194 ");
epeople.write(files);
}
@Test
void download2() {
EPeople2 epeople = new EPeople2();
String head = "http://www.epeople.go.kr/FileDownload.do?file=/attach19/nep/eai/"; String head = "http://www.epeople.go.kr/FileDownload.do?file=/attach19/nep/eai/";
List<FileInfo> files = List.of( List<FileInfo> files = List.of(
"2024/10/2/20241002121001397388301&filename=20241002_1_7e23810479054b1ea6ee25246908eb2c.jpg", "2024/10/2/20241002121001397388301&filename=20241002_1_7e23810479054b1ea6ee25246908eb2c.jpg",
@ -157,17 +165,11 @@ public class SaeolMessageTest extends TestSupport {
"2024/9/5/20240905020909019918103&filename=20240905_40cabda891fb4e2895c8964d000604b1_MAPIMG.png" "2024/9/5/20240905020909019918103&filename=20240905_40cabda891fb4e2895c8964d000604b1_MAPIMG.png"
).stream() ).stream()
.map(str -> head + str) .map(str -> head + str)
.map(url -> epeople.download(url, null)) .map(url -> epeople.downloadFrom(url, null))
.toList(); .toList();
epeople.write(files); epeople.write(files);
} }
@Test
void download2() {
// EPeople2 epeople = new EPeople2();
// epeople.download(null, null);
}
private void write(FileInfo fileInfo) { private void write(FileInfo fileInfo) {
if (fileInfo == null) return; if (fileInfo == null) return;

Loading…
Cancel
Save