提交 | 用户 | 时间
|
e7c126
|
1 |
package com.iailab.framework.excel.core.convert; |
H |
2 |
|
|
3 |
import cn.hutool.core.convert.Convert; |
|
4 |
import com.iailab.framework.ip.core.Area; |
|
5 |
import com.iailab.framework.ip.core.utils.AreaUtils; |
|
6 |
import com.alibaba.excel.converters.Converter; |
|
7 |
import com.alibaba.excel.enums.CellDataTypeEnum; |
|
8 |
import com.alibaba.excel.metadata.GlobalConfiguration; |
|
9 |
import com.alibaba.excel.metadata.data.ReadCellData; |
|
10 |
import com.alibaba.excel.metadata.property.ExcelContentProperty; |
|
11 |
import lombok.extern.slf4j.Slf4j; |
|
12 |
|
|
13 |
/** |
|
14 |
* Excel 数据地区转换器 |
|
15 |
* |
|
16 |
* @author HUIHUI |
|
17 |
*/ |
|
18 |
@Slf4j |
|
19 |
public class AreaConvert implements Converter<Object> { |
|
20 |
|
|
21 |
@Override |
|
22 |
public Class<?> supportJavaTypeKey() { |
|
23 |
throw new UnsupportedOperationException("暂不支持,也不需要"); |
|
24 |
} |
|
25 |
|
|
26 |
@Override |
|
27 |
public CellDataTypeEnum supportExcelTypeKey() { |
|
28 |
throw new UnsupportedOperationException("暂不支持,也不需要"); |
|
29 |
} |
|
30 |
|
|
31 |
@Override |
|
32 |
public Object convertToJavaData(ReadCellData readCellData, ExcelContentProperty contentProperty, |
|
33 |
GlobalConfiguration globalConfiguration) { |
|
34 |
// 解析地区编号 |
|
35 |
String label = readCellData.getStringValue(); |
|
36 |
Area area = AreaUtils.parseArea(label); |
|
37 |
if (area == null) { |
|
38 |
log.error("[convertToJavaData][label({}) 解析不掉]", label); |
|
39 |
return null; |
|
40 |
} |
|
41 |
// 将 value 转换成对应的属性 |
|
42 |
Class<?> fieldClazz = contentProperty.getField().getType(); |
|
43 |
return Convert.convert(fieldClazz, area.getId()); |
|
44 |
} |
|
45 |
|
|
46 |
} |