郑永安
2023-06-19 7a6abd05683528032687c75e80e0bd2030a3e46c
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
package com.gkhy.safePlatform.account.controller;
 
 
import com.alibaba.fastjson.JSONObject;
import com.gkhy.safePlatform.account.model.annotation.CommonLogEnable;
import com.gkhy.safePlatform.account.model.dto.req.AccountAddReqDTO;
import com.gkhy.safePlatform.account.model.dto.req.AccountModReqDTO;
import com.gkhy.safePlatform.account.model.dto.req.AccountPwdForgetReqDTO;
import com.gkhy.safePlatform.account.model.dto.resp.*;
import com.gkhy.safePlatform.account.model.query.AccountQuery;
import com.gkhy.safePlatform.account.model.query.UserScheduleQuery;
import com.gkhy.safePlatform.account.service.AccountService;
import com.gkhy.safePlatform.account.service.baseService.GroupStrategyUserTimeTableInfoService;
import com.gkhy.safePlatform.commons.co.ContextCacheUser;
import com.gkhy.safePlatform.commons.enums.Module;
import com.gkhy.safePlatform.commons.enums.ResultCodes;
import com.gkhy.safePlatform.commons.query.PageQuery;
import com.gkhy.safePlatform.commons.utils.PageUtils;
import com.gkhy.safePlatform.commons.vo.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.Authentication;
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.time.LocalDate;
import java.util.List;
 
/**
 * @Description: 用户模块
 */
@RestController
@RequestMapping("/account")
public class UserController {
 
    @Autowired
    private AccountService accountService;
    @Autowired
    private GroupStrategyUserTimeTableInfoService groupStrategyUserTimeTableInfoService;
 
 
    /**
     * @Description: 用户列表
     */
    @RequestMapping(value = "/page/list", method = RequestMethod.POST)
    public ResultVO<List<UserDetailRespDTO>> getAccountPage(Authentication authentication, @RequestBody PageQuery<AccountQuery> pageQuery) {
        // 校验页信息
        PageUtils.checkCheck(pageQuery);
        ContextCacheUser currentUser = (ContextCacheUser) authentication.getPrincipal();
        return accountService.listAccountByPage(currentUser.getUid(), pageQuery);
    }
 
    /**
     * @Description: 个人信息
     */
    @RequestMapping(value = "/personal", method = RequestMethod.GET)
    public ResultVO<PersonalDetailRespDTO> getPersonal(Authentication authentication) {
        ContextCacheUser currentUser = (ContextCacheUser) authentication.getPrincipal();
        PersonalDetailRespDTO personAccount = accountService.getPersonalAccountByUserId(currentUser.getUid());
        return new ResultVO<>(ResultCodes.OK, personAccount);
    }
 
    /**
     * @Description: 新增用户信息 当前统一为员工
     */
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    @PreAuthorize("hasRole('ROLE_admin')")
    @CommonLogEnable(module = Module.ACCOUNT,content = "新增用户")
    public ResultVO<String> addUser(Authentication authentication, @RequestBody AccountAddReqDTO accountAddDto) {
        ContextCacheUser currentUser = (ContextCacheUser) authentication.getPrincipal();
        accountService.addAccount(currentUser, accountAddDto);
        return new ResultVO<>(ResultCodes.OK);
    }
 
 
    /**
     * @Description: 修改用户信息
     */
 
    @RequestMapping(value = "/mod", method = RequestMethod.POST)
    @PreAuthorize("hasRole('ROLE_admin')")
    @CommonLogEnable(module = Module.ACCOUNT,content = "修改用户")
    public ResultVO<String> modUser(Authentication authentication, @RequestBody AccountModReqDTO accountModDto) {
        ContextCacheUser currentUser = (ContextCacheUser) authentication.getPrincipal();
        accountService.modAccount(currentUser, accountModDto);
        return new ResultVO<>(ResultCodes.OK);
    }
 
 
    /**
     * @Description: 删除用户信息
     */
    @RequestMapping(value = "/del", method = RequestMethod.POST)
    @PreAuthorize("hasRole('ROLE_admin')")
    @CommonLogEnable(module = Module.ACCOUNT,content = "删除用户")
    public ResultVO<String> delUser(Authentication authentication, @RequestBody JSONObject json) {
        Long uid = json.getLong("uid");
        ContextCacheUser currentUser = (ContextCacheUser) authentication.getPrincipal();
        accountService.delAccount(currentUser, uid);
        return new ResultVO<>(ResultCodes.OK);
    }
 
    /**
     * @Description: 获取部门下的用户列表
     */
    @RequestMapping(value = "/dep/list", method = RequestMethod.GET)
    public ResultVO<List<DepUserInfoRespDTO>> depUserList(Authentication authentication,Long depId) {
        ContextCacheUser currentUser = (ContextCacheUser) authentication.getPrincipal();
        List<DepUserInfoRespDTO> data = accountService.getDepUserList(currentUser.getUid(), depId);
        return new ResultVO<>(ResultCodes.OK,data);
    }
 
    /**
     * @Description: 获取部门下的用户列表
     */
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public ResultVO<List<UserListRespDTO>> list(Authentication authentication) {
        ContextCacheUser currentUser = (ContextCacheUser) authentication.getPrincipal();
        List<UserListRespDTO> data = accountService.getUserList(currentUser.getUid());
        return new ResultVO<>(ResultCodes.OK,data);
    }
 
 
    /**
    * @Description: 系统普通人员自行修改
    */
    @RequestMapping(value = "/pwd/forget", method = RequestMethod.POST)
    public ResultVO pwdForget(Authentication authentication, @RequestBody AccountPwdForgetReqDTO reqDTO) {
        accountService.pwdForget(reqDTO);
        return new ResultVO<>(ResultCodes.OK);
    }
 
    /**
    * @Description: 用户排班
    */
    @RequestMapping(value = "/schedule", method = RequestMethod.POST)
    public ResultVO<List<UserTimeTableRespDTO>> shiftDetail(Authentication authentication,@RequestBody UserScheduleQuery userScheduleQuery) {
        ContextCacheUser currentUser = (ContextCacheUser) authentication.getPrincipal();
        List<UserTimeTableRespDTO> userShift = accountService.getUserScheduleInfo(currentUser, userScheduleQuery);
        return new ResultVO<>(ResultCodes.OK,userShift);
    }
 
 
 
}