|
@@ -3,23 +3,22 @@ package com.flyer.foster.service.impl;
|
|
|
import cn.dev33.satoken.stp.StpUtil;
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.bean.copier.CopyOptions;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.flyer.exception.BusinessException;
|
|
|
import com.flyer.foster.dto.RoleAddDTO;
|
|
|
import com.flyer.foster.dto.RoleMenuAddDTO;
|
|
|
import com.flyer.foster.dto.RoleRespDTO;
|
|
|
+import com.flyer.foster.dto.RoleUpdateDTO;
|
|
|
import com.flyer.foster.entity.Role;
|
|
|
import com.flyer.foster.entity.RoleMenu;
|
|
|
-import com.flyer.foster.entity.UserRole;
|
|
|
import com.flyer.foster.enums.IsAdminEnum;
|
|
|
import com.flyer.foster.enums.StatusEnum;
|
|
|
import com.flyer.foster.enums.TFEnum;
|
|
|
import com.flyer.foster.mapper.IRoleMapper;
|
|
|
-import com.flyer.foster.mapper.IRoleMenuMapper;
|
|
|
-import com.flyer.foster.mapper.IUserRoleMapper;
|
|
|
import com.flyer.foster.pojo.Dropdown;
|
|
|
import com.flyer.foster.service.IRoleMenuService;
|
|
|
import com.flyer.foster.service.IRoleService;
|
|
|
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.flyer.foster.service.IUserRoleService;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
@@ -44,10 +43,7 @@ public class RoleServiceImpl extends ServiceImpl<IRoleMapper, Role> implements I
|
|
|
private IRoleMenuService iRoleMenuService;
|
|
|
|
|
|
@Autowired
|
|
|
- private IRoleMenuMapper iRoleMenuMapper;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private IUserRoleMapper iUserRoleMapper;
|
|
|
+ private IUserRoleService iUserRoleService;
|
|
|
|
|
|
@Override
|
|
|
public List<RoleRespDTO> getRoleList() {
|
|
@@ -88,13 +84,54 @@ public class RoleServiceImpl extends ServiceImpl<IRoleMapper, Role> implements I
|
|
|
role.setTenantId(tenantId);
|
|
|
// 新增角色
|
|
|
this.save(role);
|
|
|
+ // 保存角色菜单
|
|
|
+ RoleMenu roleMenu;
|
|
|
+ for (Integer menuId : addDTO.getMenuIdList()) {
|
|
|
+ roleMenu = new RoleMenu();
|
|
|
+ roleMenu.setRoleId(role.getId());
|
|
|
+ roleMenu.setMenuId(menuId);
|
|
|
+ iRoleMenuService.save(roleMenu);
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional
|
|
|
+ @Override
|
|
|
+ public boolean updateRole(RoleUpdateDTO updateDTO) {
|
|
|
+ int tenantId = StpUtil.getTokenSession().getInt("tenantId");
|
|
|
+ Role role = this.lambdaQuery()
|
|
|
+ .eq(Role::getId, updateDTO.getRoleId())
|
|
|
+ .eq(Role::getTenantId, tenantId)
|
|
|
+ .one();
|
|
|
+ if (role == null) {
|
|
|
+ throw new BusinessException(StrUtil.format("无效的角色id:{}", updateDTO.getRoleId()));
|
|
|
+ }
|
|
|
|
|
|
+ // 删除菜单后新增
|
|
|
RoleMenuAddDTO roleMenuAddDTO = new RoleMenuAddDTO();
|
|
|
- roleMenuAddDTO.setRoleId(role.getId());
|
|
|
- roleMenuAddDTO.setMenuIdList(addDTO.getMenuIdList());
|
|
|
- // 保存角色菜单
|
|
|
+ roleMenuAddDTO.setRoleId(updateDTO.getRoleId());
|
|
|
+ roleMenuAddDTO.setMenuIdList(updateDTO.getMenuIdList());
|
|
|
iRoleMenuService.addRoleMenu(roleMenuAddDTO);
|
|
|
- return true;
|
|
|
+
|
|
|
+ // 没有修改则不作修改
|
|
|
+ if (role.getRoleName().equals(updateDTO.getRoleName()) && role.getRoleCode().equals(updateDTO.getRoleCode())) {
|
|
|
+ return true;
|
|
|
+ } else if (StrUtil.isBlank(updateDTO.getRoleName()) && StrUtil.isBlank(updateDTO.getRoleCode())) {
|
|
|
+ return true;
|
|
|
+ } else {
|
|
|
+ Role one = this.lambdaQuery()
|
|
|
+ .eq(Role::getRoleName, updateDTO.getRoleName())
|
|
|
+ .eq(Role::getRoleCode, updateDTO.getRoleCode())
|
|
|
+ .eq(Role::getTenantId, tenantId)
|
|
|
+ .ne(Role::getId, updateDTO.getRoleId())
|
|
|
+ .one();
|
|
|
+ if (one != null) {
|
|
|
+ throw new BusinessException(StrUtil.format("角色名称:{}+角色编码:{}已存在", role.getRoleName(), role.getRoleCode()));
|
|
|
+ }
|
|
|
+ role.setRoleName(updateDTO.getRoleName());
|
|
|
+ role.setRoleCode(updateDTO.getRoleCode());
|
|
|
+ return this.updateById(role);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Transactional
|
|
@@ -104,9 +141,9 @@ public class RoleServiceImpl extends ServiceImpl<IRoleMapper, Role> implements I
|
|
|
// 物理删除角色
|
|
|
baseMapper.deleteByIdList(roleIdList);
|
|
|
// 物理删除角色菜单
|
|
|
- iRoleMenuMapper.deleteByRoleIdList(roleIdList);
|
|
|
+ iRoleMenuService.deleteByRoleIdList(roleIdList);
|
|
|
// 物理删除用户角色
|
|
|
- iUserRoleMapper.deleteByRoleIdList(roleIdList);
|
|
|
+ iUserRoleService.deleteByRoleIdList(roleIdList);
|
|
|
return true;
|
|
|
}
|
|
|
|