zm
2020-05-18 a18bfacbf56b401f6e0fdae8710fbca4df8cff77
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package com.changhong.epc.rely.api.epc.tenant;
 
import com.alibaba.fastjson.TypeReference;
import com.changhong.epc.bean.tenant.system.SystemConfig;
import com.changhong.epc.constter.system.SystemClients;
import com.changhong.epc.constter.system.run.EpcRestInterface;
import com.changhong.epc.constter.tenant.TenantUrlConst;
import com.iemsoft.framework.cloud.core.base.ResMsg;
import com.iemsoft.framework.cloud.core.tools.JSONTool;
import com.iemsoft.framework.cloud.core.tools.ObjectUtil;
import com.iemsoft.framework.cloud.core.tools.SpringUtil;
import com.iemsoft.framework.cloud.ribbon.RestInterface;
import org.springframework.stereotype.Service;
 
import java.util.Collections;
import java.util.List;
import java.util.function.Function;
 
@Service
public class SystemConfigApi implements SystemClients{
 
    /**
     * 获得配置信息
     * @param param
     * @return
     */
    public SystemConfig getSystemConfig(SystemConfig param){
        List<SystemConfig> configList = getSystemConfigs(param);
        return ObjectUtil.empty(configList) ? new SystemConfig() : configList.get(0);
    }
 
    /**
     * 获得配置信息集
     * @param param
     * @return
     */
    public List<SystemConfig> getSystemConfigs(SystemConfig param){
        ResMsg<List<SystemConfig>> resMsg =
                (ResMsg<List<SystemConfig>>)
                        SpringUtil.getBean(SERVER_TENANT.getBeanName(), RestInterface.class).post(
                                TenantUrlConst.REST_TENANT_SYSTEMCONFIG_BYGROUPKEY
                                , param
                                , new TypeReference<ResMsg<List<SystemConfig>>>(){}.getType()
                                , EpcRestInterface.getEpcHeads());
        List<SystemConfig> configList =  JSONTool.toList(JSONTool.toJson(resMsg.getData()), SystemConfig.class);
        return configList == null ? Collections.emptyList() : configList;
    }
 
    public String getVal(SystemConfig systemConfig, Function<SystemConfig, String> mapper){
        SystemConfig result = getSystemConfig(systemConfig);
        if(ObjectUtil.notEmpty(result)){
            return mapper.apply(result);
        }
        return "";
    }
 
}