Commit 7df02a6f by zhouhaibao

feat(excel): 更新百分比和数值转换器以支持多种数据格式

- 在BatchStoreCombinedExcelDTO中将PercentStringConverter替换为PercentAndNumberConverter
- 在SingleStoreExcelDTO中将PercentStringConverter和NumberStringConverter替换为PercentAndNumberConverter
- 添加新的PercentAndNumberConverter类来统一处理百分比和数值格式转换
- 新转换器支持百分比格式(带%符号)和普通数值格式的数据转换
- 保留原有的数值精度处理和空值处理逻辑
1 parent 5fce09b8
......@@ -68,7 +68,7 @@ public class BatchStoreCombinedExcelDTO {
@FillFromPreviousRow
private String trafficPartyProfitType;
@ExcelProperty(value = "*流量方比例", index = 17, converter = PercentStringConverter.class)
@ExcelProperty(value = "*流量方比例", index = 17, converter = PercentAndNumberConverter.class)
@FillFromPreviousRow
private BigDecimal trafficPartyRatio;
......@@ -92,7 +92,7 @@ public class BatchStoreCombinedExcelDTO {
@FillFromPreviousRow
private String serviceProviderProfitType;
@ExcelProperty(value = "*服务商比例", index = 23, converter = PercentStringConverter.class)
@ExcelProperty(value = "*服务商比例", index = 23, converter = PercentAndNumberConverter.class)
@FillFromPreviousRow
private BigDecimal serviceProviderRatio;
......@@ -112,7 +112,7 @@ public class BatchStoreCombinedExcelDTO {
@FillFromPreviousRow
private String resourceFeeProfitType;
@ExcelProperty(value = "*资源费比例", index = 28, converter = PercentStringConverter.class)
@ExcelProperty(value = "*资源费比例", index = 28, converter = PercentAndNumberConverter.class)
@FillFromPreviousRow
private BigDecimal resourceFeeRatio;
......@@ -124,7 +124,7 @@ public class BatchStoreCombinedExcelDTO {
@FillFromPreviousRow
private String otherFeeProfitType;
@ExcelProperty(value = "*其他费用分润比例", index = 31, converter = PercentStringConverter.class)
@ExcelProperty(value = "*其他费用分润比例", index = 31, converter = PercentAndNumberConverter.class)
@FillFromPreviousRow
private BigDecimal otherFeeRatio;
......@@ -144,7 +144,7 @@ public class BatchStoreCombinedExcelDTO {
@FillFromPreviousRow
private String managementMarketFee1CalculationMethod;
@ExcelProperty(value = "*管理层市场费1", index = 36, converter = NumberStringConverter.class)
@ExcelProperty(value = "*管理层市场费1", index = 36, converter = PercentAndNumberConverter.class)
@FillFromPreviousRow
private BigDecimal managementMarketFee1;
......@@ -156,7 +156,7 @@ public class BatchStoreCombinedExcelDTO {
@FillFromPreviousRow
private String managementMarketFee2CalculationMethod;
@ExcelProperty(value = "*管理层市场费2", index = 39, converter = NumberStringConverter.class)
@ExcelProperty(value = "*管理层市场费2", index = 39, converter = PercentAndNumberConverter.class)
@FillFromPreviousRow
private BigDecimal managementMarketFee2;
......@@ -176,7 +176,7 @@ public class BatchStoreCombinedExcelDTO {
@FillFromPreviousRow
private String sunshineCalculationMethod;
@ExcelProperty(value = "*一线阳光激励费", index = 44, converter = NumberStringConverter.class)
@ExcelProperty(value = "*一线阳光激励费", index = 44, converter = PercentAndNumberConverter.class)
@FillFromPreviousRow
private BigDecimal sunshineIncentiveFee;
......@@ -192,7 +192,7 @@ public class BatchStoreCombinedExcelDTO {
@FillFromPreviousRow
private String sunshine2CalculationMethod;
@ExcelProperty(value = "*一线阳光2激励费", index = 48, converter = NumberStringConverter.class)
@ExcelProperty(value = "*一线阳光2激励费", index = 48, converter = PercentAndNumberConverter.class)
@FillFromPreviousRow
private BigDecimal sunshine2IncentiveFee;
......
package cn.com.glsx.dj.oaapproval.dto.excel;
import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.CellData;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import java.math.BigDecimal;
import java.math.RoundingMode;
import org.apache.commons.lang3.StringUtils;
public class PercentAndNumberConverter implements Converter<BigDecimal> {
@Override
public Class<?> supportJavaTypeKey() {
return BigDecimal.class;
}
@Override
public CellDataTypeEnum supportExcelTypeKey() {
return null;
}
@Override
public BigDecimal convertToJavaData(CellData cellData, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) throws Exception {
if (cellData == null) {
return null;
}
if (cellData.getStringValue() != null) {
String stringValue = cellData.getStringValue().trim();
if (stringValue.endsWith("%")) {
String numStr = stringValue.substring(0, stringValue.length() - 1).trim();
if (StringUtils.isEmpty(numStr)) {
return null;
}
try {
BigDecimal value = new BigDecimal(String.valueOf(numStr)).multiply(new BigDecimal("100"));
return value;
} catch (NumberFormatException e) {
return null;
}
}else{
try {
return new BigDecimal(stringValue);
} catch (NumberFormatException e) {
return null;
}
}
} else if (cellData.getNumberValue() != null) {
return cellData.getNumberValue();
} else {
return null;
}
}
@Override
public CellData<?> convertToExcelData(BigDecimal value, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
if (value == null) {
return new CellData<>("");
}
BigDecimal percentValue = value.multiply(new BigDecimal("100"));
return new CellData<>(percentValue.setScale(2, RoundingMode.HALF_UP) + "%");
}
}
......@@ -72,7 +72,7 @@ public class SingleStoreExcelDTO {
private String trafficPartyProfitType;
@ExcelMergeRow(columIndex = 15)
@ExcelProperty(value = "*流量方比例", index = 15, converter = PercentStringConverter.class)
@ExcelProperty(value = "*流量方比例", index = 15, converter = PercentAndNumberConverter.class)
private BigDecimal trafficPartyRatio;
@ExcelMergeRow(columIndex = 16)
......@@ -98,7 +98,7 @@ public class SingleStoreExcelDTO {
private String serviceProviderProfitType;
@ExcelMergeRow(columIndex = 21)
@ExcelProperty(value = "*服务商比例", index = 21, converter = PercentStringConverter.class)
@ExcelProperty(value = "*服务商比例", index = 21, converter = PercentAndNumberConverter.class)
private BigDecimal serviceProviderRatio;
@ExcelMergeRow(columIndex = 22)
......@@ -120,7 +120,7 @@ public class SingleStoreExcelDTO {
private String resourceFeeProfitType;
@ExcelMergeRow(columIndex = 26)
@ExcelProperty(value = "*资源费比例", index = 26, converter = PercentStringConverter.class)
@ExcelProperty(value = "*资源费比例", index = 26, converter = PercentAndNumberConverter.class)
private BigDecimal resourceFeeRatio;
@ExcelMergeRow(columIndex = 27)
......@@ -132,7 +132,7 @@ public class SingleStoreExcelDTO {
private String otherFeeProfitType;
@ExcelMergeRow(columIndex = 29)
@ExcelProperty(value = "*其他费用分润比例", index = 29, converter = PercentStringConverter.class)
@ExcelProperty(value = "*其他费用分润比例", index = 29, converter = PercentAndNumberConverter.class)
private BigDecimal otherFeeRatio;
@ExcelMergeRow(columIndex = 30)
......@@ -154,7 +154,7 @@ public class SingleStoreExcelDTO {
private String managementMarketFee1CalculationMethod;
@ExcelMergeRow(columIndex = 34)
@ExcelProperty(value = "*管理层市场费1", index = 34, converter = NumberStringConverter.class)
@ExcelProperty(value = "*管理层市场费1", index = 34, converter = PercentAndNumberConverter.class)
private BigDecimal managementMarketFee1;
@ExcelMergeRow(columIndex = 35)
......@@ -166,7 +166,7 @@ public class SingleStoreExcelDTO {
private String managementMarketFee2CalculationMethod;
@ExcelMergeRow(columIndex = 37)
@ExcelProperty(value = "*管理层市场费2", index = 37, converter = NumberStringConverter.class)
@ExcelProperty(value = "*管理层市场费2", index = 37, converter = PercentAndNumberConverter.class)
private BigDecimal managementMarketFee2;
@ExcelMergeRow(columIndex = 38)
......@@ -188,7 +188,7 @@ public class SingleStoreExcelDTO {
private String sunshineCalculationMethod;
@ExcelMergeRow(columIndex = 42)
@ExcelProperty(value = "*一线阳光激励费", index = 42, converter = NumberStringConverter.class)
@ExcelProperty(value = "*一线阳光激励费", index = 42, converter = PercentAndNumberConverter.class)
private BigDecimal sunshineIncentiveFee;
@ExcelMergeRow(columIndex = 43)
......@@ -205,7 +205,7 @@ public class SingleStoreExcelDTO {
private String sunshine2CalculationMethod;
@ExcelMergeRow(columIndex = 46)
@ExcelProperty(value = "*一线阳光2激励费", index = 46, converter = NumberStringConverter.class)
@ExcelProperty(value = "*一线阳光2激励费", index = 46, converter = PercentAndNumberConverter.class)
private BigDecimal sunshine2IncentiveFee;
@ExcelMergeRow(columIndex = 47)
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!