Last active
August 29, 2015 14:16
-
-
Save jonatasemidio/1ed6a076ff1f9e4c0214 to your computer and use it in GitHub Desktop.
ConversorTipoBDToJava.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
arquivos = | |
[ | |
[ | |
bloco:'1#Dados Origem do Tipo Informação = 1 (Contrato)', | |
detalhes:[ | |
'Tipo Registro | Num | 1 | Identifica o tipo do registro: 0 = Header 1 = Detalhe 9 = Trailer', | |
'Elemento | Char | 4 | Sigla do elemento (centro de custo) ', | |
'Data Movimento | Num | 8 | Data de Movimento ', | |
'Filler | Char | 367 | Filler ' | |
] | |
] | |
] | |
def processa(arquivos) { | |
StringBuilder sb = new StringBuilder() | |
arquivos.each{ | |
sb.append "//Bloco $it.bloco" | |
sb.append "\n" | |
sb.append "private void montaContratoBloco${it.bloco.split('#')[0]}(ArquivoFactory arquivoFactory, ContratoVO contrato, String tipoRegistro) {" | |
sb.append "\n" | |
sb.append " montaContratoBlocoDetalhe(arquivoFactory, contrato, tipoRegistro);" | |
sb.append "\n" | |
processaArquivo(it, sb) | |
sb.append "\n" | |
sb.append " arquivoFactory.quebraLinha();" | |
sb.append "\n" | |
sb.append "}" | |
} | |
sb | |
} | |
def processaArquivo(arquivo, sb) { | |
arquivo.detalhes.each{ | |
itens = it.split("\\|") | |
type = itens[1].trim() | |
size = itens[2].trim() as Integer | |
quot = "[${itens[0].trim()}] ${itens[3].trim()}" | |
sb.append " arquivoFactory.${type =='Num' ? 'numero' : 'texto'}(\"\", $size ); // ${quot}" | |
sb.append "\n" | |
} | |
sb | |
} | |
println processa(arquivos) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
lista = | |
[] | |
def converte(String texto) { | |
options = [] | |
options = texto.replace('(', ' ').replace(')', ' ').trim().split(' ') | |
tipo = options.first() | |
tamanho = options.last() | |
println "arquivoFactory.${tipo=='DECIMAL' ? 'numero' : 'texto'}(\"\", $tamanho); //" | |
} | |
println lista.each{ converte(it) } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
l = | |
[ | |
['Numérico ','0001 ' ], | |
['Numérico ','0009 ' ], | |
['Numérico ','0003 ' ], | |
['Numérico ','0002 ' ], | |
['Numérico ','0010 ' ], | |
['Alfanumérico',' 0001'], | |
['Alfanumérico',' 0004'], | |
['Alfanumérico',' 0010'], | |
['Numérico ','0004 ' ], | |
['Alfanumérico',' 0054'], | |
['Numérico ','0009 ' ], | |
['Numérico ','0010 ' ], | |
['Alfanumérico',' 0001'], | |
['Numérico ','0005 ' ], | |
['Alfanumérico',' 0010'], | |
['Alfanumérico',' 0005'], | |
['Alfanumérico',' 0928'] | |
] | |
println l.each { | |
type = it[0].trim() | |
size = it[1].trim() as Integer | |
println "arquivoFactory.${type =='Numérico' ? 'numero' : 'texto'}(\"X\", $size ); //" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
arquivos = | |
[ | |
[ | |
bloco:9, | |
detalhes:[ | |
'Numérico |00005 |Categoria ', | |
'Alfanumérico| 00001|Indicador ', | |
'Numérico |00009 |CNPJ ', | |
'Alfanumérico| 00001|Retorno', | |
'Numérico |00004 |CNPJ ', | |
'Alfanumérico| 00001|Retorno', | |
'Numérico |00002 |CNPJ ', | |
'Alfanumérico| 00001|Retorno', | |
'Alfanumérico| 00070|Razão Social ', | |
'Alfanumérico| 00001|Retorno', | |
'Numérico |00005 |Profissão ', | |
'Alfanumérico| 00001|Retorno', | |
'Numérico |00005 |Cargo ', | |
'Alfanumérico| 00001|Retorno', | |
'Alfanumérico| 00010|Data ', | |
'Alfanumérico| 00001|Retorno', | |
'Numérico |00006 |"Atividade" ', | |
'Alfanumérico| 00001|Retorno', | |
'Numérico |00015 |Renda ', | |
'Alfanumérico| 00001|Retorno', | |
'Alfanumérico| 00001|Renda? ', | |
'Alfanumérico| 00001|Retorno', | |
'Numérico |00002 |Periodicidade ', | |
'Alfanumérico| 00001|Retorno', | |
'Alfanumérico| 00010|Demissão ', | |
'Alfanumérico| 00001|Retorno', | |
'Alfanumérico| 00004|DDD ', | |
'Alfanumérico| 00001|Retorno - ', | |
'Numérico |00011 | Telefone ', | |
'Alfanumérico| 00001|Retorno', | |
'Alfanumérico| 00754|Espaços ' | |
] | |
] | |
] | |
def processa(arquivos) { | |
StringBuilder sb = new StringBuilder() | |
arquivos.each{ | |
sb.append "//Bloco $it.bloco" | |
sb.append "\n" | |
sb.append "private void montaPessoaBloco${it.bloco}(ArquivoFactory arquivoFactory, PessoaVO pessoa) {" | |
sb.append "\n" | |
processaArquivo(it, sb) | |
sb.append "\n" | |
sb.append " arquivoFactory.quebraLinha();" | |
sb.append "\n" | |
sb.append "}" | |
} | |
sb | |
} | |
def processaArquivo(arquivo, sb) { | |
arquivo.detalhes.each{ | |
itens = it.split("\\|") | |
type = itens[0].trim() | |
size = itens[1].trim() as Integer | |
quot = itens[2].trim() | |
sb.append " arquivoFactory.${type =='Numérico' ? 'numero' : 'texto'}(\"X\", $size ); // ${quot}" | |
sb.append "\n" | |
} | |
sb | |
} | |
println processa(arquivos) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment