From e4c7f45ed5a06512fa9981ef63d256e950b433c8 Mon Sep 17 00:00:00 2001
From: yujian <yujian@163.com>
Date: 星期一, 29 六月 2020 17:54:22 +0800
Subject: [PATCH] 取消新人免单券奖励
---
fanli/src/main/java/com/yeshi/fanli/service/impl/config/ConfigServiceImpl.java | 204 ++++++++++++++++++++++++++++++++++++++------------
1 files changed, 154 insertions(+), 50 deletions(-)
diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/config/ConfigServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/config/ConfigServiceImpl.java
index 8174bca..ed14aee 100644
--- a/fanli/src/main/java/com/yeshi/fanli/service/impl/config/ConfigServiceImpl.java
+++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/config/ConfigServiceImpl.java
@@ -1,94 +1,97 @@
package com.yeshi.fanli.service.impl.config;
-import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Date;
import java.util.List;
import javax.annotation.Resource;
-import net.sf.json.JSONArray;
-
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
+import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.yeshi.utils.entity.ProxyIP;
import com.google.gson.Gson;
-import com.yeshi.fanli.dao.config.ConfigDao;
+import com.yeshi.fanli.dao.mybatis.ConfigMapper;
import com.yeshi.fanli.entity.common.Config;
import com.yeshi.fanli.entity.config.AppHomeFloatImg;
+import com.yeshi.fanli.entity.system.ConfigKeyEnum;
import com.yeshi.fanli.entity.xcx.XCXSettingConfig;
+import com.yeshi.fanli.log.LogHelper;
import com.yeshi.fanli.service.inter.config.ConfigService;
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.StringUtil;
+import com.yeshi.fanli.util.dataoke.DaTaoKeApiUtil;
+
+import net.sf.json.JSONArray;
@Service
public class ConfigServiceImpl implements ConfigService {
@Resource
- private ConfigDao configDao;
+ private ConfigMapper configMapper;
+
@Cacheable(value = "config")
public List<Config> getAllList() {
- return configDao.list("from Config");
+ return configMapper.listAll();
}
@Override
public List<Config> listObjects(String key, int page) {
int start = (page - 1) * Constant.PAGE_SIZE;
- StringBuffer hqlBuf = new StringBuffer("from Config pr where 1=1 ");
-
- if (key != null && !"".equals(key.trim())) {
- hqlBuf.append(" and (pr.name like ? )");
- }
-
- hqlBuf.append(" order by pr.id desc ");
- String hql = hqlBuf.toString();
- if (hql.contains("pr.name")) {
- return configDao.list(hqlBuf.toString(), start, Constant.PAGE_SIZE, new Serializable[] { "%" + key + "%" });
- } else {
- return configDao.list(hqlBuf.toString(), start, Constant.PAGE_SIZE, new Serializable[] {});
- }
-
+ return configMapper.listSearchByName(key, start, Constant.PAGE_SIZE);
}
@Override
- public int getCount(String key, int page) {
-
- StringBuffer hqlBuf = new StringBuffer("select count(*) from Config pr where 1=1 ");
-
- if (key != null && !"".equals(key.trim())) {
- hqlBuf.append(" and (pr.name like ? )");
- }
-
- String hql = hqlBuf.toString();
-
- if (hql.contains("pr.name")) {
- return (int) configDao.getCount(hqlBuf.toString(), new Serializable[] { "%" + key + "%" });
- } else {
- return (int) configDao.getCount(hqlBuf.toString(), new Serializable[] {});
- }
+ 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() + "");
- configDao.update(config);
+ configMapper.updateByPrimaryKeySelective(config);
}
}
@CacheEvict(value = "config", allEntries = true)
public void update(Config config) {
+ if (config.getValue() == null)
+ config.setValue("");
+
config.setCreatetime(new Date().getTime() + "");
- configDao.update(config);
+ configMapper.updateByPrimaryKeySelective(config);
}
@Cacheable(value = "config", key = "#p0+'Str'")
public String get(String key) {
- List<Config> list = configDao.list("from Config c where c.key=? ", new Serializable[] { 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;
}
@@ -98,7 +101,7 @@
@Cacheable(value = "config", key = "#p0")
public Config getConfig(String key) {
- List<Config> list = configDao.list("from Config c where c.key=? ", new Serializable[] { key });
+ List<Config> list = configMapper.listByKey(key, null, null);
if (list.size() == 0) {
return null;
}
@@ -110,7 +113,7 @@
if (version == null)
return false;
- String value = get("xcx_setting");
+ String value = get(ConfigKeyEnum.xcxSetting.getKey());
if (StringUtil.isNullOrEmpty(value))
return false;
JSONArray array = JSONArray.fromObject(value);
@@ -128,7 +131,7 @@
@Override
public XCXSettingConfig getXCXInfoByGhId(String ghId) {
- String value = get("xcx_setting");
+ 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);
@@ -141,7 +144,7 @@
@Override
public String getH5Host() {
- String value = get("h5_url");
+ String value = get(ConfigKeyEnum.h5Url.getKey());
String[] sts = value.split(",");
value = sts[(int) (sts.length * Math.random())];
return value.trim();
@@ -150,7 +153,7 @@
@Cacheable(value = "config", key = "'iosOnLining'+#version")
@Override
public boolean iosOnLining(int version) {
- String value = get("ios_onling_version");
+ String value = get(ConfigKeyEnum.iosOnlingVersion.getKey());
if (StringUtil.isNullOrEmpty(value))
return false;
return version >= Integer.parseInt(value);
@@ -159,7 +162,7 @@
@Cacheable(value = "config", key = "'isConvertTaoBaoLinkInServer'")
@Override
public boolean isConvertTaoBaoLinkInServer() {
- String value = get("convert_taobao_link_in_server");
+ String value = get(ConfigKeyEnum.convertTaoBaoLinkInServer.getKey());
if (StringUtil.isNullOrEmpty(value))
return false;
if ("1".equalsIgnoreCase(value.trim()))
@@ -171,7 +174,7 @@
@Cacheable(value = "config", key = "'getAppHomeFloatImg'")
@Override
public AppHomeFloatImg getAppHomeFloatImg() {
- String value = get("app_float_img");
+ String value = get(ConfigKeyEnum.appFloatImg.getKey());
if (!StringUtil.isNullOrEmpty(value)) {
Gson gson = new Gson();
AppHomeFloatImg appHomeFloatImg = gson.fromJson(value, AppHomeFloatImg.class);
@@ -185,18 +188,52 @@
@Cacheable(value = "config", key = "'getHomeWEEXUrl'")
@Override
public String getHomeWEEXUrl() {
- String value = get("home_weex_url");
+ 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;
+ }
+ }
+
+
+
+ @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 configDao.find(Config.class, id);
+ return configMapper.selectByPrimaryKey(id);
}
@Override
public ProxyIP getTaoBaoProxyIP() {
- String value = get("taobao_proxy_ip");
+ String value = get(ConfigKeyEnum.taobaoProxyIP.getKey());
try {
String[] sts = value.split(":");
return new ProxyIP(sts[0], Integer.parseInt(sts[1]));
@@ -207,8 +244,75 @@
@Override
public String getAppHomeFloatNotifyImg() {
-
- return get("home_float_notify_img");
+ return get(ConfigKeyEnum.homeFloatNotifyImg.getKey());
}
+ @Override
+ public void save(Config config) {
+ List<Config> list = configMapper.listByKey(config.getKey(), null, null);
+ if (list == null || list.size() == 0) {
+ configMapper.insertSelective(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;
+
+ Config config = list.get(0);
+ if (config == null)
+ return null;
+
+ // 鏇存柊
+ updateSearchDiscoveryKeys(config);
+
+ String value = config.getValue();
+ return value;
+ }
+
+ /**
+ * 鏇存柊鎼滅储鍙戠幇璇�
+ *
+ * @param config
+ */
+ @Async
+ 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) {
+ List<Config> list = configMapper.listByKey(key, null, null);
+ if (list.size() == 0) {
+ return null;
+ }
+ return list.get(0);
+ }
}
--
Gitblit v1.8.0