PurchaseHandler.java
2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package com.dili.titan.handler;
import com.dili.titan.domain.RedisKeyConstant;
import com.dili.titan.domain.gq.Purchase;
import com.dili.titan.domain.log.LogHelper;
import com.dili.titan.domain.log.LogTypeEnum;
import com.dili.titan.mq.sender.TopicProducer;
import com.dili.titan.redis.JedisClient;
import com.dili.titan.service.impl.PurchaseService;
import org.apache.commons.collections.CollectionUtils;
import org.codehaus.jackson.JsonNode;
import org.codehaus.jackson.map.DeserializationConfig;
import org.codehaus.jackson.map.ObjectMapper;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
/**
* <B>Description</B> 求购信息 <br />
* <B>Copyright</B> Copyright (c) 2014 www.diligrp.com All rights reserved. <br />
* 本软件源代码版权归地利集团,未经许可不得任意复制与传播.<br />
* <B>Company</B> 地利集团
* @createTime 2014年12月22日 下午6:24:00
* @author ywd
*/
@Component
public class PurchaseHandler implements BaseHandler {
private ObjectMapper mapper = new ObjectMapper().configure(
DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
@Resource
private PurchaseService purchaseService;
@Resource(name = "jedisClient")
private JedisClient jedisClient;
@Resource(name = "topicProducer")
private TopicProducer topicProducer;
@Override
public void handle(String message) throws Exception {
try {
JsonNode node = mapper.readTree(message);
int operType = node.get("oper").asInt();
Long pid = node.get("pid").asLong();
put(pid);
topicProducer.sendMQPurchase(pid,operType);
} catch (Exception e) {
LogHelper.error(LogTypeEnum.PURCHASE, e, e.getMessage());
throw e;
}
}
/**
* this method is 根据供应ID存储供应
* @createTime 2014年12月22日 下午5:14:24
* @author ywd
*/
private void put(Long pid)throws Exception{
try {
Purchase purchase= purchaseService.findByKey(pid);
if(purchase == null){
LogHelper.error(LogTypeEnum.PURCHASE ,
"can't find Purchase by pid={}", pid);
return;
}
String json = mapper.writeValueAsString(purchase);
jedisClient.hput(RedisKeyConstant.PURCHASE,purchase.getId().toString(), json,JedisClient.expireTime);
} catch (Exception e) {
LogHelper.error(LogTypeEnum.PURCHASE, e,
"load putPurchase error!pid={}", pid);
throw e;
}
}
}