|
|
@@ -54,7 +54,7 @@ public class MpRelationServiceImpl extends MyBaseServiceImpl<MpRelationMapper, M
|
|
|
WxMpUserList wxUserList = wxMpService.getUserService().userList(nextOpenid);
|
|
|
var openids = wxUserList.getOpenids();
|
|
|
if (CommUtil.isEmptyOrNull(openids)) {
|
|
|
- return;
|
|
|
+ break;
|
|
|
}
|
|
|
|
|
|
// 通过unionid获取公众号openid
|
|
|
@@ -83,10 +83,28 @@ public class MpRelationServiceImpl extends MyBaseServiceImpl<MpRelationMapper, M
|
|
|
|
|
|
// 检查是否有下一页
|
|
|
if (CommUtil.isEmptyOrNull(wxUserList.getNextOpenid())) {
|
|
|
- return;
|
|
|
+ break;
|
|
|
}
|
|
|
nextOpenid = wxUserList.getNextOpenid();
|
|
|
}
|
|
|
+ // 同步关注状态到 t_user(兜底事件丢失场景)
|
|
|
+ var allRelations = lambdaQuery().isNotNull(MpRelation::getUserId).list();
|
|
|
+ if (CommUtil.isNotEmptyOrNull(allRelations)) {
|
|
|
+ var subscribedIds = allRelations.stream()
|
|
|
+ .filter(MpRelation::getSubscribe)
|
|
|
+ .map(MpRelation::getUserId).toList();
|
|
|
+ if (!subscribedIds.isEmpty()) {
|
|
|
+ userService.lambdaUpdate().set(User::getFollowOfficialAccount, 1)
|
|
|
+ .in(User::getId, subscribedIds).update();
|
|
|
+ }
|
|
|
+ var unsubscribedIds = allRelations.stream()
|
|
|
+ .filter(r -> !r.getSubscribe())
|
|
|
+ .map(MpRelation::getUserId).toList();
|
|
|
+ if (!unsubscribedIds.isEmpty()) {
|
|
|
+ userService.lambdaUpdate().set(User::getFollowOfficialAccount, 2)
|
|
|
+ .in(User::getId, unsubscribedIds).update();
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -116,9 +134,35 @@ public class MpRelationServiceImpl extends MyBaseServiceImpl<MpRelationMapper, M
|
|
|
mpRelation.setUserId(user.getId());
|
|
|
}
|
|
|
saveOrUpdate(mpRelation);
|
|
|
+ // 同步关注状态到 t_user
|
|
|
+ if (user != null) {
|
|
|
+ userService.lambdaUpdate()
|
|
|
+ .set(User::getFollowOfficialAccount, 1)
|
|
|
+ .eq(User::getId, user.getId())
|
|
|
+ .update();
|
|
|
+ }
|
|
|
} catch (WxErrorException e) {
|
|
|
throw new RuntimeException(e);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 取消关注公众号
|
|
|
+ *
|
|
|
+ * @param mpOpenid 公众号openid
|
|
|
+ */
|
|
|
+ public void unbindMpUser(String mpOpenid) {
|
|
|
+ var mpRelation = lambdaQuery().eq(MpRelation::getMpOpenid, mpOpenid).one();
|
|
|
+ if (mpRelation != null) {
|
|
|
+ lambdaUpdate().set(MpRelation::getSubscribe, false)
|
|
|
+ .eq(MpRelation::getMpOpenid, mpOpenid).update();
|
|
|
+ if (mpRelation.getUserId() != null) {
|
|
|
+ userService.lambdaUpdate()
|
|
|
+ .set(User::getFollowOfficialAccount, 2)
|
|
|
+ .eq(User::getId, mpRelation.getUserId())
|
|
|
+ .update();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|