亮哥你好呀

detached
ZhangXushuo 2024-12-09 11:56:03 +08:00
parent cb073f2a58
commit 94198b487c
24 changed files with 157 additions and 94 deletions

View File

@ -7,7 +7,7 @@ nacos:
addr: nacos.cloud.muyu.icu:8848
user-name: nacos
password: nacos
namespace: muyu-cloud
namespace: muyu-cloud-zxs
# Spring
spring:
application:

View File

@ -1,5 +1,9 @@
package com.muyu.common.system.domain;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.muyu.common.core.web.domain.BaseEntity;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
@ -20,6 +24,7 @@ import java.util.List;
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
@TableName("sys_dept")
@EqualsAndHashCode(callSuper = true)
public class SysDept extends BaseEntity {
private static final long serialVersionUID = 1L;
@ -27,6 +32,7 @@ public class SysDept extends BaseEntity {
/**
* ID
*/
@TableId(type = IdType.AUTO)
private Long deptId;
/**
@ -77,11 +83,13 @@ public class SysDept extends BaseEntity {
/**
*
*/
@TableField(exist = false)
private String parentName;
/**
*
*/
@TableField(exist = false)
private List<SysDept> children = new ArrayList<SysDept>();
@NotBlank(message = "部门名称不能为空")

View File

@ -1,5 +1,7 @@
package com.muyu.common.system.domain;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.muyu.common.core.annotation.Excel;
import com.muyu.common.core.annotation.Excel.ColumnType;
import com.muyu.common.core.web.domain.BaseEntity;
@ -73,26 +75,31 @@ public class SysRole extends BaseEntity {
/**
* 0 2
*/
@TableLogic
private String delFlag;
/**
*
*/
@TableField(exist = false)
private boolean flag = false;
/**
*
*/
@TableField(exist = false)
private Long[] menuIds;
/**
*
*/
@TableField(exist = false)
private Long[] deptIds;
/**
*
*/
@TableField(exist = false)
private Set<String> permissions;

View File

@ -7,7 +7,7 @@ nacos:
addr: nacos.cloud.muyu.icu:8848
user-name: nacos
password: nacos
namespace: muyu-cloud
namespace: muyu-cloud-zxs
# Spring
spring:

View File

@ -7,7 +7,7 @@ nacos:
addr: nacos.cloud.muyu.icu:8848
user-name: nacos
password: nacos
namespace: muyu-cloud
namespace: muyu-cloud-zxs
# Spring
spring:

View File

@ -7,7 +7,7 @@ nacos:
addr: nacos.cloud.muyu.icu:8848
user-name: nacos
password: nacos
namespace: muyu-cloud
namespace: muyu-cloud-zxs
# Spring
spring:

View File

@ -10,6 +10,7 @@ import com.muyu.common.security.annotation.RequiresPermissions;
import com.muyu.common.security.utils.SecurityUtils;
import com.muyu.common.system.domain.SysDept;
import com.muyu.system.service.SysDeptService;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.commons.lang3.ArrayUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
@ -24,6 +25,7 @@ import java.util.List;
*/
@RestController
@RequestMapping("/dept")
@Tag(name = "SysDeptController", description = "部门管理")
public class SysDeptController extends BaseController {
@Autowired

View File

@ -1,5 +1,9 @@
package com.muyu.system.domain;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.muyu.common.core.web.domain.BaseEntity;
import lombok.*;
import lombok.experimental.SuperBuilder;
@ -20,82 +24,98 @@ import java.util.List;
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
@TableName("sys_menu")
public class SysMenu extends BaseEntity {
private static final long serialVersionUID = 1L;
/**
* ID
*/
@TableId(type = IdType.AUTO)
private Long menuId;
/**
*
*/
@TableField()
private String menuName;
/**
*
*/
@TableField()
private String parentName;
/**
* ID
*/
@TableField()
private Long parentId;
/**
*
*/
@TableField()
private Integer orderNum;
/**
*
*/
@TableField()
private String path;
/**
*
*/
@TableField()
private String component;
/**
*
*/
@TableField()
private String query;
/**
* 0 1
*/
@TableField()
private String isFrame;
/**
* 0 1
*/
@TableField()
private String isCache;
/**
* M C F
*/
@TableField()
private String menuType;
/**
* 0 1
*/
@TableField()
private String visible;
/**
* 0 1
*/
@TableField()
private String status;
/**
*
*/
@TableField()
private String perms;
/**
*
*/
@TableField()
private String icon;
/**

View File

@ -1,5 +1,8 @@
package com.muyu.system.domain;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.muyu.common.core.web.domain.BaseEntity;
import com.muyu.common.core.xss.Xss;
import lombok.AllArgsConstructor;
@ -21,12 +24,14 @@ import jakarta.validation.constraints.Size;
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
@TableName("sys_notice")
public class SysNotice extends BaseEntity {
private static final long serialVersionUID = 1L;
/**
* ID
*/
@TableId(type = IdType.AUTO)
private Long noticeId;
/**

View File

@ -1,5 +1,8 @@
package com.muyu.system.domain;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.muyu.common.core.annotation.Excel;
import com.muyu.common.core.annotation.Excel.ColumnType;
import com.muyu.common.core.web.domain.BaseEntity;
@ -20,6 +23,7 @@ import jakarta.validation.constraints.Size;
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
@TableName("sys_post")
public class SysPost extends BaseEntity {
private static final long serialVersionUID = 1L;
@ -27,6 +31,7 @@ public class SysPost extends BaseEntity {
*
*/
@Excel(name = "岗位序号", cellType = ColumnType.NUMERIC)
@TableId(type = IdType.AUTO)
private Long postId;
/**

View File

@ -1,5 +1,8 @@
package com.muyu.system.domain;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
@ -14,6 +17,7 @@ import lombok.NoArgsConstructor;
@Builder
@NoArgsConstructor
@AllArgsConstructor
@TableName("sys_role_dept")
public class SysRoleDept {
/**
* ID

View File

@ -1,6 +1,9 @@
package com.muyu.system.domain;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
@ -15,6 +18,7 @@ import lombok.NoArgsConstructor;
@Builder
@NoArgsConstructor
@AllArgsConstructor
@TableName("sys_role_menu")
public class SysRoleMenu {
/**
* ID

View File

@ -1,5 +1,8 @@
package com.muyu.system.domain;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
@ -14,6 +17,7 @@ import lombok.NoArgsConstructor;
@Builder
@NoArgsConstructor
@AllArgsConstructor
@TableName("sys_user_online")
public class SysUserOnline {
/**
*

View File

@ -1,5 +1,8 @@
package com.muyu.system.domain;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
@ -14,6 +17,7 @@ import lombok.NoArgsConstructor;
@Builder
@NoArgsConstructor
@AllArgsConstructor
@TableName("sys_user_post")
public class SysUserPost {
/**
* ID

View File

@ -1,5 +1,8 @@
package com.muyu.system.domain;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
@ -14,6 +17,7 @@ import lombok.NoArgsConstructor;
@Builder
@NoArgsConstructor
@AllArgsConstructor
@TableName("sys_user_role")
public class SysUserRole {
/**
* ID

View File

@ -11,14 +11,6 @@ import java.util.List;
* @author muyu
*/
public interface SysRoleMapper extends BaseMapper<SysRole> {
/**
*
*
* @param role
*
* @return
*/
public List<SysRole> selectRoleList (SysRole role);
/**
* ID
@ -67,9 +59,9 @@ public interface SysRoleMapper extends BaseMapper<SysRole> {
*
*
* @param roleName
*
* @return
*/
public SysRole checkRoleNameUnique (String roleName);
/**
@ -79,16 +71,9 @@ public interface SysRoleMapper extends BaseMapper<SysRole> {
*
* @return
*/
public SysRole checkRoleKeyUnique (String roleKey);
/**
*
*
* @param role
*
* @return
*/
public int updateRole (SysRole role);
/**
*

View File

@ -3,6 +3,7 @@ package com.muyu.system.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.muyu.system.domain.SysRoleMenu;
import feign.Param;
import java.util.List;
@ -47,4 +48,8 @@ public interface SysRoleMenuMapper extends BaseMapper<SysRoleMenu> {
* @return
*/
public int batchRoleMenu (List<SysRoleMenu> roleMenuList);
// 批量保存角色与菜单的关联
boolean saveBatch(@Param("roleMenuList") List<SysRoleMenu> roleMenuList);
}

View File

@ -128,19 +128,17 @@ public interface SysRoleService extends IService<SysRole> {
*
*
* @param role
*
* @return
*/
public int updateRoleStatus (SysRole role);
public boolean updateRoleStatus (SysRole role);
/**
*
*
* @param role
*
* @return
*/
public int authDataScope (SysRole role);
public boolean authDataScope (SysRole role);
/**
* ID

View File

@ -29,13 +29,15 @@ import java.util.stream.Collectors;
* @author muyu
*/
@Service
public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> implements SysDeptService {
public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept>
implements SysDeptService {
@Autowired
private SysDeptMapper deptMapper;
@Autowired
private SysRoleMapper roleMapper;
/**
*
*

View File

@ -1,5 +1,7 @@
package com.muyu.system.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.muyu.common.core.constant.UserConstants;
import com.muyu.common.core.exception.ServiceException;
@ -45,14 +47,23 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
/**
*
*
* @param role
* @param params
*
* @return
*/
@Override
@DataScope(deptAlias = "d")
public List<SysRole> selectRoleList (SysRole role) {
return roleMapper.selectRoleList(role);
public List<SysRole> selectRoleList (SysRole params) {
LambdaQueryWrapper<SysRole> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(params.getRoleId() != null && params.getRoleId() != 0, SysRole::getRoleId, params.getRoleId());
wrapper.like(StringUtils.isNotBlank(params.getRoleName()), SysRole::getRoleName, params.getRoleName());
wrapper.eq(StringUtils.isNotBlank(params.getStatus()), SysRole::getStatus, params.getStatus());
wrapper.like(StringUtils.isNotBlank(params.getRoleKey()), SysRole::getRoleKey, params.getRoleKey());
wrapper.ge(params.getParams().get("beginTime") != null, SysRole::getCreateTime, params.getParams().get("beginTime"));
wrapper.le(params.getParams().get("endTime") != null, SysRole::getCreateTime, params.getParams().get("endTime"));
wrapper.orderBy(true, true, SysRole::getRoleSort);
return this.list(wrapper);
}
/**
@ -219,52 +230,80 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
roleMapper.insertRole(role);
return insertRoleMenu(role);
}
/**
*
*
* @param role
* @param sysRole
*
* @return
*/
@Override
@Transactional(rollbackFor = Exception.class)
public int updateRole (SysRole role) {
// 修改角色信息
roleMapper.updateRole(role);
public int updateRole (SysRole sysRole) {
LambdaUpdateWrapper<SysRole> updateWrapper = new LambdaUpdateWrapper<>();
// 条件判断并更新字段
updateWrapper.eq(SysRole::getRoleId, sysRole.getRoleId());
if (sysRole.getRoleName() != null && !sysRole.getRoleName().isEmpty()) {
updateWrapper.set(SysRole::getRoleName, sysRole.getRoleName());
}
if (sysRole.getRoleKey() != null && !sysRole.getRoleKey().isEmpty()) {
updateWrapper.set(SysRole::getRoleKey, sysRole.getRoleKey());
}
if (sysRole.getRoleSort() != null) {
updateWrapper.set(SysRole::getRoleSort, sysRole.getRoleSort());
}
if (sysRole.getDataScope() != null && !sysRole.getDataScope().isEmpty()) {
updateWrapper.set(SysRole::getDataScope, sysRole.getDataScope());
}
if (sysRole.getStatus() != null && !sysRole.getStatus().isEmpty()) {
updateWrapper.set(SysRole::getStatus, sysRole.getStatus());
}
if (sysRole.getRemark() != null) {
updateWrapper.set(SysRole::getRemark, sysRole.getRemark());
}
if (sysRole.getUpdateBy() != null && !sysRole.getUpdateBy().isEmpty()) {
updateWrapper.set(SysRole::getUpdateBy, sysRole.getUpdateBy());
}
// 更新时间
updateWrapper.set(SysRole::getUpdateTime, new java.util.Date());
// 执行更新
this.update(updateWrapper);
// 删除角色与菜单关联
roleMenuMapper.deleteRoleMenuByRoleId(role.getRoleId());
return insertRoleMenu(role);
roleMenuMapper.deleteRoleMenuByRoleId(sysRole.getRoleId());
return insertRoleMenu(sysRole);
}
/**
*
*
* @param role
*
* @return
*/
@Override
public int updateRoleStatus (SysRole role) {
return roleMapper.updateRole(role);
public boolean updateRoleStatus (SysRole role) {
boolean updateResult = updateById(role); // 通过 roleId 更新角色信息
return updateResult;
}
/**
*
*
* @param role
*
* @return
*/
@Override
@Transactional(rollbackFor = Exception.class)
public int authDataScope (SysRole role) {
public boolean authDataScope (SysRole role) {
// 修改角色信息
roleMapper.updateRole(role);
boolean updateResult = updateById(role); // 通过 roleId 更新角色信息
// 删除角色与部门关联
roleDeptMapper.deleteRoleDeptByRoleId(role.getRoleId());
// 新增角色和部门信息(数据权限)
return insertRoleDept(role);
return updateResult;
}
/**
@ -273,7 +312,11 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
* @param role
*/
public int insertRoleMenu (SysRole role) {
int rows = 1;
// 假设role.getMenuIds()返回角色关联的菜单ID列表
List<Long> menuIds = List.of(role.getMenuIds());
if (menuIds == null || menuIds.isEmpty()){
return 0;
}
// 新增用户与角色管理
List<SysRoleMenu> list = new ArrayList<SysRoleMenu>();
for (Long menuId : role.getMenuIds()) {
@ -282,10 +325,10 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
rm.setMenuId(menuId);
list.add(rm);
}
if (list.size() > 0) {
rows = roleMenuMapper.batchRoleMenu(list);
}
return rows;
// 使用MyBatis-Plus的saveBatch方法批量插入角色与菜单的关联关系
boolean saveResult = roleMenuMapper.saveBatch(list);
return saveResult ? list.size() : 0; // 返回成功插入的数量
}
/**

View File

@ -7,7 +7,7 @@ nacos:
addr: nacos.cloud.muyu.icu:8848
user-name: nacos
password: nacos
namespace: muyu-cloud
namespace: muyu-cloud-zxs
# SPRING_AMQP_DESERIALIZATION_TRUST_ALL=true spring.amqp.deserialization.trust.all
# Spring
spring:
@ -57,4 +57,4 @@ spring:
- application-rabbit-config-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
logging:
level:
com.muyu.system.mapper: DEBUG
com.muyu.system.mapper: DEBUG

View File

@ -39,32 +39,6 @@
left join sys_dept d on u.dept_id = d.dept_id
</sql>
<select id="selectRoleList" parameterType="com.muyu.common.system.domain.SysRole" resultMap="SysRoleResult">
<include refid="selectRoleVo"/>
where r.del_flag = '0'
<if test="roleId != null and roleId != 0">
AND r.role_id = #{roleId}
</if>
<if test="roleName != null and roleName != ''">
AND r.role_name like concat('%', #{roleName}, '%')
</if>
<if test="status != null and status != ''">
AND r.status = #{status}
</if>
<if test="roleKey != null and roleKey != ''">
AND r.role_key like concat('%', #{roleKey}, '%')
</if>
<if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
and date_format(r.create_time,'%y%m%d') &gt;= date_format(#{params.beginTime},'%y%m%d')
</if>
<if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
and date_format(r.create_time,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d')
</if>
<!-- 数据范围过滤 -->
${params.dataScope}
order by r.role_sort
</select>
<select id="selectRolePermissionByUserId" parameterType="Long" resultMap="SysRoleResult">
<include refid="selectRoleVo"/>
WHERE r.del_flag = '0' and ur.user_id = #{userId}
@ -130,23 +104,6 @@
)
</insert>
<update id="updateRole" parameterType="com.muyu.common.system.domain.SysRole">
update sys_role
<set>
<if test="roleName != null and roleName != ''">role_name = #{roleName},</if>
<if test="roleKey != null and roleKey != ''">role_key = #{roleKey},</if>
<if test="roleSort != null">role_sort = #{roleSort},</if>
<if test="dataScope != null and dataScope != ''">data_scope = #{dataScope},</if>
<if test="menuCheckStrictly != null">menu_check_strictly = #{menuCheckStrictly},</if>
<if test="deptCheckStrictly != null">dept_check_strictly = #{deptCheckStrictly},</if>
<if test="status != null and status != ''">status = #{status},</if>
<if test="remark != null">remark = #{remark},</if>
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
update_time = sysdate()
</set>
where role_id = #{roleId}
</update>
<delete id="deleteRoleById" parameterType="Long">
update sys_role
set del_flag = '2'

View File

@ -34,5 +34,11 @@
(#{item.roleId},#{item.menuId})
</foreach>
</insert>
<insert id="saveBatch">
insert into sys_role_menu(role_id, menu_id) values
<foreach item="item" index="index" collection="list" separator=",">
(#{item.roleId},#{item.menuId})
</foreach>
</insert>
</mapper>

View File

@ -7,7 +7,7 @@ nacos:
addr: nacos.cloud.muyu.icu:8848
user-name: nacos
password: nacos
namespace: muyu-cloud
namespace: muyu-cloud-zxs
# Spring
spring: