|
|
|
@ -3,11 +3,14 @@ package com.thing.thing.dict.service.impl; |
|
|
|
import cn.hutool.core.collection.CollectionUtil; |
|
|
|
import cn.hutool.core.map.MapUtil; |
|
|
|
import cn.hutool.core.util.ObjectUtil; |
|
|
|
import com.google.common.collect.Lists; |
|
|
|
import com.google.common.collect.Maps; |
|
|
|
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; |
|
|
|
@ -384,4 +387,63 @@ public class IotThingDictServiceImpl extends BaseServiceImpl<IotThingDictMapper, |
|
|
|
.toList(); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void dragAndDrop(Long id, Long toId, Long sort) { |
|
|
|
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)); |
|
|
|
|
|
|
|
//自定义字典列表 |
|
|
|
List<IotThingDictEntity> defaultList = mapper.selectListByQuery(QueryWrapper.create() |
|
|
|
.eq(IotThingDictEntity::getIsDefault, 0)); |
|
|
|
List<IotThingDictEntity> iotThingDictEntities = Lists.newArrayList(); |
|
|
|
iotThingDictEntities.addAll(noDefaultList); |
|
|
|
iotThingDictEntities.addAll(defaultList); |
|
|
|
//若是大于当前目前序号,则更新当前序号之前的排序 |
|
|
|
AtomicLong aLong = new AtomicLong(0); |
|
|
|
if(toDictEntity.getSort()<=sort){ |
|
|
|
iotThingDictEntities.stream().filter(s -> s.getSort() < sort) |
|
|
|
.sorted(Comparator.comparing(IotThingDictEntity::getSort)) |
|
|
|
.forEach(s -> { |
|
|
|
s.setSort(aLong.incrementAndGet()); |
|
|
|
mapper.update(s); |
|
|
|
}); |
|
|
|
iotThingDictEntity.setSort(aLong.incrementAndGet()); |
|
|
|
mapper.update(iotThingDictEntity); |
|
|
|
iotThingDictEntities.stream() |
|
|
|
.sorted(Comparator.comparing(IotThingDictEntity::getSort)) |
|
|
|
.filter(s -> s.getSort() >= sort).forEach(s -> { |
|
|
|
s.setSort(aLong.incrementAndGet()); |
|
|
|
mapper.update(s); |
|
|
|
}); |
|
|
|
}else{ |
|
|
|
iotThingDictEntities.stream().filter(s -> s.getSort() >= sort) |
|
|
|
.sorted(Comparator.comparing(IotThingDictEntity::getSort)) |
|
|
|
.forEach(s -> { |
|
|
|
s.setSort(aLong.incrementAndGet()); |
|
|
|
mapper.update(s); |
|
|
|
}); |
|
|
|
iotThingDictEntity.setSort(aLong.incrementAndGet()); |
|
|
|
iotThingDictEntities.stream().filter(s -> s.getSort() > sort) |
|
|
|
.sorted(Comparator.comparing(IotThingDictEntity::getSort)) |
|
|
|
.forEach(s -> { |
|
|
|
s.setSort(aLong.incrementAndGet()); |
|
|
|
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); |
|
|
|
} |
|
|
|
|
|
|
|
} |