надо сделать отображение компонентов в заказе (componentIds in DTO)
This commit is contained in:
parent
e111e75e54
commit
c4810cda16
@ -5,7 +5,7 @@ import Favor from "../models/Favor";
|
||||
import Component from '../models/Component';
|
||||
import Order from '../models/Order';
|
||||
import DataService from '../services/DataService';
|
||||
|
||||
//import Multiselect from 'vue-multiselect'
|
||||
export default {
|
||||
mixins: [
|
||||
CatalogMixins
|
||||
@ -19,11 +19,15 @@ export default {
|
||||
{ name: 'favorName', label: 'name' },
|
||||
{ name: 'price', label: 'price' },
|
||||
],
|
||||
headersComps: [
|
||||
{ name: 'componentName', label: 'Компонент' }
|
||||
],
|
||||
selectedItemsComps: [],
|
||||
dataFilterUrl: 'favor/filter?',
|
||||
orderUrl: 'order/',
|
||||
orders: [],
|
||||
componentUrl: 'component/',
|
||||
components: []
|
||||
components: [],
|
||||
}
|
||||
},
|
||||
created() {
|
||||
@ -76,29 +80,23 @@ export default {
|
||||
this.componentId = null;
|
||||
this.orderId = null;
|
||||
},
|
||||
addOrderToFavor(favorId) {
|
||||
let orderId = document.getElementById('orders').value;
|
||||
let response = axios.post(`http://localhost:8080/api/favor/${favorId}/order?orderId=${orderId}`);
|
||||
addComponentToFavor(favorId) {
|
||||
let componentId = document.getElementById('components').value;
|
||||
let response = axios.post(`http://localhost:8080/api/favor/${favorId}/component?compId=${componentId}`);
|
||||
},
|
||||
itemsComps(favors) {
|
||||
if (typeof favors === 'undefined') {
|
||||
itemsComps(componentIds) {
|
||||
let result = [];
|
||||
if (typeof componentIds === 'undefined') {
|
||||
return;
|
||||
}
|
||||
favors.forEach(favor => {
|
||||
this.components.forEach(component => {
|
||||
if (favor.componentId === component.id) {
|
||||
favor.component = component;
|
||||
this.components.forEach(component => {
|
||||
for (let i = 0; i < componentIds.length; i++) {
|
||||
if (component.id === componentIds[i]) {
|
||||
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">
|
||||
<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 class="form-select" id="orderFilterSelect" v-model="orderId">
|
||||
@ -132,7 +130,7 @@ export default {
|
||||
</ToolBar>
|
||||
<DataTable
|
||||
:headers="this.headers"
|
||||
:items="itemsComps(this.items)"
|
||||
:items="this.items"
|
||||
:selectedItems="this.selectedItems"
|
||||
@dblclick="showEditModalDblClick">
|
||||
</DataTable>
|
||||
@ -142,24 +140,31 @@ export default {
|
||||
v-model:visible="this.modalShow"
|
||||
@done="saveItem">
|
||||
<div class="mb-3">
|
||||
<label for="model" class="form-label">Модель</label>
|
||||
<input type="text" class="form-control" id="model" required v-model="data.modelName">
|
||||
<label for="number" class="form-label">Номер кабинета</label>
|
||||
<input type="text" class="form-control" id="number" required v-model="data.number">
|
||||
</div>
|
||||
<DataTable
|
||||
:headers="this.headersComps"
|
||||
:items="itemsComps(data.componentIds)"
|
||||
:selectedItems="this.selectedItemsComps">
|
||||
</DataTable>
|
||||
<div class="mb-3">
|
||||
<label for="serialNum" class="form-label">Серийный номер</label>
|
||||
<input type="text" class="form-control" id="serialNum" required v-model="data.serialNum">
|
||||
</div>
|
||||
<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>
|
||||
<label for="computers" class="form-label">Добавить компьютер</label>
|
||||
<select class="form-select" id="computers" required>
|
||||
<option disabled value="">Выберите компьютер</option>
|
||||
<option v-for="component in this.components"
|
||||
:value="component.id"
|
||||
:selected="data.componentId && component.id === data.componentId">
|
||||
{{ component.modelName }}
|
||||
:value="component.id">
|
||||
{{ component.componentName }}
|
||||
</option>
|
||||
</select>
|
||||
</div>
|
||||
<button class="btn btn-outline-secondary" type="button" id="addComputerButton"
|
||||
@click.prevent="addComponentToFavor(data.id)">Добавить</button>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<!-- <div class="mb-3">
|
||||
<label for="order" class="form-label">Номер кабинета</label>
|
||||
<select class="form-select" id="order" v-model="data.orderId">
|
||||
|
@ -13,7 +13,7 @@ export default {
|
||||
<div class="container-fluid">
|
||||
<a class="navbar-brand" href="/">
|
||||
<i class="fa-solid fa-book"></i>
|
||||
Рабочее место оператора пункта выдачи заказов
|
||||
Service
|
||||
</a>
|
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav"
|
||||
aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
|
||||
|
@ -2,9 +2,11 @@ package ru.ulstu.is.sbapp.repair.controller;
|
||||
|
||||
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.service.FavorService;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@ -15,8 +17,8 @@ public class FavorController {
|
||||
this.favorService = favorService;
|
||||
}
|
||||
@PostMapping
|
||||
public FavorDTO addFavor(@RequestParam("name") String name, @RequestParam("price") Integer price) {
|
||||
return new FavorDTO(favorService.addFavor(name, price));
|
||||
public FavorDTO addFavor(@RequestBody @Valid FavorDTO favorDTO) {
|
||||
return new FavorDTO(favorService.addFavor(favorDTO.getFavorName(), favorDTO.getPrice()));
|
||||
}
|
||||
|
||||
@PutMapping("/{id}")
|
||||
|
@ -6,15 +6,15 @@ import java.util.List;
|
||||
|
||||
public class FavorDTO {
|
||||
private long id;
|
||||
private String FavorName;
|
||||
private Integer Price;
|
||||
private String favorName;
|
||||
private Integer price;
|
||||
private List<ComponentDTO> componentsDTOList;
|
||||
private List<OrderDTO> ordersDTOList;
|
||||
|
||||
public FavorDTO(Favor favor){
|
||||
this.id =favor.getId();
|
||||
this.FavorName = favor.getFavorName();
|
||||
this.Price = favor.getPrice();
|
||||
this.favorName = favor.getFavorName();
|
||||
this.price = favor.getPrice();
|
||||
this.componentsDTOList = favor.getComponents() == null ? null: favor.getComponents()
|
||||
.stream()
|
||||
.filter(x -> x.getFavors().contains(favor.getId()))
|
||||
@ -33,10 +33,10 @@ public class FavorDTO {
|
||||
return id;
|
||||
}
|
||||
public String getFavorName(){
|
||||
return FavorName;
|
||||
return favorName;
|
||||
}
|
||||
public Integer getPrice(){
|
||||
return Price;
|
||||
return price;
|
||||
}
|
||||
public List<ComponentDTO> getComponentsDTOList() {
|
||||
return componentsDTOList;
|
||||
|
@ -8,8 +8,8 @@ import ru.ulstu.is.sbapp.repair.model.Component;
|
||||
import java.util.List;
|
||||
|
||||
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,
|
||||
@Param("componentName") String componentName,
|
||||
@Param("amount") String amount );
|
||||
@Param("amount") Integer amount );
|
||||
}
|
||||
|
@ -35,8 +35,14 @@ public class ComponentService {
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public List<Component> findFilteredComponents(Long id, String componentName, String amount) {
|
||||
|
||||
return componentRepository.findFilteredComponents(id, componentName, amount);
|
||||
int a;
|
||||
try {
|
||||
a = Integer.parseInt(amount);
|
||||
}
|
||||
catch (Exception exception){
|
||||
a = 0;
|
||||
}
|
||||
return componentRepository.findFilteredComponents(id, componentName, a);
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
|
Loading…
Reference in New Issue
Block a user