UserRoleRpcService.java
4.36 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package cn.fw.valhalla.rpc.erp;
import cn.fw.data.base.domain.common.Message;
import cn.fw.erp.sdk.api.UserRoleApi;
import cn.fw.erp.sdk.api.result.UserRoleDataRange;
import cn.fw.erp.sdk.api.result.UserRoleInfo;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
/**
* 用户角色RPC服务
* <p>
* create at 2020-06-15
*
* @author kurisu
*/
@Slf4j
@Service
public class UserRoleRpcService {
private final UserRoleApi userRoleApi;
public UserRoleRpcService(UserRoleApi userRoleApi) {
this.userRoleApi = userRoleApi;
}
/**
* 查询用户角色的数据权限范围(门店)
*
* @param userId 用户id
* @param roleCode 角色码
* @return 门店ids
*/
public List<Long> getManageShopIds(Long userId, String roleCode) {
if (userId == null) {
return null;
}
try {
Message<List<UserRoleDataRange>> msg = userRoleApi.queryUserRoleDataRange(userId, roleCode);
log.warn("调用ERP系统查询用户数据范围,userId:{},roleCode:{}, result:{}", userId, roleCode, JSONObject.toJSONString(msg));
if (!msg.isSuccess()) {
return Collections.emptyList();
}
List<UserRoleDataRange> userRoleDataRangeList = msg.getData();
return userRoleDataRangeList.stream().map(UserRoleDataRange::getRangeValue)
.collect(Collectors.toList());
} catch (Exception e) {
log.error("调用ERP系统查询用户数据范围,userId:{},roleCode:{}, 异常:{}", userId, roleCode, e);
}
return Collections.emptyList();
}
/**
* 查询用户拥有的角色
*
* @param userId 用户id
*/
public List<UserRoleInfo> getUserRoles(Long userId) {
if (Objects.isNull(userId)) {
return Collections.emptyList();
}
String func = "调用ERP系统查询用户拥有的角色";
try {
Message<List<UserRoleInfo>> msg = userRoleApi.queryUserRoleList(userId);
log.info("{},userId:{},result:{}", func, userId, JSON.toJSONString(msg));
if (msg.isSuccess()) {
return msg.getData();
}
} catch (Exception e) {
log.error("{}失败,userId:{}", func, userId, e);
}
return Collections.emptyList();
}
/**
* 查询用户角色的数据权限范围
*
* @param userId 用户id
* @param roleCode 角色代码
*/
public List<UserRoleDataRange> getUserRoleDataRange(Long userId, String roleCode) {
if (Objects.isNull(userId) || Objects.isNull(roleCode)) {
return Collections.emptyList();
}
String func = "调用ERP系统查询用户角色的数据权限范围";
try {
Message<List<UserRoleDataRange>> msg = userRoleApi.queryUserRoleDataRange(userId, roleCode);
log.info("{},userId:{},roleCode:{},result:{}", func, userId, roleCode, JSON.toJSONString(msg));
if (msg.isSuccess()) {
return msg.getData();
}
} catch (Exception e) {
log.error("{}失败,userId:{},roleCode:{}", func, userId, roleCode, e);
}
return Collections.emptyList();
}
/**
* 查询指定服务站指定角色的用户信息
*
* @param shopId 服务站id
* @param roleCode 角色代码
*/
public List<UserRoleInfo> getUsers(Long shopId, String roleCode) {
if (Objects.isNull(shopId) || Objects.isNull(roleCode)) {
return Collections.emptyList();
}
String func = "调用ERP系统查询指定服务站指定角色的用户信息";
try {
Message<List<UserRoleInfo>> msg = userRoleApi.queryUserRoleInfos(roleCode, shopId);
log.info("{},shopId:{},roleCode:{},result:{}", func, shopId, roleCode, JSON.toJSONString(msg));
if (msg.isSuccess()) {
return msg.getData();
}
} catch (Exception e) {
log.error("{}失败,shopId:{},roleCode:{}", func, shopId, roleCode, e);
}
return Collections.emptyList();
}
}