mirror of
http://git.pig4cloud.com/pig/pigx.git
synced 2026-11-11 21:29:02 +08:00
♻️ 重构代码。 角色部门重构,角色、部门不关联
This commit is contained in:
1 parent
ee0b292d50
commit
853255f3fb
22 files changed
+44
-551
No files matched your search
@@ -1,43 +0,0 @@
|
||||
/*
|
||||
*
|
||||
* 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.pigx.admin.api.dto;
|
||||
|
||||
import com.pig4cloud.pigx.admin.api.entity.SysRole;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* @author lengleng
|
||||
* @date 2018/1/20
|
||||
* 角色Dto
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class RoleDTO extends SysRole {
|
||||
/**
|
||||
* 角色部门Id
|
||||
*/
|
||||
private Integer roleDeptId;
|
||||
|
||||
/**
|
||||
* 部门名称
|
||||
*/
|
||||
private String deptName;
|
||||
}
|
||||
-63
@@ -1,63 +0,0 @@
|
||||
/*
|
||||
*
|
||||
* 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.pigx.admin.api.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.activerecord.Model;
|
||||
import com.baomidou.mybatisplus.annotations.TableId;
|
||||
import com.baomidou.mybatisplus.annotations.TableName;
|
||||
import com.baomidou.mybatisplus.enums.IdType;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 角色与部门对应关系
|
||||
* </p>
|
||||
*
|
||||
* @author lengleng
|
||||
* @since 2018-01-20
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName("sys_role_dept")
|
||||
public class SysRoleDept extends Model<SysRoleDept> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Integer id;
|
||||
/**
|
||||
* 角色ID
|
||||
*/
|
||||
private Integer roleId;
|
||||
/**
|
||||
* 部门ID
|
||||
*/
|
||||
private Integer deptId;
|
||||
|
||||
|
||||
@Override
|
||||
protected Serializable pkVal() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
}
|
||||
+1
-1
@@ -42,8 +42,8 @@ import java.util.List;
|
||||
* @since 2018-01-20
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/dept")
|
||||
@AllArgsConstructor
|
||||
@RequestMapping("/dept")
|
||||
public class DeptController {
|
||||
private final SysDeptService sysDeptService;
|
||||
|
||||
|
||||
+3
-3
@@ -28,7 +28,7 @@ import com.pig4cloud.pigx.common.core.constant.CommonConstant;
|
||||
import com.pig4cloud.pigx.common.core.util.Query;
|
||||
import com.pig4cloud.pigx.common.core.util.R;
|
||||
import com.pig4cloud.pigx.common.log.annotation.SysLog;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
@@ -47,10 +47,10 @@ import java.util.Map;
|
||||
* @since 2017-11-19
|
||||
*/
|
||||
@RestController
|
||||
@AllArgsConstructor
|
||||
@RequestMapping("/dict" )
|
||||
public class DictController {
|
||||
@Autowired
|
||||
private SysDictService sysDictService;
|
||||
private final SysDictService sysDictService;
|
||||
|
||||
/**
|
||||
* 通过ID查询字典信息
|
||||
|
||||
+3
-3
@@ -28,7 +28,7 @@ import com.pig4cloud.pigx.admin.service.SysMenuService;
|
||||
import com.pig4cloud.pigx.common.core.constant.CommonConstant;
|
||||
import com.pig4cloud.pigx.common.core.util.R;
|
||||
import com.pig4cloud.pigx.common.security.util.SecurityUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@@ -44,10 +44,10 @@ import java.util.stream.Collectors;
|
||||
* @date 2017/10/31
|
||||
*/
|
||||
@RestController
|
||||
@AllArgsConstructor
|
||||
@RequestMapping("/menu")
|
||||
public class MenuController {
|
||||
@Autowired
|
||||
private SysMenuService sysMenuService;
|
||||
private final SysMenuService sysMenuService;
|
||||
|
||||
/**
|
||||
* 返回当前用户的树形菜单集合
|
||||
|
||||
+3
-3
@@ -25,7 +25,7 @@ import com.pig4cloud.pigx.admin.api.entity.SysOauthClientDetails;
|
||||
import com.pig4cloud.pigx.admin.service.SysOauthClientDetailsService;
|
||||
import com.pig4cloud.pigx.common.core.util.Query;
|
||||
import com.pig4cloud.pigx.common.core.util.R;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@@ -41,10 +41,10 @@ import java.util.Map;
|
||||
* @since 2018-05-15
|
||||
*/
|
||||
@RestController
|
||||
@AllArgsConstructor
|
||||
@RequestMapping("/client")
|
||||
public class OauthClientDetailsController {
|
||||
@Autowired
|
||||
private SysOauthClientDetailsService sysOauthClientDetailsService;
|
||||
private final SysOauthClientDetailsService sysOauthClientDetailsService;
|
||||
|
||||
/**
|
||||
* 通过ID查询
|
||||
|
||||
+14
-17
@@ -21,14 +21,13 @@ package com.pig4cloud.pigx.admin.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
||||
import com.baomidou.mybatisplus.plugins.Page;
|
||||
import com.pig4cloud.pigx.admin.api.dto.RoleDTO;
|
||||
import com.pig4cloud.pigx.admin.api.entity.SysRole;
|
||||
import com.pig4cloud.pigx.admin.service.SysRoleMenuService;
|
||||
import com.pig4cloud.pigx.admin.service.SysRoleService;
|
||||
import com.pig4cloud.pigx.common.core.constant.CommonConstant;
|
||||
import com.pig4cloud.pigx.common.core.util.Query;
|
||||
import com.pig4cloud.pigx.common.core.util.R;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@@ -40,12 +39,11 @@ import java.util.Map;
|
||||
* @date 2017/11/5
|
||||
*/
|
||||
@RestController
|
||||
@AllArgsConstructor
|
||||
@RequestMapping("/role")
|
||||
public class RoleController {
|
||||
@Autowired
|
||||
private SysRoleService sysRoleService;
|
||||
@Autowired
|
||||
private SysRoleMenuService sysRoleMenuService;
|
||||
private final SysRoleService sysRoleService;
|
||||
private final SysRoleMenuService sysRoleMenuService;
|
||||
|
||||
/**
|
||||
* 通过ID查询角色信息
|
||||
@@ -61,25 +59,25 @@ public class RoleController {
|
||||
/**
|
||||
* 添加角色
|
||||
*
|
||||
* @param roleDto 角色信息
|
||||
* @param sysRole 角色信息
|
||||
* @return success、false
|
||||
*/
|
||||
@PostMapping
|
||||
@PreAuthorize("@pms.hasPermission('sys_role_add')")
|
||||
public R<Boolean> role(@RequestBody RoleDTO roleDto) {
|
||||
return new R<>(sysRoleService.insertRole(roleDto));
|
||||
public R<Boolean> role(@RequestBody SysRole sysRole) {
|
||||
return new R<>(sysRoleService.insert(sysRole));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改角色
|
||||
*
|
||||
* @param roleDto 角色信息
|
||||
* @param sysRole 角色信息
|
||||
* @return success/false
|
||||
*/
|
||||
@PutMapping
|
||||
@PreAuthorize("@pms.hasPermission('sys_role_edit')")
|
||||
public R<Boolean> roleUpdate(@RequestBody RoleDTO roleDto) {
|
||||
return new R<>(sysRoleService.updateRoleById(roleDto));
|
||||
public R<Boolean> roleUpdate(@RequestBody SysRole sysRole) {
|
||||
return new R<>(sysRoleService.updateById(sysRole));
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
@@ -93,12 +91,11 @@ public class RoleController {
|
||||
/**
|
||||
* 获取角色列表
|
||||
*
|
||||
* @param deptId 部门ID
|
||||
* @return 角色列表
|
||||
*/
|
||||
@GetMapping("/roleList/{deptId}")
|
||||
public List<SysRole> roleList(@PathVariable Integer deptId) {
|
||||
return sysRoleService.selectListByDeptId(deptId);
|
||||
@GetMapping("/roleList")
|
||||
public List<SysRole> roleList() {
|
||||
return sysRoleService.selectList(new EntityWrapper<>());
|
||||
|
||||
}
|
||||
|
||||
@@ -110,7 +107,7 @@ public class RoleController {
|
||||
*/
|
||||
@GetMapping("/rolePage")
|
||||
public Page rolePage(@RequestParam Map<String, Object> params) {
|
||||
return sysRoleService.selectwithDeptPage(new Query<>(params), new EntityWrapper<>());
|
||||
return sysRoleService.selectPage(new Query<>(params), new EntityWrapper<>());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+14
-5
@@ -20,6 +20,7 @@
|
||||
package com.pig4cloud.pigx.admin.controller;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
||||
import com.baomidou.mybatisplus.plugins.Page;
|
||||
import com.pig4cloud.pigx.admin.api.dto.UserDTO;
|
||||
import com.pig4cloud.pigx.admin.api.dto.UserInfo;
|
||||
@@ -92,6 +93,19 @@ public class UserController {
|
||||
return userService.selectUserVoById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据用户名查询用户信息
|
||||
*
|
||||
* @param username 用户名
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/details/{username}")
|
||||
public R<SysUser> user(@PathVariable String username) {
|
||||
SysUser condition = new SysUser();
|
||||
condition.setUsername(username);
|
||||
return new R<>(userService.selectOne(new EntityWrapper<>(condition)));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除用户信息
|
||||
*
|
||||
@@ -110,7 +124,6 @@ public class UserController {
|
||||
|
||||
/**
|
||||
* 添加用户
|
||||
* TODO 什么鬼逻辑,先删除再增加???
|
||||
*
|
||||
* @param userDto 用户信息
|
||||
* @return success/false
|
||||
@@ -119,10 +132,6 @@ public class UserController {
|
||||
@PostMapping
|
||||
@PreAuthorize("@pms.hasPermission('sys_user_add')")
|
||||
public R<Boolean> user(@RequestBody UserDTO userDto) {
|
||||
SysUser deletedUser = userService.selectDeletedUserByUsername(userDto.getUsername());
|
||||
if (deletedUser != null) {
|
||||
userService.deleteSysUserByUsernameAndUserId(userDto.getUsername(), deletedUser.getUserId());
|
||||
}
|
||||
SysUser sysUser = new SysUser();
|
||||
BeanUtils.copyProperties(userDto, sysUser);
|
||||
sysUser.setDelFlag(CommonConstant.STATUS_NORMAL);
|
||||
|
||||
-35
@@ -1,35 +0,0 @@
|
||||
/*
|
||||
*
|
||||
* 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.pigx.admin.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.mapper.BaseMapper;
|
||||
import com.pig4cloud.pigx.admin.api.entity.SysRoleDept;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 角色与部门对应关系 Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author lengleng
|
||||
* @since 2018-01-20
|
||||
*/
|
||||
public interface SysRoleDeptMapper extends BaseMapper<SysRoleDept> {
|
||||
|
||||
}
|
||||
-20
@@ -21,10 +21,8 @@ package com.pig4cloud.pigx.admin.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.mapper.BaseMapper;
|
||||
import com.pig4cloud.pigx.admin.api.entity.SysRole;
|
||||
import com.pig4cloud.pigx.common.core.util.Query;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -35,24 +33,6 @@ import java.util.Map;
|
||||
* @since 2017-10-29
|
||||
*/
|
||||
public interface SysRoleMapper extends BaseMapper<SysRole> {
|
||||
|
||||
/**
|
||||
* 查询角色列表含有部门信息
|
||||
*
|
||||
* @param query 查询对象
|
||||
* @param condition 条件
|
||||
* @return List
|
||||
*/
|
||||
List<Object> selectRolePage(Query<Object> query, Map<String, Object> condition);
|
||||
|
||||
/**
|
||||
* 通过部门ID查询角色列表
|
||||
*
|
||||
* @param deptId 部门ID
|
||||
* @return 角色列表
|
||||
*/
|
||||
List<SysRole> selectListByDeptId(Integer deptId);
|
||||
|
||||
/**
|
||||
* 通过用户ID,查询角色信息
|
||||
*
|
||||
|
||||
-18
@@ -62,22 +62,4 @@ public interface SysUserMapper extends BaseMapper<SysUser> {
|
||||
* @return userVo
|
||||
*/
|
||||
UserVO selectUserVoById(Integer id);
|
||||
|
||||
/**
|
||||
* 通过用户名查找已经删除的用户
|
||||
*
|
||||
* @param username 用户名
|
||||
* @return 用户对象
|
||||
*/
|
||||
SysUser selectDeletedUserByUsername(@Param("username") String username);
|
||||
|
||||
/**
|
||||
* 根据用户名删除用户(真实删除)
|
||||
*
|
||||
* @param username username
|
||||
* @param userId userId
|
||||
* @return
|
||||
*/
|
||||
Boolean deleteSysUserByUsernameAndUserId(@Param("username") String username, @Param("userId") Integer userId);
|
||||
|
||||
}
|
||||
-35
@@ -1,35 +0,0 @@
|
||||
/*
|
||||
*
|
||||
* 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.pigx.admin.service;
|
||||
|
||||
import com.baomidou.mybatisplus.service.IService;
|
||||
import com.pig4cloud.pigx.admin.api.entity.SysRoleDept;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 角色与部门对应关系 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author lengleng
|
||||
* @since 2018-01-20
|
||||
*/
|
||||
public interface SysRoleDeptService extends IService<SysRoleDept> {
|
||||
|
||||
}
|
||||
-37
@@ -19,12 +19,8 @@
|
||||
|
||||
package com.pig4cloud.pigx.admin.service;
|
||||
|
||||
import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
||||
import com.baomidou.mybatisplus.plugins.Page;
|
||||
import com.baomidou.mybatisplus.service.IService;
|
||||
import com.pig4cloud.pigx.admin.api.dto.RoleDTO;
|
||||
import com.pig4cloud.pigx.admin.api.entity.SysRole;
|
||||
import com.pig4cloud.pigx.common.core.util.Query;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -38,39 +34,6 @@ import java.util.List;
|
||||
*/
|
||||
public interface SysRoleService extends IService<SysRole> {
|
||||
|
||||
/**
|
||||
* 添加角色
|
||||
*
|
||||
* @param roleDto 角色信息
|
||||
* @return 成功、失败
|
||||
*/
|
||||
Boolean insertRole(RoleDTO roleDto);
|
||||
|
||||
/**
|
||||
* 分页查角色列表
|
||||
*
|
||||
* @param objectQuery 查询条件
|
||||
* @param objectEntityWrapper wapper
|
||||
* @return page
|
||||
*/
|
||||
Page selectwithDeptPage(Query<Object> objectQuery, EntityWrapper<Object> objectEntityWrapper);
|
||||
|
||||
/**
|
||||
* 更新角色
|
||||
*
|
||||
* @param roleDto 含有部门信息
|
||||
* @return 成功、失败
|
||||
*/
|
||||
Boolean updateRoleById(RoleDTO roleDto);
|
||||
|
||||
/**
|
||||
* 通过部门ID查询角色列表
|
||||
*
|
||||
* @param deptId 部门ID
|
||||
* @return 角色列表
|
||||
*/
|
||||
List<SysRole> selectListByDeptId(Integer deptId);
|
||||
|
||||
/**
|
||||
* 通过用户ID,查询角色信息
|
||||
*
|
||||
|
||||
-17
@@ -87,23 +87,6 @@ public interface SysUserService extends IService<SysUser> {
|
||||
*/
|
||||
UserVO selectUserVoById(Integer id);
|
||||
|
||||
/**
|
||||
* 通过用户名查找已经删除的用户
|
||||
*
|
||||
* @param username 用户名
|
||||
* @return
|
||||
*/
|
||||
SysUser selectDeletedUserByUsername(String username);
|
||||
|
||||
/**
|
||||
* 根据用户名删除用户(真实删除)
|
||||
*
|
||||
* @param username username
|
||||
* @param userId userId
|
||||
* @return
|
||||
*/
|
||||
Boolean deleteSysUserByUsernameAndUserId(String username, Integer userId);
|
||||
|
||||
/**
|
||||
* 查询上级部门的用户信息
|
||||
*
|
||||
|
||||
+1
-4
@@ -26,7 +26,6 @@ import com.pig4cloud.pigx.admin.api.vo.MenuVO;
|
||||
import com.pig4cloud.pigx.admin.mapper.SysMenuMapper;
|
||||
import com.pig4cloud.pigx.admin.service.SysMenuService;
|
||||
import com.pig4cloud.pigx.common.core.constant.CommonConstant;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -43,13 +42,11 @@ import java.util.List;
|
||||
*/
|
||||
@Service
|
||||
public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> implements SysMenuService {
|
||||
@Autowired
|
||||
private SysMenuMapper sysMenuMapper;
|
||||
|
||||
@Override
|
||||
@Cacheable(value = "menu_details", key = "#roleId + '_menu'")
|
||||
public List<MenuVO> findMenuByRoleId(Integer roleId) {
|
||||
return sysMenuMapper.findMenuByRoleId(roleId);
|
||||
return baseMapper.findMenuByRoleId(roleId);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
-39
@@ -1,39 +0,0 @@
|
||||
/*
|
||||
*
|
||||
* 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.pigx.admin.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
|
||||
import com.pig4cloud.pigx.admin.api.entity.SysRoleDept;
|
||||
import com.pig4cloud.pigx.admin.mapper.SysRoleDeptMapper;
|
||||
import com.pig4cloud.pigx.admin.service.SysRoleDeptService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 角色与部门对应关系 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author lengleng
|
||||
* @since 2018-01-20
|
||||
*/
|
||||
@Service
|
||||
public class SysRoleDeptServiceImpl extends ServiceImpl<SysRoleDeptMapper, SysRoleDept> implements SysRoleDeptService {
|
||||
|
||||
}
|
||||
+1
-1
@@ -45,7 +45,7 @@ import java.util.stream.Collectors;
|
||||
@Service
|
||||
@AllArgsConstructor
|
||||
public class SysRoleMenuServiceImpl extends ServiceImpl<SysRoleMenuMapper, SysRoleMenu> implements SysRoleMenuService {
|
||||
private CacheManager cacheManager;
|
||||
private final CacheManager cacheManager;
|
||||
|
||||
/**
|
||||
* @param role
|
||||
|
||||
+1
-83
@@ -19,20 +19,11 @@
|
||||
|
||||
package com.pig4cloud.pigx.admin.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
||||
import com.baomidou.mybatisplus.plugins.Page;
|
||||
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
|
||||
import com.pig4cloud.pigx.admin.api.dto.RoleDTO;
|
||||
import com.pig4cloud.pigx.admin.api.entity.SysRole;
|
||||
import com.pig4cloud.pigx.admin.api.entity.SysRoleDept;
|
||||
import com.pig4cloud.pigx.admin.mapper.SysRoleDeptMapper;
|
||||
import com.pig4cloud.pigx.admin.mapper.SysRoleMapper;
|
||||
import com.pig4cloud.pigx.admin.service.SysRoleService;
|
||||
import com.pig4cloud.pigx.common.core.util.Query;
|
||||
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.List;
|
||||
|
||||
@@ -46,79 +37,6 @@ import java.util.List;
|
||||
*/
|
||||
@Service
|
||||
public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> implements SysRoleService {
|
||||
@Autowired
|
||||
private SysRoleDeptMapper sysRoleDeptMapper;
|
||||
@Autowired
|
||||
private SysRoleMapper sysRoleMapper;
|
||||
|
||||
/**
|
||||
* 添加角色
|
||||
*
|
||||
* @param roleDto 角色信息
|
||||
* @return 成功、失败
|
||||
*/
|
||||
@Override
|
||||
public Boolean insertRole(RoleDTO roleDto) {
|
||||
SysRole sysRole = new SysRole();
|
||||
BeanUtils.copyProperties(roleDto, sysRole);
|
||||
sysRoleMapper.insert(sysRole);
|
||||
SysRoleDept roleDept = new SysRoleDept();
|
||||
roleDept.setRoleId(sysRole.getRoleId());
|
||||
roleDept.setDeptId(roleDto.getRoleDeptId());
|
||||
sysRoleDeptMapper.insert(roleDept);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查角色列表
|
||||
*
|
||||
* @param query 查询条件
|
||||
* @param wrapper wapper
|
||||
* @return page
|
||||
*/
|
||||
@Override
|
||||
public Page selectwithDeptPage(Query<Object> query, EntityWrapper<Object> wrapper) {
|
||||
query.setRecords(sysRoleMapper.selectRolePage(query, query.getCondition()));
|
||||
return query;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新角色
|
||||
*
|
||||
* @param roleDto 含有部门信息
|
||||
* @return 成功、失败
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public Boolean updateRoleById(RoleDTO roleDto) {
|
||||
//删除原有的角色部门关系
|
||||
SysRoleDept condition = new SysRoleDept();
|
||||
condition.setRoleId(roleDto.getRoleId());
|
||||
sysRoleDeptMapper.delete(new EntityWrapper<>(condition));
|
||||
|
||||
//更新角色信息
|
||||
SysRole sysRole = new SysRole();
|
||||
BeanUtils.copyProperties(roleDto, sysRole);
|
||||
sysRoleMapper.updateById(sysRole);
|
||||
|
||||
//维护角色部门关系
|
||||
SysRoleDept roleDept = new SysRoleDept();
|
||||
roleDept.setRoleId(sysRole.getRoleId());
|
||||
roleDept.setDeptId(roleDto.getRoleDeptId());
|
||||
sysRoleDeptMapper.insert(roleDept);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过部门ID查询角色列表
|
||||
*
|
||||
* @param deptId 部门ID
|
||||
* @return 角色列表
|
||||
*/
|
||||
@Override
|
||||
public List<SysRole> selectListByDeptId(Integer deptId) {
|
||||
return sysRoleMapper.selectListByDeptId(deptId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过用户ID,查询角色信息
|
||||
@@ -128,6 +46,6 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
|
||||
*/
|
||||
@Override
|
||||
public List<SysRole> findRolesByUserId(Integer userId) {
|
||||
return sysRoleMapper.findRolesByUserId(userId);
|
||||
return baseMapper.findRolesByUserId(userId);
|
||||
}
|
||||
}
|
||||
+3
-30
@@ -62,7 +62,6 @@ import java.util.stream.Collectors;
|
||||
public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> implements SysUserService {
|
||||
private static final PasswordEncoder ENCODER = new BCryptPasswordEncoder();
|
||||
private final SysMenuService sysMenuService;
|
||||
private final SysUserMapper sysUserMapper;
|
||||
private final SysRoleService sysRoleService;
|
||||
private final SysDeptService sysDeptService;
|
||||
private final SysUserRoleService sysUserRoleService;
|
||||
@@ -120,7 +119,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
||||
dataScope.setIsOnly(true);
|
||||
dataScope.setDeptIds(getChildDepts());
|
||||
Object username = query.getCondition().get("username");
|
||||
query.setRecords(sysUserMapper.selectUserVoPage(query, username, dataScope));
|
||||
query.setRecords(baseMapper.selectUserVoPage(query, username, dataScope));
|
||||
return query;
|
||||
}
|
||||
|
||||
@@ -133,33 +132,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
||||
*/
|
||||
@Override
|
||||
public UserVO selectUserVoById(Integer id) {
|
||||
return sysUserMapper.selectUserVoById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过用户名查找已经删除的用户
|
||||
*
|
||||
* @param username 用户名
|
||||
* @return 用户对象
|
||||
*/
|
||||
@Override
|
||||
public SysUser selectDeletedUserByUsername(String username) {
|
||||
return sysUserMapper.selectDeletedUserByUsername(username);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据用户名删除用户(真实删除)
|
||||
*
|
||||
* @param username
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Boolean deleteSysUserByUsernameAndUserId(String username, Integer userId) {
|
||||
sysUserMapper.deleteSysUserByUsernameAndUserId(username, userId);
|
||||
SysUserRole condition = new SysUserRole();
|
||||
condition.setUserId(userId);
|
||||
sysUserRoleService.delete(new EntityWrapper<>(condition));
|
||||
return Boolean.TRUE;
|
||||
return baseMapper.selectUserVoById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -179,7 +152,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
||||
@Override
|
||||
@CacheEvict(value = "user_details", key = "#username")
|
||||
public R<Boolean> updateUserInfo(UserDTO userDto, String username) {
|
||||
UserVO userVO = sysUserMapper.selectUserVoByUsername(username);
|
||||
UserVO userVO = baseMapper.selectUserVoByUsername(username);
|
||||
SysUser sysUser = new SysUser();
|
||||
if (StrUtil.isNotBlank(userDto.getPassword())
|
||||
&& StrUtil.isNotBlank(userDto.getNewpassword1())) {
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
<?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.SysRoleDeptMapper">
|
||||
|
||||
<!-- 通用查询映射结果 -->
|
||||
<resultMap id="BaseResultMap" type="com.pig4cloud.pigx.admin.api.entity.SysRoleDept">
|
||||
<id column="id" property="id"/>
|
||||
<result column="role_id" property="roleId"/>
|
||||
<result column="dept_id" property="deptId"/>
|
||||
</resultMap>
|
||||
|
||||
<!-- 通用查询结果列 -->
|
||||
<sql id="Base_Column_List">
|
||||
id, role_id AS roleId, dept_id AS deptId
|
||||
</sql>
|
||||
|
||||
</mapper>
|
||||
@@ -32,41 +32,6 @@
|
||||
<result column="del_flag" property="delFlag"/>
|
||||
</resultMap>
|
||||
|
||||
<!--roleDto-->
|
||||
<resultMap id="RoleDtoMap" type="com.pig4cloud.pigx.admin.api.dto.RoleDTO">
|
||||
<id column="role_id" property="roleId"/>
|
||||
<result column="role_name" property="roleName"/>
|
||||
<result column="role_code" property="roleCode"/>
|
||||
<result column="role_desc" property="roleDesc"/>
|
||||
<result column="create_time" property="createTime"/>
|
||||
<result column="update_time" property="updateTime"/>
|
||||
<result column="del_flag" property="delFlag"/>
|
||||
<result column="dept_id" property="roleDeptId"/>
|
||||
<result column="name" property="deptName"/>
|
||||
</resultMap>
|
||||
|
||||
<select id="selectRolePage" resultMap="RoleDtoMap">
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
sys_role r
|
||||
LEFT JOIN sys_role_dept rd ON rd.role_id = r.role_id
|
||||
LEFT JOIN sys_dept d ON rd.dept_id = d.dept_id
|
||||
WHERE r.del_flag = 0
|
||||
ORDER BY r.role_id ASC
|
||||
</select>
|
||||
<select id="selectListByDeptId" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
r.role_id,
|
||||
r.role_name,
|
||||
r.role_code,
|
||||
r.role_desc,
|
||||
r.create_time,
|
||||
r.update_time,
|
||||
r.del_flag
|
||||
FROM sys_role r LEFT OUTER JOIN sys_role_dept rd ON rd.role_id = r.role_id
|
||||
WHERE rd.dept_id = #{deptId}
|
||||
</select>
|
||||
<!-- 通过用户ID,查询角色信息-->
|
||||
<select id="findRolesByUserId" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
|
||||
@@ -161,27 +161,4 @@
|
||||
</if>
|
||||
ORDER BY `user`.create_time DESC
|
||||
</select>
|
||||
|
||||
<select id="selectDeletedUserByUsername" resultMap="baseResultMap">
|
||||
SELECT user_id,
|
||||
username,
|
||||
password,
|
||||
phone,
|
||||
avatar,
|
||||
salt,
|
||||
dept_id,
|
||||
tenant_id,
|
||||
wx_openid,
|
||||
qq_openid,
|
||||
create_time,
|
||||
update_time,
|
||||
del_flag
|
||||
FROM sys_user
|
||||
WHERE username = #{username}
|
||||
AND del_flag = 1
|
||||
</select>
|
||||
|
||||
<delete id="deleteSysUserByUsernameAndUserId">
|
||||
DELETE FROM sys_user WHERE username=#{username} AND user_id=#{userId};
|
||||
</delete>
|
||||
</mapper>
|
||||
Reference in new issue
Block a user