SysUserController.java
50.2 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
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
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
package com.skua.modules.system.controller;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.skua.aop.annotation.CustomExceptionAnno;
import com.skua.core.api.ISysBaseAPI;
import com.skua.core.api.vo.LoginUser;
import com.skua.core.api.vo.Result;
import com.skua.core.aspect.annotation.AutoLog;
import com.skua.core.cache.RedisUtil;
import com.skua.core.constant.CommonConstant;
import com.skua.core.context.BaseContextHandler;
import com.skua.core.query.QueryGenerator;
import com.skua.core.util.ConvertUtils;
import com.skua.core.util.JwtUtil;
import com.skua.core.util.PasswordUtil;
import com.skua.core.util.push.IPushService;
import com.skua.core.util.push.MessageEntity;
import com.skua.core.util.push.PushMessageFactory;
import com.skua.modules.system.entity.*;
import com.skua.modules.system.model.DepartIdModel;
import com.skua.modules.system.service.ISysDepartService;
import com.skua.modules.system.service.ISysUserDepartService;
import com.skua.modules.system.service.ISysUserRoleService;
import com.skua.modules.system.service.ISysUserService;
import com.skua.modules.system.vo.SysDepartUsersVO;
import com.skua.modules.system.vo.SysUserRoleVO;
import com.skua.modules.system.vo.SysUserVO;
import com.skua.tool.query.WrapperFactory;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.jeecgframework.poi.excel.ExcelImportUtil;
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.entity.ImportParams;
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;
import springfox.documentation.annotations.ApiIgnore;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.*;
import java.util.regex.Pattern;
/**
* 用户表 前端控制器
*/
@Api(tags = "用户管理")
@ApiIgnore
@Slf4j
@RestController
@RequestMapping("/sys/user")
public class SysUserController {
@Autowired
private ISysBaseAPI sysBaseAPI;
@Autowired
private ISysUserService sysUserService;
@Autowired
private ISysDepartService sysDepartService;
@Autowired
private ISysUserRoleService sysUserRoleService;
@Autowired
private ISysUserDepartService sysUserDepartService;
@Autowired
private ISysUserRoleService userRoleService;
@Autowired
private RedisUtil redisUtil;
/**
* 校验手机号格式
*/
private static final Pattern PATTERN_PHONE = Pattern.compile("^((13[0-9])|(15[^4,\\D])|(18[0,5-9]))\\d{8}$");
/**
* 用户列表不分页
*
* @param user
* @param req
* @return
*/
@ApiOperation(value = "用户列表", notes = "用户列表-无分页")
@RequestMapping(value = "/listNoPage", method = RequestMethod.GET)
public Result<List<SysUser>> queryNoPageList(SysUser user, HttpServletRequest req) {
Result<List<SysUser>> result = new Result<List<SysUser>>();
QueryWrapper<SysUser> queryWrapper = QueryGenerator.initQueryWrapper(user, req.getParameterMap());
queryWrapper.eq("is_system_user", "0");
//获取登陆人所属集团
SysUser nowUser = sysUserService.getById(BaseContextHandler.getUserId());
queryWrapper.eq("org_code", nowUser.getOrgCode().substring(0, 3));
List<SysUser> pageList = sysUserService.list(queryWrapper);
result.setSuccess(true);
result.setResult(pageList);
return result;
}
/**
* 用户列表分页
*
* @param user
* @param pageNo
* @param pageSize
* @return
*/
@RequestMapping(value = "/list", method = RequestMethod.GET)
public Result<IPage<SysUser>> queryPageList(SysUser user, @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
Result<IPage<SysUser>> result = new Result<IPage<SysUser>>();
List<String> factorys = new ArrayList<>();
if (!BaseContextHandler.getUserLoginName().equals("superadmin")) {
user.setIsSystemUser("0");
List<String> departIds = sysUserDepartService.queryDepartIdsOfUserId(BaseContextHandler.getUserId());
factorys.addAll(departIds);
if (!StringUtils.isBlank(user.getAreaId())) {
List<String> list = new ArrayList<>();
list.add(user.getAreaId());
List<String> list1 = sysUserDepartService.loopDepart(list);
factorys.addAll(list1);
}
if (!CollectionUtils.isEmpty(factorys)) {
user.setDepartIds(factorys.toArray(new String[factorys.size()]));
}
}
Page<SysUser> page = new Page<SysUser>(pageNo, pageSize);
IPage<SysUser> pageList = sysUserService.queryDepartAndRoleList(page, user);
result.setSuccess(true);
result.setResult(pageList);
return result;
}
@RequestMapping(value = "/add", method = RequestMethod.POST)
@RequiresPermissions("user:add")
@AutoLog(value = "新增用户信息")
public Result<SysUser> add(@RequestBody JSONObject jsonObject) {
Result<SysUser> result = new Result<SysUser>();
String selectedRoles = jsonObject.getString("selectedroles");
String selectedDeparts = jsonObject.getString("selecteddeparts");
String selectedManageDeparts = jsonObject.getString("selectedmanagedeparts");
try {
SysUser user = JSON.parseObject(jsonObject.toJSONString(), SysUser.class);
//获取登陆人所属集团
SysUser nowUser = sysUserService.getById(BaseContextHandler.getUserId());
user.setOrgCode(nowUser.getOrgCode());
user.setCreateTime(new Date());//设置创建时间
String salt = ConvertUtils.randomGen(8);
user.setSalt(salt);
String passwordEncode = PasswordUtil.encrypt(user.getUsername(), user.getPassword(), salt);
user.setPassword(passwordEncode);
user.setStatus(1);
user.setDelFlag("0");
sysUserService.addUserWithRole(user, selectedRoles);
sysUserService.addUserWithDepart(user, selectedDeparts,selectedManageDeparts);
result.success("添加成功!");
} catch (Exception e) {
log.error(e.getMessage(), e);
result.error500("操作失败");
}
return result;
}
@AutoLog(value = "编辑用户信息")
@RequestMapping(value = "/edit", method = RequestMethod.PUT)
//@RequiresPermissions("user:edit")
public Result<SysUser> edit(@RequestBody JSONObject jsonObject) {
Result<SysUser> result = new Result<SysUser>();
try {
SysUser sysUser = sysUserService.getById(jsonObject.getString("id"));
sysBaseAPI.addLog("编辑用户,id: " + jsonObject.getString("id"), CommonConstant.LOG_TYPE_2, 2);
if (sysUser == null) {
result.error500("未找到对应实体");
} else {
SysUser user = JSON.parseObject(jsonObject.toJSONString(), SysUser.class);
//获取登陆人所属集团
SysUser nowUser = sysUserService.getById(BaseContextHandler.getUserId());
user.setOrgCode(nowUser.getOrgCode());
user.setUpdateTime(new Date());
//String passwordEncode = PasswordUtil.encrypt(user.getUsername(), user.getPassword(), sysUser.getSalt());
user.setPassword(sysUser.getPassword());
String roles = jsonObject.getString("selectedroles");
String departs = jsonObject.getString("selecteddeparts");
String manageDeparts = jsonObject.getString("selectedmanagedeparts");
sysUserService.editUserWithRole(user, roles);
sysUserService.editUserWithDepart(user, departs, manageDeparts);
result.success("修改成功!");
}
} catch (Exception e) {
log.error(e.getMessage(), e);
result.error500("操作失败");
}
return result;
}
/**
* 移动端头像修改
*
* @param jsonObject
* @return
*/
@RequestMapping(value = "/photoEdit", method = RequestMethod.PUT)
//@RequiresPermissions("user:edit")
public Result<SysUser> photoEdit(@RequestBody JSONObject jsonObject) {
Result<SysUser> result = new Result<SysUser>();
try {
SysUser sysUser = sysUserService.getById(jsonObject.getString("id"));
sysBaseAPI.addLog("编辑用户,id: " + jsonObject.getString("id"), CommonConstant.LOG_TYPE_2, 2);
if (sysUser == null) {
result.error500("未找到对应实体");
} else {
SysUser user = JSON.parseObject(jsonObject.toJSONString(), SysUser.class);
user.setUpdateTime(new Date());
sysUserService.updateById(user);
//user.setAvatar(viewPath + user.getAvatar());
user.setAvatar(user.getAvatar());
result.setResult(user);
result.success("修改成功!");
}
} catch (Exception e) {
log.error(e.getMessage(), e);
result.error500("操作失败");
}
return result;
}
/**
* 个人中心
*
* @param jsonObject
* @return
*/
@AutoLog(value = "编辑用户信息")
@PostMapping(value = "/editUser")
public Result<SysUser> editUser(@RequestBody JSONObject jsonObject) {
Result<SysUser> result = new Result<SysUser>();
try {
SysUser sysUser = sysUserService.getById(jsonObject.getString("id"));
sysUser.setUpdateTime(new Date());
sysUser.setRealname(jsonObject.getString("realname"));
sysUser.setEmail(jsonObject.getString("email"));
sysUser.setBirthday(jsonObject.getDate("birthday"));
sysUser.setPhone(jsonObject.getString("phone"));
sysUser.setSex(jsonObject.getInteger("sex"));
boolean ok = sysUserService.updateById(sysUser);
if (ok) {
result.success("修改成功!");
} else {
result.error500("操作失败");
}
} catch (Exception e) {
log.error(e.getMessage(), e);
result.error500("操作失败");
}
return result;
}
/**
* 删除用户
*/
@AutoLog(value = "用户删除")
@RequestMapping(value = "/delete", method = RequestMethod.DELETE)
public Result<SysUser> delete(@RequestParam(name = "id", required = true) String id) {
Result<SysUser> result = new Result<SysUser>();
// 定义SysUserDepart实体类的数据库查询LambdaQueryWrapper
LambdaQueryWrapper<SysUserDepart> query = new LambdaQueryWrapper<SysUserDepart>();
SysUser sysUser = sysUserService.getById(id);
sysBaseAPI.addLog("删除用户,id: " + id, CommonConstant.LOG_TYPE_2, 3);
if (sysUser == null) {
result.error500("未找到对应实体");
} else {
// 当某个用户被删除时,删除其ID下对应的部门数据
query.eq(SysUserDepart::getUserId, id);
boolean ok = sysUserService.removeById(id);
sysUserDepartService.remove(query);
if (ok) {
result.success("删除成功!");
}
}
return result;
}
/**
* 批量删除用户
*/
@AutoLog(value = "用户批量删除")
@RequestMapping(value = "/deleteBatch", method = RequestMethod.DELETE)
public Result<SysUser> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
// 定义SysUserDepart实体类的数据库查询对象LambdaQueryWrapper
LambdaQueryWrapper<SysUserDepart> query = new LambdaQueryWrapper<SysUserDepart>();
String[] idArry = ids.split(",");
sysBaseAPI.addLog("批量删除用户, id: " + idArry.toString(), CommonConstant.LOG_TYPE_2, 3);
Result<SysUser> result = new Result<SysUser>();
if (ids == null || "".equals(ids.trim())) {
result.error500("参数不识别!");
} else {
this.sysUserService.removeByIds(Arrays.asList(ids.split(",")));
// 当批量删除时,删除在SysUserDepart中对应的所有部门数据
for (String id : idArry) {
query.eq(SysUserDepart::getUserId, id);
this.sysUserDepartService.remove(query);
}
result.success("删除成功!");
}
return result;
}
/**
* 冻结&解冻用户
*
* @param jsonObject
* @return
*/
@AutoLog(value = "用户冻结")
@RequestMapping(value = "/frozenBatch", method = RequestMethod.PUT)
public Result<SysUser> frozenBatch(@RequestBody JSONObject jsonObject) {
Result<SysUser> result = new Result<SysUser>();
try {
String ids = jsonObject.getString("ids");
String status = jsonObject.getString("status");
String[] arr = ids.split(",");
for (String id : arr) {
if (ConvertUtils.isNotEmpty(id)) {
this.sysUserService.update(new SysUser().setStatus(Integer.parseInt(status)),
new UpdateWrapper<SysUser>().lambda().eq(SysUser::getId, id));
}
}
} catch (Exception e) {
log.error(e.getMessage(), e);
result.error500("操作失败" + e.getMessage());
}
result.success("操作成功!");
return result;
}
@RequestMapping(value = "/queryById", method = RequestMethod.GET)
public Result<SysUser> queryById(@RequestParam(name = "id", required = true) String id) {
Result<SysUser> result = new Result<SysUser>();
SysUser sysUser = sysUserService.getById(id);
if (sysUser == null) {
result.error500("未找到对应实体");
} else {
result.setResult(sysUser);
result.setSuccess(true);
}
return result;
}
@RequestMapping(value = "/queryUserRole", method = RequestMethod.GET)
public Result<List<String>> queryUserRole(@RequestParam(name = "userid", required = true) String userid) {
Result<List<String>> result = new Result<>();
List<String> list = new ArrayList<String>();
List<SysUserRole> userRole = sysUserRoleService.list(new QueryWrapper<SysUserRole>().lambda().eq(SysUserRole::getUserId, userid));
if (userRole == null || userRole.size() <= 0) {
result.error500("未找到用户相关角色信息");
} else {
for (SysUserRole sysUserRole : userRole) {
list.add(sysUserRole.getRoleId());
}
result.setSuccess(true);
result.setResult(list);
}
return result;
}
/**
* 校验用户账号是否唯一<br>
* 可以校验其他 需要检验什么就传什么。。。
*
* @param sysUser
* @return
*/
@RequestMapping(value = "/checkOnlyUser", method = RequestMethod.GET)
public Result<Boolean> checkOnlyUser(SysUser sysUser) {
Result<Boolean> result = new Result<>();
//如果此参数为false则程序发生异常
result.setResult(true);
try {
//通过传入信息查询新的用户信息
SysUser user = sysUserService.getOne(new QueryWrapper<SysUser>(sysUser));
if (user != null) {
result.setSuccess(false);
result.setMessage("用户账号已存在");
return result;
}
} catch (Exception e) {
result.setSuccess(false);
result.setMessage(e.getMessage());
return result;
}
result.setSuccess(true);
return result;
}
/**
* 修改密码
*/
@AutoLog(value = "修改密码")
@RequestMapping(value = "/changPassword", method = RequestMethod.PUT)
public Result<SysUser> changPassword(@RequestBody SysUser sysUser) {
Result<SysUser> result = new Result<SysUser>();
String password = sysUser.getPassword();
sysUser = this.sysUserService.getOne(new LambdaQueryWrapper<SysUser>().eq(SysUser::getUsername, sysUser.getUsername()));
if (sysUser == null) {
result.error500("未找到对应实体");
} else {
String salt = ConvertUtils.randomGen(8);
sysUser.setSalt(salt);
String passwordEncode = PasswordUtil.encrypt(sysUser.getUsername(), password, salt);
sysUser.setPassword(passwordEncode);
this.sysUserService.updateById(sysUser);
result.setResult(sysUser);
result.success("密码修改完成!");
}
return result;
}
/**
* 查询指定用户和部门关联的数据
*
* @param userId
* @return
*/
@RequestMapping(value = "/userDepartList", method = RequestMethod.GET)
public Result<List<DepartIdModel>> getUserDepartsList(@RequestParam(name = "userId", required = true) String userId) {
Result<List<DepartIdModel>> result = new Result<>();
try {
List<DepartIdModel> depIdModelList = this.sysUserDepartService.queryDepartIdsOfUser(userId);
if (depIdModelList != null && depIdModelList.size() > 0) {
result.setSuccess(true);
result.setMessage("查找成功");
result.setResult(depIdModelList);
} else {
result.setSuccess(false);
result.setMessage("查找失败");
}
return result;
} catch (Exception e) {
log.error(e.getMessage(), e);
result.setSuccess(false);
result.setMessage("查找过程中出现了异常: " + e.getMessage());
return result;
}
}
/**
* 生成在添加用户情况下没有主键的问题,返回给前端,根据该id绑定部门数据
*
* @return
*/
@RequestMapping(value = "/generateUserId", method = RequestMethod.GET)
public Result<String> generateUserId() {
Result<String> result = new Result<>();
System.out.println("我执行了,生成用户ID==============================");
String userId = UUID.randomUUID().toString().replace("-", "");
result.setSuccess(true);
result.setResult(userId);
return result;
}
/**
* 根据部门id查询用户信息
*
* @param id
* @return
*/
@RequestMapping(value = "/queryUserByDepId", method = RequestMethod.GET)
public Result<List<SysUser>> queryUserByDepId(@RequestParam(name = "id", required = true) String id) {
Result<List<SysUser>> result = new Result<>();
List<SysUser> userList = sysUserDepartService.queryUserByDepId(id);
try {
result.setSuccess(true);
result.setResult(userList);
return result;
} catch (Exception e) {
log.error(e.getMessage(), e);
result.setSuccess(false);
return result;
}
}
/**
* 查询所有用户所对应的角色信息
*
* @return
*/
@RequestMapping(value = "/queryUserRoleMap", method = RequestMethod.GET)
public Result<Map<String, String>> queryUserRole() {
Result<Map<String, String>> result = new Result<>();
Map<String, String> map = userRoleService.queryUserRole();
result.setResult(map);
result.setSuccess(true);
return result;
}
/**
* 导出excel
*
* @param request
* @param sysUser
*/
@RequestMapping(value = "/exportXls")
public ModelAndView exportXls(SysUser sysUser, HttpServletRequest request) {
// Step.1 组装查询条件
QueryWrapper<SysUser> queryWrapper = QueryGenerator.initQueryWrapper(sysUser, request.getParameterMap());
//Step.2 AutoPoi 导出Excel
ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
//过滤已删除数据
queryWrapper.eq("del_flag","0");
List<SysUser> pageList = sysUserService.list(queryWrapper);
//导出文件名称
mv.addObject(NormalExcelConstants.FILE_NAME, "用户列表");
mv.addObject(NormalExcelConstants.CLASS, SysUser.class);
LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("用户列表数据", "导出人:" + user.getRealname(), "导出信息"));
mv.addObject(NormalExcelConstants.DATA_LIST, pageList);
return mv;
}
/**
* 通过excel导入数据
*
* @param request
* @param response
* @return
*/
@RequiresPermissions("user:import")
@RequestMapping(value = "/importExcel", method = RequestMethod.POST)
public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
MultipartFile file = entity.getValue();// 获取上传文件对象
ImportParams params = new ImportParams();
params.setTitleRows(2);
params.setHeadRows(1);
params.setNeedSave(true);
try {
List<SysUser> listSysUsers = ExcelImportUtil.importExcel(file.getInputStream(), SysUser.class, params);
for (SysUser sysUserExcel : listSysUsers) {
if (sysUserExcel.getPassword() == null) {
// 密码默认为“123456”
sysUserExcel.setPassword("123456");
}
sysUserService.save(sysUserExcel);
}
return Result.ok("文件导入成功!数据行数:" + listSysUsers.size());
} catch (Exception e) {
log.error(e.getMessage(), e);
return Result.error("抱歉! 您导入的数据中用户名已经存在.");
} finally {
try {
file.getInputStream().close();
} catch (IOException e) {
log.error(e.getMessage(), e);
}
}
}
return Result.error("文件导入失败!");
}
/**
* @param userIds
* @return
* @功能:根据id 批量查询
*/
@RequestMapping(value = "/queryByIds", method = RequestMethod.GET)
public Result<Collection<SysUser>> queryByIds(@RequestParam String userIds) {
Result<Collection<SysUser>> result = new Result<>();
String[] userId = userIds.split(",");
Collection<String> idList = Arrays.asList(userId);
Collection<SysUser> userRole = sysUserService.listByIds(idList);
result.setSuccess(true);
result.setResult(userRole);
return result;
}
/**
* 首页密码修改
*/
@RequestMapping(value = "/updatePassword", method = RequestMethod.PUT)
public Result<SysUser> changPassword(@RequestBody JSONObject json) {
Result<SysUser> result = new Result<SysUser>();
String username = json.getString("username");
String oldpassword = json.getString("oldpassword");
SysUser user = this.sysUserService.getOne(new LambdaQueryWrapper<SysUser>().eq(SysUser::getUsername, username));
if (user == null) {
result.error500("未找到用户!");
return result;
}
String passwordEncode = PasswordUtil.encrypt(username, oldpassword, user.getSalt());
if (!user.getPassword().equals(passwordEncode)) {
result.error500("旧密码输入错误!");
return result;
}
String password = json.getString("password");
String confirmpassword = json.getString("confirmpassword");
if (ConvertUtils.isEmpty(password)) {
result.error500("新密码不存在!");
return result;
}
if (!password.equals(confirmpassword)) {
result.error500("两次输入密码不一致!");
return result;
}
String newpassword = PasswordUtil.encrypt(username, password, user.getSalt());
this.sysUserService.update(new SysUser().setPassword(newpassword), new LambdaQueryWrapper<SysUser>().eq(SysUser::getId, user.getId()));
result.success("密码修改完成!");
return result;
}
@RequestMapping(value = "/userRoleList", method = RequestMethod.GET)
public Result<IPage<SysUser>> userRoleList(@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, HttpServletRequest req) {
Result<IPage<SysUser>> result = new Result<IPage<SysUser>>();
Page<SysUser> page = new Page<SysUser>(pageNo, pageSize);
String roleId = req.getParameter("roleId");
String username = req.getParameter("username");
IPage<SysUser> pageList = sysUserService.getUserByRoleId(page, roleId, username);
result.setSuccess(true);
result.setResult(pageList);
return result;
}
/**
* 给指定角色添加用户
*
* @param
* @return
*/
@AutoLog(value = "给指定角色添加用户")
@RequestMapping(value = "/addSysUserRole", method = RequestMethod.POST)
public Result<String> addSysUserRole(@RequestBody SysUserRoleVO sysUserRoleVO) {
Result<String> result = new Result<String>();
try {
String sysRoleId = sysUserRoleVO.getRoleId();
for (String sysUserId : sysUserRoleVO.getUserIdList()) {
SysUserRole sysUserRole = new SysUserRole(sysUserId, sysRoleId);
QueryWrapper<SysUserRole> queryWrapper = new QueryWrapper<SysUserRole>();
queryWrapper.eq("role_id", sysRoleId).eq("user_id", sysUserId);
SysUserRole one = sysUserRoleService.getOne(queryWrapper);
if (one == null) {
sysUserRoleService.save(sysUserRole);
}
}
result.setMessage("添加成功!");
result.setSuccess(true);
return result;
} catch (Exception e) {
log.error(e.getMessage(), e);
result.setSuccess(false);
result.setMessage("出错了: " + e.getMessage());
return result;
}
}
/**
* 删除指定角色的用户关系
*
* @param
* @return
*/
@AutoLog(value = "删除角色用户关系")
@RequestMapping(value = "/deleteUserRole", method = RequestMethod.DELETE)
public Result<SysUserRole> deleteUserRole(@RequestParam(name = "roleId") String roleId,
@RequestParam(name = "userId", required = true) String userId
) {
Result<SysUserRole> result = new Result<SysUserRole>();
try {
QueryWrapper<SysUserRole> queryWrapper = new QueryWrapper<SysUserRole>();
queryWrapper.eq("role_id", roleId).eq("user_id", userId);
sysUserRoleService.remove(queryWrapper);
result.success("删除成功!");
} catch (Exception e) {
log.error(e.getMessage(), e);
result.error500("删除失败!");
}
return result;
}
/**
* 批量删除指定角色的用户关系
*
* @param
* @return
*/
@AutoLog(value = "批量删除角色用户关系")
@RequestMapping(value = "/deleteUserRoleBatch", method = RequestMethod.DELETE)
public Result<SysUserRole> deleteUserRoleBatch(
@RequestParam(name = "roleId") String roleId,
@RequestParam(name = "userIds", required = true) String userIds) {
Result<SysUserRole> result = new Result<SysUserRole>();
try {
QueryWrapper<SysUserRole> queryWrapper = new QueryWrapper<SysUserRole>();
queryWrapper.eq("role_id", roleId).in("user_id", Arrays.asList(userIds.split(",")));
sysUserRoleService.remove(queryWrapper);
result.success("删除成功!");
} catch (Exception e) {
log.error(e.getMessage(), e);
result.error500("删除失败!");
}
return result;
}
/**
* 部门用户列表
*/
@RequestMapping(value = "/departUserList", method = RequestMethod.GET)
public Result<IPage<SysUser>> departUserList(@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, HttpServletRequest req) {
Result<IPage<SysUser>> result = new Result<IPage<SysUser>>();
Page<SysUser> page = new Page<SysUser>(pageNo, pageSize);
String depId = req.getParameter("depId");
String username = req.getParameter("username");
IPage<SysUser> pageList = sysUserService.getUserByDepId(page, depId, username);
result.setSuccess(true);
result.setResult(pageList);
return result;
}
/**
* 给指定部门添加对应的用户
*/
@AutoLog(value = "给部门添加对应的用户")
@RequestMapping(value = "/editSysDepartWithUser", method = RequestMethod.POST)
public Result<String> editSysDepartWithUser(@RequestBody SysDepartUsersVO sysDepartUsersVO) {
Result<String> result = new Result<String>();
try {
String sysDepId = sysDepartUsersVO.getDepId();
for (String sysUserId : sysDepartUsersVO.getUserIdList()) {
SysUserDepart sysUserDepart = new SysUserDepart(null, sysUserId, sysDepId,null);
QueryWrapper<SysUserDepart> queryWrapper = new QueryWrapper<SysUserDepart>();
queryWrapper.eq("dep_id", sysDepId).eq("user_id", sysUserId);
SysUserDepart one = sysUserDepartService.getOne(queryWrapper);
if (one == null) {
sysUserDepartService.save(sysUserDepart);
}
}
result.setMessage("添加成功!");
result.setSuccess(true);
return result;
} catch (Exception e) {
log.error(e.getMessage(), e);
result.setSuccess(false);
result.setMessage("出错了: " + e.getMessage());
return result;
}
}
/**
* 删除指定机构的用户关系
*/
@AutoLog(value = "删除机构用户关系")
@RequestMapping(value = "/deleteUserInDepart", method = RequestMethod.DELETE)
public Result<SysUserDepart> deleteUserInDepart(@RequestParam(name = "depId") String depId,
@RequestParam(name = "userId", required = true) String userId
) {
Result<SysUserDepart> result = new Result<SysUserDepart>();
try {
QueryWrapper<SysUserDepart> queryWrapper = new QueryWrapper<SysUserDepart>();
queryWrapper.eq("dep_id", depId).eq("user_id", userId);
sysUserDepartService.remove(queryWrapper);
result.success("删除成功!");
} catch (Exception e) {
log.error(e.getMessage(), e);
result.error500("删除失败!");
}
return result;
}
/**
* 批量删除指定机构的用户关系
*/
@AutoLog(value = "批量删除机构用户关系")
@RequestMapping(value = "/deleteUserInDepartBatch", method = RequestMethod.DELETE)
public Result<SysUserDepart> deleteUserInDepartBatch(
@RequestParam(name = "depId") String depId,
@RequestParam(name = "userIds", required = true) String userIds) {
Result<SysUserDepart> result = new Result<SysUserDepart>();
try {
QueryWrapper<SysUserDepart> queryWrapper = new QueryWrapper<SysUserDepart>();
queryWrapper.eq("dep_id", depId).in("user_id", Arrays.asList(userIds.split(",")));
sysUserDepartService.remove(queryWrapper);
result.success("删除成功!");
} catch (Exception e) {
log.error(e.getMessage(), e);
result.error500("删除失败!");
}
return result;
}
/**
* 查询当前用户的所有部门/当前部门编码
*
* @return
*/
@RequestMapping(value = "/getCurrentUserDeparts", method = RequestMethod.GET)
public Result<Map<String, Object>> getCurrentUserDeparts() {
Result<Map<String, Object>> result = new Result<Map<String, Object>>();
try {
LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
List<SysDepart> list = this.sysDepartService.queryUserDeparts(sysUser.getId());
Map<String, Object> map = new HashMap<String, Object>();
map.put("list", list);
map.put("orgCode", sysUser.getOrgCode());
result.setSuccess(true);
result.setResult(map);
} catch (Exception e) {
log.error(e.getMessage(), e);
result.error500("查询失败!");
}
return result;
}
/**
* 用户注册接口
*
* @param jsonObject
* @param user
* @return
*/
@PostMapping("/register")
public Result<JSONObject> userRegister(@RequestBody JSONObject jsonObject, SysUser user) {
Result<JSONObject> result = new Result<JSONObject>();
String phone = jsonObject.getString("phone");
String smscode = jsonObject.getString("smscode");
Object code = redisUtil.get(phone);
String username = jsonObject.getString("username");
String password = jsonObject.getString("password");
String email = jsonObject.getString("email");
SysUser sysUser1 = sysUserService.getUserByName(username);
if (sysUser1 != null) {
result.setMessage("用户名已注册");
result.setSuccess(false);
return result;
}
SysUser sysUser2 = sysUserService.getUserByPhone(phone);
if (sysUser2 != null) {
result.setMessage("该手机号已注册");
result.setSuccess(false);
return result;
}
SysUser sysUser3 = sysUserService.getUserByEmail(email);
if (sysUser3 != null) {
result.setMessage("邮箱已被注册");
result.setSuccess(false);
return result;
}
if (!smscode.equals(code)) {
result.setMessage("手机验证码错误");
result.setSuccess(false);
return result;
}
try {
user.setCreateTime(new Date());// 设置创建时间
String salt = ConvertUtils.randomGen(8);
String passwordEncode = PasswordUtil.encrypt(username, password, salt);
user.setSalt(salt);
user.setUsername(username);
user.setRealname(username);
user.setPassword(passwordEncode);
user.setEmail(email);
user.setPhone(phone);
user.setStatus(1);
user.setDelFlag(CommonConstant.DEL_FLAG_0.toString());
user.setActivitiSync(CommonConstant.ACT_SYNC_1);
sysUserService.addUserWithRole(user, "ee8626f80f7c2619917b6236f3a7f02b");//默认临时角色 test
result.success("注册成功");
} catch (Exception e) {
result.error500("注册失败");
}
return result;
}
/**
* 根据用户名或手机号查询用户信息
*/
@GetMapping("/querySysUser")
public Result<Map<String, Object>> querySysUser(SysUser sysUser) {
String phone = sysUser.getPhone();
String username = sysUser.getUsername();
Result<Map<String, Object>> result = new Result<Map<String, Object>>();
Map<String, Object> map = new HashMap<String, Object>();
if (ConvertUtils.isNotEmpty(phone)) {
SysUser user = sysUserService.getUserByPhone(phone);
if (user != null) {
map.put("username", user.getUsername());
map.put("phone", user.getPhone());
result.setSuccess(true);
result.setResult(map);
return result;
}
}
if (ConvertUtils.isNotEmpty(username)) {
SysUser user = sysUserService.getUserByName(username);
if (user != null) {
map.put("username", user.getUsername());
map.put("phone", user.getPhone());
result.setSuccess(true);
result.setResult(map);
return result;
}
}
result.setSuccess(false);
result.setMessage("验证失败");
return result;
}
/**
* 用户手机号验证
*/
@PostMapping("/phoneVerification")
public Result<String> phoneVerification(@RequestBody JSONObject jsonObject) {
Result<String> result = new Result<String>();
String phone = jsonObject.getString("phone");
String smscode = jsonObject.getString("smscode");
Object code = redisUtil.get(phone);
if (!smscode.equals(code)) {
result.setMessage("手机验证码错误");
result.setSuccess(false);
return result;
}
redisUtil.set(phone, smscode);
result.setResult(smscode);
result.setSuccess(true);
return result;
}
/**
* 用户更改密码
*/
@GetMapping("/passwordChange")
@AutoLog(value = "更改密码")
public Result<SysUser> passwordChange(@RequestParam(name = "username") String username,
@RequestParam(name = "password") String password,
@RequestParam(name = "smscode") String smscode,
@RequestParam(name = "phone") String phone) {
Result<SysUser> result = new Result<SysUser>();
SysUser sysUser = new SysUser();
Object object = redisUtil.get(phone);
if (null == object) {
result.setMessage("更改密码失败");
result.setSuccess(false);
}
if (!smscode.equals(object)) {
result.setMessage("更改密码失败");
result.setSuccess(false);
}
sysUser = this.sysUserService.getOne(new LambdaQueryWrapper<SysUser>().eq(SysUser::getUsername, username));
if (sysUser == null) {
result.setMessage("未找到对应实体");
result.setSuccess(false);
return result;
} else {
String salt = ConvertUtils.randomGen(8);
sysUser.setSalt(salt);
String passwordEncode = PasswordUtil.encrypt(sysUser.getUsername(), password, salt);
sysUser.setPassword(passwordEncode);
this.sysUserService.updateById(sysUser);
result.setSuccess(true);
result.setMessage("密码修改完成!");
return result;
}
}
/**
* 根据TOKEN获取用户的部分信息(返回的数据是可供表单设计器使用的数据)
*
* @return
*/
@GetMapping("/getUserSectionInfoByToken")
public Result<?> getUserSectionInfoByToken(HttpServletRequest request, @RequestParam(name = "token", required = false) String token) {
try {
String username = null;
// 如果没有传递token,就从header中获取token并获取用户信息
if (ConvertUtils.isEmpty(token)) {
username = JwtUtil.getUserNameByToken(request);
} else {
username = JwtUtil.getUsername(token);
}
log.info(" ------ 通过令牌获取部分用户信息,当前用户: " + username);
// 根据用户名查询用户信息
SysUser sysUser = sysUserService.getUserByName(username);
Map<String, Object> map = new HashMap<String, Object>();
map.put("sysUserId", sysUser.getId());
map.put("sysUserCode", sysUser.getUsername()); // 当前登录用户登录账号
map.put("sysUserName", sysUser.getRealname()); // 当前登录用户真实名称
map.put("sysOrgCode", sysUser.getOrgCode()); // 当前登录用户部门编号
log.info(" ------ 通过令牌获取部分用户信息,已获取的用户信息: " + map);
return Result.ok(map);
} catch (Exception e) {
log.error(e.getMessage(), e);
return Result.error(500, "查询失败:" + e.getMessage());
}
}
@ApiOperation(value = "测试推送", notes = "测试推送")
@GetMapping(value = "/sendMessage")
public Result<String> sendMessage(String userIds) {
Result<String> result = new Result<>();
List<String> cidList = sysUserService.getCidByUserIds(userIds);
if (cidList != null && cidList.size() > 0) {
MessageEntity messageEntity = new MessageEntity();
messageEntity.setMessageTitle("测试推送通知标题");
messageEntity.setMessageBody("测试推送通知,请注意!");
messageEntity.setReceiveUserCid(cidList);
IPushService appPushService = PushMessageFactory.getPushService("MOB");
appPushService.pushMessage(messageEntity);
}
result.setSuccess(true);
result.setResult("推送完成");
return result;
}
@ApiOperation(value = "判断当前用户是否属于某一角色", notes = "判断当前用户是否属于某一角色")
@GetMapping(value = "/queryByRole")
@CustomExceptionAnno(description = "判断当前用户是否属于某一角色")
public Result<Object> queryByRoleCtrl(@RequestParam String roleCode) throws Exception {
Result<Object> result = new Result<>();
LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
List<Map<String, Object>> mapList = WrapperFactory.joinWrapper()
.select(SysUser.class.getDeclaredField("id"))
.from(SysRole.class)
.innerJoin(SysUserRole.class, SysUserRole.class.getDeclaredField("roleId"), SysRole.class.getDeclaredField("id"))
.innerJoin(SysUser.class, SysUser.class.getDeclaredField("id"), SysUserRole.class.getDeclaredField("userId"))
.where()
.eq(true, "sys_user.id", sysUser.getId())
.in(true, "sys_role.role_code", Arrays.asList(roleCode.split(",")))
.queryWrapperForList();
if (mapList != null && !mapList.isEmpty()) {
result.setResult("YES");
} else {
result.setResult("NO");
}
return result;
}
@ApiOperation(value = "获取用户分管部门ID串", notes = "获取用户分管部门ID串")
@GetMapping(value = "/getUserDepartIds")
@CustomExceptionAnno(description = "获取用户分管部门ID串")
public Result<List<Map<String, Object>>> getUserDepartIds(String userId){
Result<List<Map<String, Object>>> result = new Result<>();
List<Map<String, Object>> listMaps = new ArrayList<>();
QueryWrapper<SysUserDepart> sysUserDepartQueryWrapper = new QueryWrapper<>();
sysUserDepartQueryWrapper.eq("user_id",userId);
SysUserDepart sysUserDepart = sysUserDepartService.getOne(sysUserDepartQueryWrapper);
if (!StringUtils.isBlank(sysUserDepart.getDepIds())) {
QueryWrapper<SysDepart> sysDepartQueryWrapper = new QueryWrapper<>();
sysDepartQueryWrapper.select("id", "depart_name departName");
sysDepartQueryWrapper.in("id", Arrays.asList(sysUserDepart.getDepIds().split(",")));
listMaps = sysDepartService.listMaps(sysDepartQueryWrapper);
}
result.setResult(listMaps);
return result;
}
@RequestMapping(value = "/getAllUserContainsStatus", method = RequestMethod.POST)
@AutoLog(value = "获取所有用户(包含用户登陆状态)")
@ApiOperation(value = "获取所有用户(包含用户登陆状态)")
public Result<List<SysUserVO>> getAllUserContainsStatus() {
Result<List<SysUserVO>> result = new Result<List<SysUserVO>>();
result.setResult(sysUserService.getAllUserContainsStatus());
return result;
}
@AutoLog(value = "修改用户名")
@ApiOperation(value = "修改用户信息", notes = "用户管理")
@PostMapping(value = "/changeUser")
public Result<LoginUser> changeUser(@RequestBody LoginUser loginUser) {
Result<LoginUser> result = new Result<>();
try {
LoginUser oldUser = sysBaseAPI.getUserById(loginUser.getId());
String newRealName = loginUser.getRealname();
String newPassWord = loginUser.getPassword();
String newPhone = loginUser.getPhone();
String newEmail = loginUser.getEmail();
if (oldUser == null) {
result.error500("未找到对应实体");
return result;
}
String newCid = loginUser.getCid();
if (StrUtil.isNotBlank(newCid)) {
//修改手机cid
String oldCid = oldUser.getCid();
if (StringUtils.isBlank(oldCid)) {
oldUser.setCid(loginUser.getCid());
} else {
String[] split = oldCid.split(",");
Set<String> sets = new HashSet<>(Arrays.asList(split));
sets.add(loginUser.getCid());
StringBuilder stringBuilder = new StringBuilder();
for (String set : sets) {
stringBuilder.append(set + ",");
}
stringBuilder.deleteCharAt(stringBuilder.length() - 1);
oldUser.setCid(stringBuilder.toString());
}
sysBaseAPI.updateUser(oldUser);
result.success("cid修改成功");
}
if (StrUtil.isNotBlank(newRealName)) {
//修改用户名
oldUser.setRealname(newRealName);
sysBaseAPI.updateUser(oldUser);
result.success("用户名修改成功");
}
if (StrUtil.isNotBlank(newPhone)) {
//修改手机号
boolean matches = PATTERN_PHONE.matcher(newPhone).matches();
if (!matches) {
result.error500("手机号格式不正确");
} else {
sysBaseAPI.updateUser(oldUser.setPhone(newPhone));
result.success("手机号修改成功");
}
}
if (StrUtil.isNotBlank(newPassWord)) {
//修改密码
String salt = ConvertUtils.randomGen(8);
//md5密码盐
oldUser.setSalt(salt);
String passwordEncode = PasswordUtil.encrypt(oldUser.getUsername(), newPassWord, salt);
oldUser.setPassword(passwordEncode);
sysBaseAPI.updateUser(oldUser);
result.success("密码修改完成!");
}
if (StrUtil.isNotBlank(newEmail)) {
oldUser.setEmail(newEmail);
sysBaseAPI.updateUser(oldUser);
result.success("邮箱修改完成!");
}
} catch (Exception e) {
log.error(e.getMessage(), e);
result.error500("操作失败");
}
return result;
}
@AutoLog(value = "退出清除自己的cid")
@ApiOperation(value = "退出清除自己的cid", notes = "退出清除自己的cid")
@PostMapping(value = "/delCid")
public Result<LoginUser> delCid(@RequestBody LoginUser loginUser) {
Result<LoginUser> result = new Result<>();
try {
LoginUser oldUser = sysBaseAPI.getUserById(loginUser.getId());
String cid = loginUser.getCid();
String oldUserCid = oldUser.getCid();
if (StringUtils.isNotBlank(oldUserCid)) {
oldUser.setCid(oldUserCid.replace(cid, ""));
}
sysBaseAPI.updateUser(oldUser);
result.success("cid清除成功");
} catch (Exception e) {
log.error(e.getMessage(), e);
result.error500("操作失败");
}
return result;
}
/**
* 运营部人员列表
*/
@RequestMapping(value = "/operationUserList", method = RequestMethod.GET)
public Result<List<SysUser>> operationUserList(String departId) {
Result<List<SysUser>> result = new Result<>();
List<SysUser> pageList = sysUserService.operationUserList(departId);
result.setSuccess(true);
result.setResult(pageList);
return result;
}
@GetMapping("/getLandingUser")
public Result<SysUser> getLandingUser(){
Result<SysUser> result = new Result<>();
try {
String userId = BaseContextHandler.getUserId();
SysUser sysUser = sysUserService.getById(userId);
String departId = BaseContextHandler.getRealDepartId();
QueryWrapper<SysDepart> sysDepartQueryWrapper = new QueryWrapper<>();
sysDepartQueryWrapper.eq("id",departId);
sysDepartQueryWrapper.orderByAsc("org_type");
SysDepart sysDepart = sysDepartService.getOne(sysDepartQueryWrapper);
sysUser.setDepartName(sysDepart.getDepartName());
result.setResult(sysUser);
result.setSuccess(true);
}catch (Exception e){
e.printStackTrace();
log.error("获取登陆用户信息失败!",e.getMessage());
result.error500("获取登陆用户信息失败!");
}
return result;
}
}