From 3356e0d82523f362fe241b8960def4fb25d2f3b7 Mon Sep 17 00:00:00 2001 From: lishuai Date: Mon, 12 Aug 2024 18:18:17 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E7=BB=84=E6=A8=A1=E5=9E=8B=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E4=BF=A1=E6=81=AF3=202024=E5=B9=B48=E6=9C=8812?= =?UTF-8?q?=E6=97=A510:40:56?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/IotThingDictServiceImpl.java | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 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 0e0355e..bd5992c 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 @@ -394,16 +394,17 @@ public class IotThingDictServiceImpl extends BaseServiceImpl noDefaultList = mapper.selectListByQuery(QueryWrapper.create().eq(IotThingDictEntity::getTenantCode, UserContext.getRealTenantCode()) - .eq(IotThingDictEntity::getIsDefault, 1)); + .eq(IotThingDictEntity::getIsDefault, 1).ne(IotThingDictEntity::getId, id)); //自定义字典列表 List defaultList = mapper.selectListByQuery(QueryWrapper.create() - .eq(IotThingDictEntity::getIsDefault, 0)); + .eq(IotThingDictEntity::getIsDefault, 0).ne(IotThingDictEntity::getId, id)); List iotThingDictEntities = Lists.newArrayList(); iotThingDictEntities.addAll(noDefaultList); iotThingDictEntities.addAll(defaultList); //若是大于当前目前序号,则更新当前序号之前的排序 AtomicLong aLong = new AtomicLong(0); + List resList = Lists.newArrayList(); if(toDictEntity.getSort()<=sort){ iotThingDictEntities.stream().filter(s -> s.getSort() < sort) .sorted(Comparator.comparing(IotThingDictEntity::getSort)) @@ -420,20 +421,26 @@ public class IotThingDictServiceImpl extends BaseServiceImpl s.getSort() >= sort) - .sorted(Comparator.comparing(IotThingDictEntity::getSort)) + List list = iotThingDictEntities.stream().filter(s -> s.getSort() <= sort).toList(); + list.stream().sorted(Comparator.comparing(IotThingDictEntity::getSort)) .forEach(s -> { s.setSort(aLong.incrementAndGet()); - mapper.update(s); + // mapper.update(s); }); + resList.addAll(list); iotThingDictEntity.setSort(aLong.incrementAndGet()); - iotThingDictEntities.stream().filter(s -> s.getSort() > sort) - .sorted(Comparator.comparing(IotThingDictEntity::getSort)) + resList.add(iotThingDictEntity); + + List list1 = iotThingDictEntities.stream().filter(s -> s.getSort() > sort).toList(); + list1.stream().sorted(Comparator.comparing(IotThingDictEntity::getSort)) .forEach(s -> { s.setSort(aLong.incrementAndGet()); - mapper.update(s); +// mapper.update(s); }); + resList.addAll(list1); + } + resList.forEach(s -> mapper.update(s)); // Db.executeBatch(iotThingDictEntities.size(), 1000, IotThingDictMapper.class, (mapper, index) -> { // IotThingDictEntity account = iotThingDictEntities.get(index); From 1e1f859aa76f912eb19143144da2459be2a24dc9 Mon Sep 17 00:00:00 2001 From: lishuai Date: Mon, 12 Aug 2024 18:21:37 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E7=BB=84=E6=A8=A1=E5=9E=8B=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E4=BF=A1=E6=81=AF4=202024=E5=B9=B48=E6=9C=8812?= =?UTF-8?q?=E6=97=A510:40:56?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/IotThingDictServiceImpl.java | 20 +------------------ 1 file changed, 1 insertion(+), 19 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 bd5992c..f9b6565 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 @@ -9,8 +9,6 @@ import com.mybatisflex.core.constant.SqlConsts; import com.mybatisflex.core.paginate.Page; import com.mybatisflex.core.query.QueryCondition; import com.mybatisflex.core.query.QueryWrapper; -import com.mybatisflex.core.row.Db; -import com.mybatisflex.core.update.UpdateChain; import com.thing.common.core.enumeration.DictTypeEnum; import com.thing.common.core.enumeration.IsDefaultEnum; import com.thing.common.core.exception.SysException; @@ -391,11 +389,9 @@ 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)); @@ -425,32 +421,18 @@ public class IotThingDictServiceImpl extends BaseServiceImpl { s.setSort(aLong.incrementAndGet()); - // mapper.update(s); }); resList.addAll(list); iotThingDictEntity.setSort(aLong.incrementAndGet()); resList.add(iotThingDictEntity); - List list1 = iotThingDictEntities.stream().filter(s -> s.getSort() > sort).toList(); list1.stream().sorted(Comparator.comparing(IotThingDictEntity::getSort)) .forEach(s -> { s.setSort(aLong.incrementAndGet()); -// mapper.update(s); }); resList.addAll(list1); - } - resList.forEach(s -> mapper.update(s)); - -// Db.executeBatch(iotThingDictEntities.size(), 1000, IotThingDictMapper.class, (mapper, index) -> { -// IotThingDictEntity account = iotThingDictEntities.get(index); -// UpdateChain.of(account).update(); -// }); - - // iotThingDictEntities.forEach(s -> mapper.update(s)); -// -// int i = Db.updateEntitiesBatch(iotThingDictEntities, 1000); -// System.out.println(i); + this.updateBatch(resList); } } \ No newline at end of file