|
|
|
|
@@ -11,10 +11,12 @@ import com.njcn.user.pojo.constant.FunctionState;
|
|
|
|
|
import com.njcn.user.pojo.dto.ComponentDTO;
|
|
|
|
|
import com.njcn.user.pojo.param.ComponentParam;
|
|
|
|
|
import com.njcn.user.pojo.po.Component;
|
|
|
|
|
import com.njcn.user.pojo.po.Role;
|
|
|
|
|
import com.njcn.user.pojo.vo.ComponentVO;
|
|
|
|
|
import com.njcn.user.service.IComponentService;
|
|
|
|
|
import com.njcn.user.service.IRoleComponentService;
|
|
|
|
|
import com.njcn.user.service.IRoleService;
|
|
|
|
|
import com.njcn.user.service.IUserRoleService;
|
|
|
|
|
import com.njcn.web.utils.RequestUtil;
|
|
|
|
|
import lombok.AllArgsConstructor;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
@@ -26,7 +28,7 @@ import java.util.stream.Stream;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <p>
|
|
|
|
|
* 服务实现类
|
|
|
|
|
* 服务实现类
|
|
|
|
|
* </p>
|
|
|
|
|
*
|
|
|
|
|
* @author hongawen
|
|
|
|
|
@@ -40,25 +42,27 @@ public class ComponentServiceImpl extends ServiceImpl<ComponentMapper, Component
|
|
|
|
|
|
|
|
|
|
private final IRoleService roleService;
|
|
|
|
|
|
|
|
|
|
private final IUserRoleService iUserRoleService;
|
|
|
|
|
|
|
|
|
|
private final IRoleComponentService roleComponentService;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean addComponent(ComponentParam componentParam) {
|
|
|
|
|
checkComponentParam(componentParam,false);
|
|
|
|
|
checkComponentParam(componentParam, false);
|
|
|
|
|
Component component = new Component();
|
|
|
|
|
BeanUtil.copyProperties(componentParam, component);
|
|
|
|
|
String functionGroup = componentParam.getFunctionGroup().stream().map(String::valueOf).collect(Collectors.joining(","));
|
|
|
|
|
component.setFunctionGroup(functionGroup);
|
|
|
|
|
component.setState(ComponentState.ENABLE);
|
|
|
|
|
if (Objects.equals(componentParam.getPid(), FunctionState.FATHER_PID)){
|
|
|
|
|
if (Objects.equals(componentParam.getPid(), FunctionState.FATHER_PID)) {
|
|
|
|
|
component.setPids(FunctionState.FATHER_PID);
|
|
|
|
|
} else {
|
|
|
|
|
Component fatherComponent = this.lambdaQuery().eq(Component::getId,componentParam.getPid()).one();
|
|
|
|
|
if (Objects.equals(fatherComponent.getPid(),FunctionState.FATHER_PID)){
|
|
|
|
|
Component fatherComponent = this.lambdaQuery().eq(Component::getId, componentParam.getPid()).one();
|
|
|
|
|
if (Objects.equals(fatherComponent.getPid(), FunctionState.FATHER_PID)) {
|
|
|
|
|
component.setPids(componentParam.getPid());
|
|
|
|
|
} else {
|
|
|
|
|
String pidS = fatherComponent.getPids();
|
|
|
|
|
component.setPids(pidS+","+componentParam.getPid());
|
|
|
|
|
component.setPids(pidS + "," + componentParam.getPid());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return this.save(component);
|
|
|
|
|
@@ -74,7 +78,7 @@ public class ComponentServiceImpl extends ServiceImpl<ComponentMapper, Component
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean updateComponent(ComponentParam.ComponentUpdateParam componentParam) {
|
|
|
|
|
checkComponentParam(componentParam,true);
|
|
|
|
|
checkComponentParam(componentParam, true);
|
|
|
|
|
Component component = new Component();
|
|
|
|
|
BeanUtil.copyProperties(componentParam, component);
|
|
|
|
|
String functionGroup = componentParam.getFunctionGroup().stream().map(String::valueOf).collect(Collectors.joining(","));
|
|
|
|
|
@@ -86,14 +90,14 @@ public class ComponentServiceImpl extends ServiceImpl<ComponentMapper, Component
|
|
|
|
|
public List<ComponentVO> getComponentTree() {
|
|
|
|
|
List<ComponentVO> list = new ArrayList<>();
|
|
|
|
|
List<ComponentDTO> componentList = componentMapper.getAllComponent();
|
|
|
|
|
componentList.forEach(item->{
|
|
|
|
|
componentList.forEach(item -> {
|
|
|
|
|
ComponentVO componentVO = new ComponentVO();
|
|
|
|
|
BeanUtil.copyProperties(item, componentVO);
|
|
|
|
|
componentVO.setFunctionGroup(Arrays.stream(item.getFunctionGroup().split(",")).map(s -> Integer.valueOf(s.trim())).collect(Collectors.toList()));
|
|
|
|
|
list.add(componentVO);
|
|
|
|
|
});
|
|
|
|
|
return list.stream()
|
|
|
|
|
.filter(fun -> Objects.equals(ComponentState.FATHER_PID,fun.getPid()))
|
|
|
|
|
.filter(fun -> Objects.equals(ComponentState.FATHER_PID, fun.getPid()))
|
|
|
|
|
.peek(funS -> funS.setChildren(getChildCategoryList(funS, list)))
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
}
|
|
|
|
|
@@ -102,31 +106,35 @@ public class ComponentServiceImpl extends ServiceImpl<ComponentMapper, Component
|
|
|
|
|
public List<ComponentVO> getUserComponentTree() {
|
|
|
|
|
List<ComponentVO> result = new ArrayList<>();
|
|
|
|
|
List<ComponentVO> componentVOList = new ArrayList<>();
|
|
|
|
|
List<String> roleList = roleService.getIdByUserId(RequestUtil.getUserIndex());
|
|
|
|
|
if (!CollectionUtils.isEmpty(roleList)){
|
|
|
|
|
List<String> componentList = roleComponentService.selectRoleComponent(roleList);
|
|
|
|
|
if (!CollectionUtils.isEmpty(componentList)){
|
|
|
|
|
List<ComponentDTO> list = componentMapper.getComponentByList(componentList);
|
|
|
|
|
list.forEach(item->{
|
|
|
|
|
ComponentVO componentVO = new ComponentVO();
|
|
|
|
|
BeanUtil.copyProperties(item, componentVO);
|
|
|
|
|
componentVO.setFunctionGroup(Arrays.stream(item.getFunctionGroup().split(",")).map(s -> Integer.valueOf(s.trim())).collect(Collectors.toList()));
|
|
|
|
|
componentVOList.add(componentVO);
|
|
|
|
|
});
|
|
|
|
|
result = componentVOList.stream()
|
|
|
|
|
.filter(fun -> Objects.equals(ComponentState.FATHER_PID,fun.getPid()))
|
|
|
|
|
.peek(funS -> funS.setChildren(getChildCategoryList(funS, componentVOList)))
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
List<Role> roleList = iUserRoleService.getRoleListByUserId(RequestUtil.getUserIndex());
|
|
|
|
|
if (!CollectionUtils.isEmpty(roleList)) {
|
|
|
|
|
List<ComponentDTO> list;
|
|
|
|
|
if (roleList.stream().anyMatch(item -> "root".equals(item.getCode()))) {
|
|
|
|
|
list = componentMapper.getAllComponent();
|
|
|
|
|
} else {
|
|
|
|
|
List<String> componentList = roleComponentService.selectRoleComponent(roleList.stream().map(Role::getId).collect(Collectors.toList()));
|
|
|
|
|
list = componentMapper.getComponentByList(componentList);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
list.forEach(item -> {
|
|
|
|
|
ComponentVO componentVO = new ComponentVO();
|
|
|
|
|
BeanUtil.copyProperties(item, componentVO);
|
|
|
|
|
componentVO.setFunctionGroup(Arrays.stream(item.getFunctionGroup().split(",")).map(s -> Integer.valueOf(s.trim())).collect(Collectors.toList()));
|
|
|
|
|
componentVOList.add(componentVO);
|
|
|
|
|
});
|
|
|
|
|
result = componentVOList.stream()
|
|
|
|
|
.filter(fun -> Objects.equals(ComponentState.FATHER_PID, fun.getPid()))
|
|
|
|
|
.peek(funS -> funS.setChildren(getChildCategoryList(funS, componentVOList)))
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 递归组装组件表
|
|
|
|
|
* 递归组装组件表
|
|
|
|
|
*/
|
|
|
|
|
private List<ComponentVO> getChildCategoryList(ComponentVO currMenu, List<ComponentVO> categories) {
|
|
|
|
|
return categories.stream().filter(o -> Objects.equals(o.getPid(),currMenu.getId()))
|
|
|
|
|
return categories.stream().filter(o -> Objects.equals(o.getPid(), currMenu.getId()))
|
|
|
|
|
.peek(o -> o.setChildren(getChildCategoryList(o, categories)))
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
}
|
|
|
|
|
|