Skip to content

Commit

Permalink
Merge branch 'develop' into ordermodify2
Browse files Browse the repository at this point in the history
  • Loading branch information
freehyeon authored Dec 18, 2024
2 parents e94d1f1 + 0981927 commit 540d602
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public Map<String, String> orderRegisterPOST(@RequestBody OrderVO order, HttpSer
for (OrderItemVO item : order.getOrderItems()) {
if (order.getOrderType() == OrderType.OUTBOUND) {
// 수주의 경우 가용 재고 체크
if (!orderService.checkAvailableStock(item)) {
if (!orderService.checkAvailableStock(item,order.getOrderType())) {
throw new IllegalArgumentException(
String.format("재고 부족 - StockId: %d, 요청수량: %d",
item.getStockId(), item.getQuantity())
Expand Down
17 changes: 10 additions & 7 deletions stockMate/src/main/java/com/stockm8/controller/UserController.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public class UserController {

@Autowired
private UserService userService;

// http://localhost:8088 (o)

// http://localhost:8088/user/signup (o)
// http://localhost:8088/user/signin (o)
Expand Down Expand Up @@ -251,7 +253,7 @@ public String changepassword1GET(HttpSession session) {
return "/user/changepassword1"; // 비밀번호 입력 페이지로 이동
}


// 회원정보 수정
@RequestMapping(value = "/changepassword1", method = RequestMethod.POST)
public String changepassword2POST(@RequestParam("password") String password, RedirectAttributes rttr, HttpSession session) {
Long userId = (Long) session.getAttribute("userId");
Expand Down Expand Up @@ -281,7 +283,7 @@ public String changepassword2POST(@RequestParam("password") String password, Red
}
}


// - GET
@RequestMapping(value = "/changepassword2", method = RequestMethod.GET)
public String changepassword2GET(@ModelAttribute("currentPassword") String currentPassword, Model model) {
if (currentPassword == null || currentPassword.isEmpty()) {
Expand All @@ -292,6 +294,7 @@ public String changepassword2GET(@ModelAttribute("currentPassword") String curre
return "/user/changepassword2"; // JSP 페이지 반환
}

// - POST
@RequestMapping(value = "/changepassword2", method = RequestMethod.POST)
public void changePasswordPOST(
@RequestParam("newPassword") String newPassword,
Expand Down Expand Up @@ -420,13 +423,13 @@ protected PasswordAuthentication getPasswordAuthentication() {


// 비밀번호 찾기 - GET
@RequestMapping(value = "/findPassword", method = RequestMethod.GET)
@RequestMapping(value = "/findpassword", method = RequestMethod.GET)
public String findPasswordGet() {
return "/user/findPassword"; // 비밀번호 찾기 페이지로 이동
return "/user/findpassword"; // 비밀번호 찾기 페이지로 이동
}

// 비밀번호 찾기 - POST
@RequestMapping(value = "/findPassword", method = RequestMethod.POST)
@RequestMapping(value = "/findpassword", method = RequestMethod.POST)
public String findPasswordPost(@RequestParam("email") String email,
@RequestParam("name") String name,
Model model) {
Expand All @@ -443,13 +446,13 @@ public String findPasswordPost(@RequestParam("email") String email,
// 비밀번호가 일치하지 않으면 오류 메시지 추가
logger.info("비밀번호 찾기 실패: 이메일 또는 이름이 일치하지 않음"); // 실패 로그
model.addAttribute("errorMessage", "이메일 또는 이름이 일치하지 않습니다.");
return "/user/findPassword"; // 비밀번호 찾기 페이지로 다시 이동
return "/user/findpassword"; // 비밀번호 찾기 페이지로 다시 이동
}
} catch (Exception e) {
e.printStackTrace();
logger.error("비밀번호 찾기 처리 중 오류 발생", e); // 예외 로그 추가
model.addAttribute("errorMessage", "비밀번호 찾기 처리 중 오류가 발생했습니다.");
return "/user/findPassword"; // 오류 발생 시 비밀번호 찾기 페이지로 돌아감
return "/user/findpassword"; // 오류 발생 시 비밀번호 찾기 페이지로 돌아감
}
}

Expand Down
7 changes: 4 additions & 3 deletions stockMate/src/main/java/com/stockm8/service/OrderService.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
import com.stockm8.domain.vo.OrderItemVO;
import com.stockm8.domain.vo.OrderVO;
import com.stockm8.domain.vo.ProductVO;
import com.stockm8.domain.vo.StockVO;
import com.stockm8.domain.vo.StockVO;
import com.stockm8.domain.vo.OrderVO.OrderType;

public interface OrderService {

Expand All @@ -31,8 +32,8 @@ public interface OrderService {
// 주문 상세 항목 목록 조회
public List<OrderItemVO> getOrderItemsByOrderId(int orderId) throws Exception;

// 가용 재고 체크 미사용
public boolean checkAvailableStock(OrderItemVO item) throws Exception;
// 가용 재고 체크
public boolean checkAvailableStock(OrderItemVO item, OrderType orderType) throws Exception;

// 전체 주문 개수 조회 (페이징 계산)
public int getTotalOrderCount(int businessId);
Expand Down
14 changes: 11 additions & 3 deletions stockMate/src/main/java/com/stockm8/service/OrderServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ private void processOrderByType(OrderVO order) throws Exception {
// 수주(출고) 처리
for (OrderItemVO item : order.getOrderItems()) {
// 재고 감소
if (!checkAvailableStock(item, OrderType.OUTBOUND)) {
throw new Exception("수주 처리 중 오류: 가용 재고가 부족합니다.");
}
updateStockQuantity(item.getStockId(), item.getQuantity());
// 수주(출고)일 때는 예약수량을 양수로 처리해야 함 (+)
}
Expand Down Expand Up @@ -135,9 +138,14 @@ public List<OrderItemVO> getOrderItemsByOrderId(int orderId) throws Exception {

// 가용재고 체크
@Override
public boolean checkAvailableStock(OrderItemVO item) throws Exception {
StockVO stock = odao.getStockById(item.getStockId());
return stock != null && stock.getAvailableStock() >= item.getQuantity();
public boolean checkAvailableStock(OrderItemVO item, OrderType orderType) throws Exception {
// 발주(INBOUND)인 경우 체크하지 않음
if (orderType == OrderType.INBOUND) {
return true;
}
// 수주(OUTBOUND)인 경우만 재고 체크
StockVO stock = odao.getStockById(item.getStockId());
return stock != null && stock.getAvailableStock() >= item.getQuantity();
}

// 전체 주문 개수 조회 (페이징 계산)
Expand Down
34 changes: 24 additions & 10 deletions stockMate/src/main/webapp/WEB-INF/views/order/register.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -480,9 +480,10 @@
card.find('.base-unit').val(stock.product.baseUnit);
card.find('.unit-price').val(stock.product.productPrice);
// 주문 수량 입력 필드
const quantityInput = card.find('.order-quantity');
// 수주(OUTBOUND)인 경우에만 최대 수량 제한 설정
if (orderType === 'OUTBOUND') {
quantityInput.attr('max', stock.availableStock); // 가용 재고로 최대값 설정
Expand All @@ -501,8 +502,7 @@
const card = input.closest('.stock-info-card');
// 주문 유형 가져오기
const orderType = $('input[name="orderType"]:checked').val();
// 입력된 수량과 가용 재고를 정수로 변환 (값이 없으면 0으로 설정)
const quantity = parseInt(input.val()) || 0; // 입력된 주문 수량 반환실패 시 null 대신 0 값 들어감
const available = parseInt(card.find('.available-stock').val()) || 0; // 가용 재고량
Expand All @@ -511,6 +511,7 @@
if (quantity < 1) { // 최소 주문 수량(1개) 미만인 경우
alert('주문 수량은 1 이상이어야 합니다.');
input.val(1); // 수량을 1로 재설정
}else if (orderType === 'OUTBOUND' && quantity > available) { // 수주의 경우 가용재고 체크
alert('수주 수량이 가용 재고를 초과할 수 없습니다.');
input.val(available);
Expand Down Expand Up @@ -559,29 +560,42 @@
buttons.prop('disabled', buttons.length <= 1);
}
// 폼 유효성 검사
function validateForm() {
let isValid = true;
let hasUnselectedItems = false;
// 주문 유형 체크(수주/ 발주)
if (!$('input[name="orderType"]:checked').val()){
alert('주문 유형을 선택 해주세요.');
return false;
// 주문 유형 체크(수주/발주)
const orderType = $('input[name="orderType"]:checked').val();
if (!orderType) {
alert('주문 유형을 선택해주세요.');
return false;
}
// 각 주문 항목 검증
$('.stock-info-card:visible').each(function() {
const card = $(this);
// 재고 선택 여부 체크
if (!card.find('.stock-id').val()) {
hasUnselectedItems = true;
return false;
return false; // each 루프 중단
}
// 수량 유효성 체크
const quantity = parseInt(card.find('.order-quantity').val());
const available = parseInt(card.find('.available-stock').val());
if (!quantity || quantity < 1) {
alert('모든 주문의 수량은 1 이상이어야 합니다.');
isValid = false;
return false;
return false; // each 루프 중단
}
// 수주(OUTBOUND)인 경우에만 가용 재고 체크
if (orderType === 'OUTBOUND' && quantity > available) {
alert('수주 수량이 가용 재고를 초과할 수 없습니다.');
isValid = false;
return false; // each 루프 중단
}
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html lang="ko">
<head>
Expand Down Expand Up @@ -108,10 +109,10 @@
<!-- Container -->
<div class="container">
<div class="back-button">
<a href="/user/main">&larr; 뒤로 가기</a>
<a href="/">&larr; 뒤로 가기</a>
</div>
<h1>비밀번호 찾기</h1>
<form action="findPassword" method="post">
<form action="findpassword" method="post">
<input type="email" id="email" name="email" placeholder="이메일" required>
<input type="text" id="name" name="name" placeholder="이름" required>
<button type="submit">비밀번호 찾기</button>
Expand All @@ -120,9 +121,13 @@
</div>

<!-- 실패 시 errorMessage를 알림창으로 표시 -->
<script>
alert("${errorMessage}");
</script>
<script type="text/javascript">
<c:if test="${not empty errorMessage}">
alert("${errorMessage}");
</c:if>
</script>


<!-- Footer -->
Expand Down
17 changes: 17 additions & 0 deletions stockMate/src/main/webapp/WEB-INF/views/user/showpassword.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<title>비밀번호 확인</title>
</head>
<body>
<script>
// 서버에서 전달받은 비밀번호를 알림창으로 표시
alert("${alertMessage}");
// 알림창이 닫히면 메인 페이지로 리다이렉트
window.location.href = "/";
</script>
</body>
</html>
2 changes: 1 addition & 1 deletion stockMate/src/main/webapp/WEB-INF/views/user/signin.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
</form>
<div class="links">
<a href="/user/signup">회원가입</a>
<a href="/user/findPassword">비밀번호 찾기</a>
<a href="/user/findpassword">비밀번호 찾기</a>
</div>
<div class="footer">회사 정보 - 사업자 번호, 연락처 등 추가 정보</div>
</div>
Expand Down

0 comments on commit 540d602

Please sign in to comment.