diff --git a/src/main/java/cokr/xit/interfaces/saeol/SOHNN00011.java b/src/main/java/cokr/xit/interfaces/saeol/SOHNN00011.java index 5cdd397..9b8e179 100644 --- a/src/main/java/cokr/xit/interfaces/saeol/SOHNN00011.java +++ b/src/main/java/cokr/xit/interfaces/saeol/SOHNN00011.java @@ -1,10 +1,13 @@ package cokr.xit.interfaces.saeol; +import java.io.File; +import java.util.ArrayList; import java.util.Collections; import java.util.List; import com.fasterxml.jackson.core.type.TypeReference; +import cokr.xit.base.file.FileInfo; import cokr.xit.foundation.data.XML; import cokr.xit.interfaces.saeol.service.bean.XmlSupport; import lombok.Getter; @@ -12,6 +15,28 @@ import lombok.Setter; public class SOHNN00011 extends SaeolMessage { public static final String INF_TYPE = "011"; + private ArrayList fileInfos; + private ArrayList converted; + + public List getFileInfos() { + return ifEmpty(fileInfos, Collections::emptyList); + } + + public void addFileInfos(List fileInfos) { + if (this.fileInfos == null) + this.fileInfos = new ArrayList<>(); + this.fileInfos.addAll(fileInfos); + } + + public List getConverted() { + return ifEmpty(converted, Collections::emptyList); + } + + public void addConverted(List converted) { + if (this.converted == null) + this.converted = new ArrayList<>(); + this.converted.addAll(converted); + } @Override protected Req00011 newRequest() { diff --git a/src/main/java/cokr/xit/interfaces/saeol/dao/SaeolMapper.java b/src/main/java/cokr/xit/interfaces/saeol/dao/SaeolMapper.java index 3f095bc..65f8b83 100644 --- a/src/main/java/cokr/xit/interfaces/saeol/dao/SaeolMapper.java +++ b/src/main/java/cokr/xit/interfaces/saeol/dao/SaeolMapper.java @@ -74,7 +74,6 @@ public interface SaeolMapper extends AbstractMapper { if (SOHNN00004.Item.GET.equals(detail)) affected = insertSOHNN00011(item); - if (affected < 1 && SOHNN00004.Item.UPDATE.equals(detail)) return affected = updateSOHNN00011(item); @@ -107,5 +106,5 @@ public interface SaeolMapper extends AbstractMapper { int insertSOINN00050(SOINN00050 msg); - int updateSOINN00050(SOINN00050.Resp00050 resp); + int updateSOINN00050(SOINN00050 msg); } \ No newline at end of file diff --git a/src/main/java/cokr/xit/interfaces/saeol/service/SaeolService.java b/src/main/java/cokr/xit/interfaces/saeol/service/SaeolService.java index 53a064d..3e73f7c 100644 --- a/src/main/java/cokr/xit/interfaces/saeol/service/SaeolService.java +++ b/src/main/java/cokr/xit/interfaces/saeol/service/SaeolService.java @@ -6,9 +6,9 @@ import java.util.Map; import cokr.xit.interfaces.saeol.SOINN00050; public interface SaeolService { - Map getMinwons(String deptCode, String fromDate, String toDate); + Map searchMinwons(String deptCode, String fromDate, String toDate); - void getMinwons(); + void searchMinwons(); int updateSOHNN00004(String[] cnsl_qna_nos, String[] msg_keys); @@ -20,5 +20,5 @@ public interface SaeolService { SOINN00050.Resp00050 register(SOINN00050.Req00050 req); - void registerAnswers(); + Map registerAnswers(); } \ No newline at end of file diff --git a/src/main/java/cokr/xit/interfaces/saeol/service/bean/AnswerBean.java b/src/main/java/cokr/xit/interfaces/saeol/service/bean/AnswerBean.java index 67aab31..4230827 100644 --- a/src/main/java/cokr/xit/interfaces/saeol/service/bean/AnswerBean.java +++ b/src/main/java/cokr/xit/interfaces/saeol/service/bean/AnswerBean.java @@ -44,8 +44,9 @@ public class AnswerBean extends SaeolBean { resp.setState_dtl(saeolMapper.flatDatetime(resp.getState_dtl())); if (create) saeolMapper.insertSOINN00050(msg); - else - saeolMapper.updateSOINN00050(resp); + else { + saeolMapper.updateSOINN00050(msg); + } return resp; } } \ No newline at end of file diff --git a/src/main/java/cokr/xit/interfaces/saeol/service/bean/EPeople.java b/src/main/java/cokr/xit/interfaces/saeol/service/bean/EPeople.java index 2445b07..f8ce993 100644 --- a/src/main/java/cokr/xit/interfaces/saeol/service/bean/EPeople.java +++ b/src/main/java/cokr/xit/interfaces/saeol/service/bean/EPeople.java @@ -156,7 +156,12 @@ public class EPeople extends AbstractComponent { String filename = fileInfo.getName(); if (!filename.toLowerCase().endsWith(".png")) return null; - filename = filename.replace(".png", ".jpg").replace(".PNG", ".jpg"); + String dirPath = "temp"; + File dir = new File(dirPath); + if (!dir.exists()) + dir.mkdirs(); + + filename = dirPath + "/" + filename.replace(".png", ".jpg").replace(".PNG", ".jpg"); try (InputStream input = fileInfo.getInputStream();) { BufferedImage png = ImageIO.read(input), diff --git a/src/main/java/cokr/xit/interfaces/saeol/service/bean/MinwonBean.java b/src/main/java/cokr/xit/interfaces/saeol/service/bean/MinwonBean.java index a2fb368..57ba3e0 100644 --- a/src/main/java/cokr/xit/interfaces/saeol/service/bean/MinwonBean.java +++ b/src/main/java/cokr/xit/interfaces/saeol/service/bean/MinwonBean.java @@ -8,6 +8,7 @@ import java.util.Map; import javax.annotation.Resource; +import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Component; import cokr.xit.base.file.FileInfo; @@ -16,11 +17,16 @@ import cokr.xit.interfaces.saeol.SOHNN00004; import cokr.xit.interfaces.saeol.SOHNN00011; @Component("minwonBean") +@Scope("prototype") public class MinwonBean extends SaeolBean { private EPeople epeople = new EPeople(); @Resource(name = "fileBean") private FileBean fileBean; + public MinwonBean() { + log().debug("MinwonBean created"); + } + public Map getMinwons(String deptCode, String startDate, String endDate) { log().debug("Getting minwons: '{}', {} ~ {}", deptCode, startDate, endDate); SOHNN00004.Req00004 req00004 = new SOHNN00004.Req00004(); @@ -35,12 +41,39 @@ public class MinwonBean extends SaeolBean { result.put("success", true); result.put("minwonsReceived", resp00004.getResult().size()); + resp00004.getResult().stream() + .map(item -> { + 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 sohnn00011; + }) + .forEach(sohnn00011 -> { + List files = sohnn00011.getFileInfos(); + if (Configuration.logToDatabase()) + fileBean.create(files); + else + epeople.write(files); + + sohnn00011.getConverted().forEach(File::delete); + }); +/* + .forEach(sohnn00011 -> { + List 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; } @@ -96,13 +129,42 @@ public class MinwonBean extends SaeolBean { .setInfoType(SOHNN00011.INF_TYPE) .setInfoKey(result.infoKey()); - create(relation, phoneNo, resp.getFileinfo_m()); - create(relation, phoneNo, resp.getFileinfo_p()); + 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; } + private void create(SOHNN00011 msg, FileInfo.Relation relation, String phoneNo, List fileItems) { + ArrayList converted = new ArrayList<>(); + + List 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(); + + msg.addFileInfos(files); + msg.addConverted(converted); + } + private void create(FileInfo.Relation relation, String phoneNo, List fileItems) { ArrayList converted = new ArrayList<>(); diff --git a/src/main/java/cokr/xit/interfaces/saeol/service/bean/SaeolServiceBean.java b/src/main/java/cokr/xit/interfaces/saeol/service/bean/SaeolServiceBean.java index 37a1c80..43724c0 100644 --- a/src/main/java/cokr/xit/interfaces/saeol/service/bean/SaeolServiceBean.java +++ b/src/main/java/cokr/xit/interfaces/saeol/service/bean/SaeolServiceBean.java @@ -4,6 +4,7 @@ import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; import javax.annotation.Resource; @@ -21,17 +22,17 @@ public class SaeolServiceBean extends ScheduledServiceBean implements SaeolServi private AnswerBean answerBean; @Override - public Map getMinwons(String deptCode, String fromDate, String toDate) { + public Map searchMinwons(String deptCode, String fromDate, String toDate) { return minwonBean.getMinwons(deptCode, toDate, toDate); } private static final DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("yyyyMMdd"); @Override - public void getMinwons() { + public void searchMinwons() { LocalDateTime now = LocalDateTime.now(); String - fromDate = now.minusDays(Configuration.minwonDates()).format(dateFormat), + fromDate = now.minusDays(Math.max(0, Configuration.minwonDates() - 1)).format(dateFormat), toDate = now.format(dateFormat); execute( @@ -66,12 +67,17 @@ public class SaeolServiceBean extends ScheduledServiceBean implements SaeolServi } @Override - public void registerAnswers() { - execute( + public Map registerAnswers() { + return execute( answerBean, () -> { - log().debug("Registering answers..."); - answerBean.getAnwsers().forEach(answerBean::register); + log().debug("Registering answers..."); + return answerBean.getAnwsers().stream() + .map(msg -> answerBean.register(msg)) + .collect(Collectors.toMap( + resp -> resp.getCnsl_qna_no(), + resp -> "0".equals(resp.getState_code()) ? "success" : "fail" + )); } ); } diff --git a/src/main/java/cokr/xit/interfaces/saeol/service/bean/XmlSupport.java b/src/main/java/cokr/xit/interfaces/saeol/service/bean/XmlSupport.java index fdb28ef..2ee9ce7 100644 --- a/src/main/java/cokr/xit/interfaces/saeol/service/bean/XmlSupport.java +++ b/src/main/java/cokr/xit/interfaces/saeol/service/bean/XmlSupport.java @@ -6,6 +6,7 @@ import com.fasterxml.jackson.dataformat.xml.ser.ToXmlGenerator; import cokr.xit.foundation.AbstractComponent; import cokr.xit.foundation.data.XML; import cokr.xit.interfaces.gpki.GPKI; +import cokr.xit.interfaces.saeol.SOINN00050; import cokr.xit.interfaces.saeol.SaeolMessage; public class XmlSupport extends AbstractComponent { @@ -25,6 +26,7 @@ public class XmlSupport extends AbstractComponent { private XML xml = new XML().configure(mapper -> { mapper.configure(ToXmlGenerator.Feature.WRITE_XML_DECLARATION, false); mapper.configure(ToXmlGenerator.Feature.WRITE_XML_1_1, false); + mapper.configure(ToXmlGenerator.Feature.WRITE_NULLS_AS_XSI_NIL, false); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); }); @@ -88,7 +90,7 @@ public class XmlSupport extends AbstractComponent { .replace("<" + className + ">", "") .replace("", "") .trim(); - return "" + messageBody + ""; + return request instanceof SOINN00050.Req00050 ? "
0
" + messageBody + "
" : "" + messageBody + ""; } public void parse(SaeolMessage msg, String resp) { diff --git a/src/main/java/cokr/xit/interfaces/saeol/web/SaeolController.java b/src/main/java/cokr/xit/interfaces/saeol/web/SaeolController.java index 0f19eb8..57ee59c 100644 --- a/src/main/java/cokr/xit/interfaces/saeol/web/SaeolController.java +++ b/src/main/java/cokr/xit/interfaces/saeol/web/SaeolController.java @@ -26,7 +26,7 @@ public class SaeolController extends AbstractController { @PostMapping("/minwons") @Operation(summary = "민원 목록/상세 조회", tags = "민원 목록/상세") public Map getMinwons(@RequestParam(required = false) String deptCode, String fromDate, String toDate) { - return saeolService.getMinwons(deptCode, fromDate, toDate); + return saeolService.searchMinwons(deptCode, fromDate, toDate); } @PostMapping("/sohnn00004/update") @@ -53,4 +53,10 @@ public class SaeolController extends AbstractController { req.setHeader(null); return saeolService.register(req); } + + @PostMapping("/soinn00050/registerAll") + @Operation(summary = "답변등록/추가답변 일괄전송", tags = "SOINN00050") + public Map registerAll() { + return saeolService.registerAnswers(); + } } \ No newline at end of file diff --git a/src/main/resources/sql/mapper/saeol/saeol-mapper.xml b/src/main/resources/sql/mapper/saeol/saeol-mapper.xml index 01a7012..7b1eaa4 100644 --- a/src/main/resources/sql/mapper/saeol/saeol-mapper.xml +++ b/src/main/resources/sql/mapper/saeol/saeol-mapper.xml @@ -360,10 +360,11 @@ INSERT INTO TB_SOINN00050 ( /* 답변등록 결과 업데이트(saeolMapper.updateSOINN00050) */ UPDATE TB_SOINN00050 - SET STATE_CODE = #{state_code} - , STATE_MSG = #{state_msg} - , STATE_DTL = #{state_dtl} - WHERE CNSL_QNA_NO = #{cnsl_qna_no} - AND MSG_KEY = #{msg_key} + SET MSG_KEY = #{response.msg_key} + , STATE_CODE = #{response.state_code} + , STATE_MSG = #{response.state_msg} + , STATE_DTL = #{response.state_dtl} + WHERE CNSL_QNA_NO = #{response.cnsl_qna_no} + AND MSG_ID = #{msgId} \ No newline at end of file diff --git a/src/test/java/cokr/xit/interfaces/saeol/SaeolMessageTest.java b/src/test/java/cokr/xit/interfaces/saeol/SaeolMessageTest.java index 5ab848d..32b7aff 100644 --- a/src/test/java/cokr/xit/interfaces/saeol/SaeolMessageTest.java +++ b/src/test/java/cokr/xit/interfaces/saeol/SaeolMessageTest.java @@ -147,7 +147,7 @@ public class SaeolMessageTest extends TestSupport { } @Test - void downloader() { + void download() { EPeople epeople = new EPeople(); String head = "http://www.epeople.go.kr/FileDownload.do?file=/attach19/nep/eai/"; List files = List.of( @@ -162,6 +162,12 @@ public class SaeolMessageTest extends TestSupport { epeople.write(files); } + @Test + void download2() { +// EPeople2 epeople = new EPeople2(); +// epeople.download(null, null); + } + private void write(FileInfo fileInfo) { if (fileInfo == null) return;