@Override @SuppressWarnings("unchecked") public Conversation create(Conversation conv) { final Long id = getId(conv); if (template .opsForValue() .get( KeyUtils.conversationProductIdAndVisitorToken( conv.getTopic().getProductId(), conv.getVisitor())) != null) { return findBy(id); } conv.setId(id); template.opsForHash().put(getIdKey(id), "id", id.toString()); template.opsForHash().put(getIdKey(id), "topic", conv.getTopic().getId().toString()); template.opsForHash().put(getIdKey(id), "visitor", conv.getVisitor()); template.opsForHash().put(getIdKey(id), "visitorName", conv.getVisitorName()); template .opsForHash() .put(getIdKey(id), "customerServiceUser", conv.getCustomerServiceUsername()); template.opsForHash().put(getIdKey(id), "status", conv.getStatus().toString()); template .opsForHash() .put(getIdKey(id), "createDate", String.valueOf(conv.getCreateDate().getTime())); template .opsForValue() .set( KeyUtils.conversationProductIdAndVisitorToken( conv.getTopic().getProductId(), conv.getVisitor()), id.toString()); return conv; }
public Conversation findBy(Long id) { Conversation result = new Conversation(); result.setId(id); result.setVisitor(template.opsForHash().get(getIdKey(id), "visitor").toString()); result.setVisitorName(template.opsForHash().get(getIdKey(id), "visitorName").toString()); result.setStatus( ConversationStatus.valueOf(template.opsForHash().get(getIdKey(id), "status").toString())); Date d = new Date(Long.valueOf(template.opsForHash().get(getIdKey(id), "createDate").toString())); String topicId = template.opsForHash().get(getIdKey(id), "topic").toString(); result.setTopic(createConversationTopic(topicId)); String userName = template.opsForHash().get(getIdKey(id), "customerServiceUser").toString(); if (StringUtils.isNotEmpty(userName)) { result.setCustomerServiceUser(customerServiceUserDao.findBy(userName)); } result.setCreateDate(d); return result; }