mirror of
https://github.com/suhf/No1WMS.git
synced 2026-02-04 19:54:00 +09:00
#update
This commit is contained in:
@@ -8,6 +8,7 @@ import java.io.OutputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
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"));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.no1.wms.stock;
|
||||
|
||||
|
||||
import com.no1.wms.excel.ExcelDownlodeUtils;
|
||||
import com.no1.wms.vendor.VendorDto;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
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.servlet.ModelAndView;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -20,6 +23,9 @@ public class StockController {
|
||||
@Autowired
|
||||
StockService service;
|
||||
|
||||
@Autowired
|
||||
ExcelDownlodeUtils excelDownlodeUtils;
|
||||
|
||||
// 탭 1 재고 리스트 출력
|
||||
@GetMapping("/list")
|
||||
public String list(@RequestParam(name = "searchn1", defaultValue = "0") int searchn1,
|
||||
@@ -221,4 +227,24 @@ public class StockController {
|
||||
//테스트
|
||||
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);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ import java.util.Map;
|
||||
|
||||
@Mapper
|
||||
public interface StockMapper {
|
||||
List<Map<String, Object>> selectAll();
|
||||
|
||||
int count(Map<String, Object> m);//검색 글 갯수
|
||||
|
||||
|
||||
@@ -142,6 +142,10 @@ public class StockService {
|
||||
return mapper.warehouseCount(m);
|
||||
}
|
||||
|
||||
public List<Map<String, Object>> selectAll() {
|
||||
return mapper.selectAll();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -130,8 +130,8 @@ public class VendorController {
|
||||
}
|
||||
|
||||
// 엑셀다운로드테스트
|
||||
@GetMapping("/vendor/downloadTest")
|
||||
public void downloadExcelTest(HttpServletResponse response) {
|
||||
@GetMapping("/vendor/downlodeExcelList")
|
||||
public void downlodeExcelList(HttpServletResponse response) {
|
||||
List<VendorDto> dto = service.selectAll();
|
||||
String excelFileName = "거래처 파일";
|
||||
String sheetName = "거래처";
|
||||
|
||||
@@ -5,6 +5,15 @@
|
||||
<mapper namespace="com.no1.wms.stock.StockMapper">
|
||||
|
||||
<!-- 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 count(s.id)
|
||||
|
||||
|
||||
@@ -96,7 +96,7 @@
|
||||
<div class="row row-buttons">
|
||||
<div class="col-3 text-start">
|
||||
<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 class="col-6 d-flex justify-content-center">
|
||||
<nav>
|
||||
@@ -192,7 +192,7 @@
|
||||
<div class="row row-buttons">
|
||||
<div class="col-3 text-start">
|
||||
<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 class="col-6 d-flex justify-content-center">
|
||||
<nav>
|
||||
@@ -241,6 +241,14 @@
|
||||
|
||||
|
||||
$(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폼화면 출력
|
||||
|
||||
//탭 1 생성 버튼
|
||||
|
||||
@@ -115,6 +115,14 @@
|
||||
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폼화면 출력
|
||||
$("#createButton").on("click",function(){
|
||||
var form = document.createElement("form");
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user