All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.shoulder.web.template.dictionary.convert.DictionaryItemDomain2DTOConverter Maven / Gradle / Ivy

Go to download

shoulder WEB 模块,基于Spring Boot Web提供了 Controller AOP 日志、AOP异常处理,统一返回值,健康检查,租户、用户解析,Web 安全防护,通用CrudController,动态字典,标签管理,HTTP client AOP日志、AOP异常处理等能力,助力Web飞速开发。

The newest version!

package org.shoulder.web.template.dictionary.convert;

import jakarta.annotation.Nonnull;
import org.shoulder.core.converter.BaseDataConverter;
import org.shoulder.core.dictionary.model.DictionaryItem;
import org.shoulder.core.i18.Translator;
import org.shoulder.web.template.dictionary.dto.DictionaryItemDTO;
import org.shoulder.web.template.dictionary.model.ConfigAbleDictionaryItem;

import java.util.Optional;

/**
 * DictionaryItem domain -> VO
 *
 * @author lym
 */
@SuppressWarnings("rawtypes")
public class DictionaryItemDomain2DTOConverter extends BaseDataConverter {

    public static DictionaryItemDomain2DTOConverter INSTANCE = new DictionaryItemDomain2DTOConverter(null);

    private final Translator translator;

    public DictionaryItemDomain2DTOConverter(Translator translator) {
        this.translator = translator;
    }

    @Override
    public void doConvert(@Nonnull DictionaryItem sourceModel, @Nonnull DictionaryItemDTO targetModel) {
        if (sourceModel instanceof ConfigAbleDictionaryItem) {
//            String parentCode = ((ConfigAbleDictionaryItem) sourceModel).getParentCode();
//            targetModel.setParentCode(StringUtils.isBlank(parentCode) ? Constants.ZERO : parentCode);
        }

        targetModel.setCode(sourceModel.getItemId().toString());
        targetModel.setDictionaryType(sourceModel.getDictionaryType());
        String displayI18nName = Optional.ofNullable(translator)
                .map(t -> t.getMessageOrDefault(sourceModel.getDisplayName(),
                        sourceModel.getDisplayName()))
                .orElse(sourceModel.getDisplayName());
        targetModel.setName(sourceModel.getName());
        targetModel.setDisplayName(displayI18nName);
        targetModel.setDisplayOrder(sourceModel.getDisplayOrder());
        targetModel.setDescription(sourceModel.getDescription());
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy