фильтрация услуги по обычным полям

This commit is contained in:
VictoriaPresnyakova 2023-05-11 18:08:00 +04:00
parent 03f6fe2f9d
commit 4bfe12eb0f
4 changed files with 51 additions and 10 deletions

View File

@ -43,17 +43,17 @@ export default {
methods: {
filter() {
let urlParams = ""
if (document.getElementById('modelNameFilterInput').value != "") {
if (document.getElementById('favorNameFilterInput').value != "") {
if (urlParams != "") {
urlParams += "&";
}
urlParams += "modelName=" + this.modelName;
urlParams += "favorName=" + this.favorName;
}
if (document.getElementById('serialNumberFilterInput').value != "") {
if (document.getElementById('priceFilterInput').value != "") {
if (urlParams != "") {
urlParams += "&";
}
urlParams += "serialNum=" + this.serialNumber;
urlParams += "price=" + this.price;
}
if (document.getElementById('componentFilterSelect').value != "") {
if (urlParams != "") {
@ -75,8 +75,8 @@ export default {
clearFilters() {
this.loadItems();
this.id = null;
this.modelName = null;
this.serialNumber = null;
this.favorName = null;
this.price = null;
this.componentId = null;
this.orderId = null;
},
@ -106,17 +106,17 @@ export default {
<template>
<div class="input-group mb-3">
<input type="text" class="form-control" id="modelNameFilterInput" placeholder="Модель" required v-model="modelName">
<input type="text" class="form-control" id="favorNameFilterInput" placeholder="Услуга" required v-model="favorName">
<input type="text" class="form-control" id="serialNumberFilterInput" placeholder="Серийный номер" required v-model="serialNumber">
<input type="number" class="form-control" id="priceFilterInput" placeholder="Цена" required v-model="price">
<select class="form-select" id="componentFilterSelect" v-model="componentId">
<option disabled value="" selected>Выберите монитор</option>
<option disabled value="" selected>Выберите услугу</option>
<option v-for="component in components" :value="component.id">{{ component.componentName}}</option>
</select>
<select class="form-select" id="orderFilterSelect" v-model="orderId">
<option disabled value="" selected>Выберите номер кабинета</option>
<option disabled value="" selected>Выберите номер заказа</option>
<option v-for="order in orders" :value="order.id">{{ order.number }}</option>
</select>

View File

@ -52,4 +52,16 @@ public class FavorController {
.map(FavorDTO::new)
.toList();
}
@GetMapping("/filter")
public List<FavorDTO> getFilteredFavors(@RequestParam(value = "id", required = false) Long id,
@RequestParam(value = "favorName", required = false) String favorName,
@RequestParam(value = "price", required = false) String price,
@RequestParam(value = "componentId", required = false) Long componentId,
@RequestParam(value = "orderId", required = false) Long orderId) {
return favorService.findFilteredFavors(id, favorName, price, componentId, orderId).stream()
.map(FavorDTO::new)
.toList();
}
}

View File

@ -1,7 +1,22 @@
package ru.ulstu.is.sbapp.repair.repository;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import ru.ulstu.is.sbapp.repair.model.Favor;
import java.util.List;
public interface FavorRepository extends JpaRepository<Favor, Long> {
@Query(value = "select s from Favor s where (s.id = :id or :id is Null) and (s.favorName = :favorName or :favorName is Null) and (s.price = :price or :price = 0)")
public List<Favor> findFilteredFavors(@Param("id") Long id,
@Param("favorName") String favorName,
@Param("price") int price);
}

View File

@ -9,6 +9,7 @@ import ru.ulstu.is.sbapp.repair.model.Favor;
import ru.ulstu.is.sbapp.repair.repository.FavorRepository;
import ru.ulstu.is.sbapp.repair.util.validation.ValidatorUtil;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
@ -71,4 +72,17 @@ public class FavorService {
favorRepository.deleteAll();
}
@Transactional(readOnly = true)
public List<Favor> findFilteredFavors(Long id, String favorName, String price, Long componentId, Long orderId) {
int a;
try {
a = Integer.parseInt(price);
}
catch (Exception exception){
a = 0;
}
return favorRepository.findFilteredFavors(id, favorName, a);
// return new ArrayList<>();
}
}