✨ 用户岗位关系

This commit is contained in:
付绪壮 committed 2022-03-26 16:57:16 +08:00
1 parent 1c246388e2
commit f3b91a2aef
10 files changed
+201

No files matched your search

+16
View File
@@ -100,6 +100,22 @@ INSERT INTO `sys_post` VALUES (1, 'CTO', 'CTO', 0, 'CTO', '0', '2022-03-26 13:48
INSERT INTO `sys_post` VALUES (2, 'CEO', 'CEO', 1, 'CEO', '0', '2022-03-26 13:48:27', '', '2022-03-26 13:48:38', '', 1);
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 CHARACTER = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '用户与岗位关联表';
-- ----------------------------
-- Records of sys_user_post
-- ----------------------------
BEGIN;
INSERT INTO `sys_user_post` VALUES (1, 1);
COMMIT;
-- ----------------------------
-- Table structure for sys_dict
@@ -48,6 +48,11 @@ public class UserDTO extends SysUser {
@ApiModelProperty(value = "部门id")
private Long deptId;
/**
* 岗位ID
*/
private List<Long> post;
/**
* 新密码
*/
@@ -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.pigx.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;
}
@@ -19,6 +19,7 @@
package com.pig4cloud.pigx.admin.api.vo;
import com.pig4cloud.pigx.admin.api.entity.SysPost;
import com.pig4cloud.pigx.admin.api.entity.SysRole;
import com.pig4cloud.pigx.common.core.sensitive.Sensitive;
import com.pig4cloud.pigx.common.core.sensitive.SensitiveTypeEnum;
@@ -137,6 +138,11 @@ public class UserVO implements Serializable {
@ApiModelProperty(value = "拥有的角色列表")
private List<SysRole> roleList;
/**
* 岗位列表
*/
private List<SysPost> postList;
/**
* 昵称
*/
@@ -49,6 +49,15 @@ public class SysPostController {
private final SysPostService sysPostService;
/**
* 获取岗位列表
* @return 岗位列表
*/
@GetMapping("/list")
public R<List<SysPost>> listPosts() {
return R.ok(sysPostService.list(Wrappers.emptyWrapper()));
}
/**
* 分页查询
* @param page 分页对象
@@ -21,6 +21,8 @@ import com.pig4cloud.pigx.admin.api.entity.SysPost;
import com.pig4cloud.pigx.common.data.datascope.PigxBaseMapper;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
/**
* 岗位信息表
*
@@ -30,4 +32,11 @@ import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface SysPostMapper extends PigxBaseMapper<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.pigx.admin.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.pig4cloud.pigx.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> {
}
@@ -32,6 +32,7 @@ import com.pig4cloud.pigx.admin.api.entity.*;
import com.pig4cloud.pigx.admin.api.vo.UserExcelVO;
import com.pig4cloud.pigx.admin.api.vo.UserVO;
import com.pig4cloud.pigx.admin.mapper.SysUserMapper;
import com.pig4cloud.pigx.admin.mapper.SysUserPostMapper;
import com.pig4cloud.pigx.admin.service.*;
import com.pig4cloud.pigx.common.core.constant.CacheConstants;
import com.pig4cloud.pigx.common.core.constant.CommonConstants;
@@ -74,6 +75,8 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
private final SysUserRoleService sysUserRoleService;
private final SysUserPostMapper sysUserPostMapper;
/**
* 保存用户信息
* @param userDto DTO 对象
@@ -87,6 +90,13 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
sysUser.setDelFlag(CommonConstants.STATUS_NORMAL);
sysUser.setPassword(ENCODER.encode(userDto.getPassword()));
baseMapper.insert(sysUser);
// 保存用户岗位信息
userDto.getPost().stream().map(postId -> {
SysUserPost userPost = new SysUserPost();
userPost.setUserId(sysUser.getUserId());
userPost.setPostId(postId);
return userPost;
}).forEach(sysUserPostMapper::insert);
List<SysUserRole> userRoleList = userDto.getRole().stream().map(roleId -> {
SysUserRole userRole = new SysUserRole();
userRole.setUserId(sysUser.getUserId());
@@ -199,6 +209,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;
}
@@ -0,0 +1,53 @@
<?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.pigx.admin.mapper.SysPostMapper">
<resultMap id="sysPostMap" type="com.pig4cloud.pigx.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="updateTime" column="update_time"/>
<result property="remark" column="remark"/>
</resultMap>
<!-- 通过用户ID,查询岗位信息-->
<select id="listPostsByUserId" resultType="com.pig4cloud.pigx.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.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>
@@ -43,6 +43,9 @@
<collection property="roleList" ofType="com.pig4cloud.pigx.admin.api.entity.SysRole"
select="com.pig4cloud.pigx.admin.mapper.SysRoleMapper.listRolesByUserId" column="user_id">
</collection>
<collection property="postList" ofType="com.pig4cloud.pigx.admin.api.entity.SysPost"
select="com.pig4cloud.pigx.admin.mapper.SysPostMapper.listPostsByUserId" column="user_id">
</collection>
</resultMap>
<!-- userVo结果集 -->