浏览代码

空指针修复

xw 6 天之前
父节点
当前提交
9f4e255988

+ 5 - 1
fs-qw-task/src/main/java/com/fs/app/taskService/impl/AsyncCourseWatchFinishService.java

@@ -147,7 +147,11 @@ public class AsyncCourseWatchFinishService {
         watchLog.setQwUserId(finishLog.getQwUserId());
 
         // 验证企微用户信息
-        QwUser qwUserByRedis = qwExternalContactService.getQwUserByRedisForId(String.valueOf(finishLog.getQwUserId()));
+        if (finishLog.getQwUserId() == null) {
+            log.error("企微用户ID为空,跳过处理。logId: {}", finishLog.getLogId());
+            return ValidationResult.invalid();
+        }
+        QwUser qwUserByRedis = qwExternalContactService.getQwUserByRedisForId(finishLog.getQwUserId().toString());
         if (qwUserByRedis == null) {
             log.error("无企微员工信息 {} 跳过处理。", finishLog.getQwUserId());
             return ValidationResult.invalid();

+ 12 - 7
fs-service/src/main/java/com/fs/qw/service/impl/QwExternalContactServiceImpl.java

@@ -2187,7 +2187,7 @@ public class QwExternalContactServiceImpl extends ServiceImpl<QwExternalContactM
 
     @Override
     public QwUser getQwUserByRedisForId(String qwUserId) {
-        if(StringUtils.isEmpty(qwUserId)){
+        if(StringUtils.isEmpty(qwUserId) || "null".equals(qwUserId)){
             return null;
         }
         String redisKey = "qwUserRdById:" + qwUserId;
@@ -2203,14 +2203,19 @@ public class QwExternalContactServiceImpl extends ServiceImpl<QwExternalContactM
             }
         }
 
-        QwUser qwUser = qwUserMapper.selectQwUserById(Long.valueOf(qwUserId));
-        if (qwUser == null) {
+        try {
+            QwUser qwUser = qwUserMapper.selectQwUserById(Long.valueOf(qwUserId));
+            if (qwUser == null) {
+                return null;
+            }
+
+            // 存储时确保是JSON字符串
+            redisCache.setCacheObject(redisKey, JSON.toJSONString(qwUser), 1, TimeUnit.HOURS);
+            return qwUser;
+        } catch (NumberFormatException e) {
+            logger.error("企微用户ID格式错误: {}", qwUserId);
             return null;
         }
-
-        // 存储时确保是JSON字符串
-        redisCache.setCacheObject(redisKey, JSON.toJSONString(qwUser), 1, TimeUnit.HOURS);
-        return qwUser;
     }
     ;