From 4cb15e222cd7d099d533ccbeb7f9a8cd99bf180c Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期二, 25 十二月 2018 16:35:18 +0800
Subject: [PATCH] 替换原来老的资金详情

---
 fanli/src/main/java/com/yeshi/fanli/service/impl/config/HotSearchServiceImpl.java |  128 ++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 128 insertions(+), 0 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/config/HotSearchServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/config/HotSearchServiceImpl.java
index ecd44c8..d8d777a 100644
--- a/fanli/src/main/java/com/yeshi/fanli/service/impl/config/HotSearchServiceImpl.java
+++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/config/HotSearchServiceImpl.java
@@ -8,6 +8,7 @@
 
 import javax.annotation.Resource;
 
+import org.apache.commons.beanutils.PropertyUtils;
 import org.hibernate.HibernateException;
 import org.hibernate.Query;
 import org.hibernate.Session;
@@ -23,6 +24,7 @@
 import com.yeshi.fanli.service.inter.config.SuperHotSearchService;
 import com.yeshi.fanli.service.inter.config.SystemService;
 import com.yeshi.fanli.util.Constant;
+import com.yeshi.fanli.util.StringUtil;
 import com.yeshi.fanli.util.Utils;
 
 @Service
@@ -202,4 +204,130 @@
 		});
 	}
 
+	
+	@Override
+	@SuppressWarnings("unchecked")
+	public List<HotSearch> listQuery(int start, int count, String key, Long systemId) throws Exception {
+		
+		List<HotSearch> listObj = null;
+		if (systemId == null) {
+			
+			String hql = "from HotSearch hs where 1=1 ";
+			if (!StringUtil.isNullOrEmpty(key)) {
+				hql += " hs.name like ?";
+			}
+			final String queryHQL = hql;
+			
+			listObj = (List<HotSearch>) hotSearchDao.excute(new HibernateCallback<List<HotSearch>>() {
+				public List<HotSearch> doInHibernate(Session session) throws HibernateException {
+					Query query = session.createQuery(queryHQL);
+					query.setFirstResult(start);
+					query.setMaxResults(count);
+					if (!StringUtil.isNullOrEmpty(key)) {
+						query.setParameter(0, "%" + key + "%");
+					}
+					return query.list();
+				}
+			});
+			
+		} else {
+			List<SuperHotSearch> superHotSearchList = null;
+			if(StringUtil.isNullOrEmpty(key)){
+				superHotSearchList = superHotSearchService.getSuperHotSearchBySystemId(systemId,start, count);
+			}else{
+				String likekey = "%"+key+"%";
+				superHotSearchList = superHotSearchService.getSuperHotSearchBySystemId(systemId, start, count, likekey);
+			}
+			
+			if (superHotSearchList != null && superHotSearchList.size() > 0) {
+				listObj = new ArrayList<HotSearch>();
+				for (SuperHotSearch superHotSearch: superHotSearchList) {
+					HotSearch hotSearch = superHotSearch.getHotSearch();
+					listObj.add(hotSearch);
+				}
+			}
+		}
+
+
+		if (listObj == null || listObj.size() == 0) {
+			return null;
+		}
+		List<Long> listId = new ArrayList<>();
+		for (HotSearch hotSearch : listObj) {
+			listId.add(hotSearch.getId());
+		}
+		
+		
+		List<System> systemList = systemService.getSystems();
+		
+		List<SuperHotSearch> listSuper = superHotSearchService.listSuperHotSearch(listId);
+		
+		if (listSuper == null || listSuper.size() == 0) {
+			for (HotSearch hotSearch : listObj) {
+				hotSearch.setSystemList(systemList);
+			}
+		} else {
+			for (HotSearch hotSearch : listObj) {
+				Long id = hotSearch.getId();
+				List<System> newList = new ArrayList<System>();
+			
+				// 鏄惁鏈夊叧鑱旂郴缁熼�夐」
+				for (System dsystem : systemList) {
+					System newsystem = new System();
+
+					try {
+						PropertyUtils.copyProperties(newsystem, dsystem);
+					} catch (Exception e) {
+						e.printStackTrace();
+					}
+
+					if (listSuper != null && listSuper.size() > 0) {
+
+						Long superSystemId = newsystem.getId();
+
+						for (SuperHotSearch superHotSearch : listSuper) {
+							HotSearch search = superHotSearch.getHotSearch();
+							System system = superHotSearch.getSystem();
+
+							// 褰撳墠涓撻 銆佸綋鍓嶇郴缁�
+							if (search != null && system != null && id == search.getId() && superSystemId == system.getId()) {
+								newsystem.setCheck(1);
+								break;
+							}
+						}
+					}
+
+					if (newsystem.getCheck() != 1) {
+						newsystem.setCheck(0);
+					}
+					newList.add(newsystem);
+				}
+				hotSearch.setSystemList(newList);
+			}
+		}
+		
+		
+
+		return listObj;
+	}
+	
+	@Override
+	public int countList(String key, Long systemId) {
+		return (Integer) hotSearchDao.excute(new HibernateCallback<Integer>() {
+			
+			public Integer doInHibernate(Session session)
+					throws HibernateException {
+				Query query = null;
+				if (StringUtil.isNullOrEmpty(key)) {
+					query = session.createQuery("select count(hs.id) from HotSearch hs");
+				} else {
+					query = session.createQuery("select count(hs.id) from HotSearch hs where hs.name like ?");
+					query.setParameter(0, "%"+key+"%");
+				}
+				Long result = (Long) query.uniqueResult();
+				return result.intValue();
+			}
+		});
+	}
+
 }

--
Gitblit v1.8.0