|
@@ -1,11 +1,20 @@
|
|
|
package com.sxtvs.open.api.user.service.impl;
|
|
|
|
|
|
+import com.sxtvs.open.api.user.dto.RoleDTO;
|
|
|
+import com.sxtvs.open.api.user.entity.Menus;
|
|
|
import com.sxtvs.open.api.user.entity.UserRole;
|
|
|
import com.sxtvs.open.api.user.mapper.UserRoleMapper;
|
|
|
import com.sxtvs.open.api.user.service.IUserRoleService;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.sxtvs.open.core.advice.BizException;
|
|
|
+import jakarta.annotation.Resource;
|
|
|
+import org.apache.logging.log4j.util.Strings;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
/**
|
|
|
* <p>
|
|
|
* 服务实现类
|
|
@@ -17,4 +26,36 @@ import org.springframework.stereotype.Service;
|
|
|
@Service
|
|
|
public class UserRoleServiceImpl extends ServiceImpl<UserRoleMapper, UserRole> implements IUserRoleService {
|
|
|
|
|
|
+ @Resource
|
|
|
+ private MenusServiceImpl menusService;
|
|
|
+
|
|
|
+ public List<UserRole> roles(){
|
|
|
+ return list().stream().peek(role -> {
|
|
|
+ role.setMenus(menusService.lambdaQuery().in(Menus::getId, Arrays.asList(role.getMenuId().split(","))).list());
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
+ public void createRole(RoleDTO roleDTO){
|
|
|
+ UserRole userRole = new UserRole();
|
|
|
+ userRole.setName(roleDTO.getName());
|
|
|
+ userRole.setMenuId(Strings.join(roleDTO.getMenuId(), ','));
|
|
|
+ save(userRole);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void updateRole(RoleDTO roleDTO){
|
|
|
+ UserRole ur = getById(roleDTO.getId());
|
|
|
+ if (null == ur){
|
|
|
+ throw new BizException("角色不存在");
|
|
|
+ }
|
|
|
+ ur.setName(roleDTO.getName());
|
|
|
+ ur.setMenuId(Strings.join(roleDTO.getMenuId(), ','));
|
|
|
+ updateById(ur);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void deleteRole(Integer id){
|
|
|
+ removeById(id);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
}
|