This commit is contained in:
sungsu
2024-01-19 09:54:32 +09:00
parent 2b61691f65
commit 98de984f58
9 changed files with 125 additions and 10 deletions

View File

@@ -8,6 +8,7 @@ import java.io.OutputStream;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.util.List; import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
@@ -187,6 +188,64 @@ public class ExcelDownlodeUtils {
public void downloadStockExcelFile(String excelFileName, HttpServletResponse response,
String sheetName, String[] columnName, List<Map<String, Object>> 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 XSSFWorkbook();
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;
//수정부분
makeStockBody(dto,row,sheet,cell,rowNum);
try {
workbook.write(response.getOutputStream());
workbook.close();
} catch (IOException e) {
e.printStackTrace();
}
}
public void makeStockBody(List<Map<String, Object>> listdto, Row row, Sheet sheet,
Cell cell, int rowNum) {
//
for (int i = 0; i < listdto.size(); i++) {
row = sheet.createRow(rowNum++);
Map<String, Object> dto = listdto.get(i);
cell = row.createCell(0);
cell.setCellValue((String) dto.get("productName"));
cell = row.createCell(1);
cell.setCellValue((String) dto.get("cls_nm_4"));
cell = row.createCell(2);
cell.setCellValue((String) dto.get("warehouseName"));
cell = row.createCell(3);
cell.setCellValue((String) dto.get("quantity"));
}
}

View File

@@ -1,6 +1,7 @@
package com.no1.wms.stock; package com.no1.wms.stock;
import com.no1.wms.excel.ExcelDownlodeUtils;
import com.no1.wms.vendor.VendorDto; import com.no1.wms.vendor.VendorDto;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@@ -9,6 +10,8 @@ import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@@ -20,6 +23,9 @@ public class StockController {
@Autowired @Autowired
StockService service; StockService service;
@Autowired
ExcelDownlodeUtils excelDownlodeUtils;
// 탭 1 재고 리스트 출력 // 탭 1 재고 리스트 출력
@GetMapping("/list") @GetMapping("/list")
public String list(@RequestParam(name = "searchn1", defaultValue = "0") int searchn1, public String list(@RequestParam(name = "searchn1", defaultValue = "0") int searchn1,
@@ -221,4 +227,24 @@ public class StockController {
//테스트 //테스트
return mav; return mav;
} }
// 엑셀다운로드테스트
@GetMapping("/stock/downlodeExcelList")
public void downlodeExcelList(HttpServletResponse response) {
List<Map<String, Object>> dto = service.selectAll();
String excelFileName = "재고 파일";
String sheetName = "재고";
String[] columnName = {"제품명","카테고리","창고","재고수"};
excelDownlodeUtils.downloadStockExcelFile(excelFileName, response, sheetName, columnName, dto);
};
//서식 다운로드
@GetMapping("/vendor/downlodeVendorForm")
public void downlodeVendorForm (HttpServletResponse response) throws IOException {
String vendorFormName = "재고 데이터 입력 서식.xlsx";
excelDownlodeUtils.downlodeExcelForm(response, vendorFormName);
};
} }

View File

@@ -8,6 +8,7 @@ import java.util.Map;
@Mapper @Mapper
public interface StockMapper { public interface StockMapper {
List<Map<String, Object>> selectAll();
int count(Map<String, Object> m);//검색 글 갯수 int count(Map<String, Object> m);//검색 글 갯수

View File

@@ -142,6 +142,10 @@ public class StockService {
return mapper.warehouseCount(m); return mapper.warehouseCount(m);
} }
public List<Map<String, Object>> selectAll() {
return mapper.selectAll();
}
} }

View File

@@ -130,8 +130,8 @@ public class VendorController {
} }
// 엑셀다운로드테스트 // 엑셀다운로드테스트
@GetMapping("/vendor/downloadTest") @GetMapping("/vendor/downlodeExcelList")
public void downloadExcelTest(HttpServletResponse response) { public void downlodeExcelList(HttpServletResponse response) {
List<VendorDto> dto = service.selectAll(); List<VendorDto> dto = service.selectAll();
String excelFileName = "거래처 파일"; String excelFileName = "거래처 파일";
String sheetName = "거래처"; String sheetName = "거래처";

View File

@@ -5,6 +5,15 @@
<mapper namespace="com.no1.wms.stock.StockMapper"> <mapper namespace="com.no1.wms.stock.StockMapper">
<!-- select --> <!-- select -->
<select id="selectAll" parameterType="Map" resultType="Map">
select s.id as id, s.warehouse_id as warehouseId, s.product_id as productId, s.quantity, p.name as productName, p.kan_code, c.cls_nm_4, w.name as warehouseName
from stock s
left join warehouse w on s.warehouse_id = w.id
left join product p on s.product_id = p.id
left join product_category c on p.kan_code = c.kan_code;
</select>
<select id="count" parameterType="Map" resultType="java.lang.Integer"> <select id="count" parameterType="Map" resultType="java.lang.Integer">
select count(s.id) select count(s.id)

View File

@@ -96,7 +96,7 @@
<div class="row row-buttons"> <div class="row row-buttons">
<div class="col-3 text-start"> <div class="col-3 text-start">
<img width="50" height="50" src="https://img.icons8.com/color/48/ms-excel.png" alt="ms-excel"/> <img width="50" height="50" src="https://img.icons8.com/color/48/ms-excel.png" alt="ms-excel"/>
<button type="button" class="btn btn-success" id="download">다운로드</button> <button type="button" class="btn btn-success" id="downlodeExcelList">리스트 다운로드</button>
</div> </div>
<div class="col-6 d-flex justify-content-center"> <div class="col-6 d-flex justify-content-center">
<nav> <nav>
@@ -192,7 +192,7 @@
<div class="row row-buttons"> <div class="row row-buttons">
<div class="col-3 text-start"> <div class="col-3 text-start">
<img width="50" height="50" src="https://img.icons8.com/color/48/ms-excel.png" alt="ms-excel"/> <img width="50" height="50" src="https://img.icons8.com/color/48/ms-excel.png" alt="ms-excel"/>
<button type="button" class="btn btn-success" id="download2">다운로드</button> <button type="button" class="btn btn-success" id="downlodeExcelList2">리스트 다운로드</button>
</div> </div>
<div class="col-6 d-flex justify-content-center"> <div class="col-6 d-flex justify-content-center">
<nav> <nav>
@@ -241,6 +241,14 @@
$(document).ready(function () { $(document).ready(function () {
$("#downlodeExcelList,downlodeExcelList2").on("click",function(){
var form = document.createElement("form");
form.action = "/vendor/downlodeExcelList";
form.method = "GET";
document.body.appendChild(form);
form.submit();
});
//POST방식으로 create폼화면 출력 //POST방식으로 create폼화면 출력
//탭 1 생성 버튼 //탭 1 생성 버튼

View File

@@ -115,6 +115,14 @@
form.submit(); form.submit();
}); });
$("#downlodeExcelList").on("click",function(){
var form = document.createElement("form");
form.action = "/vendor/downlodeExcelList";
form.method = "GET";
document.body.appendChild(form);
form.submit();
});
//POST방식으로 create폼화면 출력 //POST방식으로 create폼화면 출력
$("#createButton").on("click",function(){ $("#createButton").on("click",function(){
var form = document.createElement("form"); var form = document.createElement("form");