| | |
| | | import com.ruoyi.study.vo.SubjectVO; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | |
| | | List<TStory> storyList = new ArrayList<>(); |
| | | List<String> list; |
| | | // 分类 |
| | | String sort; |
| | | if (0 == type) { |
| | | list = Arrays.stream(storyListen.getLookStory().split(",")).collect(Collectors.toList()); |
| | | sort = storyListen.getLookSort(); |
| | | } else { |
| | | list = Arrays.stream(storyListen.getStory().split(",")).collect(Collectors.toList()); |
| | | sort = storyListen.getSort(); |
| | | } |
| | | List<String> collect = Arrays.stream(sort.split(",")).collect(Collectors.toList()); |
| | | // 获取图片及语音集合 |
| | | for (String s : list) { |
| | | for (int i = 0; i < list.size(); i++) { |
| | | String s = list.get(i); |
| | | TStory story = this.lambdaQuery().eq(TStory::getId, s).eq(TStory::getDisabled, 0).one(); |
| | | String sortIndex = collect.get(i); |
| | | story.setSort(Integer.parseInt(sortIndex)); |
| | | storyList.add(story); |
| | | } |
| | | // 根据配置的顺序进行排序,使用 Comparator 对象进行排序 |
| | | storyList.sort((story1, story2) -> { |
| | | // 首先比较 sort 字段 |
| | | int sortComparison = Integer.compare(story1.getSort(), story2.getSort()); |
| | | if (sortComparison != 0) { |
| | | // sort 不相等,按 sort 升序排序 |
| | | return sortComparison; |
| | | } else { |
| | | // 如果 sort 相等,则比较 createTime 字段 |
| | | return story1.getCreateTime().compareTo(story2.getCreateTime()); |
| | | } |
| | | }); |
| | | return storyList; |
| | | } |
| | | } |