답변등록 수정

master
mjkhan21 2 weeks ago
parent 29234a4f3d
commit 93ea2ffdf9

@ -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<FileInfo> fileInfos;
private ArrayList<File> converted;
public List<FileInfo> getFileInfos() {
return ifEmpty(fileInfos, Collections::emptyList);
}
public void addFileInfos(List<FileInfo> fileInfos) {
if (this.fileInfos == null)
this.fileInfos = new ArrayList<>();
this.fileInfos.addAll(fileInfos);
}
public List<File> getConverted() {
return ifEmpty(converted, Collections::emptyList);
}
public void addConverted(List<File> converted) {
if (this.converted == null)
this.converted = new ArrayList<>();
this.converted.addAll(converted);
}
@Override
protected Req00011 newRequest() {

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

@ -6,9 +6,9 @@ import java.util.Map;
import cokr.xit.interfaces.saeol.SOINN00050;
public interface SaeolService {
Map<String, Object> getMinwons(String deptCode, String fromDate, String toDate);
Map<String, Object> 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<String, Object> registerAnswers();
}

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

@ -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),

@ -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<String, Object> 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<FileInfo> files = sohnn00011.getFileInfos();
if (Configuration.logToDatabase())
fileBean.create(files);
else
epeople.write(files);
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;
}
@ -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<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();
msg.addFileInfos(files);
msg.addConverted(converted);
}
private void create(FileInfo.Relation relation, String phoneNo, List<SOHNN00011.FileItem> fileItems) {
ArrayList<File> converted = new ArrayList<>();

@ -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<String, Object> getMinwons(String deptCode, String fromDate, String toDate) {
public Map<String, Object> 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<String, Object> registerAnswers() {
return execute(
answerBean,
() -> {
log().debug("Registering answers...");
answerBean.getAnwsers().forEach(answerBean::register);
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"
));
}
);
}

@ -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("</" + className + ">", "")
.trim();
return "<message><body>" + messageBody + "</body></message>";
return request instanceof SOINN00050.Req00050 ? "<message><header><res_cnt>0</res_cnt></header><body>" + messageBody + "</body></message>" : "<message><body>" + messageBody + "</body></message>";
}
public void parse(SaeolMessage msg, String resp) {

@ -26,7 +26,7 @@ public class SaeolController extends AbstractController {
@PostMapping("/minwons")
@Operation(summary = "민원 목록/상세 조회", tags = "민원 목록/상세")
public Map<String, Object> 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<String, Object> registerAll() {
return saeolService.registerAnswers();
}
}

@ -360,10 +360,11 @@ INSERT INTO TB_SOINN00050 (
<update id="updateSOINN00050" parameterType="map">/* 답변등록 결과 업데이트(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}</update>
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}</update>
</mapper>

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

Loading…
Cancel
Save