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

com.houkunlin.system.dict.starter.actuator.DictEndpoint Maven / Gradle / Ivy

Go to download

系统数据字典自动翻译成字典文本。可集合系统数据库中存储的用户数据字典,也可使用枚举做系统数据字典,主要用在返回数据给前端时自动把字典值翻译成字典文本信息; The system data dictionary is automatically translated into dictionary text. The user data dictionary stored in the system database can be aggregated, and the enumeration can also be used as the system data dictionary. It is mainly used to automatically translate dictionary values into dictionary text information when returning data to the front end.

The newest version!
package com.houkunlin.system.dict.starter.actuator;

import com.houkunlin.system.dict.starter.DictUtil;
import com.houkunlin.system.dict.starter.provider.DictProvider;
import com.houkunlin.system.dict.starter.store.DictStore;
import com.houkunlin.system.dict.starter.store.RemoteDict;
import lombok.RequiredArgsConstructor;
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
import org.springframework.boot.actuate.endpoint.annotation.Selector;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 字典端点
 *
 * @author HouKunLin
 * @since 1.3.0
 */
@Endpoint(id = "dict")
@RequiredArgsConstructor
public class DictEndpoint {
    private final List providers;
    private final DictStore store;
    private final RemoteDict remoteDict;

    /**
     * 默认端点接口信息
     *
     * @return 返回系统一些class对象名称
     */
    @ReadOperation
    public Object index() {
        final Map map = new HashMap<>();
        map.put("providers", providers.stream().map(Object::getClass).map(Class::getName).collect(Collectors.toList()));
        map.put("stores", store.getClass().getName());
        map.put("remoteDict", remoteDict.getClass().getName());

        final Map result = new HashMap<>();
        result.put("dict-classes", map);
        result.put("dict-types", store.dictTypeKeys());
        return result;
    }

    /**
     * 获得字典类型信息
     *
     * @param dictType 字典类型代码
     * @return 字典类型信息
     */
    @ReadOperation
    public Object type(@Selector String dictType) {
        return DictUtil.getDictType(dictType);
    }

    /**
     * 获得字典值文本信息
     *
     * @param dictType  字典类型代码
     * @param dictValue 字典值
     * @return 字典值文本
     */
    @ReadOperation
    public Object title(@Selector String dictType, @Selector String dictValue) {
        return DictUtil.getDictText(dictType, dictValue);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy