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

[#45] 주문기능 제작 #46

Merged
merged 28 commits into from
Jan 16, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
f782b3b
장바구니 기능 구현
Nov 28, 2019
6cb06dd
cart index delete 기능 구현 및 Test code 작성
Nov 29, 2019
54f8112
- Redis tranasaction 적용
Dec 2, 2019
7cafad5
장바구니 로직 추가
Dec 3, 2019
fe79388
- OrderDTO 생성
binaryyoung Dec 3, 2019
454c57c
- 캐싱하기 적합한 DTO를 사용하도록 변경
Dec 3, 2019
82905b6
빈 테스트코드 추가(Test ERROR)
Dec 3, 2019
489e028
OrderDTO에 @JsonFormat 추가
binaryyoung Dec 4, 2019
15d2f50
리뷰 반영
Dec 4, 2019
0989bc5
사용하지 않는 menuService 제거
Dec 9, 2019
9db3122
DTO를 Inner Class로 분리
Dec 9, 2019
e6cbc9b
가상 결제 구현
Dec 9, 2019
691a57e
사용하지 않는 코드 제거
Dec 10, 2019
b9d20d0
주문 로직 개발
Dec 11, 2019
a437709
계산서 발행 로직 작성 및 리뷰 일부 반영
Dec 13, 2019
792dc36
거리 계산로직 추가
Dec 13, 2019
4341748
배달료 계산 로직 추가
Dec 13, 2019
a280675
insert문을 벌크 insert로 진행하도록 변경
Dec 17, 2019
85a5f6e
주문 기능 제작
Dec 17, 2019
0d394c2
계산서 발행 시 메뉴, 메뉴 옵션에 의해 다수의 SELECT 쿼리가 질의되는 문제 해결
Dec 18, 2019
224158e
자신의 주문 정보 조회 기능 추가
Dec 18, 2019
4dc041c
OrderDTO 불변객체로 변경
Dec 19, 2019
1ddf344
유효성 검사 추가 및 변경
Dec 19, 2019
aeea70a
OrderDTO 수정으로 인한 버그 수정
Dec 19, 2019
a2f8bc4
리뷰 반영
Dec 23, 2019
cff527d
가상 결제 시스템 브랜치와 병합
Dec 24, 2019
8e1b0c3
가상 결제 진행 개발
Dec 24, 2019
a1732c1
Merge branch 'develop' into feature/20
yyy9942 Jan 16, 2020
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
2 changes: 1 addition & 1 deletion src/main/java/com/delfood/controller/OrderController.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public long getItemsBill(HttpSession session, @RequestBody List<OrderItemDTO> it
* @param orderId 주문번호
* @return
*/
@GetMapping("orderBill/{orderId}")
@GetMapping("{orderId}/bill")
@MemberLoginCheck
public OrderBillDTO orderInfo(@PathVariable("orderId") Long orderId) {
return orderService.getPreOrderBill(orderId);
Expand Down
29 changes: 29 additions & 0 deletions src/main/java/com/delfood/dto/address/Position.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.delfood.dto.address;

import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor
public class Position {
private double xPos;
private double yPos;

@Builder
public Position(double xPos, double yPos) {
this.xPos = xPos;
this.yPos = yPos;
}

/**
* 대상 위치와의 거리를 계산한다.
* @author jun
* @param position 거리를 계산할 위치
* @return
*/
public double distanceMeter(Position position) {
return Math.sqrt(
Math.pow(this.xPos - position.getXPos(), 2) + Math.pow(this.yPos - position.getYPos(), 2));
}
}
7 changes: 1 addition & 6 deletions src/main/java/com/delfood/error/ErrorController.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,5 @@ public ErrorMsg handleIllegalArgumentException(IllegalArgumentException e) {
public ErrorMsg handleCannotShopException(RuntimeException e) {
return new ErrorMsg(e.getLocalizedMessage(), getSimpleName(e));
}

@ResponseStatus(HttpStatus.BAD_REQUEST)
@ExceptionHandler(TotalPriceMismatchException.class)
public ErrorMsg handleTotalPriceMismatchException(TotalPriceMismatchException e) {
return new ErrorMsg(e.getLocalizedMessage(), getSimpleName(e));
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.delfood.error.exception.order;

public class TotalPriceMismatchException extends RuntimeException{
public class TotalPriceMismatchException extends IllegalArgumentException {
public TotalPriceMismatchException(String msg) {
super(msg);
}
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/com/delfood/mapper/AddressMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.delfood.controller.reqeust.GetAddressByZipRequest;
import com.delfood.controller.reqeust.GetAddressesByRoadRequest;
import com.delfood.dto.AddressDTO;
import com.delfood.dto.address.Position;
import java.util.List;
import org.springframework.stereotype.Repository;

Expand All @@ -14,7 +15,9 @@ public interface AddressMapper {

public List<AddressDTO> findByRoadName(GetAddressesByRoadRequest searchInfo);

public double findDistanceMeterByAddressCode(String startAddressCode, String endAddressCode);
public Position findPositionByMemberId(String memberId);

public double findDistancemeterByMemberIdAndShopId(String memberId, Long shopId);
public Position findPositionByShopId(Long shopId);

public Position findPositionByAddressCode(String addressCode);
}
22 changes: 20 additions & 2 deletions src/main/java/com/delfood/service/AddressService.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.delfood.controller.reqeust.GetAddressByZipRequest;
import com.delfood.controller.reqeust.GetAddressesByRoadRequest;
import com.delfood.dto.AddressDTO;
import com.delfood.dto.address.Position;
import com.delfood.mapper.AddressMapper;
import lombok.extern.log4j.Log4j2;
import java.util.List;
Expand Down Expand Up @@ -35,8 +36,17 @@ public List<AddressDTO> getAddressByRoadName(GetAddressesByRoadRequest searchInf
return addressMapper.findByRoadName(searchInfo);
}

/**
* 주소코드를 이용하여 거리를 계산한다.
* @param startAddressCode 시작 주소코드
* @param endAddressCode 도착 주소코드
* @return
*/
public double getDistanceMeter(String startAddressCode, String endAddressCode) {
return addressMapper.findDistanceMeterByAddressCode(startAddressCode, endAddressCode);
Position startPosition = addressMapper.findPositionByAddressCode(startAddressCode);
Position endPosition = addressMapper.findPositionByAddressCode(endAddressCode);

return startPosition.distanceMeter(endPosition);
}

/**
Expand All @@ -58,8 +68,16 @@ public long deliveryPrice(double distanceMeter) {
return deliveryCost + extraCharge;
}

/**
* 회원과 매장의 아이디를 기준으로 배달료를 계산한다.
* @param memberId 회원 id
* @param shopId 매장 id
* @return
*/
public long deliveryPrice(String memberId, Long shopId) {
double distanceMeter = addressMapper.findDistancemeterByMemberIdAndShopId(memberId, shopId);
Position memberPosition = addressMapper.findPositionByMemberId(memberId);
Position shopPosition = addressMapper.findPositionByShopId(shopId);
double distanceMeter = memberPosition.distanceMeter(shopPosition);
return deliveryPrice(distanceMeter);
}
}
36 changes: 19 additions & 17 deletions src/main/resources/mybatis/mapper/address.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,24 +74,26 @@
ORDER BY building_management_number
LIMIT 10
</select>

<select id="findDistanceMeterByAddressCode" resultType="double">
SELECT SQRT(POW(a.building_center_point_x_coordinate - b.building_center_point_x_coordinate, 2)
+ POW(a.building_center_point_y_coordinate - b.building_center_point_y_coordinate, 2)) as distanceKilometer
FROM ADDRESS a, ADDRESS b
WHERE a.building_management_number = #{startAddressCode}
AND b.building_management_number = #{endAddressCode}

<select id="findPositionByMemberId" resultType="com.delfood.dto.address.Position">
SELECT building_center_point_x_coordinate xPos, building_center_point_y_coordinate yPos
FROM ADDRESS
WHERE building_management_number = (SELECT MEMBER.address_code
FROM MEMBER
WHERE MEMBER.id = #{memberId})
</select>

<select id="findPositionByShopId" resultType="com.delfood.dto.address.Position">
SELECT building_center_point_x_coordinate xPos, building_center_point_y_coordinate yPos
FROM ADDRESS
WHERE building_management_number = (SELECT SHOP.address_code
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

여기서 서브쿼리가 좋을지, 조인이 좋을지 생각해보시는 것도 좋을 것 같습니다~

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

조인하기에는 주소 DB 양이 너무 많아서.. 서브쿼리가 더 나을거라고 생각했습니다. innoDB 조인은 nested loop join이라 주소DB는 조인하기에는 부담이 큰거같아요.

FROM SHOP
WHERE SHOP.id = #{shopId})
</select>

<select id="findDistancemeterByMemberIdAndShopId" resultType="double">
SELECT SQRT(POW(a.building_center_point_x_coordinate - b.building_center_point_x_coordinate, 2)
+ POW(a.building_center_point_y_coordinate - b.building_center_point_y_coordinate, 2)) as distanceKilometer
FROM ADDRESS a, ADDRESS b
WHERE a.building_management_number = (SELECT m.address_code
FROM MEMBER m
WHERE m.id = #{memberId})
AND b.building_management_number = (SELECT s.address_code
FROM SHOP s
WHERE s.id = #{shopId})
<select id="findPositionByAddressCode" resultType="com.delfood.dto.address.Position">
SELECT building_center_point_x_coordinate xPos, building_center_point_y_coordinate yPos
FROM ADDRESS
WHERE building_management_number = #{addressCode}
</select>
</mapper>
3 changes: 2 additions & 1 deletion src/main/resources/mybatis/mapper/orders.xml
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@
shop.id shopId,
shop.name shopName,
item.id itemId,
menu.id menuId,
menu.name menuName,
menu.price menuPrice,
item.count itemCount,
Expand Down Expand Up @@ -221,7 +222,7 @@
<collection property="options" ofType="com.delfood.dto.ItemsBillDTO$MenuInfo$OptionInfo">
<id property="id" column="optionId"/>
<result property="name" column="optionName"/>
<result property="price" column="opti`onPrice"/>
<result property="price" column="optionPrice"/>
</collection>
</resultMap>

Expand Down