Search in sources :

Example 1 with DictionaryServiceExtProvider

use of com.diboot.core.service.DictionaryServiceExtProvider in project diboot by dibo-software.

the class ExcelBindAnnoHandler method convertToNameValueMap.

/**
 * 转换为name-value map
 * @param annotation
 * @param nameList
 * @return
 */
public static Map<String, List> convertToNameValueMap(Annotation annotation, List<String> nameList) {
    // 字典
    if (annotation instanceof ExcelBindDict || annotation instanceof BindDict) {
        String dictType = null;
        if (annotation instanceof ExcelBindDict) {
            dictType = ((ExcelBindDict) annotation).type();
        } else {
            dictType = ((BindDict) annotation).type();
        }
        DictionaryServiceExtProvider bindDictService = ContextHelper.getBean(DictionaryServiceExtProvider.class);
        if (bindDictService == null) {
            throw new InvalidUsageException("DictionaryService未实现,无法使用ExcelBindDict注解!");
        }
        List<LabelValue> list = bindDictService.getLabelValueList(dictType);
        return convertLabelValueListToMap(list);
    } else if (annotation instanceof ExcelBindField) {
        ExcelBindField bindField = (ExcelBindField) annotation;
        return executeBindField(bindField, nameList);
    } else {
        return Collections.emptyMap();
    }
}
Also used : ExcelBindDict(com.diboot.file.excel.annotation.ExcelBindDict) BindDict(com.diboot.core.binding.annotation.BindDict) DictionaryServiceExtProvider(com.diboot.core.service.DictionaryServiceExtProvider) LabelValue(com.diboot.core.vo.LabelValue) ExcelBindDict(com.diboot.file.excel.annotation.ExcelBindDict) InvalidUsageException(com.diboot.core.exception.InvalidUsageException) ExcelBindField(com.diboot.file.excel.annotation.ExcelBindField)

Example 2 with DictionaryServiceExtProvider

use of com.diboot.core.service.DictionaryServiceExtProvider in project diboot by dibo-software.

the class OptionWriteHandler method getDictOptions.

/**
 * 从字典中获取选项
 *
 * @param dictType 字典类型
 * @return 选项数组
 */
protected String[] getDictOptions(String dictType) {
    DictionaryServiceExtProvider bindDictService = ContextHelper.getBean(DictionaryServiceExtProvider.class);
    if (bindDictService == null) {
        throw new InvalidUsageException("DictionaryService未实现,@ExcelOption无法关联字典!");
    }
    String[] options = bindDictService.getLabelValueList(dictType).stream().map(LabelValue::getLabel).toArray(String[]::new);
    if (V.isEmpty(options)) {
        log.warn(" @ExcelOption 关联字典: " + dictType + " 无值");
    }
    return options;
}
Also used : DictionaryServiceExtProvider(com.diboot.core.service.DictionaryServiceExtProvider) InvalidUsageException(com.diboot.core.exception.InvalidUsageException)

Aggregations

InvalidUsageException (com.diboot.core.exception.InvalidUsageException)2 DictionaryServiceExtProvider (com.diboot.core.service.DictionaryServiceExtProvider)2 BindDict (com.diboot.core.binding.annotation.BindDict)1 LabelValue (com.diboot.core.vo.LabelValue)1 ExcelBindDict (com.diboot.file.excel.annotation.ExcelBindDict)1 ExcelBindField (com.diboot.file.excel.annotation.ExcelBindField)1