Skip to content

Commit

Permalink
Merge pull request #159 from in27sung/stock_03
Browse files Browse the repository at this point in the history
Stock 03
  • Loading branch information
mingming-01 authored Dec 16, 2024
2 parents c7d6bcb + 7427145 commit 9154364
Show file tree
Hide file tree
Showing 10 changed files with 267 additions and 703 deletions.
145 changes: 63 additions & 82 deletions stockMate/src/main/java/com/stockm8/controller/StockController.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,78 +3,63 @@
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;

@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();
Expand All @@ -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<WarehouseVO> 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<StockVO> 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<WarehouseVO> 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<StockVO> 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";
}

}
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 @@ -22,6 +22,6 @@ public class StockVO {
private ProductVO product; // 상품 정보
private CategoryVO category; // 카테고리 정보
private WarehouseVO warehouse; // 창고 정보
private String warehouseName;
private String warehouseName; // 창고명

}
23 changes: 5 additions & 18 deletions stockMate/src/main/java/com/stockm8/persistence/StockDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,18 @@

public interface StockDAO {

// 재고 등록
public void insertStock(StockVO stock) throws Exception;
// 재고 등록
public void insertStock(StockVO stock) throws Exception;

// 필터링된 재고 목록 조회 (정렬 기준 포함)
public List<StockVO> selectFilteredStocks(FilterCriteria criteria, String sortOrder) throws Exception;

// 카테고리 목록 조회
public List<CategoryVO> selectCategoryList() throws Exception;


// 사업자 ID에 해당하는 재고 목록 조회
public List<StockVO> selectStockListByBusinessId(int businessId) throws Exception;

public List<StockVO> selectOnlyStockByBusinessId(int businessId) throws Exception;

// 상품 ID로 상품 상세 조회
// public ProductVO selectProductById(int productId) throws Exception;

// 필터링된 재고 목록 조회
public List<StockVO> selectFilteredStocks(String warehouseName, String categoryName, String sortOrder) throws Exception;

// 창고 목록 조회
// public List<WarehouseVO> selectAllWarehouses() throws Exception;
// 사업자 ID에 해당하는 재고 목록 조회 (단순 조회)
public List<StockVO> selectOnlyStockByBusinessId(int businessId) throws Exception;

// 카테고리 목록 조회
public List<CategoryVO> selectAllCategories() throws Exception;


}
56 changes: 10 additions & 46 deletions stockMate/src/main/java/com/stockm8/persistence/StockDAOImpl.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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 {

Expand All @@ -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<StockVO> selectStockListByBusinessId(int businessId) throws Exception {
return sqlSession.selectList(NAMESPACE + "selectStockListByBusinessId", businessId);
}


// 필터링된 재고 목록 조회 (정렬 기준 포함)
@Override
public List<StockVO> selectFilteredStocks(FilterCriteria criteria, String sortOrder) throws Exception {
Expand All @@ -56,46 +45,21 @@ public List<StockVO> selectFilteredStocks(FilterCriteria criteria, String sortOr
// MyBatis 매퍼에 정의된 SQL 쿼리 호출
return sqlSession.selectList(NAMESPACE + "selectFilteredStocks", params);
}

// 카테고리 목록 조회
@Override
public List<CategoryVO> 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<StockVO> selectFilteredStocks(String warehouseName, String categoryName, String sortOrder) throws Exception {
Map<String, Object> 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<StockVO> selectOnlyStockByBusinessId(int businessId) throws Exception {
public List<StockVO> selectOnlyStockByBusinessId(int businessId) throws Exception {
return sqlSession.selectList(NAMESPACE + "selectOnlyStockByBusinessId", businessId);
}
// 카테고리 목록 조회
@Override
public List<CategoryVO> selectAllCategories() throws Exception {
return sqlSession.selectList(NAMESPACE + "selectAllCategories");
}



@Override
public List<CategoryVO> selectAllCategories() throws Exception {
return sqlSession.selectList(NAMESPACE + "selectAllCategories");
}





}

16 changes: 6 additions & 10 deletions stockMate/src/main/java/com/stockm8/service/StockService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

// 재고 등록
Expand All @@ -22,15 +19,14 @@ public interface StockService {
public List<StockVO> getStockListByBusinessId(int businessId) throws Exception;

// 필터링된 재고 목록 조회 (정렬 기준 추가)
public List<StockVO> getStockList(FilterCriteria criteria, String sortOrder) throws Exception; // sortOrder 추가
public List<StockVO> getStockList(FilterCriteria criteria, String sortOrder) throws Exception;

// 카테고리 목록 조회
public List<CategoryVO> getCategoryList() throws Exception;

// 사용 가능한 재고 자동 계산
public int calculateAvailableStock(StockVO stock) throws Exception;

// TKDJQWK ID로 재고정보와 카테고리 정보 가져오기
// 사업자 ID로 재고정보와 카테고리 정보 가져오기 (황인성)
public Map<String, Object> getStockAndCategories(int businessId) throws Exception;


// 사용 가능한 재고 자동 계산
// public int calculateAvailableStock(StockVO stock) throws Exception;
}
Loading

0 comments on commit 9154364

Please sign in to comment.