From c72a00d22c4ddc7da87a1fb647f7d71349ea1ee2 Mon Sep 17 00:00:00 2001 From: ibaesuyeon Date: Fri, 8 Dec 2023 14:50:19 +0900 Subject: [PATCH 1/4] =?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 From 705f61d7bed3a257c84e1164c6a0851049fd716d Mon Sep 17 00:00:00 2001 From: Hyeok_Choi Date: Fri, 8 Dec 2023 15:39:38 +0900 Subject: [PATCH 2/4] =?UTF-8?q?chore:=20=ED=99=98=EA=B2=BD=EB=B3=80?= =?UTF-8?q?=EC=88=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/test_cd.yml | 10 ++++++++++ src/main/resources/application-local.yml | 6 ------ src/main/resources/application.yml | 8 +++++++- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/.github/workflows/test_cd.yml b/.github/workflows/test_cd.yml index be40f99..0dbc28d 100644 --- a/.github/workflows/test_cd.yml +++ b/.github/workflows/test_cd.yml @@ -7,6 +7,7 @@ on: env: IMAGE_NAME: insurance_system + MAIN_YML_PATH: ./src/main/resources/application.yml TEST_YML_PATH: ./src/main/resources/application-test.yml jobs: @@ -18,6 +19,15 @@ jobs: - name: Checkout repository uses: actions/checkout@v3 + - name: application.yml setting + uses: microsoft/variable-substitution@v1 + with: + files: ${{ env.MAIN_YML_PATH }} + env: + coolsms.api.key: ${{ secrets.COOLSMS_API_KEY }} + coolsms.api.secret: ${{ secrets.COOLSMS_API_SECRET }} + coolsms.api.from-number: ${{ secrets.COOLSMS_API_FROM_NUMBER }} + - name: application-test.yml setting uses: microsoft/variable-substitution@v1 with: diff --git a/src/main/resources/application-local.yml b/src/main/resources/application-local.yml index de6fa8c..871b1f6 100644 --- a/src/main/resources/application-local.yml +++ b/src/main/resources/application-local.yml @@ -16,9 +16,3 @@ decorator: datasource: p6spy: enable-logging: true - -coolsms: - api: - key: ${APIKEY} - secret: ${APISECRET} - from-number: ${FROMNUMBER} \ No newline at end of file diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 3dd396a..cab4a6e 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -13,4 +13,10 @@ spring: physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl springdoc: - show-login-endpoint: true \ No newline at end of file + show-login-endpoint: true + +coolsms: + api: + key: ${COOLSMS_API_KEY} + secret: ${COOLSMS_API_SECRET} + from-number: ${COOLSMS_API_FROM_NUMBER} \ No newline at end of file From 44b1c1b0fd7041ca15f04ff308c1ba2d2b4f00c1 Mon Sep 17 00:00:00 2001 From: Hyeok_Choi Date: Fri, 8 Dec 2023 15:39:55 +0900 Subject: [PATCH 3/4] =?UTF-8?q?refactor:=20=ED=99=98=EA=B2=BD=EB=B3=80?= =?UTF-8?q?=EC=88=98=20=EC=A3=BC=EC=9E=85=20=EB=B0=A9=EB=B2=95=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/service/MessageService.java | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/main/java/aplus/insurancesystem/common/service/MessageService.java b/src/main/java/aplus/insurancesystem/common/service/MessageService.java index 2f59d63..d37a951 100644 --- a/src/main/java/aplus/insurancesystem/common/service/MessageService.java +++ b/src/main/java/aplus/insurancesystem/common/service/MessageService.java @@ -1,27 +1,28 @@ package aplus.insurancesystem.common.service; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + 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; +@Service +@Transactional(readOnly = true) 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 final DefaultMessageService messageService; + private String fromNumber; - public MessageService(DefaultMessageService messageService) { + public MessageService(@Value("${coolsms.api.key}") String apiKey, + @Value("${coolsms.api.secret}") String apiSecretKey, + @Value("${coolsms.api.from-number}") String fromNumber) { this.messageService = NurigoApp.INSTANCE.initialize(apiKey, apiSecretKey, "https://api.coolsms.co.kr"); + this.fromNumber = fromNumber; } public SingleMessageSentResponse sendOne(String to, Esms esms) { From 6d769ad169a5b5d9d69b46eb60c44fb24d273561 Mon Sep 17 00:00:00 2001 From: Hyeok_Choi Date: Fri, 8 Dec 2023 20:58:30 +0900 Subject: [PATCH 4/4] =?UTF-8?q?chore:=20prod=20cd=20=EA=B5=AC=EC=B6=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/prod_cd.yaml | 70 +++++++++++++++++++++++++ Dockerfile_prod | 22 ++++++++ src/main/resources/application-prod.yml | 12 +++++ 3 files changed, 104 insertions(+) create mode 100644 .github/workflows/prod_cd.yaml create mode 100644 Dockerfile_prod diff --git a/.github/workflows/prod_cd.yaml b/.github/workflows/prod_cd.yaml new file mode 100644 index 0000000..02a5807 --- /dev/null +++ b/.github/workflows/prod_cd.yaml @@ -0,0 +1,70 @@ +name: main branch cd + +on: + push: + branches: + - "main" + +env: + MAIN_YML_PATH: ./src/main/resources/application.yml + PROD_YML_PATH: ./src/main/resources/application-prod.yml + +jobs: + build-and-push-image: + runs-on: ubuntu-latest + permissions: + contents: read + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: application.yml setting + uses: microsoft/variable-substitution@v1 + with: + files: ${{ env.MAIN_YML_PATH }} + env: + coolsms.api.key: ${{ secrets.COOLSMS_API_KEY }} + coolsms.api.secret: ${{ secrets.COOLSMS_API_SECRET }} + coolsms.api.from-number: ${{ secrets.COOLSMS_API_FROM_NUMBER }} + + - name: application-prod.yml setting + uses: microsoft/variable-substitution@v1 + with: + files: ${{ env.PROD_YML_PATH }} + env: + spring.datasource.url: ${{ secrets.RDS_URL }} + spring.datasource.username: ${{ secrets.PROD_DB_USERNAME }} + spring.datasource.password: ${{ secrets.PROD_DB_PASSWORD }} + + - name: Cache Gradle packages + uses: actions/cache@v1 + with: + path: ~/.gradle/caches + key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }} + restore-keys: ${{ runner.os }}-gradle + + - name: Grant execute permission for gradlew + run: chmod +x gradlew + + - name: Clean and Build with Gradle + run: ./gradlew clean build -x test + + - name: Docker build & push + run: | + docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} + docker build -t ${{ secrets.DOCKER_USERNAME }}/insurance_system_prod . + docker push ${{ secrets.DOCKER_USERNAME }}/insurance_system_prod + + - name: Deploy EC2 + uses: appleboy/ssh-action@master + with: + host: ${{ secrets.EC2_HOST_IP }} + username: ubuntu + key: ${{ secrets.EC2_KEY }} + port: 22 + script: | + docker stop insurance_system_prod + docker rm insurance_system_prod + docker rmi choihyeok/insurance_system_prod + docker pull choihyeok/insurance_system_prod + docker run -d -p 80:8080 --name insurance_system_prod choihyeok/insurance_system_prod \ No newline at end of file diff --git a/Dockerfile_prod b/Dockerfile_prod new file mode 100644 index 0000000..002450a --- /dev/null +++ b/Dockerfile_prod @@ -0,0 +1,22 @@ +# 테스트 서버 빌드 스크립트 +# jar 파일 빌드 +FROM eclipse-temurin:17 as builder + +COPY gradlew . +COPY gradle gradle +COPY build.gradle . +COPY settings.gradle . +COPY src src +RUN chmod +x ./gradlew +RUN ./gradlew bootjar + +# jar 실행 +FROM eclipse-temurin:17-jre as runtime + +COPY --from=builder build/libs/*.jar app.jar + +ENV PROFILE prod + +EXPOSE 8080 + +ENTRYPOINT ["java", "-Dspring.profiles.active=${PROFILE}", "-jar", "/app.jar"] \ No newline at end of file diff --git a/src/main/resources/application-prod.yml b/src/main/resources/application-prod.yml index e69de29..6d2f1a2 100644 --- a/src/main/resources/application-prod.yml +++ b/src/main/resources/application-prod.yml @@ -0,0 +1,12 @@ +spring: + datasource: + driver-class-name: com.mysql.cj.jdbc.Driver + url: + username: + password: + + jpa: + database-platform: org.hibernate.dialect.MySQL5InnoDBDialect + open-in-view: false + hibernate: + ddl-auto: validate \ No newline at end of file