-
Notifications
You must be signed in to change notification settings - Fork 0
/
res_bank.go
79 lines (69 loc) · 1.68 KB
/
res_bank.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
package odooconn
import (
"fmt"
"strings"
"sync"
"github.com/schollz/progressbar/v3"
)
func (o *OdooConn) ResPartnerBank() {
mdl := "res_bank"
umdl := strings.Replace(mdl, "_", ".", -1)
fmt.Printf("\n%v ResPartnerBank\n", umdl)
sem := make(chan int, o.JobCount)
var wg sync.WaitGroup
stmt := `
select distinct
upper(trim(bnka.banka)) as "name"
,upper(trim(bnka.stras)) as street
,upper(trim(bnka.ort01)) as city
,trim(s."name") as state
,trim(c."name") as country
,trim(bnka.bankl) as bic
,trim(bnka.swift) as swift
from sap.bnka bnka
join ct.state s on bnka.provz = s.state
join ct.country c on bnka.banks = c.country
order by trim(bnka.bankl)
`
type Bank struct {
Name string `db:"name"`
Street string `db:"street"`
City string `db:"city"`
State string `db:"state"`
Country string `db:"country"`
BIC string `db:"bic"`
SWIFT string `db:"swift"`
}
var rr []Bank
err := o.DB.Select(&rr, stmt)
o.checkErr(err)
recs := len(rr)
bar := progressbar.Default(int64(recs))
// tasker
wg.Add(len(rr))
for _, v := range rr {
go func(sem chan int, wg *sync.WaitGroup, bar *progressbar.ProgressBar, v Bank) {
defer bar.Add(1)
defer wg.Done()
sem <- 1
cid, err := o.CountryID(v.Country)
o.checkErr(err)
sid, err := o.StateID(cid, v.State)
o.checkErr(err)
r, err := o.GetID(umdl, oarg{oarg{"name", "=", v.Name}, oarg{"bic", "=", v.BIC}})
o.checkErr(err)
ur := map[string]interface{}{
"name": v.Name,
"street": v.Street,
"city": v.City,
"state": sid,
"country": cid,
"bic": v.BIC,
}
o.Log.Info(umdl, "record", ur, "r", r)
o.Record(umdl, r, ur)
<-sem
}(sem, &wg, bar, v)
}
wg.Wait()
}