UserServiceHelper.java
2.44 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
82
/**
*
*/
package com.yoho.unions.helper;
import com.yoho.core.rest.client.ServiceCaller;
import com.yoho.core.rest.client.hystrix.AsyncFuture;
import com.yoho.error.exception.ServiceException;
import com.yoho.service.model.order.request.OrdersStatusStatisticsRequest;
import com.yoho.service.model.order.response.CountBO;
import com.yoho.unions.vo.ApiResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;
/**
* @author ping.huang
* 2016年12月29日
*/
@Component
public class UserServiceHelper {
static Logger log = LoggerFactory.getLogger(UserServiceHelper.class);
@Resource
ServiceCaller serviceCaller;
@Resource
ClientSecretHelper clientSecretHelper;
@Value("${gateway.url}")
private String gatewayUrl;
/**
* 根据uid,查询订单数
* @param uid
* @return
* @throws ServiceException
*/
public CountBO getOrderCountByUid(int uid) throws ServiceException {
log.info("start with getOrderCountByUid. uid is {}", uid);
if (uid == 0) {
log.warn("getOrderCountByUid error with uid={}", uid);
return null;
}
OrdersStatusStatisticsRequest request = new OrdersStatusStatisticsRequest();
request.setUid(uid);
CountBO result = serviceCaller.call("order.getOrdersCountByUidAndStatus", request, CountBO.class);
log.info("getOrderCountByUid success with response={}. uid is {}", result, uid);
return result;
}
public ApiResponse getProfileByUid(int uid) throws ServiceException {
log.info("start with getProfileByUid. uid is {}", uid);
if (uid == 0) {
log.warn("getProfileByUid error with uid={}", uid);
return null;
}
Map<String, String> map = new HashMap<String, String>();
map.put("method", "app.passport.profile");
map.put("uid", String.valueOf(uid));
String param = clientSecretHelper.createClientSecret(map);
// 调用gateway的获取用户信息
AsyncFuture<ApiResponse> response = serviceCaller.get("user.getProfileByUid", gatewayUrl + "?" + param, null, ApiResponse.class, null);
ApiResponse apiResponse = response.get();
if(apiResponse.getCode() != 200){
log.warn("call app.passport.profile error e={}", apiResponse.getMessage());
return new ApiResponse();
}
log.info("getProfileByUid success with response={}. uid is {}", apiResponse, uid);
return apiResponse;
}
}