-
Notifications
You must be signed in to change notification settings - Fork 1
/
XmlController.go
109 lines (89 loc) · 3.19 KB
/
XmlController.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package Controller
import (
"os"
"strings"
"github.com/go-bongo/bongo"
"fmt"
"github.com/FixAuditoria/GoSped/Dao"
"github.com/FixAuditoria/GoSped/Utilidades"
)
var path string
func init() {
path = "empresas"
pathinvalido := path + "/invalido"
Utilidades.CriarUmDiretorio(path)
Utilidades.CriarUmDiretorio(pathinvalido)
}
// ProcessarXmls : Funcao responsavel por verificar o que contem e mandar para o destino correto
func ProcessarXmls(arquivo string, conn *bongo.Connection) {
xmlByte := TransformarXmlEmByte(arquivo)
isNfePro := string(xmlByte[0:120])
fmt.Println(isNfePro)
//fmt.Println(arquivo)
//panic(isNfePro)
if strings.Contains(isNfePro, "><NFe xmlns=") && !strings.Contains(isNfePro, "<NFeDFe") {
pathArquivo, nota := ProcessarNfeSemProcValido(xmlByte)
if pathArquivo != "" {
Utilidades.MoverArquivos(arquivo, pathArquivo)
Dao.InserirNfeProcSemValidade(Dao.COLLECTIONNFESEMVALIDADE, nota, conn)
}
}
if strings.Contains(isNfePro, "<NFe xmlns:xsi") {
pathArquivo, nota := ProcessarNfeSemValidade(xmlByte)
Utilidades.MoverArquivos(arquivo, pathArquivo)
Dao.InserirNfeProcSemValidade(Dao.COLLECTIONNFESEMVALIDADE, nota, conn)
}
// Estrutura com nfe valida
if strings.Contains(isNfePro, "<nfeProc") {
pathArquivo, nota := ProcessarNfeProcValido(xmlByte)
// Verifica se arquivo nao foi realmente preenchido
if pathArquivo != "" {
Utilidades.MoverArquivos(arquivo, pathArquivo)
Dao.InserirNfeProc(Dao.COLLECTIONNFEPROC, nota, conn)
}
}
if strings.Contains(isNfePro, "<nfeProc versao") && strings.Contains(isNfePro, "<nfeProc xmlns") {
pathArquivo, nota2 := ProcessarNfeProcNfeProc(xmlByte)
Utilidades.MoverArquivos(arquivo, pathArquivo)
Dao.InserirNfeProc(Dao.COLLECTIONNFEPROC, nota2, conn)
}
// Evento nfe inutilizada
if strings.Contains(isNfePro, "<retInutNFe") {
pathArquivo, inutilizada := ProcessarRetornoNfeInutilizada(xmlByte)
Utilidades.MoverArquivos(arquivo, pathArquivo)
Dao.InserirRetornoNfeInutilizada(Dao.COLLECTIONNFEINUTILIZADA, inutilizada, conn)
}
// Eventos das Nfe
if strings.Contains(isNfePro, "<procEventoNFe") {
pathArquivo, procEventoNfe := ProcessarEventoNfe(xmlByte)
Utilidades.MoverArquivos(arquivo, pathArquivo)
Dao.InserirEventoNfe(Dao.COLLECTIONNFEEVENTO, procEventoNfe, conn)
}
if strings.Contains(isNfePro, "<procEventoCTe") {
pathArquivo, procEventoCte := ProcessarEventoCte(xmlByte)
Utilidades.MoverArquivos(arquivo, pathArquivo)
Dao.InserirEventoCte(Dao.COLLECTIONCTEEVENTO, procEventoCte, conn)
}
if strings.Contains(isNfePro, "<cteProc") {
pathArquivo, procCte := ProcessarCteProc(xmlByte)
Utilidades.MoverArquivos(arquivo, pathArquivo)
Dao.InserirCteProc(Dao.COLLECTIONCTE, procCte, conn)
}
if strings.Contains(isNfePro, "<outrasInfDANFe") {
os.Remove(arquivo)
}
if strings.Contains(isNfePro, "<retConsReciNFe") {
os.Remove(arquivo)
}
if strings.Contains(isNfePro, "<resEvento") {
pathArquivo, resEvento := ProcessarResEvento(xmlByte)
Utilidades.MoverArquivos(arquivo, pathArquivo)
Dao.InserirResEvento(Dao.COLLECTIONRESEVENTO, resEvento, conn)
}
if strings.Contains(isNfePro, "<NFeDFe") {
os.Remove(arquivo)
}
if strings.Contains(isNfePro, "<infEvento") {
os.Remove(arquivo)
}
}