fix: 查询like使用字符串拼接替代concat

This commit is contained in:
TsMask
2025-03-05 17:39:01 +08:00
parent 4e788497d7
commit 0c83bcecc6
25 changed files with 83 additions and 66 deletions

View File

@@ -19,10 +19,10 @@ func (r TraceData) SelectByPage(query map[string]string) ([]model.TraceData, int
tx := db.DB("").Model(&model.TraceData{})
// 查询条件拼接
if v, ok := query["imsi"]; ok && v != "" {
tx = tx.Where("imsi like concat(?, '%')", v)
tx = tx.Where("imsi like ?", fmt.Sprintf("%s%%", v))
}
if v, ok := query["msisdn"]; ok && v != "" {
tx = tx.Where("msisdn like concat(?, '%')", v)
tx = tx.Where("msisdn like ?", fmt.Sprintf("%s%%", v))
}
if v, ok := query["startTime"]; ok && v != "" {
if len(v) == 10 {

View File

@@ -1,6 +1,7 @@
package repository
import (
"fmt"
"time"
"be.ems/src/framework/database/db"
@@ -22,10 +23,10 @@ func (r TraceTask) SelectByPage(query map[string]string) ([]model.TraceTask, int
tx = tx.Where("ne_type = ?", v)
}
if v, ok := query["imsi"]; ok && v != "" {
tx = tx.Where("imsi like concat(?, '%')", v)
tx = tx.Where("imsi like ?", fmt.Sprintf("%s%%", v))
}
if v, ok := query["msisdn"]; ok && v != "" {
tx = tx.Where("msisdn like concat(?, '%')", v)
tx = tx.Where("msisdn like ?", fmt.Sprintf("%s%%", v))
}
if v, ok := query["startTime"]; ok && v != "" {
tx = tx.Where("start_time >= ?", v)

View File

@@ -20,10 +20,10 @@ func (r TraceTaskHlr) SelectByPage(query model.TraceTaskHlrQuery) ([]model.Trace
tx := db.DB("").Model(&model.TraceTaskHlr{})
// 查询条件拼接
if query.IMSI != "" {
tx = tx.Where("imsi like concat(?, '%')", query.IMSI)
tx = tx.Where("imsi like ?", fmt.Sprintf("%s%%", query.IMSI))
}
if query.MSISDN != "" {
tx = tx.Where("msisdn like concat(?, '%')", query.MSISDN)
tx = tx.Where("msisdn like ?", fmt.Sprintf("%s%%", query.MSISDN))
}
if query.StartTime != "" && len(query.StartTime) == 13 {
tx = tx.Where("start_time >= ?", query.StartTime)