Newer
Older
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
package com.cesgroup.bdc.auth.web;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.cesgroup.authen4.ws.CoreHttpClientWS;
import com.cesgroup.bdc.SelfDefinedGroup.entity.SelfDefinedGroup;
import com.cesgroup.bdc.SelfDefinedGroup.entity.SelfDefinedGroupUser;
import com.cesgroup.bdc.SelfDefinedGroup.service.ISelfDefinedGroupService;
import com.cesgroup.bdc.util.Constant;
import com.cesgroup.kingkong.core.security.model.IOrganization;
import com.cesgroup.kingkong.core.security.model.IUser;
import com.cesgroup.kingkong.core.security.service.AuthsystemService;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Controller
@RequestMapping("/auth")
public class AuthController {
@Autowired
private AuthsystemService authsystemService;
@Autowired
private ISelfDefinedGroupService selfDefinedGroupService;
@Value("${kingkong.authsystem.url}")
private String host;
private CoreHttpClientWS coreHttpClientWS;
/**
* 当前登录用户
*
* @return 用户信息
* @author: shen.shaohua
* @since: 2019/7/3 15:00
*/
private IUser getUser() {
IUser currentUser = (IUser) SecurityUtils.getSubject().getPrincipal();
return currentUser;
}
/**
* 获取部门信息
*
* @return 用户信息
* @author: shen.shaohua
* @since: 2019/7/3 15:00
*/
private IOrganization getOrg(HttpSession session) {
IOrganization org = (IOrganization) session.getAttribute(Constant.CURRENT_USER_ORG);
if (org == null) {
org = authsystemService.getOrganizationByUserId(getUser().getId());
session.setAttribute(Constant.CURRENT_USER_ORG, org);
}
return org;
}
private CoreHttpClientWS getCoreHttpClientWS() {
if (coreHttpClientWS == null) {
System.out.println("host===" + host);
coreHttpClientWS = CoreHttpClientWS.getCoreHttpClientWS(host);
}
return coreHttpClientWS;
}
@RequestMapping("/test")
@ResponseBody
public Map<String, Object> test() {
Map<String, Object> mm = new HashMap<>();
//IUser uu = (IUser) SecurityUtils.getSubject().getPrincipal();
IUser uu = getUser();
//mm.put("user", uu);
List<IOrganization> list = authsystemService.findOrganizationsByTenantId(uu.getTenantId());
mm.put("list", list);
/*Object dd = uu.getUserDetail();
System.out.println(dd.getClass());
mm.put("dd", dd);
boolean cc = getCoreHttpClientWS().checkPasswordByUserId(uu.getId(), "000000");
mm.put("cc", cc);
boolean aa = getCoreHttpClientWS().checkPasswordByUserId(uu.getId(), "010000");
mm.put("aa", aa);*/
return mm;
}
/**
* 修改密码
*
* @param oldPassword
* @param newPassword
* @return
* @author: shen.shaohua
* @since: 2019/7/3 15:09
*/
@RequestMapping("/modifyPassword")
@ResponseBody
public Map<String, Object> modifyPassword(String oldPassword, String newPassword) {
Map<String, Object> mm = new HashMap<>();
IUser uu = getUser();
/*Account account = (Account) uu.getUserDetail();
account.getPassword();*/
try {
boolean correct = getCoreHttpClientWS().checkPasswordByUserId(uu.getId(), oldPassword);
if (correct) {
authsystemService.modifyPassword(uu.getId(), oldPassword, newPassword);
mm.put("code", "0");//成功
} else {
mm.put("code", "1");//原密码错误
}
} catch (Exception e) {
e.printStackTrace();
}
return mm;
}
/**
* 单位选取页面
*
* @author: shen.shaohua
* @since: 2019/7/8 22:37
*/
@RequestMapping("/selectDept")
public ModelAndView selectDept() {
ModelAndView mv = new ModelAndView("auth/selectDept");
return mv;
}
@RequestMapping("/selectStampDept")
public ModelAndView selectStampDept() {
ModelAndView mv = new ModelAndView("stamp/selectDept");
return mv;
}
/**
* 组织树
*
* @return
*/
@RequestMapping("/orgTree")
public ModelAndView orgTree() {
ModelAndView mv = new ModelAndView("auth/orgTree");
return mv;
}
/**
* 组织树数据
*
* @return
*/
@RequestMapping("/orgTreeData")
@ResponseBody
public List<IOrganization> orgTreeData() {
IUser uu = getUser();
List<IOrganization> organizationList = authsystemService.findOrganizationsByTenantId(uu.getTenantId());
return organizationList;
}
/**
* 组织及自定义组树数据
*
* @return
*/
@RequestMapping("/orgAndSelfTreeData")
@ResponseBody
public List<Map<String, Object>> orgAndSelfTreeData(HttpServletRequest request, HttpSession session) {
String searchName = request.getParameter("searchName");
System.out.println(searchName);
List<Map<String, Object>> list = new ArrayList<>();
IUser uu = getUser();
List<IOrganization> organizationList0 = authsystemService.findOrganizationsByTenantId(uu.getTenantId());
List<IOrganization> organizationList = null;
if (StrUtil.isNotBlank(searchName)) {
organizationList = organizationList0.stream().filter(org -> org.getName().indexOf(searchName) >= 0).collect(Collectors.toList());
addToTargetList(searchName, organizationList0, organizationList);
} else {
organizationList = organizationList0;
}
organizationList.forEach(org -> {
Map<String, Object> m = BeanUtil.beanToMap(org);
m.put("deptId", org.getId());
if (StrUtil.isEmpty(org.getParentId())) {
m.put("type", "orgRoot"); //根节点
m.put("open", true);
} else {
m.put("type", "org");
}
list.add(m);
});
Map<String, Object> root2 = new HashMap<>();
root2.put("id", "selfGroup");
root2.put("name", "自定义组");
root2.put("type", "groupRoot");
//root2.put("isParent", true);
root2.put("open", true);
list.add(root2);
//List<SelfDefinedGroup> selfDefinedGroupList = selfDefinedGroupService.getAll(uu.getId()); //修改自定义组查询权限
List<SelfDefinedGroup> selfDefinedGroupList = selfDefinedGroupService.getAll(getOrg(session).getId()); //修改自定义组查询权限
for (SelfDefinedGroup selfDefinedGroup : selfDefinedGroupList) {
List<SelfDefinedGroupUser> selfDefinedGroupUserList = selfDefinedGroup.getDeptList();
selfDefinedGroup.setDeptList(null);
Map<String, Object> m1 = BeanUtil.beanToMap(selfDefinedGroup);
m1.remove("deptList");
m1.put("type", "group");
m1.put("parentId", "selfGroup");
m1.put("name", selfDefinedGroup.getGroupName());
list.add(m1); //自定义组
for (SelfDefinedGroupUser selfDefinedGroupUser : selfDefinedGroupUserList) {
Map<String, Object> m2 = BeanUtil.beanToMap(selfDefinedGroupUser);
m2.put("type", "groupElement");
m2.put("parentId", selfDefinedGroupUser.getGroupId());
m2.put("id", selfDefinedGroupUser.getId());
m2.put("deptId", selfDefinedGroupUser.getDeptId());
m2.put("name", this.getDeptName(organizationList0, selfDefinedGroupUser.getDeptId()));
list.add(m2); //自定义组下的部门
}
}
return list;
}
/**
* 组织及自定义组树数据
*
* @return
*/
@RequestMapping("/orgStampTreeData")
@ResponseBody
public List<Map<String, Object>> orgStampTreeData(HttpServletRequest request, HttpSession session) {
String searchName = request.getParameter("searchName");
System.out.println(searchName);
List<Map<String, Object>> list = new ArrayList<>();
IUser uu = getUser();
List<IOrganization> organizationList0 = authsystemService.findOrganizationsByTenantId(uu.getTenantId());
List<IOrganization> organizationList = null;
if (StrUtil.isNotBlank(searchName)) {
organizationList = organizationList0.stream().filter(org -> org.getName().indexOf(searchName) >= 0).collect(Collectors.toList());
addToTargetList(searchName, organizationList0, organizationList);
} else {
organizationList = organizationList0;
}
//获取当前用户
IUser user = (IUser) SecurityUtils.getSubject().getPrincipal();
//获取当前用户组织
IOrganization org1 = authsystemService.getOrganizationByUserId(user.getId());
organizationList.forEach(org -> {
if (!org.getId().equals(org1.getId())) {
Map<String, Object> m = BeanUtil.beanToMap(org);
m.put("deptId", org.getId());
if (StrUtil.isEmpty(org.getParentId())) {
m.put("type", "orgRoot"); //根节点
m.put("open", true);
} else {
m.put("type", "org");
}
list.add(m);
}
});
return list;
}
private void addToTargetList(String searchName, List<IOrganization> organizationList0, List<IOrganization> targetList) {
List<IOrganization> targetList2 = CollUtil.newArrayList(targetList);
for (IOrganization parentOrg : targetList2) {
loopAddToTargetList(searchName, parentOrg, organizationList0, targetList);
}
}
private void loopAddToTargetList(String searchName, IOrganization parentOrg, List<IOrganization> organizationList0, List<IOrganization> targetList) {
for (IOrganization oo : organizationList0) {
if (oo.getParentId() != null && oo.getParentId().equals(parentOrg.getId()) && oo.getName().indexOf(searchName) < 0) {
targetList.add(oo);
loopAddToTargetList(searchName, oo, organizationList0, targetList);
}
}
}
private String getDeptName(List<IOrganization> organizationList, String orgId) {
String orgName = "";
for (IOrganization org : organizationList) {
if (orgId.equals(org.getId())) {
orgName = org.getName();
break;
}
}
return orgName;
}
}