用户管理页面开发
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
package com.zyplayer.doc.manage.web.manage;
|
||||
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.zyplayer.doc.core.json.DocResponseJson;
|
||||
import com.zyplayer.doc.core.json.ResponseJson;
|
||||
import com.zyplayer.doc.core.annotation.AuthMan;
|
||||
@@ -9,9 +12,11 @@ import com.zyplayer.doc.data.config.security.DocUserUtil;
|
||||
import com.zyplayer.doc.data.repository.manage.entity.AuthInfo;
|
||||
import com.zyplayer.doc.data.repository.manage.entity.UserAuth;
|
||||
import com.zyplayer.doc.data.repository.manage.entity.UserInfo;
|
||||
import com.zyplayer.doc.data.repository.manage.entity.WikiPage;
|
||||
import com.zyplayer.doc.data.service.manage.AuthInfoService;
|
||||
import com.zyplayer.doc.data.service.manage.UserAuthService;
|
||||
import com.zyplayer.doc.data.service.manage.UserInfoService;
|
||||
import com.zyplayer.doc.manage.web.manage.param.UserListParam;
|
||||
import com.zyplayer.doc.manage.web.manage.vo.AuthInfoVo;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.dozer.Mapper;
|
||||
@@ -21,6 +26,7 @@ import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -30,27 +36,63 @@ import java.util.stream.Collectors;
|
||||
@AuthMan("USER_MANAGE")
|
||||
public class UserInfoController {
|
||||
|
||||
@Autowired
|
||||
@Resource
|
||||
UserInfoService userInfoService;
|
||||
@Autowired
|
||||
@Resource
|
||||
AuthInfoService authInfoService;
|
||||
@Autowired
|
||||
@Resource
|
||||
UserAuthService userAuthService;
|
||||
@Autowired
|
||||
@Resource
|
||||
Mapper mapper;
|
||||
|
||||
@PostMapping("/list")
|
||||
public ResponseJson<Object> list(String userName) {
|
||||
public ResponseJson<Object> list(UserListParam param) {
|
||||
QueryWrapper<UserInfo> queryWrapper = new QueryWrapper<>();
|
||||
if (StringUtils.isNotBlank(userName)) {
|
||||
queryWrapper.like("user_name", userName);
|
||||
if (StringUtils.isNotBlank(param.getKeyword())) {
|
||||
queryWrapper.like(param.getType() == 1, "id", param.getKeyword());
|
||||
queryWrapper.like(param.getType() == 2, "user_no", param.getKeyword());
|
||||
queryWrapper.like(param.getType() == 3, "user_name", param.getKeyword());
|
||||
queryWrapper.like(param.getType() == 4, "phone", param.getKeyword());
|
||||
queryWrapper.like(param.getType() == 5, "email", param.getKeyword());
|
||||
}
|
||||
queryWrapper.eq("del_flag", 0);
|
||||
queryWrapper.ne("del_flag", 1);
|
||||
PageHelper.startPage(param.getPageNum(), param.getPageSize(), true);
|
||||
List<UserInfo> userInfoList = userInfoService.list(queryWrapper);
|
||||
if (userInfoList != null && userInfoList.size() > 0) {
|
||||
userInfoList.forEach(val -> val.setPassword(null));
|
||||
}
|
||||
return DocResponseJson.ok(userInfoList);
|
||||
PageInfo<UserInfo> pageInfo = new PageInfo<>(userInfoList);
|
||||
return DocResponseJson.ok(pageInfo);
|
||||
}
|
||||
|
||||
@PostMapping("/update")
|
||||
public ResponseJson<Object> update(UserInfo userInfo) {
|
||||
// 不允许修改密码
|
||||
userInfo.setPassword(null);
|
||||
if (userInfo.getId() != null && userInfo.getId() > 0) {
|
||||
userInfo.setUpdateTime(new Date());
|
||||
userInfoService.updateById(userInfo);
|
||||
} else {
|
||||
DocUserDetails currentUser = DocUserUtil.getCurrentUser();
|
||||
userInfo.setCreationTime(new Date());
|
||||
userInfo.setCreateUid(currentUser.getUserId());
|
||||
userInfoService.save(userInfo);
|
||||
}
|
||||
return DocResponseJson.ok();
|
||||
}
|
||||
|
||||
@PostMapping("/resetPassword")
|
||||
public ResponseJson<Object> resetPassword(UserInfo userInfo) {
|
||||
String password = RandomUtil.randomNumbers(6);
|
||||
UserInfo userInfoUp = new UserInfo();
|
||||
if (StringUtils.isNotBlank(password)) {
|
||||
String newPassword = DigestUtils.md5DigestAsHex(password.getBytes());
|
||||
userInfoUp.setPassword(newPassword);
|
||||
}
|
||||
userInfoUp.setId(userInfo.getId());
|
||||
userInfoUp.setUpdateTime(new Date());
|
||||
userInfoService.updateById(userInfoUp);
|
||||
return DocResponseJson.ok(password);
|
||||
}
|
||||
|
||||
@PostMapping("/auth/list")
|
||||
@@ -111,23 +153,4 @@ public class UserInfoController {
|
||||
userInfoService.updateById(userInfo);
|
||||
return DocResponseJson.ok();
|
||||
}
|
||||
|
||||
@PostMapping("/update")
|
||||
public ResponseJson<Object> update(UserInfo userInfo) {
|
||||
String password = userInfo.getPassword();
|
||||
if (StringUtils.isNotBlank(password)) {
|
||||
password = DigestUtils.md5DigestAsHex(password.getBytes());
|
||||
userInfo.setPassword(password);
|
||||
}
|
||||
if (userInfo.getId() != null && userInfo.getId() > 0) {
|
||||
userInfo.setUpdateTime(new Date());
|
||||
userInfoService.updateById(userInfo);
|
||||
} else {
|
||||
DocUserDetails currentUser = DocUserUtil.getCurrentUser();
|
||||
userInfo.setCreationTime(new Date());
|
||||
userInfo.setCreateUid(currentUser.getUserId());
|
||||
userInfoService.save(userInfo);
|
||||
}
|
||||
return DocResponseJson.ok();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.zyplayer.doc.manage.web.manage.param;
|
||||
|
||||
public class UserListParam {
|
||||
private Integer type;
|
||||
private String keyword;
|
||||
private Integer pageNum;
|
||||
private Integer pageSize;
|
||||
|
||||
public Integer getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(Integer type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getKeyword() {
|
||||
return keyword;
|
||||
}
|
||||
|
||||
public void setKeyword(String keyword) {
|
||||
this.keyword = keyword;
|
||||
}
|
||||
|
||||
public Integer getPageNum() {
|
||||
return pageNum;
|
||||
}
|
||||
|
||||
public void setPageNum(Integer pageNum) {
|
||||
this.pageNum = pageNum;
|
||||
}
|
||||
|
||||
public Integer getPageSize() {
|
||||
return pageSize;
|
||||
}
|
||||
|
||||
public void setPageSize(Integer pageSize) {
|
||||
this.pageSize = pageSize;
|
||||
}
|
||||
}
|
||||
@@ -33,7 +33,9 @@ CREATE TABLE `wiki_page_history` (
|
||||
KEY `idx_page_id` (`page_id`) USING BTREE COMMENT '页面ID索引'
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC;
|
||||
|
||||
|
||||
ALTER TABLE `user_info` ADD COLUMN `phone` varchar(20) NULL COMMENT '手机号';
|
||||
ALTER TABLE `user_info` ADD COLUMN `sex` tinyint NOT NULL DEFAULT 0 COMMENT '性别 0=女 1=男';
|
||||
ALTER TABLE `user_info` MODIFY COLUMN `del_flag` tinyint(4) NULL DEFAULT 0 COMMENT '是否删除 0=未删除 1=已删除 2=已停用';
|
||||
|
||||
|
||||
-- ------------------------全新的库:------------------------
|
||||
@@ -133,10 +135,12 @@ CREATE TABLE `user_info` (
|
||||
`user_name` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '用户名',
|
||||
`email` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '邮箱',
|
||||
`avatar` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '头像',
|
||||
`del_flag` tinyint(4) NULL DEFAULT 0 COMMENT '是否删除 0=未删除 1=已删除',
|
||||
`del_flag` tinyint(4) NULL DEFAULT 0 COMMENT '是否删除 0=未删除 1=已删除 2=已停用',
|
||||
`creation_time` datetime(0) NULL DEFAULT NULL COMMENT '创建时间',
|
||||
`create_uid` bigint(20) NULL DEFAULT NULL COMMENT '创建人用户ID',
|
||||
`update_time` datetime(0) NULL DEFAULT NULL COMMENT '更新时间',
|
||||
`phone` varchar(20) NULL COMMENT '手机号',
|
||||
`sex` tinyint NOT NULL DEFAULT 0 COMMENT '性别 0=女 1=男',
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
UNIQUE INDEX `idx_userNo`(`user_no`) USING BTREE COMMENT '登录用户名'
|
||||
) ENGINE = InnoDB AUTO_INCREMENT = 3 CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '用户信息表' ROW_FORMAT = Compact;
|
||||
|
||||
Reference in New Issue
Block a user