diff options
author | 2016-11-14 15:56:32 +0700 | |
---|---|---|
committer | 2016-11-14 15:56:32 +0700 | |
commit | d03e8b19d346563afec5fb2b6b9c9dcea68040e0 (patch) | |
tree | beb150d73b7734b5ee3823f4b38c68fa2f88f5af /server-core/src/main/java/com/juick/service/ShowQueriesServiceImpl.java | |
parent | ecbc4907669c06c7a71ffda3bd78a163ee1287fe (diff) |
jdbc services
Diffstat (limited to 'server-core/src/main/java/com/juick/service/ShowQueriesServiceImpl.java')
-rw-r--r-- | server-core/src/main/java/com/juick/service/ShowQueriesServiceImpl.java | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/server-core/src/main/java/com/juick/service/ShowQueriesServiceImpl.java b/server-core/src/main/java/com/juick/service/ShowQueriesServiceImpl.java index d3470c75..4f8d8ff2 100644 --- a/server-core/src/main/java/com/juick/service/ShowQueriesServiceImpl.java +++ b/server-core/src/main/java/com/juick/service/ShowQueriesServiceImpl.java @@ -1,10 +1,44 @@ package com.juick.service; +import com.juick.User; +import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.stereotype.Repository; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; /** * Created by aalexeev on 11/13/16. */ @Repository -public class ShowQueriesServiceImpl extends BaseJdbcDao implements SubscriptionService { +@Transactional(readOnly = true) +public class ShowQueriesServiceImpl extends BaseJdbcService implements ShowQueriesService { + + @Override + public List<String> getRecommendedUsers(final User forUser) { + return getJdbcTemplate().queryForList( + "SELECT users.nick FROM subscr_users INNER JOIN users " + + "ON subscr_users.user_id=users.id " + + "WHERE subscr_users.user_id NOT IN (SELECT user_id FROM subscr_users WHERE suser_id=?) " + + "AND subscr_users.suser_id IN (SELECT user_id FROM subscr_users WHERE suser_id=?) " + + "AND subscr_users.user_id NOT IN (SELECT bl_user_id FROM bl_users WHERE user_id=?) " + + "AND subscr_users.user_id!=? AND users.lastmessage>UNIX_TIMESTAMP()-259200 " + + "GROUP BY subscr_users.user_id ORDER BY count(*) DESC LIMIT 10", + String.class, + forUser.getUID(), + forUser.getUID(), + forUser.getUID(), + forUser.getUID()); + } + + @Override + public List<String> getTopUsers() { + return getJdbcTemplate().queryForList( + "SELECT users.nick,COUNT(subscr_users.suser_id) AS cnt " + + "FROM (subscr_users INNER JOIN users ON subscr_users.user_id=users.id) " + + "INNER JOIN useroptions ON users.id=useroptions.user_id " + + "WHERE useroptions.privacy_view>0 AND users.lastmessage > UNIX_TIMESTAMP() - 259200 " + + "AND users.id!=2 GROUP BY subscr_users.user_id ORDER BY cnt DESC LIMIT 10", + String.class); + } } |