| | |
| | | package com.lf.server.controller.sys; |
| | | |
| | | import com.lf.server.aspect.SysLog; |
| | | import com.lf.server.annotation.SysLog; |
| | | import com.lf.server.controller.all.BaseController; |
| | | import com.lf.server.entity.all.ResponseMsg; |
| | | import com.lf.server.entity.sys.UserEntity; |
| | | import com.lf.server.helper.Md5Helper; |
| | | import com.lf.server.entity.ctrl.UserUpdateEntity; |
| | | import com.lf.server.helper.StringHelper; |
| | | import com.lf.server.service.sys.TokenService; |
| | | import com.lf.server.service.sys.UserService; |
| | |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.util.List; |
| | | |
| | | /** |
| | |
| | | } |
| | | |
| | | @SysLog() |
| | | @ApiOperation(value = "根据角色+单位分页查询") |
| | | @ApiOperation(value = "根据角色+单位分页查询并返回记录数") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "uname", value = "用户名", dataType = "String", paramType = "query", example = "室"), |
| | | @ApiImplicitParam(name = "roleid", value = "角色ID", dataType = "Integer", paramType = "query", example = "1"), |
| | |
| | | } |
| | | |
| | | @SysLog() |
| | | @ApiOperation(value = "根据ID查询") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "id", value = "ID", dataType = "Integer", paramType = "query", example = "1") |
| | | }) |
| | | @GetMapping(value = "/selectUser") |
| | | public ResponseMsg<UserEntity> selectUser(int id) { |
| | | try { |
| | | UserEntity userEntity = userService.selectUser(id); |
| | | |
| | | return success(userEntity); |
| | | } catch (Exception ex) { |
| | | return fail(ex.getMessage(), null); |
| | | } |
| | | } |
| | | |
| | | @SysLog() |
| | | @ApiOperation(value = "根据用户ID查询") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "uid", value = "用户ID", dataType = "String", paramType = "query", example = "admin") |
| | | }) |
| | | @GetMapping(value = "/selectByUid") |
| | | public ResponseMsg<UserEntity> selectByUid(String uid) { |
| | | try { |
| | | if (StringHelper.isEmpty(uid)) { |
| | | fail("用户ID不能为空", null); |
| | | } |
| | | |
| | | UserEntity userEntity = userService.selectByUid(uid); |
| | | |
| | | return success(userEntity); |
| | | } catch (Exception ex) { |
| | | return fail(ex.getMessage(), null); |
| | | } |
| | | } |
| | | |
| | | @SysLog() |
| | | @ApiOperation(value = "查询所有") |
| | | @GetMapping(value = "/selectUserAll") |
| | | public ResponseMsg<List<UserEntity>> selectUserAll() { |
| | | try { |
| | | List<UserEntity> list = userService.selectUserAll(); |
| | | |
| | | return success(list); |
| | | } catch (Exception ex) { |
| | | return fail(ex.getMessage(), null); |
| | | } |
| | | } |
| | | |
| | | @SysLog() |
| | | @ApiOperation(value = "查询是/否为管理员") |
| | | @GetMapping(value = "/selectForIsAdmin") |
| | | public ResponseMsg<Boolean> selectForIsAdmin(HttpServletRequest req) { |
| | | try { |
| | | UserEntity ue = tokenService.getCurrentUser(req); |
| | | if (ue == null) { |
| | | return fail("用户未登录", false); |
| | | } |
| | | |
| | | Integer rows = userService.selectForIsAdmin(ue.getId()); |
| | | |
| | | return success("成功", rows > 0); |
| | | } catch (Exception ex) { |
| | | return fail(ex.getMessage(), false); |
| | | } |
| | | } |
| | | |
| | | @SysLog() |
| | | @ApiOperation(value = "插入一条") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "entity", value = "实体类", dataType = "com.lf.server.entity.data.UserEntity", paramType = "body", example = "") |
| | | }) |
| | | @PostMapping(value = "/insertUser", produces = "application/json; charset=UTF-8") |
| | | @SuppressWarnings("AlibabaRemoveCommentedCode") |
| | | public ResponseMsg<Integer> insertUser(@RequestBody UserEntity entity, HttpServletRequest req) { |
| | | try { |
| | | /*String str = userService.validateNewPwd(entity); |
| | | if (str != null) { |
| | | return fail(str, -1); |
| | | }*/ |
| | | |
| | | UserEntity ue = tokenService.getCurrentUser(req); |
| | | if (ue != null) { |
| | | entity.setCreateUser(ue.getId()); |
| | |
| | | @ApiImplicitParam(name = "list", value = "实体类集合", dataType = "List<UserEntity>", paramType = "body", example = "") |
| | | }) |
| | | @PostMapping(value = "/insertUsers", produces = "application/json; charset=UTF-8") |
| | | @SuppressWarnings("AlibabaRemoveCommentedCode") |
| | | public ResponseMsg<Integer> insertUsers(@RequestBody List<UserEntity> list, HttpServletRequest req) { |
| | | try { |
| | | if (list == null || list.isEmpty()) { |
| | | return fail("实体类集合为空", -1); |
| | | } |
| | | |
| | | UserEntity ue = tokenService.getCurrentUser(req); |
| | | if (ue != null) { |
| | | for (UserEntity entity : list) { |
| | | for (UserEntity entity : list) { |
| | | /*String str = userService.validateNewPwd(entity); |
| | | if (str != null) { |
| | | return fail(str, -1); |
| | | }*/ |
| | | if (ue != null) { |
| | | entity.setCreateUser(ue.getId()); |
| | | } |
| | | } |
| | |
| | | }) |
| | | @ResponseBody |
| | | @PostMapping(value = "/updateUser", produces = "application/json; charset=UTF-8") |
| | | @SuppressWarnings("AlibabaRemoveCommentedCode") |
| | | public ResponseMsg<Integer> updateUser(@RequestBody UserEntity entity, HttpServletRequest req) { |
| | | try { |
| | | /*String str = userService.validateOldPwd(entity); |
| | | if (str != null) { |
| | | return fail(str, -1); |
| | | }*/ |
| | | |
| | | UserEntity ue = tokenService.getCurrentUser(req); |
| | | if (ue != null) { |
| | | entity.setUpdateUser(ue.getId()); |
| | |
| | | } |
| | | |
| | | @SysLog() |
| | | @ApiOperation(value = "根据ID查询") |
| | | @ApiOperation(value = "更新多个用户密码") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "id", value = "ID", dataType = "Integer", paramType = "query", example = "1") |
| | | @ApiImplicitParam(name = "adminPwd", value = "管理员密码", dataType = "String", paramType = "body", example = ""), |
| | | @ApiImplicitParam(name = "newPwd", value = "新密码", dataType = "String", paramType = "body", example = ""), |
| | | @ApiImplicitParam(name = "ids", value = "用户ID集合", dataType = "List<Integer>", paramType = "body", example = "") |
| | | }) |
| | | @GetMapping(value = "/selectUser") |
| | | public ResponseMsg<UserEntity> selectUser(int id) { |
| | | @PostMapping(value = "/updateUsersPwd", produces = "application/json; charset=UTF-8") |
| | | public ResponseMsg<Boolean> updateUsersPwd(@RequestBody UserUpdateEntity uue, HttpServletRequest req) { |
| | | try { |
| | | UserEntity userEntity = userService.selectUser(id); |
| | | |
| | | return success(userEntity); |
| | | } catch (Exception ex) { |
| | | return fail(ex.getMessage(), null); |
| | | } |
| | | } |
| | | |
| | | @SysLog() |
| | | @ApiOperation(value = "查询所有") |
| | | @GetMapping(value = "/selectUserAll") |
| | | public ResponseMsg<List<UserEntity>> selectUserAll() { |
| | | try { |
| | | List<UserEntity> list = userService.selectUserAll(); |
| | | |
| | | return success(list); |
| | | } catch (Exception ex) { |
| | | return fail(ex.getMessage(), null); |
| | | } |
| | | } |
| | | |
| | | @SysLog() |
| | | @ApiOperation(value = "更新用户密码") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "user", value = "用户实体类", dataType = "UsersEntity", paramType = "body", example = "") |
| | | }) |
| | | @PostMapping(value = "/updateUserPwd") |
| | | public ResponseMsg<Boolean> updateUserPwd(@RequestBody UserEntity user, HttpServletRequest req, HttpServletResponse res) { |
| | | try { |
| | | if (user == null) { |
| | | return fail("请提交用户信息!", false); |
| | | } |
| | | if (StringHelper.isEmpty(user.getPwd())) { |
| | | return fail("请输入用户密码!", false); |
| | | } |
| | | if (StringHelper.isEmpty(user.getSalt())) { |
| | | return fail("请输入管理员密码!", false); |
| | | } |
| | | if (!StringHelper.checkPwdValid(user.getPwd())) { |
| | | return fail("新密码不符合规则要求!", false); |
| | | if (uue == null || uue.getIds() == null || uue.getIds().isEmpty()) { |
| | | return fail("没有找到数据", false); |
| | | } |
| | | |
| | | UserEntity ue = tokenService.getCurrentUser(req); |
| | | if (ue == null) { |
| | | return fail("没有登录或登录超时!", false); |
| | | } |
| | | if (!Md5Helper.validatePassword(user.getSalt(), ue.getPwd())) { |
| | | return fail("管理员密码不正确!", false); |
| | | String str = userService.validateAdminPwd(ue, uue.getAdminPwd()); |
| | | if (str != null) { |
| | | return fail(str, false); |
| | | } |
| | | |
| | | UserEntity userEntity = userService.selectUser(user.getId()); |
| | | if (userEntity == null) { |
| | | return fail("没有找到要修改的用户!", false); |
| | | Integer rows = userService.selectForIsAdmin(ue.getId()); |
| | | if (rows < 1) { |
| | | return fail("只允许管理员操作", false); |
| | | } |
| | | // 设置新密码 |
| | | String md5 = Md5Helper.reverse(Md5Helper.generate(user.getPwd())); |
| | | userEntity.setPwd(md5); |
| | | // 设置更新信息 |
| | | userEntity.setUpdateUser(ue.getId()); |
| | | |
| | | Integer rows = userService.updateUsers(userEntity); |
| | | str = userService.validateNewPwd(ue, uue.getNewPwd()); |
| | | if (str != null) { |
| | | return fail(str, false); |
| | | } |
| | | |
| | | rows = userService.updateUsersPwd(ue.getId(), ue.getSalt(), uue.getIds()); |
| | | |
| | | return success(rows > 0 ? "更新成功" : "更新失败", rows > 0); |
| | | } catch (Exception ex) { |
| | | return fail(ex.getMessage(), false); |
| | | } |
| | | } |
| | | } |
| | | } |