...
|
...
|
@@ -91,14 +91,14 @@ type Condition struct { |
|
|
|
|
|
func (c Condition) SetWhere(q *gorm.DB) {
|
|
|
if len(c.Like) > 0 {
|
|
|
q.Where(fmt.Sprintf("%v like '%%%v%%'", c.Field.SQLName, c.Like))
|
|
|
q.Where(fmt.Sprintf("%v like '%%%v%%'", FormatIfNull(c.Field), c.Like))
|
|
|
}
|
|
|
if len(c.In) > 0 {
|
|
|
q.Where(fmt.Sprintf("%v in %v", c.Field.SQLName, c.InArgs(c.In)))
|
|
|
q.Where(fmt.Sprintf("%v in %v", FormatIfNull(c.Field), c.InArgs(c.In)))
|
|
|
}
|
|
|
if len(c.Ex) > 0 {
|
|
|
in := c.InArgs(c.Ex)
|
|
|
q.Where(fmt.Sprintf("%v not in %v", c.Field.SQLName, in))
|
|
|
q.Where(fmt.Sprintf("%v not in %v", FormatIfNull(c.Field), in))
|
|
|
}
|
|
|
if len(c.Range) > 0 {
|
|
|
for _, item := range c.Range {
|
...
|
...
|
@@ -115,7 +115,7 @@ func (c Condition) SetWhere(q *gorm.DB) { |
|
|
continue
|
|
|
}
|
|
|
q.Where(fmt.Sprintf("%s %s %s",
|
|
|
c.Field.SQLName,
|
|
|
FormatIfNull(c.Field),
|
|
|
opVal,
|
|
|
c.formatByOp(item.Op, val),
|
|
|
))
|
...
|
...
|
@@ -129,6 +129,13 @@ func (c Condition) SetWhere(q *gorm.DB) { |
|
|
}
|
|
|
}
|
|
|
|
|
|
func FormatIfNull(f *domain.Field) string {
|
|
|
if domain.SQLType(f.SQLType).IsString() {
|
|
|
return fmt.Sprintf("ifnull(%s,'')", f.SQLName)
|
|
|
}
|
|
|
return f.SQLName
|
|
|
}
|
|
|
|
|
|
var opMap = map[string]string{
|
|
|
"=": "=",
|
|
|
">": ">",
|
...
|
...
|
|