Browse Source

监控分析拖拽

2024年8月13日11:16:40
thing_master
lishuai 1 year ago
parent
commit
c1840ef4da
  1. 6
      common/core/src/main/java/com/thing/common/core/utils/JacksonUtil.java
  2. 8
      modules/thing/src/main/java/com/thing/device/source/controller/IotThingSourceController.java
  3. 2
      modules/thing/src/main/java/com/thing/device/source/service/IotThingSourceService.java
  4. 56
      modules/thing/src/main/java/com/thing/device/source/service/impl/IotThingSourceServiceImpl.java
  5. 4
      modules/thing/src/main/java/com/thing/thing/dict/controller/IotThingDictController.java
  6. 16
      modules/thing/src/main/java/com/thing/thing/dict/service/impl/IotThingDictServiceImpl.java
  7. 19
      modules/thing/src/main/java/com/thing/thing/dictRelation/service/impl/IotThingDictRelationServiceImpl.java
  8. 3
      modules/thing/src/main/java/com/thing/thing/entity/service/impl/IotThingEntityServiceImpl.java

6
common/core/src/main/java/com/thing/common/core/utils/JacksonUtil.java

@ -213,10 +213,16 @@ public class JacksonUtil {
if (StringUtils.isBlank(actualValue)) { if (StringUtils.isBlank(actualValue)) {
return false; return false;
} }
if(StringUtils.equals("tenantCode",fieldName)){
if (!actualValue.equals(fieldValue)) {
return false;
}
}else{
if (!actualValue.contains(fieldValue)) { if (!actualValue.contains(fieldValue)) {
return false; return false;
} }
} }
}
return true; return true;
} }

8
modules/thing/src/main/java/com/thing/device/source/controller/IotThingSourceController.java

@ -134,4 +134,12 @@ public class IotThingSourceController {
return new Result<List<IotThingSourceAttrRespDTO>>().ok(attrList); return new Result<List<IotThingSourceAttrRespDTO>>().ok(attrList);
} }
@GetMapping("dragAndDrop")
@Operation(summary="字典类型集合")
public Result<Void> dragAndDrop(@RequestParam("id") Long id,@RequestParam("toId") Long toId,@RequestParam("sort")Long sort) {
iotThingSourceService.dragAndDrop(id, toId, sort);
return new Result<>();
}
} }

2
modules/thing/src/main/java/com/thing/device/source/service/IotThingSourceService.java

@ -41,4 +41,6 @@ public interface IotThingSourceService extends IBaseService<IotThingSourceEntity
List<IotThingSourceDTO> sourceDetail(IotThingSourceReqDTO iotThingSourceDTO); List<IotThingSourceDTO> sourceDetail(IotThingSourceReqDTO iotThingSourceDTO);
List<IotThingSourceAttrRespDTO> getAttrListByThingRelationDTONew(IotThingSourceGetAttrDTO iotThingSourceGetAttrDTO); List<IotThingSourceAttrRespDTO> getAttrListByThingRelationDTONew(IotThingSourceGetAttrDTO iotThingSourceGetAttrDTO);
void dragAndDrop(Long id,Long toId,Long sort);
} }

56
modules/thing/src/main/java/com/thing/device/source/service/impl/IotThingSourceServiceImpl.java

