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

@@ -1,6 +1,8 @@
package repository
import (
"fmt"
"be.ems/src/framework/database/db"
"be.ems/src/framework/logger"
"be.ems/src/modules/network_data/model"
@@ -17,7 +19,7 @@ func (r UDMExtend) SelectByPage(query map[string]string) ([]model.UDMExtend, int
tx := db.DB("").Model(&model.UDMExtend{})
// 查询条件拼接
if v, ok := query["imsi"]; ok && v != "" {
tx = tx.Where("imsi like concat(concat('%', ?), '%')", v)
tx = tx.Where("imsi like ?", fmt.Sprintf("%%%s%%", v))
}
if v, ok := query["neId"]; ok && v != "" {
tx = tx.Where("ne_id = ?", v)
@@ -77,7 +79,7 @@ func (r *UDMExtend) SelectByIMSIAndNeID(imsi, neId string) model.UDMExtend {
tx := db.DB("").Model(&model.UDMExtend{})
// 构建查询条件
if neId == "%" {
tx = tx.Where("imsi like concat(?, '%')", imsi)
tx = tx.Where("imsi like ?", fmt.Sprintf("%s%%", imsi))
} else {
tx = tx.Where(" imsi = ? and ne_id = ?", imsi, neId)
}
@@ -105,7 +107,7 @@ func (r *UDMExtend) Inserts(uArr []model.UDMExtend) int64 {
func (r *UDMExtend) Delete(imsi, neId string) int64 {
tx := db.DB("")
if neId == "%" {
tx = tx.Where("imsi like concat(?, '%')", imsi)
tx = tx.Where("imsi like ?", fmt.Sprintf("%s%%", imsi))
} else {
tx = tx.Where(" imsi = ? and ne_id = ?", imsi, neId)
}