Browse Source

指标导入

2024年12月19日18:34:03
qingyuan_dev_new
lishuai 1 year ago
parent
commit
532a1a7da2
  1. 22
      modules/thing/src/main/java/com/thing/thing/dict/service/impl/IotThingDictServiceImpl.java
  2. 44
      modules/thing/src/main/java/com/thing/thing/dictRelation/service/impl/IotThingDictRelationServiceImpl.java

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

@ -198,7 +198,7 @@ public class IotThingDictServiceImpl extends BaseServiceImpl<IotThingDictMapper,
public Integer findMaxSort(Integer isDefault) {
QueryWrapper queryWrapper = QueryWrapper
.create()
.select(max(IOT_THING_DICT_ENTITY.SORT)).eq(String.valueOf(IOT_THING_DICT_ENTITY.IS_DEFAULT), 1);
.select(max(IOT_THING_DICT_ENTITY.SORT)).eq(IotThingDictEntity::getIsDefault,1);
Integer sort = mapper.selectOneByQueryAs(queryWrapper, Integer.class);
return Objects.isNull(sort) ? 0 : sort;
}
@ -269,7 +269,7 @@ public class IotThingDictServiceImpl extends BaseServiceImpl<IotThingDictMapper,
/*.setTenantCode(SecurityUser.getUser().getTenantCode())
.setCompanyId(SecurityUser.getUser().getCompanyId())
.setDeptId(SecurityUser.getUser().getDeptId())*/
).toList();
).toList();
mapper.insertBatch(list);
});
}
@ -293,8 +293,8 @@ public class IotThingDictServiceImpl extends BaseServiceImpl<IotThingDictMapper,
//过滤完已经存在的字典
.filter(d-> iotThingDictDTOList.stream().noneMatch(iotThingDictDTO ->
StringUtils.equals(groupName,iotThingDictDTO.getGroupName())
&& StringUtils.equals(d.getCode(),iotThingDictDTO.getCode())
&& StringUtils.equals(d.getDataType(),iotThingDictDTO.getDataType())
&& StringUtils.equals(d.getCode(),iotThingDictDTO.getCode())
&& StringUtils.equals(d.getDataType(),iotThingDictDTO.getDataType())
))
//构建字典对象
.peek(e -> {
@ -421,14 +421,14 @@ public class IotThingDictServiceImpl extends BaseServiceImpl<IotThingDictMapper,
.and(IOT_THING_DICT_ENTITY.SORT.ge(iotThingDictEntity.getSort()))
.and(IOT_THING_DICT_ENTITY.ID.ne(id))
)
.or(IOT_THING_DICT_ENTITY.IS_DEFAULT.eq(1)
.and(IOT_THING_DICT_ENTITY.TENANT_CODE.eq(UserContext.getRealTenantCode()))
.and(
IOT_THING_DICT_ENTITY.SORT.le(toDictEntity.getSort())
.and(IOT_THING_DICT_ENTITY.SORT.ge(iotThingDictEntity.getSort()))
.or(IOT_THING_DICT_ENTITY.IS_DEFAULT.eq(1)
.and(IOT_THING_DICT_ENTITY.TENANT_CODE.eq(UserContext.getRealTenantCode()))
.and(
IOT_THING_DICT_ENTITY.SORT.le(toDictEntity.getSort())
.and(IOT_THING_DICT_ENTITY.SORT.ge(iotThingDictEntity.getSort()))
)
.and(IOT_THING_DICT_ENTITY.ID.ne(id))
)
.and(IOT_THING_DICT_ENTITY.ID.ne(id))
)
);
aLong.set(iotThingDictEntity.getSort()-1);
}

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

@ -46,6 +46,7 @@ import org.springframework.web.multipart.MultipartFile;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
import java.util.function.Function;
import java.util.stream.Collectors;
@ -153,17 +154,17 @@ public class IotThingDictRelationServiceImpl extends BaseServiceImpl<IotThingDic
@Override
public List<ObjectNode> findList(String orderField,String order,
String entityName,String groupName, String entityIds,String name,
String templateMark,String dataType,Long tenantCode)
String entityName,String groupName, String entityIds,String name,
String templateMark,String dataType,Long tenantCode)
{
List<ObjectNode> dictRelationList = cache.getTopicMap(CacheNameEnum.THING_DICT_RELATION);
if(CollectionUtils.isEmpty(dictRelationList)){
List<IotThingDictRelationDTO> dictRelationDTOList = mapper.selectListByQueryAs(getWrapper(orderField,order,null,null,null,null,
null,null,null),
IotThingDictRelationDTO.class);
if(CollectionUtils.isEmpty(dictRelationDTOList)) {
return new ArrayList<>();
}
List<IotThingDictRelationDTO> dictRelationDTOList = mapper.selectListByQueryAs(getWrapper(orderField,order,null,null,null,null,
null,null,null),
IotThingDictRelationDTO.class);
if(CollectionUtils.isEmpty(dictRelationDTOList)) {
return new ArrayList<>();
}
dictRelationList = JsonConverter.convertToJsonObjectListObjectNode(dictRelationDTOList);
//更新缓存
CacheInit.dictRelationMap(dictRelationList,cache);
@ -536,10 +537,23 @@ public class IotThingDictRelationServiceImpl extends BaseServiceImpl<IotThingDic
).toList();
dictService.saveBatch(dictEntities);
}
List<IotThingDictRelationEntity> iotThingDictRelationEntities = ConvertUtils.sourceToTarget(list, IotThingDictRelationEntity.class);
mapper.insertBatch(iotThingDictRelationEntities);
iotThingDictRelationEntities.forEach(entity -> cache.updateAccurateKeyEntity(CacheNameEnum.THING_DICT_RELATION,
List<IotThingDictRelationEntity> iotThingDictRelationEntities = mapper.selectListByQuery(QueryWrapper.create().eq(IotThingDictRelationEntity::getEntityId, optional.get().getId())
.in(IotThingDictRelationEntity::getCode, codes));
Long maxSort = 0L;
if(CollectionUtils.isNotEmpty(iotThingDictRelationEntities)){
list = list.stream().filter(e -> iotThingDictRelationEntities.stream().noneMatch(d -> StringUtils.equals(d.getCode(), e.getCode()))).toList();
maxSort = iotThingDictRelationEntities.stream().mapToLong(IotThingDictRelationEntity::getSort).max().getAsLong();
}
AtomicLong sort = new AtomicLong(maxSort);
List<IotThingDictRelationEntity> insertList = ConvertUtils.sourceToTarget(list, IotThingDictRelationEntity.class);
insertList.forEach(e -> {
e.setSort(sort.incrementAndGet());
e.setEntityId(optional.get().getId());
e.setTemplateMark(optional.get().getTemplateMark());
});
mapper.insertBatch(insertList);
insertList.forEach(entity -> cache.updateAccurateKeyEntity(CacheNameEnum.THING_DICT_RELATION,
entity.getTenantCode()+CacheInit.KEY+entity.getEntityCode()+CacheInit.KEY+entity.getCode()+CacheInit.KEY+entity.getId(),ConvertUtils.sourceToTarget(entity, IotThingDictRelationDTO.class)));
}
}
@ -573,7 +587,7 @@ public class IotThingDictRelationServiceImpl extends BaseServiceImpl<IotThingDic
.setId(null);
return iotThingDictRelationEntity;
})).toList());
//同步
//同步
if(StringUtils.equals(SyncUpdateEnum.SYNC.getValue(),dto.getSyncOrUpdate())){
QueryWrapper in = QueryWrapper.create().in(IotThingDictRelationEntity::getEntityId, entityIds);
List<IotThingDictRelationEntity> dictRelationEntities = mapper.selectListByQuery(in);
@ -588,9 +602,9 @@ public class IotThingDictRelationServiceImpl extends BaseServiceImpl<IotThingDic
if(CollectionUtils.isNotEmpty(relationDTOList)){
insertList.
removeIf(s-> relationDTOList.stream().anyMatch(r->
StringUtils.equals(r.getCode(),s.getCode())
&& StringUtils.equals(r.getDataType(),s.getDataType())
&& Objects.equals(r.getEntityId(),s.getEntityId())
StringUtils.equals(r.getCode(),s.getCode())
&& StringUtils.equals(r.getDataType(),s.getDataType())
&& Objects.equals(r.getEntityId(),s.getEntityId())
));
}
if(CollectionUtils.isNotEmpty(insertList)){

Loading…
Cancel
Save