Função para contar execuções mensais de robôs

master
Leonardo Domingues 2021-11-08 10:32:29 -03:00
parent f8acbf0c03
commit a8daeabffb
2 changed files with 47 additions and 45 deletions

View File

@ -1,6 +1,9 @@
package dataapi
import (
"strconv"
"time"
"go.digitalcircle.com.br/open/httpcli"
)
@ -58,3 +61,47 @@ func LCR_Create() {
panic(err)
}
}
func RegistrarExec(table string) {
//Para robôs, age como contador e registra cada repetição no mês
c := NewCli("RnJpIDA1IE5vdiAyMDIxIDExOjE1OjIyIEFNIFVUQwo")
current := time.Now().Format("2006-01")
res, err := c.Do(&DataAPIRequest{
Col: table,
Op: RETRIEVE,
Q: "@[?date=='" + current + "']",
})
if err != nil {
panic(err)
}
if len(res.Data) > 0 {
result := res.Data[0].(map[string]interface{})
registros := result["exec"].(float64)
registros = registros + 1
ident := strconv.Itoa(int(result["ID"].(float64)))
_, err = c.Do(&DataAPIRequest{
Col: table,
Op: UPDATE,
Id: ident,
Data: map[string]interface{}{
"exec": registros,
},
})
if err != nil {
panic(err)
}
} else {
_, err = c.Do(&DataAPIRequest{
Col: table,
Op: CREATE,
Data: map[string]interface{}{
"date": current,
"exec": 1,
},
})
if err != nil {
panic(err)
}
}
}

View File

@ -98,48 +98,3 @@ func LCR_Create(t *testing.T) {
log.Printf("%#v", res)
}
/*func CreateControl(t *testing.T, table string) {
c := dataapi.NewCli("RnJpIDA1IE5vdiAyMDIxIDExOjE1OjIyIEFNIFVUQwo")
current := time.Now().Format("2006-01")
res, err := c.Do(&dataapi.DataAPIRequest{
Col: table,
Op: dataapi.CREATE,
Data: map[string]interface{}{
"date": current,
"qtd": 0,
},
})
if err != nil {
t.Fatal(err.Error())
}
log.Printf("%#v", res)
}
func UpdateControl(t *testing.T, table string) {
c := dataapi.NewCli("RnJpIDA1IE5vdiAyMDIxIDExOjE1OjIyIEFNIFVUQwo")
current := time.Now().Format("2006-01")
res, err := c.Do(&dataapi.DataAPIRequest{
Col: table,
Op: dataapi.RETRIEVE,
Q: "@[?date=="+current+"]",
})
if err != nil {
t.Fatal(err.Error())
}
res.Data()[0]
res, err := c.Do(&dataapi.DataAPIRequest{
Col: "C1",
Op: dataapi.UPDATE,
Id: "2",
Data: map[string]interface{}{
"F2": "Novo Campo",
},
})
if err != nil {
t.Fatal(err.Error())
}
log.Printf("%#v", res)
}*/