From 46ecbd9f5a71c01df45e241c8d5795454dafe1f7 Mon Sep 17 00:00:00 2001
From: zhangqian <zhangqian@123.com>
Date: 星期三, 10 四月 2024 11:03:09 +0800
Subject: [PATCH] 字典支持关键字搜索

---
 models/dict.go |   11 +++++++++++
 1 files changed, 11 insertions(+), 0 deletions(-)

diff --git a/models/dict.go b/models/dict.go
index 00fc491..7e682d8 100644
--- a/models/dict.go
+++ b/models/dict.go
@@ -23,6 +23,7 @@
 		PageNum  int
 		PageSize int
 		Orm      *gorm.DB
+		Keyword  string
 	}
 )
 
@@ -64,6 +65,11 @@
 	return slf
 }
 
+func (slf *DictSearch) SetKeyword(keyword string) *DictSearch {
+	slf.Keyword = keyword
+	return slf
+}
+
 func (slf *DictSearch) SetDictType(dt *constvar.DictType) *DictSearch {
 	slf.DictType = dt
 	return slf
@@ -92,6 +98,11 @@
 		db = db.Where("name = ?", slf.Name)
 	}
 
+	if slf.Keyword != "" {
+		kw := "%" + slf.Keyword + "%"
+		db = db.Where("name like ? or number like ?", kw, kw)
+	}
+
 	return db
 }
 

--
Gitblit v1.8.0