From c6fbd0327644559baf534467ae1cc8a853212e7d Mon Sep 17 00:00:00 2001
From: jiang <893224616@qq.com>
Date: 星期一, 18 七月 2022 17:09:35 +0800
Subject: [PATCH] 增加用户管理功能。管理员可以添加删除用户、修改用户密码、重置pushkey

---
 src/main/java/com/genersoft/iot/vmp/vmanager/user/UserController.java |   64 ++++++++++++++++++++++++++++++++
 1 files changed, 64 insertions(+), 0 deletions(-)

diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/user/UserController.java b/src/main/java/com/genersoft/iot/vmp/vmanager/user/UserController.java
index 152122d..ca6fc84 100644
--- a/src/main/java/com/genersoft/iot/vmp/vmanager/user/UserController.java
+++ b/src/main/java/com/genersoft/iot/vmp/vmanager/user/UserController.java
@@ -8,6 +8,7 @@
 import com.genersoft.iot.vmp.storager.dao.dto.User;
 import com.genersoft.iot.vmp.utils.DateUtil;
 import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
+import com.github.pagehelper.PageInfo;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiImplicitParam;
 import io.swagger.annotations.ApiImplicitParams;
@@ -177,4 +178,67 @@
         result.setData(allUsers);
         return new ResponseEntity<>(result, HttpStatus.OK);
     }
+
+    /**
+     * 鍒嗛〉鏌ヨ鐢ㄦ埛
+     *
+     * @param page  褰撳墠椤�
+     * @param count 姣忛〉鏌ヨ鏁伴噺
+     * @return 鍒嗛〉鐢ㄦ埛鍒楄〃
+     */
+    @ApiOperation("鍒嗛〉鏌ヨ鐢ㄦ埛")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "page", value = "褰撳墠椤�", required = true, dataTypeClass = Integer.class),
+            @ApiImplicitParam(name = "count", value = "姣忛〉鏌ヨ鏁伴噺", required = true, dataTypeClass = Integer.class),
+    })
+    @GetMapping("/users")
+    public PageInfo<User> users(int page, int count) {
+        return userService.getUsers(page, count);
+    }
+
+    @ApiOperation("閲嶇疆pushkey")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "id", required = true, value = "鐢ㄦ埛Id", dataTypeClass = Integer.class),
+    })
+    @RequestMapping("/resetPushKey")
+    public ResponseEntity<WVPResult<String>> resetPushKey(@RequestParam Integer id) {
+        // 鑾峰彇褰撳墠鐧诲綍鐢ㄦ埛id
+        int currenRoleId = SecurityUtils.getUserInfo().getRole().getId();
+        WVPResult<String> result = new WVPResult<>();
+        if (currenRoleId != 1) {
+            // 鍙敤瑙掕壊id涓�0鎵嶅彲浠ュ垹闄ゅ拰娣诲姞鐢ㄦ埛
+            result.setCode(-1);
+            result.setMsg("鐢ㄦ埛鏃犳潈闄�");
+            return new ResponseEntity<>(result, HttpStatus.FORBIDDEN);
+        }
+        int resetPushKeyResult = userService.resetPushKey(id);
+
+        result.setCode(resetPushKeyResult > 0 ? 0 : -1);
+        result.setMsg(resetPushKeyResult > 0 ? "success" : "fail");
+        return new ResponseEntity<>(result, HttpStatus.OK);
+    }
+
+    @ApiOperation("绠$悊鍛樹慨鏀规櫘閫氱敤鎴峰瘑鐮�")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "adminId", required = true, value = "绠$悊鍛榠d", dataTypeClass = String.class),
+            @ApiImplicitParam(name = "userId", required = true, value = "鐢ㄦ埛id", dataTypeClass = String.class),
+            @ApiImplicitParam(name = "password", required = true, value = "鏂板瘑鐮侊紙鏈猰d5鍔犲瘑鐨勫瘑鐮侊級", dataTypeClass = String.class),
+    })
+    @PostMapping("/changePasswordForAdmin")
+    public String changePasswordForAdmin(@RequestParam int userId, @RequestParam String password) {
+        // 鑾峰彇褰撳墠鐧诲綍鐢ㄦ埛id
+        LoginUser userInfo = SecurityUtils.getUserInfo();
+        if (userInfo == null) {
+            return "fail";
+        }
+        Role role = userInfo.getRole();
+        if (role != null && role.getId() == 1) {
+            boolean result = userService.changePassword(userId, DigestUtils.md5DigestAsHex(password.getBytes()));
+            if (result) {
+                return "success";
+            }
+        }
+
+        return "fail";
+    }
 }

--
Gitblit v1.8.0