|
|
@@ -793,7 +793,39 @@ public class ArticleSercieImp implements ArticleServiceInterface {
|
|
|
|
|
|
@Override
|
|
|
public Mono<RStatus<List<ArticleOutRes>>> random6Page() {
|
|
|
- return getSizeArticle(6);
|
|
|
+ StringBuilder startSql = new StringBuilder();
|
|
|
+ startSql.append("SELECT id,front_cover,title,date_time_str FROM article WHERE deleted_at IS NULL ");
|
|
|
+ startSql.append( "AND date_time_str >'");
|
|
|
+ DateTime dateTime = DateUtil.offsetDay(new Date(), -7);
|
|
|
+ String format = DateUtil.format(dateTime, "yyyy-MM-dd");
|
|
|
+ startSql.append( format);
|
|
|
+ startSql.append( "'");
|
|
|
+ Mono<List<ArticleOutRes>> listMono1 = template.getDatabaseClient().sql(startSql.toString()).map((row, rowMetadata) -> {
|
|
|
+ ArticleOutRes articleRes = new ArticleOutRes();
|
|
|
+ articleRes.setId(row.get("id", Long.class));
|
|
|
+ articleRes.setTitle(row.get("title", String.class));
|
|
|
+ articleRes.setDateTimeStr(row.get("date_time_str", String.class));
|
|
|
+ articleRes.setFrontCover(row.get("front_cover", String.class));
|
|
|
+ return articleRes;
|
|
|
+ }).all().collectList().flatMap(articleOutRes -> {
|
|
|
+ ArrayList<ArticleOutRes> articleOutRes1 = new ArrayList<>();
|
|
|
+ if (!articleOutRes.isEmpty() &&articleOutRes.size()>6) {
|
|
|
+ for (int i =0 ;i<6;i++){
|
|
|
+ List<ArticleOutRes> collect = articleOutRes.stream()
|
|
|
+ .filter(articleOutRes2 ->
|
|
|
+ articleOutRes1.stream().noneMatch(articleOutRes3 -> articleOutRes3.getId().equals(articleOutRes2.getId()))).collect(Collectors.toList());
|
|
|
+ int i1 = RandomUtil.randomInt(0, collect.size());
|
|
|
+ ArticleOutRes articleOutRes2 = collect.get(i1);
|
|
|
+ articleOutRes1.add(articleOutRes2);
|
|
|
+ }
|
|
|
+
|
|
|
+ }else{
|
|
|
+ articleOutRes1.addAll(articleOutRes);
|
|
|
+ }
|
|
|
+ return Mono.just(articleOutRes1);
|
|
|
+
|
|
|
+ });
|
|
|
+ return RStatus.successList(listMono1);
|
|
|
}
|
|
|
|
|
|
}
|