Commit fc0ad32f815535a5a4aee55f92eaac92cbd4d97b

Authored by jiang
1 parent 7f5a18d6

1.修复新增用户没有pushkey的问题

2.将重置pushkey改为修改pushkey
src/main/java/com/genersoft/iot/vmp/service/IUserService.java
... ... @@ -25,5 +25,5 @@ public interface IUserService {
25 25  
26 26 PageInfo<User> getUsers(int page, int count);
27 27  
28   - int resetPushKey(int id);
  28 + int changePushKey(int id, String pushKey);
29 29 }
... ...
src/main/java/com/genersoft/iot/vmp/service/impl/UserServiceImpl.java
... ... @@ -75,7 +75,7 @@ public class UserServiceImpl implements IUserService {
75 75 }
76 76  
77 77 @Override
78   - public int resetPushKey(int id) {
79   - return userMapper.resetPushKey(id);
  78 + public int changePushKey(int id, String pushKey) {
  79 + return userMapper.changePushKey(id,pushKey);
80 80 }
81 81 }
... ...
src/main/java/com/genersoft/iot/vmp/storager/dao/UserMapper.java
... ... @@ -60,6 +60,6 @@ public interface UserMapper {
60 60 @ResultMap(value="roleMap")
61 61 List<User> getUsers();
62 62  
63   - @Delete("update user set pushKey=MD5(NOW()+#{id}) where id=#{id}")
64   - int resetPushKey(int id);
  63 + @Update("update user set pushKey=#{pushKey} where id=#{id}")
  64 + int changePushKey(int id, String pushKey);
65 65 }
... ...
src/main/java/com/genersoft/iot/vmp/vmanager/user/UserController.java
... ... @@ -124,7 +124,8 @@ public class UserController {
124 124 User user = new User();
125 125 user.setUsername(username);
126 126 user.setPassword(DigestUtils.md5DigestAsHex(password.getBytes()));
127   -
  127 + //新增用户的pushKey的生成规则为md5(时间戳+用户名)
  128 + user.setPushKey(DigestUtils.md5DigestAsHex((System.currentTimeMillis()+password).getBytes()));
128 129 Role role = roleService.getRoleById(roleId);
129 130  
130 131 if (role == null) {
... ... @@ -138,6 +139,7 @@ public class UserController {
138 139 user.setUpdateTime(DateUtil.getNow());
139 140 int addResult = userService.addUser(user);
140 141  
  142 +
141 143 result.setCode(addResult > 0 ? 0 : -1);
142 144 result.setMsg(addResult > 0 ? "success" : "fail");
143 145 result.setData(addResult);
... ... @@ -196,12 +198,13 @@ public class UserController {
196 198 return userService.getUsers(page, count);
197 199 }
198 200  
199   - @ApiOperation("重置pushkey")
  201 + @ApiOperation("修改pushkey")
200 202 @ApiImplicitParams({
201   - @ApiImplicitParam(name = "id", required = true, value = "用户Id", dataTypeClass = Integer.class),
  203 + @ApiImplicitParam(name = "userId", required = true, value = "用户Id", dataTypeClass = Integer.class),
  204 + @ApiImplicitParam(name = "pushKey", required = true, value = "新的pushKey", dataTypeClass = String.class),
202 205 })
203   - @RequestMapping("/resetPushKey")
204   - public ResponseEntity<WVPResult<String>> resetPushKey(@RequestParam Integer id) {
  206 + @RequestMapping("/changePushKey")
  207 + public ResponseEntity<WVPResult<String>> changePushKey(@RequestParam Integer userId,@RequestParam String pushKey) {
205 208 // 获取当前登录用户id
206 209 int currenRoleId = SecurityUtils.getUserInfo().getRole().getId();
207 210 WVPResult<String> result = new WVPResult<>();
... ... @@ -211,7 +214,7 @@ public class UserController {
211 214 result.setMsg("用户无权限");
212 215 return new ResponseEntity<>(result, HttpStatus.FORBIDDEN);
213 216 }
214   - int resetPushKeyResult = userService.resetPushKey(id);
  217 + int resetPushKeyResult = userService.changePushKey(userId,pushKey);
215 218  
216 219 result.setCode(resetPushKeyResult > 0 ? 0 : -1);
217 220 result.setMsg(resetPushKeyResult > 0 ? "success" : "fail");
... ...
web_src/src/components/UserManager.vue
... ... @@ -21,7 +21,7 @@
21 21 <template slot-scope="scope">
22 22 <el-button size="medium" icon="el-icon-edit" type="text" @click="edit(scope.row)">修改密码</el-button>
23 23 <el-divider direction="vertical"></el-divider>
24   - <el-button size="medium" icon="el-icon-refresh" type="text" @click="resetPushKey(scope.row)">重置pushkey</el-button>
  24 + <el-button size="medium" icon="el-icon-edit" type="text" @click="changePushKey(scope.row)">修改pushkey</el-button>
25 25 <el-divider direction="vertical"></el-divider>
26 26 <el-button size="medium" icon="el-icon-delete" type="text" @click="deleteUser(scope.row)"
27 27 style="color: #f56c6c">删除
... ... @@ -30,6 +30,7 @@
30 30 </el-table-column>
31 31 </el-table>
32 32 <changePasswordForAdmin ref="changePasswordForAdmin"></changePasswordForAdmin>
  33 + <changePushKey ref="changePushKey"></changePushKey>
33 34 <addUser ref="addUser"></addUser>
34 35 <el-pagination
35 36 style="float: right"
... ... @@ -47,6 +48,7 @@
47 48 <script>
48 49 import uiHeader from '../layout/UiHeader.vue'
49 50 import changePasswordForAdmin from './dialog/changePasswordForAdmin.vue'
  51 +import changePushKey from './dialog/changePushKey.vue'
50 52 import addUser from '../components/dialog/addUser.vue'
51 53  
52 54 export default {
... ... @@ -54,6 +56,7 @@ export default {
54 56 components: {
55 57 uiHeader,
56 58 changePasswordForAdmin,
  59 + changePushKey,
57 60 addUser
58 61 },
59 62 data() {
... ... @@ -118,7 +121,7 @@ export default {
118 121 message: "密码修改成功",
119 122 type: "success",
120 123 });
121   - setTimeout(this.getDeviceList, 200)
  124 + setTimeout(this.getUserList, 200)
122 125  
123 126 })
124 127 },
... ... @@ -148,34 +151,31 @@ export default {
148 151  
149 152  
150 153 },
151   - resetPushKey: function (row) {
152   - let msg = "确定重置pushkey?"
153   - if (row.online !== 0) {
154   - msg = "<strong>确定重置pushkey?</strong>"
155   - }
156   - this.$confirm(msg, '提示', {
157   - dangerouslyUseHTMLString: true,
158   - confirmButtonText: '确定',
159   - cancelButtonText: '取消',
160   - center: true,
161   - type: 'warning'
162   - }).then(() => {
163   - this.$axios({
164   - method: 'get',
165   - url: `/api/user/resetPushKey?id=${row.id}`
166   - }).then((res) => {
167   - this.getUserList();
168   - }).catch((error) => {
169   - console.error(error);
170   - });
171   - }).catch(() => {
172   -
173   - });
174 154  
  155 + changePushKey: function (row) {
  156 + this.$refs.changePushKey.openDialog(row, () => {
  157 + this.$refs.changePushKey.close();
  158 + this.$message({
  159 + showClose: true,
  160 + message: "pushKey修改成功",
  161 + type: "success",
  162 + });
  163 + setTimeout(this.getUserList, 200)
175 164  
  165 + })
176 166 },
177 167 addUser: function () {
178   - this.$refs.addUser.openDialog()
  168 + // this.$refs.addUser.openDialog()
  169 + this.$refs.addUser.openDialog( () => {
  170 + this.$refs.addUser.close();
  171 + this.$message({
  172 + showClose: true,
  173 + message: "用户添加成功",
  174 + type: "success",
  175 + });
  176 + setTimeout(this.getUserList, 200)
  177 +
  178 + })
179 179 }
180 180 }
181 181 }
... ...
web_src/src/components/dialog/changePushKey.vue 0 → 100644
  1 +<template>
  2 + <div id="changepushKey" v-loading="isLoging">
  3 + <el-dialog
  4 + title="修改密码"
  5 + width="42%"
  6 + top="2rem"
  7 + :close-on-click-modal="false"
  8 + :visible.sync="showDialog"
  9 + :destroy-on-close="true"
  10 + @close="close()"
  11 + >
  12 + <div id="shared" style="margin-right: 18px;">
  13 + <el-form ref="pushKeyForm" :rules="rules" status-icon label-width="86px">
  14 + <el-form-item label="新pushKey" prop="newPushKey" >
  15 + <el-input v-model="newPushKey" autocomplete="off"></el-input>
  16 + </el-form-item>
  17 + <el-form-item>
  18 + <div style="float: right;">
  19 + <el-button type="primary" @click="onSubmit">保存</el-button>
  20 + <el-button @click="close">取消</el-button>
  21 + </div>
  22 + </el-form-item>
  23 + </el-form>
  24 + </div>
  25 + </el-dialog>
  26 + </div>
  27 +</template>
  28 +
  29 +<script>
  30 +export default {
  31 + name: "changePushKey",
  32 + props: {},
  33 + computed: {},
  34 + created() {},
  35 + data() {
  36 + let validatePass1 = (rule, value, callback) => {
  37 + if (value === '') {
  38 + callback(new Error('请输入新pushKey'));
  39 + } else {
  40 + callback();
  41 + }
  42 + };
  43 + return {
  44 + newPushKey: null,
  45 + confirmpushKey: null,
  46 + userId: null,
  47 + showDialog: false,
  48 + isLoging: false,
  49 + listChangeCallback: null,
  50 + form: {},
  51 + rules: {
  52 + newpushKey: [{ required: true, validator: validatePass1, trigger: "blur" }],
  53 + },
  54 + };
  55 + },
  56 + methods: {
  57 + openDialog: function (row, callback) {
  58 + console.log(row)
  59 + this.showDialog = true;
  60 + this.listChangeCallback = callback;
  61 + if (row != null) {
  62 + this.form = row;
  63 + }
  64 + },
  65 + onSubmit: function () {
  66 + this.$axios({
  67 + method: 'post',
  68 + url:"/api/user/changePushKey",
  69 + params: {
  70 + pushKey: this.newPushKey,
  71 + userId: this.form.id,
  72 + }
  73 + }).then((res)=> {
  74 + console.log(res.data)
  75 + if (res.data.msg === "success"){
  76 + this.$message({
  77 + showClose: true,
  78 + message: '修改成功',
  79 + type: 'success'
  80 + });
  81 + this.showDialog = false;
  82 + this.listChangeCallback();
  83 + }else {
  84 + this.$message({
  85 + showClose: true,
  86 + message: '修改密码失败,是否已登录(接口鉴权关闭无法修改密码)',
  87 + type: 'error'
  88 + });
  89 + }
  90 + }).catch((error)=> {
  91 + console.error(error)
  92 + });
  93 + },
  94 + close: function () {
  95 + this.showDialog = false;
  96 + this.newpushKey = null;
  97 + this.userId=null;
  98 + this.adminId=null;
  99 + },
  100 + },
  101 +};
  102 +</script>
... ...