| | |
| | |
|
| | | 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;
|
| | |
| | | @Service
|
| | | public class ConfigServiceImpl implements ConfigService {
|
| | |
|
| | | @Resource
|
| | | private ConfigMapper configMapper;
|
| | | |
| | |
|
| | | @Cacheable(value = "config")
|
| | | public List<Config> getAllList() {
|
| | | return configMapper.listAll();
|
| | | }
|
| | |
|
| | | @Override
|
| | | public List<Config> listObjects(String key, int page) {
|
| | | int start = (page - 1) * Constant.PAGE_SIZE;
|
| | | return configMapper.listSearchByName(key, start, Constant.PAGE_SIZE);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public int getCount(String key) {
|
| | | return (int) configMapper.countSearchByName(key);
|
| | | }
|
| | |
|
| | | @CacheEvict(value = "config", allEntries = true)
|
| | | @Transactional
|
| | | public void update(List<Config> list) {
|
| | | for (Config config : list) {
|
| | | if (config.getValue() == null) {
|
| | | config.setValue("");
|
| | | }
|
| | | config.setCreatetime(new Date().getTime() + "");
|
| | | configMapper.updateByPrimaryKeySelective(config);
|
| | | }
|
| | | }
|
| | |
|
| | | @CacheEvict(value = "config", allEntries = true)
|
| | | public void update(Config config) {
|
| | | if (config.getValue() == null)
|
| | | config.setValue("");
|
| | | |
| | | config.setCreatetime(new Date().getTime() + "");
|
| | | configMapper.updateByPrimaryKeySelective(config);
|
| | | }
|
| | |
|
| | | @Cacheable(value = "config", key = "#p0+'Str'")
|
| | | public String get(String key) {
|
| | | List<Config> list = configMapper.listByKey(key, null, null);
|
| | | if (list.size() == 0) {
|
| | | return null;
|
| | | }
|
| | | String value = list.get(0).getValue();
|
| | | return value;
|
| | | }
|
| | |
|
| | | @Cacheable(value = "config", key = "'getByVersion'+'-'+#key+'-'+#platform+'-'+#version ")
|
| | | public String getByVersion(String key, String platform, int version) {
|
| | | Integer minAndroidVersion = null;
|
| | | Integer minIosVersion = null;
|
| | | if ("android".equalsIgnoreCase(platform)) {
|
| | | minAndroidVersion = version;
|
| | | } else
|
| | | minIosVersion = version;
|
| | |
|
| | | List<Config> list = configMapper.listByKey(key, minAndroidVersion, minIosVersion);
|
| | | if (list.size() == 0) {
|
| | | return null;
|
| | | }
|
| | | String value = list.get(0).getValue();
|
| | | return value;
|
| | | }
|
| | |
|
| | | @Cacheable(value = "config", key = "#p0")
|
| | | public Config getConfig(String key) {
|
| | | List<Config> list = configMapper.listByKey(key, null, null);
|
| | | if (list.size() == 0) {
|
| | | return null;
|
| | | }
|
| | | return list.get(0);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public boolean xcxShow(String appId, Integer version) {
|
| | | if (version == null)
|
| | | return false;
|
| | |
|
| | | String value = get(ConfigKeyEnum.xcxSetting.getKey());
|
| | | if (StringUtil.isNullOrEmpty(value))
|
| | | return false;
|
| | | JSONArray array = JSONArray.fromObject(value);
|
| | | for (int i = 0; i < array.size(); i++) {
|
| | | XCXSettingConfig config = new Gson().fromJson(array.optJSONObject(i).toString(), XCXSettingConfig.class);
|
| | | if (config.getAppId().equalsIgnoreCase(appId)) {
|
| | | if (version > config.getVersion())
|
| | | return config.isShow();
|
| | | else
|
| | | return true;
|
| | | }
|
| | | }
|
| | | return false;
|
| | | }
|
| | |
|
| | | @Override
|
| | | public XCXSettingConfig getXCXInfoByGhId(String ghId) {
|
| | | String value = get(ConfigKeyEnum.xcxSetting.getKey());
|
| | | JSONArray array = JSONArray.fromObject(value);
|
| | | for (int i = 0; i < array.size(); i++) {
|
| | | XCXSettingConfig config = new Gson().fromJson(array.optJSONObject(i).toString(), XCXSettingConfig.class);
|
| | | if (config.getGhId().equalsIgnoreCase(ghId)) {
|
| | | return config;
|
| | | }
|
| | | }
|
| | | return null;
|
| | | }
|
| | |
|
| | | @Override
|
| | | public String getH5Host() {
|
| | | String value = get(ConfigKeyEnum.h5Url.getKey());
|
| | | String[] sts = value.split(",");
|
| | | value = sts[(int) (sts.length * Math.random())];
|
| | | return value.trim();
|
| | | }
|
| | |
|
| | | @Cacheable(value = "config", key = "'iosOnLining'+#version")
|
| | | @Override
|
| | | public boolean iosOnLining(int version) {
|
| | | String value = get(ConfigKeyEnum.iosOnlingVersion.getKey());
|
| | | if (StringUtil.isNullOrEmpty(value))
|
| | | return false;
|
| | | return version >= Integer.parseInt(value);
|
| | | }
|
| | |
|
| | | @Cacheable(value = "config", key = "'isConvertTaoBaoLinkInServer'")
|
| | | @Override
|
| | | public boolean isConvertTaoBaoLinkInServer() {
|
| | | String value = get(ConfigKeyEnum.convertTaoBaoLinkInServer.getKey());
|
| | | if (StringUtil.isNullOrEmpty(value))
|
| | | return false;
|
| | | if ("1".equalsIgnoreCase(value.trim()))
|
| | | return true;
|
| | | else
|
| | | return false;
|
| | | }
|
| | |
|
| | | @Cacheable(value = "config", key = "'getAppHomeFloatImg'")
|
| | | @Override
|
| | | public AppHomeFloatImg getAppHomeFloatImg() {
|
| | | String value = get(ConfigKeyEnum.appFloatImg.getKey());
|
| | | if (!StringUtil.isNullOrEmpty(value)) {
|
| | | Gson gson = new Gson();
|
| | | AppHomeFloatImg appHomeFloatImg = gson.fromJson(value, AppHomeFloatImg.class);
|
| | | if (appHomeFloatImg.getShow())
|
| | | return appHomeFloatImg;
|
| | | }
|
| | |
|
| | | 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")
|
| | | @Override
|
| | | public boolean isRobotCloudOpen(String key) {
|
| | | String value = get(key);
|
| | | if (StringUtil.isNullOrEmpty(value))
|
| | | return false;
|
| | | if ("1".equalsIgnoreCase(value.trim())) {
|
| | | return true;
|
| | | } else {
|
| | | return false;
|
| | | }
|
| | | }
|
| | | @Resource
|
| | | private ConfigMapper configMapper;
|
| | |
|
| | |
|
| | | |
| | | @Cacheable(value = "config", key = "'getTestUsers'")
|
| | | @Override
|
| | | public List<String> getTestUsers() {
|
| | | String value = get(ConfigKeyEnum.testUserArray.getKey());
|
| | | if (StringUtil.isNullOrEmpty(value))
|
| | | return null;
|
| | | try {
|
| | | return Arrays.asList(value.split(","));
|
| | | } catch (Exception e) {
|
| | | LogHelper.errorDetailInfo(e);
|
| | | }
|
| | | return null;
|
| | | }
|
| | | |
| | | |
| | | |
| | | |
| | | |
| | | @Override
|
| | | public Config getConfig(long id) {
|
| | | return configMapper.selectByPrimaryKey(id);
|
| | | }
|
| | | @Override
|
| | | @Cacheable(value = "config")
|
| | | public List<Config> getAllList(SystemEnum system) {
|
| | | return configMapper.listAll(system);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public ProxyIP getTaoBaoProxyIP() {
|
| | | String value = get(ConfigKeyEnum.taobaoProxyIP.getKey());
|
| | | try {
|
| | | String[] sts = value.split(":");
|
| | | return new ProxyIP(sts[0], Integer.parseInt(sts[1]));
|
| | | } catch (Exception e) {
|
| | | }
|
| | | return null;
|
| | | }
|
| | | @Override
|
| | | 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, system);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public String getAppHomeFloatNotifyImg() {
|
| | | return get(ConfigKeyEnum.homeFloatNotifyImg.getKey());
|
| | | }
|
| | | @Override
|
| | | public int getCount(String key, SystemEnum system) {
|
| | | return (int) configMapper.countSearchByName(key, system);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public void save(Config config) {
|
| | | List<Config> list = configMapper.listByKey(config.getKey(), null, null);
|
| | | if (list == null || list.size() == 0) {
|
| | | configMapper.insertSelective(config);
|
| | | }
|
| | | }
|
| | | @CacheEvict(value = "config", allEntries = true)
|
| | | @Transactional
|
| | | public void update(List<Config> list) {
|
| | | for (Config config : list) {
|
| | | if (config.getValue() == null) {
|
| | | config.setValue("");
|
| | | }
|
| | | config.setCreatetime(new Date().getTime() + "");
|
| | | configMapper.updateByPrimaryKeySelective(config);
|
| | | }
|
| | | }
|
| | |
|
| | | @Cacheable(value = "config", key = "'getSearchDiscoveryKeys'")
|
| | | @Override
|
| | | public String getSearchDiscoveryKeys() {
|
| | | List<Config> list = configMapper.listByKey(ConfigKeyEnum.searchDiscoveryKeys.getKey(), null, null);
|
| | | if (list == null || list.size() == 0)
|
| | | return null;
|
| | | @CacheEvict(value = "config", allEntries = true)
|
| | | public void update(Config config) {
|
| | | if (config.getValue() == null)
|
| | | config.setValue("");
|
| | |
|
| | | Config config = list.get(0);
|
| | | if (config == null)
|
| | | return null;
|
| | | config.setCreatetime(new Date().getTime() + "");
|
| | | configMapper.updateByPrimaryKeySelective(config);
|
| | | }
|
| | |
|
| | | // 更新
|
| | | updateSearchDiscoveryKeys(config);
|
| | | @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;
|
| | | }
|
| | | String value = list.get(0).getValue();
|
| | | return value;
|
| | | }
|
| | |
|
| | | String value = config.getValue();
|
| | | return value;
|
| | | }
|
| | | @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)) {
|
| | | minAndroidVersion = version;
|
| | | } else
|
| | | minIosVersion = version;
|
| | |
|
| | | /**
|
| | | * 更新搜索发现词
|
| | | * |
| | | * @param config
|
| | | */
|
| | | @Async
|
| | | private void updateSearchDiscoveryKeys(Config config) {
|
| | | long currentTime = java.lang.System.currentTimeMillis();
|
| | | List<Config> list = configMapper.listByKey(key, minAndroidVersion, minIosVersion,system);
|
| | | if (list.size() == 0) {
|
| | | return null;
|
| | | }
|
| | | String value = list.get(0).getValue();
|
| | | return value;
|
| | | }
|
| | |
|
| | | String createtime = config.getCreatetime();
|
| | | if (!StringUtil.isNullOrEmpty(createtime)) {
|
| | | long diff = currentTime - Long.parseLong(createtime);
|
| | | if (diff < 1000 * 60 * 60)
|
| | | return; // 超过一个小时更新
|
| | | }
|
| | | @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;
|
| | | }
|
| | | return list.get(0);
|
| | | }
|
| | |
|
| | | String hotWords = DaTaoKeApiUtil.getHotWords();
|
| | | if (StringUtil.isNullOrEmpty(hotWords))
|
| | | return;
|
| | | JSONArray array = JSONArray.fromObject(hotWords);
|
| | | String reg = "^([\u4E00-\uFA29]|[\uE7C7-\uE7F3]|[a-zA-Z0-9_-]){1,20}$";
|
| | | List<String> list = new ArrayList<>();
|
| | | for (int i = 0; i < array.size(); i++) {
|
| | | String key = array.optString(i);
|
| | | if (key.matches(reg)) {
|
| | | list.add(key);
|
| | | }
|
| | | }
|
| | | config.setValue(new Gson().toJson(list));
|
| | | config.setCreatetime(currentTime + "");
|
| | | configMapper.updateByPrimaryKeySelective(config);
|
| | | }
|
| | | |
| | | |
| | | @Override
|
| | | public Config getConfigBykeyNoCache(String key) {
|
| | | List<Config> list = configMapper.listByKey(key, null, null);
|
| | | if (list.size() == 0) {
|
| | | return null;
|
| | | }
|
| | | return list.get(0);
|
| | | }
|
| | | @Override
|
| | | public boolean xcxShow(String appId, Integer version,SystemEnum system) {
|
| | | if (version == null)
|
| | | return false;
|
| | |
|
| | | String value = getValue(ConfigKeyEnum.xcxSetting.getKey(),system);
|
| | | if (StringUtil.isNullOrEmpty(value))
|
| | | return false;
|
| | | JSONArray array = JSONArray.fromObject(value);
|
| | | for (int i = 0; i < array.size(); i++) {
|
| | | XCXSettingConfig config = new Gson().fromJson(array.optJSONObject(i).toString(), XCXSettingConfig.class);
|
| | | if (config.getAppId().equalsIgnoreCase(appId)) {
|
| | | if (version > config.getVersion())
|
| | | return config.isShow();
|
| | | else
|
| | | return true;
|
| | | }
|
| | | }
|
| | | return false;
|
| | | }
|
| | |
|
| | | @Override
|
| | | 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);
|
| | | if (config.getGhId().equalsIgnoreCase(ghId)) {
|
| | | return config;
|
| | | }
|
| | | }
|
| | | return null;
|
| | | }
|
| | |
|
| | | @Override
|
| | | 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+'-'+#system")
|
| | | @Override
|
| | | 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-'+#system")
|
| | | @Override
|
| | | public boolean isConvertTaoBaoLinkInServer( SystemEnum system) {
|
| | | String value = getValue(ConfigKeyEnum.convertTaoBaoLinkInServer.getKey(),system);
|
| | | if (StringUtil.isNullOrEmpty(value))
|
| | | return false;
|
| | | if ("1".equalsIgnoreCase(value.trim()))
|
| | | return true;
|
| | | else
|
| | | return false;
|
| | | }
|
| | |
|
| | | @Cacheable(value = "config", key = "'getAppHomeFloatImg-'+#system")
|
| | | @Override
|
| | | 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);
|
| | | if (appHomeFloatImg.getShow())
|
| | | return appHomeFloatImg;
|
| | | }
|
| | |
|
| | | return null;
|
| | | }
|
| | |
|
| | |
|
| | |
|
| | | @Cacheable(value = "config", key = "'isRobotCloudOpen'+'-'+#key+'-'+#platform+'-'+#version+'-'+#system")
|
| | | @Override
|
| | | 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())) {
|
| | | return true;
|
| | | } else {
|
| | | return false;
|
| | | }
|
| | | }
|
| | |
|
| | |
|
| | | @Cacheable(value = "config", key = "'getTestUsers'")
|
| | | @Override
|
| | | public List<String> getTestUsers( SystemEnum system) {
|
| | | String value = getValue(ConfigKeyEnum.testUserArray.getKey(),system);
|
| | | if (StringUtil.isNullOrEmpty(value))
|
| | | return null;
|
| | | try {
|
| | | return Arrays.asList(value.split(","));
|
| | | } catch (Exception e) {
|
| | | LogHelper.errorDetailInfo(e);
|
| | | }
|
| | | return null;
|
| | | }
|
| | |
|
| | |
|
| | | @Override
|
| | | public Config getConfig(long id) {
|
| | | return configMapper.selectByPrimaryKey(id);
|
| | | }
|
| | |
|
| | | @Override
|
| | | 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]));
|
| | | } catch (Exception e) {
|
| | | }
|
| | | return null;
|
| | | }
|
| | |
|
| | | @Override
|
| | | 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,config.getSystem());
|
| | | if (list == null || list.size() == 0) {
|
| | | configMapper.insertSelective(config);
|
| | | }
|
| | | }
|
| | |
|
| | | @Cacheable(value = "config", key = "'getSearchDiscoveryKeys'")
|
| | | @Override
|
| | | public String getSearchDiscoveryKeys( SystemEnum system) {
|
| | | List<Config> list = configMapper.listByKey(ConfigKeyEnum.searchDiscoveryKeys.getKey(), null, null,system);
|
| | | if (list == null || list.size() == 0)
|
| | | return null;
|
| | |
|
| | | Config config = list.get(0);
|
| | | if (config == null)
|
| | | return null;
|
| | |
|
| | | ThreadUtil.run(new Runnable() {
|
| | | @Override
|
| | | public void run() {
|
| | | // 更新
|
| | | updateSearchDiscoveryKeys(config);
|
| | | }
|
| | | });
|
| | | String value = config.getValue();
|
| | | return value;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 更新搜索发现词
|
| | | *
|
| | | * @param config
|
| | | */
|
| | | private void updateSearchDiscoveryKeys(Config config) {
|
| | | long currentTime = java.lang.System.currentTimeMillis();
|
| | |
|
| | | String createtime = config.getCreatetime();
|
| | | if (!StringUtil.isNullOrEmpty(createtime)) {
|
| | | long diff = currentTime - Long.parseLong(createtime);
|
| | | if (diff < 1000 * 60 * 60)
|
| | | return; // 超过一个小时更新
|
| | | }
|
| | |
|
| | | String hotWords = DaTaoKeApiUtil.getHotWords();
|
| | | if (StringUtil.isNullOrEmpty(hotWords))
|
| | | return;
|
| | | JSONArray array = JSONArray.fromObject(hotWords);
|
| | | String reg = "^([\u4E00-\uFA29]|[\uE7C7-\uE7F3]|[a-zA-Z0-9_-]){1,20}$";
|
| | | List<String> list = new ArrayList<>();
|
| | | for (int i = 0; i < array.size(); i++) {
|
| | | String key = array.optString(i);
|
| | | if (key.matches(reg)) {
|
| | | list.add(key);
|
| | | }
|
| | | }
|
| | | config.setValue(new Gson().toJson(list));
|
| | | config.setCreatetime(currentTime + "");
|
| | | configMapper.updateByPrimaryKeySelective(config);
|
| | | }
|
| | |
|
| | |
|
| | | @Override
|
| | | public Config getConfigBykeyNoCache(String key, SystemEnum system) {
|
| | | List<Config> list = configMapper.listByKey(key, null, null,system);
|
| | | if (list.size() == 0) {
|
| | | return null;
|
| | | }
|
| | | return list.get(0);
|
| | | }
|
| | | }
|