I wrote a script and wanted to take the Visitor list through FoodPreference, but when running the script could not find “fp”. How can I fix it?
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class VisitorManufacturerRequest {
@Nullable
@Schema(description = "Страница", nullable = true)
private Integer page;
@Nullable
@Schema(description = "Размер", nullable = true)
private Integer size;
@Nullable
@Schema(description = "Текст поиск по еде", nullable = true)
private String searchText;
@Nullable
@Schema(description = "Список id по foodPreference", nullable = true)
private List<UUID> foodPreferenceIds;
}
public VisitorItemPage getVisitorManufacture(VisitorManufacturerRequest request, String mobile) {
int page = 0;
int size = 10;
LogicalCondition filterCondition = new LogicalCondition(LogicalCondition.Type.AND);
List<Condition> conditionList = new ArrayList<>();
if (request.getPage() != null) page = request.getPage();
if (request.getSize() != null) size = request.getSize();
if (request.getSearchText() != null && !request.getSearchText().isEmpty()) {
conditionList.add(
PropertyCondition.contains("companyName", request.getSearchText()));
}
if (request.getFoodPreferenceIds() != null && !request.getFoodPreferenceIds().isEmpty()) {
conditionList.add(
PropertyCondition.inList("fp.id", request.getFoodPreferenceIds()));
}
filterCondition.setConditions(conditionList);
int offset = page * size;
boolean hasNext = false;
List<Visitor> visitorList = dataManagerUc.load(Visitor.class)
.query("select distinct v from Visitor v " +
"left join v.dishCards dc " +
"left join dc.foodPreferences fp " +
"where dc.status = :status " +
"and v.userType = :userType " +
"order by v.createdDate DESC")
.parameter("status", FoodPosterStatusEnum.PUBLISHED)
.parameter("userType", UserTypeEnum.MANUFACTURER)
.condition(filterCondition)
.firstResult(offset)
.maxResults(size)
.list();
// проверка на наличие след страницы
List<Visitor> nextPage = dataManagerUc.load(Visitor.class)
.query("select distinct v from Visitor v " +
"left join v.dishCards dc " +
"left join dc.foodPreferences fp " +
"where dc.status = :status " +
"and v.userType = :userType " +
"order by v.createdDate DESC")
.parameter("status", FoodPosterStatusEnum.PUBLISHED)
.parameter("userType", UserTypeEnum.MANUFACTURER)
.condition(filterCondition)
.firstResult(offset + size)
.maxResults(size)
.list();
if (!nextPage.isEmpty()) {
hasNext = true;
}
return VisitorItemPage.builder()
.hasNext(hasNext)
.page(page)
.size(size)
.content(
visitorList.stream()
.map(VisitorInfo::of)
.collect(Collectors.toList()))
.build();
}