Explorar o código

IPAD发送问题解决

吴树波 hai 3 días
pai
achega
4abc4d3b06

+ 2 - 1
.vscode/settings.json

@@ -2,5 +2,6 @@
   // 使用当前用户的 Maven settings.xml(其中已配置 localRepository = D:\\Tool\\repository)
   "java.configuration.maven.userSettings": "C:\\Users\\Administrator\\.m2\\settings.xml",
   // Maven 可执行文件路径,便于 IDE 与终端使用
-  "maven.executable.path": "D:\\Tool\\apache-maven-3.6.3\\bin\\mvn.cmd"
+  "maven.executable.path": "D:\\Tool\\apache-maven-3.6.3\\bin\\mvn.cmd",
+  "java.compile.nullAnalysis.mode": "automatic"
 }

+ 6 - 0
fs-ipad-task/src/main/java/com/fs/app/service/IpadSendServer.java

@@ -24,11 +24,13 @@ import com.fs.ipad.IpadSendUtils;
 import com.fs.ipad.vo.*;
 import com.fs.live.domain.LiveWatchLog;
 import com.fs.live.mapper.LiveWatchLogMapper;
+import com.fs.qw.domain.QwCompany;
 import com.fs.qw.domain.QwExternalContact;
 import com.fs.qw.domain.QwUser;
 import com.fs.qw.domain.QwUserVideo;
 import com.fs.qw.mapper.QwExternalContactMapper;
 import com.fs.qw.mapper.QwUserMapper;
+import com.fs.qw.service.IQwCompanyService;
 import com.fs.qw.service.IQwUserService;
 import com.fs.qw.service.IQwUserVideoService;
 import com.fs.qw.vo.QwSopCourseFinishTempSetting;
