zoujiajian 3 роки тому
батько
коміт
c720992602
18 змінених файлів з 265 додано та 83 видалено
  1. 11 0
      netflix-dao/src/main/java/com/cyksj/mapper/corp/CorpUserAuthMapper.java
  2. 11 0
      netflix-dao/src/main/java/com/cyksj/mapper/corp/WxCorpAppMapper.java
  3. 1 1
      netflix-dao/src/main/java/com/cyksj/model/entity/CorpFollow.java
  4. 0 5
      netflix-dao/src/main/java/com/cyksj/model/entity/CorpUser.java
  5. 48 0
      netflix-dao/src/main/java/com/cyksj/model/entity/CorpUserAuth.java
  6. 5 0
      netflix-dao/src/main/java/com/cyksj/model/entity/CorpUserFollowRelation.java
  7. 47 0
      netflix-dao/src/main/java/com/cyksj/model/entity/WxCorpApp.java
  8. 6 0
      netflix-dao/src/main/java/com/cyksj/model/request/CorpCouponSendReq.java
  9. 52 0
      netflix-service/src/main/java/com/cyksj/config/corp/WeChatCorpFactory.java
  10. 0 32
      netflix-service/src/main/java/com/cyksj/config/corp/WxCorpFactory.java
  11. 0 7
      netflix-service/src/main/java/com/cyksj/config/corp/YHLXWxCorpConfig.java
  12. 1 1
      netflix-service/src/main/java/com/cyksj/service/corp/CorpService.java
  13. 24 5
      netflix-service/src/main/java/com/cyksj/service/corp/impl/CorpEventActionServiceImpl.java
  14. 31 17
      netflix-service/src/main/java/com/cyksj/service/corp/impl/CorpServiceImpl.java
  15. 7 7
      netflix-service/src/main/java/com/cyksj/service/corp/impl/WxCorpOpsImpl.java
  16. 17 4
      netflix-service/src/main/java/com/cyksj/service/mange/coupon/impl/CouponCommonServiceImpl.java
  17. 2 2
      netflix-service/src/main/java/com/cyksj/util/WxCorpUtil.java
  18. 2 2
      netflix-web/src/main/java/com/cyksj/web/controller/manage/corp/WxCorpController.java

+ 11 - 0
netflix-dao/src/main/java/com/cyksj/mapper/corp/CorpUserAuthMapper.java

@@ -0,0 +1,11 @@
+package com.cyksj.mapper.corp;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.cyksj.model.entity.CorpUserAuth;
+
+/**
+ * @author chan
+ * @date 2022/4/8 上午11:06
+ */
+public interface CorpUserAuthMapper extends BaseMapper<CorpUserAuth> {
+}

+ 11 - 0
netflix-dao/src/main/java/com/cyksj/mapper/corp/WxCorpAppMapper.java

@@ -0,0 +1,11 @@
+package com.cyksj.mapper.corp;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.cyksj.model.entity.WxCorpApp;
+
+/**
+ * @author chan
+ * @date 2022/4/7 下午6:10
+ */
+public interface WxCorpAppMapper extends BaseMapper<WxCorpApp> {
+}

+ 1 - 1
netflix-dao/src/main/java/com/cyksj/model/entity/CorpFollow.java

