Browse Source

fix: 空指针问题

dongdong.xiang 3 tuần trước cách đây
mục cha
commit
8147214fad

+ 9 - 3
fs-service-system/src/main/java/com/fs/sop/service/impl/QwSopTempServiceImpl.java

@@ -32,6 +32,7 @@ import com.fs.sop.vo.VoiceVo;
 import com.fs.system.domain.SysConfig;
 import com.fs.system.service.ISysConfigService;
 import lombok.AllArgsConstructor;
+import org.apache.commons.collections4.CollectionUtils;
 import org.apache.rocketmq.spring.core.RocketMQTemplate;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
@@ -286,10 +287,14 @@ public class QwSopTempServiceImpl implements IQwSopTempService
     @Override
     public List<QwSopTempRedPackageVo> redList(String id) {
         List<QwSopTempDay> dayList = qwSopTempRulesService.listByTempIdAll(id);
-        if(dayList.isEmpty()){
+        if(CollectionUtils.isNotEmpty(dayList)){
             return Collections.emptyList();
         }
-        List<QwSopTempRules> rules = dayList.stream().flatMap(e -> e.getList().stream()).collect(Collectors.toList());
+        List<QwSopTempRules> rules = dayList.stream()
+                .filter(e->e!= null && e.getList()!=null)
+                .flatMap(e -> e.getList().stream())
+                .filter(Objects::nonNull)
+                .collect(Collectors.toList());
         if(rules.isEmpty()){
             return Collections.emptyList();
         }
@@ -297,7 +302,8 @@ public class QwSopTempServiceImpl implements IQwSopTempService
         Map<Long, FsUserCourseVideoRedPackage> redMap = PubFun.listToMapByGroupObject(redPackageList, FsUserCourseVideoRedPackage::getVideoId);
         List<FsUserCourseVideo> videoList = fsUserCourseVideoMapper.selectVideoByCourseId(rules.get(0).getCourseId());
         Map<Long, FsUserCourseVideo> videoMap = PubFun.listToMapByGroupObject(videoList, FsUserCourseVideo::getVideoId);
-        return rules.stream().filter(e -> redMap.containsKey(e.getVideoId()) && videoMap.containsKey(e.getVideoId())).map(e -> {
+        return rules.stream()
+                .filter(e -> e.getVideoId() != null && redMap.containsKey(e.getVideoId()) && videoMap.containsKey(e.getVideoId())).map(e -> {
             FsUserCourseVideoRedPackage red = redMap.get(e.getVideoId());
             FsUserCourseVideo video = videoMap.get(e.getVideoId());
             QwSopTempRedPackageVo vo = new QwSopTempRedPackageVo();