diff --git a/backend/TMSProject/src/main/java/br/com/entra21/teamroxo/TMSProject/controllers/ShipController.java b/backend/TMSProject/src/main/java/br/com/entra21/teamroxo/TMSProject/controllers/ShipController.java index 0828913..a9773ef 100644 --- a/backend/TMSProject/src/main/java/br/com/entra21/teamroxo/TMSProject/controllers/ShipController.java +++ b/backend/TMSProject/src/main/java/br/com/entra21/teamroxo/TMSProject/controllers/ShipController.java @@ -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; @@ -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) { diff --git a/frontend/main/src/app/carrier.service.spec.ts b/frontend/main/src/app/carrier.service.spec.ts new file mode 100644 index 0000000..6d132b6 --- /dev/null +++ b/frontend/main/src/app/carrier.service.spec.ts @@ -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(); + }); +}); diff --git a/frontend/main/src/app/carrier.service.ts b/frontend/main/src/app/carrier.service.ts new file mode 100644 index 0000000..0bd06ed --- /dev/null +++ b/frontend/main/src/app/carrier.service.ts @@ -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) + + } +} diff --git a/frontend/main/src/app/loginservice.service.ts b/frontend/main/src/app/loginservice.service.ts index b4a75ed..065e399 100644 --- a/frontend/main/src/app/loginservice.service.ts +++ b/frontend/main/src/app/loginservice.service.ts @@ -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) { } @@ -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 }) diff --git a/frontend/main/src/app/quote.service.ts b/frontend/main/src/app/quote.service.ts index 12e05db..6cfa1b6 100644 --- a/frontend/main/src/app/quote.service.ts +++ b/frontend/main/src/app/quote.service.ts @@ -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'; @@ -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(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); + + }) + + + } + + + } diff --git a/frontend/main/src/app/ship-qt/ship-qt.component.html b/frontend/main/src/app/ship-qt/ship-qt.component.html index 2172d2d..6ff8125 100644 --- a/frontend/main/src/app/ship-qt/ship-qt.component.html +++ b/frontend/main/src/app/ship-qt/ship-qt.component.html @@ -1,48 +1,50 @@ - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + +
CEP de origemCEP de destinoComprimento (cm)Largura (cm)Altura (cm)Peso (kg)
CEP de origemCEP de destinoComprimento (cm)Largura (cm)Altura (cm)Peso (kg)


- - - - - - - - + + + + + + + + + - - - - - - - - - - + + + + + + + + + + + - - -
IDPreço do fretePrazoOrigemDestinoTransportadoraPeso cubado
SelecioneIDPreço do fretePrazoOrigemDestinoTransportadoraPeso cubado
{{i}}R${{quote.precoFrete}}{{quote.tempo}} dias úteis{{quote.start_adress}}{{quote.end_address}}{{quote.carrier}}{{quote.cubagem}} kg
{{i}}R${{quote.precoFrete}}{{quote.tempo}} dias úteis{{quote.start_adress}}{{quote.end_address}}{{quote.carrier}}{{quote.cubagem}} kg
+ + + \ No newline at end of file diff --git a/frontend/main/src/app/ship-qt/ship-qt.component.ts b/frontend/main/src/app/ship-qt/ship-qt.component.ts index ace0af0..00ee164 100644 --- a/frontend/main/src/app/ship-qt/ship-qt.component.ts +++ b/frontend/main/src/app/ship-qt/ship-qt.component.ts @@ -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({ @@ -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) + + + + } + }