Merge remote-tracking branch 'origin/master'

master
Paulo Simão 2021-11-20 09:21:29 -03:00
commit ccae321dc9
5 changed files with 226 additions and 14 deletions

View File

@ -1,6 +1,9 @@
package dataapi package dataapi
import ( import (
"strconv"
"time"
"go.digitalcircle.com.br/open/httpcli" "go.digitalcircle.com.br/open/httpcli"
) )
@ -43,3 +46,91 @@ func NewCli(apikey string) *Cli {
ret.Httpcli.SetBasePath("https://dataapi.digitalcircle.com.br") ret.Httpcli.SetBasePath("https://dataapi.digitalcircle.com.br")
return ret return ret
} }
func LCR_Create() {
c := NewCli("RnJpIDA1IE5vdiAyMDIxIDExOjE1OjIyIEFNIFVUQwo")
_, err := c.Do(&DataAPIRequest{
Col: "LCR_Bot",
Op: CREATE,
Data: map[string]interface{}{
"Registro": "1",
},
})
if err != nil {
panic(err)
}
}
func RegistrarExec(table string, check bool) {
//Para robôs, age como contador e registra cada repetição no mês
c := NewCli("RnJpIDA1IE5vdiAyMDIxIDExOjE1OjIyIEFNIFVUQwo")
var registros int
var erro int
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 {
if check {
result := res.Data[0].(map[string]interface{})
registros = int(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 {
result := res.Data[0].(map[string]interface{})
registros = int(result["err"].(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{}{
"err": registros,
},
})
if err != nil {
panic(err)
}
}
} else {
if check {
registros = 1
erro = 0
} else {
registros = 0
erro = 1
}
_, err = c.Do(&DataAPIRequest{
Col: table,
Op: CREATE,
Data: map[string]interface{}{
"date": current,
"exec": registros,
"err": erro,
},
})
if err != nil {
panic(err)
}
}
}

View File

@ -1,15 +1,18 @@
package dataapi_test package dataapi_test
import ( import (
"go.digitalcircle.com.br/open/replaycli-go/api/dataapi"
"log" "log"
"strconv"
"testing" "testing"
"time"
"go.digitalcircle.com.br/open/replaycli-go/api/dataapi"
) )
func TestAPIRetrieve(t *testing.T) { func TestAPIRetrieve(t *testing.T) {
c := dataapi.NewCli("RnJpIDA1IE5vdiAyMDIxIDExOjE1OjIyIEFNIFVUQwo") c := dataapi.NewCli("RnJpIDA1IE5vdiAyMDIxIDExOjE1OjIyIEFNIFVUQwo")
res, err := c.Do(&dataapi.DataAPIRequest{ res, err := c.Do(&dataapi.DataAPIRequest{
Col: "C1", Col: "teste3",
Op: dataapi.RETRIEVE, Op: dataapi.RETRIEVE,
}) })
if err != nil { if err != nil {
@ -65,18 +68,78 @@ func TestAPIDelete(t *testing.T) {
} }
func TestAPICreate(t *testing.T) { func TestAPICreate(t *testing.T) {
if true {
print("a")
print("b")
}
c := dataapi.NewCli("RnJpIDA1IE5vdiAyMDIxIDExOjE1OjIyIEFNIFVUQwo") c := dataapi.NewCli("RnJpIDA1IE5vdiAyMDIxIDExOjE1OjIyIEFNIFVUQwo")
var registros int
var erro int
current := time.Now().Format("2006-01")
res, err := c.Do(&dataapi.DataAPIRequest{ res, err := c.Do(&dataapi.DataAPIRequest{
Col: "C1", Col: "teste3",
Op: dataapi.CREATE, Op: dataapi.RETRIEVE,
Q: "@[?date=='" + current + "']",
})
if err != nil {
panic(err)
}
check := false
if len(res.Data) > 0 {
if check {
result := res.Data[0].(map[string]interface{})
registros = int(result["exec"].(float64))
registros = registros + 1
ident := strconv.Itoa(int(result["ID"].(float64)))
_, err = c.Do(&dataapi.DataAPIRequest{
Col: "teste3",
Op: dataapi.UPDATE,
Id: ident,
Data: map[string]interface{}{ Data: map[string]interface{}{
"MSG": "OI LEO", "exec": registros,
}, },
}) })
if err != nil { if err != nil {
t.Fatal(err.Error()) panic(err)
} }
} else {
result := res.Data[0].(map[string]interface{})
registros = int(result["err"].(float64))
registros = registros + 1
ident := strconv.Itoa(int(result["ID"].(float64)))
log.Printf("%#v", res) _, err = c.Do(&dataapi.DataAPIRequest{
Col: "teste3",
Op: dataapi.UPDATE,
Id: ident,
Data: map[string]interface{}{
"err": registros,
},
})
if err != nil {
panic(err)
}
}
} else {
if check {
registros = 1
erro = 0
} else {
registros = 0
erro = 1
}
_, err = c.Do(&dataapi.DataAPIRequest{
Col: "teste3",
Op: dataapi.CREATE,
Data: map[string]interface{}{
"date": current,
"exec": registros,
"err": erro,
},
})
if err != nil {
panic(err)
}
}
} }

View File

@ -10,9 +10,53 @@ type Cli struct {
*api.ApiCli *api.ApiCli
} }
//func (c *Cli) HttpCli() *api.Cli { const (
// return c.cli CCHDEVICENAME = 32
//} CCHFORMNAME = 32
ENUM_CURRENT_SETTINGS uint32 = 0xFFFFFFFF
ENUM_REGISTRY_SETTINGS uint32 = 0xFFFFFFFE
DISP_CHANGE_SUCCESSFUL uint32 = 0
DISP_CHANGE_RESTART uint32 = 1
DISP_CHANGE_FAILED uint32 = 0xFFFFFFFF
DISP_CHANGE_BADMODE uint32 = 0xFFFFFFFE
)
type DEVMODE struct {
DmDeviceName [CCHDEVICENAME]uint16
DmSpecVersion uint16
DmDriverVersion uint16
DmSize uint16
DmDriverExtra uint16
DmFields uint32
DmOrientation int16
DmPaperSize int16
DmPaperLength int16
DmPaperWidth int16
DmScale int16
DmCopies int16
DmDefaultSource int16
DmPrintQuality int16
DmColor int16
DmDuplex int16
DmYResolution int16
DmTTOption int16
DmCollate int16
DmFormName [CCHFORMNAME]uint16
DmLogPixels uint16
DmBitsPerPel uint32
DmPelsWidth uint32
DmPelsHeight uint32
DmDisplayFlags uint32
DmDisplayFrequency uint32
DmICMMethod uint32
DmICMIntent uint32
DmMediaType uint32
DmDitherType uint32
DmReserved1 uint32
DmReserved2 uint32
DmPanningWidth uint32
DmPanningHeight uint32
}
func (c *Cli) ClipRead() (string, error) { func (c *Cli) ClipRead() (string, error) {
ret := "" ret := ""
@ -208,11 +252,23 @@ func (c *Cli) ScreenRes() ([]byte, error) {
} }
return ret, err return ret, err
} }
func (c *Cli) ScreenSetRes(x, y, cor int) error { func (c *Cli) ScreenSetRes(x, y, cor int) error {
err := c.HttpCli().JsonGet(fmt.Sprintf("/ipc/wingui/screen/setres?x=%d&y=%d&c=%d", x, y, cor), nil) err := c.HttpCli().JsonGet(fmt.Sprintf("/ipc/wingui/screen/setres?x=%d&y=%d&c=%d", x, y, cor), nil)
return err return err
} }
func (c *Cli) DisplayRes() (*DEVMODE, error) {
ret := &DEVMODE{}
err := c.HttpCli().JsonGet("/ipc/wingui/display/res", ret)
return ret, err
}
func (c *Cli) DisplaySetRes(d *DEVMODE) error {
err := c.HttpCli().JsonPost("/ipc/wingui/display/setres", d, nil)
return err
}
func NewCli() *Cli { func NewCli() *Cli {
ret := &Cli{ApiCli: api.NewApiCli()} ret := &Cli{ApiCli: api.NewApiCli()}
return ret return ret

2
go.mod
View File

@ -10,5 +10,5 @@ require (
github.com/gorilla/websocket v1.4.2 github.com/gorilla/websocket v1.4.2
github.com/mitchellh/go-ps v1.0.0 github.com/mitchellh/go-ps v1.0.0
go.digitalcircle.com.br/open/httpcli v0.0.0-20211031093505-ecf33aed8afb go.digitalcircle.com.br/open/httpcli v0.0.0-20211031093505-ecf33aed8afb
golang.org/x/sys v0.0.0-20211031064116-611d5d643895 // indirect golang.org/x/sys v0.0.0-20211106132015-ebca88c72f68 // indirect
) )

2
go.sum
View File

@ -21,3 +21,5 @@ golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac h1:oN6lz7iLW/YC7un8pq+9bOLyX
golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211031064116-611d5d643895 h1:iaNpwpnrgL5jzWS0vCNnfa8HqzxveCFpFx3uC/X4Tps= golang.org/x/sys v0.0.0-20211031064116-611d5d643895 h1:iaNpwpnrgL5jzWS0vCNnfa8HqzxveCFpFx3uC/X4Tps=
golang.org/x/sys v0.0.0-20211031064116-611d5d643895/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211031064116-611d5d643895/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211106132015-ebca88c72f68 h1:Ywe/f3fNleF8I6F6qv3MeFoSZ6CTf2zBMMa/7qVML8M=
golang.org/x/sys v0.0.0-20211106132015-ebca88c72f68/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=