mdf:user
This commit is contained in:
@@ -18,6 +18,7 @@ package org.nl.system.controller.user;
|
||||
import cn.dev33.satoken.secure.SaSecureUtil;
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import io.swagger.annotations.Api;
|
||||
@@ -30,8 +31,10 @@ import org.nl.modules.common.exception.BadRequestException;
|
||||
import org.nl.modules.common.utils.RsaUtils;
|
||||
import org.nl.modules.common.utils.SecurityUtils;
|
||||
import org.nl.modules.logging.annotation.Log;
|
||||
import org.nl.modules.tools.IdUtil;
|
||||
import org.nl.system.service.user.ISysUserService;
|
||||
import org.nl.system.service.user.dao.SysUser;
|
||||
import org.nl.system.service.user.dto.SysUserDetail;
|
||||
import org.nl.system.service.user.dto.UserQuery;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
@@ -68,14 +71,8 @@ public class UserController {
|
||||
@ApiOperation("新增用户")
|
||||
@PostMapping
|
||||
// @SaCheckPermission("user:add")
|
||||
public ResponseEntity<Object> create(@Validated @RequestBody SysUser resources){
|
||||
// 默认密码 123456
|
||||
if (ObjectUtil.isEmpty(resources.getPassword())) {
|
||||
resources.setPassword(SaSecureUtil.md5BySalt("123456", "salt"));
|
||||
} else {
|
||||
resources.setPassword(SaSecureUtil.md5BySalt(resources.getPassword(), "salt"));
|
||||
}
|
||||
userService.save(resources);
|
||||
public ResponseEntity<Object> create(@RequestBody Map user){
|
||||
userService.create(user);
|
||||
return new ResponseEntity<>(HttpStatus.CREATED);
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import org.nl.common.domain.query.PageQuery;
|
||||
import org.nl.system.service.dept.dao.SysDept;
|
||||
import org.nl.system.service.dept.dto.DeptQuery;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -32,6 +33,19 @@ public interface ISysDeptService extends IService<SysDept> {
|
||||
* @return
|
||||
*/
|
||||
Map<String, Object> buildTree(DeptQuery query);
|
||||
|
||||
/**
|
||||
* 查询当前部门id的上级id
|
||||
* @param deptIds
|
||||
* @return
|
||||
*/
|
||||
Map<String, Object> getSuperior(List<Long> deptIds);
|
||||
|
||||
/**
|
||||
* 保存用户部门关系
|
||||
* @param UserId
|
||||
* @param deptIds
|
||||
*/
|
||||
void saveUserDeptRelation(String UserId, Collection<String> deptIds);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
package org.nl.system.service.dept.dao.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.nl.system.service.dept.dao.SysDept;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 部门 Mapper 接口
|
||||
@@ -13,4 +17,6 @@ import org.nl.system.service.dept.dao.SysDept;
|
||||
*/
|
||||
public interface SysDeptMapper extends BaseMapper<SysDept> {
|
||||
|
||||
void saveDeptRelation(@Param("user") String UserId,@Param("depts") Collection<String> deptId);
|
||||
|
||||
}
|
||||
|
||||
@@ -2,4 +2,10 @@
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="org.nl.system.service.dept.dao.mapper.SysDeptMapper">
|
||||
|
||||
<insert id="saveDeptRelation">
|
||||
replace into sys_user_dept values
|
||||
<foreach collection="depts" item="dept" separator=",">
|
||||
(#{user},#{dept})
|
||||
</foreach>
|
||||
</insert>
|
||||
</mapper>
|
||||
|
||||
@@ -12,7 +12,9 @@ import org.nl.system.service.dept.ISysDeptService;
|
||||
import org.nl.system.service.dept.dao.SysDept;
|
||||
import org.nl.system.service.dept.dao.mapper.SysDeptMapper;
|
||||
import org.nl.system.service.dept.dto.DeptQuery;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -28,6 +30,9 @@ import java.util.stream.Collectors;
|
||||
@Service
|
||||
public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> implements ISysDeptService {
|
||||
|
||||
@Autowired
|
||||
private SysDeptMapper sysDeptMapper;
|
||||
|
||||
@Override
|
||||
public Map<String, Object> buildTree(DeptQuery query) {
|
||||
List<SysDept> list = this.list(query.build());
|
||||
@@ -85,4 +90,13 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
|
||||
}
|
||||
return page;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void saveUserDeptRelation(String userId, Collection<String> deptIds) {
|
||||
if (StringUtils.isEmpty(userId) || CollectionUtils.isEmpty(deptIds)){
|
||||
return;
|
||||
}
|
||||
sysDeptMapper.saveDeptRelation(userId,deptIds);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,4 +54,11 @@ public interface ISysRoleService extends IService<SysRole> {
|
||||
*/
|
||||
List<String> getPermissionList(JSONObject userDto);
|
||||
|
||||
|
||||
/**
|
||||
* 保存用户角色关系
|
||||
* @param UserId
|
||||
* @param deptIds
|
||||
*/
|
||||
void saveUserRoleRelation(String UserId, List<String> deptIds);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package org.nl.system.service.role.dao.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.nl.system.service.role.dao.SysRole;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -15,4 +17,5 @@ import java.util.List;
|
||||
*/
|
||||
public interface SysRoleMapper extends BaseMapper<SysRole> {
|
||||
|
||||
void saveRoleRelation(@Param("user") String UserId, @Param("roles") Collection<String> roles);
|
||||
}
|
||||
|
||||
@@ -2,4 +2,10 @@
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="org.nl.system.service.role.dao.mapper.SysRoleMapper">
|
||||
|
||||
<insert id="saveRoleRelation">
|
||||
replace into sys_users_roles values
|
||||
<foreach collection="roles" item="role" separator=",">
|
||||
(#{user},#{role})
|
||||
</foreach>
|
||||
</insert>
|
||||
</mapper>
|
||||
|
||||
@@ -25,4 +25,6 @@ public interface ISysUserService extends IService<SysUser> {
|
||||
|
||||
List<SysUserDetail> getUserDetail(UserQuery query, PageQuery pageQuery);
|
||||
|
||||
void create(Map userDetail);
|
||||
|
||||
}
|
||||
|
||||
@@ -3,10 +3,12 @@ package org.nl.system.service.user.dao;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
@@ -103,6 +105,7 @@ public class SysUser implements Serializable {
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
@@ -118,6 +121,7 @@ public class SysUser implements Serializable {
|
||||
/**
|
||||
* 修改时间
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date updateTime;
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,21 +1,30 @@
|
||||
package org.nl.system.service.user.impl;
|
||||
|
||||
import cn.dev33.satoken.secure.SaSecureUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import lombok.SneakyThrows;
|
||||
import org.nl.common.domain.query.PageQuery;
|
||||
import org.nl.modules.common.config.FileProperties;
|
||||
import org.nl.modules.common.utils.FileUtil;
|
||||
import org.nl.modules.common.utils.SecurityUtils;
|
||||
import org.nl.modules.tools.IdUtil;
|
||||
import org.nl.system.service.dept.ISysDeptService;
|
||||
import org.nl.system.service.dept.dao.mapper.SysDeptMapper;
|
||||
import org.nl.system.service.role.ISysRoleService;
|
||||
import org.nl.system.service.role.dao.SysRole;
|
||||
import org.nl.system.service.role.dao.mapper.SysRoleMapper;
|
||||
import org.nl.system.service.user.ISysUserService;
|
||||
import org.nl.system.service.user.dao.SysUser;
|
||||
import org.nl.system.service.user.dao.mapper.SysUserMapper;
|
||||
import org.nl.system.service.user.dto.SysUserDetail;
|
||||
import org.nl.system.service.user.dto.UserQuery;
|
||||
import org.apache.commons.beanutils.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.File;
|
||||
@@ -36,9 +45,13 @@ import java.util.Objects;
|
||||
public class ISysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> implements ISysUserService {
|
||||
|
||||
@Autowired
|
||||
FileProperties properties;
|
||||
private FileProperties properties;
|
||||
@Autowired
|
||||
SysUserMapper sysUserMapper;
|
||||
private SysUserMapper sysUserMapper;
|
||||
@Autowired
|
||||
private ISysDeptService deptService;
|
||||
@Autowired
|
||||
private ISysRoleService roleService;
|
||||
|
||||
@Override
|
||||
public Map<String, String> updateAvatar(MultipartFile multipartFile) {
|
||||
@@ -61,4 +74,27 @@ public class ISysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> imp
|
||||
List<SysUserDetail> userDetail = sysUserMapper.getUserDetail(query, pageQuery);
|
||||
return userDetail;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@SneakyThrows
|
||||
public void create(Map userDetail) {
|
||||
SysUser sysUser = new SysUser();
|
||||
BeanUtils.populate(sysUser,userDetail);
|
||||
// 默认密码 123456
|
||||
if (ObjectUtil.isEmpty(sysUser.getPassword())) {
|
||||
sysUser.setPassword(SaSecureUtil.md5BySalt("123456", "salt"));
|
||||
} else {
|
||||
sysUser.setPassword(SaSecureUtil.md5BySalt(sysUser.getPassword(), "salt"));
|
||||
}
|
||||
String userId = IdUtil.getStringId();
|
||||
sysUser.setUserId(userId);
|
||||
this.save(sysUser);
|
||||
if (userDetail.get("depts") !=null){
|
||||
deptService.saveUserDeptRelation(userId,(List)userDetail.get("depts"));
|
||||
};
|
||||
if (userDetail.get("roles") !=null){
|
||||
roleService.saveUserRoleRelation(userId,(List)userDetail.get("depts"));
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,13 +100,11 @@
|
||||
<el-radio label="女">女</el-radio>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
<el-form-item label="状态" prop="is_uesd">
|
||||
<el-form-item label="状态" prop="isUesd">
|
||||
<el-switch
|
||||
v-model="form.isUsed"
|
||||
active-color="#409EFF"
|
||||
inactive-color="#F56C6C"
|
||||
active-value="1"
|
||||
inactive-value="0"
|
||||
/>
|
||||
</el-form-item>
|
||||
<br v-if="!crud.status.edit">
|
||||
@@ -156,7 +154,7 @@
|
||||
<el-table-column prop="email" label="邮箱" :min-width="flexWidth('email',crud.data,'邮箱')" />
|
||||
<el-table-column show-overflow-tooltip prop="depts" label="部门" >
|
||||
<template slot-scope="scope">
|
||||
<span>{{ scope.row.depts }}</span>
|
||||
<span v-for=" item in scope.row.depts" :key="item.index">{{item.name}} </span>
|
||||
</template>
|
||||
</el-table-column>>
|
||||
<el-table-column label="状态" align="center" prop="enabled">
|
||||
@@ -345,7 +343,7 @@ const defaultForm = {
|
||||
personName: null,
|
||||
gender: '男',
|
||||
email: null,
|
||||
isUsed: '1',
|
||||
isUsed: true,
|
||||
roles: [],
|
||||
phone: null,
|
||||
password: null
|
||||
@@ -441,7 +439,7 @@ export default {
|
||||
})
|
||||
},
|
||||
caseStatusColorFilter(isUsed) {
|
||||
if (isUsed === '1') {
|
||||
if (isUsed === true) {
|
||||
return '#378be2'
|
||||
}
|
||||
return '#F56C6C'
|
||||
@@ -533,7 +531,7 @@ export default {
|
||||
},
|
||||
getDepts() {
|
||||
console.log('获取部门')
|
||||
crudDept.getDepts({ isUsed: 1 }).then(res => {
|
||||
crudDept.getDepts({ isUsed: true }).then(res => {
|
||||
console.log('获取的部门信息', res)
|
||||
|
||||
this.depts = res.content.map(function(obj) {
|
||||
@@ -565,7 +563,7 @@ export default {
|
||||
// 获取弹窗内部门数据
|
||||
loadDepts({ action, parentNode, callback }) {
|
||||
if (action === LOAD_CHILDREN_OPTIONS) {
|
||||
crudDept.getDeptvo({ isUsed: '1', pid: parentNode.dept_id }).then(res => {
|
||||
crudDept.getDeptvo({ isUsed: true, pid: parentNode.dept_id }).then(res => {
|
||||
parentNode.children = res.content.map(function(obj) {
|
||||
obj.children = null
|
||||
return obj
|
||||
|
||||
Reference in New Issue
Block a user