|
@@ -12,13 +12,16 @@ import org.springframework.util.StringUtils;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
+import com.gihon.component.entity.BaseEntity;
|
|
import com.gihon.component.exception.BusinessException;
|
|
import com.gihon.component.exception.BusinessException;
|
|
import com.gihon.component.rbac.entity.GihonButton;
|
|
import com.gihon.component.rbac.entity.GihonButton;
|
|
|
|
+import com.gihon.component.rbac.entity.GihonCompany;
|
|
import com.gihon.component.rbac.entity.GihonRole;
|
|
import com.gihon.component.rbac.entity.GihonRole;
|
|
import com.gihon.component.rbac.mapper.GihonRoleMapper;
|
|
import com.gihon.component.rbac.mapper.GihonRoleMapper;
|
|
import com.gihon.component.rbac.service.GihonRoleService;
|
|
import com.gihon.component.rbac.service.GihonRoleService;
|
|
import com.gihon.component.rbac.vo.RoleButtonReq;
|
|
import com.gihon.component.rbac.vo.RoleButtonReq;
|
|
import com.gihon.component.rbac.vo.RoleListReq;
|
|
import com.gihon.component.rbac.vo.RoleListReq;
|
|
|
|
+import com.gihon.component.response.SelectVal;
|
|
|
|
|
|
/**
|
|
/**
|
|
* 直接继承没有多实现处理
|
|
* 直接继承没有多实现处理
|
|
@@ -63,19 +66,26 @@ public class GihonRoleServiceImpl extends ServiceImpl<GihonRoleMapper, GihonRole
|
|
* 前端分页获取角色列表
|
|
* 前端分页获取角色列表
|
|
*/
|
|
*/
|
|
public IPage<GihonRole> getRolelistPage(RoleListReq companyListReq) {
|
|
public IPage<GihonRole> getRolelistPage(RoleListReq companyListReq) {
|
|
- Page<GihonRole> page = new Page<GihonRole>(companyListReq.getPageIndex(), companyListReq.getPageSize());
|
|
|
|
- return this.lambdaQuery().like(StringUtils.hasText(companyListReq.getRoleName()), GihonRole::getRoleName, companyListReq.getRoleName())
|
|
|
|
- .like(StringUtils.hasText(companyListReq.getRoleCode()), GihonRole::getRoleCode, companyListReq.getRoleCode()).page(page);
|
|
|
|
|
|
+ Page<GihonRole> page = new Page<>(companyListReq.getPageIndex(), companyListReq.getPageSize());
|
|
|
|
+ return this.lambdaQuery()
|
|
|
|
+ .like(StringUtils.hasText(companyListReq.getRoleName()), GihonRole::getRoleName,
|
|
|
|
+ companyListReq.getRoleName())
|
|
|
|
+ .like(StringUtils.hasText(companyListReq.getRoleCode()), GihonRole::getRoleCode,
|
|
|
|
+ companyListReq.getRoleCode())
|
|
|
|
+ .eq(companyListReq.getCompanyId() != null, GihonRole::getCompanyId, companyListReq.getCompanyId())
|
|
|
|
+ .page(page);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
* 新增角色
|
|
* 新增角色
|
|
*/
|
|
*/
|
|
public boolean saveRole(GihonRole role) {
|
|
public boolean saveRole(GihonRole role) {
|
|
- int count = this.lambdaQuery().eq(GihonRole::getRoleName, role.getRoleName()).or().eq(GihonRole::getRoleCode, role.getRoleCode()).count();
|
|
|
|
|
|
+ int count = this.lambdaQuery().eq(GihonRole::getRoleName, role.getRoleName()).or()
|
|
|
|
+ .eq(GihonRole::getRoleCode, role.getRoleCode()).count();
|
|
if (count > 0) {
|
|
if (count > 0) {
|
|
throw new BusinessException("角色名称或编码重复");
|
|
throw new BusinessException("角色名称或编码重复");
|
|
}
|
|
}
|
|
|
|
+ role.setState(0);
|
|
return this.save(role);
|
|
return this.save(role);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -107,24 +117,24 @@ public class GihonRoleServiceImpl extends ServiceImpl<GihonRoleMapper, GihonRole
|
|
* 移除一个角色
|
|
* 移除一个角色
|
|
*/
|
|
*/
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Transactional(rollbackFor = Exception.class)
|
|
- public boolean removeRole(GihonRole role) {
|
|
|
|
- GihonRole roleOld = this.getById(role.getId());
|
|
|
|
|
|
+ public boolean removeRole(Long roleId) {
|
|
|
|
+ GihonRole roleOld = this.getById(roleId);
|
|
if (roleOld == null) {
|
|
if (roleOld == null) {
|
|
throw new BusinessException("角色不存在");
|
|
throw new BusinessException("角色不存在");
|
|
}
|
|
}
|
|
// 异步通知
|
|
// 异步通知
|
|
- gihonRoleButtonService.removeButtonByRoleId(role.getId(), null);
|
|
|
|
- gihonUserRoleService.removeRoleByUserId(role.getId());
|
|
|
|
- return this.removeById(role.getId());
|
|
|
|
|
|
+ gihonRoleButtonService.removeButtonByRoleId(roleId, null);
|
|
|
|
+ gihonUserRoleService.removeRoleByUserId(roleId);
|
|
|
|
+ return this.removeById(roleId);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * 获取在某个模块下的按钮权限
|
|
|
|
- * 如果是缓存的时候需要异步通知
|
|
|
|
|
|
+ * 获取在某个模块下的按钮权限 如果是缓存的时候需要异步通知
|
|
*/
|
|
*/
|
|
public List<GihonButton> getButtonByRoleModule(Long roleId, Long moduleId) {
|
|
public List<GihonButton> getButtonByRoleModule(Long roleId, Long moduleId) {
|
|
- List<Long> menuIdList = gihonMenuService.getAllMenu(moduleId,true).stream().map(m -> m.getId()).collect(Collectors.toList());
|
|
|
|
- List<GihonButton> btnList = gihonButtonService.getMenuButton(menuIdList,false);
|
|
|
|
|
|
+ List<Long> menuIdList =
|
|
|
|
+ gihonMenuService.getAllMenu(moduleId, true).stream().map(BaseEntity::getId).collect(Collectors.toList());
|
|
|
|
+ List<GihonButton> btnList = gihonButtonService.getMenuButton(menuIdList, false);
|
|
List<Long> btnCheckedList = gihonRoleButtonService.getButtonListByRole(roleId);
|
|
List<Long> btnCheckedList = gihonRoleButtonService.getButtonListByRole(roleId);
|
|
btnList.forEach(b -> b.setChecked(btnCheckedList.contains(b.getId())));
|
|
btnList.forEach(b -> b.setChecked(btnCheckedList.contains(b.getId())));
|
|
return btnList;
|
|
return btnList;
|
|
@@ -135,8 +145,10 @@ public class GihonRoleServiceImpl extends ServiceImpl<GihonRoleMapper, GihonRole
|
|
*/
|
|
*/
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Transactional(rollbackFor = Exception.class)
|
|
public boolean setButtonByRoleModule(RoleButtonReq req) {
|
|
public boolean setButtonByRoleModule(RoleButtonReq req) {
|
|
- List<Long> menuIdList = gihonMenuService.getAllMenu(req.getModuleId(),true).stream().map(m -> m.getId()).collect(Collectors.toList());
|
|
|
|
- List<Long> allbtnList = gihonButtonService.getMenuButton(menuIdList,true).stream().map(m -> m.getId()).collect(Collectors.toList());
|
|
|
|
|
|
+ List<Long> menuIdList = gihonMenuService.getAllMenu(req.getModuleId(), true).stream().map(m -> m.getId())
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
+ List<Long> allbtnList = gihonButtonService.getMenuButton(menuIdList, true).stream().map(m -> m.getId())
|
|
|
|
+ .collect(Collectors.toList());
|
|
List<Long> btnoldList = gihonRoleButtonService.getButtonListByRole(req.getRoleId());
|
|
List<Long> btnoldList = gihonRoleButtonService.getButtonListByRole(req.getRoleId());
|
|
btnoldList.retainAll(allbtnList);// 求交集,属于当前模块的角色配置
|
|
btnoldList.retainAll(allbtnList);// 求交集,属于当前模块的角色配置
|
|
req.getButtonList().retainAll(allbtnList);
|
|
req.getButtonList().retainAll(allbtnList);
|
|
@@ -155,4 +167,15 @@ public class GihonRoleServiceImpl extends ServiceImpl<GihonRoleMapper, GihonRole
|
|
|
|
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public List<SelectVal> labelAndValue(Long companyId, String roleName) {
|
|
|
|
+ return this.lambdaQuery()
|
|
|
|
+ .like(StringUtils.hasText(roleName), GihonRole::getRoleName, roleName)
|
|
|
|
+ .eq(companyId != null, GihonRole::getId, companyId)
|
|
|
|
+ .orderByDesc(GihonRole::getRoleName)
|
|
|
|
+ .list().stream().map(c -> SelectVal.builder().value(c.getId().toString()).label(c.getRoleName()).build())
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|