mirror of
https://gitee.com/hhyykk/ipms-sjy.git
synced 2025-07-15 03:25:06 +08:00
CRM:完善客户导入
This commit is contained in:
@ -0,0 +1,46 @@
|
||||
package cn.iocoder.yudao.framework.excel.core.convert;
|
||||
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.iocoder.yudao.framework.ip.core.Area;
|
||||
import cn.iocoder.yudao.framework.ip.core.utils.AreaUtils;
|
||||
import com.alibaba.excel.converters.Converter;
|
||||
import com.alibaba.excel.enums.CellDataTypeEnum;
|
||||
import com.alibaba.excel.metadata.GlobalConfiguration;
|
||||
import com.alibaba.excel.metadata.data.ReadCellData;
|
||||
import com.alibaba.excel.metadata.property.ExcelContentProperty;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* Excel 数据地区转换器
|
||||
*
|
||||
* @author HUIHUI
|
||||
*/
|
||||
@Slf4j
|
||||
public class AreaConvert implements Converter<Object> {
|
||||
|
||||
@Override
|
||||
public Class<?> supportJavaTypeKey() {
|
||||
throw new UnsupportedOperationException("暂不支持,也不需要");
|
||||
}
|
||||
|
||||
@Override
|
||||
public CellDataTypeEnum supportExcelTypeKey() {
|
||||
throw new UnsupportedOperationException("暂不支持,也不需要");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object convertToJavaData(ReadCellData readCellData, ExcelContentProperty contentProperty,
|
||||
GlobalConfiguration globalConfiguration) {
|
||||
// 解析地区编号
|
||||
String label = readCellData.getStringValue();
|
||||
Area area = AreaUtils.getArea(label);
|
||||
if (area == null) {
|
||||
log.error("[convertToJavaData][label({}) 解析不掉]", label);
|
||||
return null;
|
||||
}
|
||||
// 将 value 转换成对应的属性
|
||||
Class<?> fieldClazz = contentProperty.getField().getType();
|
||||
return Convert.convert(fieldClazz, area.getId());
|
||||
}
|
||||
|
||||
}
|
@ -9,6 +9,7 @@ import org.apache.poi.hssf.usermodel.HSSFDataValidation;
|
||||
import org.apache.poi.ss.usermodel.*;
|
||||
import org.apache.poi.ss.util.CellRangeAddressList;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -18,12 +19,13 @@ import java.util.List;
|
||||
*/
|
||||
public class SelectSheetWriteHandler implements SheetWriteHandler {
|
||||
|
||||
private List<KeyValue<Integer, List<String>>> selectMap;
|
||||
private final List<KeyValue<Integer, List<String>>> selectMap;
|
||||
|
||||
private final char[] alphabet = new char[]{'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L',
|
||||
private static final char[] ALPHABET = new char[]{'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L',
|
||||
'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
|
||||
|
||||
public SelectSheetWriteHandler(List<KeyValue<Integer, List<String>>> selectMap) {
|
||||
selectMap.sort(Comparator.comparing(item -> item.getValue().size())); // 升序不然创建下拉会报错
|
||||
this.selectMap = selectMap;
|
||||
}
|
||||
|
||||
@ -86,17 +88,17 @@ public class SelectSheetWriteHandler implements SheetWriteHandler {
|
||||
*/
|
||||
private String getExcelColumn(int num) {
|
||||
String column = "";
|
||||
int len = alphabet.length - 1;
|
||||
int len = ALPHABET.length - 1;
|
||||
int first = num / len;
|
||||
int second = num % len;
|
||||
if (num <= len) {
|
||||
column = alphabet[num] + "";
|
||||
column = ALPHABET[num] + "";
|
||||
} else {
|
||||
column = alphabet[first - 1] + "";
|
||||
column = ALPHABET[first - 1] + "";
|
||||
if (second == 0) {
|
||||
column = column + alphabet[len] + "";
|
||||
column = column + ALPHABET[len] + "";
|
||||
} else {
|
||||
column = column + alphabet[second - 1] + "";
|
||||
column = column + ALPHABET[second - 1] + "";
|
||||
}
|
||||
}
|
||||
return column;
|
||||
|
Reference in New Issue
Block a user