Commit 9ecb7eda by 吕明尚

优化自动更新用户unionid

parent 2feb3817
......@@ -30,8 +30,10 @@ import share.system.service.*;
import java.math.BigDecimal;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
@Component("redisTask")
public class RedisTask {
......@@ -511,12 +513,29 @@ public class RedisTask {
sConsumerTokenList = sConsumerTokenList.subList(0, 100);
}
List<String> wechatUSERList = wechatNewService.getWechatUSERList(list, "");
Map<String, String> stringStringMap = wechatNewService.WechatUsetListInfo(wechatUSERList);
List<SConsumerToken> updateList = new ArrayList<>();
Map<String, String> openIdMap = new ConcurrentHashMap<>();
// 使用IntStream优化分批逻辑,并行处理各批次数据
List<String> finalWechatUserList = wechatUSERList;
IntStream.range(0, (wechatUSERList.size() + 99) / 100)
.parallel()
.forEach(i -> {
List<String> subList = finalWechatUserList.subList(i * 100, Math.min((i + 1) * 100, finalWechatUserList.size()));
try {
openIdMap.putAll(wechatNewService.WechatUsetListInfo(subList));
} catch (Exception e) {
logger.error("处理微信用户信息失败", e);
}
});
sConsumerTokenList.forEach(item -> {
item.setOpenId(stringStringMap.get(item.getUnionId()));
updateList.add(item);
String openId = openIdMap.get(item.getUnionId());
if (openId != null) {
item.setOpenId(openId);
try {
sConsumerTokenService.updateById(item);
} catch (Exception e) {
logger.error("更新消费者令牌失败", e);
}
}
});
if (!CollectionUtils.isEmpty(updateList)) sConsumerTokenService.updateBatchById(updateList);
}
}
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