package grmi
|
|
|
|
import (
|
|
"LAPP_GAAS_GFrame_BACKEND/utils"
|
|
"LAPP_GAAS_GFrame_BACKEND/web/models"
|
|
"fmt"
|
|
"github.com/kataras/iris/v12/core/router"
|
|
"strconv"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
type GoType int
|
|
|
|
const (
|
|
URLDateTimeFormat = "20060102150405"
|
|
)
|
|
|
|
const (
|
|
TypeInt GoType = iota + 1
|
|
TypeInt8
|
|
TypeInt16
|
|
TypeInt32
|
|
TypeInt64
|
|
TypeUint
|
|
TypeUint8
|
|
TypeUint16
|
|
TypeUint32
|
|
TypeUint64
|
|
TypeFloat32
|
|
TypeFloat64
|
|
TypeDateTime
|
|
TypeBool
|
|
TypeString
|
|
)
|
|
|
|
var routeMapping = make(map[string]func(router.Party), 10)
|
|
|
|
func RegisterRouteMapping(path string, factory func(router.Party)) {
|
|
routeMapping[path] = factory
|
|
}
|
|
|
|
func BindRoutes(party router.Party) {
|
|
for path, factory := range routeMapping {
|
|
party.PartyFunc(path, factory)
|
|
}
|
|
}
|
|
|
|
func Equal(predicate Predicate) string {
|
|
return " and " + predicate.ColumnName + " = ?"
|
|
}
|
|
|
|
func NotEqual(predicate Predicate) string {
|
|
return " and " + predicate.ColumnName + " <> ?"
|
|
}
|
|
|
|
func Like(predicate Predicate) string {
|
|
return " and " + predicate.ColumnName + " like concat('%', ?, '%')"
|
|
}
|
|
|
|
func NotLike(predicate Predicate) string {
|
|
return " and " + predicate.ColumnName + " not like concat('%', ?, '%')"
|
|
}
|
|
|
|
func IsNull(predicate Predicate) string {
|
|
return " and " + predicate.ColumnName + " is null ?"
|
|
}
|
|
|
|
func IsNotNull(predicate Predicate) string {
|
|
return " and " + predicate.ColumnName + " is not null ?"
|
|
}
|
|
|
|
func Approximate(predicate Predicate) string {
|
|
return fmt.Sprintf(" and datediff(second, %s, ?) = 0", predicate.ColumnName)
|
|
}
|
|
|
|
func NotApproximate(predicate Predicate) string {
|
|
return fmt.Sprintf(" and datediff(second, %s, ?) <> 0", predicate.ColumnName)
|
|
}
|
|
|
|
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 intParser(value string) (interface{}, error) {
|
|
predicateValue, err := strconv.ParseInt(value, 10, 64)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return predicateValue, nil
|
|
}
|
|
|
|
func uint64Parser(value string) (interface{}, error) {
|
|
predicateValue, err := strconv.ParseUint(value, 10, 64)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return predicateValue, nil
|
|
}
|
|
|
|
func floatParser(value string) (interface{}, error) {
|
|
predicateValue, err := strconv.ParseFloat(value, 64)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return predicateValue, nil
|
|
}
|
|
|
|
func dateTimeParser(value string) (interface{}, error) {
|
|
predicateValue, err := time.Parse(URLDateTimeFormat, value)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return predicateValue, nil
|
|
}
|
|
|
|
func boolParser(value string) (interface{}, error) {
|
|
predicateValue, err := strconv.ParseBool(value)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return predicateValue, nil
|
|
}
|
|
|
|
func stringParser(value string) (interface{}, error) {
|
|
return strings.TrimSpace(value), nil
|
|
}
|
|
|
|
var valueParsers = map[GoType]func(string) (interface{}, error){
|
|
TypeInt: intParser,
|
|
TypeInt8: intParser,
|
|
TypeInt16: intParser,
|
|
TypeInt32: intParser,
|
|
TypeInt64: intParser,
|
|
TypeUint: intParser,
|
|
TypeUint8: intParser,
|
|
TypeUint16: intParser,
|
|
TypeUint32: intParser,
|
|
TypeUint64: uint64Parser,
|
|
TypeFloat32: floatParser,
|
|
TypeFloat64: floatParser,
|
|
TypeDateTime: dateTimeParser,
|
|
TypeBool: boolParser,
|
|
TypeString: stringParser,
|
|
}
|