yujian
2019-02-28 70c9043f312a52a922cb15490d90a172b3515060
fanli/src/main/java/com/yeshi/fanli/service/impl/config/ConfigServiceImpl.java
@@ -12,6 +12,7 @@
import org.springframework.cache.annotation.Cacheable;
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;
@@ -35,42 +36,41 @@
   @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())){
      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+"%"});
      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 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())){
      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+"%"});
      if (hql.contains("pr.name")) {
         return (int) configDao.getCount(hqlBuf.toString(), new Serializable[] { "%" + key + "%" });
      } else {
         return (int) configDao.getCount(hqlBuf.toString(), new Serializable[]{});
         return (int) configDao.getCount(hqlBuf.toString(), new Serializable[] {});
      }
   }
   @CacheEvict(value = "config", allEntries = true)
   @Transactional
   public void update(List<Config> list) {
@@ -142,6 +142,8 @@
   @Override
   public String getH5Host() {
      String value = get("h5_url");
      String[] sts = value.split(",");
      value = sts[(int) (sts.length * Math.random())];
      return value.trim();
   }
@@ -186,10 +188,27 @@
      String value = get("home_weex_url");
      return value;
   }
   @Override
   public Config getConfig(long id) {
      return configDao.find(Config.class, id);
   }
   @Override
   public ProxyIP getTaoBaoProxyIP() {
      String value = get("taobao_proxy_ip");
      try {
         String[] sts = value.split(":");
         return new ProxyIP(sts[0], Integer.parseInt(sts[1]));
      } catch (Exception e) {
      }
      return null;
   }
   @Override
   public String getAppHomeFloatNotifyImg() {
      return get("home_float_notify_img");
   }
}