From 2d00c781be5a68169f67669eba7f671d6d8c526b Mon Sep 17 00:00:00 2001 From: root Date: Sat, 22 Apr 2023 22:07:28 +0400 Subject: [PATCH] added main front page and filter for orders in back --- .../subd/Controllers/OrderController.java | 16 +- .../java/com/subd/subd/Dtos/OrderDto.java | 16 +- .../main/java/com/subd/subd/Models/Order.java | 13 +- .../com/subd/subd/Services/OrderService.java | 59 ++++- .../java/com/subd/subd/WebConfiguration.java | 13 + .../src/main/resources/application.properties | 4 +- SUBD-front/.vscode/launch.json | 12 + SUBD-front/main.js | 30 --- SUBD-front/package-lock.json | 19 +- .../src/components/CatalogDisciplines.vue | 44 ---- SUBD-front/src/components/CatalogGroups.vue | 44 ---- SUBD-front/src/components/CatalogStudents.vue | 82 ------ SUBD-front/src/components/Catalogs.vue | 6 +- SUBD-front/src/components/DataTable.vue | 17 +- SUBD-front/src/components/Header.vue | 2 +- SUBD-front/src/components/Orders.vue | 247 ++++++++++++++++++ .../src/components/ReportGroupDisciplines.vue | 60 ----- .../src/components/ReportGroupStudents.vue | 64 ----- SUBD-front/src/main.js | 27 ++ SUBD-front/src/mixins/CatalogMixins.js | 11 +- SUBD-front/src/models/Car.js | 4 +- SUBD-front/src/models/Order.js | 24 +- SUBD-front/{ => src}/style.css | 0 SUBD-front/vite.config.js | 5 +- 24 files changed, 458 insertions(+), 361 deletions(-) create mode 100644 SUBD-back/src/main/java/com/subd/subd/WebConfiguration.java create mode 100644 SUBD-front/.vscode/launch.json delete mode 100644 SUBD-front/main.js delete mode 100644 SUBD-front/src/components/CatalogDisciplines.vue delete mode 100644 SUBD-front/src/components/CatalogGroups.vue delete mode 100644 SUBD-front/src/components/CatalogStudents.vue create mode 100644 SUBD-front/src/components/Orders.vue delete mode 100644 SUBD-front/src/components/ReportGroupDisciplines.vue delete mode 100644 SUBD-front/src/components/ReportGroupStudents.vue create mode 100644 SUBD-front/src/main.js rename SUBD-front/{ => src}/style.css (100%) diff --git a/SUBD-back/src/main/java/com/subd/subd/Controllers/OrderController.java b/SUBD-back/src/main/java/com/subd/subd/Controllers/OrderController.java index ae044eb..1441183 100644 --- a/SUBD-back/src/main/java/com/subd/subd/Controllers/OrderController.java +++ b/SUBD-back/src/main/java/com/subd/subd/Controllers/OrderController.java @@ -5,6 +5,7 @@ import com.subd.subd.Models.Order; import com.subd.subd.Services.OrderService; import org.springframework.web.bind.annotation.*; +import java.util.Date; import java.util.List; @RestController @@ -21,13 +22,24 @@ public class OrderController { public List getOrders() { return OrderService.findAllOrders(); } + @GetMapping("/order/filter") + public List getFilteredOrders(@RequestParam(value = "id", required = false) Long id, + @RequestParam(value = "value", required = false) Double value, + @RequestParam(value = "status", required = false) String status, + @RequestParam(value = "date", required = false) Date date, + @RequestParam(value = "clientId", required = false) Long clientId, + @RequestParam(value = "sourcePickUpPointId", required = false) Long sourcePickUpPointId, + @RequestParam(value = "destPickUpPointId", required = false) Long destPickUpPointId, + @RequestParam(value = "carId", required = false) Long carId) { + return OrderService.findfilteredOrders(id, value, status, date, clientId, sourcePickUpPointId, destPickUpPointId, carId); + } @PostMapping("/order") public Order createOrder(@RequestBody OrderDto orderDto) { - return OrderService.addOrder(orderDto.getValue(), orderDto.getStatus(), orderDto.getClientId(), orderDto.getSourcePickUpPointId(), orderDto.getDestPickUpPointId(), orderDto.getCarId()); + return OrderService.addOrder(orderDto.getValue(), orderDto.getStatus(), orderDto.getDate(), orderDto.getClientId(), orderDto.getSourcePickUpPointId(), orderDto.getDestPickUpPointId(), orderDto.getCarId()); } @PutMapping("/order/{id}") public Order updateOrder(@PathVariable Long id, @RequestBody OrderDto orderDto) { - return OrderService.updateOrder(id, orderDto.getValue(), orderDto.getStatus(), orderDto.getClientId(), orderDto.getSourcePickUpPointId(), orderDto.getDestPickUpPointId(), orderDto.getCarId()); + return OrderService.updateOrder(id, orderDto.getValue(), orderDto.getStatus(), orderDto.getDate(), orderDto.getClientId(), orderDto.getSourcePickUpPointId(), orderDto.getDestPickUpPointId(), orderDto.getCarId()); } @DeleteMapping("/order/{id}") public Order deleteOrder(@PathVariable Long id) { diff --git a/SUBD-back/src/main/java/com/subd/subd/Dtos/OrderDto.java b/SUBD-back/src/main/java/com/subd/subd/Dtos/OrderDto.java index ebccfd3..03ce05b 100644 --- a/SUBD-back/src/main/java/com/subd/subd/Dtos/OrderDto.java +++ b/SUBD-back/src/main/java/com/subd/subd/Dtos/OrderDto.java @@ -1,16 +1,24 @@ package com.subd.subd.Dtos; +import com.subd.subd.Models.PickUpPoint; +import jakarta.annotation.Nullable; + +import java.util.Date; + public class OrderDto { private Double value; private String status; + private Date date; private Long clientId; private Long sourcePickUpPointId; + @Nullable private Long destPickUpPointId; private Long carId; public OrderDto() {} - public OrderDto(Double value, String status, Long clientId, Long sourcePickUpPointId, Long destPickUpPointId, Long carId) { + public OrderDto(Double value, String status, Date date, Long clientId, Long sourcePickUpPointId, @Nullable Long destPickUpPointId, Long carId) { this.value = value; this.status = status; + this.date = date; this.clientId = clientId; this.sourcePickUpPointId = sourcePickUpPointId; this.destPickUpPointId = destPickUpPointId; @@ -19,15 +27,19 @@ public class OrderDto { public Double getValue() { return this.value; } - public String getStatus() { + public String getStatus() { return this.status; } + public Date getDate() { + return this.date; + } public Long getClientId() { return this.clientId; } public Long getSourcePickUpPointId() { return this.sourcePickUpPointId; } + @Nullable public Long getDestPickUpPointId() { return this.destPickUpPointId; } diff --git a/SUBD-back/src/main/java/com/subd/subd/Models/Order.java b/SUBD-back/src/main/java/com/subd/subd/Models/Order.java index 65abd22..b903419 100644 --- a/SUBD-back/src/main/java/com/subd/subd/Models/Order.java +++ b/SUBD-back/src/main/java/com/subd/subd/Models/Order.java @@ -1,7 +1,9 @@ package com.subd.subd.Models; +import jakarta.annotation.Nullable; import jakarta.persistence.*; +import java.util.Date; import java.util.Objects; @Entity @@ -12,12 +14,14 @@ public class Order { private Long id; private Double value; private String status; + private Date date; @ManyToOne( cascade = {CascadeType.MERGE}, fetch = FetchType.EAGER) @JoinColumn(name = "Client_id", nullable = true) private Client client; @OneToOne() @JoinColumn(name = "sourcePickUpPoint_id", referencedColumnName = "id") private PickUpPoint sourcePickUpPoint; + @Nullable @OneToOne() @JoinColumn(name = "destPickUpPoint_id", referencedColumnName = "id") private PickUpPoint destPickUpPoint; @@ -25,9 +29,10 @@ public class Order { @JoinColumn(name = "Car_id", referencedColumnName = "id") private Car car; Order() {} - public Order(Double value, String status, Client client, PickUpPoint sourcePickUpPoint, PickUpPoint destPickUpPoint, Car car) { + public Order(Double value, String status, Date date, Client client, PickUpPoint sourcePickUpPoint, @Nullable PickUpPoint destPickUpPoint, Car car) { this.value = value; this.status = status; + this.date = date; this.client = client; this.sourcePickUpPoint = sourcePickUpPoint; this.destPickUpPoint = destPickUpPoint; @@ -51,6 +56,12 @@ public class Order { public void setStatus(String status) { this.status = status; } + public Date getDate() { + return this.date; + } + public void setDate(Date date) { + this.date = date; + } public Client getClient() { return client; } diff --git a/SUBD-back/src/main/java/com/subd/subd/Services/OrderService.java b/SUBD-back/src/main/java/com/subd/subd/Services/OrderService.java index 633c670..562f2f0 100644 --- a/SUBD-back/src/main/java/com/subd/subd/Services/OrderService.java +++ b/SUBD-back/src/main/java/com/subd/subd/Services/OrderService.java @@ -12,11 +12,11 @@ import com.subd.subd.Repositories.CarRepository; import com.subd.subd.Repositories.ClientRepository; import com.subd.subd.Repositories.OrderRepository; import com.subd.subd.Repositories.PickUpPointRepository; +import jakarta.annotation.Nullable; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.util.List; -import java.util.Optional; +import java.util.*; @Service public class OrderService { @@ -31,16 +31,21 @@ public class OrderService { this.carRepository = carRepository; } @Transactional - public Order addOrder(Double value, String status, Long clientId, Long sourcePickUpPointId, Long destPickUpPointId, Long carId) { + public Order addOrder(Double value, String status, Date date, Long clientId, Long sourcePickUpPointId, @Nullable Long destPickUpPointId, Long carId) { final Client client = clientRepository.findById(clientId) .orElseThrow(() -> new ClientNotFoundException(clientId)); final PickUpPoint sourcePickUpPoint = pickUpPointRepository.findById(sourcePickUpPointId) .orElseThrow(() -> new PickUpPointNotFoundException(sourcePickUpPointId)); - final PickUpPoint destPickUpPoint = pickUpPointRepository.findById(destPickUpPointId) - .orElseThrow(() -> new PickUpPointNotFoundException(destPickUpPointId)); final Car car = carRepository.findById(carId) .orElseThrow(() -> new CarNotFoundException(carId)); - final Order order = new Order(value, status, client, sourcePickUpPoint, destPickUpPoint, car); + final Order order; + if (destPickUpPointId != null) { + final PickUpPoint destPickUpPoint = pickUpPointRepository.findById(destPickUpPointId) + .orElseThrow(() -> new PickUpPointNotFoundException(destPickUpPointId)); + order = new Order(value, status, date, client, sourcePickUpPoint, destPickUpPoint, car); + } else { + order = new Order(value, status, date, client, sourcePickUpPoint, null, car); + } return orderRepository.save(order); } @Transactional(readOnly = true) @@ -52,8 +57,45 @@ public class OrderService { public List findAllOrders() { return orderRepository.findAll(); } + @Transactional(readOnly = true) + public List findfilteredOrders(Long id, Double value, String status, Date date, Long clientId, Long sourcePickUpPointId, Long destPickUpPointId, Long carId) { + List allOrders = orderRepository.findAll(); + List result = new ArrayList<>(); + for (Order order : allOrders) { + boolean flag = true; + if (id != null && !Objects.equals(order.getId(), id)) { + flag = false; + } + if (value != null && !Objects.equals(order.getValue(), value)) { + flag = false; + } + if (status != null && !Objects.equals(order.getStatus(), status)) { + flag = false; + } + if (date != null && !Objects.equals(order.getDate(), date)) { + flag = false; + } + if (clientId != null && !Objects.equals(order.getClient().getId(), clientId)) { + flag = false; + } + if (sourcePickUpPointId != null && !Objects.equals(order.getSourcePickUpPoint().getId(), sourcePickUpPointId)) { + flag = false; + } + if (destPickUpPointId != null && !Objects.equals(order.getDestPickUpPoint().getId(), destPickUpPointId)) { + flag = false; + } + if (carId != null && !Objects.equals(order.getCar().getId(), carId)) { + flag = false; + } + if (flag) { + result.add(order); + } + } + + return result; + } @Transactional - public Order updateOrder(Long id, Double value, String status, Long clientId, Long sourcePickUpPointId, Long destPickUpPointId, Long carId) { + public Order updateOrder(Long id, Double value, String status, Date date, Long clientId, Long sourcePickUpPointId, Long destPickUpPointId, Long carId) { final Order currentOrder = findOrder(id); if (value != null) { currentOrder.setValue(value); @@ -61,6 +103,9 @@ public class OrderService { if (status != null) { currentOrder.setStatus(status); } + if (date != null) { + currentOrder.setDate(date); + } if (clientId != null) { final Client client = clientRepository.findById(clientId) .orElseThrow(() -> new ClientNotFoundException(clientId)); diff --git a/SUBD-back/src/main/java/com/subd/subd/WebConfiguration.java b/SUBD-back/src/main/java/com/subd/subd/WebConfiguration.java new file mode 100644 index 0000000..3fe6d0d --- /dev/null +++ b/SUBD-back/src/main/java/com/subd/subd/WebConfiguration.java @@ -0,0 +1,13 @@ +package com.subd.subd; + +import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.config.annotation.CorsRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; + +@Configuration +public class WebConfiguration implements WebMvcConfigurer { + @Override + public void addCorsMappings(CorsRegistry registry) { + registry.addMapping("/**").allowedMethods("*"); + } +} diff --git a/SUBD-back/src/main/resources/application.properties b/SUBD-back/src/main/resources/application.properties index 38ee5df..0641ff3 100644 --- a/SUBD-back/src/main/resources/application.properties +++ b/SUBD-back/src/main/resources/application.properties @@ -1,7 +1,7 @@ -spring.jpa.hibernate.ddl-auto=create-drop +spring.jpa.hibernate.ddl-auto=none spring.datasource.initialization-mode=always spring.datasource.platform=postgres spring.datasource.url=jdbc:postgresql://109.197.199.134:5432/subd spring.datasource.username=postgres spring.datasource.password=250303Zyzf-d-grad -spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true \ No newline at end of file +spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=false \ No newline at end of file diff --git a/SUBD-front/.vscode/launch.json b/SUBD-front/.vscode/launch.json new file mode 100644 index 0000000..1f96a1a --- /dev/null +++ b/SUBD-front/.vscode/launch.json @@ -0,0 +1,12 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "type": "pwa-chrome", + "request": "launch", + "name": "Launch Chrome against localhost", + "url": "http://localhost:5174", + "webRoot": "${workspaceFolder}/src" + } + ] +} \ No newline at end of file diff --git a/SUBD-front/main.js b/SUBD-front/main.js deleted file mode 100644 index 7baf981..0000000 --- a/SUBD-front/main.js +++ /dev/null @@ -1,30 +0,0 @@ -import { createApp } from 'vue' -import { createRouter, createWebHistory } from 'vue-router' -import './style.css' -import App from './App.vue' -import Catalogs from './components/Catalogs.vue' -import CatalogStudents from './components/CatalogStudents.vue' -import CatalogGroups from './components/CatalogGroups.vue' -import CatalogDisciplines from './components/CatalogDisciplines.vue' -import Reports from './components/Reports.vue' -import ReportGroupStudents from './components/ReportGroupStudents.vue' -import ReportGroupDisciplines from './components/ReportGroupDisciplines.vue' - -const routes = [ - { path: '/', redirect: '/catalogs/students' }, - { path: '/catalogs', component: Catalogs, meta: { label: 'Справочники' } }, - { path: '/catalogs/students', component: CatalogStudents }, - { path: '/catalogs/groups', component: CatalogGroups }, - { path: '/catalogs/disciplines', component: CatalogDisciplines }, - { path: '/reports', component: Reports, meta: { label: 'Отчеты' } }, - { path: '/reports/group-students', component: ReportGroupStudents }, - { path: '/reports/group-disciplines', component: ReportGroupDisciplines } -] - -const router = createRouter({ - history: createWebHistory(), - linkActiveClass: 'active', - routes -}) - -createApp(App).use(router).mount('#app') \ No newline at end of file diff --git a/SUBD-front/package-lock.json b/SUBD-front/package-lock.json index 03e3193..cdf623b 100644 --- a/SUBD-front/package-lock.json +++ b/SUBD-front/package-lock.json @@ -8,6 +8,8 @@ "name": "subd-front", "version": "0.0.0", "dependencies": { + "@eonasdan/tempus-dominus": "^6.4.4", + "@popperjs/core": "^2.11.7", "axios": "^1.3.6", "bootstrap": "^5.2.3", "vue": "^3.2.47", @@ -465,6 +467,22 @@ "node": ">=6.9.0" } }, + "node_modules/@eonasdan/tempus-dominus": { + "version": "6.4.4", + "resolved": "https://registry.npmjs.org/@eonasdan/tempus-dominus/-/tempus-dominus-6.4.4.tgz", + "integrity": "sha512-QPxUlu+ZaJR0sERiKx1dRDxuq1NJh1jSZqf+IB7ZNG8CXBL7wOBsYAYEwSu6web3KGdzWlxfRmpgzwtR3EFgSg==", + "funding": { + "url": "https://ko-fi.com/eonasdan" + }, + "peerDependencies": { + "@popperjs/core": "^2.11.6" + }, + "peerDependenciesMeta": { + "@popperjs/core\"": { + "optional": true + } + } + }, "node_modules/@esbuild/android-arm": { "version": "0.17.15", "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.17.15.tgz", @@ -875,7 +893,6 @@ "version": "2.11.7", "resolved": "https://registry.npmjs.org/@popperjs/core/-/core-2.11.7.tgz", "integrity": "sha512-Cr4OjIkipTtcXKjAsm8agyleBuDHvxzeBoa1v543lbv1YaIwQjESsVcmjiWiPEbC1FIeHOG/Op9kdCmAmiS3Kw==", - "peer": true, "funding": { "type": "opencollective", "url": "https://opencollective.com/popperjs" diff --git a/SUBD-front/src/components/CatalogDisciplines.vue b/SUBD-front/src/components/CatalogDisciplines.vue deleted file mode 100644 index 26726da..0000000 --- a/SUBD-front/src/components/CatalogDisciplines.vue +++ /dev/null @@ -1,44 +0,0 @@ - - - \ No newline at end of file diff --git a/SUBD-front/src/components/CatalogGroups.vue b/SUBD-front/src/components/CatalogGroups.vue deleted file mode 100644 index b7ac5ac..0000000 --- a/SUBD-front/src/components/CatalogGroups.vue +++ /dev/null @@ -1,44 +0,0 @@ - - - \ No newline at end of file diff --git a/SUBD-front/src/components/CatalogStudents.vue b/SUBD-front/src/components/CatalogStudents.vue deleted file mode 100644 index 2a8aad0..0000000 --- a/SUBD-front/src/components/CatalogStudents.vue +++ /dev/null @@ -1,82 +0,0 @@ - - - \ No newline at end of file diff --git a/SUBD-front/src/components/Catalogs.vue b/SUBD-front/src/components/Catalogs.vue index 8480eb4..789e77b 100644 --- a/SUBD-front/src/components/Catalogs.vue +++ b/SUBD-front/src/components/Catalogs.vue @@ -3,9 +3,9 @@ data() { return { catalogs: [ - { name: 'groups', label: 'Группы' }, - { name: 'students', label: 'Студенты' }, - { name: 'disciplines', label: 'Дисциплины' } + { name: 'orders', label: 'Заказы' }, + // { name: 'students', label: 'Студенты' }, + // { name: 'disciplines', label: 'Дисциплины' } ] } } diff --git a/SUBD-front/src/components/DataTable.vue b/SUBD-front/src/components/DataTable.vue index f24eb88..bd883ff 100644 --- a/SUBD-front/src/components/DataTable.vue +++ b/SUBD-front/src/components/DataTable.vue @@ -24,6 +24,21 @@ }, isSelected(id) { return this.selectedItems.includes(id); + }, + dataConvert(data) { + if (data == "accepted") { + return "Принят"; + } + if (data == "inDelivery") { + return "В пути"; + } + if (data == "delvered") { + return "Доставлен"; + } + if (data == "issued") { + return "Выдан"; + } + return data; } } } @@ -46,7 +61,7 @@ :class="{selected: isSelected(item.id)}"> {{ index + 1 }} - {{ item[header.name] }} + {{ dataConvert(item[header.name]) }} diff --git a/SUBD-front/src/components/Header.vue b/SUBD-front/src/components/Header.vue index 162c8d6..f17d46f 100644 --- a/SUBD-front/src/components/Header.vue +++ b/SUBD-front/src/components/Header.vue @@ -13,7 +13,7 @@
- Деканат + Рабочее место оператора пункта выдачи заказов