Commit 398f674b authored by 赵啸非's avatar 赵啸非

分组更新设备

parent 5c68a2b5
package com.mortals.xhx.thread;
import cn.hutool.core.collection.ListUtil;
import com.mortals.framework.service.ICacheService;
import com.mortals.framework.util.AbstractThread;
import com.mortals.xhx.common.key.RedisKey;
......@@ -56,8 +57,8 @@ public class DeviceUpdateComsumerThread extends AbstractThread {
if (!ObjectUtils.isEmpty(waitUpdateDeviceList)) {
log.info("updateDeviceList size:{}", waitUpdateDeviceList.size());
Map<Long, List<DeviceEntity>> collect = waitUpdateDeviceList.parallelStream().collect(Collectors.groupingBy(x -> x.getId()));
collect.entrySet().stream().forEach(item->{
List<DeviceEntity> sortUpdateList = item.getValue().stream().sorted(new Comparator<DeviceEntity>() {
collect.entrySet().parallelStream().forEach(item->{
List<DeviceEntity> sortUpdateList = item.getValue().parallelStream().sorted(new Comparator<DeviceEntity>() {
@Override
public int compare(DeviceEntity o1, DeviceEntity o2) {
if (o1.getUpdateTime() == null) return 0;
......@@ -73,7 +74,11 @@ public class DeviceUpdateComsumerThread extends AbstractThread {
}
}
}).collect(Collectors.toList());
deviceService.update(sortUpdateList);
List<List<DeviceEntity>> partition = ListUtil.partition(sortUpdateList, 50);
for (List<DeviceEntity> deviceEntityList : partition) {
deviceService.update(deviceEntityList);
}
});
/*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment