This commit is contained in:
zhangzhiqiang
2022-12-16 18:06:55 +08:00
parent f1b69e8f90
commit 22ae7f3720
12 changed files with 113 additions and 20 deletions

View File

@@ -18,6 +18,7 @@ package org.nl.system.controller.user;
import cn.dev33.satoken.secure.SaSecureUtil; import cn.dev33.satoken.secure.SaSecureUtil;
import cn.dev33.satoken.stp.StpUtil; import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.util.ObjectUtil; 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.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import io.swagger.annotations.Api; 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.RsaUtils;
import org.nl.modules.common.utils.SecurityUtils; import org.nl.modules.common.utils.SecurityUtils;
import org.nl.modules.logging.annotation.Log; 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.ISysUserService;
import org.nl.system.service.user.dao.SysUser; 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.nl.system.service.user.dto.UserQuery;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
@@ -68,14 +71,8 @@ public class UserController {
@ApiOperation("新增用户") @ApiOperation("新增用户")
@PostMapping @PostMapping
// @SaCheckPermission("user:add") // @SaCheckPermission("user:add")
public ResponseEntity<Object> create(@Validated @RequestBody SysUser resources){ public ResponseEntity<Object> create(@RequestBody Map user){
// 默认密码 123456 userService.create(user);
if (ObjectUtil.isEmpty(resources.getPassword())) {
resources.setPassword(SaSecureUtil.md5BySalt("123456", "salt"));
} else {
resources.setPassword(SaSecureUtil.md5BySalt(resources.getPassword(), "salt"));
}
userService.save(resources);
return new ResponseEntity<>(HttpStatus.CREATED); return new ResponseEntity<>(HttpStatus.CREATED);
} }

View File

@@ -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.dao.SysDept;
import org.nl.system.service.dept.dto.DeptQuery; import org.nl.system.service.dept.dto.DeptQuery;
import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@@ -32,6 +33,19 @@ public interface ISysDeptService extends IService<SysDept> {
* @return * @return
*/ */
Map<String, Object> buildTree(DeptQuery query); Map<String, Object> buildTree(DeptQuery query);
/**
* 查询当前部门id的上级id
* @param deptIds
* @return
*/
Map<String, Object> getSuperior(List<Long> deptIds); Map<String, Object> getSuperior(List<Long> deptIds);
/**
* 保存用户部门关系
* @param UserId
* @param deptIds
*/
void saveUserDeptRelation(String UserId, Collection<String> deptIds);
} }

View File

@@ -1,8 +1,12 @@
package org.nl.system.service.dept.dao.mapper; package org.nl.system.service.dept.dao.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.nl.system.service.dept.dao.SysDept; import org.nl.system.service.dept.dao.SysDept;
import java.util.Collection;
import java.util.List;
/** /**
* <p> * <p>
* 部门 Mapper 接口 * 部门 Mapper 接口
@@ -13,4 +17,6 @@ import org.nl.system.service.dept.dao.SysDept;
*/ */
public interface SysDeptMapper extends BaseMapper<SysDept> { public interface SysDeptMapper extends BaseMapper<SysDept> {
void saveDeptRelation(@Param("user") String UserId,@Param("depts") Collection<String> deptId);
} }

View File

@@ -2,4 +2,10 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <!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"> <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> </mapper>

View File

@@ -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.SysDept;
import org.nl.system.service.dept.dao.mapper.SysDeptMapper; import org.nl.system.service.dept.dao.mapper.SysDeptMapper;
import org.nl.system.service.dept.dto.DeptQuery; import org.nl.system.service.dept.dto.DeptQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@@ -28,6 +30,9 @@ import java.util.stream.Collectors;
@Service @Service
public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> implements ISysDeptService { public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> implements ISysDeptService {
@Autowired
private SysDeptMapper sysDeptMapper;
@Override @Override
public Map<String, Object> buildTree(DeptQuery query) { public Map<String, Object> buildTree(DeptQuery query) {
List<SysDept> list = this.list(query.build()); List<SysDept> list = this.list(query.build());
@@ -85,4 +90,13 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
} }
return page; return page;
} }
@Override
public void saveUserDeptRelation(String userId, Collection<String> deptIds) {
if (StringUtils.isEmpty(userId) || CollectionUtils.isEmpty(deptIds)){
return;
}
sysDeptMapper.saveDeptRelation(userId,deptIds);
}
} }

View File

@@ -54,4 +54,11 @@ public interface ISysRoleService extends IService<SysRole> {
*/ */
List<String> getPermissionList(JSONObject userDto); List<String> getPermissionList(JSONObject userDto);
/**
* 保存用户角色关系
* @param UserId
* @param deptIds
*/
void saveUserRoleRelation(String UserId, List<String> deptIds);
} }

View File

@@ -1,8 +1,10 @@
package org.nl.system.service.role.dao.mapper; package org.nl.system.service.role.dao.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.nl.system.service.role.dao.SysRole; import org.nl.system.service.role.dao.SysRole;
import java.util.Collection;
import java.util.List; import java.util.List;
/** /**
@@ -15,4 +17,5 @@ import java.util.List;
*/ */
public interface SysRoleMapper extends BaseMapper<SysRole> { public interface SysRoleMapper extends BaseMapper<SysRole> {
void saveRoleRelation(@Param("user") String UserId, @Param("roles") Collection<String> roles);
} }

