|
|
@ -812,7 +812,8 @@ public class LabelDataProcessorServiceImpl implements LabelDataProcessorService |
|
|
private boolean hasNumberFormatSettings(ReportLabelList element) { |
|
|
private boolean hasNumberFormatSettings(ReportLabelList element) { |
|
|
return element.getDecimalPlaces() != null || |
|
|
return element.getDecimalPlaces() != null || |
|
|
Boolean.TRUE.equals(element.getShowDecimalPlaces()) || |
|
|
Boolean.TRUE.equals(element.getShowDecimalPlaces()) || |
|
|
Boolean.TRUE.equals(element.getThousandsSeparator()); |
|
|
|
|
|
|
|
|
Boolean.TRUE.equals(element.getThousandsSeparator()) || |
|
|
|
|
|
(element.getFixedDigits() != null && element.getFixedDigits() > 0); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
@ -823,7 +824,8 @@ public class LabelDataProcessorServiceImpl implements LabelDataProcessorService |
|
|
// 尝试解析为数字 |
|
|
// 尝试解析为数字 |
|
|
BigDecimal number = new BigDecimal(text.trim()); |
|
|
BigDecimal number = new BigDecimal(text.trim()); |
|
|
return formatNumber(number, element.getDecimalPlaces(), |
|
|
return formatNumber(number, element.getDecimalPlaces(), |
|
|
element.getShowDecimalPlaces(), element.getThousandsSeparator(), element.getRoundHalfUp()); |
|
|
|
|
|
|
|
|
element.getShowDecimalPlaces(), element.getThousandsSeparator(), |
|
|
|
|
|
element.getRoundHalfUp(), element.getFixedDigits()); |
|
|
} catch (NumberFormatException e) { |
|
|
} catch (NumberFormatException e) { |
|
|
log.debug("文本无法解析为数字,保持原样: {}", text); |
|
|
log.debug("文本无法解析为数字,保持原样: {}", text); |
|
|
return text; |
|
|
return text; |
|
|
@ -832,14 +834,14 @@ public class LabelDataProcessorServiceImpl implements LabelDataProcessorService |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public String formatNumber(Object value, Integer decimalPlaces, Boolean showDecimalPlaces, Boolean thousandsSeparator) { |
|
|
public String formatNumber(Object value, Integer decimalPlaces, Boolean showDecimalPlaces, Boolean thousandsSeparator) { |
|
|
return formatNumber(value, decimalPlaces, showDecimalPlaces, thousandsSeparator, true); |
|
|
|
|
|
|
|
|
return formatNumber(value, decimalPlaces, showDecimalPlaces, thousandsSeparator, true, null); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 格式化数字数据(支持四舍五入或截断) |
|
|
* 格式化数字数据(支持四舍五入或截断) |
|
|
*/ |
|
|
*/ |
|
|
private String formatNumber(Object value, Integer decimalPlaces, Boolean showDecimalPlaces, |
|
|
private String formatNumber(Object value, Integer decimalPlaces, Boolean showDecimalPlaces, |
|
|
Boolean thousandsSeparator, Boolean roundHalfUp) { |
|
|
|
|
|
|
|
|
Boolean thousandsSeparator, Boolean roundHalfUp, Integer fixedDigits) { |
|
|
if (value == null) { |
|
|
if (value == null) { |
|
|
return ""; |
|
|
return ""; |
|
|
} |
|
|
} |
|
|
@ -866,7 +868,11 @@ public class LabelDataProcessorServiceImpl implements LabelDataProcessorService |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 创建格式化器 |
|
|
// 创建格式化器 |
|
|
DecimalFormat formatter = createNumberFormatter(scale, Boolean.TRUE.equals(thousandsSeparator)); |
|
|
|
|
|
|
|
|
DecimalFormat formatter = createNumberFormatter( |
|
|
|
|
|
scale, |
|
|
|
|
|
Boolean.TRUE.equals(thousandsSeparator), |
|
|
|
|
|
fixedDigits |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
// 设置舍入模式:默认四舍五入;取消勾选时按小数位截断 |
|
|
// 设置舍入模式:默认四舍五入;取消勾选时按小数位截断 |
|
|
boolean useHalfUp = roundHalfUp == null || Boolean.TRUE.equals(roundHalfUp); |
|
|
boolean useHalfUp = roundHalfUp == null || Boolean.TRUE.equals(roundHalfUp); |
|
|
@ -883,13 +889,20 @@ public class LabelDataProcessorServiceImpl implements LabelDataProcessorService |
|
|
/** |
|
|
/** |
|
|
* 创建数字格式化器 |
|
|
* 创建数字格式化器 |
|
|
*/ |
|
|
*/ |
|
|
private DecimalFormat createNumberFormatter(int decimalPlaces, boolean useThousandsSeparator) { |
|
|
|
|
|
|
|
|
private DecimalFormat createNumberFormatter(int decimalPlaces, boolean useThousandsSeparator, Integer fixedDigits) { |
|
|
StringBuilder pattern = new StringBuilder(); |
|
|
StringBuilder pattern = new StringBuilder(); |
|
|
|
|
|
boolean useFixedDigits = fixedDigits != null && fixedDigits > 0; |
|
|
|
|
|
|
|
|
if (useThousandsSeparator) { |
|
|
if (useThousandsSeparator) { |
|
|
pattern.append("#,##0"); |
|
|
|
|
|
|
|
|
pattern.append(useFixedDigits ? buildFixedIntegerPattern(fixedDigits) : "#,##0"); |
|
|
} else { |
|
|
} else { |
|
|
pattern.append("0"); |
|
|
|
|
|
|
|
|
if (useFixedDigits) { |
|
|
|
|
|
for (int i = 0; i < fixedDigits; i++) { |
|
|
|
|
|
pattern.append("0"); |
|
|
|
|
|
} |
|
|
|
|
|
} else { |
|
|
|
|
|
pattern.append("0"); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (decimalPlaces > 0) { |
|
|
if (decimalPlaces > 0) { |
|
|
@ -902,6 +915,20 @@ public class LabelDataProcessorServiceImpl implements LabelDataProcessorService |
|
|
return new DecimalFormat(pattern.toString()); |
|
|
return new DecimalFormat(pattern.toString()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 构建带千分位的固定位数整数格式(示例:6 -> 000,000) |
|
|
|
|
|
*/ |
|
|
|
|
|
private String buildFixedIntegerPattern(int fixedDigits) { |
|
|
|
|
|
StringBuilder pattern = new StringBuilder(); |
|
|
|
|
|
for (int i = fixedDigits; i > 0; i--) { |
|
|
|
|
|
pattern.append("0"); |
|
|
|
|
|
if (i > 1 && (i - 1) % 3 == 0) { |
|
|
|
|
|
pattern.append(","); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
return pattern.toString(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public String replaceDataSourceFields(String text, Map<String, Object> dataMap) { |
|
|
public String replaceDataSourceFields(String text, Map<String, Object> dataMap) { |
|
|
if (text == null || text.isEmpty()) { |
|
|
if (text == null || text.isEmpty()) { |
|
|
@ -1612,6 +1639,7 @@ public class LabelDataProcessorServiceImpl implements LabelDataProcessorService |
|
|
copy.setShowDecimalPlaces(original.getShowDecimalPlaces()); |
|
|
copy.setShowDecimalPlaces(original.getShowDecimalPlaces()); |
|
|
copy.setThousandsSeparator(original.getThousandsSeparator()); |
|
|
copy.setThousandsSeparator(original.getThousandsSeparator()); |
|
|
copy.setRoundHalfUp(original.getRoundHalfUp()); |
|
|
copy.setRoundHalfUp(original.getRoundHalfUp()); |
|
|
|
|
|
copy.setFixedDigits(original.getFixedDigits()); |
|
|
copy.setDigits(original.getDigits()); |
|
|
copy.setDigits(original.getDigits()); |
|
|
copy.setStep(original.getStep()); |
|
|
copy.setStep(original.getStep()); |
|
|
|
|
|
|
|
|
|