[1157] DESING 견적 출력 시 중량표가 출력되지 않음 - 계산추가 #163

Merged
ysCha merged 1 commits from dev into dev-deploy 2025-07-10 17:32:01 +09:00
2 changed files with 34 additions and 0 deletions

View File

@ -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);
}
}
}