Commit 0d41710bd6b4985ca5d9ccb95dc8156fb1c5a12b

Authored by 胡翰林
1 parent 18523e6b

设备台账和供应商接口

... ... @@ -16,6 +16,8 @@ public class TkDeviceCagegoryDTO extends TenantDTO {
16 16 private String parentId;
17 17 @ApiModelProperty(value = "排序")
18 18 private Integer cagegoryOrder;
  19 + @ApiModelProperty(value = "pathid")
  20 + private String pathId;
19 21 @ApiModelProperty(value = "子类别")
20 22 private List<TkDeviceCagegoryDTO> children;
21 23 }
... ...
... ... @@ -15,4 +15,5 @@ public class TkDeviceCagegoryEntity extends TenantBaseEntity {
15 15 private String name;
16 16 private String parentId;
17 17 private Integer cagegoryOrder;
  18 + private String pathId;
18 19 }
... ...
... ... @@ -20,6 +20,7 @@ import org.thingsboard.server.dao.yunteng.entities.TkDeviceAccountEntity;
20 20 import org.thingsboard.server.dao.yunteng.mapper.TkDeviceAccountMapper;
21 21 import org.thingsboard.server.dao.yunteng.service.*;
22 22
  23 +import java.util.List;
23 24 import java.util.Map;
24 25
25 26 @Service
... ... @@ -35,11 +36,15 @@ public class TkDeviceAccountServiceImpl extends AbstractBaseService<TkDeviceAcco
35 36 private final TkUserService tkUserService;
36 37
37 38 @Override
38   - public TkPageData<TkDeviceAccountDTO> page(Map<String, Object> params) {
  39 + public TkPageData<TkDeviceAccountDTO> page(Map<String, Object> params) throws ThingsboardException {
39 40 TkPageData<TkDeviceAccountDTO> result = new TkPageData<>();
40 41 IPage<TkDeviceAccountEntity> page =
41 42 getPage(params, "create_time", false);
42   -
  43 + String categoryId = (String) params.get("categoryId");
  44 + if (StringUtils.isNotBlank(categoryId)) {
  45 + List<String> childIdList = tkDeviceCagegoryService.getChildIdById(categoryId);
  46 + params.put("categoryIds", childIdList);
  47 + }
43 48 IPage<TkDeviceAccountDTO> pageData = baseMapper.getDataPage(page, params);
44 49 if (pageData != null) {
45 50 result.setItems(pageData.getRecords());
... ...
... ... @@ -14,6 +14,7 @@ import org.thingsboard.server.common.data.yunteng.dto.BaseDTO;
14 14 import org.thingsboard.server.common.data.yunteng.dto.TkDeviceCagegoryDTO;
15 15 import org.thingsboard.server.common.data.yunteng.utils.SpringBeanUtils;
16 16 import org.thingsboard.server.dao.util.TkDeviceCagegoryUtil;
  17 +import org.thingsboard.server.dao.yunteng.entities.BaseEntity;
17 18 import org.thingsboard.server.dao.yunteng.entities.TkDeviceCagegoryEntity;
18 19 import org.thingsboard.server.dao.yunteng.mapper.TkDeviceCagegoryMapper;
19 20 import org.thingsboard.server.dao.yunteng.service.AbstractBaseService;
... ... @@ -34,11 +35,27 @@ public class TkDeviceCagegoryServiceImpl extends AbstractBaseService<TkDeviceCag
34 35 @Override
35 36 public TkDeviceCagegoryDTO save(TkDeviceCagegoryDTO tkDeviceCagegoryDTO) throws ThingsboardException {
36 37 checkDto(tkDeviceCagegoryDTO);
  38 + String parentId = tkDeviceCagegoryDTO.getParentId();
  39 + TkDeviceCagegoryDTO parentDto = null;
  40 + if (StringUtils.isNotBlank(parentId)) {
  41 + parentDto = detail(parentId);
  42 + if (parentDto == null) {
  43 + throw new TkDataValidationException("父级类别不存在!");
  44 + }
  45 + }
37 46 TkDeviceCagegoryEntity entity = new TkDeviceCagegoryEntity();
38 47 if (StringUtils.isBlank(tkDeviceCagegoryDTO.getId())) {
39 48 tkDeviceCagegoryDTO.copyToEntity(entity);
40 49 baseMapper.insert(entity);
  50 + String id = entity.getId();
  51 + tkDeviceCagegoryDTO.setPathId(parentDto.getPathId() + "_" + tkDeviceCagegoryDTO.getId());
  52 + LambdaQueryWrapper<TkDeviceCagegoryEntity> filter = new QueryWrapper<TkDeviceCagegoryEntity>().lambda()
  53 + .eq(TkDeviceCagegoryEntity::getId, tkDeviceCagegoryDTO.getId());
  54 + entity = tkDeviceCagegoryDTO.getEntity(TkDeviceCagegoryEntity.class);
  55 + baseMapper.update(entity, filter);
  56 +
41 57 } else {
  58 + tkDeviceCagegoryDTO.setPathId(parentDto.getPathId() + "_" + tkDeviceCagegoryDTO.getId());
42 59 LambdaQueryWrapper<TkDeviceCagegoryEntity> filter = new QueryWrapper<TkDeviceCagegoryEntity>().lambda()
43 60 .eq(TkDeviceCagegoryEntity::getId, tkDeviceCagegoryDTO.getId());
44 61 entity = tkDeviceCagegoryDTO.getEntity(TkDeviceCagegoryEntity.class);
... ... @@ -51,6 +68,9 @@ public class TkDeviceCagegoryServiceImpl extends AbstractBaseService<TkDeviceCag
51 68 }
52 69
53 70 private void checkDto(TkDeviceCagegoryDTO dto) throws ThingsboardException {
  71 + if (StringUtils.isBlank(dto.getName())) {
  72 + throw new TkDataValidationException("类型名称不能为空!");
  73 + }
54 74 if (StringUtils.isBlank(dto.getTenantId())) {
55 75 dto.setTenantId(SpringBeanUtils.getTenantId().getId().toString());
56 76 }
... ... @@ -146,8 +166,16 @@ public class TkDeviceCagegoryServiceImpl extends AbstractBaseService<TkDeviceCag
146 166 }
147 167
148 168 @Override
149   - public List<String> getCategoryIdParentid(String parentId) {
150   - List<String> result=new ArrayList<>();
  169 + public List<String> getChildIdById(String id) throws ThingsboardException {
  170 + QueryWrapper<TkDeviceCagegoryEntity> queryWrapper = new QueryWrapper();
  171 + LambdaQueryWrapper<TkDeviceCagegoryEntity> lambda = queryWrapper.lambda();
  172 + TenantId tenantId = SpringBeanUtils.getTenantId();
  173 + lambda.eq(TkDeviceCagegoryEntity::getTenantId, tenantId.getId().toString());
  174 + lambda.like(TkDeviceCagegoryEntity::getPathId, id);
  175 + List<TkDeviceCagegoryEntity> entityList = baseMapper.selectList(queryWrapper);
  176 + if (CollectionUtils.isNotEmpty(entityList)) {
  177 + return entityList.stream().map(BaseEntity::getId).collect(Collectors.toList());
  178 + }
151 179 return null;
152 180 }
153 181 }
... ...
... ... @@ -8,7 +8,7 @@ import org.thingsboard.server.dao.yunteng.entities.TkDeviceAccountEntity;
8 8 import java.util.Map;
9 9
10 10 public interface TkDeviceAccountService extends BaseService<TkDeviceAccountEntity> {
11   - TkPageData<TkDeviceAccountDTO> page(Map<String, Object> params);
  11 + TkPageData<TkDeviceAccountDTO> page(Map<String, Object> params) throws ThingsboardException;
12 12
13 13 TkDeviceAccountDTO save(TkDeviceAccountDTO dto) throws ThingsboardException;
14 14
... ...
... ... @@ -18,5 +18,5 @@ public interface TkDeviceCagegoryService extends BaseService<TkDeviceCagegoryEn
18 18
19 19 List<TkDeviceCagegoryDTO> getCagegoryByParentid(String parentId) throws ThingsboardException;
20 20
21   - List<String> getCategoryIdParentid(String parentId);
  21 + List<String> getChildIdById(String id) throws ThingsboardException;
22 22 }
... ...
... ... @@ -63,7 +63,7 @@
63 63 </if>
64 64 <if test="queryMap.categoryIds !=null">
65 65 AND o.category_id in
66   - <foreach collection="categoryIds" item="item" index="index"
  66 + <foreach collection="queryMap.categoryIds" item="item" index="index"
67 67 separator="," open="(" close=")">
68 68 #{item}
69 69 </foreach>
... ...