Commit 053f9e52 by shenjunjie

修复event信息3

parent f4b558b2
...@@ -36,6 +36,7 @@ import com.zhiwei.brandkbs2.service.ProjectService; ...@@ -36,6 +36,7 @@ import com.zhiwei.brandkbs2.service.ProjectService;
import com.zhiwei.brandkbs2.util.MongoUtil; import com.zhiwei.brandkbs2.util.MongoUtil;
import com.zhiwei.brandkbs2.util.RedisUtil; import com.zhiwei.brandkbs2.util.RedisUtil;
import com.zhiwei.brandkbs2.util.Tools; import com.zhiwei.brandkbs2.util.Tools;
import lombok.Data;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.ListUtils; import org.apache.commons.collections4.ListUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
...@@ -60,6 +61,7 @@ import java.util.*; ...@@ -60,6 +61,7 @@ import java.util.*;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
...@@ -686,21 +688,59 @@ public class EventServiceImpl implements EventService { ...@@ -686,21 +688,59 @@ public class EventServiceImpl implements EventService {
@Override @Override
public void updateAllEventInfo() { public void updateAllEventInfo() {
Query query = new Query(); try {
query.with(Sort.by(Sort.Order.asc("cTime"))); Query query = new Query();
List<Event> list = eventDao.findList(query); query.with(Sort.by(Sort.Order.asc("cTime")));
log.info("updateAllEventInfo-发现事件共:{}个", list.size()); MongoQueryUtil mongoQueryUtil = new MongoQueryUtil(eventDao.count(query));
AtomicInteger total = new AtomicInteger(); AtomicInteger total = new AtomicInteger();
AtomicInteger error = new AtomicInteger(); AtomicInteger error = new AtomicInteger();
list.forEach(event -> { while (mongoQueryUtil.hasNextPage()) {
try { List<Event> list = eventDao.findList(mongoQueryUtil.getNextPageQuery());
eventDataService.updateEventInfo(event); log.info("updateAllEventInfo-发现事件共:{}个,current:{},total:{}", list.size(), mongoQueryUtil.getStartPage() * mongoQueryUtil.getLimit(),
log.info("updateAllEventInfo-已更新事件:{}个,错误:{}个", total.incrementAndGet(), error.get()); mongoQueryUtil.getTotal());
} catch (Exception e) { list.forEach(event -> {
error.incrementAndGet(); try {
log.error("updateAllEventInfo-eventId:{}", event.getId(), e); eventDataService.updateEventInfo(event);
log.info("updateAllEventInfo-已更新事件:{}个,错误:{}个", total.incrementAndGet(), error.get());
} catch (Exception e) {
error.incrementAndGet();
log.error("updateAllEventInfo-eventId:{}", event.getId(), e);
}
});
} }
}); } catch (Exception e) {
log.error("updateAllEventInfo-", e);
}
}
@Data
public static class MongoQueryUtil {
private int limit = 1000;
private long startPage = 1;
private long total;
private AtomicLong removeSize = new AtomicLong();
public MongoQueryUtil(long total) {
this.total = total;
}
public boolean hasNextPage() {
long totalPage = (total + limit - 1) / limit;
return startPage <= totalPage;
}
public Query getNextPageQuery() {
Query query = new Query();
if (!hasNextPage()) {
throw new IllegalStateException("startPage>=totalPage");
}
query.skip((startPage - 1) * limit - removeSize.get());
query.limit(limit);
query.with(Sort.by(Sort.Order.desc("_id")));
startPage++;
return query;
}
} }
/** /**
......
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