Commit 7df02a6f by zhouhaibao

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

- 在BatchStoreCombinedExcelDTO中将PercentStringConverter替换为PercentAndNumberConverter
- 在SingleStoreExcelDTO中将PercentStringConverter和NumberStringConverter替换为PercentAndNumberConverter
- 添加新的PercentAndNumberConverter类来统一处理百分比和数值格式转换
- 新转换器支持百分比格式(带%符号)和普通数值格式的数据转换
- 保留原有的数值精度处理和空值处理逻辑
1 parent 5fce09b8
...@@ -68,7 +68,7 @@ public class BatchStoreCombinedExcelDTO { ...@@ -68,7 +68,7 @@ public class BatchStoreCombinedExcelDTO {
@FillFromPreviousRow @FillFromPreviousRow
private String trafficPartyProfitType; private String trafficPartyProfitType;
@ExcelProperty(value = "*流量方比例", index = 17, converter = PercentStringConverter.class) @ExcelProperty(value = "*流量方比例", index = 17, converter = PercentAndNumberConverter.class)
@FillFromPreviousRow @FillFromPreviousRow
private BigDecimal trafficPartyRatio; private BigDecimal trafficPartyRatio;
...@@ -92,7 +92,7 @@ public class BatchStoreCombinedExcelDTO { ...@@ -92,7 +92,7 @@ public class BatchStoreCombinedExcelDTO {
@FillFromPreviousRow @FillFromPreviousRow
private String serviceProviderProfitType; private String serviceProviderProfitType;
@ExcelProperty(value = "*服务商比例", index = 23, converter = PercentStringConverter.class) @ExcelProperty(value = "*服务商比例", index = 23, converter = PercentAndNumberConverter.class)
@FillFromPreviousRow @FillFromPreviousRow
private BigDecimal serviceProviderRatio; private BigDecimal serviceProviderRatio;
...@@ -112,7 +112,7 @@ public class BatchStoreCombinedExcelDTO { ...@@ -112,7 +112,7 @@ public class BatchStoreCombinedExcelDTO {
@FillFromPreviousRow @FillFromPreviousRow
private String resourceFeeProfitType; private String resourceFeeProfitType;
@ExcelProperty(value = "*资源费比例", index = 28, converter = PercentStringConverter.class) @ExcelProperty(value = "*资源费比例", index = 28, converter = PercentAndNumberConverter.class)
@FillFromPreviousRow @FillFromPreviousRow
private BigDecimal resourceFeeRatio; private BigDecimal resourceFeeRatio;
...@@ -124,7 +124,7 @@ public class BatchStoreCombinedExcelDTO { ...@@ -124,7 +124,7 @@ public class BatchStoreCombinedExcelDTO {
@FillFromPreviousRow @FillFromPreviousRow
private String otherFeeProfitType; private String otherFeeProfitType;
@ExcelProperty(value = "*其他费用分润比例", index = 31, converter = PercentStringConverter.class) @ExcelProperty(value = "*其他费用分润比例", index = 31, converter = PercentAndNumberConverter.class)
@FillFromPreviousRow @FillFromPreviousRow
private BigDecimal otherFeeRatio; private BigDecimal otherFeeRatio;
...@@ -144,7 +144,7 @@ public class BatchStoreCombinedExcelDTO { ...@@ -144,7 +144,7 @@ public class BatchStoreCombinedExcelDTO {
@FillFromPreviousRow @FillFromPreviousRow
private String managementMarketFee1CalculationMethod; private String managementMarketFee1CalculationMethod;
@ExcelProperty(value = "*管理层市场费1", index = 36, converter = NumberStringConverter.class) @ExcelProperty(value = "*管理层市场费1", index = 36, converter = PercentAndNumberConverter.class)
@FillFromPreviousRow @FillFromPreviousRow
private BigDecimal managementMarketFee1; private BigDecimal managementMarketFee1;
...@@ -156,7 +156,7 @@ public class BatchStoreCombinedExcelDTO { ...@@ -156,7 +156,7 @@ public class BatchStoreCombinedExcelDTO {
@FillFromPreviousRow @FillFromPreviousRow
private String managementMarketFee2CalculationMethod; private String managementMarketFee2CalculationMethod;
@ExcelProperty(value = "*管理层市场费2", index = 39, converter = NumberStringConverter.class) @ExcelProperty(value = "*管理层市场费2", index = 39, converter = PercentAndNumberConverter.class)
@FillFromPreviousRow @FillFromPreviousRow
private BigDecimal managementMarketFee2; private BigDecimal managementMarketFee2;
...@@ -176,7 +176,7 @@ public class BatchStoreCombinedExcelDTO { ...@@ -176,7 +176,7 @@ public class BatchStoreCombinedExcelDTO {
@FillFromPreviousRow @FillFromPreviousRow
private String sunshineCalculationMethod; private String sunshineCalculationMethod;
@ExcelProperty(value = "*一线阳光激励费", index = 44, converter = NumberStringConverter.class) @ExcelProperty(value = "*一线阳光激励费", index = 44, converter = PercentAndNumberConverter.class)
@FillFromPreviousRow @FillFromPreviousRow
private BigDecimal sunshineIncentiveFee; private BigDecimal sunshineIncentiveFee;
...@@ -192,7 +192,7 @@ public class BatchStoreCombinedExcelDTO { ...@@ -192,7 +192,7 @@ public class BatchStoreCombinedExcelDTO {
@FillFromPreviousRow @FillFromPreviousRow
private String sunshine2CalculationMethod; private String sunshine2CalculationMethod;
@ExcelProperty(value = "*一线阳光2激励费", index = 48, converter = NumberStringConverter.class) @ExcelProperty(value = "*一线阳光2激励费", index = 48, converter = PercentAndNumberConverter.class)
@FillFromPreviousRow @FillFromPreviousRow
private BigDecimal sunshine2IncentiveFee; 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 { ...@@ -72,7 +72,7 @@ public class SingleStoreExcelDTO {
private String trafficPartyProfitType; private String trafficPartyProfitType;
@ExcelMergeRow(columIndex = 15) @ExcelMergeRow(columIndex = 15)
@ExcelProperty(value = "*流量方比例", index = 15, converter = PercentStringConverter.class) @ExcelProperty(value = "*流量方比例", index = 15, converter = PercentAndNumberConverter.class)
private BigDecimal trafficPartyRatio; private BigDecimal trafficPartyRatio;
@ExcelMergeRow(columIndex = 16) @ExcelMergeRow(columIndex = 16)
...@@ -98,7 +98,7 @@ public class SingleStoreExcelDTO { ...@@ -98,7 +98,7 @@ public class SingleStoreExcelDTO {
private String serviceProviderProfitType; private String serviceProviderProfitType;
@ExcelMergeRow(columIndex = 21) @ExcelMergeRow(columIndex = 21)
@ExcelProperty(value = "*服务商比例", index = 21, converter = PercentStringConverter.class) @ExcelProperty(value = "*服务商比例", index = 21, converter = PercentAndNumberConverter.class)
private BigDecimal serviceProviderRatio; private BigDecimal serviceProviderRatio;
@ExcelMergeRow(columIndex = 22) @ExcelMergeRow(columIndex = 22)
...@@ -120,7 +120,7 @@ public class SingleStoreExcelDTO { ...@@ -120,7 +120,7 @@ public class SingleStoreExcelDTO {
private String resourceFeeProfitType; private String resourceFeeProfitType;
@ExcelMergeRow(columIndex = 26) @ExcelMergeRow(columIndex = 26)
@ExcelProperty(value = "*资源费比例", index = 26, converter = PercentStringConverter.class) @ExcelProperty(value = "*资源费比例", index = 26, converter = PercentAndNumberConverter.class)
private BigDecimal resourceFeeRatio; private BigDecimal resourceFeeRatio;
@ExcelMergeRow(columIndex = 27) @ExcelMergeRow(columIndex = 27)
...@@ -132,7 +132,7 @@ public class SingleStoreExcelDTO { ...@@ -132,7 +132,7 @@ public class SingleStoreExcelDTO {
private String otherFeeProfitType; private String otherFeeProfitType;
@ExcelMergeRow(columIndex = 29) @ExcelMergeRow(columIndex = 29)
@ExcelProperty(value = "*其他费用分润比例", index = 29, converter = PercentStringConverter.class) @ExcelProperty(value = "*其他费用分润比例", index = 29, converter = PercentAndNumberConverter.class)
private BigDecimal otherFeeRatio; private BigDecimal otherFeeRatio;
@ExcelMergeRow(columIndex = 30) @ExcelMergeRow(columIndex = 30)
...@@ -154,7 +154,7 @@ public class SingleStoreExcelDTO { ...@@ -154,7 +154,7 @@ public class SingleStoreExcelDTO {
private String managementMarketFee1CalculationMethod; private String managementMarketFee1CalculationMethod;
@ExcelMergeRow(columIndex = 34) @ExcelMergeRow(columIndex = 34)
@ExcelProperty(value = "*管理层市场费1", index = 34, converter = NumberStringConverter.class) @ExcelProperty(value = "*管理层市场费1", index = 34, converter = PercentAndNumberConverter.class)
private BigDecimal managementMarketFee1; private BigDecimal managementMarketFee1;
@ExcelMergeRow(columIndex = 35) @ExcelMergeRow(columIndex = 35)
...@@ -166,7 +166,7 @@ public class SingleStoreExcelDTO { ...@@ -166,7 +166,7 @@ public class SingleStoreExcelDTO {
private String managementMarketFee2CalculationMethod; private String managementMarketFee2CalculationMethod;
@ExcelMergeRow(columIndex = 37) @ExcelMergeRow(columIndex = 37)
@ExcelProperty(value = "*管理层市场费2", index = 37, converter = NumberStringConverter.class) @ExcelProperty(value = "*管理层市场费2", index = 37, converter = PercentAndNumberConverter.class)
private BigDecimal managementMarketFee2; private BigDecimal managementMarketFee2;
@ExcelMergeRow(columIndex = 38) @ExcelMergeRow(columIndex = 38)
...@@ -188,7 +188,7 @@ public class SingleStoreExcelDTO { ...@@ -188,7 +188,7 @@ public class SingleStoreExcelDTO {
private String sunshineCalculationMethod; private String sunshineCalculationMethod;
@ExcelMergeRow(columIndex = 42) @ExcelMergeRow(columIndex = 42)
@ExcelProperty(value = "*一线阳光激励费", index = 42, converter = NumberStringConverter.class) @ExcelProperty(value = "*一线阳光激励费", index = 42, converter = PercentAndNumberConverter.class)
private BigDecimal sunshineIncentiveFee; private BigDecimal sunshineIncentiveFee;
@ExcelMergeRow(columIndex = 43) @ExcelMergeRow(columIndex = 43)
...@@ -205,7 +205,7 @@ public class SingleStoreExcelDTO { ...@@ -205,7 +205,7 @@ public class SingleStoreExcelDTO {
private String sunshine2CalculationMethod; private String sunshine2CalculationMethod;
@ExcelMergeRow(columIndex = 46) @ExcelMergeRow(columIndex = 46)
@ExcelProperty(value = "*一线阳光2激励费", index = 46, converter = NumberStringConverter.class) @ExcelProperty(value = "*一线阳光2激励费", index = 46, converter = PercentAndNumberConverter.class)
private BigDecimal sunshine2IncentiveFee; private BigDecimal sunshine2IncentiveFee;
@ExcelMergeRow(columIndex = 47) @ExcelMergeRow(columIndex = 47)
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!