-
Notifications
You must be signed in to change notification settings - Fork 0
/
hr_department.go
70 lines (58 loc) · 1.64 KB
/
hr_department.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
package odooconn
import (
"fmt"
"strings"
"sync"
"github.com/schollz/progressbar/v3"
)
// HRDepartment function
func (o *OdooConn) HRDepartment() {
mdl := "hr_department"
umdl := strings.Replace(mdl, "_", ".", -1)
fmt.Printf("\n%v\n", umdl)
sem := make(chan int, o.JobCount)
var wg sync.WaitGroup
stmt := `
select distinct
case when u.physicaldeliveryofficename = 'Montreal' then 'Groupe A.R. Thomson' when u.company = 'Delpro' then 'DelPro Automation Inc.' else u.company end company
,u.department
from artg.users u
where u.company like any(array['A.R%','Del%'])
and u.msexchresourcedisplay <> 'Room'
and u.physicaldeliveryofficename not in ('','Datacenter','Consultant','Inactive')
and u.department not in ('','Datacenter','Inactive')
and u.name not like '%Superlok'
and u.name not like '%Delpro'
order by company,u.department
`
type HRDept struct {
Company string `db:"company"`
Department string `db:"department"`
}
dd := []HRDept{}
err := o.DB.Select(&dd, stmt)
o.checkErr(err)
recs := len(dd)
bar := progressbar.Default(int64(recs))
cids := o.ResCompanyMap()
// tasker
wg.Add(len(dd))
for _, u := range dd {
go func(sem chan int, wg *sync.WaitGroup, bar *progressbar.ProgressBar, u HRDept) {
defer bar.Add(1)
defer wg.Done()
sem <- 1
company_id := cids[u.Company]
r, err := o.GetID(umdl, oarg{oarg{"name", "=", u.Department}, oarg{"company_id", "=", company_id}})
o.checkErr(err)
ur := map[string]interface{}{
"name": u.Department,
"company_id": company_id,
}
o.Log.Info(umdl, "u", u, "record", ur, "r", r)
o.Record(umdl, r, ur)
<-sem
}(sem, &wg, bar, u)
}
wg.Wait()
}