Commit b45d4b66 by guojuxing

计费中心图标接口优化:服务配置化,如果扩展,减少工厂类的修改,符合开闭

parent 31253d4f
package com.gic.enterprise.utils.chart; package com.gic.enterprise.utils.chart;
import com.gic.enterprise.constant.billing.FeeTypeEnum;
import com.gic.enterprise.dto.HomeStatisticsDTO;
import com.gic.enterprise.qo.HomeStatisticsQO;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import com.gic.enterprise.dto.HomeStatisticsDTO;
import com.gic.enterprise.qo.HomeStatisticsQO;
/** /**
* 计费中心首页图表 * 计费中心首页图表
* @ClassName: FeeChartUtils
 * @ClassName: FeeChartUtils

...@@ -16,13 +15,10 @@ import java.util.Map; ...@@ -16,13 +15,10 @@ import java.util.Map;
* @date 2019/8/23 2:18 PM
 * @date 2019/8/23 2:18 PM

*/ */
public class FeeChartUtils { public class FeeChartUtils {
private static Map getPageMap = new HashMap<>(8); private static Map<Integer, IFeeChart> getPageMap = new HashMap<>(8);
static { static {
getPageMap.put(FeeTypeEnum.ACCOUNT_BALANCE.getCode(), new BillingAccountBalanceRecord()); getPageMap = ReadFeeChartConfig.read();
getPageMap.put(FeeTypeEnum.SMS.getCode(), new BillingSmsRecord());
getPageMap.put(FeeTypeEnum.SMS_PACKAGE.getCode(), new BillingSmsPackageRecord());
getPageMap.put(FeeTypeEnum.INTERNATIONAL_SMS.getCode(), new BillingInternationSmsRecord());
} }
/** /**
......
package com.gic.enterprise.utils.chart;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.core.io.support.PropertiesLoaderUtils;
/**
* 计费中心首页图表 服务配置解读
* @ClassName: ReadFeeChartConfig

* @Description: 

* @author guojuxing

* @date 2020/11/3 2:01 PM

*/
public class ReadFeeChartConfig {
private static Logger LOGGER = LogManager.getLogger(ReadFeeChartConfig.class);
/**
* 解读 计费中心首页图表 服务配置
* @return
*/
public static Map<Integer, IFeeChart> read() {
Map<Integer, IFeeChart> map = new HashMap<>(16);
Properties properties = new Properties();
try {
properties = PropertiesLoaderUtils.loadAllProperties("config/feechart.properties");
Set<Map.Entry<Object, Object>> entrySet = properties.entrySet();
for (Map.Entry<Object, Object> entry : entrySet) {
map.put(Integer.parseInt((String) entry.getKey()), createClass((String) entry.getValue()));
}
} catch (Exception e) {
LOGGER.warn("解析config/feechart.properties文件失败:{}", e.getMessage(), e);
}
return map;
}
private static IFeeChart createClass(String url) throws ClassNotFoundException, IllegalAccessException, InvocationTargetException, InstantiationException, NoSuchMethodException {
Class clazz = Class.forName(url);
Constructor constructor = clazz.getDeclaredConstructor();
return (IFeeChart) constructor.newInstance();
}
public static void main(String[] args) {
}
}
###计费中心首页图表 服务配置
7:com.gic.enterprise.utils.chart.BillingAccountBalanceRecord
3:com.gic.enterprise.utils.chart.BillingSmsRecord
4:com.gic.enterprise.utils.chart.BillingSmsPackageRecord
8:com.gic.enterprise.utils.chart.BillingInternationSmsRecord
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment