Browse Source

字典范围更新

2024年8月13日17:05:06
thing_master
lishuai 1 year ago
parent
commit
169ef4a1a1
  1. 53
      modules/thing/src/main/java/com/thing/thing/dict/service/impl/IotThingDictServiceImpl.java

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

@ -392,16 +392,47 @@ public class IotThingDictServiceImpl extends BaseServiceImpl<IotThingDictMapper,
IotThingDictEntity iotThingDictEntity = mapper.selectOneById(id);
IotThingDictEntity toDictEntity = mapper.selectOneById(toId);
//自定义字典列表
List<IotThingDictEntity> noDefaultList = mapper.selectListByQuery(QueryWrapper.create().eq(IotThingDictEntity::getTenantCode, UserContext.getRealTenantCode())
.eq(IotThingDictEntity::getIsDefault, 1).ne(IotThingDictEntity::getId, id));
//自定义字典列表
List<IotThingDictEntity> defaultList = mapper.selectListByQuery(QueryWrapper.create()
.eq(IotThingDictEntity::getIsDefault, 0).ne(IotThingDictEntity::getId, id));
List<IotThingDictEntity> iotThingDictEntities = Lists.newArrayList();
iotThingDictEntities.addAll(noDefaultList);
iotThingDictEntities.addAll(defaultList);
//若是大于当前目前序号则更新当前序号之前的排序
AtomicLong aLong = new AtomicLong(0);
QueryWrapper queryWrapper = QueryWrapper.create();
if(iotThingDictEntity.getSort()> toDictEntity.getSort() ){
queryWrapper.where(
IOT_THING_DICT_ENTITY.IS_DEFAULT.eq(0)
.and(
IOT_THING_DICT_ENTITY.SORT.le(iotThingDictEntity.getSort())
.and(IOT_THING_DICT_ENTITY.SORT.ge(toDictEntity.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(iotThingDictEntity.getSort())
.and(IOT_THING_DICT_ENTITY.SORT.ge(toDictEntity.getSort()))
)
.and(IOT_THING_DICT_ENTITY.ID.ne(id))
)
);
aLong.set(toDictEntity.getSort()-1);
}else{
queryWrapper.where(
IOT_THING_DICT_ENTITY.IS_DEFAULT.eq(0)
.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))
)
.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))
)
);
aLong.set(iotThingDictEntity.getSort()-1);
}
List<IotThingDictEntity> iotThingDictEntities = mapper.selectListByQuery(queryWrapper);
//若是大于当前目前序号则更新当前序号之前的排序
List<IotThingDictEntity> resList = Lists.newArrayList();
if(toDictEntity.getSort()<=sort){
List<IotThingDictEntity> list = iotThingDictEntities.stream().filter(s -> s.getSort() < sort).toList();
@ -419,9 +450,7 @@ public class IotThingDictServiceImpl extends BaseServiceImpl<IotThingDictMapper,
}else{
List<IotThingDictEntity> list = iotThingDictEntities.stream().filter(s -> s.getSort() <= sort).toList();
list.stream().sorted(Comparator.comparing(IotThingDictEntity::getSort))
.forEach(s -> {
s.setSort(aLong.incrementAndGet());
});
.forEach(s -> s.setSort(aLong.incrementAndGet()));
resList.addAll(list);
iotThingDictEntity.setSort(aLong.incrementAndGet());
resList.add(iotThingDictEntity);

Loading…
Cancel
Save