Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.util.JSONPObject;
Expand Down Expand Up @@ -44,7 +45,6 @@ public JsonNode getGoogleAPI(@PathVariable ("cepOrigem") int param1, @PathVariab
ObjectMapper mapper = new ObjectMapper();
JsonNode node = mapper.readTree(jsonEmString);


return node;

}catch (Exception e) {
Expand Down
16 changes: 16 additions & 0 deletions frontend/main/src/app/carrier.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { TestBed } from '@angular/core/testing';

import { CarrierService } from './carrier.service';

describe('CarrierService', () => {
let service: CarrierService;

beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(CarrierService);
});

it('should be created', () => {
expect(service).toBeTruthy();
});
});
19 changes: 19 additions & 0 deletions frontend/main/src/app/carrier.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Router } from '@angular/router';

@Injectable({
providedIn: 'root'
})
export class CarrierService {

apiURL:string = 'http://localhost:8080/carriers'

constructor(private router: Router, private http: HttpClient) { }

listCarrier():any{

return this.http.get(this.apiURL)

}
}
2 changes: 2 additions & 0 deletions frontend/main/src/app/loginservice.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export class LoginserviceService implements CanActivate {
progress: boolean = false
admin:boolean = false
enterprise:boolean = false
pessoaID!:number

constructor(private router: Router, private http: HttpClient) { }

Expand All @@ -42,6 +43,7 @@ export class LoginserviceService implements CanActivate {
this.user = resp.nome
this.admin = resp.admin
this.enterprise = resp.enterprise
this.pessoaID = response[0].pessoa_id
})
return response
})
Expand Down
23 changes: 20 additions & 3 deletions frontend/main/src/app/quote.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Router } from '@angular/router';
import { type } from 'os';
import { catchError } from 'rxjs';
import { ShipQtComponent } from './ship-qt/ship-qt.component';

Expand All @@ -8,14 +10,29 @@ import { ShipQtComponent } from './ship-qt/ship-qt.component';
})
export class QuoteService {

apiURL:string = 'https://maps.googleapis.com/maps/api/directions/json?origin='
apiURL:string = 'http://localhost:8080/ship'
apiURL2:string = 'http://localhost:8080/quote'

constructor(private http: HttpClient) { }
constructor(private router: Router, private http: HttpClient) { }

quote(cepOrigem:string, cepDestino:string):any{

return this.http.get<any>(this.apiURL+cepOrigem+'&destination='+cepDestino+'&key=AIzaSyCKNjLUI0d01M0SfoDjIov4vZlR3DprotM')
return this.http.get(this.apiURL+'/'+cepOrigem+'/'+cepDestino)

}

regRecentQuotes(object:any){
this.http.post(this.apiURL2+'/recent',object)
.subscribe((response)=>{


console.log(response);

})


}



}
80 changes: 41 additions & 39 deletions frontend/main/src/app/ship-qt/ship-qt.component.html
Original file line number Diff line number Diff line change
@@ -1,48 +1,50 @@
<table class="table table-bordered">
<thead>
<th>CEP de origem</th>
<th>CEP de destino</th>
<th>Comprimento (cm)</th>
<th>Largura (cm)</th>
<th>Altura (cm)</th>
<th>Peso (kg)</th>
</thead>
<tbody>
<tr>
<td><input type="number" [(ngModel)]="cepOrigem"></td>
<td><input type="number" [(ngModel)]="cepDestino"></td>
<td><input type="number" [(ngModel)]="comprimento"></td>
<td><input type="number" [(ngModel)]="largura"></td>
<td><input type="number" [(ngModel)]="altura"></td>
<td><input type="number" [(ngModel)]="peso"></td>
</tr>
</tbody>
<thead>
<th>CEP de origem</th>
<th>CEP de destino</th>
<th>Comprimento (cm)</th>
<th>Largura (cm)</th>
<th>Altura (cm)</th>
<th>Peso (kg)</th>
</thead>
<tbody>
<tr>
<td><input type="number" [(ngModel)]="cepOrigem"></td>
<td><input type="number" [(ngModel)]="cepDestino"></td>
<td><input type="number" [(ngModel)]="comprimento"></td>
<td><input type="number" [(ngModel)]="largura"></td>
<td><input type="number" [(ngModel)]="altura"></td>
<td><input type="number" [(ngModel)]="peso"></td>
</tr>
</tbody>
</table>

