Showing
1 changed file
with
15 additions
and
1 deletions
... | ... | @@ -6,6 +6,7 @@ import lombok.RequiredArgsConstructor; |
6 | 6 | import lombok.extern.slf4j.Slf4j; |
7 | 7 | import org.apache.commons.collections4.CollectionUtils; |
8 | 8 | import org.apache.commons.lang3.StringUtils; |
9 | +import org.checkerframework.checker.units.qual.C; | |
9 | 10 | import org.springframework.stereotype.Service; |
10 | 11 | import org.thingsboard.server.common.data.exception.ThingsboardException; |
11 | 12 | import org.thingsboard.server.common.data.id.TenantId; |
... | ... | @@ -48,7 +49,12 @@ public class TkDeviceCagegoryServiceImpl extends AbstractBaseService<TkDeviceCag |
48 | 49 | tkDeviceCagegoryDTO.copyToEntity(entity); |
49 | 50 | String id = UUID.randomUUID().toString(); |
50 | 51 | entity.setId(id); |
51 | - entity.setPathId(parentDto.getPathId() + "_" + id); | |
52 | + if (parentDto == null) { | |
53 | + entity.setPathId(id); | |
54 | + } else { | |
55 | + entity.setPathId(parentDto.getPathId() + "_" + id); | |
56 | + } | |
57 | + | |
52 | 58 | baseMapper.insert(entity); |
53 | 59 | |
54 | 60 | } else { |
... | ... | @@ -118,6 +124,14 @@ public class TkDeviceCagegoryServiceImpl extends AbstractBaseService<TkDeviceCag |
118 | 124 | @Override |
119 | 125 | public List<TkDeviceCagegoryDTO> getAllCagegory(TkDeviceCagegoryDTO dto) throws ThingsboardException { |
120 | 126 | List<TkDeviceCagegoryDTO> topMenuList = getCagegoryByParentid(null); |
127 | + if (CollectionUtils.isEmpty(topMenuList)) { | |
128 | + TkDeviceCagegoryDTO parent = new TkDeviceCagegoryDTO(); | |
129 | + TenantId tenantId = SpringBeanUtils.getTenantId(); | |
130 | + parent.setTenantId(tenantId.toString()); | |
131 | + parent.setName("全部"); | |
132 | + TkDeviceCagegoryDTO parentDto = save(parent); | |
133 | + topMenuList.add(parentDto); | |
134 | + } | |
121 | 135 | List<TkDeviceCagegoryDTO> subMenu = getSubCategory(); |
122 | 136 | if (CollectionUtils.isEmpty(subMenu)) { |
123 | 137 | return topMenuList; | ... | ... |