parent
09d7a77060
commit
1b291ba337
@ -0,0 +1,38 @@
|
||||
package com.worker.framework.WebClient;
|
||||
|
||||
import io.netty.channel.ChannelOption;
|
||||
import io.netty.handler.timeout.ReadTimeoutHandler;
|
||||
import io.netty.handler.timeout.WriteTimeoutHandler;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.http.client.reactive.ReactorClientHttpConnector;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.reactive.function.client.ExchangeStrategies;
|
||||
import org.springframework.web.reactive.function.client.WebClient;
|
||||
import reactor.netty.http.client.HttpClient;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Component
|
||||
public class WebClientConf {
|
||||
|
||||
@Bean
|
||||
public WebClient webClient() {
|
||||
HttpClient httpClient = HttpClient.create()
|
||||
.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 5000)
|
||||
.responseTimeout(Duration.ofSeconds(10))
|
||||
.doOnConnected(conn -> conn
|
||||
.addHandlerLast(new ReadTimeoutHandler(10, TimeUnit.SECONDS))
|
||||
.addHandlerLast(new WriteTimeoutHandler(10, TimeUnit.SECONDS)));
|
||||
|
||||
return WebClient.builder()
|
||||
.clientConnector(new ReactorClientHttpConnector(httpClient))
|
||||
.exchangeStrategies(
|
||||
ExchangeStrategies.builder()
|
||||
.codecs(c -> c.defaultCodecs().maxInMemorySize(4 * 1024 * 1024))
|
||||
.build()
|
||||
)
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
package com.worker.dto;
|
||||
package com.worker.scheduler.smg.dto;
|
||||
|
||||
import com.worker.domain.entity.*;
|
||||
import jakarta.persistence.Lob;
|
||||
@ -0,0 +1,82 @@
|
||||
package com.worker.scheduler.tax.dto;
|
||||
|
||||
import com.worker.domain.entity.CpSetinfo;
|
||||
import lombok.*;
|
||||
|
||||
public class TaxSunapDto {
|
||||
|
||||
|
||||
public static class Request {
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public static class SetInfo {
|
||||
private CpSetinfo cpSetinfo;
|
||||
private CpSetinfo epSetinfo;
|
||||
}
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public static class SendReq {
|
||||
private Header header;
|
||||
private Body body;
|
||||
}
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public static class Header {
|
||||
private String ifDate;
|
||||
private String ifMsgKEy;
|
||||
private String ifId;
|
||||
private String source;
|
||||
private String target;
|
||||
private String ifType;
|
||||
private String ifFormat;
|
||||
private String retName;
|
||||
private String retCode;
|
||||
}
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public static class Body {
|
||||
private String dmndSeCd;
|
||||
private String sgbCd;
|
||||
private String pyrSeCd;
|
||||
private String pyrNo;
|
||||
private String dptCd;
|
||||
private String spacBizCd;
|
||||
private String fyr;
|
||||
private String actSeCd;
|
||||
private String rprsTxmCd;
|
||||
private String lvyNo;
|
||||
private String itmSn;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public static class Response {
|
||||
|
||||
private String state; // Success/Fail
|
||||
private int code; // 200/500 ...
|
||||
private String data; // 상세 메시지
|
||||
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,59 @@
|
||||
package com.worker.scheduler.tax.schedule;
|
||||
|
||||
import com.worker.domain.entity.CpSetinfo;
|
||||
import com.worker.domain.repo.cp.CpSetinfoRepository;
|
||||
import com.worker.scheduler.tax.dto.TaxSunapDto;
|
||||
import com.worker.scheduler.tax.service.TaxSunapService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.reactive.function.client.WebClient;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
public class TaxSunapScheduler {
|
||||
|
||||
|
||||
private final WebClient webClient;
|
||||
|
||||
private final TaxSunapService taxSunapService;
|
||||
|
||||
private final CpSetinfoRepository cpSetinfoRepository;
|
||||
|
||||
@Scheduled(fixedRate = 60 * 60 * 1000)
|
||||
public void TaxSunapScheduler() {
|
||||
|
||||
// setinfo 조회
|
||||
|
||||
|
||||
// private String PORT = "";
|
||||
// private String DIR = "/mediate/ltis";
|
||||
|
||||
|
||||
Mono<TaxSunapDto.Response> taxSunapDtoMono = webClient.post()
|
||||
.uri("")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.accept(MediaType.APPLICATION_JSON)
|
||||
.bodyValue(taxSunapService.taxSunapFindReqInfo())
|
||||
.retrieve()
|
||||
.bodyToMono(TaxSunapDto.Response.class);
|
||||
TaxSunapDto.Response res = taxSunapDtoMono.block();
|
||||
|
||||
log.info("[TAX] response: retCode={}, retName={}, retMsg={}",
|
||||
res != null ? res.getState() : null,
|
||||
res != null ? res.getCode() : null,
|
||||
res != null ? res.getData() : null);
|
||||
|
||||
taxSunapService.taxSunapUpdate(res);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,113 @@
|
||||
package com.worker.scheduler.tax.service;
|
||||
|
||||
import com.worker.domain.entity.CpSetinfo;
|
||||
import com.worker.domain.entity.CpSetinfoId;
|
||||
import com.worker.domain.repo.cp.CpSetinfoRepository;
|
||||
import com.worker.domain.repo.ep.EpSetinfoRepository;
|
||||
import com.worker.scheduler.tax.dto.TaxSunapDto;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.stereotype.Service;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.UUID;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class TaxSunapService {
|
||||
|
||||
private final Environment env;
|
||||
|
||||
private final CpSetinfoRepository cpSetinfoRepository;
|
||||
private final EpSetinfoRepository epSetinfoRepository;
|
||||
|
||||
|
||||
public TaxSunapDto.Request.SendReq taxSunapFindReqInfo() {
|
||||
|
||||
TaxSunapDto.Request.SetInfo setInfo = findSetinfo();
|
||||
|
||||
TaxSunapDto.Request.SendReq sendReq = TaxSunapDto.Request.SendReq.builder()
|
||||
.header(
|
||||
TaxSunapDto.Request.Header.builder()
|
||||
.ifDate(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss")))
|
||||
.ifMsgKEy(createIfMsgKey())
|
||||
.ifId("ERR_Z000012LGS_1741000NIS_0002")
|
||||
.source(createIfSource(setInfo)) // 시군구 코드 +
|
||||
.target("1741000NIS")
|
||||
.ifType("S")
|
||||
.ifFormat("J")
|
||||
.retName("")
|
||||
.retCode("")
|
||||
.build())
|
||||
.body(
|
||||
TaxSunapDto.Request.Body.builder()
|
||||
.dmndSeCd("2")
|
||||
.sgbCd("")
|
||||
.pyrSeCd("")
|
||||
.pyrNo("")
|
||||
.dptCd("")
|
||||
.spacBizCd("")
|
||||
.fyr("")
|
||||
.actSeCd("")
|
||||
.rprsTxmCd("")
|
||||
.lvyNo("")
|
||||
.itmSn("00")
|
||||
.build())
|
||||
.build();
|
||||
|
||||
return sendReq;
|
||||
}
|
||||
|
||||
public void taxSunapUpdate(TaxSunapDto.Response result) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
private String createIfMsgKey() {
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyMMddHHmmssSSS");
|
||||
String datePart = LocalDateTime.now().format(formatter); // 15자리
|
||||
String guidPart = UUID.randomUUID().toString().replace("-", ""); // 32자리
|
||||
|
||||
String ifMsgKey = "Z" + datePart + "-" + guidPart;
|
||||
|
||||
return ifMsgKey;
|
||||
}
|
||||
|
||||
private String createIfSource(TaxSunapDto.Request.SetInfo setInfo) {
|
||||
|
||||
if(setInfo.getCpSetinfo() != null) return setInfo.getCpSetinfo().getIntValue2().toString() + "DPV";
|
||||
else return setInfo.getEpSetinfo().getIntValue2().toString() + "ECA";
|
||||
|
||||
}
|
||||
|
||||
private TaxSunapDto.Request.SetInfo findSetinfo() {
|
||||
|
||||
String result = null;
|
||||
|
||||
CpSetinfo cpSetinfo = cpSetinfoRepository.findById(
|
||||
CpSetinfoId.builder()
|
||||
.codeName(env.getProperty("esb.info.cp.codeName"))
|
||||
.groupCode(env.getProperty("esb.info.cp.groupCode"))
|
||||
.detailCode(env.getProperty("esb.info.cp.detailCode"))
|
||||
.build()
|
||||
).orElse(null);
|
||||
|
||||
CpSetinfo epSetInfo = epSetinfoRepository.findById(
|
||||
CpSetinfoId.builder()
|
||||
.codeName(env.getProperty("esb.info.ep.codeName"))
|
||||
.groupCode(env.getProperty("esb.info.ep.groupCode"))
|
||||
.detailCode(env.getProperty("esb.info.ep.detailCode"))
|
||||
.build()
|
||||
).orElse(null);
|
||||
|
||||
return TaxSunapDto.Request.SetInfo.builder()
|
||||
.cpSetinfo(cpSetinfo)
|
||||
.epSetinfo(epSetInfo)
|
||||
.build();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue