|
|
@@ -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);
|