Commit 79a3ee3c by 吕明尚

修改获取用户UUID定时任务

parent d5d8d741
......@@ -5,6 +5,8 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
......@@ -27,6 +29,8 @@ import share.system.service.WechatNewService;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.IntStream;
/**
......@@ -38,6 +42,8 @@ import java.util.Map;
@Api(tags = "微信 -- 开放平台")
public class WeChatController {
private static final Logger logger = LoggerFactory.getLogger(WeChatController.class);
@Autowired
private SConsumerCenterService sConsumerCenterService;
......@@ -123,16 +129,74 @@ public class WeChatController {
@GetMapping("/test")
public void getWechatUSERList() {
// List<String> list = new ArrayList<>();
// List<String> wechatUSERList = wechatNewService.getWechatUSERList(list, "");
// //当wechatUSERList大于100,以100为一批分割,分批获取WechatUsetListInfo的值
// Map<String, String> stringStringMap = new HashMap<>();
// if (wechatUSERList.size() > 100) {
// int i = 0;
// while (i < wechatUSERList.size()) {
// List<String> subList = wechatUSERList.subList(i, i + 100);
// stringStringMap.putAll(wechatNewService.WechatUsetListInfo(subList));
// System.out.println(stringStringMap);
// i = i + 100;
// }
// }
// System.out.println(stringStringMap);
// List<SConsumerToken> sConsumerTokenList = sConsumerTokenService.list(new LambdaQueryWrapper<SConsumerToken>().isNotNull(SConsumerToken::getUnionId).isNull(SConsumerToken::getOpenId));
// sConsumerTokenList.forEach(item -> {
// item.setOpenId(stringStringMap.get(item.getUnionId()));
// sConsumerTokenService.updateById(item);
// });
// System.out.println(sConsumerTokenList);
List<String> list = new ArrayList<>();
List<String> wechatUSERList = wechatNewService.getWechatUSERList(list, "");
Map<String, String> stringStringMap = wechatNewService.WechatUsetListInfo(wechatUSERList);
System.out.println(stringStringMap);
List<SConsumerToken> sConsumerTokenList = sConsumerTokenService.list(new LambdaQueryWrapper<SConsumerToken>().isNotNull(SConsumerToken::getUnionId).isNull(SConsumerToken::getOpenId));
List<String> wechatUserList = new ArrayList<>();
try {
wechatUserList = wechatNewService.getWechatUSERList(list, "");
} catch (Exception e) {
logger.error("获取微信用户列表失败", e);
return;
}
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);
}
});
logger.info("处理后的openIdMap: {}", openIdMap);
List<SConsumerToken> sConsumerTokenList;
try {
sConsumerTokenList = sConsumerTokenService.list(new LambdaQueryWrapper<SConsumerToken>()
.isNotNull(SConsumerToken::getUnionId)
.isNull(SConsumerToken::getOpenId));
} catch (Exception e) {
logger.error("获取消费者令牌列表失败", e);
return; // 或者根据实际情况进行其他处理
}
sConsumerTokenList.forEach(item -> {
item.setOpenId(stringStringMap.get(item.getUnionId()));
sConsumerTokenService.updateById(item);
String openId = openIdMap.get(item.getUnionId());
if (openId != null) {
item.setOpenId(openId);
try {
sConsumerTokenService.updateById(item);
} catch (Exception e) {
logger.error("更新消费者令牌失败", e);
}
}
});
System.out.println(sConsumerTokenList);
logger.info("更新完成的消费者令牌列表: {}", sConsumerTokenList);
}
@GetMapping("/test1")
......
......@@ -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 {
......@@ -532,10 +534,22 @@ public class RedisTask {
sConsumerTokenList = sConsumerTokenList.subList(0, 100);
}
List<String> wechatUSERList = wechatNewService.getWechatUSERList(list, "");
Map<String, String> stringStringMap = wechatNewService.WechatUsetListInfo(wechatUSERList);
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);
}
});
List<SConsumerToken> updateList = new ArrayList<>();
sConsumerTokenList.forEach(item -> {
item.setOpenId(stringStringMap.get(item.getUnionId()));
item.setOpenId(openIdMap.get(item.getUnionId()));
updateList.add(item);
});
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