From 169ef4a1a1beb8b06b305ebcc2cbae2f74a8bcef Mon Sep 17 00:00:00 2001 From: lishuai Date: Tue, 13 Aug 2024 17:05:11 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AD=97=E5=85=B8=E8=8C=83=E5=9B=B4=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=202024=E5=B9=B48=E6=9C=8813=E6=97=A517:05:06?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/IotThingDictServiceImpl.java | 53 ++++++++++++++----- 1 file changed, 41 insertions(+), 12 deletions(-) diff --git a/modules/thing/src/main/java/com/thing/thing/dict/service/impl/IotThingDictServiceImpl.java b/modules/thing/src/main/java/com/thing/thing/dict/service/impl/IotThingDictServiceImpl.java index 702c9b2..9331edd 100644 --- a/modules/thing/src/main/java/com/thing/thing/dict/service/impl/IotThingDictServiceImpl.java +++ b/modules/thing/src/main/java/com/thing/thing/dict/service/impl/IotThingDictServiceImpl.java @@ -392,16 +392,47 @@ public class IotThingDictServiceImpl extends BaseServiceImpl noDefaultList = mapper.selectListByQuery(QueryWrapper.create().eq(IotThingDictEntity::getTenantCode, UserContext.getRealTenantCode()) - .eq(IotThingDictEntity::getIsDefault, 1).ne(IotThingDictEntity::getId, id)); - //自定义字典列表 - List defaultList = mapper.selectListByQuery(QueryWrapper.create() - .eq(IotThingDictEntity::getIsDefault, 0).ne(IotThingDictEntity::getId, id)); - List 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 iotThingDictEntities = mapper.selectListByQuery(queryWrapper); + //若是大于当前目前序号,则更新当前序号之前的排序 List resList = Lists.newArrayList(); if(toDictEntity.getSort()<=sort){ List list = iotThingDictEntities.stream().filter(s -> s.getSort() < sort).toList(); @@ -419,9 +450,7 @@ public class IotThingDictServiceImpl extends BaseServiceImpl 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);