import{HttpClient}from'@angular/common/http';import{Component,Inject}from'@angular/core';import{MatDialogRef,MAT_DIALOG_DATA}from'@angular/material/dialog';import{DomSanitizer}from'@angular/platform-browser';import{FuseConfirmDialogComponent}from'@fuse/components/confirm-dialog/confirm-dialog.component';import{API}from'app/core/api/erp.api';import{ErrorService}from'app/core/service/error.service';import{environment}from'environments/environment';@Component({selector:'app-imprimir-requisicao',templateUrl:'./imprimir-requisicao.component.html',})exportclassImprimirRequisicaoComponent{publicconfirmMessage:string;relatorio:any;id:number;constructor(publicdomSanitizer:DomSanitizer,privatehttp:HttpClient,privateerrorServiceS:ErrorService,publicdialogRef:MatDialogRef<FuseConfirmDialogComponent>,@Inject(MAT_DIALOG_DATA)data:any){this.id=data.id;}asyncngOnInit():Promise<void>{awaitthis.imprimir(this.id);}privateasyncimprimir(id:number):Promise<void>{lethttpReturn:any;try{httpReturn=awaitthis.http.get(environment.RELATORIO+API+'requisicao-compra/'+id+'/').toPromise();this.relatorio='data:'+httpReturn['contentType']+';base64,';this.relatorio=this.relatorio+httpReturn['arquivo'];}catch(error:any){if(error!=='undefined'){this.errorServiceS.error('Erro em gerar relatório de requisição de compras !');}}}}
core.js:4610 ERROR Error: unsafe value used in a resource URL context (see http://g.co/ng/security#xss)
at ɵɵsanitizeResourceUrl (core.js:5539)
at elementPropertyInternal (core.js:9099)
at Module.ɵɵpropertyInterpolate1 (core.js:15873)
at ImprimirCotacaoComponent_Template (imprimir-cotacao.component.html:7)
at executeTemplate (core.js:8689)
at refreshView (core.js:8558)
at refreshComponent (core.js:9711)
at refreshChildComponents (core.js:8355)
at refreshView (core.js:8608)
at refreshEmbeddedViews (core.js:9665)
packagebr.com.ghnetsoft.comprasfood.relatorio.resource;importstaticbr.com.ghnetsoft.principal.enuns.TipoMensagemEnum.ERROR;importstaticorg.springframework.http.HttpStatus.OK;importorg.springframework.beans.factory.annotation.Autowired;importorg.springframework.http.ResponseEntity;importorg.springframework.web.bind.annotation.GetMapping;importorg.springframework.web.bind.annotation.PathVariable;importorg.springframework.web.bind.annotation.RequestMapping;importorg.springframework.web.bind.annotation.RestController;importbr.com.ghnetsoft.comprasfood.relatorio.service.CotacaoService;importbr.com.ghnetsoft.principal.exception.GeralException;importbr.com.ghnetsoft.principal.resource.PrincipalResource;importio.swagger.annotations.ApiOperation;@RestController@RequestMapping("/api/cotacao")publicclassCotacaoResourceextendsPrincipalResource{privatestaticfinallongserialVersionUID=3370601170855459651L;@AutowiredprivateCotacaoServiceservice;@ApiOperation("Imprime uma cotação pelo id")@GetMapping("{id}")publicResponseEntity<?>buscarPeloId(@PathVariableLongid){try{returnResponseEntity.status(OK).body(service.imprimir(id));}catch(GeralExceptione){returnerroExceptionComRegra(e,"cotacao");}catch(Exceptione){returnexcecaoGeralSalvar(e,ERROR,"cotacao","cotação");}}}
service
packagebr.com.ghnetsoft.comprasfood.relatorio.service;import staticbr.com.ghnetsoft.principal.util.DataUtil.DD_MM_YYYY;import staticbr.com.ghnetsoft.principal.util.DataUtil.converterLocalDateParaString;import staticbr.com.ghnetsoft.principal.util.DataUtil.converterLocalDateTimeJava;importjava.math.BigDecimal;importjava.util.ArrayList;importjava.util.Collection;importjava.util.Map;importjava.util.Optional;importorg.apache.commons.collections4.map.HashedMap;importorg.springframework.beans.factory.annotation.Autowired;importorg.springframework.beans.factory.annotation.Value;importorg.springframework.stereotype.Service;importbr.com.ghnetsoft.comprasfood.model.cotacao.Cotacao;importbr.com.ghnetsoft.comprasfood.model.cotacaoitem.CotacaoItem;importbr.com.ghnetsoft.comprasfood.relatorio.dto.CotacaoItemDTO;importbr.com.ghnetsoft.comprasfood.repository.cotacao.CotacaoRepository;importbr.com.ghnetsoft.comprasfood.repository.cotacaoitem.CotacaoItemRepository;importbr.com.ghnetsoft.principal.dto.ArquivoDTO;importbr.com.ghnetsoft.principal.exception.GeralException;importnet.sf.jasperreports.engine.JRDataSource;importnet.sf.jasperreports.engine.JRException;importnet.sf.jasperreports.engine.JasperRunManager;importnet.sf.jasperreports.engine.data.JRBeanCollectionDataSource;@ServicepublicclassCotacaoService{@AutowiredprivateCotacaoRepositoryrepository;@AutowiredprivateCotacaoItemRepositorycotacaoItemRepository;@Value("${url.angular}")privateStringurlAngular;privateBigDecimaltotal;publicbyte[]imprimir(Longid){try{Optional<Cotacao>cotacaoExiste=repository.findById(id);if(cotacaoExiste.isPresent()){total=newBigDecimal("0");JRDataSourcedataSource=newJRBeanCollectionDataSource(inserirLista(cotacaoExiste));Map<String,Object>parametros=newHashedMap<String,Object>();parametros.put("loja",cotacaoExiste.get().getLoja().getNome());parametros.put("numero",cotacaoExiste.get().getNumero());parametros.put("dataValidade",converterLocalDateParaString(converterLocalDateTimeJava(cotacaoExiste.get().getDataValidade()),DD_MM_YYYY));parametros.put("status",cotacaoExiste.get().getStatus().getDescricao());parametros.put("observacao",cotacaoExiste.get().getObservacao());parametros.put("total",total);parametros.put("aceitaMarcaSimilar",cotacaoExiste.get().getAceitaMarcaSimilar().getDescricao());parametros.put("imgParametro",urlAngular+"assets/images/");returnJasperRunManager.runReportToPdf(this.getClass().getClassLoader().getResourceAsStream("relatorio/cotacao.jasper"),parametros,dataSource);}else{thrownewGeralException("Não existe relatório com este registro !");}}catch(JRExceptione){e.printStackTrace();thrownewGeralException("Erro ao gerar relatório de Cotação !");}}privateCollection<CotacaoItemDTO>inserirLista(Optional<Cotacao>requisicaoExiste){Collection<CotacaoItemDTO>itens=newArrayList<>();for(CotacaoItemitem:cotacaoItemRepository.buscarItensPelaCotacao(requisicaoExiste.get().getId())){itens.add(CotacaoItemDTO.builder().marca(item.getMarca()).insumo(item.getInsumo().getNome()).unidade(item.getUnidade().getNome()).quantidade(item.getQuantidade()).quantidadeEstoque(item.getQuantidadeEstoque()).ultimoCusto(item.getUltimoCusto()).build());total=total.add(item.getTotal());}returnitens;}}
O que pode ser ?
guilhermebhte
Outra forma que fiz, meio que funcionou foi assim: