Merge pull request '[1157] DESING 견적 출력 시 중량표가 출력되지 않음 - 계산추가' (#164) from dev into prd-deploy
Reviewed-on: #164
This commit is contained in:
commit
4085cef279
@ -9,6 +9,7 @@ import java.beans.PropertyDescriptor;
|
||||
import java.io.*;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.*;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@ -22,6 +23,25 @@ import org.springframework.stereotype.Component;
|
||||
@RequiredArgsConstructor
|
||||
public class ExcelUtil {
|
||||
|
||||
// DecimalFormat 인스턴스를 미리 생성
|
||||
private static final DecimalFormat DECIMAL_FORMAT = new DecimalFormat("#,##0.000");
|
||||
|
||||
/**
|
||||
* 숫자 포맷팅을 위한 헬퍼 메서드
|
||||
*/
|
||||
public static String formatNumber(Object amount, Object grossWt) {
|
||||
try {
|
||||
if (amount != null && grossWt != null) {
|
||||
double amountValue = Double.parseDouble(amount.toString());
|
||||
double grossWtValue = Double.parseDouble(grossWt.toString());
|
||||
return DECIMAL_FORMAT.format(amountValue * grossWtValue);
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
log.warn("Number formatting error: {}", e.getMessage());
|
||||
}
|
||||
return "0.000";
|
||||
}
|
||||
|
||||
/**
|
||||
* jxls을 이용한 엑셀데이터 축출
|
||||
*
|
||||
@ -54,6 +74,11 @@ public class ExcelUtil {
|
||||
context.putVar("data", map);
|
||||
context.putVar("list", list);
|
||||
|
||||
// 포맷팅 함수를 컨텍스트에 추가
|
||||
context.putVar("formatNumber", new FormatNumberFunction());
|
||||
context.putVar("decimalFormat", DECIMAL_FORMAT);
|
||||
|
||||
|
||||
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
||||
JxlsHelper.getInstance().processTemplate(is, byteArrayOutputStream, context);
|
||||
|
||||
@ -162,4 +187,13 @@ public class ExcelUtil {
|
||||
}
|
||||
return resultList;
|
||||
}
|
||||
|
||||
/**
|
||||
* JXLS 템플릿에서 사용할 수 있는 포맷팅 함수 클래스
|
||||
*/
|
||||
public static class FormatNumberFunction {
|
||||
public String format(Object amount, Object grossWt) {
|
||||
return formatNumber(amount, grossWt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user