View File

@@ -2,4 +2,10 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <!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"> <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> </mapper>

View File

@@ -25,4 +25,6 @@ public interface ISysUserService extends IService<SysUser> {
List<SysUserDetail> getUserDetail(UserQuery query, PageQuery pageQuery); List<SysUserDetail> getUserDetail(UserQuery query, PageQuery pageQuery);
void create(Map userDetail);
} }

View File

@@ -3,10 +3,12 @@ package org.nl.system.service.user.dao;
import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import java.io.Serializable; import java.io.Serializable;
import java.sql.Timestamp;
import java.util.Date; import java.util.Date;
/** /**
@@ -103,6 +105,7 @@ public class SysUser implements Serializable {
/** /**
* 创建时间 * 创建时间
*/ */
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date createTime; private Date createTime;
/** /**
@@ -118,6 +121,7 @@ public class SysUser implements Serializable {
/** /**
* 修改时间 * 修改时间
*/ */
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date updateTime; private Date updateTime;
/** /**

View File

@@ -1,21 +1,30 @@
package org.nl.system.service.user.impl; 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 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.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.SneakyThrows;
import org.nl.common.domain.query.PageQuery; import org.nl.common.domain.query.PageQuery;
import org.nl.modules.common.config.FileProperties; import org.nl.modules.common.config.FileProperties;
import org.nl.modules.common.utils.FileUtil; import org.nl.modules.common.utils.FileUtil;
import org.nl.modules.common.utils.SecurityUtils; 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.ISysUserService;
import org.nl.system.service.user.dao.SysUser; import org.nl.system.service.user.dao.SysUser;
import org.nl.system.service.user.dao.mapper.SysUserMapper; import org.nl.system.service.user.dao.mapper.SysUserMapper;
import org.nl.system.service.user.dto.SysUserDetail; import org.nl.system.service.user.dto.SysUserDetail;
import org.nl.system.service.user.dto.UserQuery; import org.nl.system.service.user.dto.UserQuery;
import org.apache.commons.beanutils.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import java.io.File; import java.io.File;
@@ -36,9 +45,13 @@ import java.util.Objects;
public class ISysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> implements ISysUserService { public class ISysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> implements ISysUserService {
@Autowired @Autowired
FileProperties properties; private FileProperties properties;
@Autowired @Autowired
SysUserMapper sysUserMapper; private SysUserMapper sysUserMapper;
@Autowired
private ISysDeptService deptService;
@Autowired
private ISysRoleService roleService;
@Override @Override
public Map<String, String> updateAvatar(MultipartFile multipartFile) { 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); List<SysUserDetail> userDetail = sysUserMapper.getUserDetail(query, pageQuery);
return userDetail; 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"));
};
}
} }

View File

@@ -100,13 +100,11 @@
<el-radio label="">女</el-radio> <el-radio label="">女</el-radio>
</el-radio-group> </el-radio-group>
</el-form-item> </el-form-item>
<el-form-item label="状态" prop="is_uesd"> <el-form-item label="状态" prop="isUesd">
<el-switch <el-switch
v-model="form.isUsed" v-model="form.isUsed"
active-color="#409EFF" active-color="#409EFF"
inactive-color="#F56C6C" inactive-color="#F56C6C"
active-value="1"
inactive-value="0"
/> />
</el-form-item> </el-form-item>
<br v-if="!crud.status.edit"> <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 prop="email" label="邮箱" :min-width="flexWidth('email',crud.data,'邮箱')" />
<el-table-column show-overflow-tooltip prop="depts" label="部门" > <el-table-column show-overflow-tooltip prop="depts" label="部门" >
<template slot-scope="scope"> <template slot-scope="scope">
<span>{{ scope.row.depts }}</span> <span v-for=" item in scope.row.depts" :key="item.index">{{item.name}} </span>
</template> </template>
</el-table-column>> </el-table-column>>
<el-table-column label="状态" align="center" prop="enabled"> <el-table-column label="状态" align="center" prop="enabled">
@@ -345,7 +343,7 @@ const defaultForm = {
personName: null, personName: null,
gender: '男', gender: '男',
email: null, email: null,
isUsed: '1', isUsed: true,
roles: [], roles: [],
phone: null, phone: null,
password: null password: null
@@ -441,7 +439,7 @@ export default {
}) })
}, },
caseStatusColorFilter(isUsed) { caseStatusColorFilter(isUsed) {
if (isUsed === '1') { if (isUsed === true) {
return '#378be2' return '#378be2'
} }
return '#F56C6C' return '#F56C6C'
@@ -533,7 +531,7 @@ export default {
}, },
getDepts() { getDepts() {
console.log('获取部门') console.log('获取部门')
crudDept.getDepts({ isUsed: 1 }).then(res => { crudDept.getDepts({ isUsed: true }).then(res => {
console.log('获取的部门信息', res) console.log('获取的部门信息', res)
this.depts = res.content.map(function(obj) { this.depts = res.content.map(function(obj) {
@@ -565,7 +563,7 @@ export default {
// 获取弹窗内部门数据 // 获取弹窗内部门数据
loadDepts({ action, parentNode, callback }) { loadDepts({ action, parentNode, callback }) {
if (action === LOAD_CHILDREN_OPTIONS) { 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) { parentNode.children = res.content.map(function(obj) {
obj.children = null obj.children = null
return obj return obj