final
This commit is contained in:
parent
5c09ff94f8
commit
1faa719f92
176
frontend/src/components/Computers.vue
Normal file
176
frontend/src/components/Computers.vue
Normal file
@ -0,0 +1,176 @@
|
||||
<script>
|
||||
import axios from 'axios';
|
||||
import CatalogMixins from '../mixins/CatalogMixins.js';
|
||||
import Cabinet from "../models/Cabinet";
|
||||
import Computer from '../models/Computer';
|
||||
import Monitor from '../models/Monitor';
|
||||
import DataService from '../services/DataService';
|
||||
|
||||
export default {
|
||||
mixins: [
|
||||
CatalogMixins
|
||||
],
|
||||
data() {
|
||||
return {
|
||||
getAllUrl: 'computer/',
|
||||
dataUrl: 'computer',
|
||||
transformer: (data) => new Computer(data),
|
||||
headers: [
|
||||
{ name: 'modelName', label: 'Модель' },
|
||||
{ name: 'serialNum', label: 'Серийный номер' },
|
||||
{ name: 'monitorName', label: 'Модель монитора' },
|
||||
{ name: 'cabinetNum', label: 'Номер кабинета' }
|
||||
],
|
||||
dataFilterUrl: 'computer/filter?',
|
||||
cabinetUrl: 'cabinet/',
|
||||
cabinets: [],
|
||||
monitorUrl: 'monitor/',
|
||||
monitors: []
|
||||
}
|
||||
},
|
||||
created() {
|
||||
DataService.readAll(this.cabinetUrl, (data) => new Cabinet(data))
|
||||
.then(data => {
|
||||
this.cabinets = data;
|
||||
});
|
||||
DataService.readAll(this.monitorUrl, (data) => new Monitor(data))
|
||||
.then(data => {
|
||||
this.monitors = data;
|
||||
});
|
||||
},
|
||||
methods: {
|
||||
filter() {
|
||||
let urlParams = ""
|
||||
if (document.getElementById('modelNameFilterInput').value != "") {
|
||||
if (urlParams != "") {
|
||||
urlParams += "&";
|
||||
}
|
||||
urlParams += "modelName=" + this.modelName;
|
||||
}
|
||||
if (document.getElementById('serialNumberFilterInput').value != "") {
|
||||
if (urlParams != "") {
|
||||
urlParams += "&";
|
||||
}
|
||||
urlParams += "serialNum=" + this.serialNumber;
|
||||
}
|
||||
if (document.getElementById('monitorFilterSelect').value != "") {
|
||||
if (urlParams != "") {
|
||||
urlParams += "&";
|
||||
}
|
||||
urlParams += "monitorId=" + this.monitorId;
|
||||
}
|
||||
if (document.getElementById('cabinetFilterSelect').value != "") {
|
||||
if (urlParams != "") {
|
||||
urlParams += "&";
|
||||
}
|
||||
urlParams += "cabinetId=" + this.cabinetId;
|
||||
}
|
||||
DataService.readAll(this.dataFilterUrl + urlParams, (data) => new Computer(data))
|
||||
.then(data => {
|
||||
this.items = data;
|
||||
});
|
||||
},
|
||||
clearFilters() {
|
||||
this.loadItems();
|
||||
this.id = null;
|
||||
this.modelName = null;
|
||||
this.serialNumber = null;
|
||||
this.monitorId = null;
|
||||
this.cabinetId = null;
|
||||
},
|
||||
addCabinetToComputer(computerId) {
|
||||
let cabinetId = document.getElementById('cabinets').value;
|
||||
let response = axios.post(`http://localhost:8080/api/computer/${computerId}/cabinet?cabinetId=${cabinetId}`);
|
||||
console.log(response);
|
||||
},
|
||||
itemsComps(computers) {
|
||||
if (typeof computers === 'undefined') {
|
||||
return;
|
||||
}
|
||||
computers.forEach(computer => {
|
||||
this.monitors.forEach(monitor => {
|
||||
if (computer.monitorId === monitor.id) {
|
||||
computer.monitor = monitor;
|
||||
}
|
||||
});
|
||||
this.cabinets.forEach(cabinet => {
|
||||
if (computer.cabinetId === cabinet.id) {
|
||||
computer.cabinet = cabinet;
|
||||
}
|
||||
});
|
||||
});
|
||||
return computers;
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<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="serialNumberFilterInput" placeholder="Серийный номер" required v-model="serialNumber">
|
||||
|
||||
<select class="form-select" id="monitorFilterSelect" v-model="monitorId">
|
||||
<option disabled value="" selected>Выберите монитор</option>
|
||||
<option v-for="monitor in monitors" :value="monitor.id">{{ monitor.modelName }}</option>
|
||||
</select>
|
||||
|
||||
<select class="form-select" id="cabinetFilterSelect" v-model="cabinetId">
|
||||
<option disabled value="" selected>Выберите номер кабинета</option>
|
||||
<option v-for="cabinet in cabinets" :value="cabinet.id">{{ cabinet.number }}</option>
|
||||
</select>
|
||||
|
||||
<button class="btn btn-primary" type="button" id="report-button"
|
||||
@click.prevent="filter">Сформировать</button>
|
||||
<button class="btn btn-outline-secondary" type="button" id="report-button"
|
||||
@click.prevent="clearFilters">Очистить</button>
|
||||
</div>
|
||||
<ToolBar
|
||||
@add="showAddModal"
|
||||
@edit="showEditModal"
|
||||
@remove="removeSelectedItems">
|
||||
</ToolBar>
|
||||
<DataTable
|
||||
:headers="this.headers"
|
||||
:items="itemsComps(this.items)"
|
||||
:selectedItems="this.selectedItems"
|
||||
@dblclick="showEditModalDblClick">
|
||||
</DataTable>
|
||||
<Modal
|
||||
:header="this.modal.header"
|
||||
:confirm="this.modal.confirm"
|
||||
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">
|
||||
</div>
|
||||
<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="monitor" class="form-label">Монитор</label>
|
||||
<select class="form-select" id="monitor" v-model="data.monitorId">
|
||||
<option disabled value="">Выберите монитор</option>
|
||||
<option v-for="monitor in this.monitors"
|
||||
:value="monitor.id"
|
||||
:selected="data.monitorId && monitor.id === data.monitorId">
|
||||
{{ monitor.modelName }}
|
||||
</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="cabinet" class="form-label">Номер кабинета</label>
|
||||
<select class="form-select" id="cabinet" v-model="data.cabinetId">
|
||||
<option disabled value="">Выберите номер кабинета</option>
|
||||
<option v-for="cabinet in this.cabinets"
|
||||
:value="cabinet.id"
|
||||
:selected="data.cabinetId && cabinet.id === data.cabinetId">
|
||||
{{ cabinet.number }}
|
||||
</option>
|
||||
</select>
|
||||
</div>
|
||||
</Modal>
|
||||
</template>
|
@ -57,7 +57,11 @@
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.modal-show {
|
||||
display: block;
|
||||
}
|
||||
</style>
|
||||
.modal-show {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.modal-content {
|
||||
width: max-content;
|
||||
}
|
||||
</style>
|
71
frontend/src/components/Monitors.vue
Normal file
71
frontend/src/components/Monitors.vue
Normal file
@ -0,0 +1,71 @@
|
||||
<script>
|
||||
import axios from 'axios';
|
||||
import CatalogMixins from '../mixins/CatalogMixins.js';
|
||||
import Monitor from '../models/Monitor';
|
||||
import DataService from '../services/DataService';
|
||||
|
||||
export default {
|
||||
mixins: [
|
||||
CatalogMixins
|
||||
],
|
||||
data() {
|
||||
return {
|
||||
getAllUrl: 'monitor/',
|
||||
dataUrl: 'monitor',
|
||||
transformer: (data) => new Monitor(data),
|
||||
headers: [
|
||||
{ name: 'modelName', label: 'Модель' }
|
||||
],
|
||||
dataFilterUrl: 'monitor/filter?'
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
filter() {
|
||||
let urlParams = ""
|
||||
if (document.getElementById('modelNameFilterInput').value != "") {
|
||||
urlParams += "modelName=" + this.modelName;
|
||||
}
|
||||
DataService.readAll(this.dataFilterUrl + urlParams, (data) => new Monitor(data))
|
||||
.then(data => {
|
||||
this.items = data;
|
||||
});
|
||||
},
|
||||
clearFilters() {
|
||||
this.loadItems();
|
||||
this.id = null;
|
||||
this.modelName = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="input-group mb-3">
|
||||
<input type="text" class="form-control" id="modelNameFilterInput" placeholder="Модель" required v-model="modelName">
|
||||
<button class="btn btn-primary" type="button" id="report-button"
|
||||
@click.prevent="filter">Сформировать</button>
|
||||
<button class="btn btn-outline-secondary" type="button" id="report-button"
|
||||
@click.prevent="clearFilters">Очистить</button>
|
||||
</div>
|
||||
<ToolBar
|
||||
@add="showAddModal"
|
||||
@edit="showEditModal"
|
||||
@remove="removeSelectedItems">
|
||||
</ToolBar>
|
||||
<DataTable
|
||||
:headers="this.headers"
|
||||
:items="this.items"
|
||||
:selectedItems="this.selectedItems"
|
||||
@dblclick="showEditModalDblClick">
|
||||
</DataTable>
|
||||
<Modal
|
||||
:header="this.modal.header"
|
||||
:confirm="this.modal.confirm"
|
||||
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">
|
||||
</div>
|
||||
</Modal>
|
||||
</template>
|
@ -3,10 +3,14 @@ import { createRouter, createWebHistory } from 'vue-router'
|
||||
import './style.css'
|
||||
import App from './App.vue'
|
||||
import Cabinets from './components/Cabinets.vue'
|
||||
import Computers from './components/Computers.vue'
|
||||
import Monitors from './components/Monitors.vue'
|
||||
|
||||
const routes = [
|
||||
{ path: '/', redirect: '/cabinets' },
|
||||
{ path: '/cabinets', component: Cabinets, meta: { label: 'Кабинеты' }}
|
||||
{ path: '/cabinets', component: Cabinets, meta: { label: 'Кабинеты' } },
|
||||
{ path: '/computers', component: Computers, meta: { label: 'Компьютеры' } },
|
||||
{ path: '/monitors', component: Monitors, meta: { label: 'Мониторы' } }
|
||||
]
|
||||
|
||||
const router = createRouter({
|
||||
|
@ -63,7 +63,7 @@ const CatalogMixin = {
|
||||
},
|
||||
saveItem() {
|
||||
if (!this.isEdit) {
|
||||
DataService.create(this.dataUrl, this.data)
|
||||
DataService.create(this.dataUrl + "/", this.data)
|
||||
.then(() => {
|
||||
this.getItems();
|
||||
});
|
||||
|
@ -1,47 +0,0 @@
|
||||
export default class Car {
|
||||
constructor(data) {
|
||||
this._id = data?.id;
|
||||
this._gosNumber = data?.gosNumber;
|
||||
this._vin = data?.vin;
|
||||
this._driver = data?.driver;
|
||||
this._driverId = data?.driver.id;
|
||||
}
|
||||
|
||||
get id() {
|
||||
return this._id;
|
||||
}
|
||||
|
||||
get gosNumber() {
|
||||
return this._gosNumber;
|
||||
}
|
||||
|
||||
set gosNumber(value) {
|
||||
if (typeof value !== 'string' || value === null || value.length == 0) {
|
||||
throw 'New gos number value ' + value + ' is not a string or empty';
|
||||
}
|
||||
this._gosNumber = value;
|
||||
}
|
||||
|
||||
get vin() {
|
||||
return this._vin;
|
||||
}
|
||||
|
||||
set vin(value) {
|
||||
if (typeof value !== 'string' || value === null || value.length == 0) {
|
||||
throw 'New vin value ' + value + ' is not a string or empty';
|
||||
}
|
||||
this._vin = value;
|
||||
}
|
||||
|
||||
get driverId() {
|
||||
return this._driverId;
|
||||
}
|
||||
|
||||
set driverId(value) {
|
||||
this._driverId = value;
|
||||
}
|
||||
|
||||
get driverName() {
|
||||
return this.driver?.name;
|
||||
}
|
||||
}
|
@ -1,45 +0,0 @@
|
||||
export default class Student {
|
||||
constructor(data) {
|
||||
this._id = data?.id;
|
||||
this._name = data?.name;
|
||||
this._phone = data?.phone;
|
||||
this._email = data?.email;
|
||||
}
|
||||
|
||||
get id() {
|
||||
return this._id;
|
||||
}
|
||||
|
||||
get name() {
|
||||
return this._name;
|
||||
}
|
||||
|
||||
set name(value) {
|
||||
if (typeof value !== 'string' || value === null || value.length == 0) {
|
||||
throw 'New name value ' + value + ' is not a string or empty';
|
||||
}
|
||||
this._name = value;
|
||||
}
|
||||
|
||||
get phone() {
|
||||
return this._phone;
|
||||
}
|
||||
|
||||
set phone(value) {
|
||||
if (typeof value !== 'string' || value === null || value.length == 0) {
|
||||
throw 'New phone value ' + value + ' is not a string or empty';
|
||||
}
|
||||
this._phone = value;
|
||||
}
|
||||
|
||||
get email() {
|
||||
return this._email;
|
||||
}
|
||||
|
||||
set email(value) {
|
||||
if (typeof value !== 'string' || value === null || value.length == 0) {
|
||||
throw 'New email value ' + value + ' is not a string or empty';
|
||||
}
|
||||
this._email = value;
|
||||
}
|
||||
}
|
@ -57,7 +57,15 @@ export default class Computer {
|
||||
this._cabinetId = value;
|
||||
}
|
||||
|
||||
get cabinetNumber() {
|
||||
return this._cabinet?.numer;
|
||||
get cabinet() {
|
||||
return this._cabinet;
|
||||
}
|
||||
|
||||
set cabinet(data) {
|
||||
this._cabinet = data;
|
||||
}
|
||||
|
||||
get cabinetNum() {
|
||||
return this._cabinet?.number;
|
||||
}
|
||||
}
|
@ -1,54 +0,0 @@
|
||||
export default class Driver {
|
||||
constructor(data) {
|
||||
this._id = data?.id;
|
||||
this._name = data?.name;
|
||||
this._birthday = data?.birthday;
|
||||
this._phone = data?.phone;
|
||||
this._email = data?.email;
|
||||
}
|
||||
|
||||
get id() {
|
||||
return this._id;
|
||||
}
|
||||
|
||||
get name() {
|
||||
return this._name;
|
||||
}
|
||||
|
||||
set name(value) {
|
||||
if (typeof value !== 'string' || value === null || value.length == 0) {
|
||||
throw 'New name value ' + value + ' is not a string or empty';
|
||||
}
|
||||
this._name = value;
|
||||
}
|
||||
|
||||
get birthday() {
|
||||
return this._age;
|
||||
}
|
||||
|
||||
set birthday(value) {
|
||||
this._birthday = value;
|
||||
}
|
||||
|
||||
get phone() {
|
||||
return this._phone;
|
||||
}
|
||||
|
||||
set phone(value) {
|
||||
if (typeof value !== 'string' || value === null || value.length == 0) {
|
||||
throw 'New phone value ' + value + ' is not a string or empty';
|
||||
}
|
||||
this._phone = value;
|
||||
}
|
||||
|
||||
get email() {
|
||||
return this._email;
|
||||
}
|
||||
|
||||
set email(value) {
|
||||
if (typeof value !== 'string' || value === null || value.length == 0) {
|
||||
throw 'New email value ' + value + ' is not a string or empty';
|
||||
}
|
||||
this._email = value;
|
||||
}
|
||||
}
|
@ -1,92 +0,0 @@
|
||||
export default class Order {
|
||||
constructor(data) {
|
||||
this._id = data?.id;
|
||||
this._value = data?.value;
|
||||
this._status = data?.status;
|
||||
this._date = data?.date.split('T')[0];
|
||||
this._client = data?.client;
|
||||
this._clientId = data?.client.id;
|
||||
this._sourcePickUpPoint = data?.sourcePickUpPoint;
|
||||
this._sourcePickUpPointId = data?.sourcePickUpPoint.id;
|
||||
this._destPickUpPoint = data?.destPickUpPoint;
|
||||
this._destPickUpPointId = data?.destPickUpPoint?.id;
|
||||
this._car = data?.car;
|
||||
this._carId = data?.car.id;
|
||||
}
|
||||
|
||||
get id() {
|
||||
return this._id;
|
||||
}
|
||||
|
||||
get value() {
|
||||
return this._value;
|
||||
}
|
||||
|
||||
set value(data) {
|
||||
this._value = data;
|
||||
}
|
||||
|
||||
get status() {
|
||||
return this._status;
|
||||
}
|
||||
|
||||
set status(data) {
|
||||
this._status = data;
|
||||
}
|
||||
|
||||
get date() {
|
||||
return this._date;
|
||||
}
|
||||
|
||||
set date(data) {
|
||||
this._date = data;
|
||||
}
|
||||
|
||||
get clientId() {
|
||||
return this._clientId;
|
||||
}
|
||||
|
||||
set clientId(value) {
|
||||
this._clientId = value;
|
||||
}
|
||||
|
||||
get clientName() {
|
||||
return this._client?.name;
|
||||
}
|
||||
|
||||
get sourcePickUpPointId() {
|
||||
return this._sourcePickUpPointId;
|
||||
}
|
||||
|
||||
set sourcePickUpPointId(value) {
|
||||
this._sourcePickUpPointId = value;
|
||||
}
|
||||
|
||||
get sourcePickUpPointAddress() {
|
||||
return this._sourcePickUpPoint?.address;
|
||||
}
|
||||
|
||||
get destPickUpPointId() {
|
||||
return this._destPickUpPointId;
|
||||
}
|
||||
|
||||
set destPickUpPointId(value) {
|
||||
this._destPickUpPointId = value;
|
||||
}
|
||||
|
||||
get destPickUpPointAddress() {
|
||||
return this._destPickUpPoint?.address;
|
||||
}
|
||||
|
||||
get carId() {
|
||||
return this._carId;
|
||||
}
|
||||
|
||||
set carId(value) {
|
||||
this._carId = value;
|
||||
}
|
||||
|
||||
get carNumber() {
|
||||
return this._car?.gosNumber;
|
||||
}
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
export default class PickUpPoint {
|
||||
constructor(data) {
|
||||
this._id = data?.id;
|
||||
this._address = data?.address;
|
||||
}
|
||||
|
||||
get id() {
|
||||
return this._id;
|
||||
}
|
||||
|
||||
get address() {
|
||||
return this._address;
|
||||
}
|
||||
|
||||
set address(value) {
|
||||
if (typeof value !== 'string' || value === null || value.length == 0) {
|
||||
throw 'New address value ' + value + ' is not a string or empty';
|
||||
}
|
||||
this._address = value;
|
||||
}
|
||||
}
|
@ -28,6 +28,16 @@ public class ComputerController {
|
||||
.map(ComputerDto::new)
|
||||
.toList();
|
||||
}
|
||||
@GetMapping("/filter")
|
||||
public List<ComputerDto> getFilteredComputers(@RequestParam(value = "id", required = false) Long id,
|
||||
@RequestParam(value = "modelName", required = false) String modelName,
|
||||
@RequestParam(value = "serialNum", required = false) String serialNum,
|
||||
@RequestParam(value = "monitorId", required = false) Long monitorId,
|
||||
@RequestParam(value = "cabinetId", required = false) Long cabinetId) {
|
||||
return computerService.findFilteredComputers(id, modelName, serialNum, monitorId, cabinetId).stream()
|
||||
.map(ComputerDto::new)
|
||||
.toList();
|
||||
}
|
||||
@GetMapping("/{id}/computers")
|
||||
public CabinetDto getComputersCabinet(@PathVariable Long id) {
|
||||
return new CabinetDto(computerService.getCabinet(id));
|
||||
|
@ -17,7 +17,9 @@ import com.kalyshev.yan.computer.model.Computer;
|
||||
|
||||
import jakarta.persistence.EntityNotFoundException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
@Service
|
||||
@ -66,6 +68,33 @@ public class ComputerService {
|
||||
public List<Computer> findAllComputers() {
|
||||
return computerRepository.findAll();
|
||||
}
|
||||
@Transactional(readOnly = true)
|
||||
public List<Computer> findFilteredComputers(Long id, String modelName, String serialNum, Long monitorId, Long cabinetId) {
|
||||
List<Computer> allComputers = computerRepository.findAll();
|
||||
List<Computer> result = new ArrayList<>();
|
||||
for (Computer computer : allComputers) {
|
||||
boolean flag = true;
|
||||
if (id != null && !Objects.equals(computer.getId(), id)) {
|
||||
flag = false;
|
||||
}
|
||||
if (modelName != null && !Objects.equals(computer.getModelName(), modelName)) {
|
||||
flag = false;
|
||||
}
|
||||
if (serialNum != null && !Objects.equals(computer.getSerialNum(), serialNum)) {
|
||||
flag = false;
|
||||
}
|
||||
if (monitorId != null && computer.getMonitor() != null && !Objects.equals(computer.getMonitor().getId(), monitorId)) {
|
||||
flag = false;
|
||||
}
|
||||
if (cabinetId != null && computer.getCabinet() != null && !Objects.equals(computer.getCabinet().getId(), cabinetId)) {
|
||||
flag = false;
|
||||
}
|
||||
if (flag) {
|
||||
result.add(computer);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@Transactional
|
||||
public Computer updateComputer(Long id, String modelName, String serialNum, Long monitorId, Long cabinetId) {
|
||||
if (!(StringUtils.hasText(modelName) || StringUtils.hasText(serialNum))) {
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.kalyshev.yan.monitor.controller;
|
||||
|
||||
import com.kalyshev.yan.WebConfiguration;
|
||||
import com.kalyshev.yan.computer.controller.ComputerDto;
|
||||
import com.kalyshev.yan.monitor.model.Monitor;
|
||||
import com.kalyshev.yan.monitor.service.MonitorService;
|
||||
import jakarta.validation.Valid;
|
||||
@ -25,6 +26,13 @@ public class MonitorController {
|
||||
.map(MonitorDto::new)
|
||||
.toList();
|
||||
}
|
||||
@GetMapping("/filter")
|
||||
public List<MonitorDto> getFilteredmonitors(@RequestParam(value = "id", required = false) Long id,
|
||||
@RequestParam(value = "modelName", required = false) String modelName) {
|
||||
return monitorService.findFilteredMonitors(id, modelName).stream()
|
||||
.map(MonitorDto::new)
|
||||
.toList();
|
||||
}
|
||||
@PostMapping("/")
|
||||
public MonitorDto createMonitor(@RequestBody @Valid MonitorDto monitorDto) {
|
||||
return new MonitorDto(monitorService.addMonitor(monitorDto.getModelName()));
|
||||
|
@ -1,10 +1,11 @@
|
||||
package com.kalyshev.yan.monitor.service;
|
||||
package com.kalyshev.yan.monitor.service;
|
||||
|
||||
import com.kalyshev.yan.cabinet.model.Cabinet;
|
||||
import com.kalyshev.yan.cabinet.repository.CabinetNotFoundException;
|
||||
import com.kalyshev.yan.cabinet.repository.CabinetRepository;
|
||||
import com.kalyshev.yan.computer.model.Computer;
|
||||
import com.kalyshev.yan.computer.repository.ComputerRepository;
|
||||
import com.kalyshev.yan.monitor.controller.MonitorController;
|
||||
import com.kalyshev.yan.monitor.repository.MonitorNotFoundException;
|
||||
import com.kalyshev.yan.monitor.repository.MonitorRepository;
|
||||
import com.kalyshev.yan.util.validation.ValidatorUtil;
|
||||
@ -19,6 +20,8 @@ import com.kalyshev.yan.monitor.model.Monitor;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.EntityNotFoundException;
|
||||
import jakarta.persistence.PersistenceContext;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
@ -53,6 +56,24 @@ public class MonitorService {
|
||||
public List<Monitor> findAllMonitors() {
|
||||
return monitorRepository.findAll();
|
||||
}
|
||||
@Transactional(readOnly = true)
|
||||
public List<Monitor> findFilteredMonitors(Long id, String modelName) {
|
||||
List<Monitor> allMonitors = monitorRepository.findAll();
|
||||
List<Monitor> result = new ArrayList<>();
|
||||
for (Monitor monitor : allMonitors) {
|
||||
boolean flag = true;
|
||||
if (id != null && !Objects.equals(monitor.getId(), id)) {
|
||||
flag = false;
|
||||
}
|
||||
if (modelName != null && !Objects.equals(monitor.getModelName(), modelName)) {
|
||||
flag = false;
|
||||
}
|
||||
if (flag) {
|
||||
result.add(monitor);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@Transactional
|
||||
public Monitor updateMonitor(Long id, String modelName) {
|
||||
if (!StringUtils.hasText(modelName)) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user