Showing
1 changed file
with
15 additions
and
1 deletions
@@ -6,6 +6,7 @@ import lombok.RequiredArgsConstructor; | @@ -6,6 +6,7 @@ import lombok.RequiredArgsConstructor; | ||
6 | import lombok.extern.slf4j.Slf4j; | 6 | import lombok.extern.slf4j.Slf4j; |
7 | import org.apache.commons.collections4.CollectionUtils; | 7 | import org.apache.commons.collections4.CollectionUtils; |
8 | import org.apache.commons.lang3.StringUtils; | 8 | import org.apache.commons.lang3.StringUtils; |
9 | +import org.checkerframework.checker.units.qual.C; | ||
9 | import org.springframework.stereotype.Service; | 10 | import org.springframework.stereotype.Service; |
10 | import org.thingsboard.server.common.data.exception.ThingsboardException; | 11 | import org.thingsboard.server.common.data.exception.ThingsboardException; |
11 | import org.thingsboard.server.common.data.id.TenantId; | 12 | import org.thingsboard.server.common.data.id.TenantId; |
@@ -48,7 +49,12 @@ public class TkDeviceCagegoryServiceImpl extends AbstractBaseService<TkDeviceCag | @@ -48,7 +49,12 @@ public class TkDeviceCagegoryServiceImpl extends AbstractBaseService<TkDeviceCag | ||
48 | tkDeviceCagegoryDTO.copyToEntity(entity); | 49 | tkDeviceCagegoryDTO.copyToEntity(entity); |
49 | String id = UUID.randomUUID().toString(); | 50 | String id = UUID.randomUUID().toString(); |
50 | entity.setId(id); | 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 | baseMapper.insert(entity); | 58 | baseMapper.insert(entity); |
53 | 59 | ||
54 | } else { | 60 | } else { |
@@ -118,6 +124,14 @@ public class TkDeviceCagegoryServiceImpl extends AbstractBaseService<TkDeviceCag | @@ -118,6 +124,14 @@ public class TkDeviceCagegoryServiceImpl extends AbstractBaseService<TkDeviceCag | ||
118 | @Override | 124 | @Override |
119 | public List<TkDeviceCagegoryDTO> getAllCagegory(TkDeviceCagegoryDTO dto) throws ThingsboardException { | 125 | public List<TkDeviceCagegoryDTO> getAllCagegory(TkDeviceCagegoryDTO dto) throws ThingsboardException { |
120 | List<TkDeviceCagegoryDTO> topMenuList = getCagegoryByParentid(null); | 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 | List<TkDeviceCagegoryDTO> subMenu = getSubCategory(); | 135 | List<TkDeviceCagegoryDTO> subMenu = getSubCategory(); |
122 | if (CollectionUtils.isEmpty(subMenu)) { | 136 | if (CollectionUtils.isEmpty(subMenu)) { |
123 | return topMenuList; | 137 | return topMenuList; |