UP
lyfO_o
2022-07-08 fea25a3ca8897f415f2a8cc14e5c9497a828d32e
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
package com.gkhy.safePlatform.accountController;
 
import com.alibaba.fastjson.JSONObject;
import com.gkhy.safePlatform.account.rpc.apimodel.AccountDepartmentService;
import com.gkhy.safePlatform.account.rpc.apimodel.AccountMenuService;
import com.gkhy.safePlatform.account.rpc.apimodel.AccountUserService;
import com.gkhy.safePlatform.account.rpc.apimodel.model.req.AccountAddRPCReqDTO;
import com.gkhy.safePlatform.account.rpc.apimodel.model.req.AccountModRPCReqDTO;
import com.gkhy.safePlatform.account.rpc.apimodel.model.req.query.AccountRPCQuery;
import com.gkhy.safePlatform.account.rpc.apimodel.model.resp.DepUserRPCRespDTO;
import com.gkhy.safePlatform.account.rpc.apimodel.model.resp.PersonalDetailRPCRespDTO;
import com.gkhy.safePlatform.commons.enums.ResultCodes;
import com.gkhy.safePlatform.commons.query.PageQuery;
import com.gkhy.safePlatform.commons.vo.ResultVO;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
 
import java.security.Principal;
import java.util.List;
 
@RestController
@RequestMapping("/account")
public class UserController {
 
    @DubboReference(check = false)
    private AccountUserService accountUserService;
 
 
 
    @RequestMapping("/page/list")
    public Object getUserPage(Principal principal, PageQuery<AccountRPCQuery> rpcQueryPageQuery) {
        return accountUserService.getAccountPage(Long.valueOf(principal.getName()), rpcQueryPageQuery);
    }
 
 
    /**
     * @Description: 获取部门下的用户列表
     */
    @RequestMapping(value = "/dep/list", method = RequestMethod.GET)
    public ResultVO<List<DepUserRPCRespDTO>> depUserList(Principal principal, Long depId) {
        String userId = principal.getName();
        return accountUserService.getDepList(Long.valueOf(userId), depId);
    }
 
    /**
     * @Description: 个人信息
     */
    @RequestMapping(value = "/personal", method = RequestMethod.GET)
    public ResultVO<PersonalDetailRPCRespDTO> getPersonal(Principal principal) {
        String userId = principal.getName();
        return accountUserService.getPersonalAccountDetail(Long.valueOf(userId));
    }
 
 
    /**
     * @Description: 新增用户信息
     */
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    @PreAuthorize("hasRole('ROLE_admin')")
    public ResultVO<String> addUser(Principal principal, @RequestBody AccountAddRPCReqDTO accountAddRPCReqDTO) {
        String userId = principal.getName();
        return  accountUserService.addAccount(Long.valueOf(userId), accountAddRPCReqDTO);
    }
 
 
    /**
     * @Description: 修改用户信息
     */
 
    @RequestMapping(value = "/mod", method = RequestMethod.POST)
    @PreAuthorize("hasRole('ROLE_admin')")
    public ResultVO<String> modUser(Principal principal, @RequestBody AccountModRPCReqDTO accountModRPCReqDTO) {
        String userId = principal.getName();
        return accountUserService.modAccount(Long.valueOf(userId), accountModRPCReqDTO);
    }
 
 
    /**
     * @Description: 删除用户信息
     */
    @RequestMapping(value = "/del", method = RequestMethod.POST)
    @PreAuthorize("hasRole('ROLE_admin')")
    public ResultVO<String> delUser(Principal principal, @RequestBody JSONObject json) {
        Long uid = json.getLong("uid");
        String userId = principal.getName();
        return accountUserService.delAccount(Long.valueOf(userId), uid);
    }
}