27 changed files with 396 additions and 159 deletions
@ -1,34 +0,0 @@ |
|||
package com.epmet.excel.converter; |
|||
|
|||
import com.alibaba.excel.converters.Converter; |
|||
import com.alibaba.excel.converters.ReadConverterContext; |
|||
import com.alibaba.excel.enums.CellDataTypeEnum; |
|||
import org.apache.commons.lang3.StringUtils; |
|||
|
|||
/** |
|||
* 灵山-是否转换器 |
|||
*/ |
|||
public class LingShanSpecialCrowdIsOrNotConverter implements Converter<Integer> { |
|||
@Override |
|||
public CellDataTypeEnum supportExcelTypeKey() { |
|||
return CellDataTypeEnum.STRING; |
|||
} |
|||
|
|||
@Override |
|||
public Class<?> supportJavaTypeKey() { |
|||
return Integer.class; |
|||
} |
|||
|
|||
@Override |
|||
public Integer convertToJavaData(ReadConverterContext<?> context) throws Exception { |
|||
String content = context.getReadCellData().getStringValue(); |
|||
if (StringUtils.isNotBlank(content)) { |
|||
if (content.equals("是") || content.equals("有")) { |
|||
return 1; |
|||
} else if (content.equals("无") || content.equals("否")) { |
|||
return 0; |
|||
} |
|||
} |
|||
return Converter.super.convertToJavaData(context); |
|||
} |
|||
} |
@ -0,0 +1,78 @@ |
|||
package com.epmet.excel.converter; |
|||
|
|||
import com.alibaba.excel.converters.Converter; |
|||
import com.alibaba.excel.converters.ReadConverterContext; |
|||
import com.alibaba.excel.converters.WriteConverterContext; |
|||
import com.alibaba.excel.enums.CellDataTypeEnum; |
|||
import com.alibaba.excel.metadata.data.WriteCellData; |
|||
import org.apache.commons.lang3.StringUtils; |
|||
|
|||
import java.util.Arrays; |
|||
import java.util.List; |
|||
|
|||
/** |
|||
* 灵山-是否转换器 |
|||
*/ |
|||
public class LingShanSpecialCrowdYesOrNoConverter implements Converter<Integer> { |
|||
List<String> group1 = Arrays.asList("localFlag", "multipleFlag", "recidivismFlag", "emplacementFlag", "canceledFlag", |
|||
"detachedFlag", "canGoOutFlag", "violenceFlag", "allowanceFlag", "subsistenceFlag"); |
|||
|
|||
List<String> group2 = Arrays.asList("criminalHistoryFlag", "drugRepetitionFlag", "causeTroubleHistoryFlag"); |
|||
|
|||
|
|||
@Override |
|||
public CellDataTypeEnum supportExcelTypeKey() { |
|||
return CellDataTypeEnum.STRING; |
|||
} |
|||
|
|||
@Override |
|||
public Class<?> supportJavaTypeKey() { |
|||
return Integer.class; |
|||
} |
|||
|
|||
@Override |
|||
public Integer convertToJavaData(ReadConverterContext<?> context) throws Exception { |
|||
String content = context.getReadCellData().getStringValue(); |
|||
if (StringUtils.isNotBlank(content)) { |
|||
if (content.equals("是") || content.equals("有")) { |
|||
return 1; |
|||
} else if (content.equals("无") || content.equals("否")) { |
|||
return 0; |
|||
} |
|||
} |
|||
return Converter.super.convertToJavaData(context); |
|||
} |
|||
|
|||
@Override |
|||
public WriteCellData<?> convertToExcelData(WriteConverterContext<Integer> context) throws Exception { |
|||
String fieldName = context.getContentProperty().getField().getName(); |
|||
Integer value = context.getValue(); |
|||
if (group1.contains(fieldName)) { |
|||
return convertYesOrNoFlag(value); |
|||
} else if (group2.contains(fieldName)) { |
|||
return convertHaveOrNotFlag(value); |
|||
} |
|||
|
|||
return Converter.super.convertToExcelData(context); |
|||
} |
|||
|
|||
WriteCellData<?> convertHaveOrNotFlag(Integer value) { |
|||
if (value.equals(1)) { |
|||
return new WriteCellData("有"); |
|||
} else if (value.equals(0)) { |
|||
return new WriteCellData("无"); |
|||
} else { |
|||
return new WriteCellData("未知"); |
|||
} |
|||
} |
|||
|
|||
WriteCellData<?> convertYesOrNoFlag(Integer value) { |
|||
if (value.equals(1)) { |
|||
return new WriteCellData("是"); |
|||
} else if (value.equals(0)) { |
|||
return new WriteCellData("否"); |
|||
} else { |
|||
return new WriteCellData("未知"); |
|||
} |
|||
} |
|||
} |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in new issue