@@ -11,7 +11,7 @@ import java.io.Serializable;
 @Data
 public class CorpFollow extends BaseEntity implements Serializable {
 
-    private String corpId;
+    private Long wxCorpId;
 
     /**
      * 成员UserID

+ 0 - 5
netflix-dao/src/main/java/com/cyksj/model/entity/CorpUser.java

@@ -13,11 +13,6 @@ import java.io.Serializable;
 @Data
 public class CorpUser extends BaseEntity implements Serializable {
 
-	/**
-	 * 外部联系人的userid
-	 */
-	private String externalUserid;
-
 	/**
 	 * 外部联系人的名称
 	 */

+ 48 - 0
netflix-dao/src/main/java/com/cyksj/model/entity/CorpUserAuth.java

@@ -0,0 +1,48 @@
+package com.cyksj.model.entity;
+
+import com.baomidou.mybatisplus.annotation.FieldFill;
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableId;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+ * @author chan
+ * @date 2022/4/8 上午11:06
+ */
+@Data
+public class CorpUserAuth implements Serializable {
+
+    @TableId(value = "id", type = IdType.AUTO)
+    private Long id;
+
+    /**
+     * 企业微信客户userid
+     */
+    private String externalUserid;
+
+    /**
+     * 企业微信用户id
+     */
+    private Long corpUserId;
+
+    /**
+     *  企业id
+     */
+    private Long wxCorpId;
+
+    /**
+     * 创建时间
+     */
+    @TableField(fill = FieldFill.INSERT)
+    private Date createdTime;
+
+    /**
+     * 修改时间
+     */
+    @TableField(fill = FieldFill.INSERT_UPDATE)
+    private Date updateTime;
+}

+ 5 - 0
netflix-dao/src/main/java/com/cyksj/model/entity/CorpUserFollowRelation.java

@@ -17,6 +17,11 @@ import java.util.stream.Stream;
 @Data
 public class CorpUserFollowRelation extends BaseEntity implements Serializable {
 
+	/**
+	 * wx_corp_app_id
+	 */
+	private Long wxCorpId;
+
 	/**
 	 * corp_user 客户id
 	 */

+ 47 - 0
netflix-dao/src/main/java/com/cyksj/model/entity/WxCorpApp.java

@@ -0,0 +1,47 @@
+package com.cyksj.model.entity;
+
+import com.baomidou.mybatisplus.annotation.TableField;
+import lombok.Getter;
+import lombok.Setter;
+
+/**
+ * @author chan
+ * @date 2022/3/11 下午12:15
+ */
+@Getter
+@Setter
+public class WxCorpApp {
+
+    private Long id;
+
+    /**
+     * appId
+     */
+
+    @TableField(value = "corpId")
+    private String corpId;
+
+    /**
+     * appSecret
+     */
+    @TableField(value = "corpSecret")
+    private String corpSecret;
+
+    private String token;
+
+    @TableField(value = "encodingAESKey")
+    private String encodingAESKey;
+
+    private String domain;
+
+    /**
+     * 管理员
+     */
+    private String admin;
+
+    /**
+     * 备注
+     */
+    private String remark;
+
+}

+ 6 - 0
netflix-dao/src/main/java/com/cyksj/model/request/CorpCouponSendReq.java

@@ -26,4 +26,10 @@ public class CorpCouponSendReq {
 	 */
 	@NotNull
 	private Long couponId;
+
+	/**
+	 * 企业微信id
+	 */
+	@NotEmpty
+	private String corpId;
 }

+ 52 - 0
netflix-service/src/main/java/com/cyksj/config/corp/WeChatCorpFactory.java

@@ -0,0 +1,52 @@
+package com.cyksj.config.corp;
+
+import cn.hutool.core.util.StrUtil;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.cyksj.common.exception.BusinessRuntimeException;
+import com.cyksj.mapper.corp.WxCorpAppMapper;
+import com.cyksj.model.entity.WxCorpApp;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.PostConstruct;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * @author chan
+ * @date 2022/4/7 4:51 下午
+ */
+@Component
+public class WeChatCorpFactory {
+
+    @Autowired
+    private WxCorpAppMapper corpAppMapper;
+
+    private static Map<String, WxCorpApp> strategyBean = new ConcurrentHashMap<>();
+
+    /**
+     * 初始化
+     *
+     * @param corpId
+     * @return
+     */
+    public static WxCorpApp getCorpConfigStrategy(String corpId) {
+        if (StrUtil.isBlank(corpId)) {
+            throw BusinessRuntimeException.getInstance("corpId is empty");
+        }
+        WxCorpApp corpApp = strategyBean.get(corpId);
+        Objects.requireNonNull(corpApp, "corp config not exist");
+        return corpApp;
+    }
+
+    @PostConstruct
+    public void init() {
+        List<WxCorpApp> wxCorpApps = corpAppMapper.selectList(Wrappers.lambdaQuery(WxCorpApp.class));
+        wxCorpApps.forEach((corpApp)->{
+            strategyBean.put(corpApp.getCorpId(), corpApp);
+        });
+    }
+
+}

+ 0 - 32
netflix-service/src/main/java/com/cyksj/config/corp/WxCorpFactory.java

@@ -1,32 +0,0 @@
-package com.cyksj.config.corp;
-
-import cn.hutool.core.util.StrUtil;
-
-import java.util.Map;
-import java.util.Optional;
-import java.util.concurrent.ConcurrentHashMap;
-
-/*
- *项目名: netflix
- *文件名: WxCorpFactory
- *创建者: JavaZou
- *创建时间:2022/10/13 15:18
- */
-public class WxCorpFactory {
-
-	private static Map<String, BaseWxCorpConfig> wxCorpBean = new ConcurrentHashMap<>();
-
-	/**
-	 * 获取企业微信
-	 */
-	public static BaseWxCorpConfig getBaseWxCorpConfig(String corpId) {
-		if (StrUtil.isEmpty(corpId)) {
-			return null;
-		}
-		return Optional.ofNullable(wxCorpBean.get(corpId)).orElse(null);
-	}
-
-	public static void add(BaseWxCorpConfig baseWxCorpConfig) {
-		wxCorpBean.put(baseWxCorpConfig.getCorpId(), baseWxCorpConfig);
-	}
-}

+ 0 - 7
netflix-service/src/main/java/com/cyksj/config/corp/YHLXWxCorpConfig.java

@@ -3,8 +3,6 @@ package com.cyksj.config.corp;
 import org.springframework.boot.context.properties.ConfigurationProperties;
 import org.springframework.context.annotation.Configuration;
 
-import javax.annotation.PostConstruct;
-
 /*
  *项目名: netflix
  *文件名: A
@@ -14,9 +12,4 @@ import javax.annotation.PostConstruct;
 @Configuration
 @ConfigurationProperties(prefix = "yhlx")
 public class YHLXWxCorpConfig extends BaseWxCorpConfig {
-
-	@PostConstruct
-	public void add() {
-		WxCorpFactory.add(this);
-	}
 }

+ 1 - 1
netflix-service/src/main/java/com/cyksj/service/corp/CorpService.java

@@ -27,5 +27,5 @@ public interface CorpService {
 
 	String getAgentJsTicket(String corpId, String agentId) throws Exception;
 
-	YHLXUserDetailView getUserDetailView(String externalUserid) throws Exception;
+	YHLXUserDetailView getUserDetailView(String externalUserid, String corpId) throws Exception;
 }

+ 24 - 5
netflix-service/src/main/java/com/cyksj/service/corp/impl/CorpEventActionServiceImpl.java

@@ -2,6 +2,7 @@ package com.cyksj.service.corp.impl;
 
 import cn.hutool.core.bean.BeanUtil;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.cyksj.config.corp.WeChatCorpFactory;
 import com.cyksj.mapper.UserMapper;
 import com.cyksj.mapper.corp.*;
 import com.cyksj.model.entity.*;
@@ -45,11 +46,14 @@ public class CorpEventActionServiceImpl implements CorpEventActionService {
 
 	private final CorpTagMapper corpTagMapper;
 
+	private final CorpUserAuthMapper corpUserAuthMapper;
+
 	/**
 	 * 客户添加成员
 	 */
 	@Override
 	public CorpXmlOutMessage addExternalContact(String corpId, String userId, String externalUserId, String welcomeCode, Map<String, Object> context) throws Exception {
+		WxCorpApp wxCorpApp = WeChatCorpFactory.getCorpConfigStrategy(corpId);
 		//1.从企业微信获取客户信息
 		CorpExternalContactInfo externalContact = wxCorpOps.getExternalContact(corpId, externalUserId);
 		ExternalContact corpUserInfo = externalContact.getExternalContact();
@@ -66,7 +70,6 @@ public class CorpEventActionServiceImpl implements CorpEventActionService {
 		corpUser.setName(corpUserInfo.getName());
 		corpUser.setGender(corpUserInfo.getGender());
 		corpUser.setAvatar(corpUserInfo.getAvatar());
-		corpUser.setExternalUserid(corpUserInfo.getExternalUserId());
 		corpUser.setType(corpUserInfo.getType());
 
 		//新增修改客户信息
@@ -80,16 +83,27 @@ public class CorpEventActionServiceImpl implements CorpEventActionService {
 		} 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();
 
 		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, corpUser.getExternalUserid()));
+				.forEach(followedUser -> updateUserFollowRelation(followedUser, corpUserInfo.getExternalUserId(), wxCorpApp.getId()));
 
 		return null;
 	}
@@ -99,15 +113,17 @@ public class CorpEventActionServiceImpl implements CorpEventActionService {
 	 */
 	@Override
 	public CorpXmlOutMessage editExternalContact(CorpXmlMessage message, Map<String, Object> context) throws Exception {
+		String corpId = message.getToUserName();
+		WxCorpApp wxCorpApp = WeChatCorpFactory.getCorpConfigStrategy(corpId);
 		//客户id
 		String externalUserId = message.getExternalUserId();
 		//成员id
 		String userId = message.getUserId();
-		CorpExternalContactInfo externalContact = wxCorpOps.getExternalContact(message.getToUserName(), externalUserId);
+		CorpExternalContactInfo externalContact = wxCorpOps.getExternalContact(corpId, externalUserId);
 		Map<String, List<FollowedUser>> followedUserMap = externalContact.getFollowedUsers().stream().collect(Collectors.groupingBy(FollowedUser::getUserId));
 		FollowedUser followedUser = followedUserMap.get(userId).get(0);
 		//修改客户关系
-		updateUserFollowRelation(followedUser, externalUserId);
+		updateUserFollowRelation(followedUser, externalUserId, wxCorpApp.getId());
 		return null;
 	}
 
@@ -173,9 +189,10 @@ public class CorpEventActionServiceImpl implements CorpEventActionService {
 	 * 修改客户成员关系,客户标签
 	 */
 	@Transactional(rollbackFor = Throwable.class)
-	public void updateUserFollowRelation(FollowedUser followedUser, String externalUserid) {
+	public void updateUserFollowRelation(FollowedUser followedUser, String externalUserid, Long wxCorpId) {
 		CorpUserFollowRelation relation = Optional.ofNullable(relationMapper
 				.selectOne(Wrappers.lambdaQuery(CorpUserFollowRelation.class)
+						.eq(CorpUserFollowRelation::getWxCorpId, wxCorpId)
 						.eq(CorpUserFollowRelation::getCorpUserId, externalUserid)
 						.eq(CorpUserFollowRelation::getFollowId, followedUser.getUserId())
 						.last("limit 1"))).orElse(new CorpUserFollowRelation().setFollowId(followedUser.getUserId()).setCorpUserId(externalUserid));
@@ -186,6 +203,8 @@ public class CorpEventActionServiceImpl implements CorpEventActionService {
 		relation.setRemarkMobiles(Arrays.toString(followedUser.getRemarkMobiles()));
 		relation.setAddWay(CorpUserFollowRelation.Way.getDesc(followedUser.getAddWay()));
 		relation.setOperUserid(followedUser.getOperatorUserId());
+		relation.setStatus(1);
+		relation.setWxCorpId(wxCorpId);
 		if (relation.getId() == null) relationMapper.insert(relation);
 		else relationMapper.updateById(relation);
 		corpUserTagMapper.delete(Wrappers.lambdaQuery(CorpUserTag.class).eq(CorpUserTag::getRelationId, relation.getId()));

+ 31 - 17
netflix-service/src/main/java/com/cyksj/service/corp/impl/CorpServiceImpl.java

@@ -3,24 +3,22 @@ package com.cyksj.service.corp.impl;
 import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.date.DateTime;
 import cn.hutool.core.util.StrUtil;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.cyksj.common.task.GlobalThreadPoolTaskExecutor;
 import com.cyksj.common.util.ListsUtil;
 import com.cyksj.common.util.Xmls;
 import com.cyksj.common.util.corp.WxCryptUtil;
-import com.cyksj.config.corp.BaseWxCorpConfig;
-import com.cyksj.config.corp.WxCorpFactory;
+import com.cyksj.config.corp.WeChatCorpFactory;
 import com.cyksj.config.corp.YHLXWxCorpConfig;
 import com.cyksj.dto.CorpOauth2UserInfo;
 import com.cyksj.mapper.AddressMapper;
 import com.cyksj.mapper.UserMapper;
 import com.cyksj.mapper.corp.CorpFollowMapper;
+import com.cyksj.mapper.corp.CorpUserAuthMapper;
 import com.cyksj.mapper.corp.CorpUserMapper;
 import com.cyksj.model.dto.WxCorpEncryptDto;
-import com.cyksj.model.entity.Address;
-import com.cyksj.model.entity.CorpFollow;
-import com.cyksj.model.entity.CorpUser;
-import com.cyksj.model.entity.User;
+import com.cyksj.model.entity.*;
 import com.cyksj.model.manage.views.OrderDonView;
 import com.cyksj.model.request.corp.CorpXmlMessage;
 import com.cyksj.model.request.corp.CorpXmlOutMessage;
@@ -89,6 +87,9 @@ public class CorpServiceImpl implements CorpService {
 	@Autowired
 	private AddressMapper addressMapper;
 
+	@Autowired
+	private CorpUserAuthMapper corpUserAuthMapper;
+
 	@PostConstruct
 	private void init() {
 		corpMessageRouter = new CorpMessageRouter(this)
@@ -176,9 +177,9 @@ public class CorpServiceImpl implements CorpService {
 	@Override
 	public String corpMsg(String msgSignature, String timestamp, String nonce, String content) throws Exception {
 		WxCorpEncryptDto corpEncryptDto = Xmls.parseObject(content, WxCorpEncryptDto.class);
-		BaseWxCorpConfig corpConfig = WxCorpFactory.getBaseWxCorpConfig(corpEncryptDto.getToUserName());
+		WxCorpApp wxCorpApp = WeChatCorpFactory.getCorpConfigStrategy(corpEncryptDto.getToUserName());
 
-		WxCorpUtil wxCorpUtil = new WxCorpUtil(corpConfig.getToken(), corpConfig.getEncodingAESKey(), corpConfig.getCorpId());
+		WxCorpUtil wxCorpUtil = new WxCorpUtil(wxCorpApp.getToken(), wxCorpApp.getEncodingAESKey(), wxCorpApp.getCorpId());
 
 		String msg = wxCorpUtil.DecryptMsg(msgSignature, timestamp, nonce, corpEncryptDto);
 		log.info("企业微信 解密 msg:\n{}", msg);
@@ -198,6 +199,8 @@ public class CorpServiceImpl implements CorpService {
 	public String dataInitByCorpId(String corpId) throws Exception {
 		//获取成员列表
 		List<String> followUserList = wxCorpOps.getFollowUserList(corpId);
+		WxCorpApp wxCorpApp = WeChatCorpFactory.getCorpConfigStrategy(corpId);
+		Long wxCorpId = wxCorpApp.getId();
 		for (String userId : followUserList) {
 			THREAD_POOL.execute(() -> {
 				CorpUserInfo userInfo = null;
@@ -209,9 +212,9 @@ public class CorpServiceImpl implements CorpService {
 				}
 				CorpFollow corpFollow = new CorpFollow();
 				BeanUtil.copyProperties(userInfo, corpFollow);
-				CorpFollow follow = corpFollowMapper.selectOne(Wrappers.lambdaQuery(CorpFollow.class).eq(CorpFollow::getUserid, corpFollow.getUserid()).eq(CorpFollow::getCorpId, corpId));
+				CorpFollow follow = corpFollowMapper.selectOne(Wrappers.lambdaQuery(CorpFollow.class).eq(CorpFollow::getUserid, corpFollow.getUserid()).eq(CorpFollow::getWxCorpId, wxCorpId));
 				if (follow == null) {
-					corpFollow.setCorpId(corpId);
+					corpFollow.setWxCorpId(wxCorpId);
 					corpFollowMapper.insert(corpFollow);
 				} else {
 					corpFollow.setId(follow.getId());
@@ -265,12 +268,14 @@ public class CorpServiceImpl implements CorpService {
 	@Override
 	@Transactional(rollbackFor = Throwable.class)
 	public CorpFollow saveFollowUser(String corpId, CorpOauth2UserInfo corpOauth2UserInfo) throws Exception {
-		CorpFollow corpFollow = corpFollowMapper.selectOne(Wrappers.lambdaQuery(CorpFollow.class).eq(CorpFollow::getCorpId, corpId).eq(CorpFollow::getUserid, corpOauth2UserInfo.getUserId()));
+		WxCorpApp wxCorpApp = WeChatCorpFactory.getCorpConfigStrategy(corpId);
+		Long wxCorpId = wxCorpApp.getId();
+		CorpFollow corpFollow = corpFollowMapper.selectOne(Wrappers.lambdaQuery(CorpFollow.class).eq(CorpFollow::getWxCorpId, wxCorpId).eq(CorpFollow::getUserid, corpOauth2UserInfo.getUserId()));
 		if (corpFollow == null) {
 			CorpUserInfo userInfo = wxCorpOps.getFollowUser(corpId, corpOauth2UserInfo.getUserId());
 			corpFollow = new CorpFollow();
 			BeanUtil.copyProperties(userInfo, corpFollow);
-			corpFollow.setCorpId(corpId);
+			corpFollow.setWxCorpId(wxCorpId);
 			corpFollowMapper.insert(corpFollow);
 		}
 
@@ -288,12 +293,21 @@ public class CorpServiceImpl implements CorpService {
 	}
 
 	@Override
-	public YHLXUserDetailView getUserDetailView(String externalUserid) throws Exception {
-		CorpUser corpUser = corpUserMapper.selectOne(Wrappers.lambdaQuery(CorpUser.class).eq(CorpUser::getExternalUserid, externalUserid).last("limit 1"));
-		if (corpUser == null) {
+	public YHLXUserDetailView getUserDetailView(String externalUserid, String corpId) throws Exception {
+		WxCorpApp wxCorpApp = WeChatCorpFactory.getCorpConfigStrategy(corpId);
+
+		LambdaQueryWrapper<CorpUserAuth> corpUserAuthWrapper = Wrappers.lambdaQuery(CorpUserAuth.class)
+				.eq(CorpUserAuth::getExternalUserid, externalUserid)
+				.eq(CorpUserAuth::getWxCorpId, wxCorpApp.getId()).last("limit 1");
+		CorpUserAuth corpUserAuth = corpUserAuthMapper.selectOne(corpUserAuthWrapper);
+		CorpUser corpUser = null;
+		if (corpUserAuth == null) {
 			//尝试添加客户
-			corpEventActionService.addExternalContact(yhlXWxCorpConfig.getCorpId(), null, externalUserid, null, null);
-			corpUser = corpUserMapper.selectOne(Wrappers.lambdaQuery(CorpUser.class).eq(CorpUser::getExternalUserid, externalUserid).last("limit 1"));
+			corpEventActionService.addExternalContact(corpId, null, externalUserid, null, null);
+			corpUserAuth = corpUserAuthMapper.selectOne(corpUserAuthWrapper);
+			if (corpUserAuth != null) {
+				corpUser = corpUserMapper.selectOne(Wrappers.lambdaQuery(CorpUser.class).eq(CorpUser::getId, corpUserAuth.getCorpUserId()).last("limit 1"));
+			}
 		}
 		if (corpUser == null) {
 			log.info("该客户{}不存在", externalUserid);

+ 7 - 7
netflix-service/src/main/java/com/cyksj/service/corp/impl/WxCorpOpsImpl.java

@@ -6,11 +6,11 @@ import com.cyksj.common.exception.BusinessRuntimeException;
 import com.cyksj.common.util.IoKit;
 import com.cyksj.common.util.J11HttpC;
 import com.cyksj.common.util.Jsons;
-import com.cyksj.config.corp.BaseWxCorpConfig;
-import com.cyksj.config.corp.WxCorpFactory;
+import com.cyksj.config.corp.WeChatCorpFactory;
 import com.cyksj.config.corp.YHLXWxCorpConfig;
 import com.cyksj.dto.CorpOauth2UserInfo;
 import com.cyksj.dto.RedisKey;
+import com.cyksj.model.entity.WxCorpApp;
 import com.cyksj.model.response.*;
 import com.cyksj.redis.RedisService;
 import com.cyksj.service.corp.WxCorpOps;
@@ -136,10 +136,10 @@ public class WxCorpOpsImpl implements WxCorpOps {
 
 	@Override
 	public String createUrl(String corpId, String state) {
-		BaseWxCorpConfig wxCorpConfig = WxCorpFactory.getBaseWxCorpConfig(corpId);
+		WxCorpApp wxCorpApp = WeChatCorpFactory.getCorpConfigStrategy(corpId);
 		return "https://open.weixin.qq.com/connect/oauth2/authorize" +
-				"?appid=" + wxCorpConfig.getCorpId() +
-				"&redirect_uri=" + URLEncoder.encode(wxCorpConfig.getDomain() + "/manage/corp/redirect", IoKit.Charsets.UTF_8.getCharset()) +
+				"?appid=" + wxCorpApp.getCorpId() +
+				"&redirect_uri=" + URLEncoder.encode(wxCorpApp.getDomain() + "/manage/corp/redirect", IoKit.Charsets.UTF_8.getCharset()) +
 				"&response_type=code" +
 				"&scope=snsapi_base" +
 				"&state=" + state +
@@ -186,11 +186,11 @@ public class WxCorpOpsImpl implements WxCorpOps {
 	}
 
 	public String access_token(String corpId) throws Exception {
-		BaseWxCorpConfig corpConfig = WxCorpFactory.getBaseWxCorpConfig(corpId);
+		WxCorpApp wxCorpApp = WeChatCorpFactory.getCorpConfigStrategy(corpId);
 		if (corpId == null) {
 			throw BusinessRuntimeException.getInstance("{0}企业微信不存在", corpId);
 		}
-		String url = String.format("https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=%s&corpsecret=%s", corpConfig.getCorpId(), corpConfig.getCorpSecret());
+		String url = String.format("https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=%s&corpsecret=%s", wxCorpApp.getCorpId(), wxCorpApp.getCorpSecret());
 		HttpResponse<byte[]> res =
 				J11HttpC.custom()
 						.ofGet()

+ 17 - 4
netflix-service/src/main/java/com/cyksj/service/mange/coupon/impl/CouponCommonServiceImpl.java

@@ -1,13 +1,16 @@
 package com.cyksj.service.mange.coupon.impl;
 
 import cn.hutool.core.util.StrUtil;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.cyksj.common.exception.BusinessRuntimeException;
 import com.cyksj.common.util.Jsons;
+import com.cyksj.config.corp.WeChatCorpFactory;
 import com.cyksj.config.corp.YHLXWxCorpConfig;
 import com.cyksj.mapper.GoodsDonMapper;
 import com.cyksj.mapper.GoodsDonSkuMapper;
 import com.cyksj.mapper.UserMapper;
+import com.cyksj.mapper.corp.CorpUserAuthMapper;
 import com.cyksj.mapper.corp.CorpUserMapper;
 import com.cyksj.mapper.manage.coupon.*;
 import com.cyksj.model.entity.*;
@@ -63,6 +66,8 @@ public class CouponCommonServiceImpl implements CouponCommonService {
 
 	private final CouponFontService couponFontService;
 
+	private final CorpUserAuthMapper corpUserAuthMapper;
+
 	@Override
 	@Transactional(rollbackFor = Throwable.class)
 	public void saveCoupon(Coupon coupon) throws Exception {
@@ -160,12 +165,20 @@ public class CouponCommonServiceImpl implements CouponCommonService {
 
 	@Override
 	public void corpSendCoupon(CorpCouponSendReq corpCouponSendReq) throws Exception {
+		WxCorpApp wxCorpApp = WeChatCorpFactory.getCorpConfigStrategy(corpCouponSendReq.getCorpId());
 		String externalUserId = corpCouponSendReq.getExternalUserId();
-		CorpUser corpUser = corpUserMapper.selectOne(Wrappers.lambdaQuery(CorpUser.class).eq(CorpUser::getExternalUserid, externalUserId).last("limit 1"));
-		if (corpUser == null) {
+		LambdaQueryWrapper<CorpUserAuth> corpUserAuthWrapper = Wrappers.lambdaQuery(CorpUserAuth.class)
+				.eq(CorpUserAuth::getExternalUserid, externalUserId)
+				.eq(CorpUserAuth::getWxCorpId, wxCorpApp.getId()).last("limit 1");
+		CorpUserAuth corpUserAuth = corpUserAuthMapper.selectOne(corpUserAuthWrapper);
+		CorpUser corpUser = null;
+		if (corpUserAuth == null) {
 			//尝试添加客户
-			corpEventActionService.addExternalContact(yhlXWxCorpConfig.getCorpId(), null, externalUserId, null, null);
-			corpUser = corpUserMapper.selectOne(Wrappers.lambdaQuery(CorpUser.class).eq(CorpUser::getExternalUserid, externalUserId).last("limit 1"));
+			corpEventActionService.addExternalContact(wxCorpApp.getCorpId(), null, externalUserId, null, null);
+			corpUserAuth = corpUserAuthMapper.selectOne(corpUserAuthWrapper);
+			if (corpUserAuth != null) {
+				corpUser = corpUserMapper.selectOne(Wrappers.lambdaQuery(CorpUser.class).eq(CorpUser::getId, corpUserAuth.getCorpUserId()).last("limit 1"));
+			}
 		}
 		if (corpUser == null) {
 			log.info("该客户{}不存在", externalUserId);

+ 2 - 2
netflix-service/src/main/java/com/cyksj/util/WxCorpUtil.java

@@ -4,7 +4,7 @@ import com.cyksj.common.exception.AesException;
 import com.cyksj.common.util.Codec;
 import com.cyksj.common.util.corp.PKCS7Encoder;
 import com.cyksj.common.util.corp.SHA1;
-import com.cyksj.config.corp.WxCorpFactory;
+import com.cyksj.config.corp.WeChatCorpFactory;
 import com.cyksj.model.dto.WxCorpEncryptDto;
 
 import javax.crypto.Cipher;
@@ -135,7 +135,7 @@ public class WxCorpUtil {
 		}
 
 		// receiveid不相同的情况
-		if (WxCorpFactory.getBaseWxCorpConfig(from_receiveid) == null) {
+		if (WeChatCorpFactory.getCorpConfigStrategy(from_receiveid) == null) {
 			throw new AesException(AesException.ValidateCorpidError);
 		}
 		return xmlContent;

+ 2 - 2
netflix-web/src/main/java/com/cyksj/web/controller/manage/corp/WxCorpController.java

@@ -202,8 +202,8 @@ public class WxCorpController {
 	 * 企业微信客户银河录像详情
 	 */
 	@GetMapping("/user/detail")
-	public Result<YHLXUserDetailView> getYHLXUserDetailView(String externalUserid) throws Exception {
-		YHLXUserDetailView detailView = corpService.getUserDetailView(externalUserid);
+	public Result<YHLXUserDetailView> getYHLXUserDetailView(String externalUserid, String corpId) throws Exception {
+		YHLXUserDetailView detailView = corpService.getUserDetailView(externalUserid, corpId);
 		return GatewayResponse.SUCCESS.newBuilder().toResult(detailView);
 	}