<button class="btn btn-success" (click)="quote()">Quote</button>
<br>
<hr>
<table class="table table-bordered">
<thead>
<th>ID</th>
<th>Preço do frete</th>
<th>Prazo</th>
<th>Origem</th>
<th>Destino</th>
<th>Transportadora</th>
<th>Peso cubado</th>
<thead>
<th>Selecione</th>
<th>ID</th>
<th>Preço do frete</th>
<th>Prazo</th>
<th>Origem</th>
<th>Destino</th>
<th>Transportadora</th>
<th>Peso cubado</th>

</thead>
<tbody>
<tr *ngFor="let quote of quotes;let i = index;">
<td>{{i}}</td>
<td>R${{quote.precoFrete}}</td>
<td>{{quote.tempo}} dias úteis</td>
<td>{{quote.start_adress}}</td>
<td>{{quote.end_address}}</td>
<td>{{quote.carrier}}</td>
<td>{{quote.cubagem}} kg</td>
</thead>
<tbody>
<tr *ngFor="let quote of quotes;let i = index;">
<td class="align-items-center"><button class="btn btn-primary" (click)="regRecentQuotes(this.quote.precoFrete, this.quote.tempo, this.quote.start_adress, this.quote.end_address, this.quote.carrierID, this.quote.cubagem, this.quote.pessoaID )">Save</button></td>
<td>{{i}}</td>
<td>R${{quote.precoFrete}}</td>
<td>{{quote.tempo}} dias úteis</td>
<td>{{quote.start_adress}}</td>
<td>{{quote.end_address}}</td>
<td>{{quote.carrier}}</td>
<td>{{quote.cubagem}} kg</td>

</tr>
</tbody>
</table>
</tr>
</tbody>
</table>
113 changes: 73 additions & 40 deletions frontend/main/src/app/ship-qt/ship-qt.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { HttpClient } from '@angular/common/http';
import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { catchError, of } from 'rxjs';
import { arrayBuffer, json } from 'stream/consumers';
import { CarrierService } from '../carrier.service';
import { LoginComponent } from '../login/login.component';
import { LoginserviceService } from '../loginservice.service';
import { QuoteService } from '../quote.service';