@@ -52,6 +54,7 @@ import java.util.stream.Collectors;
 public class IpadSendServer {
 
     private final QwUserMapper qwUserMapper;
+    private final IQwCompanyService qwCompanyService;
     private final IQwUserService qwUserService;
     private final IpadSendUtils ipadSendUtils;
     private final IQwSopLogsService qwSopLogsService;
@@ -565,9 +568,12 @@ public class IpadSendServer {
 
     public void send(QwSopCourseFinishTempSetting.Setting content, QwUser qwUser, QwSopLogs qwSopLogs, Map<String, FsCoursePlaySourceConfig> miniMap, BaseVo parentVo) {
         BaseVo vo = new BaseVo();
+        QwCompany qwCompany = qwCompanyService.getQwCompanyByRedis(parentVo.getCorpCode());
+        log.info("获取到的企业微信信息:{}", qwCompany);
         vo.setId(Long.parseLong(qwSopLogs.getId()));
         vo.setRoom(qwSopLogs.getSendType() == 6);
         vo.setUuid(qwUser.getUid());
+        vo.setAgentId(qwCompany.getServerAgentId());
         vo.setExId(qwSopLogs.getExternalUserId());
         vo.setServerId(qwUser.getServerId());
         vo.setCorpCode(parentVo.getCorpCode());

+ 8 - 9
fs-ipad-task/src/main/java/com/fs/app/task/SendMsg.java

@@ -6,14 +6,13 @@ import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.fs.app.service.IpadSendServer;
 import com.fs.common.annotation.TenantDataScope;
-import com.fs.common.core.redis.RedisCacheT;
 import com.fs.common.core.redis.RedisCacheTenant;
 import com.fs.common.utils.DateUtils;
 import com.fs.common.utils.PubFun;
 import com.fs.course.config.CourseConfig;
 import com.fs.course.domain.FsCoursePlaySourceConfig;
 import com.fs.course.service.IFsCoursePlaySourceConfigService;
-import com.fs.framework.aspectj.TenantDataSourceAspect;
+import com.fs.framework.aspectj.SopTenantDataSourceAspect;
 import com.fs.ipad.vo.BaseVo;
 import com.fs.qw.domain.QwIpadServer;
 import com.fs.qw.domain.QwPushCount;
@@ -65,7 +64,7 @@ public class SendMsg {
     private final IFsCoursePlaySourceConfigService fsCoursePlaySourceConfigService;
     private final QwPushCountMapper qwPushCountMapper;
     private final QwRestrictionPushRecordMapper qwRestrictionPushRecordMapper;
-    private final TenantDataSourceAspect tenantDataSourceAspect;
+    private final SopTenantDataSourceAspect sopTenantDataSourceAspect;
 
     @Value("${group-no}")
     private String groupNo;
@@ -101,7 +100,7 @@ public class SendMsg {
     @Qualifier("customThreadPool")
     private ThreadPoolTaskExecutor customThreadPool;
 
-    public SendMsg(QwUserMapper qwUserMapper, QwSopLogsMapper qwSopLogsMapper, IpadSendServer sendServer, SysConfigMapper sysConfigMapper, IQwSopLogsService qwSopLogsService, QwIpadServerMapper qwIpadServerMapper, RedisCacheTenant<Long> redisCache, AsyncSopTestService asyncSopTestService, IFsCoursePlaySourceConfigService fsCoursePlaySourceConfigService, QwPushCountMapper qwPushCountMapper, QwRestrictionPushRecordMapper qwRestrictionPushRecordMapper, TenantDataSourceAspect tenantDataSourceAspect) {
+    public SendMsg(QwUserMapper qwUserMapper, QwSopLogsMapper qwSopLogsMapper, IpadSendServer sendServer, SysConfigMapper sysConfigMapper, IQwSopLogsService qwSopLogsService, QwIpadServerMapper qwIpadServerMapper, RedisCacheTenant<Long> redisCache, AsyncSopTestService asyncSopTestService, IFsCoursePlaySourceConfigService fsCoursePlaySourceConfigService, QwPushCountMapper qwPushCountMapper, QwRestrictionPushRecordMapper qwRestrictionPushRecordMapper, SopTenantDataSourceAspect sopTenantDataSourceAspect) {
         this.qwUserMapper = qwUserMapper;
         this.qwSopLogsMapper = qwSopLogsMapper;
         this.sendServer = sendServer;
@@ -113,7 +112,7 @@ public class SendMsg {
         this.fsCoursePlaySourceConfigService = fsCoursePlaySourceConfigService;
         this.qwPushCountMapper = qwPushCountMapper;
         this.qwRestrictionPushRecordMapper = qwRestrictionPushRecordMapper;
-        this.tenantDataSourceAspect = tenantDataSourceAspect;
+        this.sopTenantDataSourceAspect = sopTenantDataSourceAspect;
     }
     private List<QwUser> getQwUserList() {
         if (qwUserList.isEmpty()) {
@@ -155,7 +154,7 @@ public class SendMsg {
         // 消息发送延迟
         int delayStart;
         int delayEnd;
-        if (config.getDelayStart() == null || config.getDelayEnd() == null) {
+        if (config == null || config.getDelayStart() == null || config.getDelayEnd() == null) {
             log.debug("消息发送延迟为空手动设置1000ms - 2000ms");
             delayStart = 500;
             delayEnd = 1000;
@@ -187,18 +186,18 @@ public class SendMsg {
                 try {
                     log.info("开始任务:{}", e.getQwUserName());
                     // 手动切换数据源到配置的租户
-                    tenantDataSourceAspect.switchTenant(tenantId);
+                    sopTenantDataSourceAspect.switchTenant(tenantId);
                     processUser(e, delayStart, delayEnd, miniMap, newCtx);
                 } catch (Exception exception) {
                     log.error("发送错误:", exception);
                 } finally {
                     log.info("删除任务:{}", e.getQwUserName());
                     // 清理数据源
-                    tenantDataSourceAspect.clear();
+                    sopTenantDataSourceAspect.clear();
                     qwMap.remove(e.getId());
                 }
             }, customThreadPool).exceptionally(ex -> {
-                log.error("任务提交失败:{}, 错误: {}", e.getQwUserName(), ex.getMessage());
+                log.error("任务提交失败:{}, 错误: {}", e.getQwUserName(), ex.getMessage(), ex);
                 qwMap.remove(e.getId());
                 return null;
             });

+ 1 - 6
fs-ipad-task/src/main/java/com/fs/framework/aspectj/TenantDataSourceAspect.java → fs-ipad-task/src/main/java/com/fs/framework/aspectj/SopTenantDataSourceAspect.java

@@ -5,10 +5,8 @@ import com.fs.common.annotation.TenantDataScope;
 import com.fs.common.core.redis.RedisCacheT;
 import com.fs.common.enums.TenantIdType;
 import com.fs.common.exception.CustomException;
-import com.fs.common.utils.StringUtils;
 import com.fs.framework.datasource.DynamicDataSource;
 import com.fs.framework.datasource.DynamicDataSourceContextHolder;
-import com.fs.huifuPay.sdk.opps.core.exception.BasePayException;
 import com.fs.tenant.domain.TenantInfo;
 import com.fs.tenant.mapper.TenantInfoMapper;
 import lombok.extern.slf4j.Slf4j;
@@ -17,9 +15,6 @@ import org.aspectj.lang.annotation.Around;
 import org.aspectj.lang.annotation.Aspect;
 import org.aspectj.lang.annotation.Pointcut;
 import org.aspectj.lang.reflect.MethodSignature;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.core.annotation.AnnotationUtils;
@@ -42,7 +37,7 @@ import java.util.concurrent.ConcurrentHashMap;
 @Aspect
 @Order(1)
 @Component
-public class TenantDataSourceAspect {
+public class SopTenantDataSourceAspect {
     private static final String TENANT_KEY = "tenant:info:";
     @Resource
     private DynamicDataSource dynamicDataSource;

+ 2 - 2
fs-ipad-task/src/main/resources/application.yml

@@ -4,6 +4,6 @@ server:
 # Spring配置
 spring:
   profiles:
-    active: dev
+    active: dev-test
 group-no: 1
-tenant-id: 11
+tenant-id: 29

+ 25 - 6
fs-service/src/main/java/com/fs/ipad/IpadSendUtils.java

@@ -37,10 +37,7 @@ import java.net.URI;
 import java.net.URISyntaxException;
 import java.net.URL;
 import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Date;
-import java.util.List;
+import java.util.*;
 import java.util.concurrent.TimeUnit;
 import java.util.function.Supplier;
 import java.util.stream.Collectors;
@@ -52,6 +49,7 @@ public class IpadSendUtils {
 
     private final WxWorkServiceNew wxWorkService;
     private final RedisCacheTenant<String> redisCache;
+    private final RedisCacheTenant<Long> redisCacheLong;
     private final QwGroupChatMapper qwGroupChatMapper;
     private final QwSopMapper qwSopMapper;
     private final QwExternalContactMapper qwExternalContactMapper;
@@ -59,6 +57,7 @@ public class IpadSendUtils {
     private final QwUserMapper qwUserMapper;
     private final String FILE_KEY = "ipad:upload:";
     private final String USER_KEY = "ipad:user:";
+    private final String APP_AGENT_KEY = "ipad:agent:";
 
     /**
      * 发送卡片消息
@@ -225,16 +224,17 @@ public class IpadSendUtils {
         if(vo.isRoom()){
             return chatIds(vo);
         }
+        Long appList = getAppList(vo);
         WxWorkUserId2VidDTO wxWorkUserId2VidDTO = new WxWorkUserId2VidDTO();
         wxWorkUserId2VidDTO.setOpenid(Collections.singletonList(vo.getExId()));
         wxWorkUserId2VidDTO.setCorpid(vo.getCorpId());
         wxWorkUserId2VidDTO.setScorpid(vo.getCorpCode());
+        wxWorkUserId2VidDTO.setAppId(appList);
         wxWorkUserId2VidDTO.setUuid(vo.getUuid());
         WxWorkResponseDTO<List<WxWorkVid2UserIdRespDTO>> WxWorkVid2UserIdRespDTO = wxWorkService.UserId2Vid(wxWorkUserId2VidDTO, vo.getServerId());
         List<WxWorkVid2UserIdRespDTO> data = WxWorkVid2UserIdRespDTO.getData();
         if(data.isEmpty()) {
-            log.error("未找到用户数据,基础数据:{},请求数据:{},返回数据:{}", vo, JSON.toJSONString(wxWorkUserId2VidDTO), JSON.toJSONString(WxWorkVid2UserIdRespDTO));
-            throw new BaseException("未找到用户:" + vo.getId());
+            log.error("未找到用户数据,基础数据:{},请求数据:{},返回数据:{}", vo, JSON.toJSONString(wxWorkUserId2VidDTO), JSON.toJSONString(WxWorkVid2UserIdRespDTO));            throw new BaseException("未找到用户:" + vo.getId());
         }
         return data.get(0).getUser_id();
     }
@@ -579,4 +579,23 @@ public class IpadSendUtils {
         log.info("发送@所有人返回数据:{}", result);
         if(result.getErrcode() != 0) throw new BaseException("发送@所有人消息错误:" + result.getErrmsg());
     }
+
+    public Long getAppList(BaseVo vo){
+        if(vo.getAgentId() == null) throw new BaseException("服务商模式应用ID必须上传请检查");
+        String key = APP_AGENT_KEY + vo.getCorpCode() + ":" + vo.getAgentId();
+        Long appId = redisCacheLong.getCacheObject(key);
+        if(appId == null){
+            WxWorkResponseDTO<CorpAppBaseVo> result = wxWorkService.getAppList(vo, vo.getServerId());
+            log.info("获取应用列表:{}", result);
+            if(result.getErrcode() != 0) throw new BaseException("获取应用列表失败:" + result.getErrmsg());
+            List<CorpAppVo> appVoList = result.getData().getWeAppList();
+            Optional<CorpAppVo> optional = appVoList.stream().filter(e -> e.getAppOpenId() != null && e.getAppOpenId().equals(Integer.parseInt(vo.getAgentId()))).findAny();
+            if(!optional.isPresent()){
+                log.info("未找到企业对应应用:corp_code:{}, corp_id:{},获取应用ID:{}, 获取到的应用列表:{}", vo.getCorpCode(), vo.getCorpId(), vo.getAgentId(), appVoList);
+                throw new BaseException("未找到对应的应用");
+            }
+            appId = optional.get().getAppId();
+        }
+        return appId;
+    }
 }

+ 2 - 0
fs-service/src/main/java/com/fs/ipad/vo/BaseVo.java

@@ -9,6 +9,7 @@ public class BaseVo{
 
     private Long id;
     private String uuid;
+    private String agentId;
     private Long serverId;
     private List<String> exIdList;
     private String exId;
@@ -19,6 +20,7 @@ public class BaseVo{
 
     public void setBase(BaseVo vo){
         this.uuid = vo.getUuid();
+        this.agentId = vo.getAgentId();
         this.serverId = vo.getServerId();
         this.corpId = vo.getCorpId();
         this.corpCode = vo.getCorpCode();

+ 13 - 0
fs-service/src/main/java/com/fs/ipad/vo/CorpAppBaseVo.java

@@ -0,0 +1,13 @@
+package com.fs.ipad.vo;
+
+import lombok.Data;
+
+import java.util.List;
+
+
+@Data
+public class CorpAppBaseVo {
+    private List<CorpAppVo> weAppList;
+}
+
+

+ 29 - 0
fs-service/src/main/java/com/fs/ipad/vo/CorpAppVo.java

@@ -0,0 +1,29 @@
+package com.fs.ipad.vo;
+
+import lombok.Data;
+
+import java.util.List;
+
+
+@Data
+public class CorpAppVo {
+
+    private Long corpId;
+    private Long appId;
+    private Integer appOpenId;
+    private Integer appType;
+    private String name;
+    private String imgId;
+    private String desc;
+    private String homeInfo;
+    private Integer lastModTime;
+    private Object reportLocFlag;
+    private Object appOpen;
+    private Integer groupId;
+    private Integer businessId;
+    private Integer appFlag;
+    private Integer stat;
+    private boolean isReportOpen;
+}
+
+

+ 1 - 0
fs-service/src/main/java/com/fs/wxwork/dto/WxWorkUserId2VidDTO.java

@@ -9,5 +9,6 @@ public class WxWorkUserId2VidDTO {
     private String uuid;
     private String scorpid;
     private String corpid;
+    private Long appId;
     private List<String> openid;
 }

+ 6 - 4
fs-service/src/main/java/com/fs/wxwork/service/WxWorkServiceNew.java

@@ -7,10 +7,7 @@ import com.fs.common.exception.CustomException;
 import com.fs.ipad.param.WxGetSessionRoomListParam;
 import com.fs.ipad.param.WxRoomUserListParam;
 import com.fs.ipad.param.WxSendAtMsgParam;
-import com.fs.ipad.vo.WxGetSessionRoomListVo;
-import com.fs.ipad.vo.WxRoomUserListVo;
-import com.fs.ipad.vo.WxSendAtMsgVo;
-import com.fs.ipad.vo.WxSendTextAtMsgVo;
+import com.fs.ipad.vo.*;
 import com.fs.qw.domain.QwIpadServer;
 import com.fs.qw.service.IQwIpadServerService;
 import com.fs.wxwork.dto.*;
@@ -240,4 +237,9 @@ public class WxWorkServiceNew {
         String url = getUrl(serverId) + "/SendTextAtMsgTwo";
         return WxWorkHttpUtil.postWithType(url, param, new TypeReference<WxWorkResponseDTO<WxSendTextAtMsgVo>>() {});
     }
+
+    public WxWorkResponseDTO<CorpAppBaseVo> getAppList(BaseVo param, Long serverId) {
+        String url = getUrl(serverId) + "/getCorpWeApp";
+        return WxWorkHttpUtil.postWithType(url, param, new TypeReference<WxWorkResponseDTO<CorpAppBaseVo>>() {});
+    }
 }