Commit 96bc081ea94bdb76af43439a43ee12c66a8bb9c7
1 parent
d2367352
添加用户操作接口
Showing
10 changed files
with
111 additions
and
28 deletions
sql/mysql.sql
| @@ -219,5 +219,8 @@ create table user | @@ -219,5 +219,8 @@ create table user | ||
| 219 | update_time varchar(50) not null | 219 | update_time varchar(50) not null |
| 220 | ); | 220 | ); |
| 221 | 221 | ||
| 222 | +create unique index user_username_uindex | ||
| 223 | + on user (username); | ||
| 224 | + | ||
| 222 | insert into user (username, password, roleId, create_time, update_time) values ('admin', '21232f297a57a5a743894a0e4a801fc3', '0', '2021-04-13 14:14:57', '2021-04-13 14:14:57'); | 225 | insert into user (username, password, roleId, create_time, update_time) values ('admin', '21232f297a57a5a743894a0e4a801fc3', '0', '2021-04-13 14:14:57', '2021-04-13 14:14:57'); |
| 223 | 226 |
src/main/java/com/genersoft/iot/vmp/conf/MediaConfig.java
| @@ -188,8 +188,8 @@ public class MediaConfig{ | @@ -188,8 +188,8 @@ public class MediaConfig{ | ||
| 188 | mediaServerItem.setRecordAssistPort(recordAssistPort); | 188 | mediaServerItem.setRecordAssistPort(recordAssistPort); |
| 189 | 189 | ||
| 190 | SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | 190 | SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| 191 | - mediaServerItem.setCreateTime(format.format(new Date(System.currentTimeMillis()))); | ||
| 192 | - mediaServerItem.setUpdateTime(format.format(new Date(System.currentTimeMillis()))); | 191 | + mediaServerItem.setCreateTime(format.format(System.currentTimeMillis())); |
| 192 | + mediaServerItem.setUpdateTime(format.format(System.currentTimeMillis())); | ||
| 193 | 193 | ||
| 194 | return mediaServerItem; | 194 | return mediaServerItem; |
| 195 | } | 195 | } |
src/main/java/com/genersoft/iot/vmp/conf/security/dto/LoginUser.java
| @@ -92,4 +92,10 @@ public class LoginUser implements UserDetails, CredentialsContainer { | @@ -92,4 +92,10 @@ public class LoginUser implements UserDetails, CredentialsContainer { | ||
| 92 | public int getId() { | 92 | public int getId() { |
| 93 | return user.getId(); | 93 | return user.getId(); |
| 94 | } | 94 | } |
| 95 | + | ||
| 96 | + public int getRoleId() { | ||
| 97 | + return user.getRoleId(); | ||
| 98 | + } | ||
| 99 | + | ||
| 100 | + | ||
| 95 | } | 101 | } |
src/main/java/com/genersoft/iot/vmp/gb28181/event/online/OnlineEventListener.java
| @@ -52,7 +52,7 @@ public class OnlineEventListener implements ApplicationListener<OnlineEvent> { | @@ -52,7 +52,7 @@ public class OnlineEventListener implements ApplicationListener<OnlineEvent> { | ||
| 52 | case VideoManagerConstants.EVENT_ONLINE_REGISTER: | 52 | case VideoManagerConstants.EVENT_ONLINE_REGISTER: |
| 53 | // 超时时间 | 53 | // 超时时间 |
| 54 | redis.set(key, event.getDevice().getDeviceId(), sipConfig.getKeepaliveTimeOut()); | 54 | redis.set(key, event.getDevice().getDeviceId(), sipConfig.getKeepaliveTimeOut()); |
| 55 | - device.setRegisterTime(format.format(new Date(System.currentTimeMillis()))); | 55 | + device.setRegisterTime(format.format(System.currentTimeMillis())); |
| 56 | break; | 56 | break; |
| 57 | // 设备主动发送心跳触发的在线事件 | 57 | // 设备主动发送心跳触发的在线事件 |
| 58 | case VideoManagerConstants.EVENT_ONLINE_KEEPLIVE: | 58 | case VideoManagerConstants.EVENT_ONLINE_KEEPLIVE: |
| @@ -63,7 +63,7 @@ public class OnlineEventListener implements ApplicationListener<OnlineEvent> { | @@ -63,7 +63,7 @@ public class OnlineEventListener implements ApplicationListener<OnlineEvent> { | ||
| 63 | } else { | 63 | } else { |
| 64 | redis.expire(key, sipConfig.getKeepaliveTimeOut()); | 64 | redis.expire(key, sipConfig.getKeepaliveTimeOut()); |
| 65 | } | 65 | } |
| 66 | - device.setKeepaliveTime(format.format(new Date(System.currentTimeMillis()))); | 66 | + device.setKeepaliveTime(format.format(System.currentTimeMillis())); |
| 67 | break; | 67 | break; |
| 68 | // 设备主动发送消息触发的在线事件 | 68 | // 设备主动发送消息触发的在线事件 |
| 69 | case VideoManagerConstants.EVENT_ONLINE_MESSAGE: | 69 | case VideoManagerConstants.EVENT_ONLINE_MESSAGE: |
src/main/java/com/genersoft/iot/vmp/service/IUserService.java
| @@ -12,11 +12,11 @@ public interface IUserService { | @@ -12,11 +12,11 @@ public interface IUserService { | ||
| 12 | 12 | ||
| 13 | User getUserByUsername(String username); | 13 | User getUserByUsername(String username); |
| 14 | 14 | ||
| 15 | - void addUser(User user); | 15 | + int addUser(User user); |
| 16 | 16 | ||
| 17 | - void deleteUser(int id); | 17 | + int deleteUser(int id); |
| 18 | 18 | ||
| 19 | List<User> getAllUsers(); | 19 | List<User> getAllUsers(); |
| 20 | 20 | ||
| 21 | - void updateUsers(User user); | 21 | + int updateUsers(User user); |
| 22 | } | 22 | } |
src/main/java/com/genersoft/iot/vmp/service/impl/MediaServerServiceImpl.java
| @@ -276,7 +276,7 @@ public class MediaServerServiceImpl implements IMediaServerService, CommandLineR | @@ -276,7 +276,7 @@ public class MediaServerServiceImpl implements IMediaServerService, CommandLineR | ||
| 276 | resetOnlineServerItem(serverItemFromConfig); | 276 | resetOnlineServerItem(serverItemFromConfig); |
| 277 | setZLMConfig(serverItemFromConfig); | 277 | setZLMConfig(serverItemFromConfig); |
| 278 | }else { | 278 | }else { |
| 279 | - String now = this.format.format(new Date(System.currentTimeMillis())); | 279 | + String now = this.format.format(System.currentTimeMillis()); |
| 280 | if (serverItem == null){ | 280 | if (serverItem == null){ |
| 281 | // 一个新的zlm接入wvp | 281 | // 一个新的zlm接入wvp |
| 282 | serverItem = new MediaServerItem(zlmServerConfig, sipConfig.getSipIp()); | 282 | serverItem = new MediaServerItem(zlmServerConfig, sipConfig.getSipIp()); |
src/main/java/com/genersoft/iot/vmp/service/impl/UserServiceImpl.java
| @@ -13,8 +13,7 @@ public class UserServiceImpl implements IUserService { | @@ -13,8 +13,7 @@ public class UserServiceImpl implements IUserService { | ||
| 13 | 13 | ||
| 14 | @Autowired | 14 | @Autowired |
| 15 | private UserMapper userMapper; | 15 | private UserMapper userMapper; |
| 16 | - | ||
| 17 | - | 16 | + |
| 18 | @Override | 17 | @Override |
| 19 | public User getUser(String username, String password) { | 18 | public User getUser(String username, String password) { |
| 20 | return userMapper.select(username, password); | 19 | return userMapper.select(username, password); |
| @@ -33,12 +32,14 @@ public class UserServiceImpl implements IUserService { | @@ -33,12 +32,14 @@ public class UserServiceImpl implements IUserService { | ||
| 33 | } | 32 | } |
| 34 | 33 | ||
| 35 | @Override | 34 | @Override |
| 36 | - public void addUser(User user) { | ||
| 37 | - userMapper.add(user); | 35 | + public int addUser(User user) { |
| 36 | + User userByUsername = userMapper.getUserByUsername(user.getUsername()); | ||
| 37 | + if (userByUsername != null) return 0; | ||
| 38 | + return userMapper.add(user); | ||
| 38 | } | 39 | } |
| 39 | @Override | 40 | @Override |
| 40 | - public void deleteUser(int id) { | ||
| 41 | - userMapper.delete(id); | 41 | + public int deleteUser(int id) { |
| 42 | + return userMapper.delete(id); | ||
| 42 | } | 43 | } |
| 43 | 44 | ||
| 44 | @Override | 45 | @Override |
| @@ -47,8 +48,8 @@ public class UserServiceImpl implements IUserService { | @@ -47,8 +48,8 @@ public class UserServiceImpl implements IUserService { | ||
| 47 | } | 48 | } |
| 48 | 49 | ||
| 49 | @Override | 50 | @Override |
| 50 | - public void updateUsers(User user) { | ||
| 51 | - userMapper.update(user); | 51 | + public int updateUsers(User user) { |
| 52 | + return userMapper.update(user); | ||
| 52 | } | 53 | } |
| 53 | 54 | ||
| 54 | 55 |
src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStoragerImpl.java
| @@ -109,7 +109,7 @@ public class VideoManagerStoragerImpl implements IVideoManagerStorager { | @@ -109,7 +109,7 @@ public class VideoManagerStoragerImpl implements IVideoManagerStorager { | ||
| 109 | */ | 109 | */ |
| 110 | @Override | 110 | @Override |
| 111 | public synchronized boolean updateDevice(Device device) { | 111 | public synchronized boolean updateDevice(Device device) { |
| 112 | - String now = this.format.format(new Date(System.currentTimeMillis())); | 112 | + String now = this.format.format(System.currentTimeMillis()); |
| 113 | device.setUpdateTime(now); | 113 | device.setUpdateTime(now); |
| 114 | Device deviceByDeviceId = deviceMapper.getDeviceByDeviceId(device.getDeviceId()); | 114 | Device deviceByDeviceId = deviceMapper.getDeviceByDeviceId(device.getDeviceId()); |
| 115 | if (deviceByDeviceId == null) { | 115 | if (deviceByDeviceId == null) { |
| @@ -126,7 +126,7 @@ public class VideoManagerStoragerImpl implements IVideoManagerStorager { | @@ -126,7 +126,7 @@ public class VideoManagerStoragerImpl implements IVideoManagerStorager { | ||
| 126 | String channelId = channel.getChannelId(); | 126 | String channelId = channel.getChannelId(); |
| 127 | channel.setDeviceId(deviceId); | 127 | channel.setDeviceId(deviceId); |
| 128 | channel.setStreamId(streamSession.getStreamId(deviceId, channel.getChannelId())); | 128 | channel.setStreamId(streamSession.getStreamId(deviceId, channel.getChannelId())); |
| 129 | - String now = this.format.format(new Date(System.currentTimeMillis())); | 129 | + String now = this.format.format(System.currentTimeMillis()); |
| 130 | channel.setUpdateTime(now); | 130 | channel.setUpdateTime(now); |
| 131 | DeviceChannel deviceChannel = deviceChannelMapper.queryChannel(deviceId, channelId); | 131 | DeviceChannel deviceChannel = deviceChannelMapper.queryChannel(deviceId, channelId); |
| 132 | if (deviceChannel == null) { | 132 | if (deviceChannel == null) { |
| @@ -463,7 +463,7 @@ public class VideoManagerStoragerImpl implements IVideoManagerStorager { | @@ -463,7 +463,7 @@ public class VideoManagerStoragerImpl implements IVideoManagerStorager { | ||
| 463 | boolean result = false; | 463 | boolean result = false; |
| 464 | streamProxyItem.setStreamType("proxy"); | 464 | streamProxyItem.setStreamType("proxy"); |
| 465 | streamProxyItem.setStatus(true); | 465 | streamProxyItem.setStatus(true); |
| 466 | - String now = this.format.format(new Date(System.currentTimeMillis())); | 466 | + String now = this.format.format(System.currentTimeMillis()); |
| 467 | streamProxyItem.setCreateTime(now); | 467 | streamProxyItem.setCreateTime(now); |
| 468 | try { | 468 | try { |
| 469 | if (gbStreamMapper.add(streamProxyItem)<0 || streamProxyMapper.add(streamProxyItem) < 0) { | 469 | if (gbStreamMapper.add(streamProxyItem)<0 || streamProxyMapper.add(streamProxyItem) < 0) { |
| @@ -609,7 +609,7 @@ public class VideoManagerStoragerImpl implements IVideoManagerStorager { | @@ -609,7 +609,7 @@ public class VideoManagerStoragerImpl implements IVideoManagerStorager { | ||
| 609 | 609 | ||
| 610 | @Override | 610 | @Override |
| 611 | public void updateMediaServer(MediaServerItem mediaServerItem) { | 611 | public void updateMediaServer(MediaServerItem mediaServerItem) { |
| 612 | - String now = this.format.format(new Date(System.currentTimeMillis())); | 612 | + String now = this.format.format(System.currentTimeMillis()); |
| 613 | mediaServerItem.setUpdateTime(now); | 613 | mediaServerItem.setUpdateTime(now); |
| 614 | if (mediaServerMapper.queryOne(mediaServerItem.getId()) != null) { | 614 | if (mediaServerMapper.queryOne(mediaServerItem.getId()) != null) { |
| 615 | mediaServerMapper.update(mediaServerItem); | 615 | mediaServerMapper.update(mediaServerItem); |
src/main/java/com/genersoft/iot/vmp/vmanager/user/UserController.java
| @@ -3,16 +3,24 @@ package com.genersoft.iot.vmp.vmanager.user; | @@ -3,16 +3,24 @@ package com.genersoft.iot.vmp.vmanager.user; | ||
| 3 | import com.genersoft.iot.vmp.conf.security.SecurityUtils; | 3 | import com.genersoft.iot.vmp.conf.security.SecurityUtils; |
| 4 | import com.genersoft.iot.vmp.conf.security.dto.LoginUser; | 4 | import com.genersoft.iot.vmp.conf.security.dto.LoginUser; |
| 5 | import com.genersoft.iot.vmp.service.IUserService; | 5 | import com.genersoft.iot.vmp.service.IUserService; |
| 6 | +import com.genersoft.iot.vmp.storager.dao.dto.User; | ||
| 7 | +import com.genersoft.iot.vmp.vmanager.bean.WVPResult; | ||
| 6 | import io.swagger.annotations.Api; | 8 | import io.swagger.annotations.Api; |
| 7 | import io.swagger.annotations.ApiImplicitParam; | 9 | import io.swagger.annotations.ApiImplicitParam; |
| 8 | import io.swagger.annotations.ApiImplicitParams; | 10 | import io.swagger.annotations.ApiImplicitParams; |
| 9 | import io.swagger.annotations.ApiOperation; | 11 | import io.swagger.annotations.ApiOperation; |
| 10 | import org.springframework.beans.factory.annotation.Autowired; | 12 | import org.springframework.beans.factory.annotation.Autowired; |
| 13 | +import org.springframework.http.HttpStatus; | ||
| 14 | +import org.springframework.http.ResponseEntity; | ||
| 11 | import org.springframework.security.authentication.AuthenticationManager; | 15 | import org.springframework.security.authentication.AuthenticationManager; |
| 12 | import org.springframework.util.DigestUtils; | 16 | import org.springframework.util.DigestUtils; |
| 13 | import org.springframework.web.bind.annotation.*; | 17 | import org.springframework.web.bind.annotation.*; |
| 14 | 18 | ||
| 15 | import javax.security.sasl.AuthenticationException; | 19 | import javax.security.sasl.AuthenticationException; |
| 20 | +import javax.xml.crypto.Data; | ||
| 21 | +import java.text.SimpleDateFormat; | ||
| 22 | +import java.util.Date; | ||
| 23 | +import java.util.List; | ||
| 16 | 24 | ||
| 17 | @Api(tags = "用户管理") | 25 | @Api(tags = "用户管理") |
| 18 | @CrossOrigin | 26 | @CrossOrigin |
| @@ -26,13 +34,15 @@ public class UserController { | @@ -26,13 +34,15 @@ public class UserController { | ||
| 26 | @Autowired | 34 | @Autowired |
| 27 | private IUserService userService; | 35 | private IUserService userService; |
| 28 | 36 | ||
| 37 | + private final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | ||
| 38 | + | ||
| 29 | @ApiOperation("登录") | 39 | @ApiOperation("登录") |
| 30 | @ApiImplicitParams({ | 40 | @ApiImplicitParams({ |
| 31 | - @ApiImplicitParam(name = "username", value = "用户名", dataTypeClass = String.class), | ||
| 32 | - @ApiImplicitParam(name = "password", value = "密码(32位md5加密)", dataTypeClass = String.class), | 41 | + @ApiImplicitParam(name = "username", required = true, value = "用户名", dataTypeClass = String.class), |
| 42 | + @ApiImplicitParam(name = "password", required = true, value = "密码(32位md5加密)", dataTypeClass = String.class), | ||
| 33 | }) | 43 | }) |
| 34 | @GetMapping("/login") | 44 | @GetMapping("/login") |
| 35 | - public String login(String username, String password){ | 45 | + public String login(@RequestParam String username, @RequestParam String password){ |
| 36 | LoginUser user; | 46 | LoginUser user; |
| 37 | try { | 47 | try { |
| 38 | user = SecurityUtils.login(username, password, authenticationManager); | 48 | user = SecurityUtils.login(username, password, authenticationManager); |
| @@ -49,17 +59,17 @@ public class UserController { | @@ -49,17 +59,17 @@ public class UserController { | ||
| 49 | 59 | ||
| 50 | @ApiOperation("修改密码") | 60 | @ApiOperation("修改密码") |
| 51 | @ApiImplicitParams({ | 61 | @ApiImplicitParams({ |
| 52 | - @ApiImplicitParam(name = "username", value = "用户名", dataTypeClass = String.class), | ||
| 53 | - @ApiImplicitParam(name = "oldpassword", value = "旧密码(已md5加密的密码)", dataTypeClass = String.class), | ||
| 54 | - @ApiImplicitParam(name = "password", value = "新密码(未md5加密的密码)", dataTypeClass = String.class), | 62 | + @ApiImplicitParam(name = "username", required = true, value = "用户名", dataTypeClass = String.class), |
| 63 | + @ApiImplicitParam(name = "oldpassword", required = true, value = "旧密码(已md5加密的密码)", dataTypeClass = String.class), | ||
| 64 | + @ApiImplicitParam(name = "password", required = true, value = "新密码(未md5加密的密码)", dataTypeClass = String.class), | ||
| 55 | }) | 65 | }) |
| 56 | @PostMapping("/changePassword") | 66 | @PostMapping("/changePassword") |
| 57 | - public String changePassword(String oldpassword, String password){ | 67 | + public String changePassword(@RequestParam String oldPassword, @RequestParam String password){ |
| 58 | // 获取当前登录用户id | 68 | // 获取当前登录用户id |
| 59 | String username = SecurityUtils.getUserInfo().getUsername(); | 69 | String username = SecurityUtils.getUserInfo().getUsername(); |
| 60 | LoginUser user = null; | 70 | LoginUser user = null; |
| 61 | try { | 71 | try { |
| 62 | - user = SecurityUtils.login(username, oldpassword, authenticationManager); | 72 | + user = SecurityUtils.login(username, oldPassword, authenticationManager); |
| 63 | if (user != null) { | 73 | if (user != null) { |
| 64 | int userId = SecurityUtils.getUserId(); | 74 | int userId = SecurityUtils.getUserId(); |
| 65 | boolean result = userService.changePassword(userId, DigestUtils.md5DigestAsHex(password.getBytes())); | 75 | boolean result = userService.changePassword(userId, DigestUtils.md5DigestAsHex(password.getBytes())); |
| @@ -72,4 +82,67 @@ public class UserController { | @@ -72,4 +82,67 @@ public class UserController { | ||
| 72 | } | 82 | } |
| 73 | return "fail"; | 83 | return "fail"; |
| 74 | } | 84 | } |
| 85 | + | ||
| 86 | + | ||
| 87 | + @ApiOperation("添加用户") | ||
| 88 | + @ApiImplicitParams({ | ||
| 89 | + @ApiImplicitParam(name = "username", required = true, value = "用户名", dataTypeClass = String.class), | ||
| 90 | + @ApiImplicitParam(name = "password", required = true, value = "密码(未md5加密的密码)", dataTypeClass = String.class), | ||
| 91 | + @ApiImplicitParam(name = "roleId", required = true, value = "角色ID", dataTypeClass = String.class), | ||
| 92 | + }) | ||
| 93 | + @PostMapping("/add") | ||
| 94 | + public ResponseEntity<WVPResult<Integer>> add(@RequestParam String username, | ||
| 95 | + @RequestParam String password, | ||
| 96 | + @RequestParam int roleId){ | ||
| 97 | + // 获取当前登录用户id | ||
| 98 | + int currenRoleId = SecurityUtils.getUserInfo().getRoleId(); | ||
| 99 | + if (currenRoleId != 0) { | ||
| 100 | + // 只用角色id为0才可以删除和添加用户 | ||
| 101 | + return new ResponseEntity<>(null, HttpStatus.FORBIDDEN); | ||
| 102 | + } | ||
| 103 | + User user = new User(); | ||
| 104 | + user.setUsername(username); | ||
| 105 | + user.setPassword(DigestUtils.md5DigestAsHex(password.getBytes())); | ||
| 106 | + user.setRoleId(roleId); | ||
| 107 | + user.setCreateTime(format.format(System.currentTimeMillis())); | ||
| 108 | + user.setUpdateTime(format.format(System.currentTimeMillis())); | ||
| 109 | + int addResult = userService.addUser(user); | ||
| 110 | + WVPResult<Integer> result = new WVPResult<>(); | ||
| 111 | + result.setCode(addResult > 0 ? 0 : -1); | ||
| 112 | + result.setMsg(addResult > 0 ? "success" : "fail"); | ||
| 113 | + result.setData(addResult); | ||
| 114 | + return new ResponseEntity<>(result, HttpStatus.OK); | ||
| 115 | + } | ||
| 116 | + | ||
| 117 | + @ApiOperation("删除用户") | ||
| 118 | + @ApiImplicitParams({ | ||
| 119 | + @ApiImplicitParam(name = "id", required = true, value = "用户Id", dataTypeClass = Integer.class), | ||
| 120 | + }) | ||
| 121 | + @DeleteMapping("/delete") | ||
| 122 | + public ResponseEntity<WVPResult<String>> delete(@RequestParam Integer id){ | ||
| 123 | + // 获取当前登录用户id | ||
| 124 | + int currenRoleId = SecurityUtils.getUserInfo().getRoleId(); | ||
| 125 | + if (currenRoleId != 0) { | ||
| 126 | + // 只用角色id为0才可以删除和添加用户 | ||
| 127 | + return new ResponseEntity<>(null, HttpStatus.FORBIDDEN); | ||
| 128 | + } | ||
| 129 | + int deleteResult = userService.deleteUser(id); | ||
| 130 | + WVPResult<String> result = new WVPResult<>(); | ||
| 131 | + result.setCode(deleteResult>0? 0 : -1); | ||
| 132 | + result.setMsg(deleteResult>0? "success" : "fail"); | ||
| 133 | + return new ResponseEntity<>(result, HttpStatus.OK); | ||
| 134 | + } | ||
| 135 | + | ||
| 136 | + @ApiOperation("查询用户") | ||
| 137 | + @ApiImplicitParams({}) | ||
| 138 | + @GetMapping("/all") | ||
| 139 | + public ResponseEntity<WVPResult<List<User>>> all(){ | ||
| 140 | + // 获取当前登录用户id | ||
| 141 | + List<User> allUsers = userService.getAllUsers(); | ||
| 142 | + WVPResult<List<User>> result = new WVPResult<>(); | ||
| 143 | + result.setCode(0); | ||
| 144 | + result.setMsg("success"); | ||
| 145 | + result.setData(allUsers); | ||
| 146 | + return new ResponseEntity<>(result, HttpStatus.OK); | ||
| 147 | + } | ||
| 75 | } | 148 | } |
src/main/resources/wvp.sqlite
No preview for this file type