|
|
@@ -17,6 +17,7 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
|
@@ -58,33 +59,25 @@ public class MpRelationServiceImpl extends MyBaseServiceImpl<MpRelationMapper, M
|
|
|
}
|
|
|
// 通过unionid获取公众号openid
|
|
|
var mpRelationList = new ArrayList<MpRelation>();
|
|
|
- wxUserList.getOpenids().forEach(openid -> {
|
|
|
- try {
|
|
|
- WxMpUser mpUser = wxMpService.getUserService().userInfo(openid, lang);
|
|
|
- MpRelation mpRelation = new MpRelation();
|
|
|
- mpRelation.setId(IDGenerator.INS().nextId());
|
|
|
- mpRelation
|
|
|
- .setMpOpenid(mpUser.getOpenId())
|
|
|
- .setUnionid(mpUser.getUnionId())
|
|
|
- .setSubscribe(mpUser.getSubscribe())
|
|
|
- .setSubscribeScene(mpUser.getSubscribeScene());
|
|
|
- mpRelationList.add(mpRelation);
|
|
|
- } catch (WxErrorException e) {
|
|
|
- throw new RuntimeException(e);
|
|
|
- }
|
|
|
+ List<WxMpUser> mpUserList = wxMpService.getUserService().userInfoList(wxUserList.getOpenids());
|
|
|
+ mpUserList.forEach(mpUser -> {
|
|
|
+ MpRelation mpRelation = new MpRelation()
|
|
|
+ .setMpOpenid(mpUser.getOpenId())
|
|
|
+ .setUnionid(mpUser.getUnionId())
|
|
|
+ .setSubscribe(mpUser.getSubscribe())
|
|
|
+ .setSubscribeScene(mpUser.getSubscribeScene());
|
|
|
+ mpRelationList.add(mpRelation);
|
|
|
});
|
|
|
|
|
|
// 批量replace
|
|
|
replaceBatch(mpRelationList);
|
|
|
|
|
|
- var mpRelations = mpRelationList.stream().filter(mpRelation -> mpRelation.getUnionid() != null && !mpRelation.getUnionid().isEmpty()).toList();
|
|
|
+ var mpRelations = mpRelationList.stream().filter(mpRelation -> CommUtil.isNotEmptyAndNull(mpRelation.getUnionid())).toList();
|
|
|
var userList = userService.lambdaQuery().in(User::getUnionid, mpRelations.stream().map(MpRelation::getUnionid).toList()).list();
|
|
|
- userList.forEach(user -> {
|
|
|
- mpRelations.stream().filter(mpRelation -> mpRelation.getUnionid().equals(user.getUnionid())).findFirst().ifPresent(mpRelation -> {
|
|
|
- mpRelation.setOpenid(user.getOpenid());
|
|
|
- mpRelation.setUserId(user.getId());
|
|
|
- });
|
|
|
- });
|
|
|
+ userList.forEach(user -> mpRelations.stream().filter(mpRelation -> mpRelation.getUnionid().equals(user.getUnionid())).forEach(mpRelation -> {
|
|
|
+ mpRelation.setOpenid(user.getOpenid());
|
|
|
+ mpRelation.setUserId(user.getId());
|
|
|
+ }));
|
|
|
updateBatchByQueryWrapper(mpRelations, mpRelation ->
|
|
|
new QueryWrapper<MpRelation>().eq("unionid", mpRelation.getUnionid()));
|
|
|
}
|