Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void tratarArquivosProcessando() throws Exception{
- Configuracao config = configuracaoDAO.findFirst();
- ArrayList<Resumo> resumos = resumoDAO.findAllByStatusErp(ResumoStatusErp.PROCESSANDO);
- for (Resumo resumo : resumos) {
- File file = FileUtil.searchFileByDraft(resumo.getDraft(), config.getPathPrefeituraProcessando());
- tratarArquivoProcessando(config, file);
- }
- }
- public static Boolean tratarArquivoProcessando(Configuracao config,File file) throws Exception{
- if(file == null)
- return false;
- NfeVO nfeVO = new NfeVO(file);
- Resumo resumo = resumoDAO.findByCodeOrNew(nfeVO.getDraft());
- if(config.getValidaTagTeste() != null && config.getValidaTagTeste().booleanValue()&& StringTools.isEmpty(nfeVO.getDadosNota().getNfse_teste())){
- historicoDAO.save(new Historico(nfeVO.getDraft().longValue(), Historico.TIPO_HISTORICO,"Erro","Arquivo não contem a tag de teste"));
- FileUtil.moveFile(file, config.getPathPrefeituraErro());
- return false;
- }
- historicoDAO.save(new Historico(nfeVO.getDraft().longValue(), Historico.TIPO_ENVIO, "Arquivo enviado",nfeVO.getContent()));
- ResponseVO response = webService.enviarPrefeitura(config, file);
- Retorno retorno = Convert.readRetorno(response.getContent());
- if(response.getStatus() == 200 && retorno.getMensagem().getCodigo()[0].contains("00001 - Sucesso")){
- historicoDAO.save(new Historico(nfeVO.getDraft().longValue(), Historico.TIPO_RETORNO,retorno.getFullMessage(),response.getContent()));
- FileUtil.createFile(config.getPathPrefeituraRetorno()+"f_"+nfeVO.getFileName(), response.getContent());
- FileUtil.moveFile(file, config.getPathPrefeituraIntegrados());
- resumo.setNfseNumero(Util.stringAsInteger(retorno.getNumero_nfse()));
- resumo.setNfseArquivoGerador(retorno.getArquivo_gerador_nfse());
- resumo.setNfseCodVerificadorAutenticidade(retorno.getCod_verificador_autenticidade());
- resumo.setNfseLink(retorno.getLink_nfse());
- resumo.setNfseSerie(retorno.getSerie_nfse());
- resumo.setNfseDataEmissao(Util.newTimestamp());
- resumo.setStatus(ResumoStatus.CONCLUIDA);
- if(resumo.getTipo().equals(ResumoTipo.CANCELAMENTO)){
- resumo.setStatusErp(ResumoStatusErp.ENVIAR_EMAIL_CANCELAMENTO);
- }else{
- resumo.setStatusErp(ResumoStatusErp.ENVIAR_EMAIL_FATURAMENTO);
- Draft draft = draftDAO.findByDraft(resumo.getDraft());
- if(draft != null)
- resumo.setDataVencimento(Util.calculaVencimentoDraft(draft.getCondicaoPagto()));
- }
- }else{
- historicoDAO.save(new Historico(nfeVO.getDraft().longValue(), Historico.TIPO_RETORNO,retorno.getFullMessage(),response.getContent()));
- FileUtil.createFile(config.getPathPrefeituraRetorno()+"f_"+nfeVO.getFileName(), response.getContent());
- FileUtil.moveFile(file, config.getPathPrefeituraErro());
- resumo.setStatusErp(ResumoStatusErp.ERRO);
- resumo.setStatus(ResumoStatus.ERRO);
- }
- resumoDAO.saveOrUpdate(resumo);
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement