Skip to content

Commit

Permalink
Merge pull request #158 from in27sung/stockorder
Browse files Browse the repository at this point in the history
Stockorder
  • Loading branch information
freehyeon authored Dec 16, 2024
2 parents c112a6c + 5d77c10 commit c7d6bcb
Show file tree
Hide file tree
Showing 21 changed files with 604 additions and 1,296 deletions.
20 changes: 19 additions & 1 deletion stockMate/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,26 @@
<groupId>com.google.zxing</groupId>
<artifactId>javase</artifactId>
<version>3.5.1</version>
</dependency>
</dependency>

<!-- AspectJ 트랜잭션때문에... 로그 확인을 위한것...-->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.9.7</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.9.7</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>${org.springframework-version}</version>
</dependency>

<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion stockMate/src/main/java/com/stockm8/config/WebConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public class WebConfig implements WebMvcConfigurer {
public void addInterceptors(InterceptorRegistry registry) {
// Intercepter 적용
registry.addInterceptor(authorizationInterceptor)
.addPathPatterns("/dashboard", "/business", "/category/**", "/product/**", "/warehouse/**", "/stock/**" ) // 인터셉터를 적용할 경로
.addPathPatterns("/dashboard", "/business", "/category/**", "/product/**", "/warehouse/**", "/stock/**", "/order/**" ) // 인터셉터를 적용할 경로
.excludePathPatterns( // 인터셉터를 제외할 경로
"/", // HomeController 경로
"/favicon.ico", // 브라우저 기본 요청
Expand Down
94 changes: 81 additions & 13 deletions stockMate/src/main/java/com/stockm8/controller/OrderController.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -19,7 +21,9 @@

import com.stockm8.domain.vo.OrderItemVO;
import com.stockm8.domain.vo.OrderVO;
import com.stockm8.domain.vo.OrderVO.OrderType;
import com.stockm8.domain.vo.StockVO;
import com.stockm8.domain.vo.UserVO;
import com.stockm8.service.OrderService;
import com.stockm8.service.UserService;

Expand All @@ -42,18 +46,34 @@ public class OrderController {
*
*/
@RequestMapping(value = "/register", method = RequestMethod.GET)
public String orderRegisterGET(Model model, HttpServletRequest request) throws Exception {
public String orderRegisterGET(Model model, HttpServletRequest request, HttpServletResponse response) throws Exception {
logger.info("orderRegisterGET() 호출");

// // 세션에서 userId 가져오기
// HttpSession session = request.getSession(false);
// Long userId = (session != null) ? (Long)session.getAttribute("userId") : null;
//
// // userId로 사용자 정보 조회
// UserVO user = userService.getUserById(userId);
// int businessId = user.getBusinessId();

// 세션에서 userId 가져오기
HttpSession session = request.getSession(false);
Long userId = (session != null) ? (Long)session.getAttribute("userId") : null;

// userId로 사용자 정보 조회
UserVO user = userService.getUserById(userId);
int businessId = user.getBusinessId();

// HttpSession session = request.getSession(false);
// if (session != null) {
// Long userId = (Long) session.getAttribute("userId");
// if (userId != null) {
// UserVO user = userService.getUserById(userId);
// if (user != null) {
// model.addAttribute("businessId", user.getBusinessId());
// // 추가적인 권한 체크나 비즈니스 로직
// return "order/register";
// }
// }
// }
// // 인증 실패 처리 => 음 메세지 ??? 어떻게 ??
// return "user/main";

return "order/register";
return "order/register";
}

/**
Expand All @@ -71,12 +91,30 @@ public String orderRegisterGET(Model model, HttpServletRequest request) throws E
public Map<String, String> orderRegisterPOST(@RequestBody OrderVO order) throws Exception {
logger.info("orderRegisterPOST() 호출");
logger.info("주문 정보: " + order);

// orderType 유효성 검사 추가(수주인지 / 발주인지 주문유형)
if (order.getOrderType() == null) {
throw new IllegalArgumentException("주문 유형이 누락되었습니다.");
}


// 주문에 orderItems가 있는지 확인(유효성 검사)
// 주문에 orderItems가 있는지 확인(유효성 검사)
if (order.getOrderItems() == null || order.getOrderItems().isEmpty()) {
throw new IllegalArgumentException("주문 항목이 누락되었습니다.");
}

// 주문 항목별 재고 검증 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
for (OrderItemVO item : order.getOrderItems()) {
if (order.getOrderType() == OrderType.INBOUND) {
// 수주의 경우 가용 재고 체크
if (!orderService.checkAvailableStock(item)) {
throw new IllegalArgumentException(
String.format("재고 부족 - StockId: %d, 요청수량: %d",
item.getStockId(), item.getQuantity())
);
}
}
}

// 주문번호 생성 및 설정
String orderNumber = orderService.generateOrderNumber();
Expand All @@ -86,7 +124,7 @@ public Map<String, String> orderRegisterPOST(@RequestBody OrderVO order) throws
OrderItemVO orderItem = order.getOrderItems().get(0);

// 주문 처리
orderService.insertOrder(order);
orderService.insertOrderWithItems(order, order.getOrderItems());

// 응답 생성
Map<String, String> response = new HashMap<>();
Expand All @@ -105,9 +143,18 @@ public Map<String, String> orderRegisterPOST(@RequestBody OrderVO order) throws
method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public List<StockVO> findAvailableStocks() throws Exception {
public List<StockVO> findAvailableStocks(HttpServletRequest request) throws Exception {
logger.info("findAvailableStocks() 호출");
return orderService.findAvailableStocks();

// 세션에서 userId 가져오기
HttpSession session = request.getSession(false);
Long userId = (session != null) ? (Long)session.getAttribute("userId") : null;

// userId로 사용자 정보 조회
UserVO user = userService.getUserById(userId);
int businessId = user.getBusinessId();

return orderService.findAvailableStocks(businessId);
}

/**
Expand All @@ -122,4 +169,25 @@ public String generateOrderNumber() throws Exception {
logger.info("generateOrderNumber() 호출");
return orderService.generateOrderNumber();
}

/**
* 주문 목록 조회
* http://localhost:8088/order/orderList
*/
@RequestMapping(value = "/orderList" , method = RequestMethod.GET)
public String orderListGET(Model model) {
logger.info("orderListGET() 호출");

// main에서 넘어올떄 정달정보 ?? 로그인???세션 ??

//서비스 -> DAO(주문 목록)
List<OrderVO> orderList = orderService.getOrderList();

//뷰 페이지 정보 전달(model)

model.addAttribute("orderList",orderList);

return "/order/orderList";
}

} //OrderController
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,9 @@ public class OrderItemVO {
private double stotalPrice; // 주문 1건의 전체 총 금액
private Timestamp createdAt; // 생성 시간
private Timestamp updatedAt; // 수정 시간


private int stockId; // 가용 재고 구분위해 필요


} //OrderItemVO
13 changes: 10 additions & 3 deletions stockMate/src/main/java/com/stockm8/domain/vo/OrderVO.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,25 @@

@Data
public class OrderVO {

public enum OrderType {
INBOUND, // 수주
OUTBOUND // 발주
}

private int orderId; // 주문 고유 ID
private String orderNumber; // 주문 번호 (예: ORD-YYYYMMDD-001)
private double totalPrice; // 주문 전체 총 금액
private int createdBy; // 주문을 생성한 사용자 ID
private Timestamp createdAt; // 주문 생성 날짜
private Timestamp updatedAt; // 주문 수정 날짜
private OrderType orderType; // 주문 유형 (INBOUND/OUTBOUND)
private String status; // 주문 상태 (pending, confirmed, cancelled)
private OrderType orderType;

private List<OrderItemVO> orderItems; // 주문 항목 리스트







}// OrderVO
2 changes: 1 addition & 1 deletion stockMate/src/main/java/com/stockm8/domain/vo/StockVO.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ public class StockVO {
private WarehouseVO warehouse; // 창고 정보
private String warehouseName;

}
}
58 changes: 0 additions & 58 deletions stockMate/src/main/java/com/stockm8/domain/vo/StockVO2.java

This file was deleted.

27 changes: 19 additions & 8 deletions stockMate/src/main/java/com/stockm8/persistence/OrderDAO.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.stockm8.persistence;

import java.util.List;
import java.util.Map;

import com.stockm8.domain.vo.OrderItemVO;
import com.stockm8.domain.vo.OrderVO;
Expand All @@ -13,18 +14,28 @@ public interface OrderDAO {
public void insertOrder(OrderVO order) throws Exception;

// 주문 항목 등록
public void insertOrderItem(OrderItemVO orderItem) throws Exception;

// 주문과 주문항목을 한번에 처리
public void insertOrderWithItems(OrderVO order) throws Exception;
public void insertOrderItem(List<OrderItemVO> orderItem) throws Exception;

// 모든 재고 목록 조회
public List<StockVO> findAvailableStocks() throws Exception;
public List<StockVO> findAvailableStocks(int businessId) throws Exception;

//주문번호 생성
// 주문번호 생성
public String generateOrderNumber() throws Exception;

// 재고 수량 업데이트
public int updateStockQuantity(Map<String, Object> params) throws Exception;

// 주문 목록
public List<OrderVO> getOrderList();

// 재고 정보 조회 @@@@@@@@@@@@@@@@@@@@@@@@@@@@ 미사용
public StockVO getStockById(int stockId) throws Exception;

// 재고 이력 등록 @@@@@@@@@@@@@@@@@@@@@@@@@@@@ 미사용
public void insertStockHistory(Map<String, Object> params) throws Exception;





// 재고의 예약 수량을 업데이트.. 이거는 뭐지..>>
public void updateStockReservedQuantity(int stockId, int quantity) throws Exception;
} // OrderDAO
Loading

0 comments on commit c7d6bcb

Please sign in to comment.