whycxzp
2022-05-13 cc9f3e54d119db2320b2653643e03617dce9d8fc
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
package com.whyc.controller;
 
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.whyc.dto.Response;
import com.whyc.pojo.UserInf;
import com.whyc.service.UserService;
import com.whyc.util.ActionUtil;
import com.whyc.util.RSAUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.security.InvalidParameterException;
import java.util.List;
 
@RestController
@RequestMapping("user")
@Api(tags = "用户管理-用户")
@Slf4j
public class UserController {
 
    @Resource
    private UserService userService;
 
    //@PostMapping
    //@ApiOperation(value = "添加")
    //public Response add(@RequestBody UserInf user){
    //    return userService.add(user);
    //}
 
    @PostMapping
    @ApiOperation(value = "添加-RSA加密")
    public Response addByRSA(@RequestBody UserInf user){
        return userService.addByRSA(user);
    }
 
    @GetMapping
    @ApiOperation(value = "查询byId")
    public Response<UserInf> getById(@RequestParam int id){
        return new Response<UserInf>().set(1,userService.getById(id));
    }
 
    @GetMapping("all")
    @ApiOperation(value = "查询所有")
    public Response<List<UserInf>> getAll(){
        return new Response<List<UserInf>>().set(1,userService.getAll());
    }
 
    @GetMapping("page")
    @ApiOperation(value = "查询分页")
    public Response<IPage<UserInf>> getPage(@RequestParam int pageNum,int pageSize){
        Page<Object> page = new Page<>(pageNum, pageSize);
        return new Response<IPage<UserInf>>().set(1,userService.getAllWithPage(page));
    }
 
    @PutMapping
    @ApiOperation(value = "编辑")
    public Response update(@RequestBody UserInf user){
        userService.update(user);
        return new Response().setII(1,"更新成功");
    }
 
    @DeleteMapping
    @ApiOperation(value = "删除")
    public Response delete(@RequestParam int id){
        userService.delete(id);
        return new Response().setII(1,"删除成功");
    }
    @GetMapping("/searchUKeyToUName")
    @ApiOperation(value = "根据Ukey查询用户")
    public Response getUserByUkey(@RequestParam String uKeyId){
        UserInf userInf = userService.getUserByUKeyId(uKeyId);
        Response response = new Response();
        if (userInf!=null){
            response.set(1,userInf,"UKey有绑定用户");
        }else{
            response.set(0,"Ukey没有绑定用户");
        }
        return response;
    }
 
    @GetMapping("/searchUNameToUKey")
    @ApiOperation(value = "根据用户名查绑定的Ukey")
    public Response getUserByUserName(@RequestParam String uKeyId){
        UserInf userInf = userService.getUserByUKeyId(uKeyId);
        Response response = new Response();
        if (userInf!=null){
            if (StringUtils.isEmpty(userInf.getUkeyId())){
                response.set(0,"该用户没有绑定Ukey");
            }else {
                response.set(1,userInf);
            }
        }else{
            response.set(0,"该用户不存在");
        }
        return response;
    }
    @PostMapping("/bindUkey")
    @ApiOperation(value = "绑定uKey")
    public Response bindUkey(@RequestBody UserInf userInf){
        boolean b = userService.bindUkey(userInf);
        if (b){
            return new Response().set(1,"绑定成功");
        }else {
            return new Response().set(0,"绑定失败");
        }
 
    }
 
    @PostMapping("/checkUserPassword")
    @ApiOperation(value = "检查用户密码")
    public Response checkUserPassword(@RequestParam String password){
        UserInf userInf = ActionUtil.getUser();
        //前端传递的密码解密
        password = RSAUtil.decryptFrontP(password, RSAUtil.fontSeparator)[0];
        //内存存储的密码解密
        String userPassword = userInf.getUpassword();
        userPassword = RSAUtil.decrypt(userPassword,RSAUtil.getPrivateKey());
        if (password.equals(userPassword)){
            return new Response().set(1);
        }else {
            return new Response().set(0);
        }
    }
 
