package com.yeshi.fanli.service.impl.config;
|
|
import java.io.Serializable;
|
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.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import com.google.gson.Gson;
|
import com.yeshi.fanli.dao.config.ConfigDao;
|
import com.yeshi.fanli.entity.common.Config;
|
import com.yeshi.fanli.entity.config.AppHomeFloatImg;
|
import com.yeshi.fanli.entity.xcx.XCXSettingConfig;
|
import com.yeshi.fanli.service.inter.config.ConfigService;
|
import com.yeshi.fanli.util.Constant;
|
import com.yeshi.fanli.util.StringUtil;
|
|
@Service
|
public class ConfigServiceImpl implements ConfigService {
|
|
@Resource
|
private ConfigDao configDao;
|
|
@Cacheable(value = "config")
|
public List<Config> getAllList() {
|
return configDao.list("from Config");
|
}
|
|
@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[] {});
|
}
|
|
}
|
|
@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[] {});
|
}
|
}
|
|
@CacheEvict(value = "config", allEntries = true)
|
@Transactional
|
public void update(List<Config> list) {
|
for (Config config : list) {
|
config.setCreatetime(new Date().getTime() + "");
|
configDao.update(config);
|
}
|
}
|
|
@CacheEvict(value = "config", allEntries = true)
|
public void update(Config config) {
|
config.setCreatetime(new Date().getTime() + "");
|
configDao.update(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 });
|
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 = configDao.list("from Config c where c.key=? ", new Serializable[] { key });
|
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("xcx_setting");
|
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("xcx_setting");
|
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("h5_url");
|
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("ios_onling_version");
|
if (StringUtil.isNullOrEmpty(value))
|
return false;
|
return version >= Integer.parseInt(value);
|
}
|
|
@Cacheable(value = "config", key = "'isConvertTaoBaoLinkInServer'")
|
@Override
|
public boolean isConvertTaoBaoLinkInServer() {
|
String value = get("convert_taobao_link_in_server");
|
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("app_float_img");
|
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("home_weex_url");
|
return value;
|
}
|
|
@Override
|
public Config getConfig(long id) {
|
return configDao.find(Config.class, id);
|
}
|
|
}
|