| | |
| | | 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 io.swagger.annotations.*; |
| | | 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 = "用户") |
| | | @Api(tags = "用户管理-用户") |
| | | @Slf4j |
| | | public class UserController { |
| | | public class UserController extends BaseController{ |
| | | |
| | | @Resource |
| | | private UserService userService; |
| | | |
| | | //@PostMapping |
| | | //@ApiOperation(value = "添加") |
| | | //public Response add(@RequestBody UserInf user){ |
| | | // return userService.add(user); |
| | | //} |
| | | |
| | | @PostMapping |
| | | @ApiOperation(value = "添加") |
| | | public Response add(@RequestBody UserInf user){ |
| | | return userService.add(user); |
| | | @ApiOperation(value = "添加-RSA加密") |
| | | public Response addByRSA(@RequestBody UserInf user){ |
| | | return userService.addByRSA(user); |
| | | } |
| | | |
| | | @PostMapping("register") |
| | | @ApiOperation(value = "注册用户") |
| | | public Response register(@RequestBody UserInf user){ |
| | | return userService.registerUser(user); |
| | | } |
| | | @GetMapping |
| | | @ApiOperation(value = "查询byId") |
| | | public UserInf getById(@RequestParam int id){ |
| | | return userService.getById(id); |
| | | public Response<UserInf> getById(@RequestParam int id){ |
| | | return new Response<UserInf>().set(1,userService.getById(id)); |
| | | } |
| | | |
| | | @GetMapping("/all") |
| | | @GetMapping("all") |
| | | @ApiOperation(value = "查询所有") |
| | | public List<UserInf> getAll(){ |
| | | return userService.getAll(); |
| | | public Response<List<UserInf>> getAll(){ |
| | | return new Response<List<UserInf>>().set(1,userService.getAll()); |
| | | } |
| | | |
| | | @GetMapping("/page") |
| | | @GetMapping("page") |
| | | @ApiOperation(value = "查询分页") |
| | | public IPage<UserInf> getPage(@RequestParam int pageNum,int pageSize){ |
| | | Page<Object> page = new Page<>(pageNum, pageSize); |
| | | return userService.getAllWithPage(page); |
| | | public Response getPage(@RequestParam int pageNum,int pageSize){ |
| | | return new Response().set(1,userService.getAllWithPage(pageNum,pageSize)); |
| | | } |
| | | |
| | | @PutMapping |
| | | @PostMapping("update") |
| | | @ApiOperation(value = "编辑") |
| | | public boolean update(@RequestBody UserInf user){ |
| | | public Response update(@RequestBody UserInf user){ |
| | | return userService.update(user); |
| | | } |
| | | |
| | | @DeleteMapping |
| | | @PostMapping("delete") |
| | | @ApiOperation(value = "删除") |
| | | public boolean delete(@RequestParam int id){ |
| | | return userService.delete(id); |
| | | public Response delete(@RequestParam int id){ |
| | | boolean deleteFlag = userService.delete(id); |
| | | if (!deleteFlag){ |
| | | return new Response().setII(0,"删除失败,当前用户没有用户编辑权限"); |
| | | } |
| | | 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 userName){ |
| | | UserInf userInf = userService.getUserByUserName(userName); |
| | | Response response = new Response(); |
| | | if (userInf!=null){ |
| | | if (StringUtils.isEmpty(userInf.getUkeyId())){ |
| | | response.set(-1,false,"该用户没有绑定Ukey"); |
| | | }else { |
| | | response.setII(1,true,userInf,"该用户有绑定Ukey"); |
| | | } |
| | | }else{ |
| | | response.set(0,false,"该用户不存在"); |
| | | } |
| | | 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(); |
| | | }*/ |
| | | passwordEncrypt = pwd; |
| | | 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); |
| | | } |
| | | } |
| | | @GetMapping("/checkAndUpdatePasswordByRSA") |
| | | @ApiOperation(value = "检查并修改用户RSA密码") |
| | | public Response checkAndUpdatePasswordByRSA(@RequestParam String oldPwd,@RequestParam String newPwd){ |
| | | UserInf userInf = ActionUtil.getUser(); |
| | | String passwordEncrypt = oldPwd; |
| | | String password = RSAUtil.decryptFront(passwordEncrypt, RSAUtil.fontSeparator)[0]; |
| | | String passwordDB = RSAUtil.decrypt(userInf.getUpassword(),RSAUtil.getPrivateKey()); |
| | | if(passwordDB.equals(password)){ |
| | | return userService.updatePasswordByRSA(userInf,newPwd); |
| | | }else { |
| | | return new Response().set(0,false,"原密码不正确"); |
| | | } |
| | | } |
| | | |
| | | @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); |
| | | } |
| | | |
| | | @GetMapping("updatePasswordByValidity") |
| | | @ApiOperation(value = "修改密码-密码失效") |
| | | public Response updatePasswordByValidity(@RequestParam String uname,@RequestParam String oldPwd,@RequestParam String newPwd) throws UnsupportedEncodingException { |
| | | return userService.updatePasswordByValidity(uname,oldPwd,newPwd); |
| | | } |
| | | |
| | | /** |
| | | * 1.首次登录,请先修改初始化口令 |
| | | * 2.超过3个月没有修改口令,请修改口令后重新登录 |
| | | */ |
| | | @PostMapping("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为上个月未登录锁定解锁") |
| | | @PostMapping("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); |
| | | } |
| | | |
| | | /** |
| | | * 告警派单中,查询站点人员信息 |
| | | * @param stationId |
| | | * @return |
| | | */ |
| | | @ApiOperation(tags = "告警派单", value = "根据站点查询相关人员", notes = "User_infAction!getUserInfoByStationId") |
| | | @GetMapping("getUserInfoByStationId") |
| | | public Response getUserInfoByStationId(@RequestParam String stationId){ |
| | | List<UserInf> list = userService.getUserInfoByStationId(stationId); |
| | | return new Response().set(1,list); |
| | | } |
| | | |
| | | @ApiOperation(value = "伪单点登录",notes = "返回的data为布尔值,是否登录成功;data2:用户所在的权限组id;data3为用户对象,内含属性uid,uname,urole") |
| | | @GetMapping("loginByUId") |
| | | public Response searchSnIdByUId(@RequestParam int uId){ |
| | | return userService.loginByUId(uId); |
| | | } |
| | | |
| | | } |