mirror of
https://gitee.com/log4j/pig.git
synced 2024-12-22 12:48:58 +08:00
!201 岗位管理
* Merge branch 'dev' of https://gitee.com/fxzcloud/pig into dev * ✨ 岗位管理
This commit is contained in:
parent
cf44f44b00
commit
aab6d2e932
39
db/pig.sql
39
db/pig.sql
@ -10,7 +10,7 @@ USE `pig`;
|
||||
-- ----------------------------
|
||||
-- Table structure for sys_dept
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `sys_dept`;
|
||||
DROP TABLE IF EXISTS `sys_dept` ;
|
||||
CREATE TABLE `sys_dept` (
|
||||
`dept_id` bigint NOT NULL,
|
||||
`name` varchar(50) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '部门名称',
|
||||
@ -309,6 +309,43 @@ INSERT INTO `sys_oauth_client_details` VALUES ('pig', NULL, 'pig', 'server', 'pa
|
||||
INSERT INTO `sys_oauth_client_details` VALUES ('test', NULL, 'test', 'server', 'password,app,refresh_token', NULL, NULL, NULL, NULL, NULL, 'true', NULL, NULL, NULL, NULL);
|
||||
COMMIT;
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for sys_post
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `sys_post`;
|
||||
CREATE TABLE `sys_post` (
|
||||
`post_id` bigint(0) NOT NULL AUTO_INCREMENT COMMENT '岗位ID',
|
||||
`post_code` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '岗位编码',
|
||||
`post_name` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '岗位名称',
|
||||
`post_sort` int(0) NOT NULL COMMENT '岗位排序',
|
||||
`del_flag` char(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '0' COMMENT '是否删除 -1:已删除 0:正常',
|
||||
`create_time` datetime(0) NULL DEFAULT NULL COMMENT '创建时间',
|
||||
`create_by` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '' COMMENT '创建人',
|
||||
`update_time` datetime(0) NULL DEFAULT NULL COMMENT '更新时间',
|
||||
`update_by` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '' COMMENT '更新人',
|
||||
`remark` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '备注信息',
|
||||
PRIMARY KEY (`post_id`) USING BTREE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC COMMENT = '岗位信息表';
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of sys_post
|
||||
-- ----------------------------
|
||||
BEGIN;
|
||||
INSERT INTO `sys_post` VALUES (1, 'user', '普通员工', 2, '0', '2022-03-19 10:05:15', 'admin', '2022-03-19 10:42:28', 'admin', '打工人');
|
||||
INSERT INTO `sys_post` VALUES (2, 'cto', 'cto', 0, '0', '2022-03-19 10:06:20', 'admin', '2022-03-19 10:06:20', 'admin', 'cto666');
|
||||
INSERT INTO `sys_post` VALUES (3, 'boss', '董事长', -1, '0', '2022-03-19 10:06:35', 'admin', '2022-03-19 10:42:44', 'admin', '大boss');
|
||||
COMMIT;
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for sys_user_post
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `sys_user_post`;
|
||||
CREATE TABLE `sys_user_post` (
|
||||
`user_id` bigint(0) NOT NULL COMMENT '用户ID',
|
||||
`post_id` bigint(0) NOT NULL COMMENT '岗位ID',
|
||||
PRIMARY KEY (`user_id`, `post_id`) USING BTREE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC COMMENT = '用户与岗位关联表';
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for sys_role
|
||||
-- ----------------------------
|
||||
|
@ -37,6 +37,11 @@ public class UserDTO extends SysUser {
|
||||
|
||||
private Long deptId;
|
||||
|
||||
/**
|
||||
* 岗位ID
|
||||
*/
|
||||
private List<Long> post;
|
||||
|
||||
/**
|
||||
* 新密码
|
||||
*/
|
||||
|
@ -16,6 +16,7 @@
|
||||
|
||||
package com.pig4cloud.pig.admin.api.dto;
|
||||
|
||||
import com.pig4cloud.pig.admin.api.entity.SysPost;
|
||||
import com.pig4cloud.pig.admin.api.entity.SysRole;
|
||||
import com.pig4cloud.pig.admin.api.entity.SysUser;
|
||||
import lombok.Data;
|
||||
@ -53,4 +54,14 @@ public class UserInfo implements Serializable {
|
||||
*/
|
||||
private List<SysRole> roleList;
|
||||
|
||||
/**
|
||||
* 岗位集合
|
||||
*/
|
||||
private Long[] posts;
|
||||
|
||||
/**
|
||||
* 岗位集合
|
||||
*/
|
||||
private List<SysPost> postList;
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2025, lengleng All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the pig4cloud.com developer nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
* Author: lengleng (wangiegie@gmail.com)
|
||||
*/
|
||||
package com.pig4cloud.pig.admin.api.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.pig4cloud.pig.common.mybatis.base.BaseEntity;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* 岗位管理
|
||||
*
|
||||
* @author fxz
|
||||
* @date 2022-03-15 17:18:40
|
||||
*/
|
||||
@Data
|
||||
@TableName("sys_post")
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ApiModel(value = "岗位信息表")
|
||||
public class SysPost extends BaseEntity {
|
||||
|
||||
private static final long serialVersionUID = -8744622014102311894L;
|
||||
|
||||
/**
|
||||
* 岗位ID
|
||||
*/
|
||||
@TableId(type = IdType.ASSIGN_ID)
|
||||
@ApiModelProperty(value = "岗位ID")
|
||||
private Long postId;
|
||||
|
||||
/**
|
||||
* 岗位编码
|
||||
*/
|
||||
@ApiModelProperty(value = "岗位编码")
|
||||
private String postCode;
|
||||
|
||||
/**
|
||||
* 岗位名称
|
||||
*/
|
||||
@ApiModelProperty(value = "岗位名称")
|
||||
private String postName;
|
||||
|
||||
/**
|
||||
* 岗位排序
|
||||
*/
|
||||
@ApiModelProperty(value = "岗位排序")
|
||||
private Integer postSort;
|
||||
|
||||
/**
|
||||
* 是否删除 -1:已删除 0:正常
|
||||
*/
|
||||
@ApiModelProperty(value = "是否删除 -1:已删除 0:正常")
|
||||
private String delFlag;
|
||||
|
||||
/**
|
||||
* 备注信息
|
||||
*/
|
||||
@ApiModelProperty(value = "备注信息")
|
||||
private String remark;
|
||||
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (c) 2020 pig4cloud Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.pig4cloud.pig.admin.api.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.activerecord.Model;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 用户岗位表
|
||||
* </p>
|
||||
*
|
||||
* @author fxz
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class SysUserPost extends Model<SysUserPost> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 用户ID
|
||||
*/
|
||||
@ApiModelProperty(value = "用户id")
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 岗位ID
|
||||
*/
|
||||
@ApiModelProperty(value = "岗位id")
|
||||
private Long postId;
|
||||
|
||||
}
|
@ -54,6 +54,13 @@ public class UserExcelVO implements Serializable {
|
||||
@ExcelProperty("角色")
|
||||
private String roleNameList;
|
||||
|
||||
/**
|
||||
* 岗位列表
|
||||
*/
|
||||
@NotBlank(message = "岗位不能为空")
|
||||
@ExcelProperty("岗位")
|
||||
private String postNameList;
|
||||
|
||||
/**
|
||||
* 锁定标记
|
||||
*/
|
||||
|
@ -16,6 +16,7 @@
|
||||
|
||||
package com.pig4cloud.pig.admin.api.vo;
|
||||
|
||||
import com.pig4cloud.pig.admin.api.entity.SysPost;
|
||||
import com.pig4cloud.pig.admin.api.entity.SysRole;
|
||||
import lombok.Data;
|
||||
|
||||
@ -97,4 +98,9 @@ public class UserVO implements Serializable {
|
||||
*/
|
||||
private List<SysRole> roleList;
|
||||
|
||||
/**
|
||||
* 岗位列表
|
||||
*/
|
||||
private List<SysPost> postList;
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,118 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2025, lengleng All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the pig4cloud.com developer nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
* Author: lengleng (wangiegie@gmail.com)
|
||||
*/
|
||||
|
||||
package com.pig4cloud.pig.admin.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.pig4cloud.pig.admin.api.entity.SysPost;
|
||||
import com.pig4cloud.pig.admin.service.SysPostService;
|
||||
import com.pig4cloud.pig.common.core.util.R;
|
||||
import com.pig4cloud.pig.common.log.annotation.SysLog;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author fxz
|
||||
* @date 2022-03-15 17:18:40
|
||||
*/
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/post")
|
||||
@Api(value = "post", tags = "岗位管理模块")
|
||||
public class PostController {
|
||||
|
||||
private final SysPostService sysPostService;
|
||||
|
||||
/**
|
||||
* 获取岗位列表
|
||||
* @return 岗位列表
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
public R<List<SysPost>> listPosts() {
|
||||
return R.ok(sysPostService.list(Wrappers.emptyWrapper()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
* @param page 分页对象
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "分页查询", notes = "分页查询")
|
||||
@GetMapping("/page")
|
||||
@PreAuthorize("@pms.hasPermission('sys_post_get')")
|
||||
public R getSysPostPage(Page page) {
|
||||
return R.ok(sysPostService.page(page, Wrappers.<SysPost>lambdaQuery().orderByAsc(SysPost::getPostSort)));
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id查询岗位信息表
|
||||
* @param postId id
|
||||
* @return R
|
||||
*/
|
||||
@ApiOperation(value = "通过id查询", notes = "通过id查询")
|
||||
@GetMapping("/{postId}")
|
||||
@PreAuthorize("@pms.hasPermission('sys_post_get')")
|
||||
public R getById(@PathVariable("postId") Long postId) {
|
||||
return R.ok(sysPostService.getById(postId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增岗位信息表
|
||||
* @param sysPost 岗位信息表
|
||||
* @return R
|
||||
*/
|
||||
@ApiOperation(value = "新增岗位信息表", notes = "新增岗位信息表")
|
||||
@SysLog("新增岗位信息表")
|
||||
@PostMapping
|
||||
@PreAuthorize("@pms.hasPermission('sys_post_add')")
|
||||
public R save(@RequestBody SysPost sysPost) {
|
||||
return R.ok(sysPostService.save(sysPost));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改岗位信息表
|
||||
* @param sysPost 岗位信息表
|
||||
* @return R
|
||||
*/
|
||||
@ApiOperation(value = "修改岗位信息表", notes = "修改岗位信息表")
|
||||
@SysLog("修改岗位信息表")
|
||||
@PutMapping
|
||||
@PreAuthorize("@pms.hasPermission('sys_post_edit')")
|
||||
public R updateById(@RequestBody SysPost sysPost) {
|
||||
return R.ok(sysPostService.updateById(sysPost));
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id删除岗位信息表
|
||||
* @param postId id
|
||||
* @return R
|
||||
*/
|
||||
@ApiOperation(value = "通过id删除岗位信息表", notes = "通过id删除岗位信息表")
|
||||
@SysLog("通过id删除岗位信息表")
|
||||
@DeleteMapping("/{postId}")
|
||||
@PreAuthorize("@pms.hasPermission('sys_post_del')")
|
||||
public R removeById(@PathVariable Long postId) {
|
||||
return R.ok(sysPostService.removeById(postId));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2025, lengleng All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the pig4cloud.com developer nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
* Author: lengleng (wangiegie@gmail.com)
|
||||
*/
|
||||
|
||||
package com.pig4cloud.pig.admin.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.pig4cloud.pig.admin.api.entity.SysPost;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 岗位管理表 mapper接口
|
||||
*
|
||||
* @author fxz
|
||||
* @date 2022-03-15 17:18:40
|
||||
*/
|
||||
@Mapper
|
||||
public interface SysPostMapper extends BaseMapper<SysPost> {
|
||||
|
||||
/**
|
||||
* 通过用户ID,查询岗位信息
|
||||
* @param userId 用户id
|
||||
* @return 岗位信息
|
||||
*/
|
||||
List<SysPost> listPostsByUserId(Long userId);
|
||||
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright (c) 2020 pig4cloud Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.pig4cloud.pig.admin.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.pig4cloud.pig.admin.api.entity.SysUserPost;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 用户岗位 Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author fxz
|
||||
* @since 2022/3/19
|
||||
*/
|
||||
@Mapper
|
||||
public interface SysUserPostMapper extends BaseMapper<SysUserPost> {
|
||||
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2025, lengleng All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the pig4cloud.com developer nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
* Author: lengleng (wangiegie@gmail.com)
|
||||
*/
|
||||
|
||||
package com.pig4cloud.pig.admin.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.pig4cloud.pig.admin.api.entity.SysPost;
|
||||
|
||||
/**
|
||||
* 岗位管理 服务类
|
||||
*
|
||||
* @author fxz
|
||||
* @date 2022-03-15 17:18:40
|
||||
*/
|
||||
public interface SysPostService extends IService<SysPost> {
|
||||
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2025, lengleng All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the pig4cloud.com developer nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
* Author: lengleng (wangiegie@gmail.com)
|
||||
*/
|
||||
package com.pig4cloud.pig.admin.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.pig4cloud.pig.admin.api.entity.SysPost;
|
||||
import com.pig4cloud.pig.admin.mapper.SysPostMapper;
|
||||
import com.pig4cloud.pig.admin.service.SysPostService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 岗位管理表 服务实现类
|
||||
*
|
||||
* @author pig code generator
|
||||
* @date 2022-03-15 17:18:40
|
||||
*/
|
||||
@Service
|
||||
public class SysPostServiceImpl extends ServiceImpl<SysPostMapper, SysPost> implements SysPostService {
|
||||
|
||||
}
|
@ -28,10 +28,7 @@ import com.pig4cloud.pig.admin.api.dto.UserInfo;
|
||||
import com.pig4cloud.pig.admin.api.entity.*;
|
||||
import com.pig4cloud.pig.admin.api.vo.UserExcelVO;
|
||||
import com.pig4cloud.pig.admin.api.vo.UserVO;
|
||||
import com.pig4cloud.pig.admin.mapper.SysDeptMapper;
|
||||
import com.pig4cloud.pig.admin.mapper.SysRoleMapper;
|
||||
import com.pig4cloud.pig.admin.mapper.SysUserMapper;
|
||||
import com.pig4cloud.pig.admin.mapper.SysUserRoleMapper;
|
||||
import com.pig4cloud.pig.admin.mapper.*;
|
||||
import com.pig4cloud.pig.admin.service.SysMenuService;
|
||||
import com.pig4cloud.pig.admin.service.SysUserService;
|
||||
import com.pig4cloud.pig.common.core.constant.CacheConstants;
|
||||
@ -71,8 +68,12 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
||||
|
||||
private final SysMenuService sysMenuService;
|
||||
|
||||
private final SysPostMapper sysPostMapper;
|
||||
|
||||
private final SysUserRoleMapper sysUserRoleMapper;
|
||||
|
||||
private final SysUserPostMapper sysUserPostMapper;
|
||||
|
||||
/**
|
||||
* 保存用户信息
|
||||
* @param userDto DTO 对象
|
||||
@ -92,6 +93,13 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
||||
userRole.setRoleId(roleId);
|
||||
return userRole;
|
||||
}).forEach(sysUserRoleMapper::insert);
|
||||
// 保存用户岗位信息
|
||||
userDto.getPost().stream().map(postId -> {
|
||||
SysUserPost userPost = new SysUserPost();
|
||||
userPost.setUserId(sysUser.getUserId());
|
||||
userPost.setPostId(postId);
|
||||
return userPost;
|
||||
}).forEach(sysUserPostMapper::insert);
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
|
||||
@ -110,6 +118,9 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
||||
// 设置角色列表 (ID)
|
||||
List<Long> roleIds = roleList.stream().map(SysRole::getRoleId).collect(Collectors.toList());
|
||||
userInfo.setRoles(ArrayUtil.toArray(roleIds, Long.class));
|
||||
// 设置岗位列表
|
||||
List<SysPost> postList = sysPostMapper.listPostsByUserId(sysUser.getUserId());
|
||||
userInfo.setPostList(postList);
|
||||
// 设置权限列表(menu.permission)
|
||||
Set<String> permissions = roleIds.stream().map(sysMenuService::findMenuByRoleId).flatMap(Collection::stream)
|
||||
.filter(m -> MenuTypeEnum.BUTTON.getType().equals(m.getType())).map(SysMenu::getPermission)
|
||||
@ -191,6 +202,13 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
||||
userRole.setRoleId(roleId);
|
||||
userRole.insert();
|
||||
});
|
||||
sysUserPostMapper.delete(Wrappers.<SysUserPost>lambdaQuery().eq(SysUserPost::getUserId, userDto.getUserId()));
|
||||
userDto.getPost().forEach(postId -> {
|
||||
SysUserPost userPost = new SysUserPost();
|
||||
userPost.setUserId(sysUser.getUserId());
|
||||
userPost.setPostId(postId);
|
||||
userPost.insert();
|
||||
});
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
|
||||
@ -227,6 +245,9 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
||||
String roleNameList = userVO.getRoleList().stream().map(SysRole::getRoleName)
|
||||
.collect(Collectors.joining(StrUtil.COMMA));
|
||||
excelVO.setRoleNameList(roleNameList);
|
||||
String postNameList = userVO.getPostList().stream().map(SysPost::getPostName)
|
||||
.collect(Collectors.joining(StrUtil.COMMA));
|
||||
excelVO.setPostNameList(postNameList);
|
||||
return excelVO;
|
||||
}).collect(Collectors.toList());
|
||||
return userExcelVOList;
|
||||
@ -247,6 +268,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
||||
List<SysUser> userList = this.list();
|
||||
List<SysDept> deptList = sysDeptMapper.selectList(Wrappers.emptyWrapper());
|
||||
List<SysRole> roleList = sysRoleMapper.selectList(Wrappers.emptyWrapper());
|
||||
List<SysPost> postList = sysPostMapper.selectList(Wrappers.emptyWrapper());
|
||||
|
||||
// 执行数据插入操作 组装 UserDto
|
||||
for (int i = 0; i < excelVOList.size(); i++) {
|
||||
@ -277,9 +299,19 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
||||
errorMsg.add(String.format("%s 角色名称不存在", excel.getRoleNameList()));
|
||||
}
|
||||
|
||||
// 判断输入的岗位名称列表是否合法
|
||||
List<String> postNameList = StrUtil.split(excel.getPostNameList(), StrUtil.COMMA);
|
||||
List<SysPost> postCollList = postList.stream()
|
||||
.filter(post -> postNameList.stream().anyMatch(name -> post.getPostName().equals(name)))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
if (postCollList.size() != postNameList.size()) {
|
||||
errorMsg.add(String.format("%s 岗位名称不存在", excel.getPostNameList()));
|
||||
}
|
||||
|
||||
// 数据合法情况
|
||||
if (CollUtil.isEmpty(errorMsg)) {
|
||||
insertExcelUser(excel, deptOptional, roleCollList);
|
||||
insertExcelUser(excel, deptOptional, roleCollList, postCollList);
|
||||
}
|
||||
else {
|
||||
// 数据不合法情况
|
||||
@ -304,7 +336,8 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
||||
/**
|
||||
* 插入excel User
|
||||
*/
|
||||
private void insertExcelUser(UserExcelVO excel, Optional<SysDept> deptOptional, List<SysRole> roleCollList) {
|
||||
private void insertExcelUser(UserExcelVO excel, Optional<SysDept> deptOptional, List<SysRole> roleCollList,
|
||||
List<SysPost> postCollList) {
|
||||
UserDTO userDTO = new UserDTO();
|
||||
userDTO.setUsername(excel.getUsername());
|
||||
userDTO.setPhone(excel.getPhone());
|
||||
@ -315,6 +348,8 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
||||
// 根据角色名称查询角色ID
|
||||
List<Long> roleIdList = roleCollList.stream().map(SysRole::getRoleId).collect(Collectors.toList());
|
||||
userDTO.setRole(roleIdList);
|
||||
List<Long> postIdList = postCollList.stream().map(SysPost::getPostId).collect(Collectors.toList());
|
||||
userDTO.setPost(postIdList);
|
||||
// 插入用户
|
||||
this.saveUser(userDTO);
|
||||
}
|
||||
|
Binary file not shown.
@ -0,0 +1,58 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<!--
|
||||
~
|
||||
~ Copyright (c) 2018-2025, lengleng All rights reserved.
|
||||
~
|
||||
~ Redistribution and use in source and binary forms, with or without
|
||||
~ modification, are permitted provided that the following conditions are met:
|
||||
~
|
||||
~ Redistributions of source code must retain the above copyright notice,
|
||||
~ this list of conditions and the following disclaimer.
|
||||
~ Redistributions in binary form must reproduce the above copyright
|
||||
~ notice, this list of conditions and the following disclaimer in the
|
||||
~ documentation and/or other materials provided with the distribution.
|
||||
~ Neither the name of the pig4cloud.com developer nor the names of its
|
||||
~ contributors may be used to endorse or promote products derived from
|
||||
~ this software without specific prior written permission.
|
||||
~ Author: lengleng (wangiegie@gmail.com)
|
||||
~
|
||||
-->
|
||||
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
|
||||
<mapper namespace="com.pig4cloud.pig.admin.mapper.SysPostMapper">
|
||||
|
||||
<resultMap id="sysPostMap" type="com.pig4cloud.pig.admin.api.entity.SysPost">
|
||||
<id property="postId" column="post_id"/>
|
||||
<result property="postCode" column="post_code"/>
|
||||
<result property="postName" column="post_name"/>
|
||||
<result property="postSort" column="post_sort"/>
|
||||
<result property="delFlag" column="del_flag"/>
|
||||
<result property="createTime" column="create_time"/>
|
||||
<result property="createBy" column="create_by"/>
|
||||
<result property="updateTime" column="update_time"/>
|
||||
<result property="updateBy" column="update_by"/>
|
||||
<result property="remark" column="remark"/>
|
||||
</resultMap>
|
||||
|
||||
<!-- 通过用户ID,查询岗位信息-->
|
||||
<select id="listPostsByUserId" resultType="com.pig4cloud.pig.admin.api.entity.SysPost">
|
||||
SELECT p.post_id,
|
||||
p.post_name,
|
||||
p.post_code,
|
||||
p.post_sort,
|
||||
p.del_flag,
|
||||
p.create_time,
|
||||
p.update_time,
|
||||
p.update_by,
|
||||
p.create_by,
|
||||
p.remark
|
||||
FROM sys_post p,
|
||||
sys_user_post up
|
||||
WHERE p.post_id = up.post_id
|
||||
AND p.del_flag = 0
|
||||
and up.user_id = #{userId}
|
||||
</select>
|
||||
|
||||
</mapper>
|
@ -34,6 +34,9 @@
|
||||
<collection property="roleList" ofType="com.pig4cloud.pig.admin.api.entity.SysRole"
|
||||
select="com.pig4cloud.pig.admin.mapper.SysRoleMapper.listRolesByUserId" column="user_id">
|
||||
</collection>
|
||||
<collection property="postList" ofType="com.pig4cloud.pig.admin.api.entity.SysPost"
|
||||
select="com.pig4cloud.pig.admin.mapper.SysPostMapper.listPostsByUserId" column="user_id">
|
||||
</collection>
|
||||
</resultMap>
|
||||
|
||||
<!-- userVo结果集 -->
|
||||
|
Loading…
Reference in New Issue
Block a user