package cn.iocoder.yudao.module.crm.framework.excel.core; import cn.idev.excel.converters.Converter; import cn.idev.excel.enums.CellDataTypeEnum; import cn.idev.excel.metadata.GlobalConfiguration; import cn.idev.excel.metadata.data.ReadCellData; import cn.idev.excel.metadata.data.WriteCellData; import cn.idev.excel.metadata.property.ExcelContentProperty; /** 是否流入公海的 Excel 转换;非法值必须报错,避免意外开放公海可见度。 */ public class AutoPoolEnabledConvert implements Converter { @Override public Class supportJavaTypeKey() { return Boolean.class; } @Override public CellDataTypeEnum supportExcelTypeKey() { return CellDataTypeEnum.STRING; } @Override public Boolean convertToJavaData(ReadCellData cell, ExcelContentProperty property, GlobalConfiguration configuration) { if (cell.getType() == CellDataTypeEnum.EMPTY) { return null; } if (cell.getType() == CellDataTypeEnum.BOOLEAN) { return cell.getBooleanValue(); } String value = cell.getType() == CellDataTypeEnum.NUMBER ? cell.getNumberValue().stripTrailingZeros().toPlainString() : cell.getStringValue(); if (value == null || value.isBlank()) { return null; } return switch (value.trim().toLowerCase(java.util.Locale.ROOT)) { case "是", "true", "1" -> true; case "否", "false", "0" -> false; default -> throw new IllegalArgumentException("是否流入公海请填写是或否"); }; } @Override public WriteCellData convertToExcelData(Boolean value, ExcelContentProperty property, GlobalConfiguration configuration) { return new WriteCellData<>(value == null ? "" : value ? "是" : "否"); } }