|
@@ -101,60 +101,34 @@ public class CorpEventActionServiceImpl implements CorpEventActionService {
|
|
|
if (corpUserInfo == null) {
|
|
if (corpUserInfo == null) {
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
- //查询客户是否存在
|
|
|
|
|
- CorpUser corpUser = Optional.ofNullable(
|
|
|
|
|
- corpUserMapper.selectOne(Wrappers.lambdaQuery(CorpUser.class)
|
|
|
|
|
- .eq(CorpUser::getUnionid, corpUserInfo.getUnionId())))
|
|
|
|
|
- .orElseGet(() -> new CorpUser()
|
|
|
|
|
- .setUnionid(corpUserInfo.getUnionId()));
|
|
|
|
|
-
|
|
|
|
|
- corpUser.setName(corpUserInfo.getName());
|
|
|
|
|
- corpUser.setGender(corpUserInfo.getGender());
|
|
|
|
|
- corpUser.setAvatar(corpUserInfo.getAvatar());
|
|
|
|
|
- corpUser.setType(corpUserInfo.getType());
|
|
|
|
|
- //扫码来源
|
|
|
|
|
- corpUser.setState(state);
|
|
|
|
|
-
|
|
|
|
|
- //新增修改客户信息
|
|
|
|
|
- if (corpUser.getId() == null) {
|
|
|
|
|
- //查询是否已微信授权,关联user表id
|
|
|
|
|
- User user = userMapper.selectOne(Wrappers.lambdaQuery(User.class).eq(User::getUnionid, corpUser.getUnionid()));
|
|
|
|
|
- if (user != null) {
|
|
|
|
|
- corpUser.setUserId(user.getId());
|
|
|
|
|
- //加入企业微信后发放优惠券
|
|
|
|
|
- groupRelationFrontService.isJoinCorpWx(user.getId(), true, false);
|
|
|
|
|
- //发放抽奖机会
|
|
|
|
|
- sendSpecificChanceNum(user.getId());
|
|
|
|
|
- //添加固定客服发放优惠券
|
|
|
|
|
- isJoinFixedCustomer(user.getId(), userId);
|
|
|
|
|
|
|
+ THREAD_POOL.execute(()->{
|
|
|
|
|
+ //保存企微用户
|
|
|
|
|
+ CorpUser corpUser = saveOrUpdateCorpUser(message, corpUserInfo);
|
|
|
|
|
+
|
|
|
|
|
+ CorpUserAuth corpUserAuth = corpUserAuthMapper.selectOne(Wrappers.lambdaQuery(CorpUserAuth.class).eq(CorpUserAuth::getExternalUserid, corpUserInfo.getExternalUserId()).eq(CorpUserAuth::getWxCorpId, wxCorpApp.getId()));
|
|
|
|
|
+ if (corpUserAuth == null) {
|
|
|
|
|
+ corpUserAuth = new CorpUserAuth();
|
|
|
|
|
+ corpUserAuth.setWxCorpId(wxCorpApp.getId());
|
|
|
|
|
+ corpUserAuth.setCorpUserId(corpUser.getId());
|
|
|
|
|
+ corpUserAuth.setExternalUserid(corpUserInfo.getExternalUserId());
|
|
|
|
|
+ corpUserAuthMapper.insert(corpUserAuth);
|
|
|
}
|
|
}
|
|
|
- corpUserMapper.insert(corpUser);
|
|
|
|
|
- } else {
|
|
|
|
|
- corpUserMapper.updateById(corpUser);
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
- CorpUserAuth corpUserAuth = corpUserAuthMapper.selectOne(Wrappers.lambdaQuery(CorpUserAuth.class).eq(CorpUserAuth::getExternalUserid, corpUserInfo.getExternalUserId()).eq(CorpUserAuth::getWxCorpId, wxCorpApp.getId()));
|
|
|
|
|
- if (corpUserAuth == null) {
|
|
|
|
|
- corpUserAuth = new CorpUserAuth();
|
|
|
|
|
- corpUserAuth.setWxCorpId(wxCorpApp.getId());
|
|
|
|
|
- corpUserAuth.setCorpUserId(corpUser.getId());
|
|
|
|
|
- corpUserAuth.setExternalUserid(corpUserInfo.getExternalUserId());
|
|
|
|
|
- corpUserAuthMapper.insert(corpUserAuth);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ //2.客户添加成员信息
|
|
|
|
|
+ List<FollowedUser> followedUsers = externalContact.getFollowedUsers();
|
|
|
|
|
|
|
|
- //2.客户添加成员信息
|
|
|
|
|
- List<FollowedUser> followedUsers = externalContact.getFollowedUsers();
|
|
|
|
|
|
|
+ Set<String> relationFollowUserIds = relationMapper.selectList(Wrappers.lambdaQuery(CorpUserFollowRelation.class)
|
|
|
|
|
+ .select(CorpUserFollowRelation::getFollowId)
|
|
|
|
|
+ .eq(CorpUserFollowRelation::getWxCorpId, wxCorpApp.getCorpId())
|
|
|
|
|
+ .eq(CorpUserFollowRelation::getCorpUserId, corpUserInfo.getExternalUserId())).stream().map(CorpUserFollowRelation::getFollowId).collect(Collectors.toSet());
|
|
|
|
|
|
|
|
- Set<String> relationFollowUserIds = relationMapper.selectList(Wrappers.lambdaQuery(CorpUserFollowRelation.class)
|
|
|
|
|
- .select(CorpUserFollowRelation::getFollowId)
|
|
|
|
|
- .eq(CorpUserFollowRelation::getWxCorpId, wxCorpApp.getCorpId())
|
|
|
|
|
- .eq(CorpUserFollowRelation::getCorpUserId, corpUserInfo.getExternalUserId())).stream().map(CorpUserFollowRelation::getFollowId).collect(Collectors.toSet());
|
|
|
|
|
|
|
+ followedUsers.stream()
|
|
|
|
|
+ .filter((followedUser) -> !relationFollowUserIds.contains(followedUser.getUserId()))
|
|
|
|
|
+ .forEach(followedUser -> updateUserFollowRelation(followedUser, corpUserInfo.getExternalUserId(), wxCorpApp.getId()));
|
|
|
|
|
+ });
|
|
|
|
|
|
|
|
- followedUsers.stream()
|
|
|
|
|
- .filter((followedUser) -> !relationFollowUserIds.contains(followedUser.getUserId()))
|
|
|
|
|
- .forEach(followedUser -> updateUserFollowRelation(followedUser, corpUserInfo.getExternalUserId(), wxCorpApp.getId()));
|
|
|
|
|
//发送自定义欢迎语
|
|
//发送自定义欢迎语
|
|
|
- sendDesignWelcomeMsg(corpId, welcomeCode, userId, corpUserInfo.getCorpName());
|
|
|
|
|
|
|
+ //sendDesignWelcomeMsg(corpId, welcomeCode, userId, corpUserInfo.getCorpName());
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -225,6 +199,11 @@ public class CorpEventActionServiceImpl implements CorpEventActionService {
|
|
|
FollowedUser followedUser = followedUserMap.get(userId).get(0);
|
|
FollowedUser followedUser = followedUserMap.get(userId).get(0);
|
|
|
//修改客户关系
|
|
//修改客户关系
|
|
|
updateUserFollowRelation(followedUser, externalUserId, wxCorpApp.getId());
|
|
updateUserFollowRelation(followedUser, externalUserId, wxCorpApp.getId());
|
|
|
|
|
+
|
|
|
|
|
+ //保存企微用户
|
|
|
|
|
+ if (externalContact.getExternalContact() != null) {
|
|
|
|
|
+ saveOrUpdateCorpUser(message, externalContact.getExternalContact());
|
|
|
|
|
+ }
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -421,4 +400,43 @@ public class CorpEventActionServiceImpl implements CorpEventActionService {
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ public CorpUser saveOrUpdateCorpUser(CorpXmlMessage message, ExternalContact corpUserInfo) {
|
|
|
|
|
+ //查询客户是否存在
|
|
|
|
|
+ CorpUser corpUser = Optional.ofNullable(
|
|
|
|
|
+ corpUserMapper.selectOne(Wrappers.lambdaQuery(CorpUser.class)
|
|
|
|
|
+ .eq(CorpUser::getUnionid, corpUserInfo.getUnionId())))
|
|
|
|
|
+ .orElseGet(() -> new CorpUser()
|
|
|
|
|
+ .setUnionid(corpUserInfo.getUnionId()));
|
|
|
|
|
+
|
|
|
|
|
+ corpUser.setName(corpUserInfo.getName());
|
|
|
|
|
+ corpUser.setGender(corpUserInfo.getGender());
|
|
|
|
|
+ corpUser.setAvatar(corpUserInfo.getAvatar());
|
|
|
|
|
+ corpUser.setType(corpUserInfo.getType());
|
|
|
|
|
+ //扫码来源
|
|
|
|
|
+ corpUser.setState(message.getState());
|
|
|
|
|
+
|
|
|
|
|
+ //新增修改客户信息
|
|
|
|
|
+ if (corpUser.getId() == null) {
|
|
|
|
|
+ //查询是否已微信授权,关联user表id
|
|
|
|
|
+ User user = userMapper.selectOne(Wrappers.lambdaQuery(User.class).eq(User::getUnionid, corpUser.getUnionid()));
|
|
|
|
|
+ if (user != null) {
|
|
|
|
|
+ corpUser.setUserId(user.getId());
|
|
|
|
|
+ //加入企业微信后发放优惠券
|
|
|
|
|
+ groupRelationFrontService.isJoinCorpWx(user.getId(), true, false);
|
|
|
|
|
+ //发放抽奖机会
|
|
|
|
|
+ try {
|
|
|
|
|
+ sendSpecificChanceNum(user.getId());
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ }
|
|
|
|
|
+ //添加固定客服发放优惠券
|
|
|
|
|
+ isJoinFixedCustomer(user.getId(), message.getUserId());
|
|
|
|
|
+ }
|
|
|
|
|
+ corpUserMapper.insert(corpUser);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ corpUserMapper.updateById(corpUser);
|
|
|
|
|
+ }
|
|
|
|
|
+ return corpUser;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|