|
@ -4,6 +4,7 @@ import ( |
|
|
"LAPP_GAAS_GFrame_BACKEND/container" |
|
|
"LAPP_GAAS_GFrame_BACKEND/container" |
|
|
"LAPP_GAAS_GFrame_BACKEND/utils" |
|
|
"LAPP_GAAS_GFrame_BACKEND/utils" |
|
|
"LAPP_GAAS_GFrame_BACKEND/web/models" |
|
|
"LAPP_GAAS_GFrame_BACKEND/web/models" |
|
|
|
|
|
"errors" |
|
|
"fmt" |
|
|
"fmt" |
|
|
"github.com/kataras/iris/v12/core/router" |
|
|
"github.com/kataras/iris/v12/core/router" |
|
|
"strconv" |
|
|
"strconv" |
|
@ -68,48 +69,76 @@ func RepeatStrings(content string, count int) []string { |
|
|
return result |
|
|
return result |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func Equal(predicate Predicate) string { |
|
|
|
|
|
return fmt.Sprintf(" and %s = ?", predicate.ColumnName) |
|
|
|
|
|
|
|
|
func Equal(predicate Predicate) (string, error) { |
|
|
|
|
|
if predicate.Values == nil || len(predicate.Values) != 1 { |
|
|
|
|
|
return "", errors.New("相等性比较只支持一个参数") |
|
|
|
|
|
} |
|
|
|
|
|
return fmt.Sprintf(" and %s = ?", predicate.ColumnName), nil |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func NotEqual(predicate Predicate) string { |
|
|
|
|
|
return fmt.Sprintf(" and %s <> ?", predicate.ColumnName) |
|
|
|
|
|
|
|
|
func NotEqual(predicate Predicate) (string, error) { |
|
|
|
|
|
if predicate.Values == nil || len(predicate.Values) != 1 { |
|
|
|
|
|
return "", errors.New("相等性比较只支持一个参数") |
|
|
|
|
|
} |
|
|
|
|
|
return fmt.Sprintf(" and %s <> ?", predicate.ColumnName), nil |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func Like(predicate Predicate) string { |
|
|
|
|
|
return fmt.Sprintf(" and %s like concat('%%', ?, '%%')", predicate.ColumnName) |
|
|
|
|
|
|
|
|
func Like(predicate Predicate) (string, error) { |
|
|
|
|
|
if predicate.Values == nil || len(predicate.Values) != 1 { |
|
|
|
|
|
return "", errors.New("相似性比较只支持一个参数") |
|
|
|
|
|
} |
|
|
|
|
|
return fmt.Sprintf(" and %s like concat('%%', ?, '%%')", predicate.ColumnName), nil |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func NotLike(predicate Predicate) string { |
|
|
|
|
|
return fmt.Sprintf(" and %s not like concat('%%', ?, '%%')", predicate.ColumnName) |
|
|
|
|
|
|
|
|
func NotLike(predicate Predicate) (string, error) { |
|
|
|
|
|
if predicate.Values == nil || len(predicate.Values) != 1 { |
|
|
|
|
|
return "", errors.New("相似性比较只支持一个参数") |
|
|
|
|
|
} |
|
|
|
|
|
return fmt.Sprintf(" and %s not like concat('%%', ?, '%%')", predicate.ColumnName), nil |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func IsNull(predicate Predicate) string { |
|
|
|
|
|
return fmt.Sprintf(" and %s is null", predicate.ColumnName) |
|
|
|
|
|
|
|
|
func IsNull(predicate Predicate) (string, error) { |
|
|
|
|
|
if predicate.Values != nil && len(predicate.Values) > 0 { |
|
|
|
|
|
return "", errors.New("为空比较比较不支持参数") |
|
|
|
|
|
} |
|
|
|
|
|
return fmt.Sprintf(" and %s is null", predicate.ColumnName), nil |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func IsNotNull(predicate Predicate) string { |
|
|
|
|
|
return fmt.Sprintf(" and %s is not null", predicate.ColumnName) |
|
|
|
|
|
|
|
|
func IsNotNull(predicate Predicate) (string, error) { |
|
|
|
|
|
if predicate.Values != nil && len(predicate.Values) > 0 { |
|
|
|
|
|
return "", errors.New("为空比较比较不支持参数") |
|
|
|
|
|
} |
|
|
|
|
|
return fmt.Sprintf(" and %s is not null", predicate.ColumnName), nil |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func Include(predicate Predicate) string { |
|
|
|
|
|
|
|
|
func Include(predicate Predicate) (string, error) { |
|
|
if predicate.Values != nil && len(predicate.Values) > 0 { |
|
|
if predicate.Values != nil && len(predicate.Values) > 0 { |
|
|
return fmt.Sprintf(" and %s in (%s)", predicate.ColumnName, strings.Join(RepeatStrings("?", len(predicate.Values)), ",")) |
|
|
|
|
|
|
|
|
return fmt.Sprintf(" and %s in (%s)", predicate.ColumnName, strings.Join(RepeatStrings("?", len(predicate.Values)), ",")), nil |
|
|
} else { |
|
|
} else { |
|
|
return " and 1 <> 1" |
|
|
|
|
|
|
|
|
return " and 1 <> 1", nil |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func Exclude(predicate Predicate) string { |
|
|
|
|
|
return fmt.Sprintf(" and %s not in (%s)", predicate.ColumnName, strings.Join(RepeatStrings("?", len(predicate.Values)), ",")) |
|
|
|
|
|
|
|
|
func Exclude(predicate Predicate) (string, error) { |
|
|
|
|
|
if predicate.Values != nil && len(predicate.Values) > 0 { |
|
|
|
|
|
return fmt.Sprintf(" and %s not in (%s)", predicate.ColumnName, strings.Join(RepeatStrings("?", len(predicate.Values)), ",")), nil |
|
|
|
|
|
} else { |
|
|
|
|
|
return " and 1 = 1", nil |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func Approximate(predicate Predicate) string { |
|
|
|
|
|
return fmt.Sprintf(" and datediff(second, %s, ?) = 0", predicate.ColumnName) |
|
|
|
|
|
|
|
|
func Approximate(predicate Predicate) (string, error) { |
|
|
|
|
|
if predicate.Values == nil || len(predicate.Values) != 1 { |
|
|
|
|
|
return "", errors.New("约等于比较比较只支持一个参数") |
|
|
|
|
|
} |
|
|
|
|
|
return fmt.Sprintf(" and datediff(second, %s, ?) = 0", predicate.ColumnName), nil |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func NotApproximate(predicate Predicate) string { |
|
|
|
|
|
return fmt.Sprintf(" and datediff(second, %s, ?) <> 0", predicate.ColumnName) |
|
|
|
|
|
|
|
|
func NotApproximate(predicate Predicate) (string, error) { |
|
|
|
|
|
if predicate.Values == nil || len(predicate.Values) != 1 { |
|
|
|
|
|
return "", errors.New("约等于比较比较只支持一个参数") |
|
|
|
|
|
} |
|
|
|
|
|
return fmt.Sprintf(" and datediff(second, %s, ?) <> 0", predicate.ColumnName), nil |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func Log(user *models.Usertab, codeFile string, function string, message string) { |
|
|
func Log(user *models.Usertab, codeFile string, function string, message string) { |
|
|