Commit 5a6e7fbd by 崔彦峰

modify:修改合同导出代码。

1 parent 362f41a9
...@@ -4,6 +4,7 @@ import com.alibaba.excel.annotation.ExcelProperty; ...@@ -4,6 +4,7 @@ import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.format.DateTimeFormat; import com.alibaba.excel.annotation.format.DateTimeFormat;
import com.gsc4cloud.gsc.vpc.api.util.excel.ExcelValueReplace; import com.gsc4cloud.gsc.vpc.api.util.excel.ExcelValueReplace;
import com.gsc4cloud.gsc.vpc.api.util.excel.ReplaceIntegerToStringConvert; import com.gsc4cloud.gsc.vpc.api.util.excel.ReplaceIntegerToStringConvert;
import com.gsc4cloud.gsc.vpc.api.util.excel.ReplaceStringToStringConvert;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
...@@ -113,6 +114,6 @@ public class EvalElectronicContractExportResDTO implements Serializable { ...@@ -113,6 +114,6 @@ public class EvalElectronicContractExportResDTO implements Serializable {
private Integer signerType; private Integer signerType;
@ExcelValueReplace(replace={"惠州广联_hzglsk","优加_szyjzh"},repeatValue=true) @ExcelValueReplace(replace={"惠州广联_hzglsk","优加_szyjzh"},repeatValue=true)
@ExcelProperty(value="合同企业主体") @ExcelProperty(value="合同企业主体", converter= ReplaceStringToStringConvert.class)
private String contractOrg; private String contractOrg;
} }
package com.gsc4cloud.gsc.vpc.api.util.excel;
import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.data.CellData;
import com.alibaba.excel.metadata.data.WriteCellData;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import org.apache.commons.collections4.BidiMap;
import org.apache.commons.collections4.bidimap.DualHashBidiMap;
import org.apache.commons.lang3.StringUtils;
import java.text.MessageFormat;
public class ReplaceStringToStringConvert implements Converter<String> {
private BidiMap data = null;
public ReplaceStringToStringConvert() {
}
public Class supportJavaTypeKey() {
return null;
}
public CellDataTypeEnum supportExcelTypeKey() {
return CellDataTypeEnum.STRING;
}
public String convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
if (cellData == null) {
return null;
} else {
String text = cellData.getStringValue();
if (StringUtils.isBlank(text)) {
return null;
} else {
ExcelValueReplace vr = (ExcelValueReplace) contentProperty.getField().getAnnotation(ExcelValueReplace.class);
if (vr != null) {
Object value = this.getValue(vr, contentProperty, text, false);
if (value != null) {
return value.toString();
}
}
return text;
}
}
}
public WriteCellData convertToExcelData(String value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
if (value == null) {
return new WriteCellData("");
} else {
ExcelValueReplace vr = (ExcelValueReplace) contentProperty.getField().getAnnotation(ExcelValueReplace.class);
if (vr != null) {
Object text = this.getValue(vr, contentProperty, value, true);
if (text != null) {
return new WriteCellData(text.toString());
}
}
return new WriteCellData(value);
}
}
private Object getValue(ExcelValueReplace vr, ExcelContentProperty contentProperty, String key, boolean isGetValue) {
String textMethod;
int var18;
if (vr.repeatValue()) {
if (vr != null && vr.replace() != null) {
String[] var15 = vr.replace();
int var17 = var15.length;
for (var18 = 0; var18 < var17; ++var18) {
textMethod = var15[var18];
String[] arr = textMethod.split("_");
if (arr.length < 2) {
throw new RuntimeException(MessageFormat.format("{0}.ExcelValueReplace.replace error", contentProperty.getField().getName()));
}
String text = arr[0];
String value = textMethod.substring(textMethod.indexOf("_") + 1);
if (isGetValue) {
if (value.equals(key)) {
return text;
}
} else if (text.equals(key)) {
return value;
}
}
}
return null;
} else if (this.data != null) {
return isGetValue ? this.data.get(key) : this.data.getKey(key);
} else {
this.data = new DualHashBidiMap();
Class<? extends Enum> enumClass = vr.enumClass();
if (enumClass != Enum.class) {
Enum[] bes = (Enum[]) enumClass.getEnumConstants();
String valueMethod = vr.enumValueMethod();
textMethod = vr.enumTextMethod();
Enum[] var9 = bes;
int var10 = bes.length;
for (int var11 = 0; var11 < var10; ++var11) {
Enum be = var9[var11];
Object value = EasyExcelConverterUtil.getValue(enumClass, be, new String[]{valueMethod});
Object text = EasyExcelConverterUtil.getValue(enumClass, be, new String[]{textMethod});
if (value == null || text == null) {
break;
}
this.data.put(value.toString(), text.toString());
}
}
if (vr != null && vr.replace() != null) {
String[] var16 = vr.replace();
var18 = var16.length;
for (int var19 = 0; var19 < var18; ++var19) {
String v = var16[var19];
String[] arr = v.split("_");
if (arr.length < 2) {
throw new RuntimeException(MessageFormat.format("{0}.ExcelValueReplace.replace error", contentProperty.getField().getName()));
}
this.data.put(v.substring(v.indexOf("_") + 1), arr[0]);
}
}
return isGetValue ? this.data.get(key) : this.data.getKey(key);
}
}
}
\ No newline at end of file \ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!