|
|
- package grmi
-
- import (
- "github.com/kataras/iris/v12"
- "leit.com/LAPP_GAAS_GFrame/utils"
- "leit.com/LAPP_GAAS_GFrame/web/models"
- "strings"
- "time"
- )
-
- const PageSize = "pageSize"
- const PageIndex = "pageIndex"
-
- func Log(user *models.Usertab, codeFile string, function string, message string) {
-
- logs := new(models.LeitServerLog)
- logs.File = codeFile
- logs.Level = "info"
- logs.Function = function
- logs.Message = message
- logs.Operator = user.Userid
- logs.TimeStamp = utils.TimeFormat(time.Now(), "yyyyMMddHHmmss")
- logs.InsertRecord()
- }
-
- func GetPageSize(ctx iris.Context) int {
- if value := ctx.URLParam(PageSize); value != "" {
- return utils.ValueToInt(value, 0)
- }
- return 10
- }
-
- func GetPageIndex(ctx iris.Context) int {
- if index := ctx.URLParam(PageIndex); index != "" {
- return utils.ValueToInt(index, 0)
- }
- return 1
- }
-
- func BuildCondtion(meta map[string]Field, ctx iris.Context) ([]Predicate, error) {
-
- predicates := make([]Predicate, 0, 10)
- for name, value := range ctx.URLParams() {
- if field, ok := meta[strings.ToLower(name)]; ok {
- var predicateValue interface{} = value
- var err error
- switch field.GoType {
- case "int":
- {
- predicateValue, err = ctx.URLParamInt64(name)
- if err != nil {
- return nil, err
- }
- }
- case "int8":
- {
- predicateValue, err = ctx.URLParamInt64(name)
- if err != nil {
- return nil, err
- }
- }
- case "int16":
- {
- predicateValue, err = ctx.URLParamInt64(name)
- if err != nil {
- return nil, err
- }
- }
- case "int32":
- {
- predicateValue, err = ctx.URLParamInt64(name)
- if err != nil {
- return nil, err
- }
- }
- case "int64":
- {
- predicateValue, err = ctx.URLParamInt64(name)
- if err != nil {
- return nil, err
- }
- }
- case "uint":
- {
- predicateValue, err = ctx.URLParamInt64(name)
- if err != nil {
- return nil, err
- }
- }
- case "uint8":
- {
- predicateValue, err = ctx.URLParamInt64(name)
- if err != nil {
- return nil, err
- }
- }
- case "uint16":
- {
- predicateValue, err = ctx.URLParamInt64(name)
- if err != nil {
- return nil, err
- }
- }
- case "uint32":
- {
- predicateValue, err = ctx.URLParamInt64(name)
- if err != nil {
- return nil, err
- }
- }
- case "uint64":
- {
- continue
- }
- case "float32":
- {
- predicateValue, err = ctx.URLParamFloat64(name)
- if err != nil {
- return nil, err
- }
- }
- case "float64":
- {
- predicateValue, err = ctx.URLParamFloat64(name)
- if err != nil {
- return nil, err
- }
- }
- case "grmi.DateTime":
- {
- continue
- }
- case "bool":
- {
- predicateValue, err = ctx.URLParamBool(name)
- if err != nil {
- return nil, err
- }
- }
- case "string":
- {
- predicateValue = ctx.URLParamTrim(name)
- }
- }
- predicates = append(predicates, Predicate{field.Name, "", predicateValue})
- }
- }
- return predicates, nil
- }
|