admin
2020-07-03 651a15c78f668bef3859d9ed1bb7ad0b669d3600
fanli/src/main/java/com/yeshi/fanli/service/impl/config/ConfigServiceImpl.java
@@ -7,6 +7,8 @@
import javax.annotation.Resource;
import com.yeshi.fanli.entity.SystemEnum;
import com.yeshi.fanli.util.ThreadUtil;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.scheduling.annotation.Async;
@@ -35,20 +37,21 @@
   private ConfigMapper configMapper;
   
    @Override
   @Cacheable(value = "config")
   public List<Config> getAllList() {
      return configMapper.listAll();
    public List<Config> getAllList(SystemEnum system) {
        return configMapper.listAll(system);
   }
   @Override
   public List<Config> listObjects(String key, int page) {
    public List<Config> listObjects(String key, int page, SystemEnum system) {
      int start = (page - 1) * Constant.PAGE_SIZE;
      return configMapper.listSearchByName(key, start, Constant.PAGE_SIZE);
        return configMapper.listSearchByName(key, start, Constant.PAGE_SIZE, system);
   }
   @Override
   public int getCount(String key) {
      return (int) configMapper.countSearchByName(key);
    public int getCount(String key, SystemEnum system) {
        return (int) configMapper.countSearchByName(key, system);
   }
   @CacheEvict(value = "config", allEntries = true)
@@ -72,9 +75,10 @@
      configMapper.updateByPrimaryKeySelective(config);
   }
   @Cacheable(value = "config", key = "#p0+'Str'")
   public String get(String key) {
      List<Config> list = configMapper.listByKey(key, null, null);
    @Override
    @Cacheable(value = "config", key = "'getValue-'+#key+'-'+#system")
    public String getValue(String key, SystemEnum system) {
        List<Config> list = configMapper.listByKey(key, null, null,system);
      if (list.size() == 0) {
         return null;
      }
@@ -82,8 +86,8 @@
      return value;
   }
   @Cacheable(value = "config", key = "'getByVersion'+'-'+#key+'-'+#platform+'-'+#version ")
   public String getByVersion(String key, String platform, int version) {
    @Cacheable(value = "config", key = "'getByVersion'+'-'+#key+'-'+#platform+'-'+#version+'-'+#system ")
    public String getByVersion(String key, String platform, int version, SystemEnum system) {
      Integer minAndroidVersion = null;
      Integer minIosVersion = null;
      if ("android".equalsIgnoreCase(platform)) {
@@ -91,7 +95,7 @@
      } else
         minIosVersion = version;
      List<Config> list = configMapper.listByKey(key, minAndroidVersion, minIosVersion);
        List<Config> list = configMapper.listByKey(key, minAndroidVersion, minIosVersion,system);
      if (list.size() == 0) {
         return null;
      }
@@ -99,9 +103,9 @@
      return value;
   }
   @Cacheable(value = "config", key = "#p0")
   public Config getConfig(String key) {
      List<Config> list = configMapper.listByKey(key, null, null);
    @Cacheable(value = "config", key = "'getConfig-'+ #key+'-'+#system")
    public Config getConfig(String key, SystemEnum system) {
        List<Config> list = configMapper.listByKey(key, null, null,system);
      if (list.size() == 0) {
         return null;
      }
@@ -109,11 +113,11 @@
   }
   @Override
   public boolean xcxShow(String appId, Integer version) {
    public boolean xcxShow(String appId, Integer version,SystemEnum system) {
      if (version == null)
         return false;
      String value = get(ConfigKeyEnum.xcxSetting.getKey());
        String value = getValue(ConfigKeyEnum.xcxSetting.getKey(),system);
      if (StringUtil.isNullOrEmpty(value))
         return false;
      JSONArray array = JSONArray.fromObject(value);
@@ -130,8 +134,8 @@
   }
   @Override
   public XCXSettingConfig getXCXInfoByGhId(String ghId) {
      String value = get(ConfigKeyEnum.xcxSetting.getKey());
    public XCXSettingConfig getXCXInfoByGhId(String ghId,SystemEnum system) {
        String value = getValue(ConfigKeyEnum.xcxSetting.getKey(),system);
      JSONArray array = JSONArray.fromObject(value);
      for (int i = 0; i < array.size(); i++) {
         XCXSettingConfig config = new Gson().fromJson(array.optJSONObject(i).toString(), XCXSettingConfig.class);
@@ -143,26 +147,26 @@
   }
   @Override
   public String getH5Host() {
      String value = get(ConfigKeyEnum.h5Url.getKey());
    public String getH5Host(SystemEnum system) {
        String value = getValue(ConfigKeyEnum.h5Url.getKey(),system);
      String[] sts = value.split(",");
      value = sts[(int) (sts.length * Math.random())];
      return value.trim();
   }
   @Cacheable(value = "config", key = "'iosOnLining'+#version")
    @Cacheable(value = "config", key = "'iosOnLining'+#version+'-'+#system")
   @Override
   public boolean iosOnLining(int version) {
      String value = get(ConfigKeyEnum.iosOnlingVersion.getKey());
    public boolean iosOnLining(int version, SystemEnum system) {
        String value = getValue(ConfigKeyEnum.iosOnlingVersion.getKey(),system);
      if (StringUtil.isNullOrEmpty(value))
         return false;
      return version >= Integer.parseInt(value);
   }
   @Cacheable(value = "config", key = "'isConvertTaoBaoLinkInServer'")
    @Cacheable(value = "config", key = "'isConvertTaoBaoLinkInServer-'+#system")
   @Override
   public boolean isConvertTaoBaoLinkInServer() {
      String value = get(ConfigKeyEnum.convertTaoBaoLinkInServer.getKey());
    public boolean isConvertTaoBaoLinkInServer( SystemEnum system) {
        String value = getValue(ConfigKeyEnum.convertTaoBaoLinkInServer.getKey(),system);
      if (StringUtil.isNullOrEmpty(value))
         return false;
      if ("1".equalsIgnoreCase(value.trim()))
@@ -171,10 +175,10 @@
         return false;
   }
   @Cacheable(value = "config", key = "'getAppHomeFloatImg'")
    @Cacheable(value = "config", key = "'getAppHomeFloatImg-'+#system")
   @Override
   public AppHomeFloatImg getAppHomeFloatImg() {
      String value = get(ConfigKeyEnum.appFloatImg.getKey());
    public AppHomeFloatImg getAppHomeFloatImg( SystemEnum system) {
        String value = getValue(ConfigKeyEnum.appFloatImg.getKey(),system);
      if (!StringUtil.isNullOrEmpty(value)) {
         Gson gson = new Gson();
         AppHomeFloatImg appHomeFloatImg = gson.fromJson(value, AppHomeFloatImg.class);
@@ -185,18 +189,12 @@
      return null;
   }
   @Cacheable(value = "config", key = "'getHomeWEEXUrl'")
   @Override
   public String getHomeWEEXUrl() {
      String value = get(ConfigKeyEnum.homeWeexUrl.getKey());
      return value;
   }
   
   @Cacheable(value = "config", key = "'isRobotCloudOpen'+'-'+#key+'-'+#platform+'-'+#version")
    @Cacheable(value = "config", key = "'isRobotCloudOpen'+'-'+#key+'-'+#platform+'-'+#version+'-'+#system")
   @Override
   public boolean isRobotCloudOpen(String key,String platform,String version) {
      String value = getByVersion(key, platform,Integer.parseInt(version));
    public boolean isRobotCloudOpen(String key, String platform, String version, SystemEnum system) {
        String value = getByVersion(key, platform, Integer.parseInt(version),system);
      if (StringUtil.isNullOrEmpty(value))
         return false;
      if ("1".equalsIgnoreCase(value.trim())) {
@@ -209,8 +207,8 @@
   
   @Cacheable(value = "config", key = "'getTestUsers'")
   @Override
   public List<String> getTestUsers() {
      String value = get(ConfigKeyEnum.testUserArray.getKey());
    public List<String> getTestUsers( SystemEnum system) {
        String value = getValue(ConfigKeyEnum.testUserArray.getKey(),system);
      if (StringUtil.isNullOrEmpty(value))
         return null;
      try {
@@ -222,15 +220,14 @@
   }
   
   
   @Override
   public Config getConfig(long id) {
      return configMapper.selectByPrimaryKey(id);
   }
   @Override
   public ProxyIP getTaoBaoProxyIP() {
      String value = get(ConfigKeyEnum.taobaoProxyIP.getKey());
    public ProxyIP getTaoBaoProxyIP( SystemEnum system) {
        String value = getValue(ConfigKeyEnum.taobaoProxyIP.getKey(),system);
      try {
         String[] sts = value.split(":");
         return new ProxyIP(sts[0], Integer.parseInt(sts[1]));
@@ -240,13 +237,13 @@
   }
   @Override
   public String getAppHomeFloatNotifyImg() {
      return get(ConfigKeyEnum.homeFloatNotifyImg.getKey());
    public String getAppHomeFloatNotifyImg( SystemEnum system) {
        return getValue(ConfigKeyEnum.homeFloatNotifyImg.getKey(),system);
   }
   @Override
   public void save(Config config) {
      List<Config> list = configMapper.listByKey(config.getKey(), null, null);
        List<Config> list = configMapper.listByKey(config.getKey(), null, null,config.getSystem());
      if (list == null || list.size() == 0) {
         configMapper.insertSelective(config);
      }
@@ -254,8 +251,8 @@
   @Cacheable(value = "config", key = "'getSearchDiscoveryKeys'")
   @Override
   public String getSearchDiscoveryKeys() {
      List<Config> list = configMapper.listByKey(ConfigKeyEnum.searchDiscoveryKeys.getKey(), null, null);
    public String getSearchDiscoveryKeys( SystemEnum system) {
        List<Config> list = configMapper.listByKey(ConfigKeyEnum.searchDiscoveryKeys.getKey(), null, null,system);
      if (list == null || list.size() == 0)
         return null;
@@ -263,9 +260,13 @@
      if (config == null)
         return null;
        ThreadUtil.run(new Runnable() {
            @Override
            public void run() {
      // 更新
      updateSearchDiscoveryKeys(config);
            }
        });
      String value = config.getValue();
      return value;
   }
@@ -275,7 +276,6 @@
    * 
    * @param config
    */
   @Async
   private void updateSearchDiscoveryKeys(Config config) {
      long currentTime = java.lang.System.currentTimeMillis();
@@ -305,8 +305,8 @@
   
   
   @Override
   public Config getConfigBykeyNoCache(String key) {
      List<Config> list = configMapper.listByKey(key, null, null);
    public Config getConfigBykeyNoCache(String key, SystemEnum system) {
        List<Config> list = configMapper.listByKey(key, null, null,system);
      if (list.size() == 0) {
         return null;
      }