소스 검색

fix 更新企业微信用户昵称

zoujiajian 2 년 전
부모
커밋
198419f609

+ 2 - 0
netflix-common/src/main/java/com/cyksj/common/constant/Constant.java

@@ -153,4 +153,6 @@ public interface Constant {
 	 * GPT 平台账号重复
 	 */
 	List<Long> GPT_GOODS_IDS = List.of(18l, 29l, 30l);
+
+	List<String> TRACK_RENEW_TYPE = List.of("email", "wechat");
 }

+ 66 - 48
netflix-service/src/main/java/com/cyksj/service/corp/impl/CorpEventActionServiceImpl.java

@@ -101,60 +101,34 @@ public class CorpEventActionServiceImpl implements CorpEventActionService {
 		if (corpUserInfo == 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;
 	}
 
@@ -225,6 +199,11 @@ public class CorpEventActionServiceImpl implements CorpEventActionService {
 		FollowedUser followedUser = followedUserMap.get(userId).get(0);
 		//修改客户关系
 		updateUserFollowRelation(followedUser, externalUserId, wxCorpApp.getId());
+
+		//保存企微用户
+		if (externalContact.getExternalContact() != null) {
+			saveOrUpdateCorpUser(message, externalContact.getExternalContact());
+		}
 		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;
+	}
 }

+ 15 - 5
netflix-web/src/main/java/com/cyksj/web/controller/manage/group/CmsGroupsRelationExpiryController.java

@@ -3,17 +3,16 @@ package com.cyksj.web.controller.manage.group;
 import cn.dev33.satoken.stp.StpUtil;
 import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.cyksj.common.constant.Constant;
 import com.cyksj.common.exception.BusinessRuntimeException;
 import com.cyksj.dto.Result;
 import com.cyksj.enums.GatewayResponse;
 import com.cyksj.mapper.GroupsRelationCustomerServiceFollowRecordMapper;
 import com.cyksj.mapper.GroupsRelationExpiryRecordMapper;
 import com.cyksj.mapper.UserMapper;
+import com.cyksj.mapper.corp.CorpUserMapper;
 import com.cyksj.mapper.market.task.UserBindDetailMapper;
-import com.cyksj.model.entity.GroupsRelationCustomerServiceFollowRecord;
-import com.cyksj.model.entity.GroupsRelationExpiryRecord;
-import com.cyksj.model.entity.User;
-import com.cyksj.model.entity.UserBindDetail;
+import com.cyksj.model.entity.*;
 import com.cyksj.service.user.UserBackService;
 import com.ejlchina.searcher.BeanSearcher;
 import com.ejlchina.searcher.SearchResult;
@@ -24,6 +23,7 @@ import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.bind.annotation.*;
 
 import javax.servlet.http.HttpServletRequest;
+import java.util.Optional;
 
 /*
  *项目名: netflix
@@ -49,6 +49,8 @@ public class CmsGroupsRelationExpiryController {
 
 	private final UserBindDetailMapper userBindDetailMapper;
 
+	private final CorpUserMapper corpUserMapper;
+
 	/**
 	 * 到期用户 客服跟进续费列表
 	 */
@@ -69,13 +71,21 @@ public class CmsGroupsRelationExpiryController {
 				.orderBy(GroupsRelationExpiryRecord::getId).desc()
 				.build());
 		search.getDataList().forEach(data -> {
-			if ("email".equals(data.getRegister())) {
+			if (Constant.TRACK_RENEW_TYPE.contains(data.getRegister())) {
 				UserBindDetail userBindDetail = userBindDetailMapper.selectOne(Wrappers.lambdaQuery(UserBindDetail.class).eq(UserBindDetail::getEmailUserId, data.getUserId())
 						.ne(UserBindDetail::getPhone, StrUtil.EMPTY)
 						.last("limit 1"));
 				if (userBindDetail != null) {
 					data.setContact(userBindDetail.getPhone());
 				}
+				if (Constant.TRACK_RENEW_TYPE.get(1).equals(data.getRegister())) {
+					//实时获取企业微信昵称
+					Optional.ofNullable(corpUserMapper.selectOne(Wrappers.lambdaQuery(CorpUser.class)
+							.eq(CorpUser::getUserId, data.getUserId()).last("limit 1")))
+							.ifPresent(cu -> {
+								data.setNickname(cu.getName());
+							});
+				}
 			}
 		});
 		return GatewayResponse.SUCCESS.newBuilder().toResult(search);