|
@@ -1,19 +1,17 @@
|
|
package com.genersoft.iot.vmp.vmanager.user;
|
|
package com.genersoft.iot.vmp.vmanager.user;
|
|
|
|
|
|
import cn.dev33.satoken.annotation.SaIgnore;
|
|
import cn.dev33.satoken.annotation.SaIgnore;
|
|
-import cn.dev33.satoken.stp.StpUtil;
|
|
|
|
import com.genersoft.iot.vmp.conf.exception.ControllerException;
|
|
import com.genersoft.iot.vmp.conf.exception.ControllerException;
|
|
-import com.genersoft.iot.vmp.conf.security.JwtUtils;
|
|
|
|
import com.genersoft.iot.vmp.conf.security.SecurityUtils;
|
|
import com.genersoft.iot.vmp.conf.security.SecurityUtils;
|
|
import com.genersoft.iot.vmp.conf.security.dto.LoginUser;
|
|
import com.genersoft.iot.vmp.conf.security.dto.LoginUser;
|
|
import com.genersoft.iot.vmp.conf.security.saToken.SaAdminCheckRole;
|
|
import com.genersoft.iot.vmp.conf.security.saToken.SaAdminCheckRole;
|
|
-import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.notify.cmd.KeepaliveNotifyMessageHandler;
|
|
|
|
|
|
+import com.genersoft.iot.vmp.service.IAdminService;
|
|
import com.genersoft.iot.vmp.service.IRoleService;
|
|
import com.genersoft.iot.vmp.service.IRoleService;
|
|
-import com.genersoft.iot.vmp.service.IUserService;
|
|
|
|
|
|
+import com.genersoft.iot.vmp.storager.dao.dto.AdminAccount;
|
|
import com.genersoft.iot.vmp.storager.dao.dto.Role;
|
|
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.utils.DateUtil;
|
|
import com.genersoft.iot.vmp.utils.StpAdminUtil;
|
|
import com.genersoft.iot.vmp.utils.StpAdminUtil;
|
|
|
|
+import com.genersoft.iot.vmp.utils.StpUserUtil;
|
|
import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
|
|
import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
|
|
import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
|
|
import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
|
|
import com.github.pagehelper.PageInfo;
|
|
import com.github.pagehelper.PageInfo;
|
|
@@ -44,7 +42,7 @@ public class UserController {
|
|
private AuthenticationManager authenticationManager;
|
|
private AuthenticationManager authenticationManager;
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
- private IUserService userService;
|
|
|
|
|
|
+ private IAdminService userService;
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
private IRoleService roleService;
|
|
private IRoleService roleService;
|
|
@@ -59,11 +57,11 @@ public class UserController {
|
|
@Parameter(name = "password", description = "密码(32位md5加密)", required = true)
|
|
@Parameter(name = "password", description = "密码(32位md5加密)", required = true)
|
|
public WVPResult login(HttpServletRequest request, HttpServletResponse response, @RequestParam String username, @RequestParam String password) {
|
|
public WVPResult login(HttpServletRequest request, HttpServletResponse response, @RequestParam String username, @RequestParam String password) {
|
|
|
|
|
|
- User user = userService.getUser(username, password);
|
|
|
|
- if (user == null) {
|
|
|
|
|
|
+ AdminAccount adminAccount = userService.getUser(username, password);
|
|
|
|
+ if (adminAccount == null) {
|
|
return WVPResult.fail(ErrorCode.ERROR100);
|
|
return WVPResult.fail(ErrorCode.ERROR100);
|
|
}
|
|
}
|
|
- StpAdminUtil.login(user.getId());
|
|
|
|
|
|
+ StpAdminUtil.login(adminAccount.getId());
|
|
return WVPResult.success();
|
|
return WVPResult.success();
|
|
}
|
|
}
|
|
|
|
|
|
@@ -108,41 +106,32 @@ public class UserController {
|
|
@Parameter(name = "roleId", description = "角色ID", required = true)
|
|
@Parameter(name = "roleId", description = "角色ID", required = true)
|
|
public void add(@RequestParam String username,
|
|
public void add(@RequestParam String username,
|
|
@RequestParam String password,
|
|
@RequestParam String password,
|
|
- @RequestParam Integer roleId){
|
|
|
|
- try {
|
|
|
|
- if (ObjectUtils.isEmpty(username) || ObjectUtils.isEmpty(password) || roleId == null) {
|
|
|
|
- throw new ControllerException(ErrorCode.ERROR400.getCode(), "参数不可为空");
|
|
|
|
- }
|
|
|
|
- LoginUser loginUser = SecurityUtils.getUserInfo();
|
|
|
|
- String _username = loginUser.getUsername();
|
|
|
|
- String _passwordMd5 = loginUser.getPassword();
|
|
|
|
- LoginUser _user = SecurityUtils.login(_username, _passwordMd5, authenticationManager);
|
|
|
|
- // 获取当前登录用户id
|
|
|
|
- int currenRoleId = _user.getRole().getId();
|
|
|
|
- logger.info("[用户管理] 添加用户,当前用户角色id:" + currenRoleId);
|
|
|
|
- if (currenRoleId != 1) {
|
|
|
|
- // 只用角色id为1才可以删除和添加用户
|
|
|
|
- throw new ControllerException(ErrorCode.ERROR400.getCode(), "用户无权限");
|
|
|
|
- }
|
|
|
|
- User user = new User();
|
|
|
|
- user.setUsername(username);
|
|
|
|
- user.setPassword(DigestUtils.md5DigestAsHex(password.getBytes()));
|
|
|
|
- //新增用户的pushKey的生成规则为md5(时间戳+用户名)
|
|
|
|
- user.setPushKey(DigestUtils.md5DigestAsHex((System.currentTimeMillis() + password).getBytes()));
|
|
|
|
- Role role = roleService.getRoleById(roleId);
|
|
|
|
|
|
+ @RequestParam Integer roleId) {
|
|
|
|
|
|
- if (role == null) {
|
|
|
|
- throw new ControllerException(ErrorCode.ERROR400.getCode(), "角色不存在");
|
|
|
|
- }
|
|
|
|
- user.setRole(role);
|
|
|
|
- user.setCreateTime(DateUtil.getNow());
|
|
|
|
- user.setUpdateTime(DateUtil.getNow());
|
|
|
|
- int addResult = userService.addUser(user);
|
|
|
|
- if (addResult <= 0) {
|
|
|
|
- throw new ControllerException(ErrorCode.ERROR100);
|
|
|
|
- }
|
|
|
|
- }catch (AuthenticationException e) {
|
|
|
|
- throw new ControllerException(ErrorCode.ERROR100.getCode(), e.getMessage());
|
|
|
|
|
|
+ if (ObjectUtils.isEmpty(username) || ObjectUtils.isEmpty(password) || roleId == null) {
|
|
|
|
+ throw new ControllerException(ErrorCode.ERROR400.getCode(), "参数不可为空");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 获取当前登录用户id
|
|
|
|
+ String accountId = StpUserUtil.getLoginId().toString();
|
|
|
|
+ logger.info("[用户管理] 添加用户,当前用户id:" + accountId);
|
|
|
|
+
|
|
|
|
+ AdminAccount adminAccount = new AdminAccount();
|
|
|
|
+ adminAccount.setUsername(username);
|
|
|
|
+ adminAccount.setPassword(DigestUtils.md5DigestAsHex(password.getBytes()));
|
|
|
|
+ //新增用户的pushKey的生成规则为md5(时间戳+用户名)
|
|
|
|
+ adminAccount.setPushKey(DigestUtils.md5DigestAsHex((System.currentTimeMillis() + password).getBytes()));
|
|
|
|
+ Role role = roleService.getRoleById(roleId);
|
|
|
|
+
|
|
|
|
+ if (role == null) {
|
|
|
|
+ throw new ControllerException(ErrorCode.ERROR400.getCode(), "角色不存在");
|
|
|
|
+ }
|
|
|
|
+ adminAccount.setRole(role);
|
|
|
|
+ adminAccount.setCreateTime(DateUtil.getNow());
|
|
|
|
+ adminAccount.setUpdateTime(DateUtil.getNow());
|
|
|
|
+ int addResult = userService.addUser(adminAccount);
|
|
|
|
+ if (addResult <= 0) {
|
|
|
|
+ throw new ControllerException(ErrorCode.ERROR100);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -172,18 +161,18 @@ public class UserController {
|
|
|
|
|
|
@GetMapping("/all")
|
|
@GetMapping("/all")
|
|
@Operation(summary = "查询用户")
|
|
@Operation(summary = "查询用户")
|
|
- public List<User> all(){
|
|
|
|
|
|
+ public List<AdminAccount> all() {
|
|
// 获取当前登录用户id
|
|
// 获取当前登录用户id
|
|
return userService.getAllUsers();
|
|
return userService.getAllUsers();
|
|
}
|
|
}
|
|
|
|
|
|
public void register(String username, String password) {
|
|
public void register(String username, String password) {
|
|
- User user = new User();
|
|
|
|
- user.setUsername(username);
|
|
|
|
- user.setPassword(DigestUtils.md5DigestAsHex(password.getBytes()));
|
|
|
|
- user.setCreateTime(DateUtil.getNow());
|
|
|
|
- user.setUpdateTime(DateUtil.getNow());
|
|
|
|
- int addResult = userService.addUser(user);
|
|
|
|
|
|
+ AdminAccount adminAccount = new AdminAccount();
|
|
|
|
+ adminAccount.setUsername(username);
|
|
|
|
+ adminAccount.setPassword(DigestUtils.md5DigestAsHex(password.getBytes()));
|
|
|
|
+ adminAccount.setCreateTime(DateUtil.getNow());
|
|
|
|
+ adminAccount.setUpdateTime(DateUtil.getNow());
|
|
|
|
+ int addResult = userService.addUser(adminAccount);
|
|
if (addResult <= 0) {
|
|
if (addResult <= 0) {
|
|
throw new ControllerException(ErrorCode.ERROR100);
|
|
throw new ControllerException(ErrorCode.ERROR100);
|
|
}
|
|
}
|
|
@@ -200,34 +189,22 @@ public class UserController {
|
|
@Operation(summary = "分页查询用户")
|
|
@Operation(summary = "分页查询用户")
|
|
@Parameter(name = "page", description = "当前页", required = true)
|
|
@Parameter(name = "page", description = "当前页", required = true)
|
|
@Parameter(name = "count", description = "每页查询数量", required = true)
|
|
@Parameter(name = "count", description = "每页查询数量", required = true)
|
|
- public PageInfo<User> users(int page, int count) {
|
|
|
|
|
|
+ public PageInfo<AdminAccount> users(int page, int count) {
|
|
return userService.getUsers(page, count);
|
|
return userService.getUsers(page, count);
|
|
}
|
|
}
|
|
|
|
|
|
@RequestMapping("/changePushKey")
|
|
@RequestMapping("/changePushKey")
|
|
@Operation(summary = "修改pushkey")
|
|
@Operation(summary = "修改pushkey")
|
|
- @Parameter(name = "userId", description = "用户Id", required = true)
|
|
|
|
@Parameter(name = "pushKey", description = "新的pushKey", required = true)
|
|
@Parameter(name = "pushKey", description = "新的pushKey", required = true)
|
|
- public void changePushKey(@RequestParam Integer userId,@RequestParam String pushKey) {
|
|
|
|
- try{
|
|
|
|
- // 获取当前登录用户id
|
|
|
|
- LoginUser loginUser = SecurityUtils.getUserInfo();
|
|
|
|
- String _username = loginUser.getUsername();
|
|
|
|
- String _passwordMd5 = loginUser.getPassword();
|
|
|
|
- LoginUser _user = SecurityUtils.login(_username, _passwordMd5, authenticationManager);
|
|
|
|
- int currenRoleId = _user.getRole().getId();
|
|
|
|
- WVPResult<String> result = new WVPResult<>();
|
|
|
|
- if (currenRoleId != 1) {
|
|
|
|
- // 只用角色id为0才可以删除和添加用户
|
|
|
|
- throw new ControllerException(ErrorCode.ERROR400.getCode(), "用户无权限");
|
|
|
|
- }
|
|
|
|
- int resetPushKeyResult = userService.changePushKey(userId,pushKey);
|
|
|
|
- if (resetPushKeyResult <= 0) {
|
|
|
|
- throw new ControllerException(ErrorCode.ERROR100);
|
|
|
|
- }
|
|
|
|
- } catch (AuthenticationException e) {
|
|
|
|
- throw new ControllerException(ErrorCode.ERROR100.getCode(), e.getMessage());
|
|
|
|
|
|
+ public WVPResult changePushKey(@RequestParam String pushKey) {
|
|
|
|
+ // 获取当前登录用户id
|
|
|
|
+ String accountId = StpUserUtil.getLoginId().toString();
|
|
|
|
+ logger.info("[用户管理] 修改pushKey,当前用户id:" + accountId);
|
|
|
|
+ int resetPushKeyResult = userService.changePushKey(Integer.parseInt(accountId), pushKey);
|
|
|
|
+ if (resetPushKeyResult <= 0) {
|
|
|
|
+ return WVPResult.fail(ErrorCode.ERROR100);
|
|
}
|
|
}
|
|
|
|
+ return WVPResult.success();
|
|
}
|
|
}
|
|
|
|
|
|
@PostMapping("/changePasswordForAdmin")
|
|
@PostMapping("/changePasswordForAdmin")
|