|
|
@ -17,6 +17,8 @@ |
|
|
|
|
|
|
|
package com.elink.esua.epdc.service.impl; |
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONArray; |
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
import com.elink.esua.epdc.commons.mybatis.service.impl.BaseServiceImpl; |
|
|
@ -24,14 +26,20 @@ import com.elink.esua.epdc.commons.tools.constant.Constant; |
|
|
|
import com.elink.esua.epdc.commons.tools.constant.FieldConstant; |
|
|
|
import com.elink.esua.epdc.commons.tools.exception.RenException; |
|
|
|
import com.elink.esua.epdc.commons.tools.page.PageData; |
|
|
|
import com.elink.esua.epdc.commons.tools.security.user.SecurityUser; |
|
|
|
import com.elink.esua.epdc.commons.tools.utils.ConvertUtils; |
|
|
|
import com.elink.esua.epdc.commons.tools.utils.Result; |
|
|
|
import com.elink.esua.epdc.commons.tools.utils.TreeUtils; |
|
|
|
import com.elink.esua.epdc.dao.ModuleTypeDao; |
|
|
|
import com.elink.esua.epdc.dto.ModuleOption; |
|
|
|
import com.elink.esua.epdc.dto.ModuleOptionDTO; |
|
|
|
import com.elink.esua.epdc.dto.ModuleTypeCategoryDTO; |
|
|
|
import com.elink.esua.epdc.dto.ModuleTypeDTO; |
|
|
|
import com.elink.esua.epdc.entity.ModuleTypeEntity; |
|
|
|
import com.elink.esua.epdc.feign.AdminFeignClient; |
|
|
|
import com.elink.esua.epdc.redis.ModuleTypeRedis; |
|
|
|
import com.elink.esua.epdc.service.ModuleTypeService; |
|
|
|
import com.google.common.collect.Lists; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
@ -51,6 +59,9 @@ public class ModuleTypeServiceImpl extends BaseServiceImpl<ModuleTypeDao, Module |
|
|
|
@Autowired |
|
|
|
private ModuleTypeRedis moduleTypeRedis; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private AdminFeignClient adminFeignClient; |
|
|
|
|
|
|
|
@Override |
|
|
|
public PageData<ModuleTypeDTO> page(Map<String, Object> params) { |
|
|
|
IPage<ModuleTypeEntity> page = baseDao.selectPage( |
|
|
@ -184,4 +195,82 @@ public class ModuleTypeServiceImpl extends BaseServiceImpl<ModuleTypeDao, Module |
|
|
|
return TreeUtils.build(dtoList); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public ModuleOption getModuleListByRole( ) { |
|
|
|
Result<String> roleResult = adminFeignClient.getRoleStringIdsByUserId(SecurityUser.getUserId()); |
|
|
|
if (!roleResult.success()) { |
|
|
|
throw new RenException("获取用户角色失败"); |
|
|
|
} |
|
|
|
List<ModuleOptionDTO> deptList = baseDao.getModuleListByRole(roleResult.getData()); |
|
|
|
|
|
|
|
JSONObject node; |
|
|
|
JSONArray headNodes = new JSONArray(); |
|
|
|
for (ModuleOptionDTO deptItemDto : deptList) { |
|
|
|
if (deptItemDto.getPid().longValue() == 0) { |
|
|
|
node = new JSONObject(); |
|
|
|
node.put("value", deptItemDto.getId()); |
|
|
|
node.put("label", deptItemDto.getLabel()); |
|
|
|
headNodes.add(node); |
|
|
|
} |
|
|
|
} |
|
|
|
// 用于存放所有父级节点
|
|
|
|
JSONArray parent; |
|
|
|
parent = headNodes; |
|
|
|
// 用于存放所有子级节点
|
|
|
|
JSONArray allChildren = new JSONArray(); |
|
|
|
JSONArray children; |
|
|
|
// 用于存放单个子级节点
|
|
|
|
JSONObject childNode; |
|
|
|
// 存放其余未处理的类别(节点)
|
|
|
|
List<ModuleOptionDTO> others = this.getOtherDept(deptList, parent); |
|
|
|
|
|
|
|
while (!others.isEmpty()) { |
|
|
|
for (int i = 0; i < parent.size(); i++) { |
|
|
|
node = parent.getJSONObject(i); |
|
|
|
children = new JSONArray(); |
|
|
|
for (ModuleOptionDTO categoryTreeDto : others) { |
|
|
|
if (categoryTreeDto.getPid().equals(node.get("value"))) { |
|
|
|
childNode = new JSONObject(); |
|
|
|
childNode.put("value", categoryTreeDto.getId()); |
|
|
|
childNode.put("label", categoryTreeDto.getLabel()); |
|
|
|
children.add(childNode); |
|
|
|
allChildren.add(childNode); |
|
|
|
} |
|
|
|
} |
|
|
|
if (!children.isEmpty()) { |
|
|
|
node.put("children", children); |
|
|
|
} |
|
|
|
} |
|
|
|
parent = allChildren; |
|
|
|
|
|
|
|
others = this.getOtherDept(others, parent); |
|
|
|
|
|
|
|
} |
|
|
|
//存放到redis中
|
|
|
|
ModuleOption option = new ModuleOption(); |
|
|
|
option.setModuleOptions(headNodes); |
|
|
|
|
|
|
|
return option; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<ModuleOptionDTO> getOtherDept(List<ModuleOptionDTO> deptList, JSONArray parent) { |
|
|
|
List<Long> already = Lists.newArrayList(); |
|
|
|
for (int i = 0; i < parent.size(); i++) { |
|
|
|
already.add((Long) parent.getJSONObject(i).get("value")); |
|
|
|
} |
|
|
|
|
|
|
|
List<ModuleOptionDTO> others = Lists.newArrayList(); |
|
|
|
|
|
|
|
for (ModuleOptionDTO categoryTreeDto : deptList) { |
|
|
|
Long categoryTreeDtoId = categoryTreeDto.getId(); |
|
|
|
if (!already.contains(categoryTreeDtoId)) { |
|
|
|
others.add(categoryTreeDto); |
|
|
|
} |
|
|
|
} |
|
|
|
return others; |
|
|
|
} |
|
|
|
|
|
|
|
} |