abank 0.2.4 → 0.2.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +7 -21
- data/Gemfile +4 -2
- data/Gemfile.lock +15 -13
- data/README.md +9 -5
- data/Rakefile +4 -2
- data/abank.gemspec +7 -10
- data/bin/console +4 -3
- data/lib/abank.rb +63 -68
- data/lib/abank/big.rb +121 -124
- data/lib/abank/contrato.rb +93 -63
- data/lib/abank/folha.rb +133 -136
- data/lib/abank/rendas.rb +108 -80
- data/lib/abank/version.rb +1 -1
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 84af9c14c7d615540fdb2b6ca02452fc7401fe6ba15e1f67e9cda7b7e1e776c2
|
4
|
+
data.tar.gz: 0d062d44e2a74adc8435e169c79289924b187e222f40b176ed8829e3ee363c2f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 169af6db74fa54a8dddef3cbc504b0e5f1d902c0628df9d4f60b742c6deef19e4a400e7065c2fe9031c4a1f98519991b3a5f84c1ed8cfa7fd01de784bbd677ee
|
7
|
+
data.tar.gz: 11786fa35a4b31532c2b0cea7c728f5e73ad7b0e2a8d95630a941822c7a713fda7848ae263c8d9f4d4550d4942f6741fc796d0b3ec1928930090f46a0fbdb5d7
|
data/.rubocop.yml
CHANGED
@@ -1,29 +1,15 @@
|
|
1
1
|
AllCops:
|
2
|
+
TargetRubyVersion: 2.7
|
2
3
|
EnabledByDefault: true
|
3
4
|
|
4
|
-
Style/ClassAndModuleChildren:
|
5
|
-
EnforcedStyle: compact
|
6
|
-
|
7
5
|
Style/Copyright:
|
8
|
-
|
9
|
-
|
10
|
-
Style/DocumentationMethod:
|
11
|
-
Enabled: false
|
6
|
+
Enabled: false
|
12
7
|
|
13
|
-
|
14
|
-
|
8
|
+
Lint/ConstantResolution:
|
9
|
+
Enabled: false
|
15
10
|
|
16
11
|
Style/ConstantVisibility:
|
17
|
-
|
18
|
-
|
19
|
-
Layout/MultilineMethodArgumentLineBreaks:
|
20
|
-
Enabled: false
|
21
|
-
|
22
|
-
Layout/MultilineHashKeyLineBreaks:
|
23
|
-
Enabled: false
|
24
|
-
|
25
|
-
Layout/FirstMethodParameterLineBreak:
|
26
|
-
Enabled: false
|
12
|
+
Enabled: false
|
27
13
|
|
28
|
-
|
29
|
-
|
14
|
+
Style/EmptyElse:
|
15
|
+
EnforcedStyle: nil
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
abank (0.2.
|
4
|
+
abank (0.2.10)
|
5
5
|
google-cloud-bigquery
|
6
6
|
roo
|
7
7
|
thor
|
@@ -12,20 +12,21 @@ GEM
|
|
12
12
|
specs:
|
13
13
|
addressable (2.7.0)
|
14
14
|
public_suffix (>= 2.0.2, < 5.0)
|
15
|
-
concurrent-ruby (1.1.
|
16
|
-
declarative (0.0.
|
15
|
+
concurrent-ruby (1.1.7)
|
16
|
+
declarative (0.0.20)
|
17
17
|
declarative-option (0.1.0)
|
18
18
|
faraday (1.0.1)
|
19
19
|
multipart-post (>= 1.2, < 3)
|
20
|
-
google-api-client (0.
|
20
|
+
google-api-client (0.45.0)
|
21
21
|
addressable (~> 2.5, >= 2.5.1)
|
22
22
|
googleauth (~> 0.9)
|
23
23
|
httpclient (>= 2.8.1, < 3.0)
|
24
24
|
mini_mime (~> 1.0)
|
25
25
|
representable (~> 3.0)
|
26
26
|
retriable (>= 2.0, < 4.0)
|
27
|
+
rexml
|
27
28
|
signet (~> 0.12)
|
28
|
-
google-cloud-bigquery (1.
|
29
|
+
google-cloud-bigquery (1.23.0)
|
29
30
|
concurrent-ruby (~> 1.0)
|
30
31
|
google-api-client (~> 0.33)
|
31
32
|
google-cloud-core (~> 1.2)
|
@@ -34,10 +35,10 @@ GEM
|
|
34
35
|
google-cloud-core (1.5.0)
|
35
36
|
google-cloud-env (~> 1.0)
|
36
37
|
google-cloud-errors (~> 1.0)
|
37
|
-
google-cloud-env (1.3.
|
38
|
+
google-cloud-env (1.3.3)
|
38
39
|
faraday (>= 0.17.3, < 2.0)
|
39
|
-
google-cloud-errors (1.0.
|
40
|
-
googleauth (0.
|
40
|
+
google-cloud-errors (1.0.1)
|
41
|
+
googleauth (0.13.1)
|
41
42
|
faraday (>= 0.17.3, < 2.0)
|
42
43
|
jwt (>= 1.4, < 3.0)
|
43
44
|
memoist (~> 0.16)
|
@@ -45,22 +46,23 @@ GEM
|
|
45
46
|
os (>= 0.9, < 2.0)
|
46
47
|
signet (~> 0.14)
|
47
48
|
httpclient (2.8.3)
|
48
|
-
jwt (2.2.
|
49
|
+
jwt (2.2.2)
|
49
50
|
memoist (0.16.2)
|
50
51
|
mini_mime (1.0.2)
|
51
52
|
mini_portile2 (2.4.0)
|
52
|
-
multi_json (1.
|
53
|
+
multi_json (1.15.0)
|
53
54
|
multipart-post (2.1.1)
|
54
|
-
nokogiri (1.10.
|
55
|
+
nokogiri (1.10.10)
|
55
56
|
mini_portile2 (~> 2.4.0)
|
56
|
-
os (1.1.
|
57
|
-
public_suffix (4.0.
|
57
|
+
os (1.1.1)
|
58
|
+
public_suffix (4.0.6)
|
58
59
|
rake (12.3.3)
|
59
60
|
representable (3.0.4)
|
60
61
|
declarative (< 0.1.0)
|
61
62
|
declarative-option (< 0.2.0)
|
62
63
|
uber (< 0.2.0)
|
63
64
|
retriable (3.1.2)
|
65
|
+
rexml (3.2.4)
|
64
66
|
roo (2.8.3)
|
65
67
|
nokogiri (~> 1)
|
66
68
|
rubyzip (>= 1.3.0, < 3.0.0)
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Abank [![Build Status](https://travis-ci.com/hernanirvaz/abank.svg?branch=master)](https://travis-ci.com/hernanirvaz/abank)
|
2
2
|
|
3
|
-
Arquiva movimentos conta-corrente, conta-cartao do activobank no bigquery. Permite apagar movimentos
|
3
|
+
Arquiva movimentos conta-corrente, conta-cartao do activobank no bigquery. Permite apagar/recriar movimentos/rendas ja no bigquery. Permite ainda classificar movimentos no bigquery.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -20,10 +20,14 @@ Or install it yourself as:
|
|
20
20
|
|
21
21
|
## Usage
|
22
22
|
|
23
|
-
$ abank
|
24
|
-
$ abank
|
25
|
-
$ abank
|
26
|
-
$ abank
|
23
|
+
$ abank apagamv -k=KEY[,KEY...] # apaga movimentos
|
24
|
+
$ abank apagact -c=CONTRATO # apaga contrato arrendamento
|
25
|
+
$ abank criact -c=CONTRATO # cria contrato arrendamento
|
26
|
+
$ abank recriact -c=CONTRATO # atualiza rendas de contrato arrendamento
|
27
|
+
$ abank recriare # atualiza rendas dos contratos ativos
|
28
|
+
$ abank load # carrega dados da folha calculo
|
29
|
+
$ abank show # mostra dados da folha calculo
|
30
|
+
$ abank tag # classifica movimentos
|
27
31
|
|
28
32
|
## Development
|
29
33
|
|
data/Rakefile
CHANGED
data/abank.gemspec
CHANGED
@@ -10,12 +10,9 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.homepage = 'https://github.com/hernanirvaz/abank'
|
11
11
|
spec.license = 'MIT'
|
12
12
|
|
13
|
-
spec.summary = 'Arquiva
|
14
|
-
|
15
|
-
|
16
|
-
' Pode apagar movimentos similares/existentes' \
|
17
|
-
' ja no bigquery.' \
|
18
|
-
' Pode ainda classificar movimentos ja no bigquery.'
|
13
|
+
spec.summary = 'Arquiva movimentos conta-corrente, conta-cartao do activobank no bigquery.'
|
14
|
+
spec.description = spec.summary + ' Permite apagar/recriar movimentos/rendas ja no bigquery. ' \
|
15
|
+
' Permite ainda classificar movimentos no bigquery.'
|
19
16
|
|
20
17
|
spec.metadata['homepage_uri'] = spec.homepage
|
21
18
|
spec.metadata['yard.run'] = 'yard'
|
@@ -24,10 +21,10 @@ Gem::Specification.new do |spec|
|
|
24
21
|
|
25
22
|
# Specify which files should be added to the gem when it is released.
|
26
23
|
# The `git ls-files -z` loads files in RubyGem that have been added into git.
|
27
|
-
spec.files =
|
28
|
-
|
29
|
-
|
30
|
-
|
24
|
+
spec.files =
|
25
|
+
Dir.chdir(File.expand_path(__dir__)) do
|
26
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
27
|
+
end
|
31
28
|
spec.bindir = 'exe'
|
32
29
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
33
30
|
spec.require_paths = ['lib']
|
data/bin/console
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
|
-
require
|
4
|
-
require
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'abank'
|
5
6
|
|
6
7
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
8
|
# with your gem easier. You can also use a different console, if you like.
|
@@ -10,5 +11,5 @@ require "abank"
|
|
10
11
|
# require "pry"
|
11
12
|
# Pry.start
|
12
13
|
|
13
|
-
require
|
14
|
+
require 'irb'
|
14
15
|
IRB.start(__FILE__)
|
data/lib/abank.rb
CHANGED
@@ -1,100 +1,95 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
3
|
+
require('thor')
|
4
|
+
require('abank/big')
|
5
|
+
require('abank/contrato')
|
6
|
+
require('abank/rendas')
|
7
|
+
require('abank/folha')
|
8
|
+
require('abank/version')
|
9
9
|
|
10
10
|
# @author Hernani Rodrigues Vaz
|
11
11
|
module Abank
|
12
|
-
|
12
|
+
DR = "/home/#{`whoami`.chomp}/Downloads"
|
13
|
+
BD = 'hernanilr.ab'
|
13
14
|
|
14
15
|
class Error < StandardError; end
|
15
16
|
|
16
17
|
# CLI para carregar folhas calculo comuns no bigquery
|
17
18
|
class CLI < Thor
|
18
|
-
desc 'tag', 'classifica movimentos
|
19
|
-
# classifica movimentos
|
19
|
+
desc 'tag', 'classifica movimentos'
|
20
|
+
# classifica movimentos
|
20
21
|
def tag
|
21
|
-
Big.new
|
22
|
+
Big.new.mv_classifica
|
22
23
|
end
|
23
24
|
|
24
|
-
desc '
|
25
|
-
|
26
|
-
|
27
|
-
|
25
|
+
desc 'apagamv', 'apaga movimentos'
|
26
|
+
option :k, banner: 'KEY[,KEY...]', required: true, desc: 'keys movimentos a apagar'
|
27
|
+
# apaga movimentos
|
28
|
+
def apagamv
|
29
|
+
Big.new(k: options[:k]).mv_delete.mv_insert.re_work
|
28
30
|
end
|
29
31
|
|
30
|
-
desc '
|
31
|
-
option :
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
32
|
+
desc 'criact', 'cria contrato arrendamento'
|
33
|
+
option :c, banner: 'CONTRATO', required: true, desc: 'Identificador contrato arrendamento'
|
34
|
+
option :t, type: :boolean, default: true, desc: 'cria todas as rendas?'
|
35
|
+
option :d, banner: 'DATA', default: '', desc: 'data contrato arrendamento'
|
36
|
+
# cria contrato arrendamento
|
37
|
+
def criact
|
38
|
+
Big.new(c: options[:c], t: options[:t], d: options[:d]).ct_cria
|
36
39
|
end
|
37
40
|
|
38
|
-
desc '
|
39
|
-
option :
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
option :
|
48
|
-
|
49
|
-
option :
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
41
|
+
desc 'apagact', 'apaga contrato arrendamento'
|
42
|
+
option :c, banner: 'CONTRATO', required: true, desc: 'Identificador contrato arrendamento'
|
43
|
+
option :t, type: :boolean, default: false, desc: 'apaga todas as rendas?'
|
44
|
+
# apaga contrato arrendamento
|
45
|
+
def apagact
|
46
|
+
Big.new(c: options[:c], t: options[:t]).ct_apaga
|
47
|
+
end
|
48
|
+
|
49
|
+
desc 'recriact', 'atualiza rendas de contrato arrendamento'
|
50
|
+
option :c, banner: 'CONTRATO', required: true, desc: 'Identificador contrato arrendamento'
|
51
|
+
option :t, type: :boolean, default: false, desc: 'apaga todas as rendas?'
|
52
|
+
option :d, banner: 'DATA', default: '', desc: 'data contrato arrendamento'
|
53
|
+
# atualiza rendas de contrato arrendamento
|
54
|
+
def recriact
|
55
|
+
Big.new(c: options[:c], t: options[:t]).ct_apaga
|
56
|
+
Big.new(c: options[:c], t: true, d: options[:d]).ct_cria
|
57
|
+
end
|
58
|
+
|
59
|
+
desc 'recriare', 'atualiza rendas dos contratos ativos'
|
60
|
+
option :t, type: :boolean, default: false, desc: 'atualiza todas as rendas?'
|
61
|
+
# atualiza rendas dos contratos ativos
|
62
|
+
def recriare
|
63
|
+
Big.new(t: options[:t]).re_atualiza
|
64
|
+
end
|
65
|
+
|
66
|
+
desc 'work', 'carrega/apaga dados da folha calculo'
|
67
|
+
option :s, type: :boolean, default: false, desc: 'apaga movimento similar'
|
68
|
+
option :e, type: :boolean, default: false, desc: 'apaga movimento igual'
|
69
|
+
option :v, banner: 'DATA', default: '', desc: 'data valor para movimentos a carregar'
|
70
|
+
option :g, banner: 'TAG', default: '', desc: 'classificacao para movimentos a carregar'
|
71
|
+
# carrega/apaga dados da folha calculo
|
72
|
+
def work
|
73
|
+
Dir.glob("#{DR}/*.xlsx").sort.each do |f|
|
74
|
+
Folha.new(work_opc.merge(f: f)).processa_xls
|
55
75
|
end
|
56
76
|
end
|
57
77
|
|
58
78
|
desc 'show', 'mostra dados da folha calculo'
|
59
|
-
option :d, banner: 'DIR', default: "/home/#{ID}/Downloads",
|
60
|
-
desc: 'Onde procurar folhas calculo'
|
61
79
|
# mostra folha calculo
|
62
80
|
def show
|
63
|
-
Dir.glob("#{
|
64
|
-
|
81
|
+
Dir.glob("#{DR}/*.xlsx").sort.each do |f|
|
82
|
+
Folha.new(f: f).processa_xls
|
65
83
|
end
|
66
84
|
end
|
67
85
|
|
68
|
-
desc 'criare', 'cria contrato arrendamento/rendas no bigquery'
|
69
|
-
option :c, banner: 'CONTRATO', required: true,
|
70
|
-
desc: 'Identificador contrato arrendamento a criar'
|
71
|
-
option :t, type: :boolean, default: true,
|
72
|
-
desc: 'cria todas as rendas?'
|
73
|
-
option :v, banner: 'DATA', default: '',
|
74
|
-
desc: 'data contrato arrendamento a criar'
|
75
|
-
# cria contrato arrendamento/rendas no bigquery
|
76
|
-
def criare
|
77
|
-
Big::Contrato.new(options[:c], { t: options[:t], v: options[:v] }).re_cria
|
78
|
-
end
|
79
|
-
|
80
|
-
desc 'apagare', 'apaga contrato arrendamento/rendas no bigquery'
|
81
|
-
option :c, banner: 'CONTRATO', required: true,
|
82
|
-
desc: 'Identificador contrato arrendamento a apagar'
|
83
|
-
option :t, type: :boolean, default: false,
|
84
|
-
desc: 'apaga todas as rendas?'
|
85
|
-
# apaga contrato arrendamento/rendas no bigquery
|
86
|
-
def apagare
|
87
|
-
Big::Contrato.new(options[:c], { t: options[:t], v: '' }).re_apaga
|
88
|
-
end
|
89
|
-
|
90
86
|
no_commands do
|
91
|
-
# @return [Hash] opcoes trabalho com
|
92
|
-
def
|
93
|
-
{ s: options[:s], e: options[:e],
|
94
|
-
v: options[:v], g: options[:g] }
|
87
|
+
# @return [Hash] opcoes trabalho com movimentos para work
|
88
|
+
def work_opc
|
89
|
+
{ s: options[:s], e: options[:e], i: true, v: options[:v], g: options[:g] }
|
95
90
|
end
|
96
91
|
end
|
97
92
|
|
98
|
-
default_task :
|
93
|
+
default_task :show
|
99
94
|
end
|
100
95
|
end
|
data/lib/abank/big.rb
CHANGED
@@ -1,138 +1,135 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
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
|
-
re_atualiza
|
47
|
-
end
|
48
|
-
|
49
|
-
# (see CLI#atualiza)
|
50
|
-
def re_atualiza
|
51
|
-
r = re_join(lista_ativos)
|
52
|
-
if r.size.zero?
|
53
|
-
puts 'NAO EXISTEM RENDAS NOVAS'
|
54
|
-
else
|
55
|
-
puts 'RENDAS CRIADAS ' + dml('insert hernanilr.ab.re VALUES' + r).to_s
|
3
|
+
require('google/cloud/bigquery')
|
4
|
+
|
5
|
+
module Abank
|
6
|
+
# @see Big
|
7
|
+
class Big
|
8
|
+
DF = '%Y-%m-%d'
|
9
|
+
|
10
|
+
# @return [Hash] opcoes trabalho
|
11
|
+
attr_reader :opcao
|
12
|
+
|
13
|
+
# @return [Google::Cloud::Bigquery] API bigquery
|
14
|
+
attr_reader :bqapi
|
15
|
+
|
16
|
+
# @return [Google::Cloud::Bigquery::QueryJob] job bigquery
|
17
|
+
attr_reader :bqjob
|
18
|
+
|
19
|
+
# @return [Google::Cloud::Bigquery::Data] resultado do select
|
20
|
+
attr_reader :bqres
|
21
|
+
|
22
|
+
# @return [Integer] numero linhas afetadas pela Data Manipulation Language (DML)
|
23
|
+
attr_reader :bqnrs
|
24
|
+
|
25
|
+
# @return [String] movimentos a inserir (values.mv)
|
26
|
+
attr_reader :mvvls
|
27
|
+
|
28
|
+
# @return [String] movimentos a apagar (keysin.mv)
|
29
|
+
attr_reader :mvkys
|
30
|
+
|
31
|
+
# acesso a base dados abank no bigquery
|
32
|
+
#
|
33
|
+
# @param [Hash] opc opcoes trabalho
|
34
|
+
# @option opc [String] :k ('') movimentos a apagar (keysin.mv)
|
35
|
+
# @option opc [String] :c ('') id contrato arrendamento (re)
|
36
|
+
# @option opc [String] :d ('') data inicio contrato arrendamento (re)
|
37
|
+
# @option opc [Boolean] :t (false) trabalha todas as rendas? (re)
|
38
|
+
# @return [Hash] opcoes trabalho
|
39
|
+
def initialize(opc = {})
|
40
|
+
@opcao = opc
|
41
|
+
@bqapi = Google::Cloud::Bigquery.new
|
42
|
+
@mvvls = ''
|
43
|
+
@mvkys = opc.fetch(:k, '')
|
44
|
+
@ctide = opc.fetch(:c, '')
|
45
|
+
opcao
|
56
46
|
end
|
57
|
-
end
|
58
|
-
|
59
|
-
# (see CLI#apagamv)
|
60
|
-
def mv_apaga
|
61
|
-
e = ct_envolvidos
|
62
|
-
i = dml(sql_apaga_mv)
|
63
|
-
puts 'MOVIMENTOS APAGADOS ' + i.to_s
|
64
|
-
return unless i.positive? && e.count.positive?
|
65
47
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
def ct_envolvidos
|
72
|
-
sel(sql_sel_mv).group_by { |r| r[:ct] }
|
73
|
-
.delete_if { |k, _| !k || k[0] != 'r' }.keys
|
74
|
-
end
|
75
|
-
|
76
|
-
# @return [Array<Hash>] lista contratos com lista movimentos novos
|
77
|
-
def lista_ativos
|
78
|
-
sel(sql_ativos_re).map { |c| Contrato.new(c[:ct]).dados_contrato }.compact
|
79
|
-
end
|
80
|
-
|
81
|
-
# @param [Array<Hash>] lct lista contratos com lista movimentos novos
|
82
|
-
# @return [String] row formatada das novas rendas para inserir bigquery
|
83
|
-
def re_join(lct)
|
84
|
-
lct.map { |c| Contrato::Rendas.new(c).rendas }.flatten(1).join(',')
|
85
|
-
end
|
48
|
+
# (see CLI#tag)
|
49
|
+
def mv_classifica
|
50
|
+
dml("update #{BD}.mv set mv.ct=tt.nct from (select * from #{BD}.cl) as tt where #{ky_mv}=tt.ky")
|
51
|
+
puts("MOVIMENTOS CLASSIFICADOS #{bqnrs}")
|
52
|
+
end
|
86
53
|
|
87
|
-
|
88
|
-
|
89
|
-
|
54
|
+
# apaga movimentos & suas rendas associadas no bigquery
|
55
|
+
#
|
56
|
+
# @return [Big] acesso a base dados abank no bigquery
|
57
|
+
def mv_delete
|
58
|
+
vars_mv_work
|
59
|
+
if mvkys.size.positive?
|
60
|
+
# obtem lista contratos arrendamento associados aos movimentos a apagar
|
61
|
+
@ctlct = sql("select ct from #{BD}.mv where #{ky_mv} in(#{mvkys}) and substr(ct,1,1)='r' group by 1")
|
62
|
+
|
63
|
+
# apaga rendas associadas e depois movimentos
|
64
|
+
@opcao[:t] = true
|
65
|
+
lr_apaga.mv_delete_dml
|
66
|
+
|
67
|
+
# para obrigar re_work a trabalhar com lista contratos (ctlct)
|
68
|
+
@bqnrs = 0
|
69
|
+
else
|
70
|
+
end
|
71
|
+
self
|
72
|
+
end
|
90
73
|
|
91
|
-
|
92
|
-
|
93
|
-
|
74
|
+
# insere & classifica movimentos no bigquery
|
75
|
+
#
|
76
|
+
# @return [Big] acesso a base dados abank no bigquery
|
77
|
+
def mv_insert
|
78
|
+
if mvvls.size.positive?
|
79
|
+
dml("insert #{BD}.mv VALUES#{mvvls}")
|
80
|
+
puts("MOVIMENTOS INSERIDOS #{bqnrs}")
|
81
|
+
mv_classifica if bqnrs.positive?
|
82
|
+
else
|
83
|
+
end
|
84
|
+
self
|
85
|
+
end
|
94
86
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
87
|
+
# inicializa variaveis para delete/insert movimentos
|
88
|
+
def vars_mv_work
|
89
|
+
@bqnrs = 0
|
90
|
+
@ctlct = []
|
91
|
+
@mvkys = mvkys[1..] if mvkys[0] == ','
|
92
|
+
@mvvls = mvvls[1..] if mvvls[0] == ','
|
93
|
+
end
|
99
94
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
95
|
+
# apaga movimentos no bigquery
|
96
|
+
def mv_delete_dml
|
97
|
+
dml("delete from #{BD}.mv where #{ky_mv} in(#{mvkys})")
|
98
|
+
puts("MOVIMENTOS APAGADOS #{bqnrs}")
|
99
|
+
end
|
104
100
|
|
105
|
-
|
106
|
-
|
107
|
-
'ds,CAST(dl as STRING),CAST(vl as STRING)))'
|
108
|
-
|
101
|
+
# @return [String] expressao sql da chave de movimentos
|
102
|
+
def ky_mv
|
103
|
+
'FARM_FINGERPRINT(CONCAT(CAST(mv.nc as STRING),mv.ds,CAST(mv.dl as STRING),CAST(mv.vl as STRING)))'
|
104
|
+
end
|
109
105
|
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
106
|
+
# cria job bigquery & verifica execucao
|
107
|
+
#
|
108
|
+
# @param [String] cmd comando a executar
|
109
|
+
# @return [Boolean] job ok?
|
110
|
+
def job?(cmd)
|
111
|
+
# p cmd
|
112
|
+
@bqjob = bqapi.query_job(cmd)
|
113
|
+
@bqjob.wait_until_done!
|
114
|
+
puts(@bqjob.error['message']) if @bqjob.failed?
|
115
|
+
@bqjob.failed?
|
116
|
+
end
|
121
117
|
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
118
|
+
# executa sql & devolve resultado do bigquery
|
119
|
+
#
|
120
|
+
# @param (see job?)
|
121
|
+
# @param [Array] erro quando da erro no bigquery
|
122
|
+
# @return [Google::Cloud::Bigquery::Data] resultado do sql
|
123
|
+
def sql(cmd, erro = [])
|
124
|
+
@bqres = job?(cmd) ? erro : bqjob.data
|
125
|
+
end
|
129
126
|
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
127
|
+
# executa Data Manipulation Language (DML) no bigquery
|
128
|
+
#
|
129
|
+
# @param (see job?)
|
130
|
+
# @return [Integer] numero rows afetadas pelo dml
|
131
|
+
def dml(cmd)
|
132
|
+
@bqnrs = job?(cmd) ? 0 : bqjob.num_dml_affected_rows
|
133
|
+
end
|
137
134
|
end
|
138
135
|
end
|