forked from luyan/epmet-cloud-lingshan
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
1.5 KiB
58 lines
1.5 KiB
6 years ago
|
/**
|
||
|
* Copyright (c) 2018 人人开源 All rights reserved.
|
||
|
* <p>
|
||
|
* https://www.renren.io
|
||
|
* <p>
|
||
|
* 版权所有,侵权必究!
|
||
|
*/
|
||
|
|
||
|
package com.epmet.remote;
|
||
|
|
||
|
import com.alibaba.fastjson.JSON;
|
||
|
import com.epmet.feign.ParamsFeignClient;
|
||
|
import com.epmet.commons.tools.exception.ErrorCode;
|
||
|
import com.epmet.commons.tools.exception.RenException;
|
||
|
import org.apache.commons.lang3.StringUtils;
|
||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||
|
import org.springframework.stereotype.Component;
|
||
|
|
||
|
/**
|
||
|
* 参数
|
||
|
*
|
||
|
* @author Mark sunlightcs@gmail.com
|
||
|
* @since 1.1.0
|
||
|
*/
|
||
|
@Component
|
||
|
public class ParamsRemoteService {
|
||
|
@Autowired
|
||
|
private ParamsFeignClient paramsFeignClient;
|
||
|
|
||
|
/**
|
||
|
* 根据参数编码,获取value的Object对象
|
||
|
* @param paramCode 参数编码
|
||
|
* @param clazz Object对象
|
||
|
*/
|
||
|
public <T> T getValueObject(String paramCode, Class<T> clazz) {
|
||
|
String paramValue = paramsFeignClient.getValue(paramCode);
|
||
|
if(StringUtils.isNotBlank(paramValue)){
|
||
|
return JSON.parseObject(paramValue, clazz);
|
||
|
}
|
||
|
|
||
|
try {
|
||
|
return clazz.newInstance();
|
||
|
} catch (Exception e) {
|
||
|
throw new RenException(ErrorCode.PARAMS_GET_ERROR);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 根据参数编码,更新value
|
||
|
* @param paramCode 参数编码
|
||
|
* @param paramValue 参数值
|
||
|
*/
|
||
|
public void updateValueByCode(String paramCode, String paramValue){
|
||
|
paramsFeignClient.updateValueByCode(paramCode, paramValue);
|
||
|
}
|
||
|
|
||
|
}
|