Search in sources :

Example 1 with DictDataRespDTO

use of cn.iocoder.yudao.framework.dict.core.dto.DictDataRespDTO in project ruoyi-vue-pro by YunaiV.

the class DictConvert method convertToExcelData.

@Override
public CellData<String> convertToExcelData(Object object, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) {
    // 空时,返回空
    if (object == null) {
        return new CellData<>("");
    }
    // 使用字典格式化
    String type = getType(contentProperty);
    String value = String.valueOf(object);
    DictDataRespDTO dictData = DictFrameworkUtils.getDictDataFromCache(type, value);
    if (dictData == null) {
        log.error("[convertToExcelData][type({}) 转换不了 label({})]", type, value);
        return new CellData<>("");
    }
    // 生成 Excel 小表格
    return new CellData<>(dictData.getLabel());
}
Also used : CellData(com.alibaba.excel.metadata.CellData) DictDataRespDTO(cn.iocoder.yudao.framework.dict.core.dto.DictDataRespDTO)

Example 2 with DictDataRespDTO

use of cn.iocoder.yudao.framework.dict.core.dto.DictDataRespDTO in project ruoyi-vue-pro by YunaiV.

the class DictConvert method convertToJavaData.

@Override
public Object convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) {
    // 使用字典解析
    String type = getType(contentProperty);
    String label = cellData.getStringValue();
    DictDataRespDTO dictData = DictFrameworkUtils.parseDictDataFromCache(type, label);
    if (dictData == null) {
        log.error("[convertToJavaData][type({}) 解析不掉 label({})]", type, label);
        return null;
    }
    // 将 String 的 value 转换成对应的属性
    Class<?> fieldClazz = contentProperty.getField().getType();
    return Convert.convert(fieldClazz, dictData.getValue());
}
Also used : DictDataRespDTO(cn.iocoder.yudao.framework.dict.core.dto.DictDataRespDTO)

Aggregations

DictDataRespDTO (cn.iocoder.yudao.framework.dict.core.dto.DictDataRespDTO)2 CellData (com.alibaba.excel.metadata.CellData)1