From c6fbd0327644559baf534467ae1cc8a853212e7d Mon Sep 17 00:00:00 2001 From: jiang <893224616@qq.com> Date: Mon, 18 Jul 2022 17:09:35 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=94=A8=E6=88=B7=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E5=8A=9F=E8=83=BD=E3=80=82=E7=AE=A1=E7=90=86=E5=91=98?= =?UTF-8?q?=E5=8F=AF=E4=BB=A5=E6=B7=BB=E5=8A=A0=E5=88=A0=E9=99=A4=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E3=80=81=E4=BF=AE=E6=94=B9=E7=94=A8=E6=88=B7=E5=AF=86?= =?UTF-8?q?=E7=A0=81=E3=80=81=E9=87=8D=E7=BD=AEpushkey?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../iot/vmp/service/IUserService.java | 5 + .../iot/vmp/service/impl/UserServiceImpl.java | 16 +- .../iot/vmp/storager/dao/UserMapper.java | 7 + .../iot/vmp/vmanager/user/UserController.java | 64 +++++ web_src/src/components/Login.vue | 2 +- web_src/src/components/UserManager.vue | 236 ++++++++++++++++++ web_src/src/components/dialog/addUser.vue | 159 ++++++++++++ .../dialog/changePasswordForAdmin.vue | 121 +++++++++ web_src/src/layout/UiHeader.vue | 3 + web_src/src/router/index.js | 6 + 10 files changed, 617 insertions(+), 2 deletions(-) create mode 100644 web_src/src/components/UserManager.vue create mode 100644 web_src/src/components/dialog/addUser.vue create mode 100644 web_src/src/components/dialog/changePasswordForAdmin.vue 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 e362605b..616fd1a3 100644 --- a/src/main/java/com/genersoft/iot/vmp/service/IUserService.java +++ b/src/main/java/com/genersoft/iot/vmp/service/IUserService.java @@ -1,6 +1,7 @@ package com.genersoft.iot.vmp.service; import com.genersoft.iot.vmp.storager.dao.dto.User; +import com.github.pagehelper.PageInfo; import java.util.List; @@ -21,4 +22,8 @@ public interface IUserService { int updateUsers(User user); boolean checkPushAuthority(String callId, String sign); + + PageInfo getUsers(int page, int count); + + int resetPushKey(int id); } 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 01d91a55..46d9ad5d 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 @@ -3,6 +3,8 @@ package com.genersoft.iot.vmp.service.impl; import com.genersoft.iot.vmp.service.IUserService; import com.genersoft.iot.vmp.storager.dao.UserMapper; import com.genersoft.iot.vmp.storager.dao.dto.User; +import com.github.pagehelper.PageHelper; +import com.github.pagehelper.PageInfo; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.util.StringUtils; @@ -11,7 +13,7 @@ import java.util.List; @Service public class UserServiceImpl implements IUserService { - + @Autowired private UserMapper userMapper; @@ -64,4 +66,16 @@ public class UserServiceImpl implements IUserService { return userMapper.checkPushAuthorityByCallIdAndSign(callId, sign).size() > 0; } } + + @Override + public PageInfo getUsers(int page, int count) { + PageHelper.startPage(page, count); + List users = userMapper.getUsers(); + return new PageInfo<>(users); + } + + @Override + public int resetPushKey(int id) { + return userMapper.resetPushKey(id); + } } 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 5ed0a57d..850e4d44 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 @@ -55,4 +55,11 @@ public interface UserMapper { @Select("select * from user where md5(pushKey) = '${sign}'") List checkPushAuthorityByCallId(String sign); + + @Select("select u.idu.username,u.pushKey,u.roleId, r.id as roleID, r.name as roleName, r.authority as roleAuthority , r.createTime as roleCreateTime , r.updateTime as roleUpdateTime FROM user u join user_role r on u.roleId=r.id") + @ResultMap(value="roleMap") + List getUsers(); + + @Delete("update user set pushKey=MD5(NOW()+#{id}) where id=#{id}") + int resetPushKey(int id); } 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 152122d2..ca6fc84e 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.Role; 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 @@ public class UserController { 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 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> resetPushKey(@RequestParam Integer id) { + // 获取当前登录用户id + int currenRoleId = SecurityUtils.getUserInfo().getRole().getId(); + WVPResult 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 = "管理员id", dataTypeClass = String.class), + @ApiImplicitParam(name = "userId", required = true, value = "用户id", dataTypeClass = String.class), + @ApiImplicitParam(name = "password", required = true, value = "新密码(未md5加密的密码)", 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"; + } } diff --git a/web_src/src/components/Login.vue b/web_src/src/components/Login.vue index d823659b..4ade7444 100644 --- a/web_src/src/components/Login.vue +++ b/web_src/src/components/Login.vue @@ -86,7 +86,7 @@ export default { }).then(function (res) { console.log(JSON.stringify(res)); if (res.data.code == 0 && res.data.msg == "success") { - that.$cookies.set("session", {"username": that.username}) ; + that.$cookies.set("session", {"username": that.username,"roleId":res.data.data.role.id}) ; //登录成功后 that.cancelEnterkeyDefaultAction(); that.$router.push('/'); diff --git a/web_src/src/components/UserManager.vue b/web_src/src/components/UserManager.vue new file mode 100644 index 00000000..10faf6d3 --- /dev/null +++ b/web_src/src/components/UserManager.vue @@ -0,0 +1,236 @@ + + + + diff --git a/web_src/src/components/dialog/addUser.vue b/web_src/src/components/dialog/addUser.vue new file mode 100644 index 00000000..403ecebe --- /dev/null +++ b/web_src/src/components/dialog/addUser.vue @@ -0,0 +1,159 @@ + + + diff --git a/web_src/src/components/dialog/changePasswordForAdmin.vue b/web_src/src/components/dialog/changePasswordForAdmin.vue new file mode 100644 index 00000000..0e0ae229 --- /dev/null +++ b/web_src/src/components/dialog/changePasswordForAdmin.vue @@ -0,0 +1,121 @@ + + + diff --git a/web_src/src/layout/UiHeader.vue b/web_src/src/layout/UiHeader.vue index 3c933f14..42d617e9 100644 --- a/web_src/src/layout/UiHeader.vue +++ b/web_src/src/layout/UiHeader.vue @@ -13,6 +13,7 @@ 云端录像 节点管理 国标级联 + 用户管理 @@ -47,9 +48,11 @@ export default { alarmNotify: false, sseSource: null, activeIndex: this.$route.path, + editUser: this.$cookies.get("session").roleId==1 }; }, created() { + console.log(this.$cookies.get("session")) if (this.$route.path.startsWith("/channelList")) { this.activeIndex = "/deviceList" } diff --git a/web_src/src/router/index.js b/web_src/src/router/index.js index 2c9c6f37..7651a725 100644 --- a/web_src/src/router/index.js +++ b/web_src/src/router/index.js @@ -17,6 +17,7 @@ import sip from '../components/setting/Sip.vue' import media from '../components/setting/Media.vue' import live from '../components/live.vue' import deviceTree from '../components/common/DeviceTree.vue' +import userManager from '../components/UserManager.vue' import wasmPlayer from '../components/common/jessibuca.vue' import rtcPlayer from '../components/dialog/rtcPlayer.vue' @@ -103,6 +104,11 @@ export default new VueRouter({ name: 'map', component: map, }, + { + path: '/userManager', + name: 'userManager', + component: userManager, + } ] }, {