From fc0ad32f815535a5a4aee55f92eaac92cbd4d97b Mon Sep 17 00:00:00 2001
From: jiang <893224616@qq.com>
Date: 星期二, 19 七月 2022 18:13:19 +0800
Subject: [PATCH] 1.修复新增用户没有pushkey的问题 2.将重置pushkey改为修改pushkey
---
web_src/src/components/UserManager.vue | 52 ++++++++--------
src/main/java/com/genersoft/iot/vmp/storager/dao/UserMapper.java | 4
src/main/java/com/genersoft/iot/vmp/service/impl/UserServiceImpl.java | 4
src/main/java/com/genersoft/iot/vmp/vmanager/user/UserController.java | 15 +++--
src/main/java/com/genersoft/iot/vmp/service/IUserService.java | 2
web_src/src/components/dialog/changePushKey.vue | 102 ++++++++++++++++++++++++++++++++++
6 files changed, 142 insertions(+), 37 deletions(-)
diff --git a/src/main/java/com/genersoft/iot/vmp/service/IUserService.java b/src/main/java/com/genersoft/iot/vmp/service/IUserService.java
index 616fd1a..7e2a839 100644
--- a/src/main/java/com/genersoft/iot/vmp/service/IUserService.java
+++ b/src/main/java/com/genersoft/iot/vmp/service/IUserService.java
@@ -25,5 +25,5 @@
PageInfo<User> getUsers(int page, int count);
- int resetPushKey(int id);
+ int changePushKey(int id, String pushKey);
}
diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/UserServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/UserServiceImpl.java
index 46d9ad5..f5dc7b0 100644
--- a/src/main/java/com/genersoft/iot/vmp/service/impl/UserServiceImpl.java
+++ b/src/main/java/com/genersoft/iot/vmp/service/impl/UserServiceImpl.java
@@ -75,7 +75,7 @@
}
@Override
- public int resetPushKey(int id) {
- return userMapper.resetPushKey(id);
+ public int changePushKey(int id, String pushKey) {
+ return userMapper.changePushKey(id,pushKey);
}
}
diff --git a/src/main/java/com/genersoft/iot/vmp/storager/dao/UserMapper.java b/src/main/java/com/genersoft/iot/vmp/storager/dao/UserMapper.java
index 57d2fdc..c7a44fd 100644
--- a/src/main/java/com/genersoft/iot/vmp/storager/dao/UserMapper.java
+++ b/src/main/java/com/genersoft/iot/vmp/storager/dao/UserMapper.java
@@ -60,6 +60,6 @@
@ResultMap(value="roleMap")
List<User> getUsers();
- @Delete("update user set pushKey=MD5(NOW()+#{id}) where id=#{id}")
- int resetPushKey(int id);
+ @Update("update user set pushKey=#{pushKey} where id=#{id}")
+ int changePushKey(int id, String pushKey);
}
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 ca6fc84..442832b 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
@@ -124,7 +124,8 @@
User user = new User();
user.setUsername(username);
user.setPassword(DigestUtils.md5DigestAsHex(password.getBytes()));
-
+ //鏂板鐢ㄦ埛鐨刾ushKey鐨勭敓鎴愯鍒欎负md5(鏃堕棿鎴�+鐢ㄦ埛鍚�)
+ user.setPushKey(DigestUtils.md5DigestAsHex((System.currentTimeMillis()+password).getBytes()));
Role role = roleService.getRoleById(roleId);
if (role == null) {
@@ -137,6 +138,7 @@
user.setCreateTime(DateUtil.getNow());
user.setUpdateTime(DateUtil.getNow());
int addResult = userService.addUser(user);
+
result.setCode(addResult > 0 ? 0 : -1);
result.setMsg(addResult > 0 ? "success" : "fail");
@@ -196,12 +198,13 @@
return userService.getUsers(page, count);
}
- @ApiOperation("閲嶇疆pushkey")
+ @ApiOperation("淇敼pushkey")
@ApiImplicitParams({
- @ApiImplicitParam(name = "id", required = true, value = "鐢ㄦ埛Id", dataTypeClass = Integer.class),
+ @ApiImplicitParam(name = "userId", required = true, value = "鐢ㄦ埛Id", dataTypeClass = Integer.class),
+ @ApiImplicitParam(name = "pushKey", required = true, value = "鏂扮殑pushKey", dataTypeClass = String.class),
})
- @RequestMapping("/resetPushKey")
- public ResponseEntity<WVPResult<String>> resetPushKey(@RequestParam Integer id) {
+ @RequestMapping("/changePushKey")
+ public ResponseEntity<WVPResult<String>> changePushKey(@RequestParam Integer userId,@RequestParam String pushKey) {
// 鑾峰彇褰撳墠鐧诲綍鐢ㄦ埛id
int currenRoleId = SecurityUtils.getUserInfo().getRole().getId();
WVPResult<String> result = new WVPResult<>();
@@ -211,7 +214,7 @@
result.setMsg("鐢ㄦ埛鏃犳潈闄�");
return new ResponseEntity<>(result, HttpStatus.FORBIDDEN);
}
- int resetPushKeyResult = userService.resetPushKey(id);
+ int resetPushKeyResult = userService.changePushKey(userId,pushKey);
result.setCode(resetPushKeyResult > 0 ? 0 : -1);
result.setMsg(resetPushKeyResult > 0 ? "success" : "fail");
diff --git a/web_src/src/components/UserManager.vue b/web_src/src/components/UserManager.vue
index 10faf6d..1048f53 100644
--- a/web_src/src/components/UserManager.vue
+++ b/web_src/src/components/UserManager.vue
@@ -21,7 +21,7 @@
<template slot-scope="scope">
<el-button size="medium" icon="el-icon-edit" type="text" @click="edit(scope.row)">淇敼瀵嗙爜</el-button>
<el-divider direction="vertical"></el-divider>
- <el-button size="medium" icon="el-icon-refresh" type="text" @click="resetPushKey(scope.row)">閲嶇疆pushkey</el-button>
+ <el-button size="medium" icon="el-icon-edit" type="text" @click="changePushKey(scope.row)">淇敼pushkey</el-button>
<el-divider direction="vertical"></el-divider>
<el-button size="medium" icon="el-icon-delete" type="text" @click="deleteUser(scope.row)"
style="color: #f56c6c">鍒犻櫎
@@ -30,6 +30,7 @@
</el-table-column>
</el-table>
<changePasswordForAdmin ref="changePasswordForAdmin"></changePasswordForAdmin>
+ <changePushKey ref="changePushKey"></changePushKey>
<addUser ref="addUser"></addUser>
<el-pagination
style="float: right"
@@ -47,6 +48,7 @@
<script>
import uiHeader from '../layout/UiHeader.vue'
import changePasswordForAdmin from './dialog/changePasswordForAdmin.vue'
+import changePushKey from './dialog/changePushKey.vue'
import addUser from '../components/dialog/addUser.vue'
export default {
@@ -54,6 +56,7 @@
components: {
uiHeader,
changePasswordForAdmin,
+ changePushKey,
addUser
},
data() {
@@ -118,7 +121,7 @@
message: "瀵嗙爜淇敼鎴愬姛",
type: "success",
});
- setTimeout(this.getDeviceList, 200)
+ setTimeout(this.getUserList, 200)
})
},
@@ -148,34 +151,31 @@
},
- resetPushKey: function (row) {
- let msg = "纭畾閲嶇疆pushkey锛�"
- if (row.online !== 0) {
- msg = "<strong>纭畾閲嶇疆pushkey锛�</strong>"
- }
- this.$confirm(msg, '鎻愮ず', {
- dangerouslyUseHTMLString: true,
- confirmButtonText: '纭畾',
- cancelButtonText: '鍙栨秷',
- center: true,
- type: 'warning'
- }).then(() => {
- this.$axios({
- method: 'get',
- url: `/api/user/resetPushKey?id=${row.id}`
- }).then((res) => {
- this.getUserList();
- }).catch((error) => {
- console.error(error);
+
+ changePushKey: function (row) {
+ this.$refs.changePushKey.openDialog(row, () => {
+ this.$refs.changePushKey.close();
+ this.$message({
+ showClose: true,
+ message: "pushKey淇敼鎴愬姛",
+ type: "success",
});
- }).catch(() => {
+ setTimeout(this.getUserList, 200)
- });
-
-
+ })
},
addUser: function () {
- this.$refs.addUser.openDialog()
+ // this.$refs.addUser.openDialog()
+ this.$refs.addUser.openDialog( () => {
+ this.$refs.addUser.close();
+ this.$message({
+ showClose: true,
+ message: "鐢ㄦ埛娣诲姞鎴愬姛",
+ type: "success",
+ });
+ setTimeout(this.getUserList, 200)
+
+ })
}
}
}
diff --git a/web_src/src/components/dialog/changePushKey.vue b/web_src/src/components/dialog/changePushKey.vue
new file mode 100644
index 0000000..9f18475
--- /dev/null
+++ b/web_src/src/components/dialog/changePushKey.vue
@@ -0,0 +1,102 @@
+<template>
+ <div id="changepushKey" v-loading="isLoging">
+ <el-dialog
+ title="淇敼瀵嗙爜"
+ width="42%"
+ top="2rem"
+ :close-on-click-modal="false"
+ :visible.sync="showDialog"
+ :destroy-on-close="true"
+ @close="close()"
+ >
+ <div id="shared" style="margin-right: 18px;">
+ <el-form ref="pushKeyForm" :rules="rules" status-icon label-width="86px">
+ <el-form-item label="鏂皃ushKey" prop="newPushKey" >
+ <el-input v-model="newPushKey" autocomplete="off"></el-input>
+ </el-form-item>
+ <el-form-item>
+ <div style="float: right;">
+ <el-button type="primary" @click="onSubmit">淇濆瓨</el-button>
+ <el-button @click="close">鍙栨秷</el-button>
+ </div>
+ </el-form-item>
+ </el-form>
+ </div>
+ </el-dialog>
+ </div>
+</template>
+
+<script>
+export default {
+ name: "changePushKey",
+ props: {},
+ computed: {},
+ created() {},
+ data() {
+ let validatePass1 = (rule, value, callback) => {
+ if (value === '') {
+ callback(new Error('璇疯緭鍏ユ柊pushKey'));
+ } else {
+ callback();
+ }
+ };
+ return {
+ newPushKey: null,
+ confirmpushKey: null,
+ userId: null,
+ showDialog: false,
+ isLoging: false,
+ listChangeCallback: null,
+ form: {},
+ rules: {
+ newpushKey: [{ required: true, validator: validatePass1, trigger: "blur" }],
+ },
+ };
+ },
+ methods: {
+ openDialog: function (row, callback) {
+ console.log(row)
+ this.showDialog = true;
+ this.listChangeCallback = callback;
+ if (row != null) {
+ this.form = row;
+ }
+ },
+ onSubmit: function () {
+ this.$axios({
+ method: 'post',
+ url:"/api/user/changePushKey",
+ params: {
+ pushKey: this.newPushKey,
+ userId: this.form.id,
+ }
+ }).then((res)=> {
+ console.log(res.data)
+ if (res.data.msg === "success"){
+ this.$message({
+ showClose: true,
+ message: '淇敼鎴愬姛',
+ type: 'success'
+ });
+ this.showDialog = false;
+ this.listChangeCallback();
+ }else {
+ this.$message({
+ showClose: true,
+ message: '淇敼瀵嗙爜澶辫触锛屾槸鍚﹀凡鐧诲綍锛堟帴鍙i壌鏉冨叧闂棤娉曚慨鏀瑰瘑鐮侊級',
+ type: 'error'
+ });
+ }
+ }).catch((error)=> {
+ console.error(error)
+ });
+ },
+ close: function () {
+ this.showDialog = false;
+ this.newpushKey = null;
+ this.userId=null;
+ this.adminId=null;
+ },
+ },
+};
+</script>
--
Gitblit v1.8.0