UnionShareOrderConsumer.java
3.01 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
package com.yoho.unions.server.mqconsumer;
import com.yoho.core.common.utils.DateUtil;
import com.yoho.core.common.utils.JsonUtil;
import com.yoho.core.rabbitmq.YhConsumer;
import com.yoho.service.model.union.bo.ShareOrderBo;
import com.yoho.unions.common.enums.ShareOrdersKeyEnum;
import com.yoho.unions.common.redis.RedisHashCache;
import com.yoho.unions.server.service.IUnionShareService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.*;
/**
* Created by mingdan.ge on 2018/5/10.
*/
@Component
public class UnionShareOrderConsumer implements YhConsumer {
private Logger logger = LoggerFactory.getLogger("cps_mq");
@Autowired
private IUnionShareService unionShareService;
@Autowired
private RedisHashCache redisHashCache;
@Override
public void handleMessage(Object o) throws Exception{
logger.info("UnionShareOrderConsumer,handleMessage {}", o);
try {
if (null == o) {
return;
}
List<Object> list = JsonUtil.jsonToObject(o.toString(), List.class);
Map<Integer,Set<String>> uids = new HashMap<>();
list.forEach(l->{
try {
ShareOrderBo bo = JsonUtil.jsonToObject(l.toString(), ShareOrderBo.class);
// 订单插入或更新
unionShareService.saveOrUpdateOrder(bo);
Set<String> dates=uids.get(bo.getPromoteUid());
if (dates == null) {
dates = new HashSet<>();
}
dates.add(DateUtil.getDateStrBySecond(bo.getOrderTime(),"yyyyMM"));
uids.put(bo.getPromoteUid(), dates);
} catch (Exception e) {
logger.warn("UnionShareOrderConsumer,handleMessage fail! bo is {}, e {}",l,e.getMessage());
}
});
logger.info("UnionShareOrderConsumer,begin to updateMonthData,uids is {},o is {}",uids, o);
//更新dates月用户月收益数据
uids.forEach((u,dates)->{
//todo 更新uid月预估收益,里面是否需要校验一下log表和order表
try {
unionShareService.updateMonthData(u,dates);
} catch (Exception e) {
logger.warn("UnionShareOrderConsumer,updateMonthData error,uid is {},dates is {},e is {}",u, dates,e.getMessage());
}
});
logger.info("UnionShareOrderConsumer,updateMonthData end,uids is {},o is {}",uids, o);
//清达人相关redis
int date = Integer.valueOf(com.yoho.unions.common.utils.DateUtil.getToday("yyyyMMdd"));
redisHashCache.delete(ShareOrdersKeyEnum.RANK_LIST.getPreKey(),date);
} catch (Exception e) {
logger.warn("UnionShareOrderConsumer,handleMessage fail! obj is {}, e {}",o,e.getMessage());
}
}
}