mirror of
https://github.com/suhf/No1WMS.git
synced 2026-02-05 19:53:26 +09:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -18,6 +18,7 @@ public class ExcelRequestManager {
|
||||
public List<HashMap<String, String>> parseExcelSpringMultiPart
|
||||
(Map<String, MultipartFile> files , String KeyStr, int fileKeyParam,String atchFileId ,String storePath,HttpServletRequest request) throws Exception{
|
||||
List<HashMap<String, String>> list = null;
|
||||
|
||||
int fileKey = fileKeyParam;
|
||||
|
||||
String storePathString = "";
|
||||
|
||||
@@ -8,6 +8,9 @@ import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.google.gson.Gson;
|
||||
import com.no1.wms.account.AccountDto;
|
||||
import com.no1.wms.utils.ConstantValues;
|
||||
import com.no1.wms.utils.Utils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
@@ -16,6 +19,8 @@ import org.springframework.web.servlet.ModelAndView;
|
||||
import com.no1.wms.product.ProductDto;
|
||||
import com.no1.wms.product.ProductService;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
|
||||
@Controller
|
||||
@@ -42,6 +47,17 @@ public class PlanInController {
|
||||
|
||||
//스톡서비스로 재고 리스트 출력 메서트 작성
|
||||
List<PlanInDto> list = planinservice.selectAll(searchn, search, startRow, perPage);
|
||||
HashMap<String, Integer> map = new HashMap<>();
|
||||
for( int i = 0 ; i < list.size(); ++i){
|
||||
PlanInDto obj = list.get(i);
|
||||
String name = obj.getProductDto().getName();
|
||||
if(map.containsKey(name)){
|
||||
map.put(name, map.get(name)+1);
|
||||
}else{
|
||||
map.put(name, 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int begin = (page - 1) / pageNum * pageNum + 1;
|
||||
int end = begin + pageNum - 1;
|
||||
@@ -49,6 +65,7 @@ public class PlanInController {
|
||||
end = totalPages;
|
||||
}
|
||||
mav.addObject("list", list);
|
||||
mav.addObject("map", map);
|
||||
mav.addObject("end", end);
|
||||
mav.addObject("searchn", searchn);
|
||||
mav.addObject("search", search);
|
||||
@@ -67,29 +84,43 @@ public class PlanInController {
|
||||
System.out.println(list.get(0).toString());
|
||||
mav.addObject("list", list);
|
||||
mav.addObject("groupNum", dto.getGroupNumber());
|
||||
|
||||
mav.setViewName("planin/read");
|
||||
|
||||
return mav;
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/update")
|
||||
public ModelAndView update(PlanInDto dto, ModelAndView mav){
|
||||
List<PlanInDto> list = planinservice.selectById(dto);
|
||||
mav.addObject("list", list);
|
||||
|
||||
mav.addObject("groupNumber", dto.getGroupNumber());
|
||||
mav.addObject("viewGroupNumber", list.get(0).getViewGroupNumber());
|
||||
mav.setViewName("/planin/update");
|
||||
|
||||
return mav;
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/create")
|
||||
public ModelAndView create(ModelAndView mav){
|
||||
mav.addObject("groupNumber",UUID.randomUUID().toString() );
|
||||
mav.setViewName("/planin/create");
|
||||
|
||||
return mav;
|
||||
}
|
||||
|
||||
|
||||
// 엑셀 다운로드
|
||||
@GetMapping("/qr/{id}")
|
||||
public String qr(@PathVariable("id")String id)
|
||||
@ResponseBody
|
||||
public String qr(@PathVariable("id")String id, HttpServletResponse response)
|
||||
{
|
||||
|
||||
|
||||
return "";
|
||||
List<PlanInDto> list = planinservice.selectByUrl(id);
|
||||
|
||||
Utils.makePlanInExcel(list, response);
|
||||
|
||||
|
||||
|
||||
return "s";
|
||||
}
|
||||
|
||||
// 입고예정추가
|
||||
@@ -122,31 +153,66 @@ public class PlanInController {
|
||||
return mav;
|
||||
}
|
||||
|
||||
@PostMapping("/delete")
|
||||
public ModelAndView delete(ModelAndView mav, PlanInDto dto)
|
||||
{
|
||||
|
||||
|
||||
planinservice.delete(dto);
|
||||
List<PlanInDto> list = planinservice.selectAll(0,"",0,10000 );
|
||||
|
||||
mav.addObject("list", list);
|
||||
mav.setViewName("planin/list");
|
||||
|
||||
return mav;
|
||||
}
|
||||
|
||||
@PostMapping("/planin_update_process")
|
||||
@ResponseBody
|
||||
public String updateProcess(@RequestBody List<Map<String, Object>> list, Gson gson, PlanInDto dto) throws JsonProcessingException, ParseException {
|
||||
public String updateProcess(@RequestBody List<Map<String, Object>> list, Gson gson, PlanInDto dto, HttpServletRequest request) throws ParseException {
|
||||
|
||||
if(list.isEmpty())
|
||||
return gson.toJson("f");
|
||||
|
||||
AccountDto aDto =(AccountDto)request.getSession().getAttribute("userData");
|
||||
|
||||
dto.setGroupNumber((String) list.get(0).get("groupNumber"));
|
||||
|
||||
Integer viewGroupNumber = null;
|
||||
try {
|
||||
viewGroupNumber = Integer.parseInt((String) list.get(0).get("viewGroupNumber"));
|
||||
}catch (NumberFormatException e){
|
||||
viewGroupNumber = null;
|
||||
}
|
||||
String uuid;
|
||||
planinservice.deleteById(dto);
|
||||
|
||||
|
||||
if(dto.getGroupNumber() == null){
|
||||
uuid = UUID.randomUUID().toString();
|
||||
}else{
|
||||
uuid = dto.getGroupNumber();
|
||||
}
|
||||
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
|
||||
|
||||
|
||||
for(int i = 0; i < list.size(); ++i){
|
||||
Map<String, Object> data = list.get(i);
|
||||
PlanInDto newDto = new PlanInDto();
|
||||
newDto.setGroupNumber(uuid);
|
||||
newDto.setGroupNumber((String) data.get("groupNumber"));
|
||||
newDto.setDate( format.parse((String) data.get("date")));
|
||||
newDto.setQuantity((Integer) data.get("quantity"));
|
||||
newDto.setQuantity(Integer.parseInt((String) data.get("quantity")));
|
||||
newDto.setProductId((String)data.get("productId"));
|
||||
newDto.setManagerId(aDto.getId());
|
||||
newDto.setWarehouseId("5d201e83-b102-11ee-935d-0242ac110006");
|
||||
newDto.setViewGroupNumber(viewGroupNumber);
|
||||
|
||||
newDto.setActivation(true);
|
||||
|
||||
planinservice.insert(newDto);
|
||||
}
|
||||
|
||||
|
||||
|
||||
return gson.toJson("s");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -31,9 +31,8 @@ public class PlanInDto {
|
||||
private String warehouseId;
|
||||
private String qrHash;
|
||||
private String url;
|
||||
private Boolean clear;
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd")
|
||||
private Date vendorDate;
|
||||
@Builder.Default
|
||||
private Boolean clear = false;
|
||||
private String other;
|
||||
private Boolean activation;
|
||||
private Integer viewGroupNumber;
|
||||
|
||||
@@ -16,7 +16,11 @@ public interface PlanInMapper {
|
||||
|
||||
List<PlanInDto> selectById(PlanInDto dto);
|
||||
|
||||
List<PlanInDto> selectByUrl(String id);
|
||||
|
||||
int deleteById(PlanInDto dto);
|
||||
|
||||
void insert(PlanInDto dto);
|
||||
|
||||
int delete(PlanInDto dto);
|
||||
}
|
||||
|
||||
@@ -40,4 +40,16 @@ public class PlanInService {
|
||||
void insert(PlanInDto dto){
|
||||
mapper.insert(dto);
|
||||
}
|
||||
|
||||
int delete(PlanInDto dto){
|
||||
return mapper.delete(dto);
|
||||
}
|
||||
|
||||
List<PlanInDto> selectByUrl(String id) {
|
||||
|
||||
return mapper.selectByUrl(id);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -2,4 +2,8 @@ package com.no1.wms.utils;
|
||||
|
||||
public class ConstantValues {
|
||||
public static final int PER_PAGE = 1000;
|
||||
|
||||
public static final String PNG_TYPE = "img/png";
|
||||
|
||||
public static final String EXCEL_TYPE= "ms-vnd/excel";
|
||||
}
|
||||
|
||||
@@ -1,7 +1,175 @@
|
||||
package com.no1.wms.utils;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.MultiFormatWriter;
|
||||
import com.google.zxing.WriterException;
|
||||
import com.google.zxing.client.j2se.MatrixToImageWriter;
|
||||
import com.google.zxing.common.BitMatrix;
|
||||
import com.no1.wms.category.CategoryDto;
|
||||
import com.no1.wms.planin.PlanInDto;
|
||||
import org.apache.poi.ss.usermodel.*;
|
||||
import org.apache.poi.xssf.usermodel.*;
|
||||
|
||||
import javax.servlet.ServletOutputStream;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class Utils {
|
||||
public static byte[] makeQr(String url) {
|
||||
// QR 정보
|
||||
int width = 200;
|
||||
int height = 200;
|
||||
BitMatrix encode = null;
|
||||
try {
|
||||
// QR Code - BitMatrix: qr code 정보 생성
|
||||
encode = new MultiFormatWriter()
|
||||
.encode(url, BarcodeFormat.QR_CODE, width, height);
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
if(encode == null)
|
||||
return null;
|
||||
|
||||
// QR Code - Image 생성. : 1회성으로 생성해야 하기 때문에
|
||||
// stream으로 Generate(1회성이 아니면 File로 작성 가능.)
|
||||
try {
|
||||
//output Stream
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
|
||||
//Bitmatrix, file.format, outputStream
|
||||
MatrixToImageWriter.writeToStream(encode, "PNG", out);
|
||||
|
||||
return out.toByteArray();
|
||||
|
||||
} catch (Exception e) {
|
||||
System.err.println("QR Code OutputStream 도중 Excpetion 발생, " + e.getMessage());
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void download(String fileName, byte[] data, String contentType, HttpServletResponse response ) {
|
||||
|
||||
try {
|
||||
fileName = new String((fileName).getBytes("utf-8"), "iso-8859-1");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
response.setContentType(contentType);
|
||||
response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\";");
|
||||
|
||||
try(ServletOutputStream os = response.getOutputStream();) {
|
||||
os.write(data);
|
||||
response.flushBuffer();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void makePlanInExcel(List<PlanInDto> list, HttpServletResponse response){
|
||||
XSSFWorkbook xssfWorkbook = new XSSFWorkbook();
|
||||
|
||||
int rowNum = 0;
|
||||
XSSFCellStyle cellStyle = null;
|
||||
cellStyle = xssfWorkbook.createCellStyle();
|
||||
cellStyle.setAlignment(HorizontalAlignment.CENTER);
|
||||
cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
|
||||
cellStyle.setFillBackgroundColor(IndexedColors.BLACK.getIndex());
|
||||
XSSFFont font = xssfWorkbook.createFont();
|
||||
font.setColor(IndexedColors.WHITE.getIndex());
|
||||
font.setBold(true);
|
||||
|
||||
cellStyle.setFont(font);
|
||||
XSSFSheet sheet = xssfWorkbook.createSheet("자료");
|
||||
Row topRow = sheet.createRow(0);
|
||||
Cell cell = null;
|
||||
cell = topRow.createCell(0);
|
||||
cell.setCellValue("카테고리");
|
||||
cell.setCellStyle(cellStyle);
|
||||
cell = topRow.createCell(1);
|
||||
cell.setCellValue("제품명");
|
||||
cell.setCellStyle(cellStyle);
|
||||
cell = topRow.createCell(2);
|
||||
cell.setCellValue("수량");
|
||||
cell.setCellStyle(cellStyle);
|
||||
cell = topRow.createCell(3);
|
||||
cell.setCellValue("공급업체");
|
||||
cell.setCellStyle(cellStyle);
|
||||
cell = topRow.createCell(4);
|
||||
cell.setCellValue("날짜");
|
||||
cell.setCellStyle(cellStyle);
|
||||
|
||||
cell = topRow.createCell(5);
|
||||
cell.setCellValue("QR");
|
||||
cell.setCellStyle(cellStyle);
|
||||
|
||||
|
||||
XSSFCreationHelper helper = xssfWorkbook.getCreationHelper();
|
||||
XSSFCellStyle dataCellStyle = xssfWorkbook.createCellStyle();
|
||||
dataCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
||||
dataCellStyle.setDataFormat(helper.createDataFormat().getFormat("yy-MM-dd"));
|
||||
sheet.setColumnWidth(5,(short)6000);
|
||||
|
||||
for( int i = 0 ; i < list.size(); ++i){
|
||||
|
||||
XSSFDrawing drawing = sheet.createDrawingPatriarch();
|
||||
XSSFClientAnchor anchor = helper.createClientAnchor();
|
||||
PlanInDto dto = list.get(i);
|
||||
System.out.println(dto);
|
||||
Row row = sheet.createRow(i+1);
|
||||
int cellNum = 0;
|
||||
row.setHeight((short) 3000);
|
||||
|
||||
row.createCell(cellNum++).setCellValue(dto.getCaName());
|
||||
setColumnSize(sheet, 0, dto.getCaName());
|
||||
row.createCell(cellNum++).setCellValue(dto.getProductDto().getName());
|
||||
setColumnSize(sheet, 1, dto.getProductDto().getName());
|
||||
row.createCell(cellNum++).setCellValue(dto.getQuantity());
|
||||
setColumnSize(sheet, 2, dto.getQuantity().toString());
|
||||
row.createCell(cellNum++).setCellValue(dto.getVendorDto().getName());
|
||||
setColumnSize(sheet, 3, dto.getVendorDto().getName());
|
||||
|
||||
Cell dateCell = row.createCell(cellNum);
|
||||
dateCell.setCellValue(dto.getDate());
|
||||
dateCell.setCellStyle(dataCellStyle);
|
||||
|
||||
anchor.setCol1(5);
|
||||
anchor.setRow1(i+1);
|
||||
String url = "http://localhost:8080/qr/"+dto.getUrl();
|
||||
int picIdx = xssfWorkbook.addPicture(Utils.makeQr(url), XSSFWorkbook.PICTURE_TYPE_PNG);
|
||||
XSSFPicture pic = drawing.createPicture(anchor,picIdx );
|
||||
pic.resize();
|
||||
|
||||
}
|
||||
try(ByteArrayOutputStream baos = new ByteArrayOutputStream();){
|
||||
xssfWorkbook.write(baos);
|
||||
download("QR데이터.xlsx", baos.toByteArray(), ConstantValues.EXCEL_TYPE, response);
|
||||
}catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
static void setColumnSize(XSSFSheet sheet, int index, String value) {
|
||||
int defaultColumnWidth = 2048;
|
||||
int maxLength = 70;
|
||||
int characterWidth = 256;
|
||||
double lengthWeight = 1.14388;
|
||||
int len = Math.min(value.length(), maxLength);
|
||||
int adjust = (((int)(len * lengthWeight) )* characterWidth) + defaultColumnWidth;
|
||||
|
||||
int columnWidth = sheet.getColumnWidth(index);
|
||||
if (columnWidth > adjust) return;
|
||||
|
||||
try {
|
||||
sheet.setColumnWidth(index, adjust);
|
||||
} catch (Exception e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user