@Component({
Expand All @@ -19,74 +24,102 @@ export class ShipQtComponent implements OnInit {
peso!: number
precoFrete!: number
tempo!: number
end_address!:string
start_adress!:string
taxQuote!:number
carrier!:string
vol!:number
cubagem!:number
priceFix!:number
fatorCub!:number
end_address!: string
start_adress!: string
taxQuote!: number
carrier!: string
vol!: number
cubagem!: number
priceFix!: number
fatorCub!: number
distance!: number
carrierData = [];


constructor(public quoteService:QuoteService) {}
constructor(public loginService: LoginserviceService, public carrierService: CarrierService, public quoteService: QuoteService, private router: Router, private http: HttpClient) { }

ngOnInit(): void {
this.quotes = new Array()
//this.quotes.push({ precoFrete: 45.50, tempo: 3, trackid: "BR23154546TR", cepOrigem: 88058086, cepDestino: 88058086, comprimento: 50, largura: 50, altura: 50, peso: 10 })
//this.quotes.push({ precoFrete: 94.50, tempo: 6, trackid: "BR22315445TR", cepOrigem: 46513265, cepDestino: 65898454, comprimento: 100, largura: 200, altura: 10, peso: 25 })
//this.quotes.push({ precoFrete: 45.50, tempo: 3, trackid: "BR23154546TR", cepOrigem: 88058086, cepDestino: 88058086, comprimento: 50, largura: 50, altura: 50, peso: 10 })
//this.quotes.push({ precoFrete: 94.50, tempo: 6, trackid: "BR22315445TR", cepOrigem: 46513265, cepDestino: 65898454, comprimento: 100, largura: 200, altura: 10, peso: 25 })

}

quote() {

if(this.cepOrigem != null && this.cepDestino != null){
if (this.cepOrigem != null && this.cepDestino != null && this.comprimento != null, this.altura != null, this.largura != null, this.peso != null) {
this.quoteService.quote(this.cepOrigem, this.cepDestino)
.pipe()
.subscribe((response:any) => {
console.log(response);
console.log(response.routes[0].legs[0].distance.value);
console.log(response.routes[0].legs[0].duration.value);
.pipe()
.subscribe((response: any) => {

this.fatorCub = 300; //fator cubado - rodoviário
this.taxQuote = 0.041;
this.carrier= "Total Express";
this.priceFix = 14.55;
console.log(response);

this.start_adress = response.routes[0].legs[0].start_address;
this.end_address = response.routes[0].legs[0].end_address;
//variaveis fixas
this.fatorCub = 300; //fator cubado - rodoviário
this.priceFix = 14.55;

this.vol = (this.comprimento*this.altura*this.largura)/1000000;
//variaveis google
this.start_adress = response.routes[0].legs[0].start_address;
this.end_address = response.routes[0].legs[0].end_address;
this.distance = (response.routes[0].legs[0].distance.value);

this.cubagem = this.vol*this.fatorCub;
console.log(this.cubagem);
//cálculos
this.vol = (this.comprimento * this.altura * this.largura) / 1000000; //conversão em m³
this.cubagem = this.vol * this.fatorCub;
this.tempo = Math.ceil((((this.distance) / 1000) / 80) / 7); //dividido por 1000 para converter, /80 velocidade med, /7 horas diárias

//dados da transportadora
this.carrierService.listCarrier().pipe().subscribe((response: any) => {

this.tempo = Math.ceil((((response.routes[0].legs[0].distance.value)/1000)/80)/7); //dividido por 1000 para converter, /80 velocidade med, /7 horas diárias
this.precoFrete = this.priceFix + ((response.routes[0].legs[0].distance.value/10000)*this.taxQuote)*(this.cubagem);
var count = Object.keys(response).length;

console.log(this.tempo);
console.log(this.precoFrete);
for (let i = 0; i < count; i++) {

console.log(response[i].taxa);

console.log(this.priceFix + this.distance * response[i].taxa * this.cubagem);

this.precoFrete = this.priceFix + this.distance * response[i].taxa * this.cubagem;

this.quotes.push({ precoFrete: this.precoFrete, tempo: this.tempo, start_adress: this.start_adress, end_address: this.end_address, carrier: response[i].razao, vol: this.vol, cubagem: this.cubagem, carrierID: response[i].id, pessoaID: this.loginService.pessoaID });

// this.quotes.push({precoFrete:this.precoFrete, tempo:this.tempo , start_adress:this.start_adress, end_address:this.end_address})
this.quotes.push({precoFrete:this.precoFrete, tempo:this.tempo , start_adress:this.start_adress, end_address:this.end_address, carrier:this.carrier, vol:this.vol, cubagem:this.cubagem});
this.cepDestino=""
this.cepOrigem=""
this.comprimento=0
this.largura=0
this.altura=0
this.peso=0


})
}else{
}

})

this.cepDestino = ""
this.cepOrigem = ""
this.comprimento = 0
this.largura = 0
this.altura = 0
this.peso = 0


})
} else {
alert('DIGITE TODOS OS DADOS!')
}

}

regRecentQuotes(priceQuote: number, prazo: number, origem: string, destino: string, carrierID: number, cubagem: number, pessoaID:number) {

let build ={
"price":priceQuote,
"await":prazo,
"origin":origem,
"destiny":destino,
"carrier_id":carrierID,
"cub_height":cubagem,
"pessoa_id":pessoaID
}

this.quoteService.regRecentQuotes(build)



}

}