надо сделать отображение компонентов в заказе (componentIds in DTO)

This commit is contained in:
VictoriaPresnyakova 2023-05-10 20:04:22 +04:00
parent e111e75e54
commit c4810cda16
6 changed files with 60 additions and 47 deletions

View File

@ -5,7 +5,7 @@ import Favor from "../models/Favor";
import Component from '../models/Component'; import Component from '../models/Component';
import Order from '../models/Order'; import Order from '../models/Order';
import DataService from '../services/DataService'; import DataService from '../services/DataService';
//import Multiselect from 'vue-multiselect'
export default { export default {
mixins: [ mixins: [
CatalogMixins CatalogMixins
@ -19,11 +19,15 @@ export default {
{ name: 'favorName', label: 'name' }, { name: 'favorName', label: 'name' },
{ name: 'price', label: 'price' }, { name: 'price', label: 'price' },
], ],
headersComps: [
{ name: 'componentName', label: 'Компонент' }
],
selectedItemsComps: [],
dataFilterUrl: 'favor/filter?', dataFilterUrl: 'favor/filter?',
orderUrl: 'order/', orderUrl: 'order/',
orders: [], orders: [],
componentUrl: 'component/', componentUrl: 'component/',
components: [] components: [],
} }
}, },
created() { created() {
@ -76,29 +80,23 @@ export default {
this.componentId = null; this.componentId = null;
this.orderId = null; this.orderId = null;
}, },
addOrderToFavor(favorId) { addComponentToFavor(favorId) {
let orderId = document.getElementById('orders').value; let componentId = document.getElementById('components').value;
let response = axios.post(`http://localhost:8080/api/favor/${favorId}/order?orderId=${orderId}`); let response = axios.post(`http://localhost:8080/api/favor/${favorId}/component?compId=${componentId}`);
}, },
itemsComps(favors) { itemsComps(componentIds) {
if (typeof favors === 'undefined') { let result = [];
if (typeof componentIds === 'undefined') {
return; return;
} }
favors.forEach(favor => { this.components.forEach(component => {
this.components.forEach(component => { for (let i = 0; i < componentIds.length; i++) {
if (favor.componentId === component.id) { if (component.id === componentIds[i]) {
favor.component = component; result.push(component);
} }
}); }
this.orders.forEach(order => {
order.favorIds.forEach(favorId => {
if (favor.id === favorId) {
favor.order = order;
}
});
});
}); });
return favors; return result;
} }
} }
} }
@ -112,7 +110,7 @@ export default {
<select class="form-select" id="componentFilterSelect" v-model="componentId"> <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.modelName }}</option> <option v-for="component in components" :value="component.id">{{ component.componentName}}</option>
</select> </select>
<select class="form-select" id="orderFilterSelect" v-model="orderId"> <select class="form-select" id="orderFilterSelect" v-model="orderId">
@ -132,7 +130,7 @@ export default {
</ToolBar> </ToolBar>
<DataTable <DataTable
:headers="this.headers" :headers="this.headers"
:items="itemsComps(this.items)" :items="this.items"
:selectedItems="this.selectedItems" :selectedItems="this.selectedItems"
@dblclick="showEditModalDblClick"> @dblclick="showEditModalDblClick">
</DataTable> </DataTable>
@ -142,24 +140,31 @@ export default {
v-model:visible="this.modalShow" v-model:visible="this.modalShow"
@done="saveItem"> @done="saveItem">
<div class="mb-3"> <div class="mb-3">
<label for="model" class="form-label">Модель</label> <label for="number" class="form-label">Номер кабинета</label>
<input type="text" class="form-control" id="model" required v-model="data.modelName"> <input type="text" class="form-control" id="number" required v-model="data.number">
</div> </div>
<DataTable
:headers="this.headersComps"
:items="itemsComps(data.componentIds)"
:selectedItems="this.selectedItemsComps">
</DataTable>
<div class="mb-3"> <div class="mb-3">
<label for="serialNum" class="form-label">Серийный номер</label> <label for="computers" class="form-label">Добавить компьютер</label>
<input type="text" class="form-control" id="serialNum" required v-model="data.serialNum"> <select class="form-select" id="computers" required>
</div> <option disabled value="">Выберите компьютер</option>
<div class="mb-3">
<label for="component" class="form-label">Монитор</label>
<select class="form-select" id="component" v-model="data.componentId">
<option disabled value="">Выберите монитор</option>
<option v-for="component in this.components" <option v-for="component in this.components"
:value="component.id" :value="component.id">
:selected="data.componentId && component.id === data.componentId"> {{ component.componentName }}
{{ component.modelName }}
</option> </option>
</select> </select>
</div> </div>
<button class="btn btn-outline-secondary" type="button" id="addComputerButton"
@click.prevent="addComponentToFavor(data.id)">Добавить</button>
<!-- <div class="mb-3"> <!-- <div class="mb-3">
<label for="order" class="form-label">Номер кабинета</label> <label for="order" class="form-label">Номер кабинета</label>
<select class="form-select" id="order" v-model="data.orderId"> <select class="form-select" id="order" v-model="data.orderId">

View File

@ -13,7 +13,7 @@ export default {
<div class="container-fluid"> <div class="container-fluid">
<a class="navbar-brand" href="/"> <a class="navbar-brand" href="/">
<i class="fa-solid fa-book"></i> <i class="fa-solid fa-book"></i>
Рабочее место оператора пункта выдачи заказов Service
</a> </a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav"
aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation"> aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">

View File

@ -2,9 +2,11 @@ package ru.ulstu.is.sbapp.repair.controller;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import ru.ulstu.is.sbapp.repair.dtos.ComponentDTO;
import ru.ulstu.is.sbapp.repair.dtos.FavorDTO; import ru.ulstu.is.sbapp.repair.dtos.FavorDTO;
import ru.ulstu.is.sbapp.repair.service.FavorService; import ru.ulstu.is.sbapp.repair.service.FavorService;
import javax.validation.Valid;
import java.util.List; import java.util.List;
@RestController @RestController
@ -15,8 +17,8 @@ public class FavorController {
this.favorService = favorService; this.favorService = favorService;
} }
@PostMapping @PostMapping
public FavorDTO addFavor(@RequestParam("name") String name, @RequestParam("price") Integer price) { public FavorDTO addFavor(@RequestBody @Valid FavorDTO favorDTO) {
return new FavorDTO(favorService.addFavor(name, price)); return new FavorDTO(favorService.addFavor(favorDTO.getFavorName(), favorDTO.getPrice()));
} }
@PutMapping("/{id}") @PutMapping("/{id}")

View File

@ -6,15 +6,15 @@ import java.util.List;
public class FavorDTO { public class FavorDTO {
private long id; private long id;
private String FavorName; private String favorName;
private Integer Price; private Integer price;
private List<ComponentDTO> componentsDTOList; private List<ComponentDTO> componentsDTOList;
private List<OrderDTO> ordersDTOList; private List<OrderDTO> ordersDTOList;
public FavorDTO(Favor favor){ public FavorDTO(Favor favor){
this.id =favor.getId(); this.id =favor.getId();
this.FavorName = favor.getFavorName(); this.favorName = favor.getFavorName();
this.Price = favor.getPrice(); this.price = favor.getPrice();
this.componentsDTOList = favor.getComponents() == null ? null: favor.getComponents() this.componentsDTOList = favor.getComponents() == null ? null: favor.getComponents()
.stream() .stream()
.filter(x -> x.getFavors().contains(favor.getId())) .filter(x -> x.getFavors().contains(favor.getId()))
@ -33,10 +33,10 @@ public class FavorDTO {
return id; return id;
} }
public String getFavorName(){ public String getFavorName(){
return FavorName; return favorName;
} }
public Integer getPrice(){ public Integer getPrice(){
return Price; return price;
} }
public List<ComponentDTO> getComponentsDTOList() { public List<ComponentDTO> getComponentsDTOList() {
return componentsDTOList; return componentsDTOList;

View File

@ -8,8 +8,8 @@ import ru.ulstu.is.sbapp.repair.model.Component;
import java.util.List; import java.util.List;
public interface ComponentRepository extends JpaRepository<Component, Long> { public interface ComponentRepository extends JpaRepository<Component, Long> {
@Query(value = "select s from Component s where (s.id = :id or :id is Null) and (s.amount = :amount or :amount is Null) and (s.componentName = :componentName or :componentName is Null)") @Query(value = "select s from Component s where (s.id = :id or :id is Null) and (s.amount = :amount or :amount = 0) and (s.componentName = :componentName or :componentName is Null)")
public List<Component> findFilteredComponents(@Param("id") Long id, public List<Component> findFilteredComponents(@Param("id") Long id,
@Param("componentName") String componentName, @Param("componentName") String componentName,
@Param("amount") String amount ); @Param("amount") Integer amount );
} }

View File

@ -35,8 +35,14 @@ public class ComponentService {
@Transactional(readOnly = true) @Transactional(readOnly = true)
public List<Component> findFilteredComponents(Long id, String componentName, String amount) { public List<Component> findFilteredComponents(Long id, String componentName, String amount) {
int a;
return componentRepository.findFilteredComponents(id, componentName, amount); try {
a = Integer.parseInt(amount);
}
catch (Exception exception){
a = 0;
}
return componentRepository.findFilteredComponents(id, componentName, a);
} }
@Transactional(readOnly = true) @Transactional(readOnly = true)