|
@@ -1,6 +1,7 @@
|
|
|
package com.usky.controller.sys;
|
|
|
|
|
|
import com.usky.constant.Constant;
|
|
|
+import com.usky.entity.ResponseBean;
|
|
|
import com.usky.entity.sys.SysUserDTO;
|
|
|
import com.usky.entity.sys.vo.SysUserVO;
|
|
|
import com.usky.exception.CustomException;
|
|
@@ -13,11 +14,20 @@ import io.swagger.annotations.ApiImplicitParam;
|
|
|
import io.swagger.annotations.ApiImplicitParams;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.apache.shiro.authz.annotation.Logical;
|
|
|
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.http.HttpStatus;
|
|
|
+
|
|
|
+import org.springframework.validation.annotation.Validated;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
+import javax.validation.Valid;
|
|
|
+import java.sql.Timestamp;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
import java.util.List;
|
|
|
+import java.util.Set;
|
|
|
|
|
|
/**
|
|
|
* @author laowo
|
|
@@ -33,6 +43,8 @@ public class UserController {
|
|
|
private UserService userService;
|
|
|
@Autowired
|
|
|
private RoleService roleService;
|
|
|
+ @Autowired
|
|
|
+ private RedisUtil redisUtil;
|
|
|
|
|
|
private String prefix = "sys/user";
|
|
|
|
|
@@ -55,39 +67,41 @@ public class UserController {
|
|
|
@ApiImplicitParam(name = "userName", value = "用户名", required = true, paramType = "query"),
|
|
|
@ApiImplicitParam(name = "remark", value = "备注", required = false, paramType = "query"),
|
|
|
})
|
|
|
+// @PostMapping("addUser")
|
|
|
+// public Result<?> addUser(
|
|
|
+// @RequestParam(value = "loginName", required = true) String loginName,
|
|
|
+// @RequestParam(value = "status", defaultValue = "0") String status,
|
|
|
+// @RequestParam(value = "phonenumber", required = true) String phonenumber,
|
|
|
+// @RequestParam(value = "deptId", required = true) Integer deptId,
|
|
|
+// @RequestParam(value = "password", required = true) String password,
|
|
|
+// @RequestParam(value = "userName", required = true) String userName,
|
|
|
+// @RequestParam(value = "roleIds", required = true) String roleIds,
|
|
|
+// @RequestParam(value = "remark", required = false) String remark
|
|
|
+// ) {
|
|
|
@PostMapping("addUser")
|
|
|
- public Result<?> addUser(
|
|
|
- @RequestParam(value = "loginName", required = true) String loginName,
|
|
|
- @RequestParam(value = "status", required = false) String status,
|
|
|
- @RequestParam(value = "phonenumber", required = true) String phonenumber,
|
|
|
- @RequestParam(value = "deptId", required = true) Integer deptId,
|
|
|
- @RequestParam(value = "password", required = true) String password,
|
|
|
- @RequestParam(value = "userName", required = true) String userName,
|
|
|
- @RequestParam(value = "roleIds", required = true) String roleIds,
|
|
|
- @RequestParam(value = "remark", required = false) String remark
|
|
|
- ) {
|
|
|
+ public Result<?> addUser(@Validated SysUserVO userVO) {
|
|
|
//登录名校验
|
|
|
- List<SysUserVO> sysUserVOList = userService.listAll(new SysUserVO(), null, loginName, null, null, null, null);
|
|
|
+ List<SysUserVO> sysUserVOList = userService.listAll(new SysUserVO(), null, userVO.getLoginName(), null, null, null, null);
|
|
|
if (ListUtil.isNotBlank(sysUserVOList)) {
|
|
|
return Result.error("登录名已存在");
|
|
|
}
|
|
|
- List<SysUserVO> phone = userService.listAll(new SysUserVO(), null, null, phonenumber, null, null, null);
|
|
|
+ List<SysUserVO> phone = userService.listAll(new SysUserVO(), null, null, userVO.getPhonenumber(), null, null, null);
|
|
|
if (ListUtil.isNotBlank(phone)) {
|
|
|
return Result.error("手机号已存在");
|
|
|
}
|
|
|
- if (password.length() > Constant.PASSWORD_MAX_LEN) {
|
|
|
+ if (userVO.getPassword().length() > Constant.PASSWORD_MAX_LEN) {
|
|
|
throw new CustomException("密码最多8位");
|
|
|
}
|
|
|
- String key = AesCipherUtil.enCrypto(loginName + password);
|
|
|
- SysUserVO user = new SysUserVO();
|
|
|
- user.setLoginName(loginName);
|
|
|
- user.setDeptId(deptId);
|
|
|
- user.setRemark(remark);
|
|
|
- user.setUserName(userName);
|
|
|
- user.setPassword(key);
|
|
|
- user.setStatus(status);
|
|
|
- user.setRoleIds(roleIds);
|
|
|
- userService.addUser(user);
|
|
|
+ String key = AesCipherUtil.enCrypto(userVO.getLoginName() + userVO.getPassword());
|
|
|
+// SysUserVO user = new SysUserVO();
|
|
|
+// user.setLoginName(loginName);
|
|
|
+// user.setDeptId(deptId);
|
|
|
+// user.setRemark(remark);
|
|
|
+// user.setUserName(userName);
|
|
|
+// user.setPassword(key);
|
|
|
+// user.setStatus(status);
|
|
|
+// user.setRoleIds(roleIds);
|
|
|
+ userService.addUser(userVO);
|
|
|
return Result.OK();
|
|
|
}
|
|
|
|
|
@@ -118,6 +132,7 @@ public class UserController {
|
|
|
SysUserVO sysUserVO = new SysUserVO();
|
|
|
return userService.list(sysUserVO, status, loginName, phonenumber, startTime, endTime, deptId, pageSize, pageNo);
|
|
|
}
|
|
|
+
|
|
|
@ApiOperation(value = "用户查询-全部 -可用于导出")
|
|
|
@PostMapping("listAll")
|
|
|
@ApiImplicitParams({
|
|
@@ -141,6 +156,7 @@ public class UserController {
|
|
|
List<SysUserVO> sysUserVOList = userService.listAll(new SysUserVO(), status, loginName, phonenumber, startTime, endTime, deptId);
|
|
|
return Result.OK(sysUserVOList);
|
|
|
}
|
|
|
+
|
|
|
@ApiOperation(value = "修改用户")
|
|
|
@RequiresPermissions("system:user:edit")
|
|
|
@PostMapping("/edit")
|
|
@@ -203,6 +219,39 @@ public class UserController {
|
|
|
userService.reSetPW(user);
|
|
|
return Result.OK();
|
|
|
}
|
|
|
-
|
|
|
+ @ApiOperation(value = "在线用户查看")
|
|
|
+ @GetMapping("/online")
|
|
|
+ @RequiresPermissions("online:user:view")
|
|
|
+ public Result<?> online() {
|
|
|
+ List<Object> userDtos = new ArrayList<Object>();
|
|
|
+ // 查询所有Redis键
|
|
|
+ Set<String> keys = redisUtil.keys(Constant.PREFIX_SHIRO_REFRESH_TOKEN);
|
|
|
+ for (String key : keys) {
|
|
|
+ if (redisUtil.hasKey(key)) {
|
|
|
+ // 根据:分割key,获取最后一个字符(帐号)
|
|
|
+ String[] strArray = key.split(":");
|
|
|
+ SysUserVO userDto = new SysUserVO();
|
|
|
+ String loginName = strArray[strArray.length - 1];
|
|
|
+ userDto = userService.queryuserByLoginName(loginName);
|
|
|
+ // 设置登录时间
|
|
|
+ userDto.setLoginDate(new Timestamp(Long.parseLong(redisUtil.get(key).toString())));
|
|
|
+ userDtos.add(userDto);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return Result.OK(userDtos);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 剔除在线用户
|
|
|
+ */
|
|
|
+ @DeleteMapping("/online/{id}")
|
|
|
+ @RequiresPermissions("online:user:view")
|
|
|
+ public Result<?> deleteOnline(@PathVariable("id") Integer id) {
|
|
|
+ SysUserDTO user = userService.queryUserById(id);
|
|
|
+ if (redisUtil.hasKey(Constant.PREFIX_SHIRO_REFRESH_TOKEN + user.getLoginName())) {
|
|
|
+ redisUtil.del(Constant.PREFIX_SHIRO_REFRESH_TOKEN + user.getLoginName());
|
|
|
+ return Result.OK();
|
|
|
+ }
|
|
|
+ throw new CustomException("剔除失败,LoginName不存在");
|
|
|
+ }
|
|
|
|
|
|
}
|