@ -3,6 +3,7 @@ package com.thing.device.source.service.impl;
import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.map.MapUtil; import cn.hutool.core.map.MapUtil;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.google.common.collect.Lists;
import com.mybatisflex.core.paginate.Page; import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper; import com.mybatisflex.core.query.QueryWrapper;
import com.thing.common.core.enumeration.AttributeTypeEnum; import com.thing.common.core.enumeration.AttributeTypeEnum;
@ -31,7 +32,6 @@ import com.thing.thing.relation.detail.dto.ThingTreeDTO;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@ -51,6 +51,10 @@ public class IotThingSourceServiceImpl extends BaseServiceImpl<IotThingSourceMap
private final ThingManageContextService thingManageContextService; private final ThingManageContextService thingManageContextService;
private final IotThingMenuConfigMapper iotThingMenuConfigMapper;
@Override @Override
public QueryWrapper getWrapper(Map<String, Object> params) { public QueryWrapper getWrapper(Map<String, Object> params) {
QueryWrapper queryWrapper = new QueryWrapper(); QueryWrapper queryWrapper = new QueryWrapper();
@ -427,10 +431,6 @@ public class IotThingSourceServiceImpl extends BaseServiceImpl<IotThingSourceMap
.toList(); .toList();
} }
@Autowired
private IotThingMenuConfigMapper iotThingMenuConfigMapper;
@Override @Override
public List<IotThingSourceAttrRespDTO> getAttrListByThingRelationDTONew(IotThingSourceGetAttrDTO iotThingSourceGetAttrDTO) { public List<IotThingSourceAttrRespDTO> getAttrListByThingRelationDTONew(IotThingSourceGetAttrDTO iotThingSourceGetAttrDTO) {
if (CollectionUtil.isEmpty(iotThingSourceGetAttrDTO.getIotThingSourceRelationDTOList())) { if (CollectionUtil.isEmpty(iotThingSourceGetAttrDTO.getIotThingSourceRelationDTOList())) {
@ -483,6 +483,52 @@ public class IotThingSourceServiceImpl extends BaseServiceImpl<IotThingSourceMap
return iotThingSourceAttrList.stream().filter(distinctByKey(IotThingSourceAttrRespDTO::getThingAttrCode)).sorted(Comparator.comparing(IotThingSourceAttrRespDTO::getSort)).collect(Collectors.toList()); return iotThingSourceAttrList.stream().filter(distinctByKey(IotThingSourceAttrRespDTO::getThingAttrCode)).sorted(Comparator.comparing(IotThingSourceAttrRespDTO::getSort)).collect(Collectors.toList());
} }
@Override
public void dragAndDrop(Long id, Long toId, Long sort) {
IotThingSourceEntity sourceEntity = mapper.selectOneById(id);
IotThingSourceEntity toSourceEntity = mapper.selectOneById(toId);
if(!Objects.equals(sourceEntity.getFromId(),toSourceEntity.getFromId()) || !Objects.equals(sourceEntity.getConfigType(),toSourceEntity.getConfigType())){
throw new SysException("不能拖拽到不同层级");
}
//自定义字典列表
List<IotThingSourceEntity> sourceOtherEntities = mapper.selectListByQuery(QueryWrapper.create()
.eq(IotThingSourceEntity::getFromId, sourceEntity.getFromId())
.eq(IotThingSourceEntity::getConfigType, sourceEntity.getConfigType())
.ne(IotThingSourceEntity::getId, id)
);
if(CollectionUtils.isEmpty(sourceOtherEntities)){
return;
}
//若是大于当前目前序号则更新当前序号之前的排序
AtomicLong aLong = new AtomicLong(0);
List<IotThingSourceEntity> resList = Lists.newArrayList();
if(toSourceEntity.getSort()<=sort){
sourceOtherEntities.stream().filter(s -> s.getSort() < sort)
.sorted(Comparator.comparing(IotThingSourceEntity::getSort))
.forEach(s -> s.setSort(aLong.incrementAndGet()));
sourceEntity.setSort(aLong.incrementAndGet());
mapper.update(sourceEntity);
sourceOtherEntities.stream()
.sorted(Comparator.comparing(IotThingSourceEntity::getSort))
.filter(s -> s.getSort() >= sort).forEach(s -> s.setSort(aLong.incrementAndGet()));
}else{
List<IotThingSourceEntity> list = sourceOtherEntities.stream().filter(s -> s.getSort() <= sort).toList();
list.stream().sorted(Comparator.comparing(IotThingSourceEntity::getSort))
.forEach(s -> {
s.setSort(aLong.incrementAndGet());
});
resList.addAll(list);
sourceEntity.setSort(aLong.incrementAndGet());
resList.add(sourceEntity);
List<IotThingSourceEntity> list1 = sourceOtherEntities.stream().filter(s -> s.getSort() > sort).toList();
list1.stream().sorted(Comparator.comparing(IotThingSourceEntity::getSort))
.forEach(s -> s.setSort(aLong.incrementAndGet()));
resList.addAll(list1);
}
this.updateBatch(resList);
}
/** /**
* 自定义函数去重 * 自定义函数去重
* *

4
modules/thing/src/main/java/com/thing/thing/dict/controller/IotThingDictController.java

@ -168,9 +168,9 @@ public class IotThingDictController {
} }
@GetMapping("dragAndDrop/{id}/{toId}/{sort}")
@GetMapping("dragAndDrop")
@Operation(summary="字典类型集合") @Operation(summary="字典类型集合")
public Result<Void> dragAndDrop(@PathVariable("id") Long id,@PathVariable("toId") Long toId,@PathVariable("sort")Long sort) {
public Result<Void> dragAndDrop(@RequestParam("id") Long id,@RequestParam("toId") Long toId,@RequestParam("sort")Long sort) {
service.dragAndDrop(id, toId, sort); service.dragAndDrop(id, toId, sort);
return new Result<>(); return new Result<>();
} }

16
modules/thing/src/main/java/com/thing/thing/dict/service/impl/IotThingDictServiceImpl.java

@ -208,6 +208,8 @@ public class IotThingDictServiceImpl extends BaseServiceImpl<IotThingDictMapper,
QueryWrapper queryWrapper = QueryWrapper QueryWrapper queryWrapper = QueryWrapper
.create() .create()
.select(max(IOT_THING_DICT_ENTITY.SORT)); .select(max(IOT_THING_DICT_ENTITY.SORT));
queryWrapper.where(IOT_THING_DICT_ENTITY.IS_DEFAULT.eq(1)
.or(IOT_THING_DICT_ENTITY.IS_DEFAULT.eq(0).and(IOT_THING_DICT_ENTITY.TENANT_CODE.eq(UserContext.getRealTenantCode()))));
Long num = mapper.selectOneByQueryAs(queryWrapper, Long.class); Long num = mapper.selectOneByQueryAs(queryWrapper, Long.class);
return Objects.isNull(num) ? 1 : num+1; return Objects.isNull(num) ? 1 : num+1;
} }
@ -404,18 +406,12 @@ public class IotThingDictServiceImpl extends BaseServiceImpl<IotThingDictMapper,
if(toDictEntity.getSort()<=sort){ if(toDictEntity.getSort()<=sort){
iotThingDictEntities.stream().filter(s -> s.getSort() < sort) iotThingDictEntities.stream().filter(s -> s.getSort() < sort)
.sorted(Comparator.comparing(IotThingDictEntity::getSort)) .sorted(Comparator.comparing(IotThingDictEntity::getSort))
.forEach(s -> {
s.setSort(aLong.incrementAndGet());
mapper.update(s);
});
.forEach(s -> s.setSort(aLong.incrementAndGet()));
iotThingDictEntity.setSort(aLong.incrementAndGet()); iotThingDictEntity.setSort(aLong.incrementAndGet());
mapper.update(iotThingDictEntity); mapper.update(iotThingDictEntity);
iotThingDictEntities.stream() iotThingDictEntities.stream()
.sorted(Comparator.comparing(IotThingDictEntity::getSort)) .sorted(Comparator.comparing(IotThingDictEntity::getSort))
.filter(s -> s.getSort() >= sort).forEach(s -> {
s.setSort(aLong.incrementAndGet());
mapper.update(s);
});
.filter(s -> s.getSort() >= sort).forEach(s -> s.setSort(aLong.incrementAndGet()));
}else{ }else{
List<IotThingDictEntity> list = iotThingDictEntities.stream().filter(s -> s.getSort() <= sort).toList(); List<IotThingDictEntity> list = iotThingDictEntities.stream().filter(s -> s.getSort() <= sort).toList();
list.stream().sorted(Comparator.comparing(IotThingDictEntity::getSort)) list.stream().sorted(Comparator.comparing(IotThingDictEntity::getSort))
@ -427,9 +423,7 @@ public class IotThingDictServiceImpl extends BaseServiceImpl<IotThingDictMapper,
resList.add(iotThingDictEntity); resList.add(iotThingDictEntity);
List<IotThingDictEntity> list1 = iotThingDictEntities.stream().filter(s -> s.getSort() > sort).toList(); List<IotThingDictEntity> list1 = iotThingDictEntities.stream().filter(s -> s.getSort() > sort).toList();
list1.stream().sorted(Comparator.comparing(IotThingDictEntity::getSort)) list1.stream().sorted(Comparator.comparing(IotThingDictEntity::getSort))
.forEach(s -> {
s.setSort(aLong.incrementAndGet());
});
.forEach(s -> s.setSort(aLong.incrementAndGet()));
resList.addAll(list1); resList.addAll(list1);
} }
this.updateBatch(resList); this.updateBatch(resList);

19
modules/thing/src/main/java/com/thing/thing/dictRelation/service/impl/IotThingDictRelationServiceImpl.java

@ -168,17 +168,22 @@ public class IotThingDictRelationServiceImpl extends BaseServiceImpl<IotThingDic
//更新缓存 //更新缓存
CacheInit.dictRelationMap(dictRelationList,cache); CacheInit.dictRelationMap(dictRelationList,cache);
} }
if(StringUtils.isBlank(entityIds)){
List<ObjectNode> entityServiceList = thingEntityService.findList(null, null, null, null, tenantCode, null, null, null, null, templateMark);
entityIds = entityServiceList.stream().map(jsonObject -> jsonObject.get(CacheNameEnum.EntityField.THING_ENTITY_ID.getField()).asText()).collect(Collectors.joining(","));
}
if(StringUtils.isBlank(orderField)){ if(StringUtils.isBlank(orderField)){
orderField = CacheNameEnum.DictField.THING_DICT_RELATION_SORT.getField(); orderField = CacheNameEnum.DictField.THING_DICT_RELATION_SORT.getField();
} }
String finalOrderField = CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, orderField);; String finalOrderField = CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, orderField);;
Comparator<ObjectNode> comparator = CompareUtils.getComparator(order, finalOrderField); //封装参数 Comparator<ObjectNode> comparator = CompareUtils.getComparator(order, finalOrderField); //封装参数
List<Pair<String, String>> pairs = buildParam(groupName,templateMark,dataType,tenantCode);
List<Pair<String, String>> pairs = buildParam(groupName,templateMark,dataType);
String finalEntityIds = entityIds;
return dictRelationList.stream() return dictRelationList.stream()
.filter(jsonObject -> { .filter(jsonObject -> {
boolean passesFilter = JacksonUtil.filter(jsonObject, pairs); boolean passesFilter = JacksonUtil.filter(jsonObject, pairs);
if (passesFilter && StringUtils.isNotBlank(entityIds)) {
String[] entityIdList = entityIds.split(",");
if (passesFilter && StringUtils.isNotBlank(finalEntityIds)) {
String[] entityIdList = finalEntityIds.split(",");
long entityId = jsonObject.get(CacheNameEnum.DictField.THING_DICT_ENTITY_ID.getField()).asLong(); long entityId = jsonObject.get(CacheNameEnum.DictField.THING_DICT_ENTITY_ID.getField()).asLong();
passesFilter = ArrayUtils.contains(entityIdList, String.valueOf(entityId)); passesFilter = ArrayUtils.contains(entityIdList, String.valueOf(entityId));
} }
@ -562,7 +567,7 @@ public class IotThingDictRelationServiceImpl extends BaseServiceImpl<IotThingDic
} }
private List<Pair<String, String>> buildParam(String groupName,String templateMark,String dataType,Long tenantCode){
private List<Pair<String, String>> buildParam(String groupName,String templateMark,String dataType){
List<Pair<String, String>> filterList = new ArrayList<>(); List<Pair<String, String>> filterList = new ArrayList<>();
if (StringUtils.isNotBlank(groupName)) { if (StringUtils.isNotBlank(groupName)) {
filterList.add(Pair.of(CacheNameEnum.DictField.THING_DICT_GROUP_NAME.getField(), groupName)); filterList.add(Pair.of(CacheNameEnum.DictField.THING_DICT_GROUP_NAME.getField(), groupName));
@ -575,9 +580,9 @@ public class IotThingDictRelationServiceImpl extends BaseServiceImpl<IotThingDic
filterList.add(Pair.of(CacheNameEnum.DictField.THING_DICT_DATA_TYPE.getField(), dataType)); filterList.add(Pair.of(CacheNameEnum.DictField.THING_DICT_DATA_TYPE.getField(), dataType));
} }
if (Objects.nonNull(tenantCode)) {
filterList.add(Pair.of(CacheNameEnum.DictField.THING_DICT_TENANT_CODE.getField(), tenantCode.toString()));
}
// if (Objects.nonNull(tenantCode)) {
// filterList.add(Pair.of(CacheNameEnum.DictField.THING_DICT_TENANT_CODE.getField(), tenantCode.toString()));
// }
return filterList; return filterList;
} }

3
modules/thing/src/main/java/com/thing/thing/entity/service/impl/IotThingEntityServiceImpl.java

@ -281,7 +281,8 @@ public class IotThingEntityServiceImpl extends BaseServiceImpl<IotThingEntityMap
String finalOrderField = CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, orderField); String finalOrderField = CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, orderField);
Comparator<ObjectNode> comparator = CompareUtils.getComparator(order, finalOrderField); Comparator<ObjectNode> comparator = CompareUtils.getComparator(order, finalOrderField);
return thingList.stream().filter(jsonObject -> JacksonUtil.filter(jsonObject, pairs)) return thingList.stream().filter(jsonObject -> JacksonUtil.filter(jsonObject, pairs))
.filter(jsonObject -> JacksonUtil.filterOr(jsonObject, name,CacheNameEnum.EntityField.THING_ENTITY_CODE.getField(),CacheNameEnum.EntityField.THING_ENTITY_NAME.getField()))
.filter(jsonObject -> JacksonUtil.filterOr(jsonObject, name,CacheNameEnum.EntityField.THING_ENTITY_CODE.getField()
,CacheNameEnum.EntityField.THING_ENTITY_NAME.getField()))
.sorted(comparator.thenComparing(obj -> obj.get(CacheNameEnum.EntityField.THING_ENTITY_ID.getField()).asLong())).toList(); .sorted(comparator.thenComparing(obj -> obj.get(CacheNameEnum.EntityField.THING_ENTITY_ID.getField()).asLong())).toList();
} }

Loading…
Cancel
Save