Compare commits

...

6 Commits
main ... nosql

Author SHA1 Message Date
1672a95835 done 2023-05-19 15:21:42 +04:00
4a469eb8ad done 2023-05-15 16:01:22 +04:00
fe9682c43b Merge remote-tracking branch 'origin/nosql' into nosql
# Conflicts:
#	SUBD-back/build.gradle
#	SUBD-back/src/main/java/com/subd/subd/Controllers/CustomRequest.java
#	SUBD-back/src/main/java/com/subd/subd/Models/Car.java
#	SUBD-back/src/main/java/com/subd/subd/Models/Client.java
#	SUBD-back/src/main/java/com/subd/subd/Models/Order.java
#	SUBD-back/src/main/java/com/subd/subd/Repositories/OrderRepository.java
2023-05-14 19:09:55 +04:00
a9284a5971 many of done 2023-05-14 19:07:45 +04:00
3ad6e77a70 init of mongodb 2023-05-14 18:16:10 +04:00
bdc8ec8871 init of mongodb 2023-05-13 23:56:36 +04:00
32 changed files with 300 additions and 149 deletions

View File

@ -19,11 +19,10 @@ repositories {
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-data-mongodb:3.0.4'
compileOnly 'org.projectlombok:lombok'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
runtimeOnly 'org.postgresql:postgresql'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

View File

@ -14,23 +14,27 @@ public class CarController {
this.CarService = CarService;
}
@GetMapping("/car/{id}")
public Car getCar(@PathVariable Long id) {
public Car getCar(@PathVariable String id) {
return CarService.findCar(id);
}
@GetMapping("/car")
public List<Car> getCars() {
return CarService.findAllCars();
}
@PostMapping("/carWithId")
public Car createCarWithId(@RequestBody CarDto carDto) {
return CarService.addCarWithId(carDto.getId(), carDto.getGosNumber(), carDto.getVin(), carDto.getDriverId());
}
@PostMapping("/car")
public Car createCar(@RequestBody CarDto carDto) {
return CarService.addCar(carDto.getGosNumber(), carDto.getVin(), carDto.getDriverId());
}
@PutMapping("/car/{id}")
public Car updateCar(@PathVariable Long id, @RequestBody CarDto carDto) {
public Car updateCar(@PathVariable String id, @RequestBody CarDto carDto) {
return CarService.updateCar(id, carDto.getGosNumber(), carDto.getVin(), carDto.getDriverId());
}
@DeleteMapping("/car/{id}")
public Car deleteCar(@PathVariable Long id) {
public Car deleteCar(@PathVariable String id) {
return CarService.deleteCar(id);
}
}

View File

@ -2,6 +2,7 @@ package com.subd.subd.Controllers;
import com.subd.subd.Models.Client;
import com.subd.subd.Services.ClientService;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@ -13,7 +14,7 @@ public class ClientController {
this.ClientService = ClientService;
}
@GetMapping("/client/{id}")
public Client getClient(@PathVariable Long id) {
public Client getClient(@PathVariable String id) {
return ClientService.findClient(id);
}
@GetMapping("/client")
@ -24,12 +25,16 @@ public class ClientController {
public Client createClient(@RequestBody Client client) {
return ClientService.addClient(client.getName(), client.getPhone(), client.getEmail());
}
@PostMapping("/clientWithId")
public Client createClientWithId(@RequestBody Client client) {
return ClientService.addClientWithId(client.getId(), client.getName(), client.getPhone(), client.getEmail());
}
@PutMapping("/client/{id}")
public Client updateClient(@PathVariable Long id, @RequestBody Client client) {
public Client updateClient(@PathVariable String id, @RequestBody Client client) {
return ClientService.updateClient(id, client.getName(), client.getPhone(), client.getEmail());
}
@DeleteMapping("/client/{id}")
public Client deleteClient(@PathVariable Long id) {
public Client deleteClient(@PathVariable String id) {
return ClientService.deleteClient(id);
}
}

View File

@ -2,9 +2,18 @@ package com.subd.subd.Controllers;
import com.subd.subd.Models.Order;
import com.subd.subd.Repositories.OrderRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.data.mongodb.core.query.Query;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
@ -13,16 +22,31 @@ import java.util.List;
@RestController
public class CustomRequest {
private final OrderRepository orderRepository;
public CustomRequest(OrderRepository orderRepository) {
private final MongoTemplate mongoTemplate;
private static final Logger log = LoggerFactory.getLogger(CustomRequest.class);
public CustomRequest(OrderRepository orderRepository, MongoTemplate mongoTemplate) {
this.orderRepository = orderRepository;
this.mongoTemplate = mongoTemplate;
}
@GetMapping("/custom")
public Long performCustomRequest(String date, Double value, String status, String orderBy) throws ParseException {
public Long performCustomRequest(@RequestParam("date") String date,
@RequestParam("value") Double value,
@RequestParam("status") String status,
@RequestParam("orderBy") String orderBy) throws ParseException {
SimpleDateFormat format = new SimpleDateFormat("yyyy-M-d");
Date date1 = format.parse(date);
Query query = new Query();
query.addCriteria(Criteria.where("date").gt(date1))
.addCriteria(Criteria.where("value").gt(value))
.addCriteria(Criteria.where("status").is(status));
query.with(Sort.by(Sort.Direction.ASC, orderBy));
Long start = System.nanoTime();
orderRepository.customAction(date1, value, status, orderBy);
// orderRepository.customAction(date1, value, status, orderBy);
List<Order> orders = mongoTemplate.find(query, Order.class);
Long finish = System.nanoTime();
for (Order order : orders) {
log.info(order.toString());
}
return finish - start;
}
}

View File

@ -13,7 +13,7 @@ public class DriverController {
this.DriverService = DriverService;
}
@GetMapping("/driver/{id}")
public Driver getDriver(@PathVariable Long id) {
public Driver getDriver(@PathVariable String id) {
return DriverService.findDriver(id);
}
@GetMapping("/driver")
@ -24,12 +24,16 @@ public class DriverController {
public Driver createDriver(@RequestBody Driver driver) {
return DriverService.addDriver(driver.getName(), driver.getBirthday(), driver.getPhone(), driver.getEmail());
}
@PostMapping("/driverWithId")
public Driver createDriverWithId(@RequestBody Driver driver) {
return DriverService.addDriverWithId(driver.getId(), driver.getName(), driver.getBirthday(), driver.getPhone(), driver.getEmail());
}
@PutMapping("/driver/{id}")
public Driver updateDriver(@PathVariable Long id, @RequestBody Driver driver) {
public Driver updateDriver(@PathVariable String id, @RequestBody Driver driver) {
return DriverService.updateDriver(id, driver.getName(), driver.getBirthday(), driver.getPhone(), driver.getEmail());
}
@DeleteMapping("/driver/{id}")
public Driver deleteDriver(@PathVariable Long id) {
public Driver deleteDriver(@PathVariable String id) {
return DriverService.deleteDriver(id);
}
}

View File

@ -15,7 +15,7 @@ public class OrderController {
this.OrderService = OrderService;
}
@GetMapping("/order/{id}")
public Order getOrder(@PathVariable Long id) {
public Order getOrder(@PathVariable String id) {
return OrderService.findOrder(id);
}
@GetMapping("/order")
@ -23,26 +23,30 @@ public class OrderController {
return OrderService.findAllOrders();
}
@GetMapping("/order/filter")
public List<Order> getFilteredOrders(@RequestParam(value = "id", required = false) Long id,
public List<Order> getFilteredOrders(@RequestParam(value = "id", required = false) String 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) {
@RequestParam(value = "clientId", required = false) String clientId,
@RequestParam(value = "sourcePickUpPointId", required = false) String sourcePickUpPointId,
@RequestParam(value = "destPickUpPointId", required = false) String destPickUpPointId,
@RequestParam(value = "carId", required = false) String 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.getDate(), orderDto.getClientId(), orderDto.getSourcePickUpPointId(), orderDto.getDestPickUpPointId(), orderDto.getCarId());
}
@PostMapping("/orderWithId")
public Order createOrderWithId(@RequestBody OrderDto orderDto) {
return OrderService.addOrderWithId(orderDto.getId(), 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) {
public Order updateOrder(@PathVariable String id, @RequestBody OrderDto orderDto) {
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) {
public Order deleteOrder(@PathVariable String id) {
return OrderService.deleteOrder(id);
}
}

View File

@ -13,7 +13,7 @@ public class PickUpPointController {
this.PickUpPointService = PickUpPointService;
}
@GetMapping("/pickUpPoint/{id}")
public PickUpPoint getPickUpPoint(@PathVariable Long id) {
public PickUpPoint getPickUpPoint(@PathVariable String id) {
return PickUpPointService.findPickUpPoint(id);
}
@GetMapping("/pickUpPoint")
@ -24,12 +24,16 @@ public class PickUpPointController {
public PickUpPoint createPickUpPoint(@RequestBody PickUpPoint pickUpPoint) {
return PickUpPointService.addPickUpPoint(pickUpPoint.getAddress());
}
@PostMapping("/pickUpPointWithId")
public PickUpPoint createPickUpPointWithId(@RequestBody PickUpPoint pickUpPoint) {
return PickUpPointService.addPickUpPointWithId(pickUpPoint.getId(), pickUpPoint.getAddress());
}
@PutMapping("/pickUpPoint/{id}")
public PickUpPoint updatePickUpPoint(@PathVariable Long id, @RequestBody PickUpPoint pickUpPoint) {
public PickUpPoint updatePickUpPoint(@PathVariable String id, @RequestBody PickUpPoint pickUpPoint) {
return PickUpPointService.updatePickUpPoint(id, pickUpPoint.getAddress());
}
@DeleteMapping("/pickUpPoint/{id}")
public PickUpPoint deletePickUpPoint(@PathVariable Long id) {
public PickUpPoint deletePickUpPoint(@PathVariable String id) {
return PickUpPointService.deletePickUpPoint(id);
}
}

View File

@ -1,22 +1,32 @@
package com.subd.subd.Dtos;
public class CarDto {
private String id;
private String gosNumber;
private String vin;
private Long driverId;
private String driverId;
public CarDto() {}
public CarDto(String gosNumber, String vin, Long driverId) {
public CarDto(String gosNumber, String vin, String driverId) {
this.gosNumber = gosNumber;
this.vin = vin;
this.driverId = driverId;
}
public CarDto(String id, String gosNumber, String vin, String driverId) {
this.id = id;
this.gosNumber = gosNumber;
this.vin = vin;
this.driverId = driverId;
}
public String getId() {
return this.id;
}
public String getGosNumber() {
return this.gosNumber;
}
public String getVin() {
return this.vin;
}
public Long getDriverId() {
public String getDriverId() {
return this.driverId;
}
}

View File

@ -1,21 +1,21 @@
package com.subd.subd.Dtos;
import com.subd.subd.Models.PickUpPoint;
import jakarta.annotation.Nullable;
import java.util.Date;
public class OrderDto {
private String id;
private Double value;
private String status;
private Date date;
private Long clientId;
private Long sourcePickUpPointId;
private String clientId;
private String sourcePickUpPointId;
@Nullable
private Long destPickUpPointId;
private Long carId;
private String destPickUpPointId;
private String carId;
public OrderDto() {}
public OrderDto(Double value, String status, Date date, Long clientId, Long sourcePickUpPointId, @Nullable Long destPickUpPointId, Long carId) {
public OrderDto(Double value, String status, Date date, String clientId, String sourcePickUpPointId, @Nullable String destPickUpPointId, String carId) {
this.value = value;
this.status = status;
this.date = date;
@ -24,6 +24,19 @@ public class OrderDto {
this.destPickUpPointId = destPickUpPointId;
this.carId = carId;
}
public OrderDto(String id, Double value, String status, Date date, String clientId, String sourcePickUpPointId, @Nullable String destPickUpPointId, String carId) {
this.id = id;
this.value = value;
this.status = status;
this.date = date;
this.clientId = clientId;
this.sourcePickUpPointId = sourcePickUpPointId;
this.destPickUpPointId = destPickUpPointId;
this.carId = carId;
}
public String getId() {
return this.id;
}
public Double getValue() {
return this.value;
}
@ -33,17 +46,17 @@ public class OrderDto {
public Date getDate() {
return this.date;
}
public Long getClientId() {
public String getClientId() {
return this.clientId;
}
public Long getSourcePickUpPointId() {
public String getSourcePickUpPointId() {
return this.sourcePickUpPointId;
}
@Nullable
public Long getDestPickUpPointId() {
public String getDestPickUpPointId() {
return this.destPickUpPointId;
}
public Long getCarId() {
public String getCarId() {
return this.carId;
}
}

View File

@ -1,7 +1,7 @@
package com.subd.subd.Exceptions;
public class CarNotFoundException extends RuntimeException{
public CarNotFoundException(Long id) {
public CarNotFoundException(String id) {
super(String.format("Not found car with id: %s", id));
}
}

View File

@ -1,7 +1,7 @@
package com.subd.subd.Exceptions;
public class ClientNotFoundException extends RuntimeException{
public ClientNotFoundException(Long id) {
public ClientNotFoundException(String id) {
super(String.format("Not found client with id: %s", id));
}
}

View File

@ -1,7 +1,7 @@
package com.subd.subd.Exceptions;
public class DriverNotFoundException extends RuntimeException{
public DriverNotFoundException(Long id) {
public DriverNotFoundException(String id) {
super(String.format("Not found driver with id: %s", id));
}
}

View File

@ -1,7 +1,7 @@
package com.subd.subd.Exceptions;
public class OrderNotFoundException extends RuntimeException{
public OrderNotFoundException(Long id) {
public OrderNotFoundException(String id) {
super(String.format("Not found order with id: %s", id));
}
}

View File

@ -1,7 +1,7 @@
package com.subd.subd.Exceptions;
public class PickUpPointNotFoundException extends RuntimeException{
public PickUpPointNotFoundException(Long id) {
public PickUpPointNotFoundException(String id) {
super(String.format("Not found pickUpPoint with id: %s", id));
}
}

View File

@ -1,35 +1,40 @@
package com.subd.subd.Models;
import com.subd.subd.Dtos.CarDto;
import jakarta.persistence.*;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.mongodb.core.mapping.DocumentReference;
import java.util.Objects;
@Entity
@Table(name = "Car")
@Document("Car")
public class Car {
@Id
@GeneratedValue
private Long id;
private String id;
private String gosNumber;
private String vin;
@OneToOne()
@JoinColumn(name = "Driver_id", referencedColumnName = "id")
@DocumentReference()
private Driver driver;
Car() {}
public Car() {}
public Car(String gosNumber, String vin, Driver driver) {
this.gosNumber = gosNumber;
this.vin = vin;
this.driver = driver;
}
public Car(String id, String gosNumber, String vin, Driver driver) {
this.id = id;
this.gosNumber = gosNumber;
this.vin = vin;
this.driver = driver;
}
public Car(CarDto carDto) {
this.gosNumber = carDto.getGosNumber();
this.vin = carDto.getVin();
}
public Long getId() {
public String getId() {
return this.id;
}
public void setId(Long id) {
public void setId(String id) {
this.id = id;
}
public String getGosNumber() {

View File

@ -1,32 +1,38 @@
package com.subd.subd.Models;
import jakarta.annotation.Nullable;
import jakarta.persistence.*;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.mongodb.core.mapping.Unwrapped;
import org.springframework.lang.Nullable;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
@Entity
@Table(name = "Client")
@Document("Client")
public class Client {
@Id
@GeneratedValue
private Long id;
private String id;
private String name;
private String phone;
@Nullable
@Unwrapped.Nullable
private String email;
@OneToMany(cascade = {CascadeType.MERGE})
private List<Order> orders;
Client() {}
public Client() {}
public Client(String name, String phone, @Nullable String email) {
this.name = name;
this.phone = phone;
this.email = email;
}
public Long getId() { return this.id; }
public void setId(Long id) { this.id = id; }
public Client(String id, String name, String phone, @Nullable String email) {
this.id = id;
this.name = name;
this.phone = phone;
this.email = email;
}
public String getId() { return this.id; }
public void setId(String id) { this.id = id; }
public String getName() { return this.name; }
public void setName(String name) { this.name = name; }
public String getPhone() { return this.phone; }

View File

@ -1,32 +1,36 @@
package com.subd.subd.Models;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import java.util.Date;
import java.util.Objects;
@Entity
@Table(name = "Driver")
@Document("Driver")
public class Driver {
@Id
@GeneratedValue
private Long id;
private String id;
private String name;
private Date birthday;
private String phone;
private String email;
Driver() {}
public Driver() {}
public Driver(String name, Date birthday, String phone, String email) {
this.name = name;
this.birthday = birthday;
this.phone = phone;
this.email = email;
}
public Long getId() { return this.id; }
public void setId(Long id) { this.id = id; }
public Driver(String id, String name, Date birthday, String phone, String email) {
this.id = id;
this.name = name;
this.birthday = birthday;
this.phone = phone;
this.email = email;
}
public String getId() { return this.id; }
public void setId(String id) { this.id = id; }
public String getName() { return this.name; }
public void setName(String name) { this.name = name; }
public Date getBirthday() { return this.birthday; }

View File

@ -1,34 +1,32 @@
package com.subd.subd.Models;
import jakarta.annotation.Nullable;
import jakarta.persistence.*;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.mongodb.core.mapping.DocumentReference;
import org.springframework.data.mongodb.core.mapping.Unwrapped;
import org.springframework.lang.Nullable;
import java.util.Date;
import java.util.Objects;
@Entity
@Table(name = "\"Order\"")
@Document("Order")
public class Order {
@Id
@GeneratedValue
private Long id;
private String id;
private Double value;
private String status;
private Date date;
@ManyToOne( cascade = {CascadeType.MERGE}, fetch = FetchType.EAGER)
@JoinColumn(name = "Client_id", nullable = true)
@DocumentReference
private Client client;
@OneToOne()
@JoinColumn(name = "sourcePickUpPoint_id", referencedColumnName = "id")
@DocumentReference
private PickUpPoint sourcePickUpPoint;
@Nullable
@OneToOne()
@JoinColumn(name = "destPickUpPoint_id", referencedColumnName = "id")
@DocumentReference
private PickUpPoint destPickUpPoint;
@OneToOne()
@JoinColumn(name = "Car_id", referencedColumnName = "id")
@DocumentReference
private Car car;
Order() {}
public Order() {}
public Order(Double value, String status, Date date, Client client, PickUpPoint sourcePickUpPoint, @Nullable PickUpPoint destPickUpPoint, Car car) {
this.value = value;
this.status = status;
@ -38,10 +36,20 @@ public class Order {
this.destPickUpPoint = destPickUpPoint;
this.car = car;
}
public Long getId() {
public Order(String id, Double value, String status, Date date, Client client, PickUpPoint sourcePickUpPoint, @Nullable PickUpPoint destPickUpPoint, Car car) {
this.id = id;
this.value = value;
this.status = status;
this.date = date;
this.client = client;
this.sourcePickUpPoint = sourcePickUpPoint;
this.destPickUpPoint = destPickUpPoint;
this.car = car;
}
public String getId() {
return this.id;
}
public void setId(Long id) {
public void setId(String id) {
this.id = id;
}
public Double getValue() {

View File

@ -1,28 +1,31 @@
package com.subd.subd.Models;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import java.util.Objects;
import jakarta.persistence.*;
@Entity
@Table(name = "PickUpPoint")
@Document("PickUpPoint")
public class PickUpPoint {
@Id
@GeneratedValue
private Long id;
@Column(unique=true)
private String id;
private String address;
PickUpPoint() {}
public PickUpPoint() {}
public PickUpPoint(String address) {
this.address = address;
}
public Long getId() {
public PickUpPoint(String id, String address) {
this.id = id;
this.address = address;
}
public String getId() {
return this.id;
}
public String getAddress() {
return this.address;
}
public void setId(Long id) {
public void setId(String id) {
this.id = id;
}
public void setAddress(String address) {

View File

@ -1,7 +1,7 @@
package com.subd.subd.Repositories;
import com.subd.subd.Models.Car;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.mongodb.repository.MongoRepository;
public interface CarRepository extends JpaRepository<Car, Long> {
public interface CarRepository extends MongoRepository<Car, String> {
}

View File

@ -1,7 +1,7 @@
package com.subd.subd.Repositories;
import com.subd.subd.Models.Client;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.mongodb.repository.MongoRepository;
public interface ClientRepository extends JpaRepository<Client, Long> {
public interface ClientRepository extends MongoRepository<Client, String> {
}

View File

@ -1,7 +1,7 @@
package com.subd.subd.Repositories;
import com.subd.subd.Models.Driver;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.mongodb.repository.MongoRepository;
public interface DriverRepository extends JpaRepository<Driver, Long> {
public interface DriverRepository extends MongoRepository<Driver, String> {
}

View File

@ -1,21 +1,23 @@
package com.subd.subd.Repositories;
import com.subd.subd.Models.Order;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.data.mongodb.repository.Query;
import org.springframework.data.repository.query.Param;
import java.util.Date;
import java.util.List;
public interface OrderRepository extends JpaRepository<Order, Long> {
@Query(value = "SELECT \"order\".ID, \"order\".DATE, \"order\".STATUS, \"car\".GOS_NUMBER, \"driver\".NAME as driver_name, \"client\".NAME as client_name\n" +
"FROM \"order\"\n" +
"JOIN CAR ON CAR.ID = \"order\".CAR_ID\n" +
"JOIN DRIVER ON CAR.DRIVER_ID = DRIVER.ID\n" +
"JOIN CLIENT ON CLIENT.ID = \"order\".CLIENT_ID\n" +
"WHERE \"order\".DATE > :date AND \"order\".VALUE > :value AND \"order\".STATUS like :status\n" +
"ORDER BY :orderBy", nativeQuery = true)
public interface OrderRepository extends MongoRepository<Order, String> {
@Query(value = """
db.Order.find({date: {$gt: ISODate("2000-01-01")}, value: {$gt: 1}, status: "accepted"}).sort({date: 1}).forEach(function(order){
var client = db.Client.findOne({_id: order.client});
var car=db.Car.findOne({_id: order.car});
car.driver = db.Driver.findOne({_id: car.driver});
var sourcePickUpPoint = db.PickUpPoint.findOne({_id: order.sourcePickUpPoint});
var destPickUpPoint = db.PickUpPoint.findOne({_id: order.destPickUpPoint});
print(order._id, order.value, order.status, order.date, client, car, sourcePickUpPoint, destPickUpPoint);
})""")
List<Object> customAction(@Param("date") Date date,
@Param("value") Double value,
@Param("status") String status,

View File

@ -1,7 +1,7 @@
package com.subd.subd.Repositories;
import com.subd.subd.Models.PickUpPoint;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.mongodb.repository.MongoRepository;
public interface PickUpPointRepository extends JpaRepository<PickUpPoint, Long> {
public interface PickUpPointRepository extends MongoRepository<PickUpPoint, String> {
}

View File

@ -21,14 +21,21 @@ public class CarService {
this.driverRepository = driverRepository;
}
@Transactional
public Car addCar(String gosNumber, String vin, Long driverId) {
public Car addCar(String gosNumber, String vin, String driverId) {
final Driver driver = driverRepository.findById(driverId)
.orElseThrow(() -> new DriverNotFoundException(driverId));
final Car car = new Car(gosNumber, vin, driver);
return carRepository.save(car);
}
@Transactional
public Car addCarWithId(String id, String gosNumber, String vin, String driverId) {
final Driver driver = driverRepository.findById(driverId)
.orElseThrow(() -> new DriverNotFoundException(driverId));
final Car car = new Car(id, gosNumber, vin, driver);
return carRepository.save(car);
}
@Transactional(readOnly = true)
public Car findCar(Long id) {
public Car findCar(String id) {
final Optional<Car> car = carRepository.findById(id);
return car.orElseThrow(() -> new CarNotFoundException(id));
}
@ -37,7 +44,7 @@ public class CarService {
return carRepository.findAll();
}
@Transactional
public Car updateCar(Long id, String gosNumber, String vin, Long driverId) {
public Car updateCar(String id, String gosNumber, String vin, String driverId) {
final Car currentCar = findCar(id);
if (gosNumber != null) {
currentCar.setGosNumber(gosNumber);
@ -53,13 +60,13 @@ public class CarService {
return carRepository.save(currentCar);
}
@Transactional
public Driver getDriver(Long carId) {
public Driver getDriver(String carId) {
Car currentCar = carRepository.findById(carId)
.orElseThrow(() -> new CarNotFoundException(carId));
return currentCar.getDriver();
}
@Transactional
public void setDriver(Long carId, Long driverId) {
public void setDriver(String carId, String driverId) {
Car currentCar = carRepository.findById(carId)
.orElseThrow(() -> new CarNotFoundException(carId));
Driver driver = driverRepository.findById(driverId)
@ -67,7 +74,7 @@ public class CarService {
currentCar.setDriver(driver);
}
@Transactional
public Car deleteCar(Long id) {
public Car deleteCar(String id) {
final Car currentCar = findCar(id);
carRepository.delete(currentCar);
return currentCar;

View File

@ -20,8 +20,13 @@ public class ClientService {
final Client client = new Client(name, phone, email);
return clientRepository.save(client);
}
@Transactional
public Client addClientWithId(String id, String name, String phone, String email) {
final Client client = new Client(id, name, phone, email);
return clientRepository.save(client);
}
@Transactional(readOnly = true)
public Client findClient(Long id) {
public Client findClient(String id) {
final Optional<Client> client = clientRepository.findById(id);
return client.orElseThrow(() -> new ClientNotFoundException(id));
}
@ -30,7 +35,7 @@ public class ClientService {
return clientRepository.findAll();
}
@Transactional
public Client updateClient(Long id, String name, String phone, String email) {
public Client updateClient(String id, String name, String phone, String email) {
final Client currentClient = findClient(id);
if (name != null) {
currentClient.setName(name);
@ -44,7 +49,7 @@ public class ClientService {
return clientRepository.save(currentClient);
}
@Transactional
public Client deleteClient(Long id) {
public Client deleteClient(String id) {
final Client currentClient = findClient(id);
clientRepository.delete(currentClient);
return currentClient;

View File

@ -21,8 +21,13 @@ public class DriverService {
final Driver driver = new Driver(name, birthday, phone, email);
return driverRepository.save(driver);
}
@Transactional
public Driver addDriverWithId(String id, String name, Date birthday, String phone, String email) {
final Driver driver = new Driver(id, name, birthday, phone, email);
return driverRepository.save(driver);
}
@Transactional(readOnly = true)
public Driver findDriver(Long id) {
public Driver findDriver(String id) {
final Optional<Driver> driver = driverRepository.findById(id);
return driver.orElseThrow(() -> new DriverNotFoundException(id));
}
@ -31,7 +36,7 @@ public class DriverService {
return driverRepository.findAll();
}
@Transactional
public Driver updateDriver(Long id, String name, Date birthday, String phone, String email) {
public Driver updateDriver(String id, String name, Date birthday, String phone, String email) {
final Driver currentDriver = findDriver(id);
if (name != null) {
currentDriver.setName(name);
@ -48,7 +53,7 @@ public class DriverService {
return driverRepository.save(currentDriver);
}
@Transactional
public Driver deleteDriver(Long id) {
public Driver deleteDriver(String id) {
final Driver currentDriver = findDriver(id);
driverRepository.delete(currentDriver);
return currentDriver;

View File

@ -31,7 +31,7 @@ public class OrderService {
this.carRepository = carRepository;
}
@Transactional
public Order addOrder(Double value, String status, Date date, Long clientId, Long sourcePickUpPointId, @Nullable Long destPickUpPointId, Long carId) {
public Order addOrder(Double value, String status, Date date, String clientId, String sourcePickUpPointId, @Nullable String destPickUpPointId, String carId) {
final Client client = clientRepository.findById(clientId)
.orElseThrow(() -> new ClientNotFoundException(clientId));
final PickUpPoint sourcePickUpPoint = pickUpPointRepository.findById(sourcePickUpPointId)
@ -48,8 +48,26 @@ public class OrderService {
}
return orderRepository.save(order);
}
@Transactional
public Order addOrderWithId(String id, Double value, String status, Date date, String clientId, String sourcePickUpPointId, @Nullable String destPickUpPointId, String carId) {
final Client client = clientRepository.findById(clientId)
.orElseThrow(() -> new ClientNotFoundException(clientId));
final PickUpPoint sourcePickUpPoint = pickUpPointRepository.findById(sourcePickUpPointId)
.orElseThrow(() -> new PickUpPointNotFoundException(sourcePickUpPointId));
final Car car = carRepository.findById(carId)
.orElseThrow(() -> new CarNotFoundException(carId));
final Order order;
if (destPickUpPointId != null) {
final PickUpPoint destPickUpPoint = pickUpPointRepository.findById(destPickUpPointId)
.orElseThrow(() -> new PickUpPointNotFoundException(destPickUpPointId));
order = new Order(id, value, status, date, client, sourcePickUpPoint, destPickUpPoint, car);
} else {
order = new Order(id, value, status, date, client, sourcePickUpPoint, null, car);
}
return orderRepository.save(order);
}
@Transactional(readOnly = true)
public Order findOrder(Long id) {
public Order findOrder(String id) {
final Optional<Order> order = orderRepository.findById(id);
return order.orElseThrow(() -> new OrderNotFoundException(id));
}
@ -58,7 +76,7 @@ public class OrderService {
return orderRepository.findAll();
}
@Transactional(readOnly = true)
public List<Order> findfilteredOrders(Long id, Double value, String status, Date date, Long clientId, Long sourcePickUpPointId, Long destPickUpPointId, Long carId) {
public List<Order> findfilteredOrders(String id, Double value, String status, Date date, String clientId, String sourcePickUpPointId, String destPickUpPointId, String carId) {
List<Order> allOrders = orderRepository.findAll();
List<Order> result = new ArrayList<>();
for (Order order : allOrders) {
@ -95,7 +113,7 @@ public class OrderService {
return result;
}
@Transactional
public Order updateOrder(Long id, Double value, String status, Date date, Long clientId, Long sourcePickUpPointId, Long destPickUpPointId, Long carId) {
public Order updateOrder(String id, Double value, String status, Date date, String clientId, String sourcePickUpPointId, String destPickUpPointId, String carId) {
final Order currentOrder = findOrder(id);
if (value != null) {
currentOrder.setValue(value);
@ -129,7 +147,7 @@ public class OrderService {
return orderRepository.save(currentOrder);
}
@Transactional
public Order deleteOrder(Long id) {
public Order deleteOrder(String id) {
final Order currentOrder = findOrder(id);
orderRepository.delete(currentOrder);
return currentOrder;

View File

@ -20,8 +20,13 @@ public class PickUpPointService {
final PickUpPoint pickUpPoint = new PickUpPoint(address);
return pickUpPointRepository.save(pickUpPoint);
}
@Transactional
public PickUpPoint addPickUpPointWithId(String id, String address) {
final PickUpPoint pickUpPoint = new PickUpPoint(id, address);
return pickUpPointRepository.save(pickUpPoint);
}
@Transactional(readOnly = true)
public PickUpPoint findPickUpPoint(Long id) {
public PickUpPoint findPickUpPoint(String id) {
final Optional<PickUpPoint> pickUpPoint = pickUpPointRepository.findById(id);
return pickUpPoint.orElseThrow(() -> new PickUpPointNotFoundException(id));
}
@ -30,7 +35,7 @@ public class PickUpPointService {
return pickUpPointRepository.findAll();
}
@Transactional
public PickUpPoint updatePickUpPoint(Long id, String address) {
public PickUpPoint updatePickUpPoint(String id, String address) {
final PickUpPoint currentPickUpPoint = findPickUpPoint(id);
if (address != null) {
currentPickUpPoint.setAddress(address);
@ -38,7 +43,7 @@ public class PickUpPointService {
return pickUpPointRepository.save(currentPickUpPoint);
}
@Transactional
public PickUpPoint deletePickUpPoint(Long id) {
public PickUpPoint deletePickUpPoint(String id) {
final PickUpPoint currentPickUpPoint = findPickUpPoint(id);
pickUpPointRepository.delete(currentPickUpPoint);
return currentPickUpPoint;

View File

@ -1,10 +1,24 @@
package com.subd.subd;
import com.subd.subd.Repositories.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.mongodb.repository.config.EnableMongoRepositories;
@SpringBootApplication
@EnableMongoRepositories
public class SubdApplication {
@Autowired
CarRepository carRepository;
@Autowired
ClientRepository clientRepository;
@Autowired
DriverRepository driverRepository;
@Autowired
OrderRepository orderRepository;
@Autowired
PickUpPointRepository pickUpPointRepository;
public static void main(String[] args) {
SpringApplication.run(SubdApplication.class, args);
}

View File

@ -1,7 +1,9 @@
spring.jpa.hibernate.ddl-auto=create
spring.sql.init.mode=always
spring.sql.init.platform=postgres
spring.datasource.url=jdbc:postgresql://192.168.31.77:5432/yan
spring.datasource.username=yan
spring.datasource.password=250303zyzf
spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true
#spring.jpa.hibernate.ddl-auto=update
#spring.sql.init.mode=always
#spring.sql.init.platform=postgres
#spring.datasource.url=jdbc:postgresql://192.168.0.177:5432/yan
#spring.datasource.username=yan
#spring.datasource.password=250303zyzf
#spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true
spring.data.mongodb.uri=mongodb://192.168.43.105:27017/yan
spring.data.mongodb.database=yan

View File

@ -42,7 +42,7 @@
let count = document.getElementById('measureCount').value;
this.wholeTime = 0;
for (let i = 0; i < count; i++) {
const response = axios.get("http://localhost:8080/custom?date=2023-2-1&value=1000&status=delivered&orderBy=date")
const response = axios.get("http://localhost:8080/custom?date=2000-2-1&value=1000&status=delivered&orderBy=date")
.then(data => {
this.wholeTime += data.data;
});