用户新增,删除.
This commit is contained in:
29
src/main/java/com/xuxd/kafka/console/beans/vo/SysUserVO.java
Normal file
29
src/main/java/com/xuxd/kafka/console/beans/vo/SysUserVO.java
Normal file
@@ -0,0 +1,29 @@
|
||||
package com.xuxd.kafka.console.beans.vo;
|
||||
|
||||
import com.xuxd.kafka.console.beans.dos.SysUserDO;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author: xuxd
|
||||
* @date: 2023/5/6 13:06
|
||||
**/
|
||||
@Data
|
||||
public class SysUserVO {
|
||||
|
||||
private Long id;
|
||||
|
||||
private String username;
|
||||
|
||||
private String password;
|
||||
|
||||
private String roleIds;
|
||||
|
||||
public static SysUserVO from(SysUserDO userDO) {
|
||||
SysUserVO userVO = new SysUserVO();
|
||||
userVO.setId(userDO.getId());
|
||||
userVO.setUsername(userDO.getUsername());
|
||||
userVO.setRoleIds(userDO.getRoleIds());
|
||||
userVO.setPassword(userDO.getPassword());
|
||||
return userVO;
|
||||
}
|
||||
}
|
||||
@@ -21,10 +21,10 @@ public class UserManageController {
|
||||
this.userManageService = userManageService;
|
||||
}
|
||||
|
||||
@ControllerLog("新增用户")
|
||||
@ControllerLog("新增/更新用户")
|
||||
@PostMapping("/user")
|
||||
public Object addUser(@RequestBody SysUserDTO userDTO) {
|
||||
return userManageService.addUser(userDTO);
|
||||
public Object addOrUpdateUser(@RequestBody SysUserDTO userDTO) {
|
||||
return userManageService.addOrUpdateUser(userDTO);
|
||||
}
|
||||
|
||||
@ControllerLog("新增/更新角色")
|
||||
@@ -55,8 +55,20 @@ public class UserManageController {
|
||||
return userManageService.selectPermission();
|
||||
}
|
||||
|
||||
@GetMapping("/user")
|
||||
public Object selectUser() {
|
||||
return userManageService.selectUser();
|
||||
}
|
||||
|
||||
@ControllerLog("删除角色")
|
||||
@DeleteMapping("/role")
|
||||
public Object deleteRole(@RequestParam Long id) {
|
||||
return userManageService.deleteRole(id);
|
||||
}
|
||||
|
||||
@ControllerLog("删除用户")
|
||||
@DeleteMapping("/user")
|
||||
public Object deleteUser(@RequestParam Long id) {
|
||||
return userManageService.deleteUser(id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,15 +20,19 @@ public interface UserManageService {
|
||||
|
||||
ResponseData addOrUdpateRole(SysRoleDTO roleDTO);
|
||||
|
||||
ResponseData addUser(SysUserDTO userDTO);
|
||||
ResponseData addOrUpdateUser(SysUserDTO userDTO);
|
||||
|
||||
ResponseData selectRole();
|
||||
|
||||
ResponseData selectPermission();
|
||||
|
||||
ResponseData selectUser();
|
||||
|
||||
ResponseData updateUser(SysUserDTO userDTO);
|
||||
|
||||
ResponseData updateRole(SysRoleDTO roleDTO);
|
||||
|
||||
ResponseData deleteRole(Long id);
|
||||
|
||||
ResponseData deleteUser(Long id);
|
||||
}
|
||||
|
||||
@@ -4,15 +4,18 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.xuxd.kafka.console.beans.ResponseData;
|
||||
import com.xuxd.kafka.console.beans.dos.SysPermissionDO;
|
||||
import com.xuxd.kafka.console.beans.dos.SysRoleDO;
|
||||
import com.xuxd.kafka.console.beans.dos.SysUserDO;
|
||||
import com.xuxd.kafka.console.beans.dto.SysPermissionDTO;
|
||||
import com.xuxd.kafka.console.beans.dto.SysRoleDTO;
|
||||
import com.xuxd.kafka.console.beans.dto.SysUserDTO;
|
||||
import com.xuxd.kafka.console.beans.vo.SysPermissionVO;
|
||||
import com.xuxd.kafka.console.beans.vo.SysRoleVO;
|
||||
import com.xuxd.kafka.console.beans.vo.SysUserVO;
|
||||
import com.xuxd.kafka.console.dao.SysPermissionMapper;
|
||||
import com.xuxd.kafka.console.dao.SysRoleMapper;
|
||||
import com.xuxd.kafka.console.dao.SysUserMapper;
|
||||
import com.xuxd.kafka.console.service.UserManageService;
|
||||
import com.xuxd.kafka.console.utils.UUIDStrUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.ObjectProvider;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -60,8 +63,26 @@ public class UserManageServiceImpl implements UserManageService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseData addUser(SysUserDTO userDTO) {
|
||||
userMapper.insert(userDTO.toDO());
|
||||
public ResponseData addOrUpdateUser(SysUserDTO userDTO) {
|
||||
if (userDTO.getId() == null) {
|
||||
SysUserDO userDO = userDTO.toDO();
|
||||
userDO.setSalt(UUIDStrUtil.random());
|
||||
userDO.setPassword(UUIDStrUtil.generate(userDTO.getPassword(), userDO.getSalt()));
|
||||
userMapper.insert(userDTO.toDO());
|
||||
} else {
|
||||
SysUserDO userDO = userMapper.selectById(userDTO.getId());
|
||||
if (userDO == null) {
|
||||
log.error("查不到用户: {}", userDTO.getId());
|
||||
return ResponseData.create().failed("Unknown User.");
|
||||
}
|
||||
// 判断是否更新密码
|
||||
String oldPass = UUIDStrUtil.generate(userDO.getPassword(), userDO.getSalt());
|
||||
if (!userDTO.getPassword().equals(oldPass)) {
|
||||
userDO.setSalt(UUIDStrUtil.random());
|
||||
userDO.setPassword(UUIDStrUtil.generate(userDTO.getPassword(), userDO.getSalt()));
|
||||
}
|
||||
userMapper.updateById(userDO);
|
||||
}
|
||||
return ResponseData.create().success();
|
||||
}
|
||||
|
||||
@@ -126,6 +147,13 @@ public class UserManageServiceImpl implements UserManageService {
|
||||
return ResponseData.create().data(vos).success();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseData selectUser() {
|
||||
QueryWrapper<SysUserDO> queryWrapper = new QueryWrapper<>();
|
||||
List<SysUserDO> userDOS = userMapper.selectList(queryWrapper);
|
||||
return ResponseData.create().data(userDOS.stream().map(SysUserVO::from).collect(Collectors.toList())).success();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseData updateUser(SysUserDTO userDTO) {
|
||||
userMapper.updateById(userDTO.toDO());
|
||||
@@ -143,4 +171,10 @@ public class UserManageServiceImpl implements UserManageService {
|
||||
roleMapper.deleteById(id);
|
||||
return ResponseData.create().success();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseData deleteUser(Long id) {
|
||||
userMapper.deleteById(id);
|
||||
return ResponseData.create().success();
|
||||
}
|
||||
}
|
||||
|
||||
22
src/main/java/com/xuxd/kafka/console/utils/UUIDStrUtil.java
Normal file
22
src/main/java/com/xuxd/kafka/console/utils/UUIDStrUtil.java
Normal file
@@ -0,0 +1,22 @@
|
||||
package com.xuxd.kafka.console.utils;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @author: xuxd
|
||||
* @date: 2023/5/6 13:30
|
||||
**/
|
||||
public class UUIDStrUtil {
|
||||
|
||||
public static String random() {
|
||||
return UUID.randomUUID().toString();
|
||||
}
|
||||
|
||||
public static String generate(String ... strs) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (String str : strs) {
|
||||
sb.append(str);
|
||||
}
|
||||
return UUID.nameUUIDFromBytes(sb.toString().getBytes()).toString();
|
||||
}
|
||||
}
|
||||
@@ -330,4 +330,16 @@ export const UserManageApi = {
|
||||
url: "/sys/user/manage/role",
|
||||
method: "delete",
|
||||
},
|
||||
getUsers: {
|
||||
url: "/sys/user/manage/user",
|
||||
method: "get",
|
||||
},
|
||||
addOrUpdateUser: {
|
||||
url: "/sys/user/manage/user",
|
||||
method: "post",
|
||||
},
|
||||
deleteUser: {
|
||||
url: "/sys/user/manage/user",
|
||||
method: "delete",
|
||||
},
|
||||
};
|
||||
137
ui/src/views/user/CreateUser.vue
Normal file
137
ui/src/views/user/CreateUser.vue
Normal file
@@ -0,0 +1,137 @@
|
||||
<template>
|
||||
<a-modal
|
||||
title="新增用户"
|
||||
:visible="show"
|
||||
:width="800"
|
||||
:mask="false"
|
||||
:destroyOnClose="true"
|
||||
:footer="null"
|
||||
:maskClosable="false"
|
||||
@cancel="handleCancel"
|
||||
>
|
||||
<div>
|
||||
<a-spin :spinning="loading">
|
||||
<a-form
|
||||
:form="form"
|
||||
:label-col="{ span: 5 }"
|
||||
:wrapper-col="{ span: 12 }"
|
||||
@submit="handleSubmit"
|
||||
>
|
||||
<a-form-item label="用户名">
|
||||
<a-input
|
||||
v-decorator="[
|
||||
'username',
|
||||
{ rules: [{ required: true, message: '输入用户名' }] },
|
||||
]"
|
||||
placeholder="输入用户名"
|
||||
/>
|
||||
</a-form-item>
|
||||
<a-form-item label="角色">
|
||||
<a-select
|
||||
show-search
|
||||
option-filter-prop="children"
|
||||
v-decorator="[
|
||||
'roleIds',
|
||||
{ rules: [{ required: true, message: '请选择一个角色!' }] },
|
||||
]"
|
||||
placeholder="请选择一个角色"
|
||||
>
|
||||
<a-select-option
|
||||
v-for="role in roles"
|
||||
:key="role.id"
|
||||
:value="role.id"
|
||||
>
|
||||
{{ role.roleName }}
|
||||
</a-select-option>
|
||||
</a-select>
|
||||
</a-form-item>
|
||||
<a-form-item :wrapper-col="{ span: 12, offset: 5 }">
|
||||
<a-button type="primary" html-type="submit"> 提交</a-button>
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
</a-spin>
|
||||
</div>
|
||||
</a-modal>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import request from "@/utils/request";
|
||||
import notification from "ant-design-vue/es/notification";
|
||||
import { UserManageApi } from "@/utils/api";
|
||||
|
||||
export default {
|
||||
name: "CreateUser",
|
||||
props: {
|
||||
visible: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
show: this.visible,
|
||||
data: [],
|
||||
loading: false,
|
||||
form: this.$form.createForm(this, { name: "coordinated" }),
|
||||
roles: [],
|
||||
};
|
||||
},
|
||||
watch: {
|
||||
visible(v) {
|
||||
this.show = v;
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
handleSubmit(e) {
|
||||
e.preventDefault();
|
||||
this.form.validateFields((err, values) => {
|
||||
if (!err) {
|
||||
this.loading = true;
|
||||
request({
|
||||
url: UserManageApi.addOrUpdateUser.url,
|
||||
method: UserManageApi.addOrUpdateUser.method,
|
||||
data: values,
|
||||
}).then((res) => {
|
||||
this.loading = false;
|
||||
if (res.code == 0) {
|
||||
this.$message.success(res.msg);
|
||||
this.$emit("closeCreateUserDialog", { refresh: true });
|
||||
} else {
|
||||
notification.error({
|
||||
message: "error",
|
||||
description: res.msg,
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
getRoles() {
|
||||
this.loading = true;
|
||||
request({
|
||||
url: UserManageApi.getRole.url,
|
||||
method: UserManageApi.getRole.method,
|
||||
}).then((res) => {
|
||||
this.loading = false;
|
||||
if (res.code == 0) {
|
||||
this.roles = res.data;
|
||||
} else {
|
||||
notification.error({
|
||||
message: "error",
|
||||
description: res.msg,
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
handleCancel() {
|
||||
this.data = [];
|
||||
this.$emit("closeCreateUserDialog", { refresh: false });
|
||||
},
|
||||
},
|
||||
created() {
|
||||
this.getRoles();
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped></style>
|
||||
@@ -24,7 +24,7 @@
|
||||
title="确定删除角色?"
|
||||
ok-text="确认"
|
||||
cancel-text="取消"
|
||||
@confirm="deleteRole(item.id)"
|
||||
@confirm="deleteRole(item)"
|
||||
>
|
||||
<a :style="{ display: 'flex' }">
|
||||
<a-icon type="delete" />
|
||||
@@ -35,7 +35,7 @@
|
||||
<span
|
||||
:style="{ margin: '25px', fontSize: '15px', display: 'block' }"
|
||||
>
|
||||
<a><a-icon type="plus" /> 新增角色</a>
|
||||
<a @click="addRole()"><a-icon type="plus" /> 新增角色</a>
|
||||
</span>
|
||||
</a-col>
|
||||
<a-col :md="20">
|
||||
@@ -212,16 +212,23 @@ export default {
|
||||
this.selectedPermissions.push(menu);
|
||||
});
|
||||
},
|
||||
deleteRole(id) {
|
||||
deleteRole(role) {
|
||||
if (role.adding) {
|
||||
this.roles.pop();
|
||||
return;
|
||||
}
|
||||
this.loading = true;
|
||||
request({
|
||||
url: UserManageApi.deleteRole.url + "?id=" + id,
|
||||
url: UserManageApi.deleteRole.url + "?id=" + role.id,
|
||||
method: UserManageApi.deleteRole.method,
|
||||
}).then((res) => {
|
||||
this.loading = false;
|
||||
if (res.code == 0) {
|
||||
this.$message.success(res.msg);
|
||||
this.getRoles();
|
||||
if (role.id == this.selectedRole.id) {
|
||||
this.selectedRole = {};
|
||||
}
|
||||
} else {
|
||||
notification.error({
|
||||
message: "error",
|
||||
@@ -230,6 +237,15 @@ export default {
|
||||
}
|
||||
});
|
||||
},
|
||||
addRole() {
|
||||
const role = {
|
||||
roleName: "角色名称",
|
||||
description: "角色描述",
|
||||
adding: true,
|
||||
};
|
||||
this.roles.push(role);
|
||||
this.selected(role);
|
||||
},
|
||||
onSave() {
|
||||
this.form.validateFields((err, values) => {
|
||||
if (!err) {
|
||||
|
||||
225
ui/src/views/user/User.vue
Normal file
225
ui/src/views/user/User.vue
Normal file
@@ -0,0 +1,225 @@
|
||||
<template>
|
||||
<div class="tab-content">
|
||||
<a-spin :spinning="loading">
|
||||
<div id="search-offset-form-advanced-search">
|
||||
<a-form
|
||||
class="ant-advanced-search-form"
|
||||
:form="form"
|
||||
@submit="handleSearch"
|
||||
>
|
||||
<a-row :gutter="24">
|
||||
<a-col :span="16">
|
||||
<a-form-item label="用户名">
|
||||
<a-input
|
||||
v-decorator="['username']"
|
||||
placeholder="请输入用户名!"
|
||||
@change="onUsernameChange"
|
||||
/>
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
<a-col :span="2" :style="{ textAlign: 'right' }">
|
||||
<a-form-item>
|
||||
<a-button
|
||||
type="primary"
|
||||
html-type="submit"
|
||||
@click="handleSearch()"
|
||||
>
|
||||
刷新</a-button
|
||||
>
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
</a-row>
|
||||
</a-form>
|
||||
</div>
|
||||
<div class="operation-row-button">
|
||||
<a-button type="primary" @click="openCreateUserDialog()"
|
||||
>新增用户</a-button
|
||||
>
|
||||
</div>
|
||||
<a-table
|
||||
:columns="columns"
|
||||
:data-source="filteredData"
|
||||
bordered
|
||||
row-key="id"
|
||||
>
|
||||
<div slot="operation" slot-scope="record" v-show="!record.internal">
|
||||
<a-popconfirm
|
||||
:title="'删除用户: ' + record.username + '?'"
|
||||
ok-text="确认"
|
||||
cancel-text="取消"
|
||||
@confirm="deleteUser(record)"
|
||||
>
|
||||
<a-button size="small" href="javascript:;" class="operation-btn"
|
||||
>删除
|
||||
</a-button>
|
||||
</a-popconfirm>
|
||||
<a-button size="small" href="javascript:;" class="operation-btn"
|
||||
>重置密码
|
||||
</a-button>
|
||||
</div>
|
||||
</a-table>
|
||||
<CreateUser
|
||||
@closeCreateUserDialog="closeCreateUserDialog"
|
||||
:visible="showCreateUserDialog"
|
||||
></CreateUser>
|
||||
</a-spin>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import request from "@/utils/request";
|
||||
|
||||
import notification from "ant-design-vue/lib/notification";
|
||||
import { UserManageApi } from "@/utils/api";
|
||||
import CreateUser from "@/views/user/CreateUser.vue";
|
||||
|
||||
export default {
|
||||
name: "User",
|
||||
components: { CreateUser },
|
||||
props: {
|
||||
topicList: {
|
||||
type: Array,
|
||||
},
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
loading: false,
|
||||
form: this.$form.createForm(this, { name: "user" }),
|
||||
data: [],
|
||||
filteredData: [],
|
||||
filterUsername: "",
|
||||
showCreateUserDialog: false,
|
||||
columns: [
|
||||
{
|
||||
title: "用户名",
|
||||
dataIndex: "username",
|
||||
key: "username",
|
||||
},
|
||||
{
|
||||
title: "角色",
|
||||
dataIndex: "roleIds",
|
||||
key: "roleIds",
|
||||
},
|
||||
{
|
||||
title: "操作",
|
||||
key: "operation",
|
||||
scopedSlots: { customRender: "operation" },
|
||||
},
|
||||
],
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
handleSearch() {
|
||||
this.form.validateFields((err) => {
|
||||
if (!err) {
|
||||
this.loading = true;
|
||||
request({
|
||||
url: UserManageApi.getUsers.url,
|
||||
method: UserManageApi.getUsers.method,
|
||||
}).then((res) => {
|
||||
this.loading = false;
|
||||
if (res.code == 0) {
|
||||
this.data = res.data;
|
||||
this.filter();
|
||||
} else {
|
||||
notification.error({
|
||||
message: "error",
|
||||
description: res.msg,
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
refresh() {
|
||||
this.handleSearch();
|
||||
},
|
||||
filter() {
|
||||
this.filteredData = this.data.filter(
|
||||
(e) => e.username.indexOf(this.filterUsername) != -1
|
||||
);
|
||||
},
|
||||
onUsernameChange(input) {
|
||||
this.filterUsername = input.target.value;
|
||||
this.filter();
|
||||
},
|
||||
openCreateUserDialog() {
|
||||
this.showCreateUserDialog = true;
|
||||
},
|
||||
closeCreateUserDialog(p) {
|
||||
this.showCreateUserDialog = false;
|
||||
if (p.refresh) {
|
||||
this.refresh();
|
||||
}
|
||||
},
|
||||
deleteUser(user) {
|
||||
this.loading = true;
|
||||
request({
|
||||
url: UserManageApi.deleteUser.url + "?id=" + user.id,
|
||||
method: UserManageApi.deleteUser.method,
|
||||
}).then((res) => {
|
||||
this.loading = false;
|
||||
if (res.code == 0) {
|
||||
this.refresh();
|
||||
} else {
|
||||
notification.error({
|
||||
message: "error",
|
||||
description: res.msg,
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
},
|
||||
created() {
|
||||
this.handleSearch();
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.tab-content {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.ant-advanced-search-form {
|
||||
padding: 24px;
|
||||
background: #fbfbfb;
|
||||
border: 1px solid #d9d9d9;
|
||||
border-radius: 6px;
|
||||
}
|
||||
|
||||
.ant-advanced-search-form .ant-form-item {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.ant-advanced-search-form input {
|
||||
width: 400px;
|
||||
}
|
||||
|
||||
.ant-advanced-search-form .ant-form-item-control-wrapper {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
#components-form-topic-advanced-search .ant-form {
|
||||
max-width: none;
|
||||
margin-bottom: 1%;
|
||||
}
|
||||
|
||||
#search-offset-form-advanced-search .search-result-list {
|
||||
margin-top: 16px;
|
||||
border: 1px dashed #e9e9e9;
|
||||
border-radius: 6px;
|
||||
background-color: #fafafa;
|
||||
min-height: 200px;
|
||||
text-align: center;
|
||||
padding-top: 80px;
|
||||
}
|
||||
|
||||
.operation-row-button {
|
||||
height: 4%;
|
||||
text-align: left;
|
||||
margin-bottom: 5px;
|
||||
margin-top: 5px;
|
||||
}
|
||||
</style>
|
||||
@@ -2,7 +2,9 @@
|
||||
<div class="content">
|
||||
<a-spin :spinning="loading">
|
||||
<a-tabs default-active-key="1" size="large" tabPosition="top">
|
||||
<a-tab-pane key="1" tab="用户列表"> </a-tab-pane>
|
||||
<a-tab-pane key="1" tab="用户列表">
|
||||
<User></User>
|
||||
</a-tab-pane>
|
||||
<a-tab-pane key="2" tab="角色列表">
|
||||
<Role></Role>
|
||||
</a-tab-pane>
|
||||
@@ -18,9 +20,10 @@
|
||||
<script>
|
||||
import Permission from "@/views/user/Permission.vue";
|
||||
import Role from "@/views/user/Role.vue";
|
||||
import User from "@/views/user/User.vue";
|
||||
export default {
|
||||
name: "UserManage",
|
||||
components: { Permission, Role },
|
||||
components: { Permission, Role, User },
|
||||
data() {
|
||||
return {
|
||||
loading: false,
|
||||
|
||||
Reference in New Issue
Block a user