BizUserManager.java
2.32 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
package cn.com.glsx.dj.weapp.manager;
import cn.com.glsx.dj.weapp.config.DjWeappProperty;
import cn.com.glsx.dj.weapp.enums.RequestStatusEnum;
import cn.com.glsx.dj.weapp.util.gop.GopUtil;
import cn.com.glsx.dj.weapp.util.gop.RequestConstants;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.glsx.biz.user.common.entity.User;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.RequestMethod;
/**
* @author yangjia
* @Description: 用户信息
* @Title: BizUserManager
* @date 2019/07/03
*/
@Component
public class BizUserManager {
private Logger logger = LoggerFactory.getLogger(getClass());
@Autowired
private DjWeappProperty property;
private static final String MSGKEY = "message";
private static final String CODE = "code";
/**
* 获取用户信息
*
* @param userId
* @return User
* @date 2019/07/03
* @author yangjia
*/
public User getByUserId(Integer userId) {
logger.info("getByUserId(userId:{})", userId);
MultiValueMap<String, String> form = new LinkedMultiValueMap<String, String>();
form.add("userId", String.valueOf(userId));
String requestResult = GopUtil.getRequestResult(form, RequestConstants.GOP_METHOD_BIZUSER_GETBYID, RequestMethod.GET);
logger.info("invoked result:{}", requestResult);
if (StringUtils.isEmpty(requestResult)) {
return null;
}
JSONObject jsonObject = JSON.parseObject(requestResult);
if (!RequestStatusEnum.REQUEST_SUCESS.getValue().equals(jsonObject.getString(CODE))) {
logger.info("getByUserId error code:{}, message{} ", jsonObject.getString(CODE), jsonObject.getString(MSGKEY));
}
String userKey = "user";
if (StringUtils.isNotEmpty(jsonObject.getString(userKey))) {
User user = JSON.parseObject(jsonObject.getString(userKey), new TypeReference<User>() {
});
return user;
}
return null;
}
}