UserToolObject.java
6.19 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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
package com.xiniunet.erp.tool;
import com.xiniunet.framework.util.SpringContext;
import com.xiniunet.framework.util.auth.LocalData;
import com.xiniunet.master.domain.system.User;
import com.xiniunet.master.request.system.UserGetRequest;
import com.xiniunet.master.response.system.UserGetResponse;
import com.xiniunet.master.service.MasterService;
import java.io.Serializable;
/**
*
* Created on 2014/09/15.
* @author 沈振家
* @version 0.1.0
*/
public class UserToolObject implements Serializable {
private static final long serialVersionUID = -7507510429755782597L;
/**
* 从Spring中取得可以获得用户对象的工具类
*/
private static final MasterService masterService =
(MasterService) SpringContext.getApplicationContext().getBean(MasterService.class);
// /**
// * 从Spring中取得可以获得仓库对象的工具类
// */
// private static final InventoryHelper inventoryHelper =
// (InventoryHelper) SpringContext.getApplicationContext().getBean(InventoryHelper.class);
//
// /**
// * 从Spring中取得可以获得采购对象的工具类
// */
// private static final SalesHelper salesHelper =
// (SalesHelper) SpringContext.getApplicationContext().getBean(SalesHelper.class);
//
// /**
// * 从Spring中取得可以获得销售对象的工具类
// */
// private static final PurchasingHelper purchasingHelper =
// (PurchasingHelper) SpringContext.getApplicationContext().getBean(PurchasingHelper.class);
//
// /**
// * 从Spring中取得可以获得销售对象的工具类
// */
// private static final LedgerHelper ledgerHelper =
// (LedgerHelper) SpringContext.getApplicationContext().getBean(LedgerHelper.class);
//
// public static boolean isStorer(){
// Long userId = LocalData.getCurrentPassport().getUserId();
// StorerFindRequest request = new StorerFindRequest();
// List<Long> userIdList = new ArrayList<>();
// userIdList.add(userId);
// request.setUserIds(userIdList);
// StorerFindResponse response = inventoryHelper.findStorer(request, LocalData.getCurrentPassport());
// if(response.hasError()){
// return false;
// }
// if(response.getTotalCount() < 1){
// return false;
// }
// return true;
// }
//
// public static boolean isSaler(){
// Long userId = LocalData.getCurrentPassport().getUserId();
// SalesPersonFindRequest request = new SalesPersonFindRequest();
// List<Long> userIdList = new ArrayList<>();
// userIdList.add(userId);
// request.setUserIds(userIdList);
// SalesPersonFindResponse response = salesHelper.findSalesPerson(request, LocalData.getCurrentPassport());
// if(response.hasError()){
// return false;
// }
// if(response.getTotalCount() < 1){
// return false;
// }
// return true;
// }
//
// public static boolean isApplicant(){
// Long userId = LocalData.getCurrentPassport().getUserId();
// ApplicantFindRequest request = new ApplicantFindRequest();
// List<Long> userIdList = new ArrayList<>();
// userIdList.add(userId);
// request.setUserIds(userIdList);
// ApplicantFindResponse response = purchasingHelper.findApplicant(request, LocalData.getCurrentPassport());
// if(response.hasError()){
// return false;
// }
// if(response.getTotalCount() < 1){
// return false;
// }
// return true;
// }
//
// public static boolean isBuyer(){
// Long userId = LocalData.getCurrentPassport().getUserId();
// BuyerFindRequest request = new BuyerFindRequest();
// List<Long> userIdList = new ArrayList<>();
// userIdList.add(userId);
// request.setUserIds(userIdList);
// BuyerFindResponse response = purchasingHelper.findBuyer(request, LocalData.getCurrentPassport());
// if(response.hasError()){
// return false;
// }
// if(response.getTotalCount() < 1){
// return false;
// }
// return true;
// }
//
//
// public static boolean isInspector(){
// Long userId = LocalData.getCurrentPassport().getUserId();
// InspectorFindRequest request = new InspectorFindRequest();
// List<Long> userIdList = new ArrayList<>();
// userIdList.add(userId);
// request.setUserIds(userIdList);
// InspectorFindResponse response = purchasingHelper.findInspector(request, LocalData.getCurrentPassport());
// if(response.hasError()){
// return false;
// }
// if(response.getTotalCount() < 1){
// return false;
// }
// return true;
// }
//
// //--------------------财务相关工具-------------------
// /**
// * 当前用户是否是会计人员
// * @return
// */
// public static boolean isAccountant(){
// if(LocalData.getCurrentPassport() != null) {
// Long userId = LocalData.getCurrentPassport().getUserId();
//
// AccountantFindRequest request = new AccountantFindRequest();
// request.setUserId(userId);
// AccountantFindResponse response = ledgerHelper.findAccountant(request, LocalData.getCurrentPassport());
// return response.getTotalCount() > 1;
// }
// return false;
// }
//---------------------系统管理相关工具----------------
/**
* 通过用户ID获取用户名
* @param userId
* @return
*/
public static String getUserName(Long userId) {
UserGetRequest request = new UserGetRequest();
request.setId(userId);
UserGetResponse response = masterService.getUser(request, LocalData.getCurrentPassport());
if (response.hasError()) {
return "";
}
return response.getUser().getName();
}
/**
* 通过用户ID获取用户信息
* @param userId
* @return
*/
public static User getUser(Long userId) {
UserGetResponse response = masterService.getUser(new UserGetRequest(userId), LocalData.getCurrentPassport());
return response.getUser();
}
@Override
public String toString() {
return "";
}
}