Skip to content
This repository has been archived by the owner on Aug 13, 2022. It is now read-only.

[#14] 아파트 가격 정보 자동 갱신 배치 개발 #26

Open
wants to merge 19 commits into
base: develop-jpa
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
e6bbc73
refactor: 중복 기능 클래스 제거
ShimSeoungChul Jan 22, 2022
4d875b6
fix: 컴포넌트 스캔 범위 변경
ShimSeoungChul Jan 23, 2022
e90dbcc
feat: ToString 기능 추가
ShimSeoungChul Jan 23, 2022
04fb00d
fix: read-only를 막기 위해 데이터 저장 로직에 @Transactional 애너테이션 추가
ShimSeoungChul Jan 23, 2022
51d3a22
fix: 한자리 월 (1~9)이 01, 02, 03 ... 형식으로 정장되도록 수정
ShimSeoungChul Jan 23, 2022
6a9a945
refactor: Runner 클래스와 아파트 정보 저장 클래스 나누기
ShimSeoungChul Jan 23, 2022
6f94d54
refactor: 중복 기능 클래스로 제거된 서비스 클래스 교체
ShimSeoungChul Jan 23, 2022
c896c67
feat: 파싱한 데이터가 올바른 데이터인지 확인하는 기능
ShimSeoungChul Jan 23, 2022
ff24328
refactor: 코드 재활용을 위한 패키지 이동
ShimSeoungChul Jan 23, 2022
15cc0fc
fix: float 자료형의 areaForExclusiveUse 변수 값을 소수점 4자리까지 반올림한 BigDecimal 타…
ShimSeoungChul Jan 23, 2022
fe86386
refactor: 클래스 이름 변경
ShimSeoungChul Jan 23, 2022
c7f56cf
refactor: 클래스 이름 변경, SoaringPricesService -> SoaringPriceService
ShimSeoungChul Jan 24, 2022
4cb0ddd
feat: ApartmentPriceDto 추가
ShimSeoungChul Jan 24, 2022
7533ca5
feat: SoaringPriceDto 추가
ShimSeoungChul Jan 24, 2022
a273a6c
refactor: 클래스 이름 변경 SoaringPrices -> SoaringPrice
ShimSeoungChul Jan 24, 2022
f49835a
feat: 급상승 아파트 정보 저장 기능 추가
ShimSeoungChul Jan 24, 2022
b330444
feat: 매일 밤 12시에 아파트 가격 정보와 급상승 아파트 정보를 갱신하는 기능 추가
ShimSeoungChul Jan 24, 2022
cc396d1
fix: 퍼센트 금액 차이 계산식 수정
ShimSeoungChul Jan 25, 2022
8047117
fix: 통합 테스트 실패 오류 제거
ShimSeoungChul Jan 26, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified realestate-prices/2018_11_10-2019_11_09.xlsx
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,25 @@
import org.springframework.web.bind.annotation.RestController;

import kancho.realestate.comparingprices.domain.dto.response.SuccessReponseDto;
import kancho.realestate.comparingprices.domain.model.SoaringPrices;
import kancho.realestate.comparingprices.service.SoaringPricesService;
import kancho.realestate.comparingprices.domain.model.SoaringPrice;
import kancho.realestate.comparingprices.service.SoaringPriceService;
import lombok.RequiredArgsConstructor;

@RestController
@RequiredArgsConstructor
@RequestMapping(value = "/soaring-prices", produces = "application/json; charset=utf8")
public class SoaringPricesController {
private final SoaringPricesService soaringPricesService;
private final SoaringPriceService soaringPriceService;

@GetMapping(value = "/percent")
public ResponseEntity percentList() {
List<SoaringPrices> soaringPricesList = soaringPricesService.getSoaringPrices(SoaringPrices.Unit.PERCENT);
return new ResponseEntity<>(new SuccessReponseDto<>("급상승 부동산 가격 조회 성공", soaringPricesList), HttpStatus.OK);
List<SoaringPrice> soaringPriceList = soaringPriceService.getSoaringPrices(SoaringPrice.Unit.PERCENT);
return new ResponseEntity<>(new SuccessReponseDto<>("급상승 부동산 가격 조회 성공", soaringPriceList), HttpStatus.OK);
}

@GetMapping(value = "/won")
public ResponseEntity wonList() {
List<SoaringPrices> soaringPricesList = soaringPricesService.getSoaringPrices(SoaringPrices.Unit.WON);
return new ResponseEntity<>(new SuccessReponseDto<>("급상승 부동산 가격 조회 성공", soaringPricesList), HttpStatus.OK);
List<SoaringPrice> soaringPriceList = soaringPriceService.getSoaringPrices(SoaringPrice.Unit.WON);
return new ResponseEntity<>(new SuccessReponseDto<>("급상승 부동산 가격 조회 성공", soaringPriceList), HttpStatus.OK);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
import kancho.realestate.comparingprices.exception.InvalidDealYearAndMonthException;
import kancho.realestate.comparingprices.exception.InvalidRegionalCodeException;
import lombok.Getter;
import lombok.ToString;

@Getter
@ToString
public class RequestApartmentDetailDto {
private String regionalCode;
private int dealYear;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package kancho.realestate.comparingprices.domain.dto.request;

import java.time.LocalDate;

import kancho.realestate.comparingprices.domain.model.SoaringPrice;
import lombok.Getter;
import lombok.ToString;

@Getter
@ToString
public class RequestSoaringPriceDto {
private long apartmentId;
private String areaForExclusiveUse;
private LocalDate pastDate;
private long pastPrice;
private LocalDate latestDate;
private long latestPrice;
private SoaringPrice.Unit priceDifferenceUnit; // PERCENT, WON
private long priceDifference;

public RequestSoaringPriceDto(long apartmentId, String areaForExclusiveUse, LocalDate pastDate, long pastPrice,
LocalDate latestDate, long latestPrice, SoaringPrice.Unit priceDifferenceUnit, long priceDifference) {
this.apartmentId = apartmentId;
this.areaForExclusiveUse = areaForExclusiveUse;
this.pastDate = pastDate;
this.pastPrice = pastPrice;
this.latestDate = latestDate;
this.latestPrice = latestPrice;
this.priceDifferenceUnit = priceDifferenceUnit;
this.priceDifference = priceDifference;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package kancho.realestate.comparingprices.domain.dto.request;

import java.math.BigDecimal;
import java.util.Objects;

import kancho.realestate.comparingprices.domain.model.ApartmentPrice;
import lombok.Getter;
import lombok.ToString;

@Getter
@ToString
public class ResponseApartmentPriceDto {
private long apartmentId;
private BigDecimal areaForExclusiveUse;
private int dealYear;
private int dealMonth;
private int dealDay;
private int dealAmount;
private int floor;

public ResponseApartmentPriceDto(long apartmentId, BigDecimal areaForExclusiveUse, int dealYear, int dealMonth,
int dealDay, int dealAmount, int floor) {
this.apartmentId = apartmentId;
this.areaForExclusiveUse = areaForExclusiveUse;
this.dealYear = dealYear;
this.dealMonth = dealMonth;
this.dealDay = dealDay;
this.dealAmount = dealAmount;
this.floor = floor;
}

public static ResponseApartmentPriceDto from(ApartmentPrice apartmentPrice) {
return new ResponseApartmentPriceDto(
apartmentPrice.getApartmentId(),
apartmentPrice.getAreaForExclusiveUse(),
apartmentPrice.getDealYear(),
apartmentPrice.getDealMonth(),
apartmentPrice.getDealDay(),
apartmentPrice.getDealAmount(),
apartmentPrice.getFloor());
}

@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
ResponseApartmentPriceDto that = (ResponseApartmentPriceDto)o;
return apartmentId == that.apartmentId && dealYear == that.dealYear && dealMonth == that.dealMonth
&& dealDay == that.dealDay && dealAmount == that.dealAmount && floor == that.floor
&& areaForExclusiveUse.compareTo(that.areaForExclusiveUse) == 0;
}

@Override
public int hashCode() {
return Objects.hash(apartmentId, areaForExclusiveUse, dealYear, dealMonth, dealDay, dealAmount, floor);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package kancho.realestate.comparingprices.domain.dto.response;

import java.math.BigDecimal;
import java.util.Objects;

import kancho.realestate.comparingprices.domain.model.ApartmentPrice;
import lombok.Getter;
import lombok.ToString;

@Getter
@ToString
public class ResponseApartmentPriceDto {
private long apartmentId;
private BigDecimal areaForExclusiveUse;
private int dealYear;
private int dealMonth;
private int dealDay;
private int dealAmount;
private int floor;

public ResponseApartmentPriceDto(long apartmentId, BigDecimal areaForExclusiveUse, int dealYear, int dealMonth,
int dealDay, int dealAmount, int floor) {
this.apartmentId = apartmentId;
this.areaForExclusiveUse = areaForExclusiveUse;
this.dealYear = dealYear;
this.dealMonth = dealMonth;
this.dealDay = dealDay;
this.dealAmount = dealAmount;
this.floor = floor;
}

public static ResponseApartmentPriceDto from(ApartmentPrice apartmentPrice) {
return new ResponseApartmentPriceDto(
apartmentPrice.getApartmentId(),
apartmentPrice.getAreaForExclusiveUse(),
apartmentPrice.getDealYear(),
apartmentPrice.getDealMonth(),
apartmentPrice.getDealDay(),
apartmentPrice.getDealAmount(),
apartmentPrice.getFloor());
}

@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
ResponseApartmentPriceDto that = (ResponseApartmentPriceDto)o;
return apartmentId == that.apartmentId && dealYear == that.dealYear && dealMonth == that.dealMonth
&& dealDay == that.dealDay && dealAmount == that.dealAmount && floor == that.floor
&& areaForExclusiveUse.compareTo(that.areaForExclusiveUse) == 0;
}

@Override
public int hashCode() {
return Objects.hash(apartmentId, areaForExclusiveUse, dealYear, dealMonth, dealDay, dealAmount, floor);
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package kancho.realestate.comparingprices.domain.dto.response;


import java.time.LocalDate;

import kancho.realestate.comparingprices.domain.model.SoaringPrice;
import lombok.Getter;
import lombok.ToString;

@Getter
@ToString
public class ResponseSoaringPriceDto {
private int id;
private long apartmentId;
private String areaForExclusiveUse;
private LocalDate pastDate;
private long pastPrice;
private LocalDate latestDate;
private long latestPrice;
private String priceDifferenceUnit; // PERCENT, WON
private long priceDifference;

public ResponseSoaringPriceDto(int id, long apartmentId, String areaForExclusiveUse, LocalDate pastDate,
long pastPrice, LocalDate latestDate, long latestPrice, String priceDifferenceUnit, long priceDifference) {
this.id = id;
this.apartmentId = apartmentId;
this.areaForExclusiveUse = areaForExclusiveUse;
this.pastDate = pastDate;
this.pastPrice = pastPrice;
this.latestDate = latestDate;
this.latestPrice = latestPrice;
this.priceDifferenceUnit = priceDifferenceUnit;
this.priceDifference = priceDifference;
}

public static ResponseSoaringPriceDto from(SoaringPrice soaringPrice) {
return new ResponseSoaringPriceDto(
soaringPrice.getId(),
soaringPrice.getApartment().getId(),
soaringPrice.getAreaForExclusiveUse().toString(),
soaringPrice.getPastDate(),
soaringPrice.getPastPrice(),
soaringPrice.getLatestDate(),
soaringPrice.getLatestPrice(),
soaringPrice.getPriceDifferenceUnit().toString(),
soaringPrice.getPriceDifference());
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package kancho.realestate.comparingprices.domain.model;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Objects;

import javax.persistence.Entity;
Expand All @@ -11,9 +12,11 @@
import kancho.realestate.comparingprices.domain.vo.ApartmentDetail;
import kancho.realestate.comparingprices.domain.vo.ApartmentPriceUniqueInfo;
import lombok.Getter;
import lombok.ToString;

@Getter
@Entity
@ToString
public class ApartmentPrice extends BaseTimeEntity{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Expand Down Expand Up @@ -46,25 +49,31 @@ public ApartmentPrice(ApartmentDetail detail) {
}

private int parseDealAmount(String dealAmount) {
dealAmount = dealAmount.trim().replace(",",""); // 공백 제거
return Integer.parseInt(dealAmount);
dealAmount = dealAmount.trim().replace(",",""); // 공백 제거
return Integer.parseInt(dealAmount);
}

public ApartmentPriceUniqueInfo getApartmentPriceUniqueInfo() {
return new ApartmentPriceUniqueInfo(this);
}

public BigDecimal getAreaForExclusiveUse() {
return BigDecimal.valueOf(areaForExclusiveUse)
.setScale(4, RoundingMode.HALF_EVEN)
.stripTrailingZeros();
}

@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (!(o instanceof ApartmentPrice))
if (o == null || getClass() != o.getClass())
return false;

ApartmentPrice that = (ApartmentPrice)o;
BigDecimal thisAreaForExclusiveUse = new BigDecimal(that.areaForExclusiveUse);
BigDecimal thatAreaForExclusiveUse = new BigDecimal(areaForExclusiveUse);
BigDecimal thisAreaForExclusiveUse = this.getAreaForExclusiveUse();
BigDecimal thatAreaForExclusiveUse = that.getAreaForExclusiveUse();

return apartmentId == that.apartmentId
&& thisAreaForExclusiveUse.compareTo(thatAreaForExclusiveUse) == 0 && dealYear == that.dealYear
&& dealMonth == that.dealMonth && dealDay == that.dealDay && dealAmount == that.dealAmount
Expand All @@ -73,6 +82,6 @@ public boolean equals(Object o) {

@Override
public int hashCode() {
return Objects.hash(apartmentId, areaForExclusiveUse, dealYear, dealMonth, dealDay, dealAmount, floor);
return Objects.hash(apartmentId, this.getAreaForExclusiveUse(), dealYear, dealMonth, dealDay, dealAmount, floor);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package kancho.realestate.comparingprices.domain.model;

import java.time.LocalDate;
import java.util.Objects;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Index;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import kancho.realestate.comparingprices.domain.dto.request.RequestSoaringPriceDto;
import lombok.Getter;

@Getter
@Table(indexes = @Index(name = "idx_created_date", columnList = "createdDate"))
@Entity
public class SoaringPrice extends BaseTimeEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;

@ManyToOne
private Apartment apartment;

private String areaForExclusiveUse;

private LocalDate pastDate;

private long pastPrice;

private LocalDate latestDate;

private long latestPrice;

private String priceDifferenceUnit; // PERCENT, WON

private long priceDifference;

public SoaringPrice(Apartment apartment, String areaForExclusiveUse, LocalDate pastDate, long pastPrice, LocalDate latestDate,
long latestPrice, String priceDifferenceUnit, long priceDifference) {
this.apartment = apartment;
this.areaForExclusiveUse = areaForExclusiveUse;
this.pastDate = pastDate;
this.pastPrice = pastPrice;
this.latestDate = latestDate;
this.latestPrice = latestPrice;
this.priceDifferenceUnit = priceDifferenceUnit;
this.priceDifference = priceDifference;
}

public enum Unit{
PERCENT { // 퍼센트(%)
public long calculatePriceDifference(long latestPrice, long pastPrice){
return latestPrice * 100 / pastPrice - 100;
}
},
WON{ // 원(₩)
public long calculatePriceDifference(long latestPrice, long pastPrice){
return latestPrice - pastPrice;
}
};

public abstract long calculatePriceDifference(long latestPrice, long pastPrice);
}

@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (!(o instanceof SoaringPrice))
return false;
SoaringPrice that = (SoaringPrice)o;
return getId() == that.getId();
}

@Override
public int hashCode() {
return Objects.hash(getId());
}
}
Loading