public Conversation findByWithMessage(final Long convId) { Conversation result = findBy(convId); String messageQueue = KeyUtils.conversationMessage(convId); for (String msgId : template.opsForList().range(messageQueue, 0, 0)) { result.addMessage(messageDao.findBy(msgId)); } return result; }
public List<Conversation> findBy( final String queueName, final int pageFrom, final int pageSize, String order) { List<Conversation> result = new ArrayList<Conversation>(); List<String> sort = template.sort( SortQueryBuilder.sort(queueName) .order(SortParameters.Order.valueOf(StringUtils.upperCase(order))) .limit(pageFrom, pageSize) .build()); for (String covId : sort) { Conversation c = findBy(Long.valueOf(covId)); String messageQueue = KeyUtils.conversationMessage(Long.valueOf(covId)); for (String msgId : template.opsForList().range(messageQueue, 0, 0)) { c.addMessage(messageDao.findBy(msgId)); } result.add(c); } return result; }
public List<Conversation> findByVisitor(String visitor, int pageFrom, int pageSize) { List<Conversation> result = new ArrayList<Conversation>(); template.delete(KeyUtils.conversationVisitor(visitor)); for (String k : template.keys(KeyUtils.conversationProductIdAndVisitorKey(visitor))) { template .opsForSet() .add(KeyUtils.conversationVisitor(visitor), template.opsForValue().get(k)); } template.delete(KeyUtils.conversationWithMessageKey()); for (String k : template.keys("conversation:*:messages")) { template .opsForSet() .add(KeyUtils.conversationWithMessageKey(), StringUtils.substringBetween(k, ":")); } template .opsForSet() .intersectAndStore( KeyUtils.conversationVisitor(visitor), KeyUtils.conversationWithMessageKey(), KeyUtils.conversationVisitor(visitor)); List<String> sort = template.sort( SortQueryBuilder.sort(KeyUtils.conversationVisitor(visitor)) .order(SortParameters.Order.DESC) .limit(pageFrom, pageSize) .build()); for (String covId : sort) { Conversation c = findBy(Long.valueOf(covId)); String messageQueue = KeyUtils.conversationMessage(Long.valueOf(covId)); for (String msgId : template.opsForList().range(messageQueue, 0, 0)) { c.addMessage(messageDao.findBy(msgId)); result.add(c); } } return result; }