엑셀다운로드 관련 함수 위치 변경

This commit is contained in:
LAPTOP-L3VE7KK2\USER 2024-11-21 16:05:39 +09:00
parent 1309504606
commit bee5c7059f
2 changed files with 62 additions and 65 deletions

View File

@ -34,18 +34,11 @@ import com.interplug.qcast.util.InterfaceQsp;
import com.interplug.qcast.util.PdfUtil;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.beans.BeanInfo;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.io.IOException;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import lombok.RequiredArgsConstructor;
@ -1019,8 +1012,8 @@ public class EstimateService {
excelUtil.download(
request,
response,
this.convertVoToMap(estimateResponse),
this.convertListToMap(estimateItemList),
excelUtil.convertVoToMap(estimateResponse),
excelUtil.convertListToMap(estimateItemList),
estimateRequest.getFileName(),
excelTemplateNam);
}
@ -1557,60 +1550,6 @@ public class EstimateService {
return doc;
}
/**
* Object => Map 변환 함수
*
* @param vo Object
* @return Map<String, Object> Map 변환 정보
*/
public Map<String, Object> convertVoToMap(Object vo) {
Map<String, Object> result = new HashMap<String, Object>();
try {
BeanInfo info = Introspector.getBeanInfo(vo.getClass());
for (PropertyDescriptor pd : info.getPropertyDescriptors()) {
Method reader = pd.getReadMethod();
if (reader != null) {
result.put(pd.getName(), reader.invoke(vo));
}
}
} catch (Exception e) {
log.error("convertVoToMap >>> " + e.getMessage());
}
return result;
}
/**
* List<Object> => List<Map> 변환 함수
*
* @param target List<Object>
* @return List<Map<String, Object>> List<Map> 변환 정보
*/
public static <T> List<Map<String, Object>> convertListToMap(Collection<T> target) {
List<Map<String, Object>> resultList = new ArrayList<Map<String, Object>>();
for (T element : target) {
Map<String, Object> resultMap = new HashMap<String, Object>();
Field[] fieldList = element.getClass().getDeclaredFields();
if (fieldList != null && fieldList.length > 0) {
try {
for (int i = 0; i < fieldList.length; i++) {
String curInsName = fieldList[i].getName();
Field field = element.getClass().getDeclaredField(curInsName);
field.setAccessible(true);
Object targetValue = field.get(element);
resultMap.put(curInsName, targetValue);
}
resultList.add(resultMap);
} catch (Exception e) {
log.error("convertListToMap >>> " + e.getMessage());
}
}
}
return resultList;
}
/**
* Plan 확정 정보 동기화
*

View File

@ -3,9 +3,13 @@ package com.interplug.qcast.util;
import com.fasterxml.jackson.databind.exc.InvalidFormatException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.beans.BeanInfo;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.io.*;
import java.util.List;
import java.util.Map;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.*;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import net.sf.jxls.exception.ParsePropertyException;
@ -60,4 +64,58 @@ public class ExcelUtil {
log.debug(e.getMessage());
}
}
/**
* Object => Map 변환 함수
*
* @param vo Object
* @return Map<String, Object> Map 변환 정보
*/
public Map<String, Object> convertVoToMap(Object vo) {
Map<String, Object> result = new HashMap<String, Object>();
try {
BeanInfo info = Introspector.getBeanInfo(vo.getClass());
for (PropertyDescriptor pd : info.getPropertyDescriptors()) {
Method reader = pd.getReadMethod();
if (reader != null) {
result.put(pd.getName(), reader.invoke(vo));
}
}
} catch (Exception e) {
log.error("convertVoToMap >>> " + e.getMessage());
}
return result;
}
/**
* List<Object> => List<Map> 변환 함수
*
* @param target List<Object>
* @return List<Map<String, Object>> List<Map> 변환 정보
*/
public static <T> List<Map<String, Object>> convertListToMap(Collection<T> target) {
List<Map<String, Object>> resultList = new ArrayList<Map<String, Object>>();
for (T element : target) {
Map<String, Object> resultMap = new HashMap<String, Object>();
Field[] fieldList = element.getClass().getDeclaredFields();
if (fieldList != null && fieldList.length > 0) {
try {
for (int i = 0; i < fieldList.length; i++) {
String curInsName = fieldList[i].getName();
Field field = element.getClass().getDeclaredField(curInsName);
field.setAccessible(true);
Object targetValue = field.get(element);
resultMap.put(curInsName, targetValue);
}
resultList.add(resultMap);
} catch (Exception e) {
log.error("convertListToMap >>> " + e.getMessage());
}
}
}
return resultList;
}
}