abank 0.2.2 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/abank.rb +31 -5
- data/lib/abank/bigquery.rb +45 -6
- data/lib/abank/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 90945827ff39ea567dd16f073018ef56215da38498e9ca317a2aff12a23e9a6d
|
4
|
+
data.tar.gz: a2797459015e62c0a3bacc5eb2897ca58b52be346d885ce2494d9dd81cc08ba0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 87b7130b7a34943a80dad48903c083b5a06074f35d951575d435d4c4f58a466141bf0ef3021bca22515110e14cd179c64d7991292207d1fb029e309832d3258b
|
7
|
+
data.tar.gz: 48562e6cdae584b35bacea3c9a7ab5149922c244fe1b6248b57527577c288675e2da1b9eb082e7bd5ee9bb075b26199a34368e52cc3a3d18bcf575e9369fd6c7
|
data/Gemfile.lock
CHANGED
data/lib/abank.rb
CHANGED
@@ -45,17 +45,43 @@ module Abank
|
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
|
-
desc 'classifica', 'classifica
|
49
|
-
# classifica
|
48
|
+
desc 'classifica', 'classifica movimentos no bigquery'
|
49
|
+
# classifica movimentos no bigquery
|
50
50
|
def classifica
|
51
|
-
Bigquery.new.classifica
|
51
|
+
Bigquery.new('', { i: true }).classifica
|
52
|
+
end
|
53
|
+
|
54
|
+
desc 'atualiza', 'atualiza rendas no arquivo bigquery'
|
55
|
+
# atualiza rendas no arquivo bigquery
|
56
|
+
def atualiza
|
57
|
+
Bigquery.new.atualiza
|
58
|
+
end
|
59
|
+
|
60
|
+
desc 'cria', 'cria contrato arrendamento/rendas no arquivo bigquery'
|
61
|
+
option :r, banner: 'REN', required: true,
|
62
|
+
desc: 'identificador contrato arrendamento a criar'
|
63
|
+
option :t, type: :boolean, default: false,
|
64
|
+
desc: 'trabalha com renda inicio ou todas'
|
65
|
+
# cria contrato arrendamento/rendas no arquivo bigquery
|
66
|
+
def cria
|
67
|
+
Bigquery.new('', { r: options[:r], t: options[:t] }).cria
|
68
|
+
end
|
69
|
+
|
70
|
+
desc 'apaga', 'apaga contrato arrendamento/rendas no arquivo bigquery'
|
71
|
+
option :r, banner: 'REN', required: true,
|
72
|
+
desc: 'identificador contrato arrendamento a apagar'
|
73
|
+
option :t, type: :boolean, default: false,
|
74
|
+
desc: 'trabalha com renda inicio ou todas'
|
75
|
+
# apaga contrato arrendamento/rendas no arquivo bigquery
|
76
|
+
def apaga
|
77
|
+
Bigquery.new('', { r: options[:r], t: options[:t] }).apaga
|
52
78
|
end
|
53
79
|
|
54
80
|
no_commands do
|
55
81
|
# @return [Hash] ops opcoes trabalho com linhas para load
|
56
82
|
def load_ops
|
57
|
-
{ s: options[:s], e: options[:e],
|
58
|
-
|
83
|
+
{ s: options[:s], e: options[:e], m: options[:m],
|
84
|
+
i: true, t: false, n: options[:n], r: '' }
|
59
85
|
end
|
60
86
|
end
|
61
87
|
|
data/lib/abank/bigquery.rb
CHANGED
@@ -30,11 +30,13 @@ module Abank
|
|
30
30
|
# @option ops [Boolean] :e (false) apaga linha igual?
|
31
31
|
# @option ops [Boolean] :m (false) apaga linhas existencia multipla?
|
32
32
|
# @option ops [Boolean] :i (false) insere linha nova?
|
33
|
+
# @option ops [Boolean] :t (false) apaga rendas totalmente?
|
33
34
|
# @option ops [Numeric] :n (0) numero dias correcao para data valor
|
35
|
+
# @option ops [String] :r identificador contrato arrendamento
|
34
36
|
# @return [Bigquery] acesso folhas calculo activobank
|
35
37
|
# & correspondente bigquery dataset
|
36
38
|
def initialize(xls = '', ops = { s: false, e: false, m: false,
|
37
|
-
i: false, n: 0 })
|
39
|
+
i: false, t: false, n: 0, r: '' })
|
38
40
|
# usa env GOOGLE_APPLICATION_CREDENTIALS para obter credentials
|
39
41
|
# @see https://cloud.google.com/bigquery/docs/authentication/getting-started
|
40
42
|
@apibq = Google::Cloud::Bigquery.new
|
@@ -72,6 +74,7 @@ module Abank
|
|
72
74
|
# @param (see job_bigquery?)
|
73
75
|
# @return [Integer] numero linhas afetadas
|
74
76
|
def dml(sql)
|
77
|
+
p sql
|
75
78
|
job_bigquery?(sql) ? 0 : job.num_dml_affected_rows
|
76
79
|
end
|
77
80
|
|
@@ -96,14 +99,50 @@ module Abank
|
|
96
99
|
def classifica
|
97
100
|
return unless linha[:i]
|
98
101
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
102
|
+
i = dml('update hernanilr.ab.mv set mv.ct=tt.nct' \
|
103
|
+
' from (select * from hernanilr.ab.cl) as tt' \
|
104
|
+
' where mv.dl=tt.dl and mv.dv=tt.dv' \
|
105
|
+
' and mv.ds=tt.ds and mv.vl=tt.vl')
|
106
|
+
puts 'LINHAS CLASSIFICADAS ' + i.to_s
|
107
|
+
return unless i.positive?
|
108
|
+
|
109
|
+
atualiza
|
110
|
+
end
|
111
|
+
|
112
|
+
# (see CLI#atualiza)
|
113
|
+
def atualiza
|
104
114
|
puts 'RENDAS INSERIDAS ' + esp('call hernanilr.ab.rendas()').to_s
|
105
115
|
end
|
106
116
|
|
117
|
+
# (see CLI#cria)
|
118
|
+
def cria
|
119
|
+
i = dml('insert into hernanilr.ab.re ' + sql_contrato)
|
120
|
+
puts i.zero? ? 'NAO EXISTE CONTRATO' : 'CONTRATO INSERIDO'
|
121
|
+
return unless i.positive? && linha[:t]
|
122
|
+
|
123
|
+
atualiza
|
124
|
+
end
|
125
|
+
|
126
|
+
# @return [String] sql obtem dados inicio contrato arrendamento
|
127
|
+
def sql_contrato
|
128
|
+
'select ct,EXTRACT(YEAR FROM DATE_TRUNC(dl,MONTH)) as ano,0 as cnt' \
|
129
|
+
',DATE_TRUNC(dl,MONTH) as dl,0 dias' \
|
130
|
+
' from hernanilr.ab.mv' \
|
131
|
+
" where ct='#{linha[:r]}' " \
|
132
|
+
'order by dl limit 1'
|
133
|
+
end
|
134
|
+
|
135
|
+
# (see CLI#apaga)
|
136
|
+
def apaga
|
137
|
+
puts 'RENDAS APAGADAS ' + dml(sql_apaga).to_s
|
138
|
+
end
|
139
|
+
|
140
|
+
# @return [String] sql apaga rendas
|
141
|
+
def sql_apaga
|
142
|
+
"delete from hernanilr.ab.re where ct='#{linha[:r]}'" +
|
143
|
+
(linha[:t] ? '' : ' and cnt>0')
|
144
|
+
end
|
145
|
+
|
107
146
|
# @return [Integer] numero linhas inseridas
|
108
147
|
def sql_insert
|
109
148
|
return 1 unless linha[:i]
|
data/lib/abank/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: abank
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hernâni Rodrigues Vaz
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-05-
|
11
|
+
date: 2020-05-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|