|
|
@@ -1,5 +1,6 @@
|
|
|
package com.webflux.launchadmin.mysql.controller.lbOut;
|
|
|
|
|
|
+import com.webflux.launchadmin.global.BaseException;
|
|
|
import com.webflux.launchadmin.mysql.controller.lbIn.request.HomePageItemRequest;
|
|
|
import com.webflux.launchadmin.mysql.controller.lbOut.request.HomePageItemOutRequest;
|
|
|
import com.webflux.launchadmin.mysql.controller.lbOut.resp.DataList;
|
|
|
@@ -14,6 +15,7 @@ import org.springframework.data.r2dbc.core.R2dbcEntityTemplate;
|
|
|
import org.springframework.data.relational.core.query.Criteria;
|
|
|
import org.springframework.data.relational.core.query.Query;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
+import reactor.core.publisher.Flux;
|
|
|
import reactor.core.publisher.Mono;
|
|
|
|
|
|
import java.util.*;
|
|
|
@@ -46,6 +48,14 @@ public class HomePageOutController {
|
|
|
return RStatus.success(cc);
|
|
|
}
|
|
|
|
|
|
+ @PostMapping("pageTempItem1")
|
|
|
+ public Mono<RStatus<List<HomePageTemp>>> pageTempItem1(@RequestBody HomePageItemOutRequest request) {
|
|
|
+ String code = request.getCode();
|
|
|
+ Mono<List<HomePageTemp>> type_id = template.select(Query.query(Criteria.where("type_id").is(4)), HomePageTemp.class).collectList();
|
|
|
+ // Mono<Plan> code1 = template.selectOne(Query.query(Criteria.where("code").is(code)), Plan.class);
|
|
|
+ return RStatus.success(type_id);
|
|
|
+
|
|
|
+ }
|
|
|
/**
|
|
|
* H5 短剧查询
|
|
|
* @param request
|
|
|
@@ -55,10 +65,11 @@ public class HomePageOutController {
|
|
|
public Mono<RStatus<DataList<HomePageTempItem>>> pageTempItem(@RequestBody HomePageItemOutRequest request) {
|
|
|
String code = request.getCode();
|
|
|
Mono<Plan> code1 = template.selectOne(Query.query(Criteria.where("code").is(code)), Plan.class);
|
|
|
- code1.switchIfEmpty(Mono.error(new Exception("code is match failed")));
|
|
|
- Mono<DataList<HomePageTempItem>> dataListMono = code1.flatMap(plan ->
|
|
|
+ code1.switchIfEmpty(Mono.error(new BaseException("code is match failed")));
|
|
|
+ Mono<DataList<HomePageTempItem>> dataListMono = code1.filter(f->Objects.nonNull(f.groupTypeIdSc())&& f.groupTypeIdSc()>0).flatMap(plan ->
|
|
|
template.select(Query.query(Criteria.where("type_id").is(plan.groupTypeIdSc())), HomePageTemp.class)
|
|
|
.collectList()
|
|
|
+ .filter(f->!f.isEmpty())
|
|
|
.flatMap(fm -> Mono.just(selectRandomDataOne(fm)))
|
|
|
.flatMap(homePageTemp -> template.select(Query.query(Criteria.where("home_page_id").is(homePageTemp.homePageId())), HomePageTempItem.class)
|
|
|
.collectList()
|
|
|
@@ -91,10 +102,11 @@ public class HomePageOutController {
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
- return new DataList<HomePageTempItem>(bannerList, hotList, recommendList);
|
|
|
- }).switchIfEmpty(Mono.error(new Exception(" match failed")))
|
|
|
- ).switchIfEmpty(Mono.error(new Exception(" match failed"))))
|
|
|
- .switchIfEmpty(Mono.error(new Exception(" code match failed")));
|
|
|
+ return new DataList<HomePageTempItem>("成功",bannerList, hotList, recommendList);
|
|
|
+ }).switchIfEmpty(Mono.error(new BaseException(" 首页模版查询结果无关联子模版")))
|
|
|
+ ).switchIfEmpty(Mono.error(new BaseException(" 根据模版类型匹配结果为空"))))
|
|
|
+ .switchIfEmpty(Mono.error(new BaseException(" 通过code查询结果为空")))
|
|
|
+ .onErrorResume(throwable ->Mono.just(new DataList<HomePageTempItem>(throwable.getMessage(),List.of(), List.of(), List.of())) );
|
|
|
return RStatus.successList(dataListMono);
|
|
|
}
|
|
|
|
|
|
@@ -114,7 +126,6 @@ public class HomePageOutController {
|
|
|
}
|
|
|
|
|
|
public static <T> T selectRandomDataOne(List<T> dataList) {
|
|
|
- List<T> selectedData = new ArrayList<>();
|
|
|
Random random = new Random();
|
|
|
int randomIndex = random.nextInt(dataList.size());
|
|
|
T data = dataList.get(randomIndex);
|