提交 60356d13 编写于 作者: Q qinxiaodong@pannk.com

更新项目

上级 6f9949c4
......@@ -48,6 +48,14 @@ export function treeDataTranslate (data, id = 'id', pid = 'parentId') {
return res
}
/**
* 数组去重
* @param {*} arr 数组
*/
export function unique (arr) {
return Array.from(new Set(arr))
}
/**
* 清除登录信息
*/
......
......@@ -90,7 +90,7 @@
// 获取当前管理员信息
getUserInfo () {
this.$http({
url: this.$http.adornUrl('/sys/user/info'),
url: this.$http.adornUrl('/sys/user/currentUser'),
method: 'get',
params: this.$http.adornParams()
}).then(({data}) => {
......
......@@ -2,179 +2,246 @@
<el-dialog
:title="!dataForm.id ? '新增' : '修改'"
:close-on-click-modal="false"
:visible.sync="visible">
<el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
<el-form-item label="用户名" prop="userName">
<el-input v-model="dataForm.userName" placeholder="登录帐号"></el-input>
</el-form-item>
<el-form-item label="密码" prop="password" :class="{ 'is-required': !dataForm.id }">
<el-input v-model="dataForm.password" type="password" placeholder="密码"></el-input>
</el-form-item>
<el-form-item label="确认密码" prop="comfirmPassword" :class="{ 'is-required': !dataForm.id }">
<el-input v-model="dataForm.comfirmPassword" type="password" placeholder="确认密码"></el-input>
</el-form-item>
<el-form-item label="邮箱" prop="email">
<el-input v-model="dataForm.email" placeholder="邮箱"></el-input>
</el-form-item>
:visible.sync="visible"
>
<el-form
:model="dataForm"
:rules="dataRule"
ref="dataForm"
@keyup.enter.native="dataFormSubmit()"
label-width="80px"
>
<el-row>
<el-col :span="12">
<el-form-item label="用户名" prop="userName">
<el-input
v-model="dataForm.userName"
placeholder="登录帐号"
ref="userName"
></el-input>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="头像" prop="avatar">
<el-upload
class="upload-demo"
ref="upload"
action=""
:on-change="getFiles"
multiple
:data="addFilesDate"
:file-list="fileList"
:auto-upload="false">
<el-button size="small" type="primary">选择文件</el-button>
</el-upload>
</el-form-item>
</el-col>
</el-row>
<el-row>
<el-col :span="12">
<el-form-item label="姓名" prop="fullName">
<el-input v-model="dataForm.fullName" placeholder="姓名"></el-input>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="编号" prop="code">
<el-input v-model="dataForm.code" placeholder="编号"></el-input>
</el-form-item>
</el-col>
</el-row>
<el-row>
<el-col :span="12">
<el-form-item label="邮箱" prop="email">
<el-input v-model="dataForm.email" placeholder="邮箱"></el-input>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="手机号" prop="mobile">
<el-input v-model="dataForm.mobile" placeholder="手机号"></el-input>
</el-form-item>
<el-form-item label="角色" size="mini" prop="roleIdList">
<el-checkbox-group v-model="dataForm.roleIdList">
<el-checkbox v-for="role in roleList" :key="role.roleId" :label="role.roleId">{{ role.roleName }}</el-checkbox>
</el-checkbox-group>
</el-form-item>
<el-form-item label="状态" size="mini" prop="status">
<el-radio-group v-model="dataForm.status">
<el-radio :label="0">禁用</el-radio>
<el-radio :label="1">正常</el-radio>
</el-radio-group>
</el-form-item>
</el-col>
</el-row>
<el-row>
<el-col :span="12">
<el-form-item label="状态" size="mini" prop="status">
<el-radio-group v-model="dataForm.status">
<el-radio :label="1">禁用</el-radio>
<el-radio :label="0">正常</el-radio>
</el-radio-group>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="性别" size="mini" prop="gender">
<el-radio-group v-model="dataForm.gender">
<el-radio :label="0"></el-radio>
<el-radio :label="1"></el-radio>
</el-radio-group>
</el-form-item>
</el-col>
</el-row>
<el-row>
<el-col :span="24">
<el-form-item label="角色" size="mini" prop="roleIdList">
<el-checkbox-group v-model="dataForm.roleIdList">
<el-checkbox
v-for="role in roleList"
:key="role.id"
:label="role.id"
>{{ role.name }}
</el-checkbox>
</el-checkbox-group>
</el-form-item>
</el-col>
</el-row>
<el-row>
<el-col :span="24">
<el-form-item label="备注" prop="remark">
<el-input type="textarea" :rows="4" v-model="dataForm.remark"></el-input>
</el-form-item>
</el-col>
</el-row>
</el-form>
<span slot="footer" class="dialog-footer">
<el-button @click="visible = false">取消</el-button>
<el-button @click="cancel()">取消</el-button>
<el-button type="primary" @click="dataFormSubmit()">确定</el-button>
</span>
</el-dialog>
</template>
<script>
import { isEmail, isMobile } from '@/utils/validate'
export default {
data () {
var validatePassword = (rule, value, callback) => {
if (!this.dataForm.id && !/\S/.test(value)) {
callback(new Error('密码不能为空'))
} else {
callback()
}
}
var validateComfirmPassword = (rule, value, callback) => {
if (!this.dataForm.id && !/\S/.test(value)) {
callback(new Error('确认密码不能为空'))
} else if (this.dataForm.password !== value) {
callback(new Error('确认密码与密码输入不一致'))
} else {
callback()
}
import { isEmail, isMobile } from '@/utils/validate'
import { unique } from '@/utils/index'
export default {
data () {
var validateEmail = (rule, value, callback) => {
if (!isEmail(value)) {
callback(new Error('邮箱格式错误'))
} else {
callback()
}
var validateEmail = (rule, value, callback) => {
if (!isEmail(value)) {
callback(new Error('邮箱格式错误'))
} else {
callback()
}
}
var validateMobile = (rule, value, callback) => {
if (!isMobile(value)) {
callback(new Error('手机号格式错误'))
} else {
callback()
}
}
var validateMobile = (rule, value, callback) => {
if (!isMobile(value)) {
callback(new Error('手机号格式错误'))
} else {
callback()
}
return {
visible: false,
roleList: [],
dataForm: {
id: 0,
userName: '',
password: '',
comfirmPassword: '',
salt: '',
email: '',
mobile: '',
roleIdList: [],
status: 1
},
dataRule: {
userName: [
{ required: true, message: '用户名不能为空', trigger: 'blur' }
],
password: [
{ validator: validatePassword, trigger: 'blur' }
],
comfirmPassword: [
{ validator: validateComfirmPassword, trigger: 'blur' }
],
email: [
{ required: true, message: '邮箱不能为空', trigger: 'blur' },
{ validator: validateEmail, trigger: 'blur' }
],
mobile: [
{ required: true, message: '手机号不能为空', trigger: 'blur' },
{ validator: validateMobile, trigger: 'blur' }
]
}
}
return {
visible: false,
roleList: [],
dataForm: {
id: 0,
code: '',
userName: '',
fullName: '',
email: '',
mobile: '',
roleIdList: [],
status: 0,
gender: 0,
remark: ''
},
dataRule: {
userName: [
{ required: true, message: '用户名不能为空', trigger: 'blur' }
],
code: [
{ required: true, message: '用户编号不能为空', trigger: 'blur' }
],
email: [
{ required: true, message: '邮箱不能为空', trigger: 'blur' },
{ validator: validateEmail, trigger: 'blur' }
],
mobile: [
{ required: true, message: '手机号不能为空', trigger: 'blur' },
{ validator: validateMobile, trigger: 'blur' }
]
}
},
methods: {
init (id) {
this.dataForm.id = id || 0
this.$http({
url: this.$http.adornUrl('/sys/role/select'),
method: 'get',
params: this.$http.adornParams()
}).then(({data}) => {
this.roleList = data && data.code === 0 ? data.list : []
}).then(() => {
}
},
methods: {
init (id) {
this.dataForm.id = id || 0
this.$http({
url: this.$http.adornUrl('/sys/role/list'),
method: 'get',
params: this.$http.adornParams()
})
.then(({ data }) => {
this.roleList = data && data.code === 0 ? data.data : []
})
.then(() => {
this.visible = true
this.$nextTick(() => {
this.$refs['userName'].focus()
this.$refs['dataForm'].resetFields()
})
}).then(() => {
})
.then(() => {
if (this.dataForm.id) {
this.$http({
url: this.$http.adornUrl(`/sys/user/info/${this.dataForm.id}`),
method: 'get',
params: this.$http.adornParams()
}).then(({data}) => {
}).then(({ data }) => {
if (data && data.code === 0) {
this.dataForm.userName = data.user.username
this.dataForm.salt = data.user.salt
this.dataForm.email = data.user.email
this.dataForm.mobile = data.user.mobile
this.dataForm.roleIdList = data.user.roleIdList
this.dataForm.status = data.user.status
let user = data.data
this.dataForm.userName = user.userName
this.dataForm.fullName = user.fullName
this.dataForm.code = user.code
this.dataForm.gender = user.gender
this.dataForm.email = user.email
this.dataForm.mobile = user.mobile
this.dataForm.roleIdList = user.roleIdList
this.dataForm.status = user.status
}
})
}
})
},
// 表单提交
dataFormSubmit () {
this.$refs['dataForm'].validate((valid) => {
if (valid) {
this.$http({
url: this.$http.adornUrl(`/sys/user/${!this.dataForm.id ? 'save' : 'update'}`),
method: 'post',
data: this.$http.adornData({
'userId': this.dataForm.id || undefined,
'username': this.dataForm.userName,
'password': this.dataForm.password,
'salt': this.dataForm.salt,
'email': this.dataForm.email,
'mobile': this.dataForm.mobile,
'status': this.dataForm.status,
'roleIdList': this.dataForm.roleIdList
})
}).then(({data}) => {
if (data && data.code === 0) {
this.$message({
message: '操作成功',
type: 'success',
duration: 1500,
onClose: () => {
this.visible = false
this.$emit('refreshDataList')
}
})
} else {
this.$message.error(data.msg)
}
},
cancel () {
this.visible = false
this.$emit('refreshDataList')
},
// 表单提交
dataFormSubmit () {
this.$refs['dataForm'].validate((valid) => {
if (valid) {
this.$http({
url: this.$http.adornUrl(
`/sys/user/${!this.dataForm.id ? 'save' : 'update'}`
),
method: !this.dataForm.id ? 'post' : 'put',
data: this.$http.adornData({
id: this.dataForm.id || undefined,
userName: this.dataForm.userName,
fullName: this.dataForm.fullName,
code: this.dataForm.code,
email: this.dataForm.email,
mobile: this.dataForm.mobile,
status: this.dataForm.status,
gender: this.dataForm.gender,
roleIdList: unique(this.dataForm.roleIdList)
})
}
})
}
}).then(({ data }) => {
if (data && data.code === 0) {
this.$message({
message: '操作成功',
type: 'success',
duration: 1500,
onClose: () => {
this.visible = false
this.$emit('refreshDataList')
}
})
} else {
this.$message.error(data.msg)
}
})
}
})
}
}
}
</script>
......@@ -2,7 +2,7 @@
<div class="mod-user">
<el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
<el-form-item>
<el-input v-model="dataForm.userName" placeholder="用户名" clearable></el-input>
<el-input v-model="dataForm.userName" ref="userName" placeholder="用户名" clearable></el-input>
</el-form-item>
<el-form-item>
<el-button @click="getDataList()">查询</el-button>
......@@ -21,19 +21,27 @@
header-align="center"
align="center"
width="50">
</el-table-column>
<el-table-column
prop="userName"
header-align="center"
align="center"
width="150"
label="用户名">
</el-table-column>
<el-table-column
prop="userId"
prop="code"
header-align="center"
align="center"
width="80"
label="ID">
width="150"
label="编码">
</el-table-column>
<el-table-column
prop="username"
prop="fullName"
header-align="center"
align="center"
label="用户名">
width="150"
label="姓名">
</el-table-column>
<el-table-column
prop="email"
......@@ -45,20 +53,22 @@
prop="mobile"
header-align="center"
align="center"
width="120"
label="手机号">
</el-table-column>
<el-table-column
prop="status"
header-align="center"
align="center"
width="80"
label="状态">
<template slot-scope="scope">
<el-tag v-if="scope.row.status === 0" size="small" type="danger">禁用</el-tag>
<el-tag v-if="scope.row.status === 1" size="small" type="danger">禁用</el-tag>
<el-tag v-else size="small">正常</el-tag>
</template>
</el-table-column>
<el-table-column
prop="createTime"
prop="createDate"
header-align="center"
align="center"
width="180"
......@@ -71,8 +81,8 @@
width="150"
label="操作">
<template slot-scope="scope">
<el-button v-if="isAuth('sys:user:update')" type="text" size="small" @click="addOrUpdateHandle(scope.row.userId)">修改</el-button>
<el-button v-if="isAuth('sys:user:delete')" type="text" size="small" @click="deleteHandle(scope.row.userId)">删除</el-button>
<el-button v-if="isAuth('sys:user:update')" type="text" size="small" @click="addOrUpdateHandle(scope.row.id)">修改</el-button>
<el-button v-if="isAuth('sys:user:delete')" type="text" size="small" @click="deleteHandle(scope.row.id)">删除</el-button>
</template>
</el-table-column>
</el-table>
......@@ -113,6 +123,11 @@
activated () {
this.getDataList()
},
mounted () {
this.$nextTick(() => {
this.$refs.userName.focus()
})
},
methods: {
// 获取数据列表
getDataList () {
......@@ -123,7 +138,7 @@
params: this.$http.adornParams({
'page': this.pageIndex,
'limit': this.pageSize,
'username': this.dataForm.userName
'userName': this.dataForm.userName
})
}).then(({data}) => {
if (data && data.code === 0) {
......@@ -134,6 +149,9 @@
this.totalPage = 0
}
this.dataListLoading = false
this.$nextTick(() => {
this.$refs.userName.focus()
})
})
},
// 每页数
......
......@@ -20,8 +20,11 @@ public class Constant {
public static final String PAGE = "page";
public static final String LIMIT = "limit";
public static final String ORDER_FIELD = "sidx";
public static final String ORDER ="order";
public static final String ORDER = "order";
public static final String ASC = "ASC";
public static final String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";
public static final String SIMPLE_DATE_FORMAT = "yyyy-MM-dd";
public static final String INIT_PASSWORD = "123456";
/**
* 菜单类型
......
package com.pannk.mms.common.config;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.alibaba.fastjson.support.config.FastJsonConfig;
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
import com.pannk.mms.common.base.Constant;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
import java.util.ArrayList;
import java.util.List;
/**
* Created by wolf on 20-11-23.
*/
@Configuration
public class FastJsonMessageConverterConfig extends WebMvcConfigurationSupport {
@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
for (int i = 0; i < converters.size(); i++) {
HttpMessageConverter<?> converter = converters.get(i);
if (converter instanceof MappingJackson2HttpMessageConverter) {
converters.remove(converter);
break;
}
}
FastJsonHttpMessageConverter fastJsonHttpMessageConverter = new FastJsonHttpMessageConverter();
FastJsonConfig fastJsonConfig = new FastJsonConfig();
fastJsonConfig.setSerializerFeatures(SerializerFeature.WriteMapNullValue, // 是否输出值为null的字段,默认为false,我们将它打开
SerializerFeature.WriteNullListAsEmpty, // 将Collection类型字段的字段空值输出为[]
SerializerFeature.WriteNullStringAsEmpty, // 将字符串类型字段的空值输出为空字符串
SerializerFeature.WriteNullNumberAsZero, // 将数值类型字段的空值输出为0
SerializerFeature.WriteDateUseDateFormat,
SerializerFeature.DisableCircularReferenceDetect // 禁用循环引用
);
fastJsonConfig.setDateFormat(Constant.DATE_FORMAT);
fastJsonHttpMessageConverter.setFastJsonConfig(fastJsonConfig);
List<MediaType> fastMediaTypes = new ArrayList<>();
fastMediaTypes.add(MediaType.APPLICATION_JSON);
fastJsonHttpMessageConverter.setSupportedMediaTypes(fastMediaTypes);
converters.add(fastJsonHttpMessageConverter);
}
}
package com.pannk.mms.modules.sys.controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.pannk.mms.common.base.BaseController;
import com.pannk.mms.common.base.PageData;
import com.pannk.mms.common.base.Result;
import com.pannk.mms.modules.sys.entity.SysUserEntity;
import com.pannk.mms.modules.sys.service.SysUserService;
import com.pannk.mms.modules.sys.vo.SysUserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import java.util.Map;
......@@ -24,29 +22,86 @@ public class SysUserController extends BaseController {
private SysUserService sysUserService;
/**
* 用户列表
*
* @param params 参数
* @return
*/
@GetMapping("/list")
public Result list(@RequestParam Map<String,Object> params) {
public Result list(@RequestParam Map<String, Object> params) {
return Result.success(sysUserService.queryPage(params));
}
@GetMapping("/info")
public Result detail() {
/**
* 当前登录用户
*
* @return
*/
@GetMapping("/currentUser")
public Result currentUser() {
return Result.success(sysUserService.queryUserInfo(getUserId()));
}
@GetMapping("/save")
public Result save() {
SysUserEntity sysUserEntity = new SysUserEntity();
sysUserEntity.setCode("P00001");
sysUserEntity.setEmail("qxd@126.com");
sysUserEntity.setFullName("秦晓东");
sysUserEntity.setGender(0);
sysUserEntity.setStatus(0);
sysUserEntity.setUserName("qxd");
sysUserEntity.setPassword("123456");
createData(sysUserEntity);
sysUserService.save(sysUserEntity);
return Result.success(sysUserEntity);
/**
* 用户信息
*
* @param id id
* @return
*/
@GetMapping("/info/{id}")
public Result info(@PathVariable Long id) {
return Result.success(sysUserService.queryUserInfo(id));
}
/**
* 新增用户
*
* @param sysUserInfo 用户
* @return
*/
@PostMapping("/save")
public Result save(@RequestBody SysUserInfo sysUserInfo) {
createData(sysUserInfo);
sysUserService.saveUserInfo(sysUserInfo);
return Result.success(sysUserInfo);
}
/**
* 更新信息
*
* @param sysUserInfo 用户信息
* @return
*/
@PutMapping("/update")
public Result update(@RequestBody SysUserInfo sysUserInfo) {
updateDate(sysUserInfo);
sysUserService.updateUserInfo(sysUserInfo);
return Result.success(sysUserInfo);
}
/**
* 删除用户
*
* @param id id
* @return
*/
@DeleteMapping("/delete/{id}")
public Result delete(@PathVariable Long id) {
sysUserService.removeById(id);
return Result.success();
}
/**
* 批量删除
*
* @param ids id数组
* @return
*/
@DeleteMapping("/batchDelete")
public Result batchDelete(Long[] ids) {
sysUserService.remove(new QueryWrapper<SysUserEntity>().in("id", ids));
return Result.success();
}
}
......@@ -16,4 +16,10 @@ public interface SysUserMapper extends BaseMapper<SysUserEntity> {
* @return
*/
SysUserEntity queryByUserName(String userName);
/**
* 删除用户角色
* @param id 用户ID
*/
void deleteUserRole(Long id);
}
package com.pannk.mms.modules.sys.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.pannk.mms.modules.sys.entity.SysUserRoleEntity;
import org.apache.ibatis.annotations.Mapper;
/**
* Created by wolf on 20-11-23.
*/
@Mapper
public interface SysUserRoleMapper extends BaseMapper<SysUserRoleEntity> {
}
......@@ -58,9 +58,12 @@ public class SysUserEntity extends BaseEntity {
/**
* 头像
*/
private String avatar;
private String mobile;
/**
* 备注
*/
private String remark;
/**
......
package com.pannk.mms.modules.sys.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.pannk.mms.modules.sys.entity.SysUserRoleEntity;
/**
* Created by wolf on 20-11-23.
*/
public interface SysUserRoleService extends IService<SysUserRoleEntity>{
}
......@@ -55,4 +55,18 @@ public interface SysUserService extends IService<SysUserEntity> {
* @return
*/
PageData<SysUserEntity> queryPage(Map<String, Object> params);
/**
* 更新用户信息
*
* @param sysUserInfo 用户信息
*/
void updateUserInfo(SysUserInfo sysUserInfo);
/**
* 新增用户信息
*
* @param sysUserInfo 用户信息
*/
void saveUserInfo(SysUserInfo sysUserInfo);
}
package com.pannk.mms.modules.sys.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pannk.mms.modules.sys.dao.SysUserRoleMapper;
import com.pannk.mms.modules.sys.entity.SysUserRoleEntity;
import com.pannk.mms.modules.sys.service.SysUserRoleService;
import org.springframework.stereotype.Service;
/**
* Created by wolf on 20-11-23.
*/
@Service
public class SysUserRoleServiceImpl extends ServiceImpl<SysUserRoleMapper, SysUserRoleEntity> implements
SysUserRoleService {
}
......@@ -12,15 +12,20 @@ import com.pannk.mms.common.utils.TokenUtil;
import com.pannk.mms.modules.sys.dao.SysUserMapper;
import com.pannk.mms.modules.sys.entity.SysRoleEntity;
import com.pannk.mms.modules.sys.entity.SysUserEntity;
import com.pannk.mms.modules.sys.entity.SysUserRoleEntity;
import com.pannk.mms.modules.sys.service.SysRoleService;
import com.pannk.mms.modules.sys.service.SysUserRoleService;
import com.pannk.mms.modules.sys.service.SysUserService;
import com.pannk.mms.modules.sys.vo.LoginForm;
import com.pannk.mms.modules.sys.vo.SysUserInfo;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
......@@ -38,6 +43,9 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUserEntity
@Autowired
private SysRoleService sysRoleService;
@Autowired
private SysUserRoleService sysUserRoleService;
@Override
public SysUserEntity queryByUserName(String userName) {
......@@ -68,6 +76,11 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUserEntity
List<SysRoleEntity> roles = sysRoleService.queryUserRole(sysUserEntity.getId());
BeanUtils.copyProperties(sysUserEntity, sysUserInfo);
sysUserInfo.setRoles(roles);
List<Long> roleIdList = new ArrayList<>();
for (SysRoleEntity sre : roles) {
roleIdList.add(sre.getId());
}
sysUserInfo.setRoleIdList(roleIdList);
return sysUserInfo;
}
......@@ -77,9 +90,47 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUserEntity
redisUtil.del(Constant.PERMS_CAHCE + userId);
}
@Override
public PageData<SysUserEntity> queryPage(Map<String, Object> params) {
IPage<SysUserEntity> page = this.page(new Query<SysUserEntity>().getPage(params), new QueryWrapper<>());
String userName = (String) params.get("userName");
IPage<SysUserEntity> page = this.page(new Query<SysUserEntity>().getPage(params), new
QueryWrapper<SysUserEntity>().like(StringUtils.isNotEmpty(userName), "user_name", userName));
return new PageData<>(page);
}
@Transactional(rollbackFor = Exception.class)
@Override
public void updateUserInfo(SysUserInfo sysUserInfo) {
this.updateById(sysUserInfo);
sysUserRoleService.remove(new QueryWrapper<SysUserRoleEntity>().eq("user_id", sysUserInfo.getId()));
saveUserRole(sysUserInfo);
}
/**
* 保存用户角色
*
* @param sysUserInfo 用户信息
*/
private void saveUserRole(SysUserInfo sysUserInfo) {
List<Long> sysUserRoleIdList = sysUserInfo.getRoleIdList();
if (sysUserRoleIdList.size() > 0) {
List<SysUserRoleEntity> list = new ArrayList<>(sysUserRoleIdList.size());
for (Long roleId : sysUserRoleIdList) {
SysUserRoleEntity sysUserRoleEntity = new SysUserRoleEntity();
sysUserRoleEntity.setUserId(sysUserInfo.getId());
sysUserRoleEntity.setRoleId(roleId);
list.add(sysUserRoleEntity);
}
sysUserRoleService.saveBatch(list);
}
}
@Transactional(rollbackFor = Exception.class)
@Override
public void saveUserInfo(SysUserInfo sysUserInfo) {
sysUserInfo.setPassword(Constant.INIT_PASSWORD);
save(sysUserInfo);
saveUserRole(sysUserInfo);
}
}
......@@ -15,4 +15,9 @@ public class SysUserInfo extends SysUserEntity {
* 用户角色
*/
List<SysRoleEntity> roles;
/**
* 角色Id
*/
List<Long> roleIdList;
}
-- 系统用户表
CREATE TABLE `sys_user` (
`id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键',
`user_name` varchar(100) NOT NULL COMMENT '用户名',
`password` varchar(100) NOT NULL COMMENT '密码',
`code` varchar(100) NOT NULL COMMENT '编号',
`gender` smallint DEFAULT '0' COMMENT '性别,0:男,1:女',
`email` varchar(100) DEFAULT NULL COMMENT '邮箱',
`full_name` varchar(100) DEFAULT NULL COMMENT '姓名',
`status` varchar(100) NOT NULL COMMENT '状态,0:启用,1:禁用',
`create_date` date DEFAULT NULL COMMENT '新增日期',
`create_user` varchar(100) DEFAULT NULL COMMENT '新增人',
`update_date` date DEFAULT NULL COMMENT '更新日期',
`update_user` varchar(100) DEFAULT NULL COMMENT '更新人',
`avatar` blob,
`remark` text,
`id` BIGINT NOT NULL AUTO_INCREMENT
COMMENT '主键',
`user_name` VARCHAR(100) NOT NULL
COMMENT '用户名',
`password` VARCHAR(100) NOT NULL
COMMENT '密码',
`code` VARCHAR(100) NOT NULL
COMMENT '编号',
`gender` SMALLINT DEFAULT '0'
COMMENT '性别,0:男,1:女',
`email` VARCHAR(100) DEFAULT NULL
COMMENT '邮箱',
`full_name` VARCHAR(100) DEFAULT NULL
COMMENT '姓名',
`status` VARCHAR(100) NOT NULL
COMMENT '状态,0:启用,1:禁用',
`create_date` DATETIME DEFAULT NULL
COMMENT '新增日期',
`create_user` VARCHAR(100) DEFAULT NULL
COMMENT '新增人',
`update_date` DATETIME DEFAULT NULL
COMMENT '更新日期',
`update_user` VARCHAR(100) DEFAULT NULL
COMMENT '更新人',
`mobile` VARCHAR(20) COMMENT '手机号',
`remark` TEXT,
PRIMARY KEY (`id`),
UNIQUE KEY `user_name_unique` (`user_name`),
UNIQUE KEY `code_unique` (`code`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
)
ENGINE = InnoDB
AUTO_INCREMENT = 4
DEFAULT CHARSET = utf8mb4
COLLATE = utf8mb4_0900_ai_ci
-- 用户角色表
CREATE TABLE `sys_user_role` (
`id` BIGINT NOT NULL AUTO_INCREMENT
......@@ -203,51 +219,51 @@ CREATE TABLE `biz_workflow` (
ENGINE = InnoDB
DEFAULT CHARSET = utf8mb4
COLLATE = utf8mb4_general_ci;
INSERT INTO `sys_menu`(id,parent_id,name,url,perms,type,icon,seq,create_user,create_date) VALUES
(1,0,'系统管理',NULL,NULL,0,'system',0,1,now()),
(2,1,'管理员列表','sys/user',NULL,1,'admin',1,1,now()),
(3,1,'角色管理','sys/role',NULL,1,'role',2,1,now()),
(4,1,'菜单管理','sys/menu',NULL,1,'menu',3,1,now()),
(6,1,'定时任务','job/schedule',NULL,1,'job',5,1,now()),
(7,6,'查看',NULL,'sys:schedule:list,sys:schedule:info',2,NULL,0,1,now()),
(8,6,'新增',NULL,'sys:schedule:save',2,NULL,0,1,now()),
(9,6,'修改',NULL,'sys:schedule:update',2,NULL,0,1,now()),
(10,6,'删除',NULL,'sys:schedule:delete',2,NULL,0,1,now()),
(11,6,'暂停',NULL,'sys:schedule:pause',2,NULL,0,1,now()),
(12,6,'恢复',NULL,'sys:schedule:resume',2,NULL,0,1,now()),
(13,6,'立即执行',NULL,'sys:schedule:run',2,NULL,0,1,now()),
(14,6,'日志列表',NULL,'sys:schedule:log',2,NULL,0,1,now()),
(15,2,'查看',NULL,'sys:user:list,sys:user:info',2,NULL,0,1,now()),
(16,2,'新增',NULL,'sys:user:save,sys:role:select',2,NULL,0,1,now()),
(17,2,'修改',NULL,'sys:user:update,sys:role:select',2,NULL,0,1,now()),
(18,2,'删除',NULL,'sys:user:delete',2,NULL,0,1,now()),
(19,3,'查看',NULL,'sys:role:list,sys:role:info',2,NULL,0,1,now()),
(20,3,'新增',NULL,'sys:role:save,sys:menu:list',2,NULL,0,1,now()),
(21,3,'修改',NULL,'sys:role:update,sys:menu:list',2,NULL,0,1,now()),
(22,3,'删除',NULL,'sys:role:delete',2,NULL,0,1,now()),
(23,4,'查看',NULL,'sys:menu:list,sys:menu:info',2,NULL,0,1,now()),
(24,4,'新增',NULL,'sys:menu:save,sys:menu:select',2,NULL,0,1,now()),
(25,4,'修改',NULL,'sys:menu:update,sys:menu:select',2,NULL,0,1,now()),
(26,4,'删除',NULL,'sys:menu:delete',2,NULL,0,1,now()),
(27,1,'参数管理','sys/config','sys:config:list,sys:config:info,sys:config:save,sys:config:update,sys:config:delete',1,'config',6,1,now()),
(29,1,'系统日志','sys/log','sys:log:list',1,'log',7,1,now()),
(36,0,'设备管理','','',0,'shouye',1,1,now()),
(45,36,'设备类型','devices/device/devicetype','',1,'menu',0,1,now()),
(46,36,'设备实例','devices/deviceExample/deviceExa','',1,'editor',3,1,now()),
(47,36,'设备厂家','devices/deviceFactory/deviceFac','',1,'role',1,1,now()),
(49,45,'查看','','device:devicetype:list,device:devicetype:info',2,'',0,1,now()),
(52,45,'修改状态','','device:devicetype:status',2,'',0,1,now()),
(53,46,'查看',NULL,'device:accessdeviceinfo:list,device:accessdeviceinfo:info',2,NULL,0,1,now()),
(54,46,'新增',NULL,'device:accessdeviceinfo:save',2,NULL,0,1,now()),
(55,46,'删除',NULL,'device:accessdeviceinfo:delete',2,NULL,0,1,now()),
(56,46,'修改',NULL,'device:accessdeviceinfo:update,device:accessdeviceinfo:updateStatus',2,NULL,0,1,now()),
(57,47,'查看','','device:manufacturer:list,device:manufacturer:info',2,'',0,1,now()),
(60,47,'修改状态','','device:manufacturer:status',2,'',0,1,now()),
(65,36,'区域管理','devices/region/index','',1,'config',2,1,now()),
(66,65,'新增','','device:deviceregion:save',2,'',0,1,now()),
(67,65,'查看','','device:deviceregion:list,device:deviceregion:info',2,'',0,1,now()),
(68,65,'更新','','device:deviceregion:update',2,'',0,1,now()),
(69,65,'删除','','device:deviceregion:delete',2,'',0,1,now()),
(72,45,'保存订阅地址','','device:devicetypetemplate:updateSubscribeUrl',2,'',0,1,now()),
(73,45,'修改类型模板状态','','device:devicetypetemplate:updateStatus',2,'',0,1,now()),
(74,36,'设备告警','devices/deviceReport/index','',1,'',5,1,now());
\ No newline at end of file
INSERT INTO `sys_menu` (id, parent_id, name, url, perms, type, icon, seq, create_user, create_date) VALUES
(1, 0, '系统管理', NULL, NULL, 0, 'system', 0, 1, now()),
(2, 1, '管理员列表', 'sys/user', NULL, 1, 'admin', 1, 1, now()),
(3, 1, '角色管理', 'sys/role', NULL, 1, 'role', 2, 1, now()),
(4, 1, '菜单管理', 'sys/menu', NULL, 1, 'menu', 3, 1, now()),
(6, 1, '定时任务', 'job/schedule', NULL, 1, 'job', 5, 1, now()),
(7, 6, '查看', NULL, 'sys:schedule:list,sys:schedule:info', 2, NULL, 0, 1, now()),
(8, 6, '新增', NULL, 'sys:schedule:save', 2, NULL, 0, 1, now()),
(9, 6, '修改', NULL, 'sys:schedule:update', 2, NULL, 0, 1, now()),
(10, 6, '删除', NULL, 'sys:schedule:delete', 2, NULL, 0, 1, now()),
(11, 6, '暂停', NULL, 'sys:schedule:pause', 2, NULL, 0, 1, now()),
(12, 6, '恢复', NULL, 'sys:schedule:resume', 2, NULL, 0, 1, now()),
(13, 6, '立即执行', NULL, 'sys:schedule:run', 2, NULL, 0, 1, now()),
(14, 6, '日志列表', NULL, 'sys:schedule:log', 2, NULL, 0, 1, now()),
(15, 2, '查看', NULL, 'sys:user:list,sys:user:info', 2, NULL, 0, 1, now()),
(16, 2, '新增', NULL, 'sys:user:save,sys:role:select', 2, NULL, 0, 1, now()),
(17, 2, '修改', NULL, 'sys:user:update,sys:role:select', 2, NULL, 0, 1, now()),
(18, 2, '删除', NULL, 'sys:user:delete', 2, NULL, 0, 1, now()),
(19, 3, '查看', NULL, 'sys:role:list,sys:role:info', 2, NULL, 0, 1, now()),
(20, 3, '新增', NULL, 'sys:role:save,sys:menu:list', 2, NULL, 0, 1, now()),
(21, 3, '修改', NULL, 'sys:role:update,sys:menu:list', 2, NULL, 0, 1, now()),
(22, 3, '删除', NULL, 'sys:role:delete', 2, NULL, 0, 1, now()),
(23, 4, '查看', NULL, 'sys:menu:list,sys:menu:info', 2, NULL, 0, 1, now()),
(24, 4, '新增', NULL, 'sys:menu:save,sys:menu:select', 2, NULL, 0, 1, now()),
(25, 4, '修改', NULL, 'sys:menu:update,sys:menu:select', 2, NULL, 0, 1, now()),
(26, 4, '删除', NULL, 'sys:menu:delete', 2, NULL, 0, 1, now()),
(27, 1, '参数管理', 'sys/config', 'sys:config:list,sys:config:info,sys:config:save,sys:config:update,sys:config:delete', 1, 'config', 6, 1, now()),
(29, 1, '系统日志', 'sys/log', 'sys:log:list', 1, 'log', 7, 1, now()),
(36, 0, '设备管理', '', '', 0, 'shouye', 1, 1, now()),
(45, 36, '设备类型', 'devices/device/devicetype', '', 1, 'menu', 0, 1, now()),
(46, 36, '设备实例', 'devices/deviceExample/deviceExa', '', 1, 'editor', 3, 1, now()),
(47, 36, '设备厂家', 'devices/deviceFactory/deviceFac', '', 1, 'role', 1, 1, now()),
(49, 45, '查看', '', 'device:devicetype:list,device:devicetype:info', 2, '', 0, 1, now()),
(52, 45, '修改状态', '', 'device:devicetype:status', 2, '', 0, 1, now()),
(53, 46, '查看', NULL, 'device:accessdeviceinfo:list,device:accessdeviceinfo:info', 2, NULL, 0, 1, now()),
(54, 46, '新增', NULL, 'device:accessdeviceinfo:save', 2, NULL, 0, 1, now()),
(55, 46, '删除', NULL, 'device:accessdeviceinfo:delete', 2, NULL, 0, 1, now()),
(56, 46, '修改', NULL, 'device:accessdeviceinfo:update,device:accessdeviceinfo:updateStatus', 2, NULL, 0, 1, now()),
(57, 47, '查看', '', 'device:manufacturer:list,device:manufacturer:info', 2, '', 0, 1, now()),
(60, 47, '修改状态', '', 'device:manufacturer:status', 2, '', 0, 1, now()),
(65, 36, '区域管理', 'devices/region/index', '', 1, 'config', 2, 1, now()),
(66, 65, '新增', '', 'device:deviceregion:save', 2, '', 0, 1, now()),
(67, 65, '查看', '', 'device:deviceregion:list,device:deviceregion:info', 2, '', 0, 1, now()),
(68, 65, '更新', '', 'device:deviceregion:update', 2, '', 0, 1, now()),
(69, 65, '删除', '', 'device:deviceregion:delete', 2, '', 0, 1, now()),
(72, 45, '保存订阅地址', '', 'device:devicetypetemplate:updateSubscribeUrl', 2, '', 0, 1, now()),
(73, 45, '修改类型模板状态', '', 'device:devicetypetemplate:updateStatus', 2, '', 0, 1, now()),
(74, 36, '设备告警', 'devices/deviceReport/index', '', 1, '', 5, 1, now());
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org/DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.pannk.mms.modules.sys.dao.SysUserMapper">
<delete id="deleteUserRole">
DELETE FROM sys_user_role WHERE user_id = #{userId}
</delete>
<select id="queryByUserName" resultType="com.pannk.mms.modules.sys.entity.SysUserEntity">
......
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org/DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.pannk.mms.modules.sys.dao.SysUserRoleMapper">
</mapper>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册