UserController.java
4.35 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
package vion.controller;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.lang.Opt;
import cn.hutool.core.lang.tree.Tree;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.github.linpeilie.Converter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import vion.dto.DingDTO;
import vion.dto.UserDTO;
import vion.model.RUserRole;
import vion.model.Role;
import vion.model.TaskTemp;
import vion.model.User;
import vion.service.IRUserRoleService;
import vion.service.IRoleService;
import vion.service.ITaskTempService;
import vion.service.IUserService;
import vion.third.DingMod;
import vion.third.WechatMod;
import vion.vo.RoleVO;
import vion.vo.UserVO;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.stream.Collectors;
@RestController
@RequestMapping("/api")
@RequiredArgsConstructor
@Slf4j
public class UserController {
private final IUserService userService;
private final ITaskTempService taskTempService;
private final IRUserRoleService userRoleService;
private final IRoleService roleService;
private final Converter converter;
private final DingMod dingMod;
private final WechatMod wechatMod;
@GetMapping("/users")
@SaCheckPermission(value = "user:list", orRole = "admin")
public Page<UserVO> getUserList(UserDTO dto) {
return userService.getUserList(dto);
}
@GetMapping("/user/onlyName")
@SaCheckPermission(value = "user:listName", orRole = "admin")
public List<UserVO> getNameList(UserDTO dto) {
return converter.convert(userService.list(Wrappers.lambdaQuery(converter.convert(dto, new User())).select(User::getId, User::getUsername, User::getPreWorkOrder)), UserVO.class);
}
@GetMapping("/user")
@SaCheckPermission(value = "user:query", orRole = "admin")
public User getUserById(@RequestParam(name = "id") Integer id) {
return userService.getById(id);
}
@PostMapping("/user")
@SaCheckPermission(value = "user:edit", orRole = "admin")
public String update(@RequestBody List<User> data) {
return Opt.ofEmptyAble(data).map(userService::updateBatchById).orElse(false) ? "更新成功" : "更新失败";
}
@GetMapping("/user/{token}")
@SaCheckPermission(value = "user:token:query", orRole = "admin")
public UserVO getUserByToken(@PathVariable String token) {
return (UserVO) StpUtil.getTokenSessionByToken(token).get("curLoginUser");
}
@GetMapping("/orgTree")
@SaCheckPermission(value = "user:orgTree", orRole = "admin")
public List<Tree<String>> getOrgTree(String deptId) {
return userService.getOrgTree(deptId);
}
@GetMapping("/user/role/{id}")
@SaCheckPermission(value = "user:role", orRole = "admin")
public List<RoleVO> listRoleById(@PathVariable Long id) {
List<RUserRole> userRoleList = userRoleService.lambdaQuery().eq(RUserRole::getUserId, id).list();
List<Role> roleList = Opt.ofEmptyAble(userRoleList)
.map(l -> l.stream().map(RUserRole::getRoleId).collect(Collectors.toList()))
.filter(CollUtil::isNotEmpty)
.map(roleIdList -> roleService.lambdaQuery().in(Role::getId, roleIdList).list())
.orElse(ListUtil.empty());
return converter.convert(roleList, RoleVO.class);
}
@GetMapping("/ding/callback/{target}")
public Object dingCallback(@PathVariable String target, DingDTO dto, HttpServletResponse res) {
return dingMod.dingCallback(target, dto, res);
}
@GetMapping("/logout")
public String logout() {
StpUtil.logout();
return "注销成功";
}
@GetMapping("/wechat/callback")
public Object wechatCallback(String code, Long taskTempId) {
Object obj = wechatMod.wechatCallback(code);
if (obj instanceof String) {
return taskTempService.lambdaUpdate().set(TaskTemp::getOpenid, obj).eq(TaskTemp::getId, taskTempId).update(new TaskTemp()) ? new ModelAndView("weChatNeedAttention") : new ModelAndView("weChatError");
} else {
return obj;
}
}
}