Advertisement
Guest User

Untitled

a guest
May 27th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.95 KB | None | 0 0
  1.  
  2.     public static void tratarArquivosProcessando() throws Exception{
  3.         Configuracao config = configuracaoDAO.findFirst();
  4.  
  5.         ArrayList<Resumo> resumos = resumoDAO.findAllByStatusErp(ResumoStatusErp.PROCESSANDO);
  6.  
  7.         for (Resumo resumo : resumos) {
  8.             File file = FileUtil.searchFileByDraft(resumo.getDraft(), config.getPathPrefeituraProcessando());
  9.             tratarArquivoProcessando(config, file);
  10.         }      
  11.     }
  12.  
  13.  
  14.  
  15.  
  16.  
  17. public static Boolean tratarArquivoProcessando(Configuracao config,File file) throws Exception{
  18.         if(file == null)
  19.             return false;
  20.  
  21.         NfeVO nfeVO = new NfeVO(file);
  22.         Resumo resumo = resumoDAO.findByCodeOrNew(nfeVO.getDraft());
  23.  
  24.         if(config.getValidaTagTeste() != null && config.getValidaTagTeste().booleanValue()&& StringTools.isEmpty(nfeVO.getDadosNota().getNfse_teste())){
  25.             historicoDAO.save(new Historico(nfeVO.getDraft().longValue(), Historico.TIPO_HISTORICO,"Erro","Arquivo não contem a tag de teste"));
  26.             FileUtil.moveFile(file, config.getPathPrefeituraErro());
  27.             return false;
  28.         }
  29.  
  30.         historicoDAO.save(new Historico(nfeVO.getDraft().longValue(), Historico.TIPO_ENVIO, "Arquivo enviado",nfeVO.getContent()));
  31.        
  32.         ResponseVO response = webService.enviarPrefeitura(config, file);
  33.         Retorno retorno = Convert.readRetorno(response.getContent());
  34.  
  35.         if(response.getStatus() == 200 && retorno.getMensagem().getCodigo()[0].contains("00001 - Sucesso")){
  36.            
  37.             historicoDAO.save(new Historico(nfeVO.getDraft().longValue(), Historico.TIPO_RETORNO,retorno.getFullMessage(),response.getContent()));
  38.            
  39.             FileUtil.createFile(config.getPathPrefeituraRetorno()+"f_"+nfeVO.getFileName(), response.getContent());
  40.             FileUtil.moveFile(file, config.getPathPrefeituraIntegrados());
  41.            
  42.             resumo.setNfseNumero(Util.stringAsInteger(retorno.getNumero_nfse()));
  43.             resumo.setNfseArquivoGerador(retorno.getArquivo_gerador_nfse());
  44.             resumo.setNfseCodVerificadorAutenticidade(retorno.getCod_verificador_autenticidade());
  45.             resumo.setNfseLink(retorno.getLink_nfse());
  46.             resumo.setNfseSerie(retorno.getSerie_nfse());
  47.             resumo.setNfseDataEmissao(Util.newTimestamp());
  48.             resumo.setStatus(ResumoStatus.CONCLUIDA);
  49.             if(resumo.getTipo().equals(ResumoTipo.CANCELAMENTO)){
  50.                 resumo.setStatusErp(ResumoStatusErp.ENVIAR_EMAIL_CANCELAMENTO);
  51.  
  52.             }else{
  53.                 resumo.setStatusErp(ResumoStatusErp.ENVIAR_EMAIL_FATURAMENTO);
  54.                 Draft draft =  draftDAO.findByDraft(resumo.getDraft());
  55.  
  56.                 if(draft != null)
  57.                     resumo.setDataVencimento(Util.calculaVencimentoDraft(draft.getCondicaoPagto()));
  58.             }
  59.  
  60.            
  61.         }else{
  62.             historicoDAO.save(new Historico(nfeVO.getDraft().longValue(), Historico.TIPO_RETORNO,retorno.getFullMessage(),response.getContent()));
  63.             FileUtil.createFile(config.getPathPrefeituraRetorno()+"f_"+nfeVO.getFileName(), response.getContent());
  64.             FileUtil.moveFile(file, config.getPathPrefeituraErro());
  65.             resumo.setStatusErp(ResumoStatusErp.ERRO);
  66.             resumo.setStatus(ResumoStatus.ERRO);
  67.         }
  68.  
  69.         resumoDAO.saveOrUpdate(resumo);
  70.         return true;
  71.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement