修复:userRole模块
This commit is contained in:
@@ -1,57 +1,135 @@
|
|||||||
package com.gxwebsoft.common.system.controller;
|
package com.gxwebsoft.common.system.controller;
|
||||||
|
|
||||||
import cn.afterturn.easypoi.excel.ExcelImportUtil;
|
import com.gxwebsoft.common.core.web.BaseController;
|
||||||
import cn.afterturn.easypoi.excel.entity.ImportParams;
|
import com.gxwebsoft.common.system.entity.User;
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import com.gxwebsoft.common.system.service.UserRoleService;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import com.gxwebsoft.common.system.entity.UserRole;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.gxwebsoft.common.system.param.UserRoleParam;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.gxwebsoft.common.core.web.ApiResult;
|
||||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
import com.gxwebsoft.common.core.web.PageResult;
|
||||||
|
import com.gxwebsoft.common.core.web.PageParam;
|
||||||
|
import com.gxwebsoft.common.core.web.BatchParam;
|
||||||
import com.gxwebsoft.common.core.annotation.OperationLog;
|
import com.gxwebsoft.common.core.annotation.OperationLog;
|
||||||
import com.gxwebsoft.common.core.config.ConfigProperties;
|
|
||||||
import com.gxwebsoft.common.core.security.JwtSubject;
|
|
||||||
import com.gxwebsoft.common.core.security.JwtUtil;
|
|
||||||
import com.gxwebsoft.common.core.utils.CommonUtil;
|
|
||||||
import com.gxwebsoft.common.core.web.*;
|
|
||||||
import com.gxwebsoft.common.system.entity.*;
|
|
||||||
import com.gxwebsoft.common.system.param.UserImportParam;
|
|
||||||
import com.gxwebsoft.common.system.param.UserParam;
|
|
||||||
import com.gxwebsoft.common.system.result.LoginResult;
|
|
||||||
import com.gxwebsoft.common.system.service.*;
|
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiImplicitParam;
|
|
||||||
import io.swagger.annotations.ApiImplicitParams;
|
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import io.swagger.models.auth.In;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.math.BigDecimal;
|
import java.util.List;
|
||||||
import java.util.*;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户控制器
|
* 用户角色控制器
|
||||||
*
|
*
|
||||||
* @author WebSoft
|
* @author 科技小王子
|
||||||
* @since 2018-12-24 16:10:41
|
* @since 2025-06-16 20:39:53
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Api(tags = "用户角色管理")
|
||||||
@Api(tags = "用户角色")
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/api/system/user-role")
|
@RequestMapping("/api/system/user-role")
|
||||||
public class UserRoleController extends BaseController {
|
public class UserRoleController extends BaseController {
|
||||||
@Resource
|
@Resource
|
||||||
private UserRoleService userRoleService;
|
private UserRoleService userRoleService;
|
||||||
|
|
||||||
@ApiOperation("查询角色下的用户")
|
@ApiOperation("查询角色下的用户")
|
||||||
@GetMapping("/user-list-in-role/{id}")
|
@GetMapping("/user-list-in-role/{id}")
|
||||||
public ApiResult<List<UserRole>> userListInRole(@PathVariable Integer id) {
|
public ApiResult<List<UserRole>> userListInRole(@PathVariable Integer id) {
|
||||||
return success(userRoleService.listByRoleId(id));
|
return success(userRoleService.listByRoleId(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation("分页查询用户角色")
|
||||||
|
@GetMapping("/page")
|
||||||
|
public ApiResult<PageResult<UserRole>> page(UserRoleParam param) {
|
||||||
|
// 使用关联查询
|
||||||
|
return success(userRoleService.pageRel(param));
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation("查询全部用户角色")
|
||||||
|
@GetMapping()
|
||||||
|
public ApiResult<List<UserRole>> list(UserRoleParam param) {
|
||||||
|
// 使用关联查询
|
||||||
|
return success(userRoleService.listRel(param));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ApiOperation("根据id查询用户角色")
|
||||||
|
@GetMapping("/{id}")
|
||||||
|
public ApiResult<UserRole> get(@PathVariable("id") Integer id) {
|
||||||
|
// 使用关联查询
|
||||||
|
return success(userRoleService.getByIdRel(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
@PreAuthorize("hasAuthority('sys:userRole:save')")
|
||||||
|
@OperationLog
|
||||||
|
@ApiOperation("添加用户角色")
|
||||||
|
@PostMapping()
|
||||||
|
public ApiResult<?> save(@RequestBody UserRole userRole) {
|
||||||
|
// 记录当前登录用户id
|
||||||
|
User loginUser = getLoginUser();
|
||||||
|
if (loginUser != null) {
|
||||||
|
userRole.setUserId(loginUser.getUserId());
|
||||||
}
|
}
|
||||||
|
if (userRoleService.save(userRole)) {
|
||||||
|
return success("添加成功");
|
||||||
|
}
|
||||||
|
return fail("添加失败");
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation("修改用户角色")
|
||||||
|
@PutMapping()
|
||||||
|
public ApiResult<?> update(@RequestBody UserRole userRole) {
|
||||||
|
final User loginUser = getLoginUser();
|
||||||
|
if (loginUser == null) {
|
||||||
|
return fail("请先登录");
|
||||||
|
}
|
||||||
|
if (userRoleService.updateById(userRole)) {
|
||||||
|
return success("修改成功");
|
||||||
|
}
|
||||||
|
return fail("修改失败");
|
||||||
|
}
|
||||||
|
|
||||||
|
@PreAuthorize("hasAuthority('sys:userRole:remove')")
|
||||||
|
@OperationLog
|
||||||
|
@ApiOperation("删除用户角色")
|
||||||
|
@DeleteMapping("/{id}")
|
||||||
|
public ApiResult<?> remove(@PathVariable("id") Integer id) {
|
||||||
|
if (userRoleService.removeById(id)) {
|
||||||
|
return success("删除成功");
|
||||||
|
}
|
||||||
|
return fail("删除失败");
|
||||||
|
}
|
||||||
|
|
||||||
|
@PreAuthorize("hasAuthority('sys:userRole:save')")
|
||||||
|
@OperationLog
|
||||||
|
@ApiOperation("批量添加用户角色")
|
||||||
|
@PostMapping("/batch")
|
||||||
|
public ApiResult<?> saveBatch(@RequestBody List<UserRole> list) {
|
||||||
|
if (userRoleService.saveBatch(list)) {
|
||||||
|
return success("添加成功");
|
||||||
|
}
|
||||||
|
return fail("添加失败");
|
||||||
|
}
|
||||||
|
|
||||||
|
@PreAuthorize("hasAuthority('sys:userRole:update')")
|
||||||
|
@OperationLog
|
||||||
|
@ApiOperation("批量修改用户角色")
|
||||||
|
@PutMapping("/batch")
|
||||||
|
public ApiResult<?> removeBatch(@RequestBody BatchParam<UserRole> batchParam) {
|
||||||
|
if (batchParam.update(userRoleService, "id")) {
|
||||||
|
return success("修改成功");
|
||||||
|
}
|
||||||
|
return fail("修改失败");
|
||||||
|
}
|
||||||
|
|
||||||
|
@PreAuthorize("hasAuthority('sys:userRole:remove')")
|
||||||
|
@OperationLog
|
||||||
|
@ApiOperation("批量删除用户角色")
|
||||||
|
@DeleteMapping("/batch")
|
||||||
|
public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
|
||||||
|
if (userRoleService.removeByIds(ids)) {
|
||||||
|
return success("删除成功");
|
||||||
|
}
|
||||||
|
return fail("删除失败");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,49 +1,52 @@
|
|||||||
package com.gxwebsoft.common.system.entity;
|
package com.gxwebsoft.common.system.entity;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.IdType;
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableField;
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
import com.baomidou.mybatisplus.annotation.TableId;
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
import io.swagger.annotations.ApiModel;
|
import io.swagger.annotations.ApiModel;
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
import java.io.Serializable;
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户角色
|
* 用户角色
|
||||||
*
|
*
|
||||||
* @author WebSoft
|
* @author 科技小王子
|
||||||
* @since 2018-12-24 16:10:23
|
* @since 2025-06-16 20:39:53
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@ApiModel(description = "用户角色")
|
@ApiModel(description = "用户角色")
|
||||||
@TableName("sys_user_role")
|
@TableName("sys_user_role")
|
||||||
public class UserRole implements Serializable {
|
public class UserRole implements Serializable {
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
@ApiModelProperty("主键id")
|
@ApiModelProperty("主键id")
|
||||||
@TableId(type = IdType.AUTO)
|
@TableId(type = IdType.AUTO)
|
||||||
private Integer id;
|
private Integer id;
|
||||||
|
|
||||||
@ApiModelProperty("用户id")
|
@ApiModelProperty("用户id")
|
||||||
private Integer userId;
|
private Integer userId;
|
||||||
|
|
||||||
@ApiModelProperty("角色id")
|
@ApiModelProperty("角色id")
|
||||||
private Integer roleId;
|
private Integer roleId;
|
||||||
|
|
||||||
@ApiModelProperty("创建时间")
|
@ApiModelProperty("创建时间")
|
||||||
private Date createTime;
|
private Date createTime;
|
||||||
|
|
||||||
@ApiModelProperty("修改时间")
|
@ApiModelProperty("修改时间")
|
||||||
private Date updateTime;
|
private Date updateTime;
|
||||||
|
|
||||||
@ApiModelProperty("角色名称")
|
@ApiModelProperty("角色名称")
|
||||||
@TableField(exist = false)
|
@TableField(exist = false)
|
||||||
private String roleName;
|
private String roleName;
|
||||||
|
|
||||||
@ApiModelProperty("租户ID")
|
@ApiModelProperty("租户ID")
|
||||||
private Integer tenantId;
|
private Integer tenantId;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,8 +2,10 @@ package com.gxwebsoft.common.system.mapper;
|
|||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
|
import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
import com.gxwebsoft.common.system.entity.Role;
|
import com.gxwebsoft.common.system.entity.Role;
|
||||||
import com.gxwebsoft.common.system.entity.UserRole;
|
import com.gxwebsoft.common.system.entity.UserRole;
|
||||||
|
import com.gxwebsoft.common.system.param.UserRoleParam;
|
||||||
import org.apache.ibatis.annotations.Param;
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -11,35 +13,53 @@ import java.util.List;
|
|||||||
/**
|
/**
|
||||||
* 用户角色Mapper
|
* 用户角色Mapper
|
||||||
*
|
*
|
||||||
* @author WebSoft
|
* @author 科技小王子
|
||||||
* @since 2018-12-24 16:10:02
|
* @since 2025-06-16 20:39:53
|
||||||
*/
|
*/
|
||||||
public interface UserRoleMapper extends BaseMapper<UserRole> {
|
public interface UserRoleMapper extends BaseMapper<UserRole> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 批量添加用户角色
|
* 批量添加用户角色
|
||||||
*
|
*
|
||||||
* @param userId 用户id
|
* @param userId 用户id
|
||||||
* @param roleIds 角色id集合
|
* @param roleIds 角色id集合
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
int insertBatch(@Param("userId") Integer userId, @Param("roleIds") List<Integer> roleIds);
|
int insertBatch(@Param("userId") Integer userId, @Param("roleIds") List<Integer> roleIds);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据用户id查询角色
|
* 根据用户id查询角色
|
||||||
*
|
*
|
||||||
* @param userId 用户id
|
* @param userId 用户id
|
||||||
* @return List<Role>
|
* @return List<Role>
|
||||||
*/
|
*/
|
||||||
@InterceptorIgnore(tenantLine = "true")
|
@InterceptorIgnore(tenantLine = "true")
|
||||||
List<Role> selectByUserId(@Param("userId") Integer userId);
|
List<Role> selectByUserId(@Param("userId") Integer userId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 批量根据用户id查询角色
|
* 批量根据用户id查询角色
|
||||||
*
|
*
|
||||||
* @param userIds 用户id集合
|
* @param userIds 用户id集合
|
||||||
* @return List<RoleResult>
|
* @return List<RoleResult>
|
||||||
*/
|
*/
|
||||||
List<Role> selectByUserIds(@Param("userIds") List<Integer> userIds);
|
List<Role> selectByUserIds(@Param("userIds") List<Integer> userIds);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页查询
|
||||||
|
*
|
||||||
|
* @param page 分页对象
|
||||||
|
* @param param 查询参数
|
||||||
|
* @return List<UserRole>
|
||||||
|
*/
|
||||||
|
List<UserRole> selectPageRel(@Param("page") IPage<UserRole> page,
|
||||||
|
@Param("param") UserRoleParam param);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询全部
|
||||||
|
*
|
||||||
|
* @param param 查询参数
|
||||||
|
* @return List<User>
|
||||||
|
*/
|
||||||
|
List<UserRole> selectListRel(@Param("param") UserRoleParam param);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,35 +1,66 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" ?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<!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="com.gxwebsoft.common.system.mapper.UserRoleMapper">
|
<mapper namespace="com.gxwebsoft.common.system.mapper.UserRoleMapper">
|
||||||
|
|
||||||
<insert id="insertBatch">
|
<insert id="insertBatch">
|
||||||
INSERT INTO sys_user_role(user_id, role_id) VALUES
|
INSERT INTO sys_user_role(user_id, role_id) VALUES
|
||||||
<foreach collection="roleIds" item="roleId" separator=",">
|
<foreach collection="roleIds" item="roleId" separator=",">
|
||||||
(#{userId}, #{roleId})
|
(#{userId}, #{roleId})
|
||||||
</foreach>
|
</foreach>
|
||||||
</insert>
|
</insert>
|
||||||
|
|
||||||
<select id="selectByUserId" resultType="com.gxwebsoft.common.system.entity.Role">
|
<select id="selectByUserId" resultType="com.gxwebsoft.common.system.entity.Role">
|
||||||
SELECT *
|
SELECT *
|
||||||
FROM sys_role
|
FROM sys_role
|
||||||
WHERE role_id IN (
|
WHERE role_id IN (SELECT role_id
|
||||||
SELECT role_id
|
FROM sys_user_role
|
||||||
FROM sys_user_role
|
WHERE user_id = #{userId})
|
||||||
WHERE user_id = #{userId}
|
AND deleted = 0
|
||||||
)
|
ORDER BY role_id desc
|
||||||
AND deleted = 0
|
</select>
|
||||||
ORDER BY role_id desc
|
|
||||||
</select>
|
|
||||||
|
|
||||||
<select id="selectByUserIds" resultType="com.gxwebsoft.common.system.entity.Role">
|
<select id="selectByUserIds" resultType="com.gxwebsoft.common.system.entity.Role">
|
||||||
SELECT a.user_id, b.*
|
SELECT a.user_id, b.*
|
||||||
FROM sys_user_role a
|
FROM sys_user_role a
|
||||||
LEFT JOIN sys_role b ON a.role_id = b.role_id
|
LEFT JOIN sys_role b ON a.role_id = b.role_id
|
||||||
WHERE a.user_id IN
|
WHERE a.user_id IN
|
||||||
<foreach collection="userIds" open="(" close=")" separator="," item="userId">
|
<foreach collection="userIds" open="(" close=")" separator="," item="userId">
|
||||||
#{userId}
|
#{userId}
|
||||||
</foreach>
|
</foreach>
|
||||||
AND b.deleted = 0
|
AND b.deleted = 0
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<!-- 关联查询sql -->
|
||||||
|
<sql id="selectSql">
|
||||||
|
SELECT a.*
|
||||||
|
FROM sys_user_role a
|
||||||
|
<where>
|
||||||
|
<if test="param.id != null">
|
||||||
|
AND a.id = #{param.id}
|
||||||
|
</if>
|
||||||
|
<if test="param.userId != null">
|
||||||
|
AND a.user_id = #{param.userId}
|
||||||
|
</if>
|
||||||
|
<if test="param.roleId != null">
|
||||||
|
AND a.role_id = #{param.roleId}
|
||||||
|
</if>
|
||||||
|
<if test="param.createTimeStart != null">
|
||||||
|
AND a.create_time >= #{param.createTimeStart}
|
||||||
|
</if>
|
||||||
|
<if test="param.createTimeEnd != null">
|
||||||
|
AND a.create_time <= #{param.createTimeEnd}
|
||||||
|
</if>
|
||||||
|
</where>
|
||||||
|
</sql>
|
||||||
|
|
||||||
|
<!-- 分页查询 -->
|
||||||
|
<select id="selectPageRel" resultType="com.gxwebsoft.common.system.entity.UserRole">
|
||||||
|
<include refid="selectSql"></include>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<!-- 查询全部 -->
|
||||||
|
<select id="selectListRel" resultType="com.gxwebsoft.common.system.entity.UserRole">
|
||||||
|
<include refid="selectSql"></include>
|
||||||
|
</select>
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
package com.gxwebsoft.common.system.param;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
|
import com.gxwebsoft.common.core.annotation.QueryField;
|
||||||
|
import com.gxwebsoft.common.core.annotation.QueryType;
|
||||||
|
import com.gxwebsoft.common.core.web.BaseParam;
|
||||||
|
import io.swagger.annotations.ApiModel;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户角色查询参数
|
||||||
|
*
|
||||||
|
* @author 科技小王子
|
||||||
|
* @since 2025-06-16 20:39:53
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||||
|
@ApiModel(value = "UserRoleParam对象", description = "用户角色查询参数")
|
||||||
|
public class UserRoleParam extends BaseParam {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "主键id")
|
||||||
|
@QueryField(type = QueryType.EQ)
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "用户id")
|
||||||
|
@QueryField(type = QueryType.EQ)
|
||||||
|
private Integer userId;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "角色id")
|
||||||
|
@QueryField(type = QueryType.EQ)
|
||||||
|
private Integer roleId;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,43 +1,70 @@
|
|||||||
package com.gxwebsoft.common.system.service;
|
package com.gxwebsoft.common.system.service;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.gxwebsoft.common.core.web.PageResult;
|
||||||
import com.gxwebsoft.common.system.entity.Role;
|
import com.gxwebsoft.common.system.entity.Role;
|
||||||
import com.gxwebsoft.common.system.entity.UserRole;
|
import com.gxwebsoft.common.system.entity.UserRole;
|
||||||
|
import com.gxwebsoft.common.system.param.UserRoleParam;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户角色Service
|
* 用户角色Service
|
||||||
*
|
*
|
||||||
* @author WebSoft
|
* @author 科技小王子
|
||||||
* @since 2018-12-24 16:10:35
|
* @since 2025-06-16 20:39:53
|
||||||
*/
|
*/
|
||||||
public interface UserRoleService extends IService<UserRole> {
|
public interface UserRoleService extends IService<UserRole> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 批量添加用户角色
|
* 批量添加用户角色
|
||||||
*
|
*
|
||||||
* @param userId 用户id
|
* @param userId 用户id
|
||||||
* @param roleIds 角色id集合
|
* @param roleIds 角色id集合
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
int saveBatch(Integer userId, List<Integer> roleIds);
|
int saveBatch(Integer userId, List<Integer> roleIds);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据用户id查询角色
|
* 根据用户id查询角色
|
||||||
*
|
*
|
||||||
* @param userId 用户id
|
* @param userId 用户id
|
||||||
* @return List<Role>
|
* @return List<Role>
|
||||||
*/
|
*/
|
||||||
List<Role> listByUserId(Integer userId);
|
List<Role> listByUserId(Integer userId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 批量根据用户id查询角色
|
* 批量根据用户id查询角色
|
||||||
*
|
*
|
||||||
* @param userIds 用户id集合
|
* @param userIds 用户id集合
|
||||||
* @return List<RoleResult>
|
* @return List<RoleResult>
|
||||||
*/
|
*/
|
||||||
List<Role> listByUserIds(List<Integer> userIds);
|
List<Role> listByUserIds(List<Integer> userIds);
|
||||||
|
|
||||||
|
List<UserRole> listByRoleId(Integer roleId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页关联查询
|
||||||
|
*
|
||||||
|
* @param param 查询参数
|
||||||
|
* @return PageResult<UserRole>
|
||||||
|
*/
|
||||||
|
PageResult<UserRole> pageRel(UserRoleParam param);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 关联查询全部
|
||||||
|
*
|
||||||
|
* @param param 查询参数
|
||||||
|
* @return List<UserRole>
|
||||||
|
*/
|
||||||
|
List<UserRole> listRel(UserRoleParam param);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据id查询
|
||||||
|
*
|
||||||
|
* @param id 主键id
|
||||||
|
* @return UserRole
|
||||||
|
*/
|
||||||
|
UserRole getByIdRel(Integer id);
|
||||||
|
|
||||||
List<UserRole> listByRoleId(Integer roleId);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,9 +3,12 @@ package com.gxwebsoft.common.system.service.impl;
|
|||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.gxwebsoft.common.system.entity.Role;
|
import com.gxwebsoft.common.system.entity.Role;
|
||||||
import com.gxwebsoft.common.system.entity.UserRole;
|
|
||||||
import com.gxwebsoft.common.system.mapper.UserRoleMapper;
|
import com.gxwebsoft.common.system.mapper.UserRoleMapper;
|
||||||
import com.gxwebsoft.common.system.service.UserRoleService;
|
import com.gxwebsoft.common.system.service.UserRoleService;
|
||||||
|
import com.gxwebsoft.common.system.entity.UserRole;
|
||||||
|
import com.gxwebsoft.common.system.param.UserRoleParam;
|
||||||
|
import com.gxwebsoft.common.core.web.PageParam;
|
||||||
|
import com.gxwebsoft.common.core.web.PageResult;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -13,30 +16,54 @@ import java.util.List;
|
|||||||
/**
|
/**
|
||||||
* 用户角色Service实现
|
* 用户角色Service实现
|
||||||
*
|
*
|
||||||
* @author WebSoft
|
* @author 科技小王子
|
||||||
* @since 2018-12-24 16:10:36
|
* @since 2025-06-16 20:39:53
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
public class UserRoleServiceImpl extends ServiceImpl<UserRoleMapper, UserRole> implements UserRoleService {
|
public class UserRoleServiceImpl extends ServiceImpl<UserRoleMapper, UserRole> implements UserRoleService {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int saveBatch(Integer userId, List<Integer> roleIds) {
|
||||||
|
return baseMapper.insertBatch(userId, roleIds);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int saveBatch(Integer userId, List<Integer> roleIds) {
|
public List<Role> listByUserId(Integer userId) {
|
||||||
return baseMapper.insertBatch(userId, roleIds);
|
return baseMapper.selectByUserId(userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Role> listByUserId(Integer userId) {
|
public List<Role> listByUserIds(List<Integer> userIds) {
|
||||||
return baseMapper.selectByUserId(userId);
|
return baseMapper.selectByUserIds(userIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Role> listByUserIds(List<Integer> userIds) {
|
public List<UserRole> listByRoleId(Integer roleId) {
|
||||||
return baseMapper.selectByUserIds(userIds);
|
return list(new LambdaQueryWrapper<UserRole>().eq(UserRole::getRoleId, roleId));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PageResult<UserRole> pageRel(UserRoleParam param) {
|
||||||
|
PageParam<UserRole, UserRoleParam> page = new PageParam<>(param);
|
||||||
|
page.setDefaultOrder("create_time desc");
|
||||||
|
List<UserRole> list = baseMapper.selectPageRel(page, param);
|
||||||
|
return new PageResult<>(list, page.getTotal());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<UserRole> listRel(UserRoleParam param) {
|
||||||
|
List<UserRole> list = baseMapper.selectListRel(param);
|
||||||
|
// 排序
|
||||||
|
PageParam<UserRole, UserRoleParam> page = new PageParam<>();
|
||||||
|
page.setDefaultOrder("create_time desc");
|
||||||
|
return page.sortRecords(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public UserRole getByIdRel(Integer id) {
|
||||||
|
UserRoleParam param = new UserRoleParam();
|
||||||
|
param.setId(id);
|
||||||
|
return param.getOne(baseMapper.selectListRel(param));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<UserRole> listByRoleId(Integer roleId) {
|
|
||||||
return list(new LambdaQueryWrapper<UserRole>().eq(UserRole::getRoleId, roleId));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ public class SysGenerator {
|
|||||||
// "sys_domain",
|
// "sys_domain",
|
||||||
// "sys_company",
|
// "sys_company",
|
||||||
// "sys_user_verify"
|
// "sys_user_verify"
|
||||||
|
// "sys_user_role"
|
||||||
};
|
};
|
||||||
// 需要去除的表前缀
|
// 需要去除的表前缀
|
||||||
private static final String[] TABLE_PREFIX = new String[]{
|
private static final String[] TABLE_PREFIX = new String[]{
|
||||||
|
|||||||
Reference in New Issue
Block a user