diff --git a/stockMate/src/main/java/com/stockm8/config/GlobalExceptionHandler.java b/stockMate/src/main/java/com/stockm8/config/GlobalExceptionHandler.java index c9c107e..c997be3 100644 --- a/stockMate/src/main/java/com/stockm8/config/GlobalExceptionHandler.java +++ b/stockMate/src/main/java/com/stockm8/config/GlobalExceptionHandler.java @@ -33,4 +33,4 @@ public String handleException( String referer = request.getHeader("Referer"); // 이전 페이지로 이동 return "redirect:" + (referer != null ? referer : "/"); } -} \ No newline at end of file +} diff --git a/stockMate/src/main/java/com/stockm8/config/WebConfig.java b/stockMate/src/main/java/com/stockm8/config/WebConfig.java index 23d0f04..6e1d459 100644 --- a/stockMate/src/main/java/com/stockm8/config/WebConfig.java +++ b/stockMate/src/main/java/com/stockm8/config/WebConfig.java @@ -47,7 +47,7 @@ public class WebConfig implements WebMvcConfigurer { public void addInterceptors(InterceptorRegistry registry) { // Intercepter 적용 registry.addInterceptor(authorizationInterceptor) - .addPathPatterns("/product/**") // 인터셉터를 적용할 경로 + .addPathPatterns("/product/**", "/category/**") // 인터셉터를 적용할 경로 .excludePathPatterns( // 인터셉터를 제외할 경로 "/", // HomeController 경로 "/favicon.ico", // 브라우저 기본 요청 diff --git a/stockMate/src/main/java/com/stockm8/controller/CategoryController.java b/stockMate/src/main/java/com/stockm8/controller/CategoryController.java index d1b7bb4..02d650b 100644 --- a/stockMate/src/main/java/com/stockm8/controller/CategoryController.java +++ b/stockMate/src/main/java/com/stockm8/controller/CategoryController.java @@ -3,7 +3,11 @@ 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.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.ModelAttribute; @@ -12,21 +16,41 @@ import org.springframework.web.bind.annotation.RequestParam; import com.stockm8.domain.vo.CategoryVO; +import com.stockm8.domain.vo.UserVO; import com.stockm8.service.CategoryService; +import com.stockm8.service.UserService; @Controller @RequestMapping("/category") public class CategoryController { + + private static final Logger logger = LoggerFactory.getLogger(CategoryController.class); @Inject - private CategoryService cService; + private CategoryService categoryService; + @Inject + private UserService userService; + + // http://localhost:8088/category/register // 카테고리 등록 페이지 호출 (GET) @RequestMapping(value = "/register", method = RequestMethod.GET) - public String registerCategoryGET(Model model) throws Exception { + public String registerCategoryGET(Model model, HttpServletRequest request) throws Exception { + logger.info("registerCategoryGET(Model model, HttpServletRequest request) 호출"); + // 세션에서 userId 가져오기 + HttpSession session = request.getSession(false); + Long userId = (session != null) ? (Long)session.getAttribute("userId") : null; + logger.info("session: {}", userId); + + // userId로 사용자 정보 조회 + UserVO user = userService.getUserById(userId); + int businessId = user.getBusinessId(); + logger.info("businessId: {}", businessId); + // 필요한 데이터 (예: 상위 카테고리 목록 등) 전달 - List parentCategories = cService.getAllCategories(); - model.addAttribute("parentCategories", parentCategories); + List categoryList = categoryService.getCategoriesByBusinessId(businessId); + model.addAttribute("categoryList", categoryList); + logger.info("Category List: {}", categoryList); // 카테고리 등록 폼을 보여주는 페이지로 이동 return "category/register"; @@ -34,19 +58,33 @@ public String registerCategoryGET(Model model) throws Exception { // 카테고리 등록 처리 (POST) @RequestMapping(value = "/register", method = RequestMethod.POST) - public String registerCategoryPOST(CategoryVO vo) throws Exception { + public String registerCategoryPOST(CategoryVO category, HttpServletRequest request) throws Exception { + logger.info("registerCategoryPOST(CategoryVO category, HttpServletRequest request) 실행"); + + logger.info(category+""); + // 세션에서 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(); + category.setBusinessId(businessId); + // 서비스 호출: 부모 카테고리 체크와 카테고리 등록을 서비스에서 처리 - cService.registerCategoryWithParentCheck(vo); + categoryService.registerCategoryWithParentCheck(category); // 등록 후 목록 페이지로 리다이렉트 return "redirect:/category/list"; } - + + // http://localhost:8088/category/list // 카테고리 목록 페이지 호출 (GET) @RequestMapping(value = "/list", method = RequestMethod.GET) public String listCategoryGET(Model model) throws Exception { + logger.info("listCategoryGET(Model model) 호출"); // 카테고리 목록 조회 - List categories = cService.getAllCategories(); + List categories = categoryService.getAllCategories(); // JSP로 데이터 전달 model.addAttribute("categories", categories); @@ -56,31 +94,41 @@ public String listCategoryGET(Model model) throws Exception { // 카테고리 수정 페이지 (GET) @RequestMapping(value = "/edit", method = RequestMethod.GET) public String editCategoryGET(@RequestParam("categoryId") int categoryId, Model model) throws Exception { - // 카테고리와 상위 카테고리 정보 가져오기 - CategoryVO category = cService.getCategoryWithParents(categoryId); - model.addAttribute("category", category); - - // 상위 카테고리 정보 - if (category.getParentId() != null) { - CategoryVO parentCategory = cService.getCategoryWithParents(category.getParentId()); - model.addAttribute("parentCategory", parentCategory); - } + logger.info("editCategoryGET(@RequestParam(\"categoryId\") int categoryId, Model model) 호출"); + + // 카테고리와 상위 카테고리 정보 가져오기 + CategoryVO vo = categoryService.getCategoryWithParents(categoryId); + model.addAttribute("category", vo); + + // 상위 카테고리 정보 (부모 카테고리 리스트 가져오기) + List parentCategories = categoryService.getParentCategories(); // 부모 카테고리 리스트를 가져오기 + model.addAttribute("parentCategories", parentCategories); return "category/edit"; } // 카테고리 수정 처리 (POST) @RequestMapping(value = "/edit", method = RequestMethod.POST) - public String editCategoryPOST(@ModelAttribute CategoryVO vo) throws Exception { - cService.updateCategory(vo); - return "redirect:/category/list"; + public String editCategoryPOST(@ModelAttribute CategoryVO category) throws Exception { + logger.info("editCategoryPOST(@ModelAttribute CategoryVO vo) 실행"); + + // 부모 카테고리가 비어 있으면 null로 처리 + if (category.getParentId() != null && category.getParentId().equals("")) { + category.setParentId(null); + logger.info("부모 카테고리가 비어있어 null로 설정됨, categoryId: {}", category.getCategoryId()); + } + // 카테고리 수정 + categoryService.updateCategory(category); + logger.info("카테고리 수정 완료, categoryId: {}", category.getCategoryId()); + + return "redirect:/category/list"; // 수정 후 목록 페이지로 리다이렉트 } // 카테고리 삭제 페이지 (GET) @RequestMapping(value = "/delete", method = RequestMethod.GET) public String deleteCategoryGET(@RequestParam("categoryId") int categoryId, Model model) throws Exception { // 삭제할 카테고리 정보 가져오기 - CategoryVO category = cService.getCategoryWithParents(categoryId); + CategoryVO category = categoryService.getCategoryWithParents(categoryId); model.addAttribute("category", category); return "category/delete"; @@ -90,7 +138,7 @@ public String deleteCategoryGET(@RequestParam("categoryId") int categoryId, Mode @RequestMapping(value = "/delete", method = RequestMethod.POST) public String deleteCategoryPOST(@RequestParam("categoryId") int categoryId) throws Exception { // 카테고리 삭제 처리 - cService.deleteCategory(categoryId); + categoryService.deleteCategory(categoryId); return "redirect:/category/list"; } diff --git a/stockMate/src/main/java/com/stockm8/controller/UserController.java b/stockMate/src/main/java/com/stockm8/controller/UserController.java index 9125cad..e31cec8 100644 --- a/stockMate/src/main/java/com/stockm8/controller/UserController.java +++ b/stockMate/src/main/java/com/stockm8/controller/UserController.java @@ -34,12 +34,16 @@ public class UserController { @Autowired private UserService userService; - // http://localhost:8088/user/login (o) + // http://localhost:8088/user/signin (o) // http://localhost:8088/user/main (o) // http://localhost:8088/user/signup (o) - // http://localhost:8088/user/dash (o) + // http://localhost:8088/user/dashboard (o) // http://localhost:8088/user/info1 (o) // http://localhost:8088/user/info2 (o) + // http://localhost:8088/user/editinfo1 (o) + // http://localhost:8088/user/editinfo2 (o) + // http://localhost:8088/user/consultation (o) + // http://localhost:8088/user/changepassword1 (o) // 회원가입 - 정보입력 / GET 방식 @RequestMapping(value = "/signup", method = RequestMethod.GET) @@ -58,13 +62,13 @@ public String userSignUpPOST(/* @ModelAttribute */ UserVO user) throws Exception logger.info("Role received: " + user.getRole()); // 전달정보 저장 -// logger.info("vo :" + user); + logger.info("vo :" + user); // userDAO객체가 필요 => 주입 // DB에 정보를 전달 - 회원가입동작 실행 // mdao.userJoin(vo); // => 잘못됨 // 서비스 -> DAO 호출 -// userService.userJoin(user); + userService.userJoin(user); // 로그인 페이지로 이동 return "redirect:/user/signin"; @@ -115,7 +119,7 @@ public String userLoginPOST(UserVO user, RedirectAttributes rttr, HttpSession se session.removeAttribute("redirectAfterLogin"); // 세션에서 URL 삭제 return "redirect:" + redirectUrl; } - return "redirect:/user/main"; + return "redirect:/user/dash"; } // 로그인 실패 처리 @@ -133,7 +137,7 @@ public void mainGET() throws Exception { } // 대시보드 페이지 - GET - @RequestMapping(value = "/dash", method = RequestMethod.GET) + @RequestMapping(value = "/dashboard", method = RequestMethod.GET) public void dashGET() { logger.info(" dashGET() 호출 "); @@ -165,7 +169,18 @@ public String userInfo1GET(Model model, HttpSession session) throws Exception { model.addAttribute("resultVO", resultVO); return "user/info1"; } - + // 회원정보 조회 - /user/info1 (GET) + @RequestMapping(value = "/info2", method = RequestMethod.GET) + public String userInfo2GET(Model model, HttpSession session) throws Exception { + Long userId = (Long) session.getAttribute("id"); +// if (id == null) { +// // 세션에 id가 없으면 에러 처리 +// return "redirect:/user/main"; +// } + UserVO resultVO = userService.getUser(userId); + model.addAttribute("resultVO", resultVO); + return "user/info2"; + } @@ -187,40 +202,109 @@ public String userInfo1GET(Model model, HttpSession session) throws Exception { // } // - // 회원정보 수정 - GET - // (기존정보를 가져와서 보여주고, 수정할 정보를 입력) - @RequestMapping(value = "/editInfo1", method = RequestMethod.GET) - public void userUpdateGET(@SessionAttribute("id") Long userId, Model model) throws Exception { - logger.info(" userUpdateGET() 호출 "); - - // 사용자의 ID정보를 가져오기(세션) - logger.info("id : " + userId); - - // 서비스 -> DAO 회원정보 가져오는 동작 호출 - UserVO resultVO = userService.getUser(userId); - - // 연결된 뷰페이지에 출력 - // => model 객체에 정보 저장 - model.addAttribute("resultVO", resultVO); - // /user/update.jsp 뷰페이지 연결 - } - - // 회원정보 수정 - POST - // (수정된 정보를 전달받아서 정보 수정) - @RequestMapping(value = "/editInfo2", method = RequestMethod.POST) - public String userUpdatePOST(UserVO user) throws Exception { - logger.info(" userUpdatePOST() "); - - // 전달정보(수정정보) 저장 - logger.info("vo : " + user); - - // 서비스 -> DAO 호출 (회원정보 수정) - userService.updateUser(user); + // 회원정보 수정 - /user/info1 (GET) + @RequestMapping(value = "/editinfo1", method = RequestMethod.GET) + public String usereditinfo1GET(Model model, HttpSession session) throws Exception { + Long userId = (Long) session.getAttribute("id"); +// if (id == null) { +// // 세션에 id가 없으면 에러 처리 +// return "redirect:/user/main"; +// } + UserVO resultVO = userService.getUser(userId); + model.addAttribute("resultVO", resultVO); + return "user/editinfo1"; + } + // 회원정보 수정 - /user/info1 (GET) + @RequestMapping(value = "/editinfo2", method = RequestMethod.POST) + public String usereditinfo2GET(Model model, HttpSession session) throws Exception { + + + logger.info("ㅇㄻ니"); + Long userId = (Long) session.getAttribute("id"); +// if (id == null) { +// // 세션에 id가 없으면 에러 처리 +// return "redirect:/user/main"; +// } + UserVO resultVO = userService.getUser(userId); + model.addAttribute("resultVO", resultVO); + return "/user/editinfo2"; + } + + + + // 비밀번호 찾기 - get + @RequestMapping(value = "/findPassword", method = RequestMethod.GET) + public String findPasswordGet() { - // 수정완료시 메인페이지로 이동 - return "redirect:/user/dash"; - } + return "/user/findPassword"; + } + + +// // 회원정보 수정 - GET +// // (기존정보를 가져와서 보여주고, 수정할 정보를 입력) +// @RequestMapping(value = "/editinfo1", method = RequestMethod.GET) +// public void userUpdateGET(@SessionAttribute("userId") Long userId, Model model) throws Exception { +// logger.info(" userUpdateGET() 호출 "); +// +// // 사용자의 ID정보를 가져오기(세션) +// logger.info("userId : " + userId); +// +// // 서비스 -> DAO 회원정보 가져오는 동작 호출 +// UserVO resultVO = userService.getUser(userId); +// +// // 연결된 뷰페이지에 출력 +// // => model 객체에 정보 저장 +// model.addAttribute("resultVO", resultVO); +// // /user/update.jsp 뷰페이지 연결 +// } +// +// // 회원정보 수정 - POST +// // (수정된 정보를 전달받아서 정보 수정) +// @RequestMapping(value = "/editinfo2", method = RequestMethod.POST) +// public String userUpdatePOST(UserVO user) throws Exception { +// logger.info(" userUpdatePOST() "); +// +// // 전달정보(수정정보) 저장 +// logger.info("vo : " + user); +// +// // 서비스 -> DAO 호출 (회원정보 수정) +// userService.updateUser(user); +// +// // 수정완료시 메인페이지로 이동 +// return "redirect:/dashboard"; +// } + // 대시보드 사용법 - /user/consultation (GET) + @RequestMapping(value = "/consultation", method = RequestMethod.GET) + public String consultationGET(Model model, HttpSession session) throws Exception { + Long userId = (Long) session.getAttribute("id"); +// if (id == null) { +// // 세션에 id가 없으면 에러 처리 +// return "redirect:/user/main"; +// } + UserVO resultVO = userService.getUser(userId); + model.addAttribute("resultVO", resultVO); + return "user/consultation"; + } + + // 비밀번호 변경 - /user/changepassword1 (GET) + @RequestMapping(value = "/changepassword1", method = RequestMethod.GET) + public String changepassword1GET(Model model, HttpSession session) throws Exception { + Long userId = (Long) session.getAttribute("id"); +// if (id == null) { +// // 세션에 id가 없으면 에러 처리 +// return "redirect:/user/main"; +// } + UserVO resultVO = userService.getUser(userId); + model.addAttribute("resultVO", resultVO); + return "user/changepassword1"; + } + + + + + + // 회원정보 삭제 - 비밀번호 입력 (GET) @RequestMapping(value = "/delete", method = RequestMethod.GET) public String userDeleteGET() throws Exception { diff --git a/stockMate/src/main/java/com/stockm8/domain/vo/CategoryVO.java b/stockMate/src/main/java/com/stockm8/domain/vo/CategoryVO.java index e4cc44a..29d8e36 100644 --- a/stockMate/src/main/java/com/stockm8/domain/vo/CategoryVO.java +++ b/stockMate/src/main/java/com/stockm8/domain/vo/CategoryVO.java @@ -6,23 +6,15 @@ @Data public class CategoryVO { - private int categoryId; // 카테고리 고유 ID + private int categoryId; // 카테고리 고유 ID private Integer parentId; // 상위 카테고리 ID (NULL이면 대분류) - private int businessId; // 사업자 ID + private Integer businessId; // 사업자 ID (null 가능) private String categoryName; // 카테고리 이름 private int level; // 카테고리 계층 수준 (1=대분류, 2=소분류) private Timestamp createdAt; // 카테고리 생성 일자 private Timestamp updatedAt; // 카테고리 수정 일자 private Boolean isDeleted; // 논리 삭제 여부 (true: 삭제됨, false: 활성) - // Getter와 Setter 메서드 추가 - public Boolean getIsDeleted() { - return isDeleted; - } - - public void setIsDeleted(Boolean isDeleted) { - this.isDeleted = isDeleted; - } - - // 다른 Getter/Setter와 필드들 + // Getter와 Setter 메서드 (자동 생성되는 @Data에 의해 생략됨) + } diff --git a/stockMate/src/main/java/com/stockm8/persistence/CategoryDAO.java b/stockMate/src/main/java/com/stockm8/persistence/CategoryDAO.java index 82c558a..420f8ec 100644 --- a/stockMate/src/main/java/com/stockm8/persistence/CategoryDAO.java +++ b/stockMate/src/main/java/com/stockm8/persistence/CategoryDAO.java @@ -13,16 +13,22 @@ public interface CategoryDAO { // 카테고리 목록 조회 public List selectAllCategories() throws Exception; - + // 특정 사업자(businessId) 소속의 카테고리 목록 조회 public List selectCategoriesByBusinessId(@Param("businessId") int businessId) throws Exception; - + // 카테고리명 조회 public String selectCategoryNameById(int categoryId) throws Exception; + + // 카테고리 이름 중복 체크 + public int selectCategoryCountByName(String categoryName) throws Exception; + // 하위 카테고리들의 부모 ID를 갱신하는 메서드 + public void updateSubCategoryParentId(int parentId, int categoryId) throws Exception; + // 카테고리 존재 여부 확인 public boolean existsById(@Param("categoryId") int categoryId, @Param("businessId") int businessId); - + // 카테고리 수정 public void updateCategory(CategoryVO vo) throws Exception; @@ -32,5 +38,6 @@ public interface CategoryDAO { // 카테고리 논리 삭제 처리 public void deleteCategory(@Param("categoryId") int categoryId) throws Exception; + // 부모 카테고리만 조회 public List selectParentCategories() throws Exception; } diff --git a/stockMate/src/main/java/com/stockm8/persistence/CategoryDAOImpl.java b/stockMate/src/main/java/com/stockm8/persistence/CategoryDAOImpl.java index 2556174..26b50cc 100644 --- a/stockMate/src/main/java/com/stockm8/persistence/CategoryDAOImpl.java +++ b/stockMate/src/main/java/com/stockm8/persistence/CategoryDAOImpl.java @@ -21,8 +21,8 @@ public class CategoryDAOImpl implements CategoryDAO { // 카테고리 등록 @Override - public void insertCategory(CategoryVO category) throws Exception { - sqlSession.insert(NAMESPACE + "insertCategory", category); + public void insertCategory(CategoryVO vo) throws Exception { + sqlSession.insert(NAMESPACE + "insertCategory", vo); } // 카테고리 목록 조회 (삭제되지 않은 카테고리만 조회) @@ -43,6 +43,22 @@ public String selectCategoryNameById(int categoryId) throws Exception { return sqlSession.selectOne(NAMESPACE + "selectCategoryNameById", categoryId); } + // 카테고리 이름 중복 체크 + @Override + public int selectCategoryCountByName(String categoryName) throws Exception { + // SQL 쿼리 실행 + return sqlSession.selectOne(NAMESPACE + "selectCategoryCountByName", categoryName); + } + + // 하위 카테고리들의 부모 ID를 갱신하는 메서드 + public void updateSubCategoryParentId(int parentId, int categoryId) throws Exception { + Map params = new HashMap<>(); + params.put("parentId", parentId); + params.put("categoryId", categoryId); + + sqlSession.update(NAMESPACE + "updateSubCategoryParentId", params); + } + // 카테고리 존재 여부 확인 @Override public boolean existsById(int categoryId, int businessId) { @@ -72,6 +88,7 @@ public void deleteCategory(int categoryId) throws Exception { sqlSession.update(NAMESPACE + "deleteCategory", categoryId); } + // 부모 카테고리만 조회 @Override public List selectParentCategories() throws Exception { return sqlSession.selectList(NAMESPACE + "selectParentCategories"); diff --git a/stockMate/src/main/java/com/stockm8/persistence/UserDAOImpl.java b/stockMate/src/main/java/com/stockm8/persistence/UserDAOImpl.java index 637b07a..eed164f 100644 --- a/stockMate/src/main/java/com/stockm8/persistence/UserDAOImpl.java +++ b/stockMate/src/main/java/com/stockm8/persistence/UserDAOImpl.java @@ -62,16 +62,16 @@ public List getUserList() { } @Override - public int getIsDeleted(Long user) throws Exception{ + public int getIsDeleted(Long userId) throws Exception{ logger.info("getIsDeleted(Long userId) 실행"); - return sqlSession.selectOne(NAMESPACE + "getIsDeleted", user); + return sqlSession.selectOne(NAMESPACE + "getIsDeleted", userId); } @Override - public UserVO getUserById(Long user) throws Exception { - return sqlSession.selectOne(NAMESPACE + "getUserById", user); + public UserVO getUserById(Long userId) throws Exception { + return sqlSession.selectOne(NAMESPACE + "getUserById", userId); } } diff --git a/stockMate/src/main/java/com/stockm8/service/CategoryService.java b/stockMate/src/main/java/com/stockm8/service/CategoryService.java index cb441bd..ec7d70b 100644 --- a/stockMate/src/main/java/com/stockm8/service/CategoryService.java +++ b/stockMate/src/main/java/com/stockm8/service/CategoryService.java @@ -7,10 +7,10 @@ public interface CategoryService { // 카테고리 등록 - public void addCategory(CategoryVO vo) throws Exception; + public void addCategory(CategoryVO category) throws Exception; // 부모 카테고리 체크 후 카테고리 등록 (새 부모 카테고리 추가 여부 확인) - public void registerCategoryWithParentCheck(CategoryVO vo) throws Exception; + public void registerCategoryWithParentCheck(CategoryVO category) throws Exception; // 카테고리와 상위 카테고리 목록 조회 public CategoryVO getCategoryWithParents(int categoryId) throws Exception; @@ -18,18 +18,23 @@ public interface CategoryService { // 카테고리 목록 조회 public List getAllCategories() throws Exception; + // 부모 카테고리 조회 + public List getParentCategories() throws Exception; + + // 카테고리 이름 중복 체크 + public boolean checkCategoryNameExists(String categoryName) throws Exception; + // 특정 사업자(businessId) 소속의 카테고리 목록을 조회 public List getCategoriesByBusinessId(int businessId) throws Exception; // 카테고리ID로 카테고리명 조회 public void getCategoryNameById(int categoryId) throws Exception; - // 카테고리 수정 - public void updateCategory(CategoryVO vo) throws Exception; + // 카테고리 수정 + public void updateCategory(CategoryVO category) throws Exception; // 카테고리 삭제 public void deleteCategory(int categoryId) throws Exception; - public List getParentCategories() throws Exception; } diff --git a/stockMate/src/main/java/com/stockm8/service/CategoryServiceImpl.java b/stockMate/src/main/java/com/stockm8/service/CategoryServiceImpl.java index e5614a3..d8c3a81 100644 --- a/stockMate/src/main/java/com/stockm8/service/CategoryServiceImpl.java +++ b/stockMate/src/main/java/com/stockm8/service/CategoryServiceImpl.java @@ -5,6 +5,8 @@ import javax.inject.Inject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; import com.stockm8.domain.vo.CategoryVO; @@ -12,93 +14,134 @@ @Service public class CategoryServiceImpl implements CategoryService { - + + private static final Logger logger = LoggerFactory.getLogger(CategoryServiceImpl.class); + @Inject private CategoryDAO categoryDAO; - + + // 카테고리 등록 @Override public void addCategory(CategoryVO category) throws Exception { - System.out.println(" 카테고리 등록 실행 "); - - // 기본 businessId 설정 - category.setBusinessId(1); + logger.info("CategoryVO 내용: {}", category); + + // category가 null일 경우 예외 처리 + if (category == null) { + throw new IllegalArgumentException("CategoryVO 객체는 null일 수 없습니다."); + } + + logger.info("카테고리 등록 실행"); + + // 카테고리 이름 중복 체크 + if (checkCategoryNameExists(category.getCategoryName())) { + throw new IllegalArgumentException("이미 존재하는 카테고리 이름입니다."); + } + + // businessId가 null이라면 예외 처리 (필수 값) + if (category.getBusinessId() == null) { + throw new IllegalArgumentException("businessId는 null일 수 없습니다."); + } - // 상위 카테고리가 없으면 대분류, 있으면 소분류로 설정 + // parentId에 따라 레벨 지정 if (category.getParentId() == null) { - category.setLevel(1); // 대분류 + // 상위 카테고리가 없으므로 대분류로 설정 + category.setLevel(1); } else { - category.setLevel(2); // 소분류 + // 상위 카테고리가 존재하면 해당 상위 카테고리의 레벨을 기반으로 설정 + CategoryVO parentCategory = categoryDAO.selectCategoryById(category.getParentId()); + if (parentCategory == null) { + throw new IllegalArgumentException("존재하지 않는 상위 카테고리 ID입니다."); + } + category.setLevel(parentCategory.getLevel() + 1); // 상위 레벨 + 1 } - // 현재 시간을 생성 시간으로 설정 - category.setCreatedAt(new Timestamp(System.currentTimeMillis())); + // createdAt 설정 + if (category.getCreatedAt() == null) { + category.setCreatedAt(new Timestamp(System.currentTimeMillis())); + } - System.out.println(" DAO의 카테고리 등록 메서드 호출"); - categoryDAO.insertCategory(category); + // DAO의 insertCategory 호출 + categoryDAO.insertCategory(category); // 카테고리 등록 후 categoryId가 설정됨 + logger.info("카테고리 등록 후 Category ID: " + category.getCategoryId()); // 추가 로그로 categoryId 확인 } - + + // 카테고리 목록 조회 @Override public List getAllCategories() throws Exception { - System.out.println(" getAllCategories() 호출 "); + logger.info(" getAllCategories() 호출 "); return categoryDAO.selectAllCategories(); } - + + // 카테고리 이름 중복체크 + @Override + public boolean checkCategoryNameExists(String categoryName) throws Exception { + // 카테고리 이름 중복 체크 + int count = categoryDAO.selectCategoryCountByName(categoryName); + return count > 0; + } + + // 카테고리 수정 @Override public void updateCategory(CategoryVO category) throws Exception { - // 카테고리 수정 + category.setUpdatedAt(new Timestamp(System.currentTimeMillis())); categoryDAO.updateCategory(category); } - + + // 카테고리 및 상위 카테고리 정보 조회 @Override - public CategoryVO getCategoryWithParents(int cId) throws Exception { + public CategoryVO getCategoryWithParents(int categoryId) throws Exception { // 카테고리 정보 조회 - CategoryVO category = categoryDAO.selectCategoryById(cId); + CategoryVO category = categoryDAO.selectCategoryById(categoryId); - // 상위 카테고리 조회 - CategoryVO parentCategory = null; + // parentId가 null이면 부모 카테고리로 처리 if (category.getParentId() != null) { - parentCategory = categoryDAO.selectCategoryById(category.getParentId()); + CategoryVO parentCategory = categoryDAO.selectCategoryById(category.getParentId()); + if (parentCategory != null) { + category.setLevel(parentCategory.getLevel() + 1); // 부모 레벨 + 1 + } + } else { + category.setLevel(1); // 부모가 없으면 레벨 1 } - - // 상위 카테고리 정보를 별도로 처리 (VO에 저장하지 않음) - return category; // 단순히 카테고리 정보만 반환 + return category; // 부모 카테고리와 상관없이 카테고리 정보만 반환 } // 특정 사업자(businessId) 소속의 카테고리 목록을 조회(삭제하지 마세요) @Override public List getCategoriesByBusinessId(int businessId) throws Exception { - System.out.println(" getCategoriesByBusinessId() 호출 "); - + logger.info(" getCategoriesByBusinessId() 호출 "); return categoryDAO.selectCategoriesByBusinessId(businessId); } // 카테고리ID로 카테고리명 조회(삭제하지 마세요) @Override public void getCategoryNameById(int categoryId) throws Exception { - System.out.println(" getCategoryNameById() 호출 "); - + logger.info(" getCategoryNameById() 호출 "); categoryDAO.selectCategoryNameById(categoryId); } - + + // 카테고리 삭제 @Override public void deleteCategory(int categoryId) throws Exception { // 카테고리 논리 삭제 categoryDAO.deleteCategory(categoryId); } - // 부모 카테고리 체크 후 카테고리 등록 @Override public void registerCategoryWithParentCheck(CategoryVO category) throws Exception { + // 부모 카테고리 없을 경우 대분류 처리 if (category.getParentId() == null || category.getParentId() == 0) { - // 부모 카테고리 없는 경우 새 부모 카테고리로 등록 category.setParentId(null); // 부모 카테고리 설정되지 않음 category.setLevel(1); // 대분류 } else { - // 부모 카테고리 설정된 경우 소분류로 등록 - category.setLevel(2); // 소분류 + // 부모 카테고리 설정된 경우 + CategoryVO parentCategory = categoryDAO.selectCategoryById(category.getParentId()); + if (parentCategory == null) { + throw new IllegalArgumentException("존재하지 않는 상위 카테고리 ID입니다."); + } + category.setLevel(parentCategory.getLevel() + 1); // 부모 레벨 + 1 } - // 등록을 위해 addCategory 호출 + // 카테고리 등록 처리 addCategory(category); } @@ -106,4 +149,4 @@ public void registerCategoryWithParentCheck(CategoryVO category) throws Exceptio public List getParentCategories() throws Exception { return categoryDAO.selectParentCategories(); // 부모 카테고리만 조회 } -} +} \ No newline at end of file diff --git a/stockMate/src/main/resources/mappers/categoryMapper.xml b/stockMate/src/main/resources/mappers/categoryMapper.xml index 0883628..b144d06 100644 --- a/stockMate/src/main/resources/mappers/categoryMapper.xml +++ b/stockMate/src/main/resources/mappers/categoryMapper.xml @@ -18,26 +18,26 @@ - - INSERT INTO test_categories ( - parent_id, - business_id, - category_name, - level, - created_at, - updated_at, - is_deleted - ) - VALUES ( - #{parentId}, - #{businessId}, - #{categoryName}, - #{level}, - NOW(), - NOW(), - 0 - ) - + + INSERT INTO test_categories ( + parent_id, + business_id, + category_name, + level, + created_at, + updated_at, + is_deleted + ) + VALUES ( + #{parentId}, + #{businessId}, + #{categoryName}, + #{level}, + NOW(), + NOW(), + 0 + ) + + + + + + + + UPDATE test_categories + SET parent_id = #{parentId} + WHERE parent_id = #{categoryId} + - + \ No newline at end of file diff --git a/stockMate/src/main/resources/mappers/userMapper.xml b/stockMate/src/main/resources/mappers/userMapper.xml index 57be5f5..0e899c2 100644 --- a/stockMate/src/main/resources/mappers/userMapper.xml +++ b/stockMate/src/main/resources/mappers/userMapper.xml @@ -8,18 +8,42 @@ + + + + + + + - - - INSERT INTO test_users (email, password, name, role, tel_number) - VALUES (#{email}, #{password}, #{name}, #{role}, #{telNumber}) - + + INSERT INTO test_users ( + email, + password, + name, + role, + tel_number, + created_at, + status, + is_deleted + ) + VALUES ( + #{email}, + #{password}, + #{name}, + #{role}, + #{telNumber}, + NOW(), + 'PENDING', + 0 + ) + - + - - + + - + diff --git a/stockMate/src/main/webapp/WEB-INF/views/category/list.jsp b/stockMate/src/main/webapp/WEB-INF/views/category/list.jsp index 3d4dd1b..a43b58e 100644 --- a/stockMate/src/main/webapp/WEB-INF/views/category/list.jsp +++ b/stockMate/src/main/webapp/WEB-INF/views/category/list.jsp @@ -1,4 +1,4 @@ -<%@ page language="java" contentType="text/html; charset=EUC-KR" +<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> @@ -13,44 +13,43 @@

카테고리 목록 정보 출력

- - - - - - - - - - - - - - - - - - - - - - - - -
카테고리 ID상위 카테고리 ID카테고리 이름레벨생성 날짜액션
${category.categoryId}${category.parentId != null ? category.parentId : '없음'}${category.categoryName}${category.level == 1 ? '대분류' : '소분류'}${category.createdAt} - -
- - -
- -
- - -
-
- - - 카테고리 등록 + + + + + + + + + + + + + + + + + + + + + + + + +
카테고리 ID상위 카테고리 ID카테고리 이름레벨생성 날짜액션
${category.categoryId}${category.parentId != null ? category.parentId : '없음'} + ${category.categoryName} + ${category.level}${category.createdAt} +
+ + +
+
+ + +
+
+ + 카테고리 등록 diff --git a/stockMate/src/main/webapp/WEB-INF/views/category/register.jsp b/stockMate/src/main/webapp/WEB-INF/views/category/register.jsp index a376146..ff92db8 100644 --- a/stockMate/src/main/webapp/WEB-INF/views/category/register.jsp +++ b/stockMate/src/main/webapp/WEB-INF/views/category/register.jsp @@ -1,4 +1,4 @@ -<%@ page language="java" contentType="text/html; charset=EUC-KR" +<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> @@ -11,26 +11,25 @@

/views/category/register.jsp

- - + - - + - - - - + + + - + - +
+ 카테고리 리스트로 이동 diff --git a/stockMate/src/main/webapp/WEB-INF/views/user/Howtouse.jsp b/stockMate/src/main/webapp/WEB-INF/views/user/Howtouse.jsp new file mode 100644 index 0000000..c4aea3b --- /dev/null +++ b/stockMate/src/main/webapp/WEB-INF/views/user/Howtouse.jsp @@ -0,0 +1,132 @@ +<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> + + + + + 상담문의 + + + +
+
+

상담을 통해 궁금한 점을 즉시 해결하세요.

+ +

궁금한 점을 빠르게 확인할 수 있습니다.

+

+ • 연락처를 남겨주시면 영업 시간 기준 1일~2일 이내에 연락 드립니다.
+ • 전문가와의 상담을 통해 문의사항을 빠르고 정확하게 해결하세요. +

+ +

효과적인 시스템을 느껴보세요

+

+ • 우리 회사의 업무에 어떻게 적용할 수 있을지 확인할 수 있습니다.
+ • 프로그램 도입 여부를 빠르게 판단할 수 있습니다. +

+
+ +
+

상담문의

+
+ + + + +
+ + +
+ +
+ 개인정보 수집에 동의함 (필수) +
+ +
+ + +
+
+ + diff --git a/stockMate/src/main/webapp/WEB-INF/views/user/changePassword1.jsp b/stockMate/src/main/webapp/WEB-INF/views/user/changePassword1.jsp deleted file mode 100644 index 7728e05..0000000 --- a/stockMate/src/main/webapp/WEB-INF/views/user/changePassword1.jsp +++ /dev/null @@ -1,170 +0,0 @@ -<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> - - - - - - 비밀번호 변경 - - - - -
- -

비밀번호 변경

-
- - - - -
-
- - - - - - - - - - diff --git a/stockMate/src/main/webapp/WEB-INF/views/user/changepassword1.jsp b/stockMate/src/main/webapp/WEB-INF/views/user/changepassword1.jsp new file mode 100644 index 0000000..7096947 --- /dev/null +++ b/stockMate/src/main/webapp/WEB-INF/views/user/changepassword1.jsp @@ -0,0 +1,102 @@ +<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> + + + + + + 비밀번호 변경 + + + + +
+ +

비밀번호 변경

+
+ + + + +
+
+ + + + diff --git a/stockMate/src/main/webapp/WEB-INF/views/user/consultation.jsp b/stockMate/src/main/webapp/WEB-INF/views/user/consultation.jsp new file mode 100644 index 0000000..c4aea3b --- /dev/null +++ b/stockMate/src/main/webapp/WEB-INF/views/user/consultation.jsp @@ -0,0 +1,132 @@ +<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> + + + + + 상담문의 + + + +
+
+

상담을 통해 궁금한 점을 즉시 해결하세요.

+ +

궁금한 점을 빠르게 확인할 수 있습니다.

+

+ • 연락처를 남겨주시면 영업 시간 기준 1일~2일 이내에 연락 드립니다.
+ • 전문가와의 상담을 통해 문의사항을 빠르고 정확하게 해결하세요. +

+ +

효과적인 시스템을 느껴보세요

+

+ • 우리 회사의 업무에 어떻게 적용할 수 있을지 확인할 수 있습니다.
+ • 프로그램 도입 여부를 빠르게 판단할 수 있습니다. +

+
+ +
+

상담문의

+
+ + + + +
+ + +
+ +
+ 개인정보 수집에 동의함 (필수) +
+ +
+ + +
+
+ + diff --git a/stockMate/src/main/webapp/WEB-INF/views/user/dash.jsp b/stockMate/src/main/webapp/WEB-INF/views/user/dashboard.jsp similarity index 88% rename from stockMate/src/main/webapp/WEB-INF/views/user/dash.jsp rename to stockMate/src/main/webapp/WEB-INF/views/user/dashboard.jsp index 46a4c45..2f4f406 100644 --- a/stockMate/src/main/webapp/WEB-INF/views/user/dash.jsp +++ b/stockMate/src/main/webapp/WEB-INF/views/user/dashboard.jsp @@ -156,7 +156,7 @@