    @PostMapping("/checkUserPasswordOfRSA")
    @ApiOperation(value = "检查用户RSA密码")
    public Response checkUserPasswordOfREA(@RequestParam String pwd){
        UserInf userInf = ActionUtil.getUser();
        String passwordEncrypt = null;
        try {
            passwordEncrypt = URLDecoder.decode(pwd, "utf-8");
        }catch (UnsupportedEncodingException e){
            e.printStackTrace();
        }
        String password = RSAUtil.decryptFront(passwordEncrypt, RSAUtil.fontSeparator)[0];
        String passwordDB = RSAUtil.decrypt(userInf.getUpassword(),RSAUtil.getPrivateKey());
        if(passwordDB.equals(password)){
            return new Response().set(1);
        }else {
            return new Response().set(0);
        }
    }
 
 
    @PostMapping("/updatePassword")
    @ApiOperation(value = "修改密码")
    public Response updatePassword(@RequestParam String password){
        UserInf userInf = ActionUtil.getUser();
        return userService.updatePassword(userInf,password);
    }
 
    @PostMapping("/updatePasswordByRSA")
    @ApiOperation(value = "修改密码-RSA")
    public Response updatePasswordByRSA(@RequestParam String password){
        UserInf userInf = ActionUtil.getUser();
        return userService.updatePasswordByRSA(userInf,password);
    }
 
    /**
     * 1.首次登录,请先修改初始化口令
     * 2.超过3个月没有修改口令,请修改口令后重新登录
     */
    @PutMapping("updatePassword2")
    @ApiOperation(value = "修改密码-3个月未登录")
    public Response updatePassword2(@RequestParam String passwordOld,String passwordNew){
        //校验老密码
        String[] dataArr = RSAUtil.decryptFrontP(passwordOld, RSAUtil.fontSeparator);
        passwordOld = dataArr[0];
        String passwordMD5 = dataArr[1];
        if(!ActionUtil.EncryptionMD5(passwordOld).equals(passwordMD5)){
            throw new InvalidParameterException("参数校验失败");
        }
        //校验新密码
        String[] dataNewArr = RSAUtil.decryptFrontP(passwordNew, RSAUtil.fontSeparator);
        passwordNew = dataNewArr[0];
        String passwordNewMD5 = dataNewArr[1];
        if(!ActionUtil.EncryptionMD5(passwordNew).equals(passwordNewMD5)){
            throw new InvalidParameterException("参数校验失败");
        }
 
        UserInf userInf = ActionUtil.getUser();
 
        //校验用户名和密码是否包含
        if(passwordNew.contains(userInf.getUName())){
            return new Response().set(1,false,"密码包含用户名");
        }
        return userService.updatePassword2(userInf,passwordOld,passwordNew);
    }
 
 
    @GetMapping("/getUserInf")
    @ApiOperation(value = "获取当前用户的用户名等信息",notes = "原User_infAction!searchUname(获取用户名)接口")
    public Response getUserInf(){
        UserInf userInf = ActionUtil.getUser();
        return new Response().set(1,userInf);
    }
 
    /**
     * 账号解锁
     */
    @ApiOperation(value = "账号解锁",notes = "unLockType=1为失败锁定解锁,2为上个月未登录锁定解锁")
    @PutMapping("unLock")
    public Response unLock(@RequestParam int uId,@RequestParam int unLockType){
        userService.unLock(uId,unLockType);
        return new Response().setII(1,"解锁成功");
    }
 
    /**
     * 包机组重做(穿梭框)查询所有的用户-更新为查询未被添加到权限组的所有用户
     */
    @ApiOperation(value = "包机组重做(穿梭框)查询所有的用户")
    @GetMapping("searchCS_All2")
    public Response searchCS_All2(){
        List<UserInf> list = userService.searchCS_All2();
        return new Response().set(1,list);
    }
 
}