From c72a00d22c4ddc7da87a1fb647f7d71349ea1ee2 Mon Sep 17 00:00:00 2001 From: ibaesuyeon Date: Fri, 8 Dec 2023 14:50:19 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20sms=EC=A0=84=EC=86=A1=20=EC=84=9C?= =?UTF-8?q?=EB=B9=84=EC=8A=A4=20=EA=B5=AC=ED=98=84(survey=EC=83=9D?= =?UTF-8?q?=EC=84=B1=EC=8B=9C=20=EC=A0=84=EC=86=A1)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 1 + .../insurancesystem/common/service/Esms.java | 16 ++++++++ .../common/service/MessageService.java | 38 +++++++++++++++++++ .../service/SurveyServiceImpl.java | 12 ++++++ src/main/resources/application-local.yml | 8 +++- 5 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 src/main/java/aplus/insurancesystem/common/service/Esms.java create mode 100644 src/main/java/aplus/insurancesystem/common/service/MessageService.java diff --git a/build.gradle b/build.gradle index 2656147..910fc25 100644 --- a/build.gradle +++ b/build.gradle @@ -29,6 +29,7 @@ dependencies { implementation 'org.springframework.boot:spring-boot-starter-security' implementation "com.github.gavlyukovskiy:p6spy-spring-boot-starter:1.9.0" implementation 'org.springframework.boot:spring-boot-starter-security' + implementation 'net.nurigo:sdk:4.3.0' compileOnly 'org.projectlombok:lombok' runtimeOnly 'com.mysql:mysql-connector-j' diff --git a/src/main/java/aplus/insurancesystem/common/service/Esms.java b/src/main/java/aplus/insurancesystem/common/service/Esms.java new file mode 100644 index 0000000..1c63d57 --- /dev/null +++ b/src/main/java/aplus/insurancesystem/common/service/Esms.java @@ -0,0 +1,16 @@ +package aplus.insurancesystem.common.service; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@Getter +@RequiredArgsConstructor +public enum Esms { + COMPENSATION_CLAIM_COMPLETED("보상금 청구가 완료되었습니다. 손해사정에는 수일이 걸릴 수 있습니다."), + + SURVEY_COMPLETED("손해사정이 완료되었습니다. 홈페이지에서 결과를 확인해주세요."), + + INSURANCE_APPLICATION_APPROVED("보험 가입 심사가 완료되었습니다. 홈페이지에서 결과를 확인해주세요."); + + private final String message; +} diff --git a/src/main/java/aplus/insurancesystem/common/service/MessageService.java b/src/main/java/aplus/insurancesystem/common/service/MessageService.java new file mode 100644 index 0000000..2f59d63 --- /dev/null +++ b/src/main/java/aplus/insurancesystem/common/service/MessageService.java @@ -0,0 +1,38 @@ +package aplus.insurancesystem.common.service; + +import net.nurigo.sdk.NurigoApp; +import net.nurigo.sdk.message.model.Message; +import net.nurigo.sdk.message.request.MessageListRequest; +import net.nurigo.sdk.message.request.SingleMessageSendingRequest; +import net.nurigo.sdk.message.response.MessageListResponse; +import net.nurigo.sdk.message.response.SingleMessageSentResponse; +import net.nurigo.sdk.message.service.DefaultMessageService; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.web.bind.annotation.GetMapping; + +public class MessageService { + final DefaultMessageService messageService; + + @Value("${coolsms.api.key}") + private String apiKey; + @Value("${coolsms.api.secret}") + private String apiSecretKey; + @Value("${coolsms.api.from-number}") + private String fromNumber; + + public MessageService(DefaultMessageService messageService) { + this.messageService = NurigoApp.INSTANCE.initialize(apiKey, apiSecretKey, "https://api.coolsms.co.kr"); + } + + public SingleMessageSentResponse sendOne(String to, Esms esms) { + Message message = new Message(); + // 발신번호(fromNumber) 및 수신번호(to)는 반드시 01012345678 형태로 입력되어야 함 + message.setFrom(fromNumber); + message.setTo(to); + message.setText("[A+보험사] " + esms.getMessage()); + + SingleMessageSentResponse response = this.messageService.sendOne(new SingleMessageSendingRequest(message)); + return response; + } + +} diff --git a/src/main/java/aplus/insurancesystem/domain/compensationClaim/service/SurveyServiceImpl.java b/src/main/java/aplus/insurancesystem/domain/compensationClaim/service/SurveyServiceImpl.java index 47ac1c4..7f26bd9 100644 --- a/src/main/java/aplus/insurancesystem/domain/compensationClaim/service/SurveyServiceImpl.java +++ b/src/main/java/aplus/insurancesystem/domain/compensationClaim/service/SurveyServiceImpl.java @@ -1,7 +1,9 @@ package aplus.insurancesystem.domain.compensationClaim.service; +import aplus.insurancesystem.common.service.Esms; import aplus.insurancesystem.common.service.FileService; +import aplus.insurancesystem.common.service.MessageService; import aplus.insurancesystem.domain.compensationClaim.dto.request.CreateCarAccidentRequest; import aplus.insurancesystem.domain.compensationClaim.dto.request.CreateCompensationClaimRequest; import aplus.insurancesystem.domain.compensationClaim.dto.request.CreateSurveyRequest; @@ -21,6 +23,9 @@ import aplus.insurancesystem.domain.contract.entity.Contract; import aplus.insurancesystem.domain.contract.exception.ContractNotFoundException; import aplus.insurancesystem.domain.contract.repository.ContractRepository; +import aplus.insurancesystem.domain.contract.service.ContractService; +import aplus.insurancesystem.domain.customer.entity.customer.Customer; +import aplus.insurancesystem.domain.customer.service.CustomerQueryService; import lombok.RequiredArgsConstructor; import org.springframework.core.io.InputStreamResource; import org.springframework.stereotype.Service; @@ -38,7 +43,11 @@ public class SurveyServiceImpl implements SurveyService { private final CompensationClaimRepository compensationClaimRepository; private final SurveyRepository surveyRepository; + private final ContractRepository contractRepository; + private final ContractService contractService; private final FileService fileService; + private final MessageService messageService; + private final CustomerQueryService customerQueryService; @Override @@ -70,6 +79,9 @@ public void createSurvey(Long ccid, CreateSurveyRequest request) { compensationClaim.setSurveyed(true); compensationClaimRepository.save(compensationClaim); surveyRepository.save(survey); + + String phoneNumber = compensationClaim.getReceptionistPNumber().replaceAll("-", ""); + messageService.sendOne(phoneNumber, Esms.SURVEY_COMPLETED); } @Override diff --git a/src/main/resources/application-local.yml b/src/main/resources/application-local.yml index f50ee03..de6fa8c 100644 --- a/src/main/resources/application-local.yml +++ b/src/main/resources/application-local.yml @@ -15,4 +15,10 @@ spring: decorator: datasource: p6spy: - enable-logging: true \ No newline at end of file + enable-logging: true + +coolsms: + api: + key: ${APIKEY} + secret: ${APISECRET} + from-number: ${FROMNUMBER} \ No newline at end of file