diff --git a/stockMate/src/main/java/com/stockm8/controller/StockController.java b/stockMate/src/main/java/com/stockm8/controller/StockController.java index e39d337..752296e 100644 --- a/stockMate/src/main/java/com/stockm8/controller/StockController.java +++ b/stockMate/src/main/java/com/stockm8/controller/StockController.java @@ -3,30 +3,21 @@ import java.util.List; import javax.inject.Inject; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpSession; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; -import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.ModelAttribute; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.SessionAttribute; -import com.stockm8.domain.vo.CategoryVO; import com.stockm8.domain.vo.StockVO; import com.stockm8.domain.vo.UserVO; import com.stockm8.domain.vo.WarehouseVO; import com.stockm8.persistence.FilterCriteria; -import com.stockm8.service.CategoryService; -import com.stockm8.service.ProductService; import com.stockm8.service.StockService; import com.stockm8.service.UserService; import com.stockm8.service.WarehouseService; @@ -34,47 +25,41 @@ @Controller @RequestMapping("/stock") public class StockController { - private static final Logger logger = LoggerFactory.getLogger(StockController.class); + private static final Logger logger = LoggerFactory.getLogger(StockController.class); - @Inject - private StockService stockService; + @Inject + private StockService stockService; - @Autowired - private UserService userService; + @Inject + private UserService userService; - @Autowired - private CategoryService categoryService; + @Inject + private WarehouseService warehouseService; - @Autowired - private WarehouseService warehouseService; + // 재고 등록 페이지 + // http://localhost:8088/stock/register + @RequestMapping(value = "/register", method = RequestMethod.GET) + public String stockRegisterGET(@SessionAttribute("userId") Long userId, Model model) throws Exception { + logger.info(" stockRegisterGET() 호출 "); - @Autowired - private ProductService productService; + // 사용자 정보 가져오기 + UserVO user = userService.getUserById(userId); + int businessId = user.getBusinessId(); + logger.info("Business ID for userId {}: {}", userId, businessId); - // http://localhost:8088/stock/register - /** - * 재고 등록 페이지 - */ - @GetMapping("/register") - public String stockRegisterGET(@SessionAttribute("userId") Long userId, Model model) throws Exception { - logger.info("Fetching stock register page for userId: {}", userId); + // 모델에 데이터 추가 + model.addAttribute("businessId", businessId); - // 사용자 정보 가져오기 - UserVO user = userService.getUserById(userId); - int businessId = user.getBusinessId(); - logger.info("Business ID for user: {}", businessId); - - // 모델에 데이터 추가 - model.addAttribute("businessId", businessId); - - return "/stock/register"; - } + return "/stock/register"; + } // 재고 등록 처리 - @PostMapping("/register") - public String registerStock(@ModelAttribute StockVO stock, @SessionAttribute("userId") Long userId, Model model) - throws Exception { - + @RequestMapping (value ="/register", method = RequestMethod.POST) + public String registerStockPost(@ModelAttribute StockVO stock, + @SessionAttribute("userId") + Long userId, Model model) throws Exception { + logger.info("registerStockPost() 실행"); + // 사용자 정보 가져오기 UserVO user = userService.getUserById(userId); int businessId = user.getBusinessId(); @@ -86,51 +71,47 @@ public String registerStock(@ModelAttribute StockVO stock, @SessionAttribute("us // 재고 등록 서비스 호출 stockService.registerStock(stock); - + logger.info("Stock registered successfully: {}", stock); + model.addAttribute("success", "재고 등록이 성공적으로 완료되었습니다."); return "redirect:/stock/list"; // 재고 목록 페이지로 이동 } - + + // 재고 목록 조회 // http://localhost:8088/stock/list @RequestMapping(value = "/list", method = RequestMethod.GET) - public String getStockList(StockVO stock, Model model, HttpServletRequest request, - @RequestParam(required = false) Integer warehouseId, @RequestParam(required = false) String categoryName, - @RequestParam(required = false) Integer minStock, @RequestParam(required = false) Integer maxStock, - @RequestParam(required = false, defaultValue = "desc") String sortOrder) throws Exception { - logger.info("getStockList 호출"); - - // 세션에서 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(); -// stock.setBusinessId(businessId); - - // 창고 목록 조회 (businessId에 맞는 창고 목록) - List warehouseList = warehouseService.getWarehousesByBusinessId(businessId); - logger.info("조회된 창고 목록: {}", warehouseList.size()); - - // 창고명과 카테고리명 정보 제공 - model.addAttribute("warehouseList", warehouseList); - model.addAttribute("categoryList", stockService.getCategoryList()); - - // 재고 리스트 조회 (FilterCriteria 객체를 사용하여 파라미터 전달) - FilterCriteria criteria = new FilterCriteria(warehouseId, categoryName, minStock, maxStock, sortOrder, - businessId); - List stockList = stockService.getStockList(criteria, sortOrder); // 정렬 순서 추가 - model.addAttribute("stockList", stockList); - - // 필터링된 파라미터들을 모델에 추가 - model.addAttribute("warehouseId", warehouseId); - model.addAttribute("categoryName", categoryName); - model.addAttribute("minStock", minStock); - model.addAttribute("maxStock", maxStock); - model.addAttribute("sortOrder", sortOrder); // 정렬 상태 추가 - - return sortOrder; // 이부분 수정 필요 확인해주세요 + public String getStockList(@SessionAttribute("userId") Long userId, Model model, + @RequestParam(required = false) Integer warehouseId, + @RequestParam(required = false) String categoryName, + @RequestParam(required = false) Integer minStock, + @RequestParam(required = false) Integer maxStock, + @RequestParam(required = false, defaultValue = "desc") String sortOrder) throws Exception { + logger.info("getStockList 호출"); + + // 사용자 정보 조회 + UserVO user = userService.getUserById(userId); + int businessId = user.getBusinessId(); + + // 창고 목록 조회 + List warehouseList = warehouseService.getWarehousesByBusinessId(businessId); + logger.info("조회된 창고 목록: {}", warehouseList.size()); + + // 창고명과 카테고리명 정보 제공 + model.addAttribute("warehouseList", warehouseList); + model.addAttribute("categoryList", stockService.getCategoryList()); + + // 재고 리스트 조회 + FilterCriteria criteria = new FilterCriteria(warehouseId, categoryName, minStock, maxStock, sortOrder, businessId); + List stockList = stockService.getStockList(criteria, sortOrder); + model.addAttribute("stockList", stockList); + + // 필터링된 파라미터들을 모델에 추가 + model.addAttribute("warehouseId", warehouseId); + model.addAttribute("categoryName", categoryName); + model.addAttribute("minStock", minStock); + model.addAttribute("maxStock", maxStock); + model.addAttribute("sortOrder", sortOrder); + + return "/stock/list"; } - } diff --git a/stockMate/src/main/java/com/stockm8/domain/vo/StockVO.java b/stockMate/src/main/java/com/stockm8/domain/vo/StockVO.java index 9b9e531..4fca4fc 100644 --- a/stockMate/src/main/java/com/stockm8/domain/vo/StockVO.java +++ b/stockMate/src/main/java/com/stockm8/domain/vo/StockVO.java @@ -22,6 +22,6 @@ public class StockVO { private ProductVO product; // 상품 정보 private CategoryVO category; // 카테고리 정보 private WarehouseVO warehouse; // 창고 정보 - private String warehouseName; + private String warehouseName; // 창고명 } diff --git a/stockMate/src/main/java/com/stockm8/persistence/StockDAO.java b/stockMate/src/main/java/com/stockm8/persistence/StockDAO.java index 07b0bcc..2891526 100644 --- a/stockMate/src/main/java/com/stockm8/persistence/StockDAO.java +++ b/stockMate/src/main/java/com/stockm8/persistence/StockDAO.java @@ -7,31 +7,18 @@ public interface StockDAO { - // 재고 등록 - public void insertStock(StockVO stock) throws Exception; + // 재고 등록 + public void insertStock(StockVO stock) throws Exception; // 필터링된 재고 목록 조회 (정렬 기준 포함) public List selectFilteredStocks(FilterCriteria criteria, String sortOrder) throws Exception; - - // 카테고리 목록 조회 - public List selectCategoryList() throws Exception; - + // 사업자 ID에 해당하는 재고 목록 조회 public List selectStockListByBusinessId(int businessId) throws Exception; - - public List selectOnlyStockByBusinessId(int businessId) throws Exception; - // 상품 ID로 상품 상세 조회 -// public ProductVO selectProductById(int productId) throws Exception; - - // 필터링된 재고 목록 조회 - public List selectFilteredStocks(String warehouseName, String categoryName, String sortOrder) throws Exception; - - // 창고 목록 조회 -// public List selectAllWarehouses() throws Exception; + // 사업자 ID에 해당하는 재고 목록 조회 (단순 조회) + public List selectOnlyStockByBusinessId(int businessId) throws Exception; // 카테고리 목록 조회 public List selectAllCategories() throws Exception; - - } diff --git a/stockMate/src/main/java/com/stockm8/persistence/StockDAOImpl.java b/stockMate/src/main/java/com/stockm8/persistence/StockDAOImpl.java index 2bfb25d..4b28ac0 100644 --- a/stockMate/src/main/java/com/stockm8/persistence/StockDAOImpl.java +++ b/stockMate/src/main/java/com/stockm8/persistence/StockDAOImpl.java @@ -1,10 +1,7 @@ package com.stockm8.persistence; import com.stockm8.domain.vo.StockVO; -import com.stockm8.domain.vo.ProductVO; -import com.stockm8.domain.vo.WarehouseVO; import com.stockm8.domain.vo.CategoryVO; -import com.stockm8.domain.vo.StockVO; import org.apache.ibatis.session.SqlSession; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -15,14 +12,6 @@ import java.util.List; import java.util.Map; -import javax.inject.Inject; - - -import org.apache.ibatis.session.SqlSession; -import org.springframework.stereotype.Repository; -import com.stockm8.domain.vo.ProductVO; -import com.stockm8.domain.vo.StockVO; - @Repository public class StockDAOImpl implements StockDAO { @@ -38,13 +27,13 @@ public class StockDAOImpl implements StockDAO { public void insertStock(StockVO stock) throws Exception { sqlSession.insert(NAMESPACE + "insertStock", stock); } - - @Override + + // 사업자 ID에 해당하는 재고 목록 조회 + @Override public List selectStockListByBusinessId(int businessId) throws Exception { return sqlSession.selectList(NAMESPACE + "selectStockListByBusinessId", businessId); } - // 필터링된 재고 목록 조회 (정렬 기준 포함) @Override public List selectFilteredStocks(FilterCriteria criteria, String sortOrder) throws Exception { @@ -56,46 +45,21 @@ public List selectFilteredStocks(FilterCriteria criteria, String sortOr // MyBatis 매퍼에 정의된 SQL 쿼리 호출 return sqlSession.selectList(NAMESPACE + "selectFilteredStocks", params); } - - // 카테고리 목록 조회 - @Override - public List selectCategoryList() throws Exception { - return sqlSession.selectList(NAMESPACE + "selectCategoryList"); // CategoryDAO에서 카테고리 목록 조회 - } - public ProductVO selectProductById(int productId) throws Exception { - return sqlSession.selectOne(NAMESPACE + "selectProductById", productId); - } - + // 사업자 ID에 해당하는 재고 목록 조회 (단순 조회) @Override - public List selectFilteredStocks(String warehouseName, String categoryName, String sortOrder) throws Exception { - Map params = new HashMap<>(); - if (warehouseName != null && !warehouseName.isEmpty()) { - params.put("warehouseName", warehouseName); - } - if (categoryName != null && !categoryName.isEmpty()) { - params.put("categoryName", categoryName); - } - params.put("sortOrder", sortOrder); - - return sqlSession.selectList(NAMESPACE + "selectFilteredStocks", params); - } - - @Override - public List selectOnlyStockByBusinessId(int businessId) throws Exception { + public List selectOnlyStockByBusinessId(int businessId) throws Exception { return sqlSession.selectList(NAMESPACE + "selectOnlyStockByBusinessId", businessId); } + // 카테고리 목록 조회 + @Override + public List selectAllCategories() throws Exception { + return sqlSession.selectList(NAMESPACE + "selectAllCategories"); + } - - @Override public List selectAllCategories() throws Exception { return sqlSession.selectList(NAMESPACE + "selectAllCategories"); } - - - - - } diff --git a/stockMate/src/main/java/com/stockm8/service/StockService.java b/stockMate/src/main/java/com/stockm8/service/StockService.java index b89db3e..8c60b6f 100644 --- a/stockMate/src/main/java/com/stockm8/service/StockService.java +++ b/stockMate/src/main/java/com/stockm8/service/StockService.java @@ -3,13 +3,10 @@ import com.stockm8.domain.vo.StockVO; import com.stockm8.domain.vo.WarehouseVO; // 추가된 VO import com.stockm8.persistence.FilterCriteria; -import com.stockm8.domain.vo.CategoryVO; // 추가된 VO +import com.stockm8.domain.vo.CategoryVO; import java.util.List; import java.util.Map; -import com.stockm8.domain.vo.ProductVO; -import com.stockm8.domain.vo.StockVO; - public interface StockService { // 재고 등록 @@ -22,15 +19,14 @@ public interface StockService { public List getStockListByBusinessId(int businessId) throws Exception; // 필터링된 재고 목록 조회 (정렬 기준 추가) - public List getStockList(FilterCriteria criteria, String sortOrder) throws Exception; // sortOrder 추가 + public List getStockList(FilterCriteria criteria, String sortOrder) throws Exception; // 카테고리 목록 조회 public List getCategoryList() throws Exception; - // 사용 가능한 재고 자동 계산 - public int calculateAvailableStock(StockVO stock) throws Exception; - - // TKDJQWK ID로 재고정보와 카테고리 정보 가져오기 + // 사업자 ID로 재고정보와 카테고리 정보 가져오기 (황인성) public Map getStockAndCategories(int businessId) throws Exception; - + + // 사용 가능한 재고 자동 계산 + // public int calculateAvailableStock(StockVO stock) throws Exception; } diff --git a/stockMate/src/main/java/com/stockm8/service/StockServiceImpl.java b/stockMate/src/main/java/com/stockm8/service/StockServiceImpl.java index b73ffab..7123dec 100644 --- a/stockMate/src/main/java/com/stockm8/service/StockServiceImpl.java +++ b/stockMate/src/main/java/com/stockm8/service/StockServiceImpl.java @@ -1,101 +1,83 @@ package com.stockm8.service; +import com.stockm8.domain.vo.StockVO; +import com.stockm8.domain.vo.WarehouseVO; +import com.stockm8.persistence.FilterCriteria; +import com.stockm8.domain.vo.CategoryVO; +import com.stockm8.persistence.StockDAO; +import com.stockm8.persistence.WarehouseDAO; +import com.stockm8.persistence.CategoryDAO; + +import java.util.HashMap; import java.util.List; import java.util.Map; import javax.inject.Inject; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import com.stockm8.domain.vo.CategoryVO; -import com.stockm8.domain.vo.StockVO; -import com.stockm8.domain.vo.WarehouseVO; -import com.stockm8.persistence.CategoryDAO; -import com.stockm8.persistence.FilterCriteria; -import com.stockm8.persistence.StockDAO; -import com.stockm8.persistence.WarehouseDAO; - @Service public class StockServiceImpl implements StockService { - @Inject - private StockDAO stockDAO; - - @Autowired - private CategoryDAO categoryDAO; - - // 재고 등록 - @Override - public void registerStock(StockVO stock) throws Exception { - stockDAO.insertStock(stock); - } - - @Inject - private WarehouseDAO warehouseDAO; - - // 사업자 ID에 해당하는 재고 목록 조회 - @Override - public List getStockListByBusinessId(int businessId) throws Exception { - return stockDAO.selectOnlyStockByBusinessId(businessId); - } - - // 상품 ID로 상품 상세 조회 -// @Override -// public ProductVO getProductById(int productId) throws Exception { -// return stockDAO.selectProductById(productId); -// } - - @Override - public List getStockList(FilterCriteria criteria, String sortOrder) throws Exception { - // TODO Auto-generated method stub - return null; - } - - @Override - public List getCategoryList() throws Exception { - // TODO Auto-generated method stub - return null; - } - - @Override - public int calculateAvailableStock(StockVO stock) throws Exception { - // TODO Auto-generated method stub - return 0; - } - - // 사업자 ID에 해당하는 창고 목록 조회 - @Override - public List getWarehousesByBusinessId(int businessId) throws Exception { - return warehouseDAO.selectWarehousesByBusinessId(businessId); - } - - public Map getStockAndCategories(int businessId) throws Exception { - // 재고 목록 조회 - List stockList = stockDAO.selectStockListByBusinessId(businessId); - return null; - } - // 필터링된 재고 목록 조회 -// @Override -// public List getStockList(FilterCriteria criteria, String sortOrder) throws Exception { -// // sortOrder를 전달하여 정렬 기준을 처리 -// return stockDAO.selectFilteredStocks(criteria, sortOrder); // StockDAO에서 필터링된 재고 목록 조회 -// } + @Inject + private StockDAO stockDAO; - // 카테고리 목록 조회 -// @Override -// public List getCategoryList() throws Exception { -// return categoryDAO.selectAllCategories(); // CategoryDAO에서 카테고리 목록 조회 -// } -// // 카테고리 목록은 CategoryService를 통해 가져오기 -// List categoryList = categoryDAO.selectCategoriesByBusinessId(businessId); -// -// // 결과를 Map에 담아서 반환 -// Map result = new HashMap<>(); -// result.put("stockList", stockList); -// result.put("categoryList", categoryList); -// -// return result; -// } + @Inject + private WarehouseDAO warehouseDAO; + + @Inject + private CategoryDAO categoryDAO; + + // 재고 등록 + @Override + public void registerStock(StockVO stock) throws Exception { + stockDAO.insertStock(stock); + } + // 사업자 ID에 해당하는 창고 목록 조회 + @Override + public List getWarehousesByBusinessId(int businessId) throws Exception { + return warehouseDAO.selectWarehousesByBusinessId(businessId); // WarehouseDAO에서 창고 목록 조회 + } + + // 사업자 ID에 해당하는 재고 목록 조회 + @Override + public List getStockListByBusinessId(int businessId) throws Exception { + return stockDAO.selectOnlyStockByBusinessId(businessId); + } + + // 필터링된 재고 목록 조회 (정렬 기준 추가) + @Override + public List getStockList(FilterCriteria criteria, String sortOrder) throws Exception { + return stockDAO.selectFilteredStocks(criteria, sortOrder); // StockDAO에서 필터링된 재고 목록 조회 + } + + // 카테고리 목록 조회 + @Override + public List getCategoryList() throws Exception { + return categoryDAO.selectAllCategories(); // CategoryDAO에서 카테고리 목록 조회 + } + + // 사업자 ID로 재고정보와 카테고리 정보 가져오기 + @Override + public Map getStockAndCategories(int businessId) throws Exception { + // 재고 목록 조회 + List stockList = stockDAO.selectStockListByBusinessId(businessId); + // 카테고리 목록 조회 + List categoryList = categoryDAO.selectCategoriesByBusinessId(businessId); + + // 결과를 Map에 담아서 반환 + Map result = new HashMap<>(); + result.put("stockList", stockList); + result.put("categoryList", categoryList); + + return result; + } + + // 사용 가능한 재고 자동 계산 (주석 처리) + // @Override + // public int calculateAvailableStock(StockVO stock) throws Exception { + // // DB에서 available stock을 자동으로 계산하는 방식이므로 이 메서드는 필요하지 않음. + // return 0; // 구현을 필요로 할 경우 로직 추가 + // } } \ No newline at end of file diff --git a/stockMate/src/main/resources/mappers/stockMapper.xml b/stockMate/src/main/resources/mappers/stockMapper.xml index 865ce24..62a0601 100644 --- a/stockMate/src/main/resources/mappers/stockMapper.xml +++ b/stockMate/src/main/resources/mappers/stockMapper.xml @@ -5,6 +5,29 @@ + + + + + + + + + + + + + + + + + + + + + + + @@ -20,53 +43,23 @@ - - - - - + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + - + INSERT INTO stocks ( product_id, @@ -135,55 +128,33 @@ ) - - - + + - SELECT category_id AS categoryId, category_name AS categoryName, @@ -210,7 +181,5 @@ FROM test_warehouses WHERE business_id = #{businessId} AND is_deleted = 0 - - \ No newline at end of file diff --git a/stockMate/src/main/webapp/WEB-INF/views/stock/list.jsp b/stockMate/src/main/webapp/WEB-INF/views/stock/list.jsp index 4826b65..51fb785 100644 --- a/stockMate/src/main/webapp/WEB-INF/views/stock/list.jsp +++ b/stockMate/src/main/webapp/WEB-INF/views/stock/list.jsp @@ -5,143 +5,70 @@ - -재고 리스트 - + .container { + max-width: 1200px; + margin: 0 auto; + padding: 20px; + } +
@@ -166,12 +93,15 @@ + - - ${stock.product.productName} - - N/A - + + + ${stock.product.productName} + + + N/A + ${stock.product != null ? stock.product.productBarcode : 'N/A'} ${stock.category != null ? stock.category.categoryName : 'N/A'} @@ -215,4 +145,4 @@
- + \ No newline at end of file diff --git a/stockMate/src/main/webapp/WEB-INF/views/stock/list2.jsp b/stockMate/src/main/webapp/WEB-INF/views/stock/list2.jsp deleted file mode 100644 index dacf3ae..0000000 --- a/stockMate/src/main/webapp/WEB-INF/views/stock/list2.jsp +++ /dev/null @@ -1,118 +0,0 @@ -<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> -<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> - - - - - -재고 리스트 - - - - -

재고 리스트

- - -
- - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
상품명바코드창고명카테고리명재고 수량상태정보마지막 수정일비고
- ${stock.productName} - ${stock.barcode}${stock.warehouseName}${stock.categoryName} - - ${stock.availableStock} - - - ${stock.availableStock} - - ${stock.statusInfo}${stock.updatedAt}${stock.description}
- - - - - -
- - -
-
-
-
- - - \ No newline at end of file diff --git a/stockMate/src/main/webapp/WEB-INF/views/stock/registerDropdown.jsp b/stockMate/src/main/webapp/WEB-INF/views/stock/registerDropdown.jsp deleted file mode 100644 index fca93e7..0000000 --- a/stockMate/src/main/webapp/WEB-INF/views/stock/registerDropdown.jsp +++ /dev/null @@ -1,127 +0,0 @@ -<%@ page language="java" contentType="text/html; charset=UTF-8" - pageEncoding="UTF-8"%> -<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> - - - - -재고 등록 - - - - - - - -
- -

재고 등록

-
- - - - - - - - - - - - - - - - - -
-
- - - -