From c4776ac8a230b255d3f906b268be02e028d83634 Mon Sep 17 00:00:00 2001 From: sungsu Date: Sun, 21 Jan 2024 23:25:34 +0900 Subject: [PATCH] #update --- .../com/no1/wms/excel/ExcelDownlodeUtils.java | 2 +- .../com/no1/wms/out/ProductOutController.java | 13 ++-- .../com/no1/wms/out/ProductOutMapper.java | 2 + .../com/no1/wms/out/ProductOutService.java | 5 ++ .../com/no1/wms/stock/StockController.java | 7 +- .../com/no1/wms/vendor/VendorController.java | 64 +++++++++++++++++++ .../java/com/no1/wms/vendor/VendorMapper.java | 2 + .../com/no1/wms/vendor/VendorService.java | 4 +- .../resources/mappers/ProductOutMapper.xml | 6 ++ src/main/resources/mappers/StockMapper.xml | 20 +++++- src/main/resources/mappers/VendorMapper.xml | 13 +++- .../resources/mappers/WarehouseMapper.xml | 10 +-- src/main/webapp/WEB-INF/views/out/create.jsp | 4 +- src/main/webapp/WEB-INF/views/out/list.jsp | 6 +- src/main/webapp/WEB-INF/views/out/read.jsp | 19 +++++- src/main/webapp/WEB-INF/views/out/update.jsp | 2 +- .../webapp/WEB-INF/views/stock/create.jsp | 32 ++++++---- src/main/webapp/WEB-INF/views/stock/list.jsp | 20 +++--- .../webapp/WEB-INF/views/stock/update.jsp | 8 +-- src/main/webapp/WEB-INF/views/vendor/list.jsp | 34 ++++++++-- .../webapp/WEB-INF/views/warehouse/list.jsp | 8 +-- .../webapp/WEB-INF/views/warehouse/read.jsp | 6 +- 22 files changed, 215 insertions(+), 72 deletions(-) diff --git a/src/main/java/com/no1/wms/excel/ExcelDownlodeUtils.java b/src/main/java/com/no1/wms/excel/ExcelDownlodeUtils.java index daa6dd8..8850a21 100644 --- a/src/main/java/com/no1/wms/excel/ExcelDownlodeUtils.java +++ b/src/main/java/com/no1/wms/excel/ExcelDownlodeUtils.java @@ -240,7 +240,7 @@ public class ExcelDownlodeUtils { cell = row.createCell(2); cell.setCellValue((String) dto.get("warehouseName")); cell = row.createCell(3); - cell.setCellValue((String) dto.get("quantity")); + cell.setCellValue((int) dto.get("quantity")); } } diff --git a/src/main/java/com/no1/wms/out/ProductOutController.java b/src/main/java/com/no1/wms/out/ProductOutController.java index 47423ee..5603f85 100644 --- a/src/main/java/com/no1/wms/out/ProductOutController.java +++ b/src/main/java/com/no1/wms/out/ProductOutController.java @@ -120,7 +120,7 @@ public class ProductOutController { @ResponseBody public int delete(ProductOutDto dto) { System.out.println("데이터 :: " + dto); - int i = service.deleteOut(dto); + int i = service.outNow(dto); return i; } @@ -130,13 +130,10 @@ public class ProductOutController { @PutMapping("/outNow") @ResponseBody public boolean outNow(ProductOutDto dto) { - int i = service.outNowUpdate(dto); - if (i != 0) { - service.updateWarehouseDeleteStock(dto); - return true; - } else { - return false; - } + service.outNowUpdate(dto); + service.updateWarehouseDeleteStock(dto); + service.stockQuantityUpdate(dto); + return true; } diff --git a/src/main/java/com/no1/wms/out/ProductOutMapper.java b/src/main/java/com/no1/wms/out/ProductOutMapper.java index f28f3b3..e7e3975 100644 --- a/src/main/java/com/no1/wms/out/ProductOutMapper.java +++ b/src/main/java/com/no1/wms/out/ProductOutMapper.java @@ -25,6 +25,8 @@ public interface ProductOutMapper { int updateWarehousePlus(ProductOutDto dto); int updateWarehouseDeleteStock(ProductOutDto dto); + + int stockQuantityUpdate(ProductOutDto dto); int createOut(ProductOutDto dto); diff --git a/src/main/java/com/no1/wms/out/ProductOutService.java b/src/main/java/com/no1/wms/out/ProductOutService.java index ae3eb8d..cd8e79e 100644 --- a/src/main/java/com/no1/wms/out/ProductOutService.java +++ b/src/main/java/com/no1/wms/out/ProductOutService.java @@ -73,6 +73,11 @@ public class ProductOutService { return mapper.updateWarehouseDeleteStock(dto); } + public int stockQuantityUpdate(ProductOutDto dto){ + return mapper.stockQuantityUpdate(dto); + } + + public int deleteOut(ProductOutDto dto) { return mapper.deleteOut(dto); } diff --git a/src/main/java/com/no1/wms/stock/StockController.java b/src/main/java/com/no1/wms/stock/StockController.java index facdd24..fdf0673 100644 --- a/src/main/java/com/no1/wms/stock/StockController.java +++ b/src/main/java/com/no1/wms/stock/StockController.java @@ -196,7 +196,7 @@ public class StockController { list = service.warehousesSelect(searchn, search, startRow, perPage ,product_id); count = service.warehouseCount(searchn, search ,product_id); } - + System.out.println("테스트 :: "+ product_id); mav.addObject("list", list); mav.addObject("start", startRow + 1); @@ -230,9 +230,10 @@ public class StockController { // 리스트 다운로드 - @GetMapping("/stock/downloadExcelList") + @GetMapping("/downloadExcelList") public void downlodeExcelList(HttpServletResponse response) { List> dto = service.selectAll(); + System.out.println("엑셀 출력 확인 : : " + dto); String excelFileName = "재고 파일"; String sheetName = "재고"; String[] columnName = {"제품명","카테고리","창고","재고수"}; @@ -241,7 +242,7 @@ public class StockController { }; //서식 다운로드 - @GetMapping("/stock/downloadStockForm") + @GetMapping("/downloadStockForm") public void downlodeStockForm (HttpServletResponse response) throws IOException { String stockFormName = "재고 데이터 입력 서식.xlsx"; excelDownlodeUtils.downlodeExcelForm(response, stockFormName); diff --git a/src/main/java/com/no1/wms/vendor/VendorController.java b/src/main/java/com/no1/wms/vendor/VendorController.java index 0f53f17..c414826 100644 --- a/src/main/java/com/no1/wms/vendor/VendorController.java +++ b/src/main/java/com/no1/wms/vendor/VendorController.java @@ -2,15 +2,22 @@ package com.no1.wms.vendor; import com.no1.wms.category.CategoryDto; import com.no1.wms.excel.ExcelDownlodeUtils; +import com.no1.wms.excel.ExcelRequestManager; import com.no1.wms.warehouse.WarehouseDto; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; +import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; +import org.springframework.web.multipart.MultipartHttpServletRequest; +import org.springframework.web.servlet.mvc.support.RedirectAttributes; +import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -146,4 +153,61 @@ public class VendorController { String vendorFormName = "거래처 데이터 입력 서식.xlsx"; excelDownlodeUtils.downlodeExcelForm(response, vendorFormName); }; + + + + @PostMapping("/vendor/uplodeExcel") + public String uploadExcel(@ModelAttribute("dto") VendorDto dto , RedirectAttributes redirectAttributes, final MultipartHttpServletRequest multiRequest, + HttpServletRequest request, ModelMap model) { + + Map resMap = new HashMap<>(); + + + try { + + ExcelRequestManager em = new ExcelRequestManager(); + + // 멀티파트 요청 객체에서 파일 맵을 가져옴 + final Map files = multiRequest.getFileMap(); + //초기화 + List> apply =null; + + //엑셀파일 가져와서 저장 및 읽기 + //변수는 멀티파트 요청 객체의 파일맵, 저장할 엑셀파일명 이름에 추가할 숫자(그냥 0으로 해도 됨) + //마찬가지로 엑셀파일 명 이름에 추가할 문자열, uplode폴더에 들어갈 폴더명(카테고리같은 파트 이름으로 해주세요) + //폴더가 없으면 자동생성되게 해뒀습니다. + //마지막으로 HttpServletRequest + apply = em.parseExcelSpringMultiPart(files, "테스트파일", 0, "", "category", request); + + for (int i = 0; i < apply.size(); i++) { + + + dto.setName(apply.get(i).get("nsme")); + dto.setPresident_name(apply.get(i).get("president_name")); + dto.setAddress(apply.get(i).get("address")); + dto.setRegistration_number(apply.get(i).get("registration_number")); + dto.setEmail(apply.get(i).get("email")); + dto.setPresident_telephone(apply.get(i).get("president_telephone")); + dto.setVendor_manager(apply.get(i).get("vendor_manager")); + dto.setVendor_manager_telephone(apply.get(i).get("vendor_manager_telephone")); + dto.setMain_product(apply.get(i).get("main_product")); + dto.setManager_id(apply.get(i).get("manager_id")); + dto.setActivation(true); + + service.createProcess(dto); + + } + + resMap.put("res", "ok"); + resMap.put("msg", "업로드 성공"); + } catch (Exception e) { + System.out.println(e.toString()); + resMap.put("res", "error"); + resMap.put("msg", "업로드 실패"); + } + + redirectAttributes.addFlashAttribute("resMap", resMap); + + return "redirect:/vendor/list"; + }; } diff --git a/src/main/java/com/no1/wms/vendor/VendorMapper.java b/src/main/java/com/no1/wms/vendor/VendorMapper.java index 46e39b6..179f677 100644 --- a/src/main/java/com/no1/wms/vendor/VendorMapper.java +++ b/src/main/java/com/no1/wms/vendor/VendorMapper.java @@ -1,5 +1,6 @@ package com.no1.wms.vendor; +import com.no1.wms.category.CategoryDto; import com.no1.wms.warehouse.WarehouseDto; import org.apache.ibatis.annotations.Mapper; @@ -19,6 +20,7 @@ public interface VendorMapper { int updateVendor(VendorDto dto); int createVendor(VendorDto dto); + int createProcess(VendorDto dto); int deleteVendor(String id); diff --git a/src/main/java/com/no1/wms/vendor/VendorService.java b/src/main/java/com/no1/wms/vendor/VendorService.java index 7e67e76..2a51ca3 100644 --- a/src/main/java/com/no1/wms/vendor/VendorService.java +++ b/src/main/java/com/no1/wms/vendor/VendorService.java @@ -1,6 +1,5 @@ package com.no1.wms.vendor; -import com.no1.wms.warehouse.WarehouseDto; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -49,6 +48,9 @@ public class VendorService { public int createVendor(VendorDto dto) { return mapper.createVendor(dto); } + public int createProcess(VendorDto dto) { + return mapper.createProcess(dto); + } public int deleteVendor(String id) { diff --git a/src/main/resources/mappers/ProductOutMapper.xml b/src/main/resources/mappers/ProductOutMapper.xml index 316f79c..a9b7abd 100644 --- a/src/main/resources/mappers/ProductOutMapper.xml +++ b/src/main/resources/mappers/ProductOutMapper.xml @@ -119,6 +119,12 @@ set quantity = #{quantity}, expected_delivery_date = #{expected_delivery_date}, delivery_date = #{delivery_date} where id = #{id}; + + + update stock + set quantity = quantity - #{quantity} + where product_id = #{product_id} and warehouse_id = #{warehouse_id}; + diff --git a/src/main/resources/mappers/StockMapper.xml b/src/main/resources/mappers/StockMapper.xml index d41cf96..8c05105 100644 --- a/src/main/resources/mappers/StockMapper.xml +++ b/src/main/resources/mappers/StockMapper.xml @@ -27,6 +27,7 @@ s.activation = 1 and p.name like concat('%',#{search},'%') s.activation = 1 and c.cls_Nm_4 like concat('%',#{search},'%') s.activation = 1 and s.quantity like concat('%',#{search},'%') + s.activation = 1 and w.name like concat('%',#{search},'%') @@ -44,6 +45,7 @@ s.activation = 1 and p.name like concat('%',#{search},'%') s.activation = 1 and c.cls_Nm_4 like concat('%',#{search},'%') s.activation = 1 and s.quantity like concat('%',#{search},'%') + s.activation = 1 and w.name like concat('%',#{search},'%') order by s.id desc limit #{start}, #{perPage} @@ -62,6 +64,7 @@ quantity <= 200 and s.activation = 1 and p.name like concat('%',#{search},'%') quantity <= 200 and s.activation = 1 and c.cls_Nm_4 like concat('%',#{search},'%') quantity <= 200 and s.activation = 1 and s.quantity like concat('%',#{search},'%') + s.activation = 1 and w.name like concat('%',#{search},'%') @@ -79,13 +82,22 @@ quantity <= 200 and s.activation = 1 and p.name like concat('%',#{search},'%') quantity <= 200 and s.activation = 1 and c.cls_Nm_4 like concat('%',#{search},'%') quantity <= 200 and s.activation = 1 and s.quantity like concat('%',#{search},'%') + s.activation = 1 and w.name like concat('%',#{search},'%') order by s.id desc limit #{start}, #{perPage} - select + select id, name, president_name, address, @@ -14,7 +14,9 @@ president_telephone, vendor_manager, vendor_manager_telephone, - main_products + main_product, + manager_id, + activation from vendor; @@ -108,7 +110,12 @@ insert into vendor (id, name, president_name, address, registration_number, email, president_telephone, vendor_manager, vendor_manager_telephone, main_product, manager_id, activation) - values (UUID(), #{name}, #{president_name}, #{address}, #{registration_number}, #{email}, #{president_telephone}, #{vendor_manager}, #{vendor_manager_telephone}, #{main_product}, #{manager_id}, #{activation}) + values (UUID(), #{name}, #{president_name}, #{address}, #{registration_number}, #{email}, #{president_telephone}, #{vendor_manager}, #{vendor_manager_telephone}, #{main_product}, #{manager_id}, 1) + + + + insert into vendor (id, name, president_name, address, registration_number, email, president_telephone, vendor_manager, vendor_manager_telephone, main_product, manager_id, activation) + values (UUID(), #{name}, #{president_name}, #{address}, #{registration_number}, #{email}, #{president_telephone}, #{vendor_manager}, #{vendor_manager_telephone}, #{main_product}, #{manager_id}, 1) diff --git a/src/main/resources/mappers/WarehouseMapper.xml b/src/main/resources/mappers/WarehouseMapper.xml index 060e266..4222582 100644 --- a/src/main/resources/mappers/WarehouseMapper.xml +++ b/src/main/resources/mappers/WarehouseMapper.xml @@ -6,7 +6,7 @@ - - + + + aria-label="Text input with dropdown button" value="${search}" placeholder="검색어를 입력하세요"> diff --git a/src/main/webapp/WEB-INF/views/out/read.jsp b/src/main/webapp/WEB-INF/views/out/read.jsp index 8a9d1d6..463cf23 100644 --- a/src/main/webapp/WEB-INF/views/out/read.jsp +++ b/src/main/webapp/WEB-INF/views/out/read.jsp @@ -60,7 +60,7 @@
비고 - +
@@ -68,7 +68,7 @@
-
+
@@ -109,7 +109,7 @@
@@ -137,6 +137,13 @@ $(document).ready(function () { + var deliveryDate = $("#delivery_date").val(); + + // '출고 날짜' 입력 필드에 값이 있다면, '출고' 버튼을 숨깁니다. + if (deliveryDate) { + $("#outNow").hide(); + } + $("#modifyBtn").on("click", function () { var id = $("#id").val(); @@ -207,6 +214,9 @@ function outNowUpdate() { var id = $("#id").val(); + var quantity = $("#quantity").val(); + var product_id = $("#product_id").val() + var warehouse_id = $("#warehouse_id").val(); var expected_delivery_date = $("#expected_delivery_date").val(); // 현재 날짜와 시간을 얻기 var now = new Date(); @@ -217,6 +227,9 @@ type: "put", data: { "id": id, + "quantity": quantity, + "product_id":product_id, + "warehouse_id": warehouse_id, "expected_delivery_date": expected_delivery_date, "delivery_date": delivery_date }, diff --git a/src/main/webapp/WEB-INF/views/out/update.jsp b/src/main/webapp/WEB-INF/views/out/update.jsp index 1428606..0dc409d 100644 --- a/src/main/webapp/WEB-INF/views/out/update.jsp +++ b/src/main/webapp/WEB-INF/views/out/update.jsp @@ -59,7 +59,7 @@
비고 - +
diff --git a/src/main/webapp/WEB-INF/views/stock/create.jsp b/src/main/webapp/WEB-INF/views/stock/create.jsp index a014b1d..4826f05 100644 --- a/src/main/webapp/WEB-INF/views/stock/create.jsp +++ b/src/main/webapp/WEB-INF/views/stock/create.jsp @@ -54,7 +54,7 @@
잔여 용량 - +
@@ -62,13 +62,15 @@
재고량
+ + @@ -103,15 +105,16 @@ } function showSearchModals2(title, val){ - $("#searchModalLabel").text(title); - const data = { name : val}; var product_id = $("#product_id").val(); + $("#searchModalLabel").text(title); + const data = { name : val, + product_id :product_id}; $.ajax({ type : 'post', // 타입 (get, post, put 등등) url : '/stock/show_modal', // 요청할 서버url dataType : 'html', // 데이터 타입 (html, xml, json, text 등등) - data : {"product_id" : product_id},data, + data : data, success : function(result) { // 결과 성공 콜백함수 $("#search_modal_body").html(result); searchModalBootStrap.show(); @@ -129,9 +132,18 @@ $("#submitBtn").on("click", function () { var product_id = $("#product_id").val(); var warehouse_id = $("#warehouse_id").val(); - var quantity = $("#quantity").val(); var activation = $("#activation").val(); - var remainingcapacity = $("#remainingcapacity").val(); + var quantity = parseInt($("#quantity").val(), 10); + var remainingcapacity = parseInt($("#remainingcapacity").val(), 10); + + console.log("Quantity:", quantity); + console.log("Remaining Capacity:", remainingcapacity); + + if (quantity > remainingcapacity) { + alert("적재 할 재고량이 잔여 용량을 넘을 수 없습니다."); + $("#quantity").focus(); + return false; + } if (!product_id) { alert("제품을 선택해야 합니다."); @@ -150,12 +162,6 @@ return false; } - if (quantity > remainingcapacity) { - alert("적재 할 재고량이 잔여 용량을 넘을 수 없습니다."); - $("#quantity").focus(); - return false; - } - $.ajax({ url: "/stock/create_process", type: "post", diff --git a/src/main/webapp/WEB-INF/views/stock/list.jsp b/src/main/webapp/WEB-INF/views/stock/list.jsp index cd8c958..00e8aaa 100644 --- a/src/main/webapp/WEB-INF/views/stock/list.jsp +++ b/src/main/webapp/WEB-INF/views/stock/list.jsp @@ -48,13 +48,14 @@
+ aria-label="Text input with dropdown button" value="${search}" placeholder="검색어를 입력하세요"> @@ -98,7 +99,6 @@
ms-excel -
@@ -147,13 +147,14 @@
+ aria-label="Text input with dropdown button" value="${search}" placeholder="검색어를 입력하세요"> @@ -195,7 +196,6 @@
ms-excel -
diff --git a/src/main/webapp/WEB-INF/views/stock/update.jsp b/src/main/webapp/WEB-INF/views/stock/update.jsp index 321b97e..5384654 100644 --- a/src/main/webapp/WEB-INF/views/stock/update.jsp +++ b/src/main/webapp/WEB-INF/views/stock/update.jsp @@ -39,7 +39,7 @@
창고 - + <%-- --%>
@@ -55,7 +55,7 @@
- 재고량 한도 + 수정 가능한 재고량 한도
@@ -120,9 +120,9 @@ var warehouse_id = $("#warehouse_id").val(); var quantity = $("#quantity").val(); var activation = $("#activation").val(); - var remainingcapacity = $("#remainingcapacity").val(); var id = $("#id").val(); - var quantityAdjustment = $("#quantityAdjustment").val(); + var quantityAdjustment = parseInt($("#quantityAdjustment").val(), 10); + var remainingcapacity = parseInt($("#remainingcapacity").val(), 10); if (!product_id) { diff --git a/src/main/webapp/WEB-INF/views/vendor/list.jsp b/src/main/webapp/WEB-INF/views/vendor/list.jsp index c5b211c..ae305b3 100644 --- a/src/main/webapp/WEB-INF/views/vendor/list.jsp +++ b/src/main/webapp/WEB-INF/views/vendor/list.jsp @@ -18,13 +18,13 @@
- + @@ -69,8 +69,7 @@
ms-excel - - +
@@ -99,6 +98,14 @@
+ + +
+ + +
+ +
@@ -215,6 +222,19 @@ document.body.appendChild(form); form.submit(); } + + function _onSubmit(){ + + if($("#file").val() == ""){ + alert("파일을 업로드해주세요."); + $("#file").focus(); + return false; + } + + + + return true; + } \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/views/warehouse/list.jsp b/src/main/webapp/WEB-INF/views/warehouse/list.jsp index b153df8..40d248c 100644 --- a/src/main/webapp/WEB-INF/views/warehouse/list.jsp +++ b/src/main/webapp/WEB-INF/views/warehouse/list.jsp @@ -30,13 +30,13 @@
+ aria-label="Text input with dropdown button" value="${search}" placeholder="검색어를 입력하세요"> diff --git a/src/main/webapp/WEB-INF/views/warehouse/read.jsp b/src/main/webapp/WEB-INF/views/warehouse/read.jsp index 12fe0e4..4954ee0 100644 --- a/src/main/webapp/WEB-INF/views/warehouse/read.jsp +++ b/src/main/webapp/WEB-INF/views/warehouse/read.jsp @@ -53,13 +53,13 @@
+ aria-label="Text input with dropdown button" value="${search}" placeholder="검색어를 입력하세요">