-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from Billing-Wise/dev
[release] 배포
- Loading branch information
Showing
63 changed files
with
4,299 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
## 관련 이슈 | ||
|
||
- [지라 이슈 코드를 적어주세요.] | ||
|
||
## 구현 기능 | ||
|
||
- 구현 기능을 적어주세요. | ||
|
||
## 참고 사항 | ||
|
||
- 참고 사항을 적어주세요. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
name: CD | ||
on: | ||
push: | ||
branches: | ||
- prod | ||
jobs: | ||
deploy: | ||
name: Deploy to AWS | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: create secure file | ||
run: | | ||
cd src/main/resources | ||
touch secure.properties | ||
echo "${{ secrets.SECURE }}" >> secure.properties | ||
- name: Configure AWS credentials | ||
uses: aws-actions/configure-aws-credentials@v1 | ||
with: | ||
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | ||
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | ||
aws-region: ap-northeast-2 | ||
|
||
- name: Login to Amazon ECR | ||
uses: aws-actions/amazon-ecr-login@v1 | ||
|
||
- name: Set up JDK 17 | ||
uses: actions/setup-java@v3 | ||
with: | ||
java-version: 17 | ||
distribution: 'temurin' | ||
cache: gradle | ||
|
||
- name: Grant execute permission to Gradle Wrapper | ||
run: chmod +x ./gradlew | ||
|
||
- name: Build and push image to Amazon ECR | ||
run: ./gradlew clean jib -x test | ||
|
||
- name: Deploy to AWS ECS | ||
uses: aws-actions/amazon-ecs-deploy-task-definition@v1 | ||
with: | ||
task-definition: task-definition.json | ||
cluster: t5-ecs-fargate-cluster | ||
service: t5-batch-service | ||
wait-for-service-stability: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
name: CI | ||
on: | ||
push: | ||
branches: | ||
- prod | ||
- dev | ||
pull_request: | ||
|
||
jobs: | ||
sonarcloud: | ||
name: SonarCloud | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: create secure file | ||
run: | | ||
cd src/main/resources | ||
touch secure.properties | ||
echo "${{ secrets.SECURE }}" >> secure.properties | ||
- name: Set up JDK 17 | ||
uses: actions/setup-java@v3 | ||
with: | ||
java-version: 17 | ||
distribution: 'temurin' | ||
cache: 'gradle' | ||
|
||
- name: Cache SonarCloud packages | ||
uses: actions/cache@v3 | ||
with: | ||
path: ~/.sonar/cache | ||
key: ${{ runner.os }}-sonar | ||
restore-keys: ${{ runner.os }}-sonar | ||
|
||
- name: Grant execute permission to Gradle Wrapper | ||
run: chmod +x ./gradlew | ||
|
||
- name: Build and analyze | ||
run: ./gradlew build jacocoTestReport sonar --info | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,3 +35,5 @@ out/ | |
|
||
### VS Code ### | ||
.vscode/ | ||
|
||
secure.properties |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
...a/site/billingwise/batch/server_batch/batch/generateinvoice/GenerateInvoiceJobConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package site.billingwise.batch.server_batch.batch.generateinvoice; | ||
|
||
|
||
import jakarta.persistence.EntityManagerFactory; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.batch.core.Job; | ||
import org.springframework.batch.core.Step; | ||
import org.springframework.batch.core.job.builder.JobBuilder; | ||
import org.springframework.batch.core.repository.JobRepository; | ||
import org.springframework.batch.core.step.builder.StepBuilder; | ||
import org.springframework.batch.item.ItemWriter; | ||
import org.springframework.batch.item.database.JpaPagingItemReader; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.transaction.PlatformTransactionManager; | ||
import site.billingwise.batch.server_batch.batch.listner.JobCompletionCheckListener; | ||
import site.billingwise.batch.server_batch.domain.contract.Contract; | ||
import site.billingwise.batch.server_batch.domain.invoice.repository.InvoiceRepository; | ||
import site.billingwise.batch.server_batch.domain.invoice.repository.PaymentStatusRepository; | ||
|
||
@Configuration | ||
@RequiredArgsConstructor | ||
public class GenerateInvoiceJobConfig { | ||
|
||
private final int CHUNK_SIZE = 100; | ||
private final EntityManagerFactory entityManagerFactory; | ||
private final JobCompletionCheckListener jobCompletionCheckListener; | ||
|
||
@Bean | ||
public Job generateInvoiceJob(JobRepository jobRepository, Step generateInvoiceStep) { | ||
return new JobBuilder("generateInvoiceJob", jobRepository) | ||
.listener(jobCompletionCheckListener) | ||
.start(generateInvoiceStep) | ||
.build(); | ||
} | ||
|
||
@Bean | ||
public Step generateInvoiceStep(JobRepository jobRepository, PlatformTransactionManager transactionManager, | ||
JpaPagingItemReader<Contract> contractItemReader, ItemWriter<Contract> contractItemWriter) { | ||
return new StepBuilder("generateInvoiceStep", jobRepository) | ||
.<Contract, Contract>chunk(CHUNK_SIZE, transactionManager) | ||
.reader(contractItemReader) | ||
.writer(contractItemWriter) | ||
.build(); | ||
} | ||
|
||
@Bean | ||
public JpaPagingItemReader<Contract> contractItemReader() { | ||
JpaPagingItemReader<Contract> reader = new JpaPagingItemReader<>(); | ||
reader.setEntityManagerFactory(entityManagerFactory); | ||
reader.setQueryString("SELECT c FROM Contract c WHERE c.contractStatus.name = '진행' ORDER BY c.id ASC"); | ||
reader.setPageSize(CHUNK_SIZE); | ||
return reader; | ||
} | ||
|
||
@Bean | ||
public ItemWriter<Contract> contractItemWriter(PaymentStatusRepository paymentStatusRepository, InvoiceRepository invoiceRepository) { | ||
return new GenerateInvoiceWriter(paymentStatusRepository, invoiceRepository); | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
...java/site/billingwise/batch/server_batch/batch/generateinvoice/GenerateInvoiceWriter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package site.billingwise.batch.server_batch.batch.generateinvoice; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.batch.item.Chunk; | ||
import org.springframework.batch.item.ItemWriter; | ||
import org.springframework.stereotype.Component; | ||
import site.billingwise.batch.server_batch.domain.contract.Contract; | ||
import site.billingwise.batch.server_batch.domain.invoice.Invoice; | ||
import site.billingwise.batch.server_batch.domain.invoice.PaymentStatus; | ||
import site.billingwise.batch.server_batch.domain.invoice.repository.InvoiceRepository; | ||
import site.billingwise.batch.server_batch.domain.invoice.repository.PaymentStatusRepository; | ||
|
||
import java.time.LocalDate; | ||
import java.time.LocalDateTime; | ||
|
||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class GenerateInvoiceWriter implements ItemWriter<Contract> { | ||
|
||
private final PaymentStatusRepository paymentStatusRepository; | ||
private final InvoiceRepository invoiceRepository; | ||
|
||
@Override | ||
public void write(Chunk<? extends Contract> chunk) throws Exception { | ||
LocalDate now = LocalDate.now(); | ||
LocalDate nextMonth = now.plusMonths(1); | ||
int nextMonthValue = nextMonth.getMonthValue(); | ||
int yearValue = nextMonth.getYear(); | ||
|
||
PaymentStatus paymentStatusUnpaid = paymentStatusRepository.findByName("미납") | ||
.orElseThrow(() -> new IllegalArgumentException("결제 미납 상태가 존재하지 않습니다.")); | ||
|
||
for (Contract contract : chunk) { | ||
boolean exists = invoiceRepository.existsByContractAndMonthAndYear(contract, nextMonthValue, yearValue); | ||
|
||
if (!exists) { | ||
LocalDate setContractDate = LocalDate.of(yearValue, nextMonthValue, contract.getContractCycle()); | ||
LocalDateTime dueDate = calculateDueDate(contract, setContractDate); | ||
|
||
Invoice invoice = Invoice.builder() | ||
.contract(contract) | ||
.invoiceType(contract.getInvoiceType()) | ||
.paymentType(contract.getPaymentType()) | ||
.paymentStatus(paymentStatusUnpaid) | ||
.chargeAmount(contract.getItemPrice() * contract.getItemAmount()) | ||
.contractDate(setContractDate.atStartOfDay()) | ||
.dueDate(dueDate) | ||
.build(); | ||
invoiceRepository.save(invoice); | ||
} | ||
} | ||
} | ||
|
||
private LocalDateTime calculateDueDate(Contract contract, LocalDate setContractDate) { | ||
if (contract.getPaymentType().getName().equals("납부자 결제")) { | ||
return setContractDate.plusDays(contract.getPaymentDueCycle()).atStartOfDay(); | ||
} | ||
return setContractDate.atStartOfDay(); | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
...llingwise/batch/server_batch/batch/generateinvoice/jdbc/JdbcGenerateInvoiceJobConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package site.billingwise.batch.server_batch.batch.generateinvoice.jdbc; | ||
|
||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.batch.core.Job; | ||
import org.springframework.batch.core.Step; | ||
import org.springframework.batch.core.job.builder.JobBuilder; | ||
import org.springframework.batch.core.repository.JobRepository; | ||
import org.springframework.batch.core.step.builder.StepBuilder; | ||
import org.springframework.batch.item.ItemReader; | ||
import org.springframework.batch.item.ItemWriter; | ||
import org.springframework.batch.item.database.builder.JdbcCursorItemReaderBuilder; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.jdbc.core.JdbcTemplate; | ||
import org.springframework.transaction.PlatformTransactionManager; | ||
import site.billingwise.batch.server_batch.batch.listner.JobCompletionCheckListener; | ||
import site.billingwise.batch.server_batch.batch.generateinvoice.rowmapper.JdbcContractRowMapper; | ||
import site.billingwise.batch.server_batch.domain.contract.Contract; | ||
|
||
import javax.sql.DataSource; | ||
|
||
@Configuration | ||
@RequiredArgsConstructor | ||
public class JdbcGenerateInvoiceJobConfig { | ||
|
||
private final int CHUNK_SIZE = 100; | ||
private final DataSource dataSource; | ||
private final JdbcTemplate jdbcTemplate; | ||
private final JobCompletionCheckListener jobCompletionCheckListener; | ||
|
||
@Bean | ||
public Job jdbcGenerateInvoiceJob(JobRepository jobRepository, Step jdbcGenerateInvoiceStep) { | ||
return new JobBuilder("jdbcGenerateInvoiceJob", jobRepository) | ||
.listener(jobCompletionCheckListener) | ||
.start(jdbcGenerateInvoiceStep) | ||
.build(); | ||
} | ||
|
||
|
||
@Bean | ||
public Step jdbcGenerateInvoiceStep(JobRepository jobRepository, PlatformTransactionManager transactionManager) { | ||
return new StepBuilder("jdbcGenerateInvoiceStep", jobRepository) | ||
.<Contract, Contract>chunk(CHUNK_SIZE, transactionManager) | ||
.reader(jdbcContractItemReader()) | ||
.writer(jdbcContractItemWriter()) | ||
.build(); | ||
} | ||
|
||
@Bean | ||
public ItemReader<Contract> jdbcContractItemReader() { | ||
return new JdbcCursorItemReaderBuilder<Contract>() | ||
.name("jdbcContractItemReader") | ||
.fetchSize(CHUNK_SIZE) | ||
.sql("select c.*, c.is_deleted " + | ||
"from contract c " + | ||
"where c.contract_status_id = 2") | ||
.rowMapper(new JdbcContractRowMapper()) | ||
.dataSource(dataSource) | ||
.build(); | ||
} | ||
|
||
|
||
|
||
|
||
@Bean | ||
public ItemWriter<Contract> jdbcContractItemWriter() { | ||
return new JdbcGenerateInvoiceWriter(jdbcTemplate); | ||
} | ||
} |
Oops, something went wrong.