From 06bac5a89b4ddd85fde823f010499f94b051654b Mon Sep 17 00:00:00 2001 From: Kana Date: Thu, 4 Jan 2024 16:23:39 +0900 Subject: [PATCH] change Category and add category jsp files and add ExcelUtils(test) --- .../no1/wms/category/CategoryController.java | 89 ++++++++----- .../com/no1/wms/category/CategoryMapper.java | 5 +- .../com/no1/wms/category/CategoryService.java | 21 +++- .../java/com/no1/wms/excel/ExcelUtils.java | 78 ++++++++++++ src/main/resources/mappers/CategoryMapper.xml | 23 +++- .../webapp/WEB-INF/views/category/create.jsp | 68 ++++++++++ .../webapp/WEB-INF/views/category/list.jsp | 118 ++++++++++++++++++ 7 files changed, 363 insertions(+), 39 deletions(-) create mode 100644 src/main/java/com/no1/wms/excel/ExcelUtils.java create mode 100644 src/main/webapp/WEB-INF/views/category/create.jsp create mode 100644 src/main/webapp/WEB-INF/views/category/list.jsp diff --git a/src/main/java/com/no1/wms/category/CategoryController.java b/src/main/java/com/no1/wms/category/CategoryController.java index d25edb7..287efa9 100644 --- a/src/main/java/com/no1/wms/category/CategoryController.java +++ b/src/main/java/com/no1/wms/category/CategoryController.java @@ -5,38 +5,46 @@ import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; + +import com.no1.wms.excel.ExcelUtils; + +import jakarta.servlet.http.HttpServletResponse; @Controller public class CategoryController { - + @Autowired CategoryService categoryService; + @Autowired + ExcelUtils excelUtils; + // 테스트 @GetMapping("/category/test") - public String testpage(Model m) { + public String testPage(Model m) { List dto = categoryService.selectAllCategory(); m.addAttribute("dto", dto); - + return "category/test"; } - - + // 카테고리 리스트 출력 @GetMapping("/category/list") - public String list(@RequestParam(name="p", defaultValue = "1")int p, Model m) { - + public String list(@RequestParam(name = "p", defaultValue = "1") int p, Model m) { + // 서비스로 카테고리 목록 불러오는 메서드 작성 List dto = categoryService.categoryList(p); m.addAttribute("list", dto); return "category/list"; } - + // 상세페이지 @PostMapping("/category/read/{kan_code}") public String read(@PathVariable String kan_code, Model m) { @@ -45,57 +53,78 @@ public class CategoryController { m.addAttribute("dto", dto); return "category/read"; } - + // 생성 - 폼 - @PostMapping("/category/create") + @GetMapping("/category/create") public String create() { return "category/create"; } - + // 생성 - Ajax @PostMapping("/category/create_process") + @ResponseBody public int createProcess(CategoryDto dto, Model m) { int i = categoryService.createProcess(dto); - if(i == 1) { + if (i == 1) { return i; - }else{ + } else { // ajax테스트후 결정 - //m.addAttribute("dto", dto); + // m.addAttribute("dto", dto); return 0; } } - - + // 수정 - 폼 - @PostMapping("/category/update/{kan_code}") + @GetMapping("/category/update/{kan_code}") public String update(@PathVariable String kan_code, Model m) { CategoryDto dto = categoryService.selectByKanCode(kan_code); m.addAttribute("dto", dto); return "category/update"; } // 수정 - Ajax - + @PutMapping("/category//update_process") + @ResponseBody public int updateProcess(CategoryDto dto, Model m) { - - int i = categoryService.createProcess(dto); - if(i == 1) { + + int i = categoryService.updateByKanCode(dto); + if (i == 1) { return i; - }else{ + } else { // ajax테스트후 결정 - //m.addAttribute("dto", dto); + // m.addAttribute("dto", dto); + return 0; + } + } + + // 삭제 + @DeleteMapping("/category/delete/{kan_code}") + @ResponseBody + public int delete(@PathVariable String kan_code) { + int i = categoryService.deactivateByKanCode(kan_code); + if (i == 1) { + return i; + } else { + // ajax테스트후 결정 + // m.addAttribute("dto", dto); return 0; } } - // 삭제 - - - - - - + @GetMapping("/category/download") + public void downloadExcel(HttpServletResponse response) { + List dto = categoryService.selectAllCategory(); + String excelFileName = "카테고리 테스트 파일"; + String sheetName = "카테고리"; + String[] columnName = {"KAN_CODE","대분류","중분류","소분류","세분류"}; + excelUtils.downloadCategoryExcelFile(excelFileName, response, sheetName, columnName, dto); + + } + // KAN코드 중복확인 메서드 + public int chackKancode(String kan_code) { + return 0; + } diff --git a/src/main/java/com/no1/wms/category/CategoryMapper.java b/src/main/java/com/no1/wms/category/CategoryMapper.java index 6500506..c702642 100644 --- a/src/main/java/com/no1/wms/category/CategoryMapper.java +++ b/src/main/java/com/no1/wms/category/CategoryMapper.java @@ -11,6 +11,7 @@ public interface CategoryMapper { CategoryDto selectByKanCode(String kan_code); int createProcess(CategoryDto dto); List selectAllCategory(); - - + int updateByKanCode(CategoryDto dto); + int deactivateByKanCode(String kan_code); + int activateByKanCode(String kan_code); } diff --git a/src/main/java/com/no1/wms/category/CategoryService.java b/src/main/java/com/no1/wms/category/CategoryService.java index 05f62c4..cdcbc57 100644 --- a/src/main/java/com/no1/wms/category/CategoryService.java +++ b/src/main/java/com/no1/wms/category/CategoryService.java @@ -17,11 +17,11 @@ public class CategoryService { // String start에 int값 넣고 String end에 int값 넣고 // CategoryMapper에 있는 메서드 사용함. int start = 0; - int end = 0; + int count = 10; Map m = new HashMap(); m.put("start", start); - m.put("end", end); + m.put("count", count); @@ -33,13 +33,26 @@ public class CategoryService { } public int createProcess(CategoryDto dto) { - mapper.createProcess(dto); - return 1; + return mapper.createProcess(dto); } public List selectAllCategory() { + // 테스트용 return mapper.selectAllCategory(); } + public int updateByKanCode(CategoryDto dto) { + return mapper.updateByKanCode(dto); + } + + public int deactivateByKanCode(String kan_code) { + return mapper.deactivateByKanCode(kan_code); + } + public int activateByKanCode(String kan_code) { + return mapper.activateByKanCode(kan_code); + } + + + } diff --git a/src/main/java/com/no1/wms/excel/ExcelUtils.java b/src/main/java/com/no1/wms/excel/ExcelUtils.java new file mode 100644 index 0000000..b39ba4b --- /dev/null +++ b/src/main/java/com/no1/wms/excel/ExcelUtils.java @@ -0,0 +1,78 @@ +package com.no1.wms.excel; + +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.util.List; + +import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import org.apache.poi.ss.usermodel.Cell; +import org.apache.poi.ss.usermodel.Row; +import org.apache.poi.ss.usermodel.Sheet; +import org.apache.poi.ss.usermodel.Workbook; +import org.springframework.stereotype.Service; + +import com.no1.wms.category.CategoryDto; + +import jakarta.servlet.http.HttpServletResponse; + +@Service +public class ExcelUtils { + + public void downloadCategoryExcelFile(String excelFileName, HttpServletResponse response, + String sheetName, String[] columnName, List dto) { + String fileName = ""; + try { + fileName = new String((excelFileName + ".xlsx").getBytes("utf-8"), "iso-8859-1"); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + response.setContentType("ms-vnd/excel"); + response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\";"); + + Workbook workbook = new HSSFWorkbook(); + Sheet sheet = workbook.createSheet(sheetName); + + Row row = null; + Cell cell = null; + int rowNum = 0; + + row = sheet.createRow(rowNum); + for( int i = 0; i <= columnName.length -1; i++ ) { + cell = row.createCell(i); + cell.setCellValue(columnName[i]); + } + rowNum += 1; + //수정부분 + makeCategoryBody(dto,row,sheet,cell,rowNum); + + try { + workbook.write(response.getOutputStream()); + workbook.close(); + } catch (IOException e) { + e.printStackTrace(); + } + + + } + + public void makeCategoryBody(List listdto, Row row, Sheet sheet, + Cell cell, int rowNum) { + // + for (int i = 0; i < listdto.size(); i++) { + row = sheet.createRow(rowNum++); + CategoryDto dto = listdto.get(i); + cell = row.createCell(0); + cell.setCellValue(dto.getKan_code()); + cell = row.createCell(1); + cell.setCellValue(dto.getCls_nm_1()); + cell = row.createCell(2); + cell.setCellValue(dto.getCls_nm_2()); + cell = row.createCell(3); + cell.setCellValue(dto.getCls_nm_3()); + cell = row.createCell(4); + cell.setCellValue(dto.getCls_nm_4()); + } + } + + +} diff --git a/src/main/resources/mappers/CategoryMapper.xml b/src/main/resources/mappers/CategoryMapper.xml index c6160fc..f81d0c6 100644 --- a/src/main/resources/mappers/CategoryMapper.xml +++ b/src/main/resources/mappers/CategoryMapper.xml @@ -12,14 +12,26 @@ - + UPDATE product_category SET cls_nm_1 = #{dto.cls_nm_1}, cls_nm_2 = #{dto.cls_nm_2},cls_nm_3 = #{dto.cls_nm_3}, cls_nm_4 = #{dto.cls_nm_4} WHERE kan_code = {dto.kan_code} - + + UPDATE product_category + SET activation = 0 + WHERE kan_code = {kan_code} + + + UPDATE product_category + SET activation = 1 + WHERE kan_code = {kan_code} + + + + @@ -28,7 +40,7 @@ + + + + + \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/views/category/create.jsp b/src/main/webapp/WEB-INF/views/category/create.jsp new file mode 100644 index 0000000..05fb642 --- /dev/null +++ b/src/main/webapp/WEB-INF/views/category/create.jsp @@ -0,0 +1,68 @@ +<%@ page contentType="text/html; charset=UTF-8"%> + + + + +카테고리 생성 + + + +
+

제품 카테고리 생성

+
+
+
+
+
+
    +
  • 대분류
  • + +
    +
  • 중분류
  • + +
    +
  • 소분류
  • + +
    +
  • 세분류
  • + +
    +
  • KAN 분류코드
  • + + + +
+
+
+ + +
+
+ + + +
+ + \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/views/category/list.jsp b/src/main/webapp/WEB-INF/views/category/list.jsp new file mode 100644 index 0000000..e37e511 --- /dev/null +++ b/src/main/webapp/WEB-INF/views/category/list.jsp @@ -0,0 +1,118 @@ +<%@ page contentType="text/html; charset=UTF-8"%> +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> + + + + +제품 카테고리 + + + + + +
+

제품 카테고리 관리

+
+
+
+ + +
+ + + + + + + + + + + + + + + + + + +
KAN코드대분류중분류소분류세분류
${dto.kan_code }${dto.cls_nm_1 }${dto.cls_nm_2 }${dto.cls_nm_3 }${dto.cls_nm_4 }
+
+
+
+ 엑셀다운로드 이미지 + +
+
+ +
+
+ +
+ + +
+ + + + + \ No newline at end of file