From 01b5e854a7fac028a9ec68f3eccc103e0c2ffc9e Mon Sep 17 00:00:00 2001 From: Alex Bustos Date: Thu, 21 Apr 2022 19:33:01 -0500 Subject: [PATCH 1/5] feat: partir utils, 1/2 --- helpers/utilsHelper/{utils.go => bee.go} | 0 helpers/utilsHelper/utilidades.go | 224 +++++++++++++++++++++++ 2 files changed, 224 insertions(+) rename helpers/utilsHelper/{utils.go => bee.go} (100%) create mode 100644 helpers/utilsHelper/utilidades.go diff --git a/helpers/utilsHelper/utils.go b/helpers/utilsHelper/bee.go similarity index 100% rename from helpers/utilsHelper/utils.go rename to helpers/utilsHelper/bee.go diff --git a/helpers/utilsHelper/utilidades.go b/helpers/utilsHelper/utilidades.go new file mode 100644 index 00000000..eecbe052 --- /dev/null +++ b/helpers/utilsHelper/utilidades.go @@ -0,0 +1,224 @@ +package utilsHelper + +import ( + "encoding/json" + "fmt" + "net/url" + "strings" + + "github.com/astaxie/beego/logs" + + "github.com/udistrital/arka_mid/models" + "github.com/udistrital/utils_oas/errorctrl" + "github.com/udistrital/utils_oas/formatdata" +) + +// ConvertirInterfaceMap +func ConvertirInterfaceMap(Objeto interface{}) (Salida map[string]interface{}, outputError map[string]interface{}) { + + defer func() { + if err := recover(); err != nil { + outputError = map[string]interface{}{ + "funcion": "ConvertirInterfaceMap - Unhandled Error!", + "err": err, + "status": "500", + } + panic(outputError) + } + }() + + if jsonString, err := json.Marshal(Objeto); err == nil { + if err2 := json.Unmarshal(jsonString, &Salida); err2 != nil { + logs.Error(err) + outputError = map[string]interface{}{ + "funcion": "ConvertirInterfaceMap - json.Unmarshal(jsonString, &Salida)", + "err": err, + "status": "500", + } + return nil, outputError + } + } else { + logs.Error(err) + outputError = map[string]interface{}{ + "funcion": "ConvertirInterfaceMap - json.Marshal(Objeto)", + "err": err, + "status": "500", + } + return nil, outputError + } + return Salida, nil +} + +// ConvertirInterfaceArrayMap +func ConvertirInterfaceArrayMap(Objeto_ interface{}) (Salida []map[string]interface{}, err error) { + fmt.Println(Objeto_) + if jsonString, err := json.Marshal(Objeto_); err == nil { + if err2 := json.Unmarshal(jsonString, &Salida); err2 != nil { + panic(err.Error()) + } + } else { + panic(err.Error()) + } + return Salida, nil +} + +// ConvertirStringJson +func ConvertirStringJson(Objeto_ interface{}) (Salida map[string]interface{}, outputError map[string]interface{}) { + + defer func() { + if err := recover(); err != nil { + outputError = map[string]interface{}{ + "funcion": "ConvertirStringJson - Unhandled Error!", + "err": err, + "status": "500", + } + panic(outputError) + } + }() + + str := fmt.Sprintf("%v", Objeto_) + if err := json.Unmarshal([]byte(str), &Salida); err != nil { + logs.Error(err) + outputError = map[string]interface{}{ + "funcion": "ConvertirStringJson - json.Unmarshal([]byte(str), &Salida)", + "err": err, + "status": "500", + } + return nil, outputError + } + return Salida, nil + +} + +// ArrayFind +func ArrayFind(Objeto__ []map[string]interface{}, campo string, valor string) (Busqueda map[string]interface{}, err error) { + + if len(Objeto__) == 0 { + return nil, nil + } + + Busqueda_ := make(map[string]interface{}) + if keys := len(Objeto__[0]); keys != 0 { + + for _, value := range Objeto__ { + if value[campo] == valor { + Busqueda_ = value + return Busqueda_, nil + } + } + + } else { + panic(err.Error()) + } + + return Busqueda_, nil +} + +// KeysValuesMap descompone un mapeo en dos arreglos con sus claves y valores +func KeysValuesMap(m map[interface{}]interface{}) (keys []interface{}, vals []interface{}) { + + defer func() { + if err := recover(); err != nil { + panic(map[string]interface{}{ + "funcion": "KeysValuesMap - Unhandled Error!", + "err": err, + "status": "500", + }) + } + }() + + for k, v := range m { + keys = append(keys, k) + vals = append(vals, v) + } + return +} + +func ArrayToString(a []int, delim string) string { + return strings.Trim(strings.Replace(fmt.Sprint(a), " ", delim, -1), "[]") +} + +// findIdInArray Retorna la posicion en que se encuentra el id específicado +func FindIdInArray(idsList []*models.Elemento, id int) (i int) { + for i, id_ := range idsList { + if int(id_.Id) == id { + return i + } + } + return -1 +} + +// findElementoInArray Retorna la posicion en que se encuentra el id específicado +func FindElementoInArrayElementosMovimiento(elementos []*models.ElementosMovimiento, id int) (i int) { + for i, el_ := range elementos { + if int(el_.Id) == id { + return i + } + } + return -1 +} + +// fillElemento Agrega la vida útil y valor residual al elemento del acta +func FillElemento(elActa *models.DetalleElemento, elMov *models.ElementosMovimiento) (completo *models.DetalleElemento__, outputError map[string]interface{}) { + + funcion := "fillElemento" + defer errorctrl.ErrorControlFunction(funcion+" - Unhandled Error!", "500") + + if err := formatdata.FillStruct(elActa, &completo); err != nil { + logs.Error(err) + eval := " - formatdata.FillStruct(elActa, &completo)" + return nil, errorctrl.Error(funcion+eval, err, "500") + } + completo.VidaUtil = elMov.VidaUtil + completo.ValorResidual = elMov.ValorResidual + + return completo, nil + +} + +// removeDuplicateIds Remueve de un vector los enteros duplicados +func RemoveDuplicateIds(addrs []int) []int { + result := make([]int, 0, len(addrs)) + temp := map[int]struct{}{} + for _, item := range addrs { + if _, ok := temp[item]; !ok { + temp[item] = struct{}{} + result = append(result, item) + } + } + return result +} + +func EncodeUrl(query string, fields string, sortby string, order string, offset string, limit string) string { + params := url.Values{} + + if len(query) > 0 { + params.Add("query", query) + } + + if len(fields) > 0 { + params.Add("fields", fields) + } + + if len(sortby) > 0 { + params.Add("sortby", sortby) + + } + + if len(order) > 0 { + params.Add("order", order) + + } + + if len(offset) > 0 { + params.Add("offset", offset) + + } + + if len(limit) > 0 { + params.Add("limit", limit) + + } + + return params.Encode() +} From 6c1e07bfaad3bd528f17996328f5f5bee7e872ea Mon Sep 17 00:00:00 2001 From: Alex Bustos Date: Thu, 21 Apr 2022 19:34:30 -0500 Subject: [PATCH 2/5] feat: partir utils, 2/2 --- helpers/utilsHelper/bee.go | 185 ------------------------------ helpers/utilsHelper/utilidades.go | 35 ------ 2 files changed, 220 deletions(-) diff --git a/helpers/utilsHelper/bee.go b/helpers/utilsHelper/bee.go index eecbe052..c3594886 100644 --- a/helpers/utilsHelper/bee.go +++ b/helpers/utilsHelper/bee.go @@ -1,194 +1,9 @@ package utilsHelper import ( - "encoding/json" - "fmt" "net/url" - "strings" - - "github.com/astaxie/beego/logs" - - "github.com/udistrital/arka_mid/models" - "github.com/udistrital/utils_oas/errorctrl" - "github.com/udistrital/utils_oas/formatdata" ) -// ConvertirInterfaceMap -func ConvertirInterfaceMap(Objeto interface{}) (Salida map[string]interface{}, outputError map[string]interface{}) { - - defer func() { - if err := recover(); err != nil { - outputError = map[string]interface{}{ - "funcion": "ConvertirInterfaceMap - Unhandled Error!", - "err": err, - "status": "500", - } - panic(outputError) - } - }() - - if jsonString, err := json.Marshal(Objeto); err == nil { - if err2 := json.Unmarshal(jsonString, &Salida); err2 != nil { - logs.Error(err) - outputError = map[string]interface{}{ - "funcion": "ConvertirInterfaceMap - json.Unmarshal(jsonString, &Salida)", - "err": err, - "status": "500", - } - return nil, outputError - } - } else { - logs.Error(err) - outputError = map[string]interface{}{ - "funcion": "ConvertirInterfaceMap - json.Marshal(Objeto)", - "err": err, - "status": "500", - } - return nil, outputError - } - return Salida, nil -} - -// ConvertirInterfaceArrayMap -func ConvertirInterfaceArrayMap(Objeto_ interface{}) (Salida []map[string]interface{}, err error) { - fmt.Println(Objeto_) - if jsonString, err := json.Marshal(Objeto_); err == nil { - if err2 := json.Unmarshal(jsonString, &Salida); err2 != nil { - panic(err.Error()) - } - } else { - panic(err.Error()) - } - return Salida, nil -} - -// ConvertirStringJson -func ConvertirStringJson(Objeto_ interface{}) (Salida map[string]interface{}, outputError map[string]interface{}) { - - defer func() { - if err := recover(); err != nil { - outputError = map[string]interface{}{ - "funcion": "ConvertirStringJson - Unhandled Error!", - "err": err, - "status": "500", - } - panic(outputError) - } - }() - - str := fmt.Sprintf("%v", Objeto_) - if err := json.Unmarshal([]byte(str), &Salida); err != nil { - logs.Error(err) - outputError = map[string]interface{}{ - "funcion": "ConvertirStringJson - json.Unmarshal([]byte(str), &Salida)", - "err": err, - "status": "500", - } - return nil, outputError - } - return Salida, nil - -} - -// ArrayFind -func ArrayFind(Objeto__ []map[string]interface{}, campo string, valor string) (Busqueda map[string]interface{}, err error) { - - if len(Objeto__) == 0 { - return nil, nil - } - - Busqueda_ := make(map[string]interface{}) - if keys := len(Objeto__[0]); keys != 0 { - - for _, value := range Objeto__ { - if value[campo] == valor { - Busqueda_ = value - return Busqueda_, nil - } - } - - } else { - panic(err.Error()) - } - - return Busqueda_, nil -} - -// KeysValuesMap descompone un mapeo en dos arreglos con sus claves y valores -func KeysValuesMap(m map[interface{}]interface{}) (keys []interface{}, vals []interface{}) { - - defer func() { - if err := recover(); err != nil { - panic(map[string]interface{}{ - "funcion": "KeysValuesMap - Unhandled Error!", - "err": err, - "status": "500", - }) - } - }() - - for k, v := range m { - keys = append(keys, k) - vals = append(vals, v) - } - return -} - -func ArrayToString(a []int, delim string) string { - return strings.Trim(strings.Replace(fmt.Sprint(a), " ", delim, -1), "[]") -} - -// findIdInArray Retorna la posicion en que se encuentra el id específicado -func FindIdInArray(idsList []*models.Elemento, id int) (i int) { - for i, id_ := range idsList { - if int(id_.Id) == id { - return i - } - } - return -1 -} - -// findElementoInArray Retorna la posicion en que se encuentra el id específicado -func FindElementoInArrayElementosMovimiento(elementos []*models.ElementosMovimiento, id int) (i int) { - for i, el_ := range elementos { - if int(el_.Id) == id { - return i - } - } - return -1 -} - -// fillElemento Agrega la vida útil y valor residual al elemento del acta -func FillElemento(elActa *models.DetalleElemento, elMov *models.ElementosMovimiento) (completo *models.DetalleElemento__, outputError map[string]interface{}) { - - funcion := "fillElemento" - defer errorctrl.ErrorControlFunction(funcion+" - Unhandled Error!", "500") - - if err := formatdata.FillStruct(elActa, &completo); err != nil { - logs.Error(err) - eval := " - formatdata.FillStruct(elActa, &completo)" - return nil, errorctrl.Error(funcion+eval, err, "500") - } - completo.VidaUtil = elMov.VidaUtil - completo.ValorResidual = elMov.ValorResidual - - return completo, nil - -} - -// removeDuplicateIds Remueve de un vector los enteros duplicados -func RemoveDuplicateIds(addrs []int) []int { - result := make([]int, 0, len(addrs)) - temp := map[int]struct{}{} - for _, item := range addrs { - if _, ok := temp[item]; !ok { - temp[item] = struct{}{} - result = append(result, item) - } - } - return result -} - func EncodeUrl(query string, fields string, sortby string, order string, offset string, limit string) string { params := url.Values{} diff --git a/helpers/utilsHelper/utilidades.go b/helpers/utilsHelper/utilidades.go index eecbe052..56f97e11 100644 --- a/helpers/utilsHelper/utilidades.go +++ b/helpers/utilsHelper/utilidades.go @@ -3,7 +3,6 @@ package utilsHelper import ( "encoding/json" "fmt" - "net/url" "strings" "github.com/astaxie/beego/logs" @@ -188,37 +187,3 @@ func RemoveDuplicateIds(addrs []int) []int { } return result } - -func EncodeUrl(query string, fields string, sortby string, order string, offset string, limit string) string { - params := url.Values{} - - if len(query) > 0 { - params.Add("query", query) - } - - if len(fields) > 0 { - params.Add("fields", fields) - } - - if len(sortby) > 0 { - params.Add("sortby", sortby) - - } - - if len(order) > 0 { - params.Add("order", order) - - } - - if len(offset) > 0 { - params.Add("offset", offset) - - } - - if len(limit) > 0 { - params.Add("limit", limit) - - } - - return params.Encode() -} From 906648f6170a54b5d98ae5c71923b242c4038e38 Mon Sep 17 00:00:00 2001 From: "Alex F. Bustos P" Date: Fri, 29 Apr 2022 01:27:56 -0500 Subject: [PATCH 3/5] feat: traer ids de roles y comprobantes contables de configuracion --- conf/app.conf | 2 + go.mod | 2 +- go.sum | 10 +++- helpers/configuracion/StructsParametros.go | 43 ++++++++++++++ helpers/configuracion/configuracion.go | 15 +++++ helpers/configuracion/lectura.go | 65 ++++++++++++++++++++++ helpers/crud/configuracion/parametro.go | 38 +++++++++++++ helpers/utilsHelper/bee.go | 50 +++++++++++++++++ main.go | 2 +- statusCheck.go | 18 ++++++ 10 files changed, 241 insertions(+), 4 deletions(-) create mode 100644 helpers/configuracion/StructsParametros.go create mode 100644 helpers/configuracion/configuracion.go create mode 100644 helpers/configuracion/lectura.go create mode 100644 helpers/crud/configuracion/parametro.go create mode 100644 statusCheck.go diff --git a/conf/app.conf b/conf/app.conf index 26ea4e4e..908dd282 100644 --- a/conf/app.conf +++ b/conf/app.conf @@ -4,12 +4,14 @@ copyrequestbody = true EnableDocs = true httpport = ${ARKA_MID_HTTP_PORT||8080} runmode = ${RUN_MODE||prod} +nombreAplicacion = ${NOMBRE_APLICACION||"arka_ii_main"} actaRecibidoService = ${ACTA_RECIBIDO_CRUD} administrativaJbpmService = ${ADMINISTRATIVA_JBPM} administrativaService = ${ADMINISTRATIVA_SERVICE} autenticacionService = ${AUTENTICACION_MID_SERVICE} catalogoElementosService = ${CATALOGO_ELEMENTOS_SERVICE} +configuracionCrud = ${CONFIGURACION_CRUD} consecutivosService = ${CONSECUTIVOS_SERVICE} cuentasContablesService = ${CUENTAS_CONTABLES_SERVICE} movimientosArkaService = ${MOVIMIENTOS_ARKA_SERVICE} diff --git a/go.mod b/go.mod index af177e87..239077ba 100644 --- a/go.mod +++ b/go.mod @@ -4,9 +4,9 @@ go 1.14 require ( github.com/astaxie/beego v1.12.3 - github.com/mitchellh/mapstructure v1.4.1 github.com/smartystreets/goconvey v1.6.4 github.com/tealeg/xlsx v1.0.5 + github.com/udistrital/configuracion_api v0.0.0-20220225180608-8a66ca19fcc2 github.com/udistrital/utils_oas v0.0.0-20220415063412-5dae4bd58180 ) diff --git a/go.sum b/go.sum index 2e00d2b6..6596e405 100644 --- a/go.sum +++ b/go.sum @@ -136,6 +136,7 @@ github.com/go-playground/universal-translator v0.18.0 h1:82dyy6p4OuJq4/CByFNOn/j github.com/go-playground/universal-translator v0.18.0/go.mod h1:UvRDBj+xPUEGrFYl+lu/H90nyDXpg0fqeB/AQUGNTVA= github.com/go-redis/redis v6.14.2+incompatible/go.mod h1:NAIEuMOZ/fxfXJIrKDQDz8wamY7mA7PouImQ2Jvg6kA= github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w= +github.com/go-sql-driver/mysql v1.5.0 h1:ozyZYNQW3x3HtqT1jira07DN2PArx2v7/mN66gGcHOs= github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/gogo/googleapis v1.1.0/go.mod h1:gf4bu3Q80BeJ6H1S1vYPm8/ELATdvryBaNFGgqEef3s= @@ -264,6 +265,7 @@ github.com/ledisdb/ledisdb v0.0.0-20200510135210-d35789ec47e6/go.mod h1:n931TsDu github.com/leodido/go-urn v1.2.1 h1:BqpAaACuzVSgi/VLzGZIobT2z4v53pjosyNd9Yv6n/w= github.com/leodido/go-urn v1.2.1/go.mod h1:zt4jvISO2HfUBqxjfIshjdMTYS56ZS/qv49ictyFfxY= github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= +github.com/lib/pq v1.10.0 h1:Zx5DJFEYQXio93kgXnQ09fXNiUKsqv4OUEu2UtGcB1E= github.com/lib/pq v1.10.0/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= github.com/lightstep/lightstep-tracer-common/golang/gogo v0.0.0-20190605223551-bc2310a04743/go.mod h1:qklhhLq1aX+mtWk9cPHPzaBjWImj5ULL6C7HFJtXQMM= github.com/lightstep/lightstep-tracer-go v0.18.1/go.mod h1:jlF1pusYV4pidLvZ+XD0UBX0ZE6WURAspgAczcDHrL4= @@ -272,6 +274,7 @@ github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaO github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= +github.com/mattn/go-sqlite3 v2.0.3+incompatible h1:gXHsfypPkaMZrKbD5209QV9jbUTJKjyR5WD3HYQSd+U= github.com/mattn/go-sqlite3 v2.0.3+incompatible/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc= github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= @@ -283,8 +286,6 @@ github.com/mitchellh/gox v0.4.0/go.mod h1:Sd9lOJ0+aimLBi73mGofS1ycjY8lL3uZM3JPS4 github.com/mitchellh/iochan v1.0.0/go.mod h1:JwYml1nuB7xOzsp52dPpHFffvOCDupsG0QubkSMEySY= github.com/mitchellh/mapstructure v0.0.0-20160808181253-ca63d7c062ee/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= -github.com/mitchellh/mapstructure v1.4.1 h1:CpVNEelQCZBooIPDn+AR3NpivK/TIKU8bDxdASFVQag= -github.com/mitchellh/mapstructure v1.4.1/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/mndrix/golog v0.0.0-20170330170653-a28e2a269775/go.mod h1:Q4YHYl483MNk6wwg3g8YsINpKe5S2UzUJCRSRlFaSU0= github.com/mndrix/ps v0.0.0-20170330174427-18e65badd6ab/go.mod h1:dHgTaDInzkAqJv67VaX1IkK449M2UoBY68CZeI/bNCU= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= @@ -333,6 +334,7 @@ github.com/pierrec/lz4 v1.0.2-0.20190131084431-473cd7ce01a1/go.mod h1:3/3N9NVKO0 github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/profile v1.2.1/go.mod h1:hJw3o1OdXxsrSjjVksARp5W95eeEaEfptyVZyv6JUPA= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= @@ -414,6 +416,10 @@ github.com/syndtr/goleveldb v0.0.0-20181127023241-353a9fca669c/go.mod h1:Z4AUp2K github.com/tealeg/xlsx v1.0.5 h1:+f8oFmvY8Gw1iUXzPk+kz+4GpbDZPK1FhPiQRd+ypgE= github.com/tealeg/xlsx v1.0.5/go.mod h1:btRS8dz54TDnvKNosuAqxrM1QgN1udgk9O34bDCnORM= github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= +github.com/udistrital/auditoria v0.0.0-20200115201815-9680ae9c2515/go.mod h1:2g8J932brTzbNOcSHob/vjt+/GFfMQuRreLZhvGiUro= +github.com/udistrital/configuracion_api v0.0.0-20220225180608-8a66ca19fcc2 h1:ZEG0q9mUUtDAtcz8oeqV+d56krakHOz7L0Gy7HXUnoY= +github.com/udistrital/configuracion_api v0.0.0-20220225180608-8a66ca19fcc2/go.mod h1:rJfjFZc6WbSsydWsSTdySnbKPtMwkz08o50Ix2OguRI= +github.com/udistrital/utils_oas v0.0.0-20211011160436-7fa8127363aa/go.mod h1:ctr3PgpZazF32ukxlLZP3AVjq8b2zaZ4beG4cqkx5ZA= github.com/udistrital/utils_oas v0.0.0-20220415063412-5dae4bd58180 h1:C4NRrY0b4TYIjbgANlP7gvNVEb7+LDBHcci5Lq/a9Ao= github.com/udistrital/utils_oas v0.0.0-20220415063412-5dae4bd58180/go.mod h1:jkSKIX5KYbf0/HxzGUs2leHo3KAwTC5n0oI1JDfoY78= github.com/ugorji/go v0.0.0-20171122102828-84cb69a8af83/go.mod h1:hnLbHMwcvSihnDhEfx2/BzKp2xb0Y+ErdfYcrs9tkJQ= diff --git a/helpers/configuracion/StructsParametros.go b/helpers/configuracion/StructsParametros.go new file mode 100644 index 00000000..9dc211b3 --- /dev/null +++ b/helpers/configuracion/StructsParametros.go @@ -0,0 +1,43 @@ +// Documentar en este archivo las estructuras de datos +// a almacenar en registros de configuracion_crud.parametro + +package configuracion + +// RolesArka es la estructura de los datos a almacenar en el +// campo Valor de un regitro de configuracion_api.parametro, +// cuyo nombre es el de la constante NombreParametroRoles. +// +// El objetivo es guardar los id de registros de +// configuracion_api.perfil asociados a cada rol necesario +// desde el modelo de negocios de Arka II +// +// Adicionalmente, esto es para permitir que los roles se puedan +// renombrar directamente desde el cliente de configuración +// sin afectar el funcionamiento del sistema +type RolesArka struct { + Administrador uint + Secretaria uint + AuxiliarUno uint + AuxiliarDos uint + Proveedor uint + Contabilidad uint +} + +// TiposContablesArka es la estructura a guardar en el campo +// Valor de un registro en configuracion_api.parametro cuyo +// Nombre es el de la constante NombreParametroTiposDeComprobante. +// +// Su objetivo es guardar los id de los comprobantes contables +// de cuentas_contables_crud.comprobante a ser especificados +// en el campo de etiquetas de cada transaccion contable +// enviada a movimientos_contables_mid +type TiposContablesArka struct { + Entrada string // P8 + Salida string // H21 + Traslado string // N39 (ajuste) + Baja string // H23 + Amortizacion string // H22 (cierre) + Depreciacion string // H22 (cierre) + Ajuste string // N39 + Avaluo string // N40 +} diff --git a/helpers/configuracion/configuracion.go b/helpers/configuracion/configuracion.go new file mode 100644 index 00000000..3e0c669f --- /dev/null +++ b/helpers/configuracion/configuracion.go @@ -0,0 +1,15 @@ +package configuracion + +const ( + NombreParametroRoles = "RolesRegistrados" + NombreParametroTiposDeComprobante = "TiposDeComprobante" +) + +var ( + roles RolesArka + comprobantes TiposContablesArka +) + +func init() { + ActualizaRolesArka() +} diff --git a/helpers/configuracion/lectura.go b/helpers/configuracion/lectura.go new file mode 100644 index 00000000..9d25d004 --- /dev/null +++ b/helpers/configuracion/lectura.go @@ -0,0 +1,65 @@ +package configuracion + +import ( + "fmt" + "net/http" + + "github.com/astaxie/beego" + "github.com/astaxie/beego/logs" + + "github.com/udistrital/arka_mid/helpers/crud/configuracion" + "github.com/udistrital/arka_mid/helpers/utilsHelper" + modelsConfiguracion "github.com/udistrital/configuracion_api/models" + e "github.com/udistrital/utils_oas/errorctrl" + "github.com/udistrital/utils_oas/formatdata" +) + +// ActualizaRolesArka se puede llamar periodicamente. Un candidato podría ser +// el healthcheck +func ActualizaRolesArka() { + const funcion = "ActualizaRolesArka - " + defer e.ErrorControlFunction(funcion+"unhandled error", fmt.Sprint(http.StatusInternalServerError)) + + // parametro de roles registrados + getParametrosArka("RolesRegistrados", 1, &roles) +} + +// ActualizaTiposDeComprobante carga los tipos de comprobante +func ActualizaTiposDeComprobante() { + const funcion = "ActualizaTiposDeComprobante - " + defer e.ErrorControlFunction(funcion+"unhandled error!", fmt.Sprint(http.StatusInternalServerError)) + + getParametrosArka("TiposDeComprobante", 1, &comprobantes) +} + +func getParametrosArka(parametro string, resultadosEsperados uint, out interface{}) { + const funcion = "parametroArka - " + defer e.ErrorControlFunction(funcion+"unhandled error!", fmt.Sprint(http.StatusInternalServerError)) + + var parametros []modelsConfiguracion.Parametro + query := utilsHelper.Query{ + Query: map[string]string{ + "Aplicacion__Nombre": beego.AppConfig.String("nombreAplicacion"), + "Nombre": parametro, + }, + Limit: -1, + } + if err := configuracion.GetParametros(query, ¶metros); err != nil { + logs.Critical(err) + panic(err) + } + if len(parametros) != 1 { + cond := "" + if len(parametros) >= 10 { + cond = " (o más)" + } + err := fmt.Errorf("se esperaba encontrar %d registro(s) con Nombre:%s en configuracion_crud/parametros, hay: %d%s", + resultadosEsperados, parametro, len(parametros), cond) + logs.Critical(err) + panic(err) + } + if err := formatdata.FillStruct(parametros[0].Valor, &out); err != nil { + logs.Critical(err) + panic(err) + } +} diff --git a/helpers/crud/configuracion/parametro.go b/helpers/crud/configuracion/parametro.go new file mode 100644 index 00000000..cd66df0e --- /dev/null +++ b/helpers/crud/configuracion/parametro.go @@ -0,0 +1,38 @@ +package configuracion + +import ( + "fmt" + "net/http" + + "github.com/astaxie/beego" + "github.com/astaxie/beego/logs" + + "github.com/udistrital/arka_mid/helpers/utilsHelper" + modelsConfiguracion "github.com/udistrital/configuracion_api/models" + e "github.com/udistrital/utils_oas/errorctrl" + "github.com/udistrital/utils_oas/formatdata" + "github.com/udistrital/utils_oas/request" +) + +func GetParametros(query utilsHelper.Query, parametros *[]modelsConfiguracion.Parametro) (outputError map[string]interface{}) { + const funcion = "GetParametros - " + defer e.ErrorControlFunction(funcion+"unhandled error!", fmt.Sprint(http.StatusInternalServerError)) + + qString := query.Encode() + urlParametros := "http://" + beego.AppConfig.String("configuracionCrud") + "parametro?" + qString + logs.Debug(urlParametros) + var respuestaApi interface{} + if resp, err := request.GetJsonTest(urlParametros, &respuestaApi); err != nil || resp.StatusCode != http.StatusOK { + const contexto = "request.GetJsonTest(urlParametros, &respuestaApi)" + if err == nil { + err = fmt.Errorf("undesired status code: %d", resp.StatusCode) + } + outputError = e.Error(funcion+contexto, err, fmt.Sprint(http.StatusBadGateway)) + return + } + if err := formatdata.FillStruct(respuestaApi, ¶metros); err != nil { + const contexto = "formatdata.FillStruct(respuestaApi, ¶metros)" + outputError = e.Error(funcion+contexto, err, fmt.Sprint(http.StatusInternalServerError)) + } + return +} diff --git a/helpers/utilsHelper/bee.go b/helpers/utilsHelper/bee.go index c3594886..5e2644d5 100644 --- a/helpers/utilsHelper/bee.go +++ b/helpers/utilsHelper/bee.go @@ -1,7 +1,9 @@ package utilsHelper import ( + "fmt" "net/url" + "strings" ) func EncodeUrl(query string, fields string, sortby string, order string, offset string, limit string) string { @@ -37,3 +39,51 @@ func EncodeUrl(query string, fields string, sortby string, order string, offset return params.Encode() } + +type Sorting struct { + By string + Asc bool +} + +func (c *Sorting) OrderStr() string { + if c.Asc { + return "asc" + } + return "desc" +} + +type Query struct { + Query map[string]string + Limit int `default:"10"` + Offset int `default:"0"` + Fields []string + Sort []Sorting +} + +func (opts *Query) Encode() string { + + sortby := make([]string, 0) + order := make([]string, 0) + for _, v := range opts.Sort { + sortby = append(sortby, v.By) + order = append(order, v.OrderStr()) + } + + joinedQuery := "" + periods := len(opts.Query) + for k, v := range opts.Query { + joinedQuery += k + ":" + v + if periods > 1 { + joinedQuery += "," + periods-- + } + } + + return EncodeUrl(joinedQuery, + strings.Join(opts.Fields, ","), + strings.Join(sortby, ","), + strings.Join(order, ","), + fmt.Sprint(opts.Offset), + fmt.Sprint(opts.Limit), + ) +} diff --git a/main.go b/main.go index cb46a77d..26bc8145 100644 --- a/main.go +++ b/main.go @@ -30,7 +30,7 @@ func main() { AllowCredentials: true, })) beego.ErrorController(&customerrorv2.CustomErrorController{}) - apistatus.Init() + apistatus.InitWithHandler(statusCheck) auditoria.InitMiddleware() beego.Run() } diff --git a/statusCheck.go b/statusCheck.go new file mode 100644 index 00000000..2ffdc2c0 --- /dev/null +++ b/statusCheck.go @@ -0,0 +1,18 @@ +package main + +import ( + "fmt" + "net/http" + + "github.com/udistrital/arka_mid/helpers/configuracion" + e "github.com/udistrital/utils_oas/errorctrl" +) + +func statusCheck() interface{} { + const funcion = "statusCheck - " + defer e.ErrorControlFunction(funcion+"unhandled error!", fmt.Sprint(http.StatusInternalServerError)) + + configuracion.ActualizaRolesArka() + configuracion.ActualizaTiposDeComprobante() + return nil +} From a7ebc06f635f33d821f5e6d03b46c4b75b566512 Mon Sep 17 00:00:00 2001 From: "Alex F. Bustos P" Date: Mon, 2 May 2022 22:09:54 -0500 Subject: [PATCH 4/5] fix: `go get ./... && go mod tidy` faltante --- go.mod | 9 ++++++++- go.sum | 25 ++++++++++++++++--------- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/go.mod b/go.mod index 239077ba..9410692b 100644 --- a/go.mod +++ b/go.mod @@ -12,9 +12,16 @@ require ( require ( github.com/go-playground/universal-translator v0.18.0 // indirect + github.com/go-sql-driver/mysql v1.6.0 // indirect + github.com/google/go-cmp v0.5.7 // indirect + github.com/lib/pq v1.10.5 // indirect github.com/prometheus/common v0.34.0 // indirect + github.com/stretchr/testify v1.7.1 // indirect golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4 // indirect golang.org/x/net v0.0.0-20220420153159-1850ba15e1be // indirect - golang.org/x/sys v0.0.0-20220412211240-33da011f77ad // indirect + golang.org/x/sys v0.0.0-20220429121018-84afa8d3f7b3 // indirect + golang.org/x/xerrors v0.0.0-20220411194840-2f41105eb62f // indirect google.golang.org/protobuf v1.28.0 // indirect + gopkg.in/check.v1 v1.0.0-20200902074654-038fdea0a05b // indirect + gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect ) diff --git a/go.sum b/go.sum index 6596e405..b3626d1a 100644 --- a/go.sum +++ b/go.sum @@ -136,8 +136,9 @@ github.com/go-playground/universal-translator v0.18.0 h1:82dyy6p4OuJq4/CByFNOn/j github.com/go-playground/universal-translator v0.18.0/go.mod h1:UvRDBj+xPUEGrFYl+lu/H90nyDXpg0fqeB/AQUGNTVA= github.com/go-redis/redis v6.14.2+incompatible/go.mod h1:NAIEuMOZ/fxfXJIrKDQDz8wamY7mA7PouImQ2Jvg6kA= github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w= -github.com/go-sql-driver/mysql v1.5.0 h1:ozyZYNQW3x3HtqT1jira07DN2PArx2v7/mN66gGcHOs= github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= +github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE= +github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/gogo/googleapis v1.1.0/go.mod h1:gf4bu3Q80BeJ6H1S1vYPm8/ELATdvryBaNFGgqEef3s= github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= @@ -185,8 +186,9 @@ github.com/google/go-cmp v0.4.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.7 h1:81/ik6ipDQS2aGcBfIN5dHDB36BwrStyeAQquSYCV4o= +github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0= @@ -265,8 +267,9 @@ github.com/ledisdb/ledisdb v0.0.0-20200510135210-d35789ec47e6/go.mod h1:n931TsDu github.com/leodido/go-urn v1.2.1 h1:BqpAaACuzVSgi/VLzGZIobT2z4v53pjosyNd9Yv6n/w= github.com/leodido/go-urn v1.2.1/go.mod h1:zt4jvISO2HfUBqxjfIshjdMTYS56ZS/qv49ictyFfxY= github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= -github.com/lib/pq v1.10.0 h1:Zx5DJFEYQXio93kgXnQ09fXNiUKsqv4OUEu2UtGcB1E= github.com/lib/pq v1.10.0/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= +github.com/lib/pq v1.10.5 h1:J+gdV2cUmX7ZqL2B0lFcW0m+egaHC2V3lpO8nWxyYiQ= +github.com/lib/pq v1.10.5/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= github.com/lightstep/lightstep-tracer-common/golang/gogo v0.0.0-20190605223551-bc2310a04743/go.mod h1:qklhhLq1aX+mtWk9cPHPzaBjWImj5ULL6C7HFJtXQMM= github.com/lightstep/lightstep-tracer-go v0.18.1/go.mod h1:jlF1pusYV4pidLvZ+XD0UBX0ZE6WURAspgAczcDHrL4= github.com/lyft/protoc-gen-validate v0.0.13/go.mod h1:XbGvPuh87YZc5TdIa2/I4pLk0QoUACkjt2znoq26NVQ= @@ -409,8 +412,9 @@ github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= -github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/syndtr/goleveldb v0.0.0-20160425020131-cfa635847112/go.mod h1:Z4AUp2Km+PwemOoO/VB5AOx9XSsIItzFjoJlOSiYmn0= github.com/syndtr/goleveldb v0.0.0-20181127023241-353a9fca669c/go.mod h1:Z4AUp2Km+PwemOoO/VB5AOx9XSsIItzFjoJlOSiYmn0= github.com/tealeg/xlsx v1.0.5 h1:+f8oFmvY8Gw1iUXzPk+kz+4GpbDZPK1FhPiQRd+ypgE= @@ -595,8 +599,8 @@ golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220412211240-33da011f77ad h1:ntjMns5wyP/fN65tdBD4g8J5w8n015+iIIs9rtjXkY0= -golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220429121018-84afa8d3f7b3 h1:kBsBifDikLCf5sUMbcD8p73OinDtAQWQp8+n7FiyzlA= +golang.org/x/sys v0.0.0-20220429121018-84afa8d3f7b3/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -660,8 +664,9 @@ golang.org/x/tools v0.0.0-20200825202427-b303f430e36d/go.mod h1:njjCfa9FT2d7l9Bc golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20220411194840-2f41105eb62f h1:GGU+dLjvlC3qDwqYgL6UgRmHXhOOgns0bZu2Ty5mm6U= +golang.org/x/xerrors v0.0.0-20220411194840-2f41105eb62f/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/api v0.3.1/go.mod h1:6wY9I6uQWHQ8EM57III9mq/AjF+i8G65rmVagqKMtkk= google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M= @@ -751,8 +756,9 @@ gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLks gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU= gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20200902074654-038fdea0a05b h1:QRR6H1YWRnHb4Y/HeNFCTJLFVxaq6wH4YuVdsUOr75U= +gopkg.in/check.v1 v1.0.0-20200902074654-038fdea0a05b/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/cheggaaa/pb.v1 v1.0.25/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qStrOgw= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= @@ -774,8 +780,9 @@ gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo= +gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= From 967ae974ee80d6f0a718b8a05d6090e7cc554489 Mon Sep 17 00:00:00 2001 From: "Alex F. Bustos P" Date: Tue, 3 May 2022 01:31:37 -0500 Subject: [PATCH 5/5] fix: lectura de parametros --- conf/app.conf | 2 +- helpers/configuracion/configuracion.go | 3 ++- helpers/configuracion/lectura.go | 17 +++++++++-------- helpers/crud/configuracion/parametro.go | 5 +++-- main.go | 1 + 5 files changed, 16 insertions(+), 12 deletions(-) diff --git a/conf/app.conf b/conf/app.conf index 908dd282..7d9a0da1 100644 --- a/conf/app.conf +++ b/conf/app.conf @@ -4,7 +4,7 @@ copyrequestbody = true EnableDocs = true httpport = ${ARKA_MID_HTTP_PORT||8080} runmode = ${RUN_MODE||prod} -nombreAplicacion = ${NOMBRE_APLICACION||"arka_ii_main"} +nombreAplicacion = ${NOMBRE_APLICACION||arka_ii_main} actaRecibidoService = ${ACTA_RECIBIDO_CRUD} administrativaJbpmService = ${ADMINISTRATIVA_JBPM} diff --git a/helpers/configuracion/configuracion.go b/helpers/configuracion/configuracion.go index 3e0c669f..030d2d49 100644 --- a/helpers/configuracion/configuracion.go +++ b/helpers/configuracion/configuracion.go @@ -2,7 +2,7 @@ package configuracion const ( NombreParametroRoles = "RolesRegistrados" - NombreParametroTiposDeComprobante = "TiposDeComprobante" + NombreParametroTiposDeComprobante = "ComprobantesKronos" ) var ( @@ -12,4 +12,5 @@ var ( func init() { ActualizaRolesArka() + ActualizaTiposDeComprobante() } diff --git a/helpers/configuracion/lectura.go b/helpers/configuracion/lectura.go index 9d25d004..2754046c 100644 --- a/helpers/configuracion/lectura.go +++ b/helpers/configuracion/lectura.go @@ -1,6 +1,7 @@ package configuracion import ( + "encoding/json" "fmt" "net/http" @@ -11,7 +12,6 @@ import ( "github.com/udistrital/arka_mid/helpers/utilsHelper" modelsConfiguracion "github.com/udistrital/configuracion_api/models" e "github.com/udistrital/utils_oas/errorctrl" - "github.com/udistrital/utils_oas/formatdata" ) // ActualizaRolesArka se puede llamar periodicamente. Un candidato podría ser @@ -21,7 +21,7 @@ func ActualizaRolesArka() { defer e.ErrorControlFunction(funcion+"unhandled error", fmt.Sprint(http.StatusInternalServerError)) // parametro de roles registrados - getParametrosArka("RolesRegistrados", 1, &roles) + getParametroArka(NombreParametroRoles, &roles) } // ActualizaTiposDeComprobante carga los tipos de comprobante @@ -29,10 +29,10 @@ func ActualizaTiposDeComprobante() { const funcion = "ActualizaTiposDeComprobante - " defer e.ErrorControlFunction(funcion+"unhandled error!", fmt.Sprint(http.StatusInternalServerError)) - getParametrosArka("TiposDeComprobante", 1, &comprobantes) + getParametroArka(NombreParametroTiposDeComprobante, &comprobantes) } -func getParametrosArka(parametro string, resultadosEsperados uint, out interface{}) { +func getParametroArka(parametro string, out interface{}) { const funcion = "parametroArka - " defer e.ErrorControlFunction(funcion+"unhandled error!", fmt.Sprint(http.StatusInternalServerError)) @@ -42,7 +42,8 @@ func getParametrosArka(parametro string, resultadosEsperados uint, out interface "Aplicacion__Nombre": beego.AppConfig.String("nombreAplicacion"), "Nombre": parametro, }, - Limit: -1, + Fields: []string{"Nombre", "Valor"}, + Limit: -1, } if err := configuracion.GetParametros(query, ¶metros); err != nil { logs.Critical(err) @@ -53,12 +54,12 @@ func getParametrosArka(parametro string, resultadosEsperados uint, out interface if len(parametros) >= 10 { cond = " (o más)" } - err := fmt.Errorf("se esperaba encontrar %d registro(s) con Nombre:%s en configuracion_crud/parametros, hay: %d%s", - resultadosEsperados, parametro, len(parametros), cond) + err := fmt.Errorf("se esperaba encontrar un solo registro con Nombre:%s en configuracion_crud/parametros, hay: %d%s", + parametro, len(parametros), cond) logs.Critical(err) panic(err) } - if err := formatdata.FillStruct(parametros[0].Valor, &out); err != nil { + if err := json.Unmarshal([]byte(parametros[0].Valor), &out); err != nil { logs.Critical(err) panic(err) } diff --git a/helpers/crud/configuracion/parametro.go b/helpers/crud/configuracion/parametro.go index cd66df0e..9464373d 100644 --- a/helpers/crud/configuracion/parametro.go +++ b/helpers/crud/configuracion/parametro.go @@ -5,7 +5,7 @@ import ( "net/http" "github.com/astaxie/beego" - "github.com/astaxie/beego/logs" + // "github.com/astaxie/beego/logs" "github.com/udistrital/arka_mid/helpers/utilsHelper" modelsConfiguracion "github.com/udistrital/configuracion_api/models" @@ -20,7 +20,7 @@ func GetParametros(query utilsHelper.Query, parametros *[]modelsConfiguracion.Pa qString := query.Encode() urlParametros := "http://" + beego.AppConfig.String("configuracionCrud") + "parametro?" + qString - logs.Debug(urlParametros) + // logs.Debug(urlParametros) var respuestaApi interface{} if resp, err := request.GetJsonTest(urlParametros, &respuestaApi); err != nil || resp.StatusCode != http.StatusOK { const contexto = "request.GetJsonTest(urlParametros, &respuestaApi)" @@ -30,6 +30,7 @@ func GetParametros(query utilsHelper.Query, parametros *[]modelsConfiguracion.Pa outputError = e.Error(funcion+contexto, err, fmt.Sprint(http.StatusBadGateway)) return } + // formatdata.JsonPrint(respuestaApi) if err := formatdata.FillStruct(respuestaApi, ¶metros); err != nil { const contexto = "formatdata.FillStruct(respuestaApi, ¶metros)" outputError = e.Error(funcion+contexto, err, fmt.Sprint(http.StatusInternalServerError)) diff --git a/main.go b/main.go index 26bc8145..5051c77a 100644 --- a/main.go +++ b/main.go @@ -4,6 +4,7 @@ import ( "github.com/astaxie/beego" "github.com/astaxie/beego/plugins/cors" + _ "github.com/udistrital/arka_mid/helpers/configuracion" _ "github.com/udistrital/arka_mid/routers" apistatus "github.com/udistrital/utils_oas/apiStatusLib" "github.com/udistrital/utils_oas/auditoria"