...
|
...
|
@@ -38,6 +38,7 @@ import org.thingsboard.server.dao.yunteng.service.ThingsModelService; |
38
|
38
|
import org.thingsboard.server.dao.yunteng.service.TkDeviceProfileService;
|
39
|
39
|
|
40
|
40
|
import java.util.*;
|
|
41
|
+import java.util.concurrent.atomic.AtomicInteger;
|
41
|
42
|
import java.util.stream.Collectors;
|
42
|
43
|
|
43
|
44
|
@Service
|
...
|
...
|
@@ -68,7 +69,7 @@ public class ThingsModelServiceImpl |
68
|
69
|
}
|
69
|
70
|
IPage<TkThingsModelEntity> iPage =
|
70
|
71
|
baseMapper.selectPage(
|
71
|
|
- getPage(queryMap, FastIotConstants.DefaultOrder.CREATE_TIME, false),
|
|
72
|
+ getPage(queryMap, "sort", true),
|
72
|
73
|
new LambdaQueryWrapper<TkThingsModelEntity>()
|
73
|
74
|
.eq(StringUtils.isNotEmpty(tenantId), TkThingsModelEntity::getTenantId, tenantId)
|
74
|
75
|
.eq(StringUtils.isNotEmpty(deviceProfileId), TkThingsModelEntity::getDeviceProfileId, deviceProfileId)
|
...
|
...
|
@@ -361,7 +362,7 @@ public class ThingsModelServiceImpl |
361
|
362
|
DeviceProfile deviceProfile = deviceProfileService.findDeviceProfileById(new TenantId(UUID.fromString(tenantId)), new DeviceProfileId(UUID.fromString(profileDTO.getTbProfileId())));
|
362
|
363
|
DeviceTypeEnum type = profileDTO.getDeviceType();
|
363
|
364
|
String transportType = String.valueOf(deviceProfile.getTransportType());
|
364
|
|
- if (transportType.equals("TCP") && type.equals(DeviceTypeEnum.SENSOR) && (null != importThingsModel.getData().getServices() || null != importThingsModel.getData().getEvents())) {
|
|
365
|
+ if (transportType.equals("TCP") && type.equals(DeviceTypeEnum.SENSOR) && (!importThingsModel.getData().getServices().isEmpty() || !importThingsModel.getData().getEvents().isEmpty())) {
|
365
|
366
|
throw new TkDataValidationException(MessageUtils.message(ErrorMessage.INVALID_PARAMETER_IMPORT.getI18nCode()));
|
366
|
367
|
}
|
367
|
368
|
if (Objects.equals(importThingsModel.getFunctionType(), FunctionTypeEnum.all)
|
...
|
...
|
@@ -406,6 +407,10 @@ public class ThingsModelServiceImpl |
406
|
407
|
entities,
|
407
|
408
|
null);
|
408
|
409
|
}
|
|
410
|
+ AtomicInteger i = new AtomicInteger(getCountById(tkDeviceProfileId, false)+1);
|
|
411
|
+ entities.stream().forEach(e->{
|
|
412
|
+ e.setSort(i.getAndIncrement());
|
|
413
|
+ });
|
409
|
414
|
insertBatch(entities, TkThingsModelEntity.class);
|
410
|
415
|
entities.forEach(entity -> {
|
411
|
416
|
//云边同步
|
...
|
...
|
@@ -458,6 +463,10 @@ public class ThingsModelServiceImpl |
458
|
463
|
entities,
|
459
|
464
|
categoryId);
|
460
|
465
|
}
|
|
466
|
+ AtomicInteger i = new AtomicInteger(getCountById(categoryId, true)+1);
|
|
467
|
+ entities.stream().forEach(e->{
|
|
468
|
+ e.setSort(i.getAndIncrement());
|
|
469
|
+ });
|
461
|
470
|
return insertBatch(entities, TkThingsModelEntity.class);
|
462
|
471
|
}
|
463
|
472
|
|
...
|
...
|
@@ -507,6 +516,77 @@ public class ThingsModelServiceImpl |
507
|
516
|
return list;
|
508
|
517
|
}
|
509
|
518
|
|
|
519
|
+ @Override
|
|
520
|
+ public boolean updateSort(String id, String sortType,Boolean isCategory) {
|
|
521
|
+ TkThingsModelEntity entity = baseMapper.selectById(id);
|
|
522
|
+ TkThingsModelEntity sortEntity ;
|
|
523
|
+ List<TkThingsModelEntity> sortEntityList;
|
|
524
|
+ switch (sortType) {
|
|
525
|
+ case "up":
|
|
526
|
+ sortEntity = getSortEntity(entity,entity.getSort()-1,isCategory);
|
|
527
|
+ swapSortValues(entity,sortEntity);
|
|
528
|
+ break;
|
|
529
|
+ case "down":
|
|
530
|
+ sortEntity = getSortEntity(entity,entity.getSort()+1,isCategory);
|
|
531
|
+ swapSortValues(entity,sortEntity);
|
|
532
|
+ break;
|
|
533
|
+ case "topUp":
|
|
534
|
+ entity.setSort(0);
|
|
535
|
+ baseMapper.updateById(entity);
|
|
536
|
+ getSortEntityList(entity,isCategory);
|
|
537
|
+ break;
|
|
538
|
+ case "bottomUp":
|
|
539
|
+ sortEntityList = getSortEntityList(entity,isCategory);
|
|
540
|
+ entity.setSort(sortEntityList.size()+1);
|
|
541
|
+ baseMapper.updateById(entity);
|
|
542
|
+ break;
|
|
543
|
+ }
|
|
544
|
+ return true;
|
|
545
|
+ }
|
|
546
|
+
|
|
547
|
+ @Override
|
|
548
|
+ public Integer getCountById(String id, Boolean isCategory) {
|
|
549
|
+ return Math.toIntExact(baseMapper.selectCount(
|
|
550
|
+ new LambdaQueryWrapper<TkThingsModelEntity>()
|
|
551
|
+ .eq(isCategory, TkThingsModelEntity::getCategoryId, id)
|
|
552
|
+ .eq(!isCategory, TkThingsModelEntity::getDeviceProfileId, id)));
|
|
553
|
+ }
|
|
554
|
+
|
|
555
|
+ private List<TkThingsModelEntity> getSortEntityList(TkThingsModelEntity entity,Boolean isCategory){
|
|
556
|
+ List<TkThingsModelEntity> list = baseMapper.selectList(
|
|
557
|
+ new LambdaQueryWrapper<TkThingsModelEntity>()
|
|
558
|
+ .notIn(TkThingsModelEntity::getId,entity.getId())
|
|
559
|
+ .eq(isCategory, TkThingsModelEntity::getCategoryId, entity.getCategoryId())
|
|
560
|
+ .eq(!isCategory, TkThingsModelEntity::getDeviceProfileId, entity.getDeviceProfileId())
|
|
561
|
+ .orderBy(true, true, TkThingsModelEntity::getSort));
|
|
562
|
+ AtomicInteger i= new AtomicInteger(1);
|
|
563
|
+ list.stream().forEach(e->{
|
|
564
|
+ e.setSort(i.getAndIncrement());
|
|
565
|
+ baseMapper.updateById(e);
|
|
566
|
+ });
|
|
567
|
+ return list;
|
|
568
|
+ }
|
|
569
|
+
|
|
570
|
+ private TkThingsModelEntity getSortEntity(TkThingsModelEntity entity ,Integer sort ,Boolean isCategory){
|
|
571
|
+ return baseMapper.selectOne(
|
|
572
|
+ new LambdaQueryWrapper<TkThingsModelEntity>()
|
|
573
|
+ .eq(TkThingsModelEntity::getSort,sort)
|
|
574
|
+ .eq(isCategory, TkThingsModelEntity::getCategoryId, entity.getCategoryId())
|
|
575
|
+ .eq(!isCategory, TkThingsModelEntity::getDeviceProfileId, entity.getDeviceProfileId()));
|
|
576
|
+ }
|
|
577
|
+
|
|
578
|
+ // 交换两个对象的 sort 值
|
|
579
|
+ private void swapSortValues(TkThingsModelEntity entity1, TkThingsModelEntity entity2) {
|
|
580
|
+ if(null!=entity1&&null!=entity2){
|
|
581
|
+ Integer oldSort = entity1.getSort();
|
|
582
|
+ Integer newSort = entity2.getSort();
|
|
583
|
+ entity1.setSort(newSort);
|
|
584
|
+ entity2.setSort(oldSort);
|
|
585
|
+ baseMapper.updateById(entity1);
|
|
586
|
+ baseMapper.updateById(entity2);
|
|
587
|
+ }
|
|
588
|
+ }
|
|
589
|
+
|
510
|
590
|
private void checkNameAndIdentifier(
|
511
|
591
|
List<String> existIdentifiers,
|
512
|
592
|
FunctionTypeEnum functionType,
|
...
|
...
|
|