From a8daeabffbf39364230544a36ba8ee725bcd8c83 Mon Sep 17 00:00:00 2001 From: Leonardo Domingues Date: Mon, 8 Nov 2021 10:32:29 -0300 Subject: [PATCH] =?UTF-8?q?Fun=C3=A7=C3=A3o=20para=20contar=20execu=C3=A7?= =?UTF-8?q?=C3=B5es=20mensais=20de=20rob=C3=B4s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/dataapi/lib.go | 47 +++++++++++++++++++++++++++++++++++++++++ api/dataapi/lib_test.go | 45 --------------------------------------- 2 files changed, 47 insertions(+), 45 deletions(-) diff --git a/api/dataapi/lib.go b/api/dataapi/lib.go index aae3cc4..1909cc3 100644 --- a/api/dataapi/lib.go +++ b/api/dataapi/lib.go @@ -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) + } + } +} diff --git a/api/dataapi/lib_test.go b/api/dataapi/lib_test.go index 7c03e6a..953ff4f 100644 --- a/api/dataapi/lib_test.go +++ b/api/dataapi/lib_test.go @@ -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) -}*/